github.com/opentelekomcloud/gophertelekomcloud@v0.9.3/acceptance/openstack/dcs/v1/configs_test.go (about) 1 package v1 2 3 import ( 4 "fmt" 5 "testing" 6 7 golangsdk "github.com/opentelekomcloud/gophertelekomcloud" 8 "github.com/opentelekomcloud/gophertelekomcloud/acceptance/clients" 9 "github.com/opentelekomcloud/gophertelekomcloud/openstack/common/pointerto" 10 "github.com/opentelekomcloud/gophertelekomcloud/openstack/common/tags" 11 "github.com/opentelekomcloud/gophertelekomcloud/openstack/dcs/v1/configs" 12 dcsTags "github.com/opentelekomcloud/gophertelekomcloud/openstack/dcs/v2/tags" 13 "github.com/opentelekomcloud/gophertelekomcloud/openstack/dcs/v2/whitelists" 14 th "github.com/opentelekomcloud/gophertelekomcloud/testhelper" 15 ) 16 17 func TestDcsConfigLifeCycle(t *testing.T) { 18 client, err := clients.NewDcsV1Client() 19 th.AssertNoErr(t, err) 20 21 dcsInstance := createDCSInstance(t, client) 22 th.AssertEquals(t, dcsInstance.Capacity, 0) 23 th.AssertEquals(t, dcsInstance.CapacityMinor, ".125") 24 25 t.Logf("Attempting to update whitelist configuration") 26 err = whitelists.Put(client, dcsInstance.InstanceID, whitelists.WhitelistOpts{ 27 Enable: pointerto.Bool(true), 28 Groups: []whitelists.WhitelistGroupOpts{ 29 { 30 GroupName: "test-group-1", 31 IPList: []string{ 32 "10.10.10.1", "10.10.10.2", 33 }, 34 }, 35 }, 36 }) 37 th.AssertNoErr(t, err) 38 39 updateOpts := configs.UpdateOpts{ 40 RedisConfigs: []configs.RedisConfig{ 41 { 42 ParamID: "1", 43 ParamName: "timeout", 44 ParamValue: "100", 45 }, 46 }, 47 } 48 t.Logf("Attempting to update DCSv1 configuration") 49 err = configs.Update(client, dcsInstance.InstanceID, updateOpts) 50 th.AssertNoErr(t, err) 51 t.Logf("Updated DCSv1 configuration") 52 53 configList, err := configs.List(client, dcsInstance.InstanceID) 54 th.AssertNoErr(t, err) 55 th.AssertDeepEquals(t, updateOpts.RedisConfigs[0].ParamID, configList.RedisConfigs[0].ParamID) 56 th.AssertDeepEquals(t, updateOpts.RedisConfigs[0].ParamValue, configList.RedisConfigs[0].ParamValue) 57 th.AssertDeepEquals(t, updateOpts.RedisConfigs[0].ParamName, configList.RedisConfigs[0].ParamName) 58 59 t.Logf("Retrieving whitelist configuration") 60 err = WaitForAWhitelistToBeRetrieved(client, dcsInstance.InstanceID, 180) 61 if err == nil { 62 whitelistResp, err := whitelists.Get(client, dcsInstance.InstanceID) 63 th.AssertNoErr(t, err) 64 th.AssertEquals(t, whitelistResp.InstanceID, dcsInstance.InstanceID) 65 th.AssertEquals(t, whitelistResp.Groups[0].GroupName, "test-group-1") 66 } 67 68 t.Logf("Retrieving instance tags") 69 instanceTags, err := tags.Get(client, "instances", dcsInstance.InstanceID).Extract() 70 th.AssertNoErr(t, err) 71 th.AssertEquals(t, len(instanceTags), 2) 72 th.AssertEquals(t, instanceTags[0].Key, "muh") 73 th.AssertEquals(t, instanceTags[0].Value, "kuh") 74 75 t.Logf("Updating instance tags") 76 err = updateDcsTags(client, dcsInstance.InstanceID, instanceTags, 77 []tags.ResourceTag{ 78 { 79 Key: "muhUpdated", 80 Value: "kuhUpdated", 81 }, 82 }) 83 th.AssertNoErr(t, err) 84 t.Logf("Retrieving updated instance tags") 85 instanceTagsUpdated, err := tags.Get(client, "instances", dcsInstance.InstanceID).Extract() 86 th.AssertNoErr(t, err) 87 th.AssertEquals(t, len(instanceTagsUpdated), 1) 88 th.AssertEquals(t, instanceTagsUpdated[0].Key, "muhUpdated") 89 th.AssertEquals(t, instanceTagsUpdated[0].Value, "kuhUpdated") 90 } 91 92 // WaitForAWhitelistToBeRetrieved - wait until whitelist is retrieved 93 func WaitForAWhitelistToBeRetrieved(client *golangsdk.ServiceClient, id string, timeoutSeconds int) error { 94 return golangsdk.WaitFor(timeoutSeconds, func() (bool, error) { 95 wl, err := whitelists.Get(client, id) 96 if err != nil { 97 return false, fmt.Errorf("error retriving whitelist: %w", err) 98 } 99 if wl.InstanceID != "" { 100 return true, nil 101 } 102 return false, nil 103 }) 104 } 105 106 func updateDcsTags(client *golangsdk.ServiceClient, id string, old, new []tags.ResourceTag) error { 107 // remove old tags 108 if len(old) > 0 { 109 err := dcsTags.Delete(client, id, old) 110 if err != nil { 111 return err 112 } 113 } 114 // add new tags 115 if len(new) > 0 { 116 err := dcsTags.Create(client, id, new) 117 if err != nil { 118 return err 119 } 120 } 121 return nil 122 }