How to use Sleep method of cloudapi Package

Best K6 code snippet using cloudapi.Sleep

live_test.go

Source:live_test.go Github

copy

Full Screen

...41 c.Assert(err, gc.IsNil)42 c.Assert(machine, gc.NotNil)43 // wait for machine to be provisioned44 for !s.pollMachineState(c, machine.Id, "running") {45 time.Sleep(1 * time.Second)46 }47 return machine48}49// Helper method to create a test virtual machine in the user account with the specified tags50func (s *LiveTests) createMachineWithTags(c *gc.C, tags map[string]string) *cloudapi.Machine {51 machine, err := s.testClient.CreateMachine(cloudapi.CreateMachineOpts{Package: packageName, Image: imageId, Tags: tags})52 c.Assert(err, gc.IsNil)53 c.Assert(machine, gc.NotNil)54 // wait for machine to be provisioned55 for !s.pollMachineState(c, machine.Id, "running") {56 time.Sleep(1 * time.Second)57 }58 return machine59}60// Helper method to test the state of a given VM61func (s *LiveTests) pollMachineState(c *gc.C, machineId, state string) bool {62 machineConfig, err := s.testClient.GetMachine(machineId)63 c.Assert(err, gc.IsNil)64 return strings.EqualFold(machineConfig.State, state)65}66// Helper method to delete a test virtual machine once the test has executed67func (s *LiveTests) deleteMachine(c *gc.C, machineId string) {68 err := s.testClient.StopMachine(machineId)69 c.Assert(err, gc.IsNil)70 // wait for machine to be stopped71 for !s.pollMachineState(c, machineId, "stopped") {72 time.Sleep(1 * time.Second)73 }74 err = s.testClient.DeleteMachine(machineId)75 c.Assert(err, gc.IsNil)76}77// Helper method to list virtual machine according to the specified filter78func (s *LiveTests) listMachines(c *gc.C, filter *cloudapi.Filter) {79 var contains bool80 testMachine := s.createMachine(c)81 defer s.deleteMachine(c, testMachine.Id)82 machines, err := s.testClient.ListMachines(filter)83 c.Assert(err, gc.IsNil)84 c.Assert(machines, gc.NotNil)85 for _, m := range machines {86 if m.Id == testMachine.Id {87 contains = true88 break89 }90 }91 // result92 if !contains {93 c.Fatalf("Obtained machines [%s] do not contain test machine [%s]", machines, *testMachine)94 }95}96// Helper method to create a snapshot of a test virtual machine97func (s *LiveTests) createMachineSnapshot(c *gc.C, machineId string) string {98 // generates a unique snapshot name using the current timestamp99 t := time.Now()100 snapshotName := "test-machine-snapshot-" + t.Format("20060102_150405")101 snapshot, err := s.testClient.CreateMachineSnapshot(machineId, cloudapi.SnapshotOpts{Name: snapshotName})102 c.Assert(err, gc.IsNil)103 c.Assert(snapshot, gc.NotNil)104 c.Assert(snapshot, gc.DeepEquals, &cloudapi.Snapshot{Name: snapshotName, State: "queued"})105 return snapshotName106}107// Helper method to create a test firewall rule108func (s *LiveTests) createFirewallRule(c *gc.C) *cloudapi.FirewallRule {109 fwRule, err := s.testClient.CreateFirewallRule(cloudapi.CreateFwRuleOpts{Enabled: false, Rule: testFwRule})110 c.Assert(err, gc.IsNil)111 c.Assert(fwRule, gc.NotNil)112 c.Assert(fwRule.Rule, gc.Equals, testFwRule)113 c.Assert(fwRule.Enabled, gc.Equals, false)114 time.Sleep(10 * time.Second)115 return fwRule116}117// Helper method to a test firewall rule118func (s *LiveTests) deleteFwRule(c *gc.C, fwRuleId string) {119 err := s.testClient.DeleteFirewallRule(fwRuleId)120 c.Assert(err, gc.IsNil)121}122// Keys API123func (s *LiveTests) TestCreateKey(c *gc.C) {124 s.createKey(c)125}126func (s *LiveTests) TestListKeys(c *gc.C) {127 s.createKey(c)128 keys, err := s.testClient.ListKeys()129 c.Assert(err, gc.IsNil)130 c.Assert(keys, gc.NotNil)131 fakeKey := cloudapi.Key{Name: "fake-key", Fingerprint: testKeyFingerprint, Key: testKey}132 for _, k := range keys {133 if c.Check(k, gc.DeepEquals, fakeKey) {134 c.SucceedNow()135 }136 }137 c.Fatalf("Obtained keys [%s] do not contain test key [%s]", keys, fakeKey)138}139func (s *LiveTests) TestGetKeyByName(c *gc.C) {140 s.createKey(c)141 key, err := s.testClient.GetKey("fake-key")142 c.Assert(err, gc.IsNil)143 c.Assert(key, gc.NotNil)144 c.Assert(key, gc.DeepEquals, &cloudapi.Key{Name: "fake-key", Fingerprint: testKeyFingerprint, Key: testKey})145}146func (s *LiveTests) TestGetKeyByFingerprint(c *gc.C) {147 s.createKey(c)148 key, err := s.testClient.GetKey(testKeyFingerprint)149 c.Assert(err, gc.IsNil)150 c.Assert(key, gc.NotNil)151 c.Assert(key, gc.DeepEquals, &cloudapi.Key{Name: "fake-key", Fingerprint: testKeyFingerprint, Key: testKey})152}153func (s *LiveTests) TestDeleteKey(c *gc.C) {154 s.createKey(c)155 err := s.testClient.DeleteKey("fake-key")156 c.Assert(err, gc.IsNil)157}158// Packages API159func (s *LiveTests) TestListPackages(c *gc.C) {160 pkgs, err := s.testClient.ListPackages(nil)161 c.Assert(err, gc.IsNil)162 c.Assert(pkgs, gc.NotNil)163 for _, pkg := range pkgs {164 c.Check(pkg.Name, gc.FitsTypeOf, string(""))165 c.Check(pkg.Memory, gc.FitsTypeOf, int(0))166 c.Check(pkg.Disk, gc.FitsTypeOf, int(0))167 c.Check(pkg.Swap, gc.FitsTypeOf, int(0))168 c.Check(pkg.VCPUs, gc.FitsTypeOf, int(0))169 c.Check(pkg.Default, gc.FitsTypeOf, bool(false))170 c.Check(pkg.Id, gc.FitsTypeOf, string(""))171 c.Check(pkg.Version, gc.FitsTypeOf, string(""))172 c.Check(pkg.Description, gc.FitsTypeOf, string(""))173 c.Check(pkg.Group, gc.FitsTypeOf, string(""))174 }175}176func (s *LiveTests) TestListPackagesWithFilter(c *gc.C) {177 filter := cloudapi.NewFilter()178 filter.Set("memory", "1024")179 pkgs, err := s.testClient.ListPackages(filter)180 c.Assert(err, gc.IsNil)181 c.Assert(pkgs, gc.NotNil)182 for _, pkg := range pkgs {183 c.Check(pkg.Name, gc.FitsTypeOf, string(""))184 c.Check(pkg.Memory, gc.Equals, 1024)185 c.Check(pkg.Disk, gc.FitsTypeOf, int(0))186 c.Check(pkg.Swap, gc.FitsTypeOf, int(0))187 c.Check(pkg.VCPUs, gc.FitsTypeOf, int(0))188 c.Check(pkg.Default, gc.FitsTypeOf, bool(false))189 c.Check(pkg.Id, gc.FitsTypeOf, string(""))190 c.Check(pkg.Version, gc.FitsTypeOf, string(""))191 c.Check(pkg.Description, gc.FitsTypeOf, string(""))192 c.Check(pkg.Group, gc.FitsTypeOf, string(""))193 }194}195func (s *LiveTests) TestGetPackageFromName(c *gc.C) {196 key, err := s.testClient.GetPackage(packageName)197 c.Assert(err, gc.IsNil)198 c.Assert(key, gc.NotNil)199 c.Assert(key, gc.DeepEquals, &cloudapi.Package{200 Name: packageName,201 Memory: 1024,202 Disk: 33792,203 Swap: 2048,204 VCPUs: 0,205 Default: false,206 Id: packageId,207 Version: "1.0.0",208 Description: "Standard 1 GB RAM 0.25 vCPU and bursting 33 GB Disk",209 Group: "Standard",210 })211}212func (s *LiveTests) TestGetPackageFromId(c *gc.C) {213 key, err := s.testClient.GetPackage(packageId)214 c.Assert(err, gc.IsNil)215 c.Assert(key, gc.NotNil)216 c.Assert(key, gc.DeepEquals, &cloudapi.Package{217 Name: packageName,218 Memory: 1024,219 Disk: 33792,220 Swap: 2048,221 VCPUs: 0,222 Default: false,223 Id: packageId,224 Version: "1.0.0",225 Description: "Standard 1 GB RAM 0.25 vCPU and bursting 33 GB Disk",226 Group: "Standard",227 })228}229// Images API230func (s *LiveTests) TestListImages(c *gc.C) {231 imgs, err := s.testClient.ListImages(nil)232 c.Assert(err, gc.IsNil)233 c.Assert(imgs, gc.NotNil)234 for _, img := range imgs {235 c.Check(img.Id, gc.FitsTypeOf, string(""))236 c.Check(img.Name, gc.FitsTypeOf, string(""))237 c.Check(img.OS, gc.FitsTypeOf, string(""))238 c.Check(img.Version, gc.FitsTypeOf, string(""))239 c.Check(img.Type, gc.FitsTypeOf, string(""))240 c.Check(img.Description, gc.FitsTypeOf, string(""))241 c.Check(img.Requirements, gc.FitsTypeOf, map[string]interface{}{"key": "value"})242 c.Check(img.Homepage, gc.FitsTypeOf, string(""))243 c.Check(img.PublishedAt, gc.FitsTypeOf, string(""))244 c.Check(img.Public, gc.FitsTypeOf, string(""))245 c.Check(img.State, gc.FitsTypeOf, string(""))246 c.Check(img.Tags, gc.FitsTypeOf, map[string]string{"key": "value"})247 c.Check(img.EULA, gc.FitsTypeOf, string(""))248 c.Check(img.ACL, gc.FitsTypeOf, []string{"", ""})249 }250}251func (s *LiveTests) TestListImagesWithFilter(c *gc.C) {252 filter := cloudapi.NewFilter()253 filter.Set("os", "smartos")254 imgs, err := s.testClient.ListImages(filter)255 c.Assert(err, gc.IsNil)256 c.Assert(imgs, gc.NotNil)257 for _, img := range imgs {258 c.Check(img.Id, gc.FitsTypeOf, string(""))259 c.Check(img.Name, gc.FitsTypeOf, string(""))260 c.Check(img.OS, gc.Equals, "smartos")261 c.Check(img.Version, gc.FitsTypeOf, string(""))262 c.Check(img.Type, gc.FitsTypeOf, string(""))263 c.Check(img.Description, gc.FitsTypeOf, string(""))264 c.Check(img.Requirements, gc.FitsTypeOf, map[string]interface{}{"key": "value"})265 c.Check(img.Homepage, gc.FitsTypeOf, string(""))266 c.Check(img.PublishedAt, gc.FitsTypeOf, string(""))267 c.Check(img.Public, gc.FitsTypeOf, string(""))268 c.Check(img.State, gc.FitsTypeOf, string(""))269 c.Check(img.Tags, gc.FitsTypeOf, map[string]string{"key": "value"})270 c.Check(img.EULA, gc.FitsTypeOf, string(""))271 c.Check(img.ACL, gc.FitsTypeOf, []string{"", ""})272 }273}274// TODO Add test for deleteImage, exportImage and CreateMachineFormIMage275func (s *LiveTests) TestGetImage(c *gc.C) {276 requirements := map[string]interface{}{}277 img, err := s.testClient.GetImage(imageId)278 c.Assert(err, gc.IsNil)279 c.Assert(img, gc.NotNil)280 c.Assert(img, gc.DeepEquals, &cloudapi.Image{281 Id: imageId,282 Name: "base",283 Version: "13.1.0",284 OS: "smartos",285 Type: "smartmachine",286 Description: "A 32-bit SmartOS image with just essential packages installed. Ideal for users who are comfortable with setting up their own environment and tools.",287 Requirements: requirements,288 PublishedAt: "2013-04-26T15:16:02Z",289 })290}291// Datacenter API292func (s *LiveTests) TestListDatacenters(c *gc.C) {293 dcs, err := s.testClient.ListDatacenters()294 c.Assert(err, gc.IsNil)295 c.Assert(dcs, gc.HasLen, 4)296 c.Assert(dcs["us-west-1"], gc.Equals, "https://us-west-1.api.joyentcloud.com")297}298func (s *LiveTests) TestGetDatacenter(c *gc.C) {299 dc, err := s.testClient.GetDatacenter("us-west-1")300 c.Assert(err, gc.IsNil)301 c.Assert(dc, gc.Equals, "https://us-west-1.api.joyentcloud.com")302}303func (s *LiveTests) TestCreateMachine(c *gc.C) {304 testMachine := s.createMachine(c)305 defer s.deleteMachine(c, testMachine.Id)306 c.Assert(testMachine.Type, gc.Equals, "smartmachine")307 c.Assert(testMachine.Dataset, gc.Equals, "sdc:sdc:base:13.1.0")308 c.Assert(testMachine.Memory, gc.Equals, 1024)309 c.Assert(testMachine.Disk, gc.Equals, 33792)310 c.Assert(testMachine.Package, gc.Equals, packageName)311 c.Assert(testMachine.Image, gc.Equals, imageId)312}313func (s *LiveTests) TestCreateMachineWithTags(c *gc.C) {314 tags := map[string]string{"tag.tag1": "value1", "tag.tag2": "value2"}315 testMachine := s.createMachineWithTags(c, tags)316 defer s.deleteMachine(c, testMachine.Id)317 c.Assert(testMachine.Type, gc.Equals, "smartmachine")318 c.Assert(testMachine.Dataset, gc.Equals, "sdc:sdc:base:13.1.0")319 c.Assert(testMachine.Memory, gc.Equals, 1024)320 c.Assert(testMachine.Disk, gc.Equals, 33792)321 c.Assert(testMachine.Package, gc.Equals, packageName)322 c.Assert(testMachine.Image, gc.Equals, imageId)323 c.Assert(testMachine.Tags, gc.DeepEquals, map[string]string{"tag1": "value1", "tag2": "value2"})324}325func (s *LiveTests) TestListMachines(c *gc.C) {326 s.listMachines(c, nil)327}328func (s *LiveTests) TestListMachinesWithFilter(c *gc.C) {329 filter := cloudapi.NewFilter()330 filter.Set("memory", "1024")331 s.listMachines(c, filter)332}333func (s *LiveTests) TestCountMachines(c *gc.C) {334 testMachine := s.createMachine(c)335 defer s.deleteMachine(c, testMachine.Id)336 count, err := s.testClient.CountMachines()337 c.Assert(err, gc.IsNil)338 c.Assert(count >= 1, gc.Equals, true)339}340func (s *LiveTests) TestGetMachine(c *gc.C) {341 testMachine := s.createMachine(c)342 defer s.deleteMachine(c, testMachine.Id)343 machine, err := s.testClient.GetMachine(testMachine.Id)344 c.Assert(err, gc.IsNil)345 c.Assert(machine, gc.NotNil)346 c.Assert(machine.Equals(*testMachine), gc.Equals, true)347}348func (s *LiveTests) TestStopMachine(c *gc.C) {349 testMachine := s.createMachine(c)350 defer s.deleteMachine(c, testMachine.Id)351 err := s.testClient.StopMachine(testMachine.Id)352 c.Assert(err, gc.IsNil)353}354func (s *LiveTests) TestStartMachine(c *gc.C) {355 testMachine := s.createMachine(c)356 defer s.deleteMachine(c, testMachine.Id)357 err := s.testClient.StopMachine(testMachine.Id)358 c.Assert(err, gc.IsNil)359 // wait for machine to be stopped360 for !s.pollMachineState(c, testMachine.Id, "stopped") {361 time.Sleep(1 * time.Second)362 }363 err = s.testClient.StartMachine(testMachine.Id)364 c.Assert(err, gc.IsNil)365}366func (s *LiveTests) TestRebootMachine(c *gc.C) {367 testMachine := s.createMachine(c)368 defer s.deleteMachine(c, testMachine.Id)369 err := s.testClient.RebootMachine(testMachine.Id)370 c.Assert(err, gc.IsNil)371}372func (s *LiveTests) TestRenameMachine(c *gc.C) {373 testMachine := s.createMachine(c)374 defer s.deleteMachine(c, testMachine.Id)375 err := s.testClient.RenameMachine(testMachine.Id, "test-machine-renamed")376 c.Assert(err, gc.IsNil)377 renamed, err := s.testClient.GetMachine(testMachine.Id)378 c.Assert(err, gc.IsNil)379 c.Assert(renamed.Name, gc.Equals, "test-machine-renamed")380}381func (s *LiveTests) TestResizeMachine(c *gc.C) {382 testMachine := s.createMachine(c)383 defer s.deleteMachine(c, testMachine.Id)384 err := s.testClient.ResizeMachine(testMachine.Id, "g3-standard-1.75-smartos")385 c.Assert(err, gc.IsNil)386 resized, err := s.testClient.GetMachine(testMachine.Id)387 c.Assert(err, gc.IsNil)388 c.Assert(resized.Package, gc.Equals, "g3-standard-1.75-smartos")389}390func (s *LiveTests) TestListMachinesFirewallRules(c *gc.C) {391 testMachine := s.createMachine(c)392 defer s.deleteMachine(c, testMachine.Id)393 fwRules, err := s.testClient.ListMachineFirewallRules(testMachine.Id)394 c.Assert(err, gc.IsNil)395 c.Assert(fwRules, gc.NotNil)396}397func (s *LiveTests) TestEnableFirewallMachine(c *gc.C) {398 testMachine := s.createMachine(c)399 defer s.deleteMachine(c, testMachine.Id)400 err := s.testClient.EnableFirewallMachine(testMachine.Id)401 c.Assert(err, gc.IsNil)402}403func (s *LiveTests) TestDisableFirewallMachine(c *gc.C) {404 testMachine := s.createMachine(c)405 defer s.deleteMachine(c, testMachine.Id)406 err := s.testClient.DisableFirewallMachine(testMachine.Id)407 c.Assert(err, gc.IsNil)408}409func (s *LiveTests) TestCreateMachineSnapshot(c *gc.C) {410 testMachine := s.createMachine(c)411 defer s.deleteMachine(c, testMachine.Id)412 s.createMachineSnapshot(c, testMachine.Id)413}414func (s *LiveTests) TestStartMachineFromShapshot(c *gc.C) {415 testMachine := s.createMachine(c)416 defer s.deleteMachine(c, testMachine.Id)417 snapshotName := s.createMachineSnapshot(c, testMachine.Id)418 err := s.testClient.StopMachine(testMachine.Id)419 c.Assert(err, gc.IsNil)420 // wait for machine to be stopped421 for !s.pollMachineState(c, testMachine.Id, "stopped") {422 time.Sleep(1 * time.Second)423 }424 err = s.testClient.StartMachineFromSnapshot(testMachine.Id, snapshotName)425 c.Assert(err, gc.IsNil)426}427func (s *LiveTests) TestListMachineSnapshots(c *gc.C) {428 testMachine := s.createMachine(c)429 defer s.deleteMachine(c, testMachine.Id)430 s.createMachineSnapshot(c, testMachine.Id)431 snapshots, err := s.testClient.ListMachineSnapshots(testMachine.Id)432 c.Assert(err, gc.IsNil)433 c.Assert(snapshots, gc.HasLen, 1)434}435func (s *LiveTests) TestGetMachineSnapshot(c *gc.C) {436 testMachine := s.createMachine(c)437 defer s.deleteMachine(c, testMachine.Id)438 snapshotName := s.createMachineSnapshot(c, testMachine.Id)439 snapshot, err := s.testClient.GetMachineSnapshot(testMachine.Id, snapshotName)440 c.Assert(err, gc.IsNil)441 c.Assert(snapshot, gc.NotNil)442 c.Assert(snapshot, gc.DeepEquals, &cloudapi.Snapshot{Name: snapshotName, State: "created"})443}444func (s *LiveTests) TestDeleteMachineSnapshot(c *gc.C) {445 testMachine := s.createMachine(c)446 defer s.deleteMachine(c, testMachine.Id)447 snapshotName := s.createMachineSnapshot(c, testMachine.Id)448 err := s.testClient.DeleteMachineSnapshot(testMachine.Id, snapshotName)449 c.Assert(err, gc.IsNil)450}451func (s *LiveTests) TestUpdateMachineMetadata(c *gc.C) {452 testMachine := s.createMachine(c)453 defer s.deleteMachine(c, testMachine.Id)454 md, err := s.testClient.UpdateMachineMetadata(testMachine.Id, map[string]string{"test-metadata": "md value", "test": "test"})455 metadata := map[string]interface{}{"root_authorized_keys": "ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQCyucy41MNcPxEkNUneeRT0j4mXX5zzW4cFYZ0G/Wpqrb/A+JZV6xlwmAwsGPAvebeEp40CSc0gzauR0nsQ+0Hefdp+dHdEEZlZ7WhedknponA8cQURU38cmTnGweaw2B0+vkULo5AUPAjv0Y1nGPZVlKWNeR6NJhq51pEtj4eLYCJ+kylHEIjQbP5Q1LQHxxotoY29N/xMx+ZVYGprHUJ5ihMOC1nrz2kqUjbCvvMLC0yzAI3vfKtL14BQs9Aq9ggl9oZZylmsgy9CnrPa5t98/wqG+snGyrPSL27km0rll1Jz6xcraGkXQP0adFJxw7mFrXItAt6TUyAuLoohhjHd daniele@lightman.local\n",456 "origin": "cloudapi", "creator_uuid": "ff0c4a2b-f89a-4f14-81ee-5b31e7c89ece", "test": "test", "test-metadata": "md value",457 "context": map[string]interface{}{"caller": map[string]interface{}{"type": "signature", "ip": "127.0.0.1", "keyId": "/dstroppa/keys/12:c3:a7:cb:a2:29:e2:90:88:3f:04:53:3b:4e:75:40"},458 "params": map[string]interface{}{"account": "dstroppa", "machine": testMachine.Id, "test": "test", "test-metadata": "md value"}}}459 c.Assert(err, gc.IsNil)460 c.Assert(md, gc.NotNil)461 c.Assert(md, gc.DeepEquals, metadata)462}463func (s *LiveTests) TestGetMachineMetadata(c *gc.C) {464 testMachine := s.createMachine(c)465 defer s.deleteMachine(c, testMachine.Id)466 md, err := s.testClient.GetMachineMetadata(testMachine.Id)467 c.Assert(err, gc.IsNil)468 c.Assert(md, gc.NotNil)469 c.Assert(md, gc.HasLen, 5)470}471func (s *LiveTests) TestDeleteMachineMetadata(c *gc.C) {472 testMachine := s.createMachine(c)473 defer s.deleteMachine(c, testMachine.Id)474 _, err := s.testClient.UpdateMachineMetadata(testMachine.Id, map[string]string{"test-metadata": "md value"})475 c.Assert(err, gc.IsNil)476 // allow update to propagate477 time.Sleep(10 * time.Second)478 err = s.testClient.DeleteMachineMetadata(testMachine.Id, "test-metadata")479 c.Assert(err, gc.IsNil)480}481func (s *LiveTests) TestDeleteAllMachineMetadata(c *gc.C) {482 testMachine := s.createMachine(c)483 defer s.deleteMachine(c, testMachine.Id)484 err := s.testClient.DeleteAllMachineMetadata(testMachine.Id)485 c.Assert(err, gc.IsNil)486}487func (s *LiveTests) TestAddMachineTags(c *gc.C) {488 testMachine := s.createMachine(c)489 defer s.deleteMachine(c, testMachine.Id)490 machineTags := map[string]string{"test-tag": "test-tag-value", "test": "test", "tag1": "tagtag"}491 tags, err := s.testClient.AddMachineTags(testMachine.Id, map[string]string{"test-tag": "test-tag-value", "test": "test", "tag1": "tagtag"})492 c.Assert(err, gc.IsNil)493 c.Assert(tags, gc.NotNil)494 c.Assert(tags, gc.DeepEquals, machineTags)495}496func (s *LiveTests) TestReplaceMachineTags(c *gc.C) {497 testMachine := s.createMachine(c)498 defer s.deleteMachine(c, testMachine.Id)499 machineTags := map[string]string{"origin": "cloudapi", "creator_uuid": "ff0c4a2b-f89a-4f14-81ee-5b31e7c89ece", "test-tag": "test-tag-value", "test": "test tag", "tag1": "tag2"}500 tags, err := s.testClient.ReplaceMachineTags(testMachine.Id, map[string]string{"test-tag": "test-tag-value", "test": "test tag", "tag1": "tag2"})501 c.Assert(err, gc.IsNil)502 c.Assert(tags, gc.NotNil)503 c.Assert(tags, gc.DeepEquals, machineTags)504}505func (s *LiveTests) TestListMachineTags(c *gc.C) {506 testMachine := s.createMachine(c)507 defer s.deleteMachine(c, testMachine.Id)508 tags, err := s.testClient.ListMachineTags(testMachine.Id)509 c.Assert(err, gc.IsNil)510 c.Assert(tags, gc.NotNil)511 c.Assert(tags, gc.HasLen, 5)512}513func (s *LiveTests) TestGetMachineTag(c *gc.C) {514 testMachine := s.createMachine(c)515 defer s.deleteMachine(c, testMachine.Id)516 _, err := s.testClient.AddMachineTags(testMachine.Id, map[string]string{"test-tag": "test-tag-value"})517 c.Assert(err, gc.IsNil)518 // allow update to propagate519 time.Sleep(15 * time.Second)520 tag, err := s.testClient.GetMachineTag(testMachine.Id, "test-tag")521 c.Assert(err, gc.IsNil)522 c.Assert(tag, gc.NotNil)523 c.Assert(tag, gc.Equals, "test-tag-value")524}525func (s *LiveTests) TestDeleteMachineTag(c *gc.C) {526 testMachine := s.createMachine(c)527 defer s.deleteMachine(c, testMachine.Id)528 _, err := s.testClient.AddMachineTags(testMachine.Id, map[string]string{"test-tag": "test-tag-value"})529 c.Assert(err, gc.IsNil)530 // allow update to propagate531 time.Sleep(15 * time.Second)532 err = s.testClient.DeleteMachineTag(testMachine.Id, "test-tag")533 c.Assert(err, gc.IsNil)534}535func (s *LiveTests) TestDeleteMachineTags(c *gc.C) {536 testMachine := s.createMachine(c)537 defer s.deleteMachine(c, testMachine.Id)538 err := s.testClient.DeleteMachineTags(testMachine.Id)539 c.Assert(err, gc.IsNil)540}541func (s *LiveTests) TestMachineAudit(c *gc.C) {542 testMachine := s.createMachine(c)543 defer s.deleteMachine(c, testMachine.Id)544 actions, err := s.testClient.MachineAudit(testMachine.Id)545 c.Assert(err, gc.IsNil)...

