github.com/opentelekomcloud/gophertelekomcloud@v0.9.3/acceptance/openstack/rds/v3/configurations_test.go (about)

     1  package v3
     2  
     3  import (
     4  	"testing"
     5  
     6  	"github.com/opentelekomcloud/gophertelekomcloud/acceptance/clients"
     7  	"github.com/opentelekomcloud/gophertelekomcloud/acceptance/tools"
     8  	"github.com/opentelekomcloud/gophertelekomcloud/openstack/rds/v3/configurations"
     9  	th "github.com/opentelekomcloud/gophertelekomcloud/testhelper"
    10  )
    11  
    12  func TestConfigurationsList(t *testing.T) {
    13  	client, err := clients.NewRdsV3()
    14  	th.AssertNoErr(t, err)
    15  
    16  	allConfigurations, err := configurations.List(client)
    17  	th.AssertNoErr(t, err)
    18  
    19  	for _, configuration := range allConfigurations {
    20  		tools.PrintResource(t, configuration)
    21  	}
    22  }
    23  
    24  func TestConfigurationsLifecycle(t *testing.T) {
    25  	client, err := clients.NewRdsV3()
    26  	th.AssertNoErr(t, err)
    27  
    28  	config := createRDSConfiguration(t, client)
    29  	t.Cleanup(func() { deleteRDSConfiguration(t, client, config.ID) })
    30  
    31  	tools.PrintResource(t, config)
    32  
    33  	updateRDSConfiguration(t, client, config.ID)
    34  
    35  	newConfig, err := configurations.Get(client, config.ID)
    36  	th.AssertNoErr(t, err)
    37  
    38  	tools.PrintResource(t, newConfig)
    39  }
    40  
    41  func TestConfigurations(t *testing.T) {
    42  	client, err := clients.NewRdsV3()
    43  	th.AssertNoErr(t, err)
    44  
    45  	cc, err := clients.CloudAndClient()
    46  	th.AssertNoErr(t, err)
    47  
    48  	config := createRDSConfiguration(t, client)
    49  	t.Cleanup(func() { deleteRDSConfiguration(t, client, config.ID) })
    50  
    51  	// Create RDSv3 instance
    52  	rds := CreateRDS(t, client, cc.RegionName)
    53  	t.Cleanup(func() { DeleteRDS(t, client, rds.Id) })
    54  
    55  	t.Logf("Attempting to apply template config %s to instance %s", config.ID, rds.Id)
    56  	configApplyOpts := configurations.ApplyOpts{
    57  		ConfigId:    config.ID,
    58  		InstanceIDs: []string{rds.Id},
    59  	}
    60  	applyResult, err := configurations.Apply(client, configApplyOpts)
    61  	th.AssertNoErr(t, err)
    62  	t.Logf("Template config applied")
    63  
    64  	tools.PrintResource(t, applyResult)
    65  
    66  	instanceConfig, err := configurations.GetForInstance(client, rds.Id)
    67  	th.AssertNoErr(t, err)
    68  	th.CheckEquals(t, config.DatastoreName, instanceConfig.DatastoreName)
    69  	th.CheckEquals(t, config.DatastoreVersionName, instanceConfig.DatastoreVersionName)
    70  	if len(instanceConfig.Parameters) == 0 {
    71  		t.Errorf("instance config has empty parameter list")
    72  	}
    73  
    74  	opts := configurations.UpdateInstanceConfigurationOpts{
    75  		InstanceId: rds.Id,
    76  		Values: map[string]interface{}{
    77  			"max_connections": "37",
    78  			"autocommit":      "OFF",
    79  		}}
    80  	result, err := configurations.UpdateInstanceConfiguration(client, opts)
    81  	th.AssertNoErr(t, err)
    82  	th.AssertEquals(t, true, result.RestartRequired)
    83  }