github.com/opentelekomcloud/gophertelekomcloud@v0.9.3/acceptance/openstack/ims/create_whole_image_from_ECS_test.go (about) 1 package ims 2 3 import ( 4 "testing" 5 6 "github.com/opentelekomcloud/gophertelekomcloud/acceptance/clients" 7 "github.com/opentelekomcloud/gophertelekomcloud/acceptance/openstack" 8 "github.com/opentelekomcloud/gophertelekomcloud/acceptance/openstack/cbr/v3" 9 "github.com/opentelekomcloud/gophertelekomcloud/acceptance/tools" 10 "github.com/opentelekomcloud/gophertelekomcloud/openstack/cbr/v3/backups" 11 tag "github.com/opentelekomcloud/gophertelekomcloud/openstack/common/tags" 12 "github.com/opentelekomcloud/gophertelekomcloud/openstack/ims/v1/images" 13 "github.com/opentelekomcloud/gophertelekomcloud/openstack/ims/v2/tags" 14 th "github.com/opentelekomcloud/gophertelekomcloud/testhelper" 15 ) 16 17 func TestCreateWholeImageFromCBR(t *testing.T) { 18 t.Skip("long run test only for manual purpose") 19 client, err := clients.NewCbrV3Client() 20 th.AssertNoErr(t, err) 21 22 client1, client2 := getClient(t) 23 24 vault, _, _, _ := v3.CreateCBR(t, client) 25 list, err := backups.List(client, backups.ListOpts{VaultID: vault.ID}) 26 th.AssertNoErr(t, err) 27 t.Cleanup(func() { 28 err = backups.Delete(client, list[0].ID) 29 th.AssertNoErr(t, err) 30 }) 31 32 fromCBR, err := images.CreateWholeImageFromCBRorCSBS(client1, images.CreateWholeImageFromCBRorCSBSOpts{ 33 Name: tools.RandomString("ims-test-", 3), 34 BackupId: list[0].ID, 35 WholeImageType: "CBR", 36 }) 37 th.AssertNoErr(t, err) 38 39 jobEntities(t, client1, client2, fromCBR) 40 } 41 42 func TestCreateWholeImageFromECS(t *testing.T) { 43 client1, client2 := getClient(t) 44 45 computeClient, err := clients.NewComputeV1Client() 46 th.AssertNoErr(t, err) 47 48 ecs := openstack.CreateCloudServer(t, computeClient, openstack.GetCloudServerCreateOpts(t)) 49 t.Cleanup(func() { openstack.DeleteCloudServer(t, computeClient, ecs.ID) }) 50 51 fromECS, err := images.CreateWholeImageFromECS(client1, images.CreateWholeImageFromECSOpts{ 52 Name: tools.RandomString("ims-test-", 3), 53 InstanceId: ecs.ID, 54 }) 55 th.AssertNoErr(t, err) 56 57 image := jobEntities(t, client1, client2, fromECS) 58 59 err = tags.AddImageTag(client2, tags.AddImageTagOpts{ 60 ImageId: image.ImageId, 61 Tag: tag.ResourceTag{ 62 Key: "test", 63 Value: "testValue", 64 }, 65 }) 66 th.AssertNoErr(t, err) 67 68 imagesTags, err := tags.ListImagesTags(client2) 69 th.AssertNoErr(t, err) 70 tools.PrintResource(t, imagesTags) 71 72 err = tags.DeleteImageTag(client2, tags.DeleteImageTagOpts{ 73 ImageId: image.ImageId, 74 Key: "test", 75 }) 76 th.AssertNoErr(t, err) 77 78 err = tags.BatchAddOrDeleteTags(client2, tags.BatchAddOrDeleteTagsOpts{ 79 ImageId: image.ImageId, 80 Action: "create", 81 Tags: []tag.ResourceTag{ 82 { 83 Key: "test1", 84 Value: "testValue1", 85 }, 86 { 87 Key: "test2", 88 Value: "testValue2", 89 }, 90 }, 91 }) 92 th.AssertNoErr(t, err) 93 94 imageTags, err := tags.ListImageTags(client2, image.ImageId) 95 th.AssertNoErr(t, err) 96 tools.PrintResource(t, imageTags) 97 98 byTags, err := tags.ListImageByTags(client2, tags.ListImageByTagsOpts{ 99 Action: "count", 100 Tags: []tag.ListedTag{{ 101 Key: "test1", 102 Values: []string{"testValue1"}, 103 }}, 104 Limit: "1", 105 }) 106 th.AssertNoErr(t, err) 107 tools.PrintResource(t, byTags) 108 }