Full Screen

Full Screen

environ_instance.go

Source:environ_instance.go Github

copy

Full Screen

...138 return nil, errors.Annotate(err, "cannot start instances")139 }140 // wait for machine to start141 for !strings.EqualFold(machine.State, "running") {142 time.Sleep(1 * time.Second)143 machine, err = env.compute.cloudapi.GetMachine(machineId)144 if err != nil {145 return nil, errors.Annotate(err, "cannot start instances")146 }147 }148 logger.Infof("started instance %q", machineId)149 inst := &joyentInstance{150 machine: machine,151 env: env,152 }153 if multiwatcher.AnyJobNeedsState(args.InstanceConfig.Jobs...) {154 if err := common.AddStateInstance(env.Storage(), inst.Id()); err != nil {155 logger.Errorf("could not record instance in provider-state: %v", err)156 }157 }158 disk64 := uint64(machine.Disk)159 hc := instance.HardwareCharacteristics{160 Arch: &spec.Image.Arch,161 Mem: &spec.InstanceType.Mem,162 CpuCores: &spec.InstanceType.CpuCores,163 CpuPower: spec.InstanceType.CpuPower,164 RootDisk: &disk64,165 }166 return &environs.StartInstanceResult{167 Instance: inst,168 Hardware: &hc,169 }, nil170}171func (env *joyentEnviron) AllInstances() ([]instance.Instance, error) {172 instances := []instance.Instance{}173 filter := cloudapi.NewFilter()174 filter.Set("tag.group", "juju")175 filter.Set("tag.env", env.Config().Name())176 machines, err := env.compute.cloudapi.ListMachines(filter)177 if err != nil {178 return nil, errors.Annotate(err, "cannot retrieve instances")179 }180 for _, m := range machines {181 if strings.EqualFold(m.State, "provisioning") || strings.EqualFold(m.State, "running") {182 copy := m183 instances = append(instances, &joyentInstance{machine: &copy, env: env})184 }185 }186 return instances, nil187}188func (env *joyentEnviron) Instances(ids []instance.Id) ([]instance.Instance, error) {189 if len(ids) == 0 {190 return nil, nil191 }192 logger.Debugf("Looking for instances %q", ids)193 instances := make([]instance.Instance, len(ids))194 found := 0195 allInstances, err := env.AllInstances()196 if err != nil {197 return nil, err198 }199 for i, id := range ids {200 for _, instance := range allInstances {201 if instance.Id() == id {202 instances[i] = instance203 found++204 }205 }206 }207 logger.Debugf("Found %d instances %q", found, instances)208 if found == 0 {209 return nil, environs.ErrNoInstances210 } else if found < len(ids) {211 return instances, environs.ErrPartialInstances212 }213 return instances, nil214}215func (env *joyentEnviron) StopInstances(ids ...instance.Id) error {216 // Remove all the instances in parallel so that we incur less round-trips.217 var wg sync.WaitGroup218 //var err error219 wg.Add(len(ids))220 errc := make(chan error, len(ids))221 for _, id := range ids {222 id := id // copy to new free var for closure223 go func() {224 defer wg.Done()225 if err := env.stopInstance(string(id)); err != nil {226 errc <- err227 }228 }()229 }230 wg.Wait()231 select {232 case err := <-errc:233 return errors.Annotate(err, "cannot stop all instances")234 default:235 }236 return common.RemoveStateInstances(env.Storage(), ids...)237}238func (env *joyentEnviron) stopInstance(id string) error {239 // wait for machine to be running240 // if machine is still provisioning stop will fail241 for !env.pollMachineState(id, "running") {242 time.Sleep(1 * time.Second)243 }244 err := env.compute.cloudapi.StopMachine(id)245 if err != nil {246 return errors.Annotatef(err, "cannot stop instance %v", id)247 }248 // wait for machine to be stopped249 for !env.pollMachineState(id, "stopped") {250 time.Sleep(1 * time.Second)251 }252 err = env.compute.cloudapi.DeleteMachine(id)253 if err != nil {254 return errors.Annotatef(err, "cannot delete instance %v", id)255 }256 return nil257}258func (env *joyentEnviron) pollMachineState(machineId, state string) bool {259 instanceConfig, err := env.compute.cloudapi.GetMachine(machineId)260 if err != nil {261 return false262 }263 return strings.EqualFold(instanceConfig.State, state)264}...

Full Screen

Full Screen

local_test.go

Source:local_test.go Github

copy

Full Screen

...83 c.Assert(err, gc.IsNil)84 c.Assert(machine, gc.NotNil)85 // wait for machine to be provisioned86 for !s.pollMachineState(c, machine.Id, "running") {87 time.Sleep(1 * time.Second)88 }89 return machine90}91// Helper method to test the state of a given VM92func (s *LocalTests) pollMachineState(c *gc.C, machineId, state string) bool {93 machineConfig, err := s.testClient.GetMachine(machineId)94 c.Assert(err, gc.IsNil)95 return strings.EqualFold(machineConfig.State, state)96}97// Helper method to delete a test virtual machine once the test has executed98func (s *LocalTests) deleteMachine(c *gc.C, machineId string) {99 err := s.testClient.StopMachine(machineId)100 c.Assert(err, gc.IsNil)101 // wait for machine to be stopped102 for !s.pollMachineState(c, machineId, "stopped") {103 time.Sleep(1 * time.Second)104 }105 err = s.testClient.DeleteMachine(machineId)106 c.Assert(err, gc.IsNil)107}108// Helper method to list virtual machine according to the specified filter109func (s *LocalTests) listMachines(c *gc.C, filter *cloudapi.Filter) {110 var contains bool111 testMachine := s.createMachine(c)112 defer s.deleteMachine(c, testMachine.Id)113 machines, err := s.testClient.ListMachines(filter)114 c.Assert(err, gc.IsNil)115 c.Assert(machines, gc.NotNil)116 for _, m := range machines {117 if m.Id == testMachine.Id {118 contains = true119 break120 }121 }122 // result123 if !contains {124 c.Fatalf("Obtained machines [%v] do not contain test machine [%v]", machines, *testMachine)125 }126}127// Helper method to create a test firewall rule128func (s *LocalTests) createFirewallRule(c *gc.C) *cloudapi.FirewallRule {129 fwRule, err := s.testClient.CreateFirewallRule(cloudapi.CreateFwRuleOpts{Enabled: false, Rule: testFwRule})130 c.Assert(err, gc.IsNil)131 c.Assert(fwRule, gc.NotNil)132 c.Assert(fwRule.Rule, gc.Equals, testFwRule)133 c.Assert(fwRule.Enabled, gc.Equals, false)134 time.Sleep(10 * time.Second)135 return fwRule136}137// Helper method to a test firewall rule138func (s *LocalTests) deleteFwRule(c *gc.C, fwRuleId string) {139 err := s.testClient.DeleteFirewallRule(fwRuleId)140 c.Assert(err, gc.IsNil)141}...

Full Screen

Full Screen

Sleep

Using AI Code Generation

copy

Full Screen

1import (2type MyPlugin struct {3}4func main() {5 plugin.Start(new(MyPlugin))6}7func (p *MyPlugin) Run(context plugin.PluginContext, args []string) {8 fmt.Println("Hello from the IBM Cloud CLI!")9 time.Sleep(1000 * time.Millisecond)10}

Full Screen

Full Screen

Sleep

Using AI Code Generation

copy

Full Screen

1import "fmt"2import "time"3func main() {4 fmt.Println("Hello, playground")5 time.Sleep(5 * time.Second)6 fmt.Println("Hello, playground")7}8import "fmt"9import "time"10func main() {11 fmt.Println("Hello, playground")12 time.Sleep(5 * time.Second)13 fmt.Println("Hello, playground")14}15import "fmt"16import "time"17func main() {18 fmt.Println("Hello, playground")19 time.Sleep(5 * time.Second)20 fmt.Println("Hello, playground")21}22import "fmt"23import "time"24func main() {25 fmt.Println("Hello, playground")26 time.Sleep(5 * time.Second)27 fmt.Println("Hello, playground")28}29import "fmt"30import "time"31func main() {32 fmt.Println("Hello, playground")33 time.Sleep(5 * time.Second)34 fmt.Println("Hello, playground")35}36import "fmt"37import "time"38func main() {39 fmt.Println("Hello, playground")40 time.Sleep(5 * time.Second)41 fmt.Println("Hello, playground")42}43import "fmt"44import "time"45func main() {46 fmt.Println("Hello, playground")47 time.Sleep(5 * time.Second)48 fmt.Println("Hello, playground")49}50import "fmt"51import "time"52func main() {53 fmt.Println("Hello, playground")54 time.Sleep(5 * time.Second)55 fmt.Println("Hello, playground")56}57import "fmt"58import "time"59func main() {60 fmt.Println("Hello, playground")

Full Screen

Full Screen

Sleep

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 fmt.Println("Hello, playground")4 time.Sleep(5 * time.Second)5 fmt.Println("Hello, playground")6}7import (8func main() {9 fmt.Println("Hello, playground")10 time.Sleep(5 * time.Second)11 fmt.Println("Hello, playground")12}13import (14func main() {15 fmt.Println("Hello, playground")16 time.Sleep(5 * time.Second)17 fmt.Println("Hello, playground")18}19import (20func main() {21 fmt.Println("Hello, playground")22 time.Sleep(5 * time.Second)23 fmt.Println("Hello, playground")24}25import (26func main() {27 fmt.Println("Hello, playground")28 time.Sleep(5 * time.Second)29 fmt.Println("Hello, playground")30}31import (32func main() {33 fmt.Println("Hello, playground")34 time.Sleep(5 * time.Second)35 fmt.Println("Hello, playground")36}37import (38func main() {39 fmt.Println("Hello, playground")40 time.Sleep(5 * time.Second)41 fmt.Println("Hello, playground")42}43import (44func main() {45 fmt.Println("Hello, playground")46 time.Sleep(5 * time.Second)47 fmt.Println("Hello, playground")48}49import (50func main() {51 fmt.Println("Hello, playground")52 time.Sleep(5 * time.Second)53 fmt.Println("Hello, playground")54}

Full Screen

Full Screen

Sleep

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 fmt.Println("Hello, playground")4 time.Sleep(5 * time.Second)5 fmt.Println("Hello, playground")6}7import (8func main() {9 fmt.Println("Hello, playground")10 time.Sleep(5 * time.Second)11 fmt.Println("Hello, playground")12}13import (14func main() {15 fmt.Println("Hello, playground")16 time.Sleep(5 * time.Second)17 fmt.Println("Hello, playground")18}19import (20func main() {21 fmt.Println("Hello, playground")22 time.Sleep(5 * time.Second)23 fmt.Println("Hello, playground")24}25import (26func main() {27 fmt.Println("Hello, playground")28 time.Sleep(5 * time.Second)29 fmt.Println("Hello, playground")30}31import (32func main() {33 fmt.Println("Hello, playground")34 time.Sleep(5 * time.Second)35 fmt.Println("Hello, playground")36}37import (38func main() {39 fmt.Println("Hello, playground")40 time.Sleep(5 * time.Second)41 fmt.Println("Hello, playground")42}43import (44func main() {45 fmt.Println("Hello, playground")46 time.Sleep(5 * time.Second)47 fmt.Println("Hello, playground")48}49import (50func main() {51 fmt.Println("Hello, playground")52 time.Sleep(5 * time.Second)53 fmt.Println("Hello, playground")54}

Full Screen

Full Screen

Sleep

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 cloudapi := CloudAPI{}4 cloudapi.Sleep(2)5}6type CloudAPI struct {7}8func (cloudapi CloudAPI) Sleep(seconds int) {9 fmt.Println("Sleeping for", seconds, "seconds")10 time.Sleep(time.Duration(seconds) * time.Second)11}12import (13func main() {14 cloudapi := CloudAPI{}15 cloudapi.Sleep(2)16}17type CloudAPI struct {18}19func (cloudapi CloudAPI) Sleep(seconds int) {20 fmt.Println("Sleeping for", seconds, "seconds")21}22main.main()23runtime.goexit()24import (25func TestSleep(t *testing.T) {26 cloudapi := CloudAPI{}

Full Screen

Full Screen

Sleep

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 fmt.Println("Hello World!")4 cloudapi.Sleep(1000)5 fmt.Println("Hello World!")6}7import (8func main() {9 fmt.Println("Hello World!")10 cloudapi.Sleep(1000)11 fmt.Println("Hello World!")12}13import (14func main() {15 fmt.Println("Hello World!")16 cloudapi.Sleep(1000)17 fmt.Println("Hello World!")18}19package github.com/CloudAPI/cloudapi.go: unrecognized import path "github.com/CloudAPI/cloudapi.go" (parse

Full Screen

Full Screen

Sleep

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 time.Sleep(10 * time.Second)4 fmt.Println("Hello")5}6import (7func main() {8 time.Sleep(time.Second * 10)9 fmt.Println("Hello")10}11import (12func main() {13 time.Sleep(10 * time.Second)14 fmt.Println("Hello")15}16import (17func main() {18 time.Sleep(time.Second * 10)19 fmt.Println("Hello")20}21import (22func main() {23 time.Sleep(10 * time.Second)24 fmt.Println("Hello")25}26import (27func main() {28 time.Sleep(time.Second * 10)29 fmt.Println("Hello")30}31import (32func main() {33 time.Sleep(10 * time.Second)34 fmt.Println("Hello")35}36import (37func main()

Full Screen

Full Screen

Sleep

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 fmt.Println("Hello, playground")4 time.Sleep(10 * time.Second)5}6import (7func main() {8 fmt.Println("Hello, playground")9 time.Sleep(10 * time.Second)10}11import (12func main() {13 fmt.Println("Hello, playground")14 time.Sleep(10 * time.Second)15}16import (17func main() {18 fmt.Println("Hello, playground")19 time.Sleep(10 * time.Second)20}21import (22func main() {23 fmt.Println("Hello, playground")24 time.Sleep(10 * time.Second)25}26import (27func main() {28 fmt.Println("Hello, playground")29 time.Sleep(10 * time.Second)30}31import (32func main() {33 fmt.Println("Hello, playground")34 time.Sleep(10 * time.Second)35}36import (37func main() {38 fmt.Println("Hello, playground")39 time.Sleep(10 * time.Second)40}41import (42func main() {

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful