Skip to content

Commit

Permalink
[Test/Fix/Style] Tests rework, docstrings fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
anton-sidelnikov committed Oct 22, 2024
1 parent 606e69e commit 88144b6
Show file tree
Hide file tree
Showing 30 changed files with 159 additions and 124 deletions.
76 changes: 53 additions & 23 deletions acceptance/openstack/ddm/v1/helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,11 @@ import (

golangsdk "github.com/opentelekomcloud/gophertelekomcloud"
"github.com/opentelekomcloud/gophertelekomcloud/acceptance/clients"
"github.com/opentelekomcloud/gophertelekomcloud/acceptance/openstack"
"github.com/opentelekomcloud/gophertelekomcloud/acceptance/tools"

ddminstances "github.com/opentelekomcloud/gophertelekomcloud/openstack/ddm/v1/instances"
ddminstancesv1 "github.com/opentelekomcloud/gophertelekomcloud/openstack/ddm/v1/instances"
ddminstancesv2 "github.com/opentelekomcloud/gophertelekomcloud/openstack/ddm/v2/instances"
rdsinstances "github.com/opentelekomcloud/gophertelekomcloud/openstack/rds/v3/instances"

th "github.com/opentelekomcloud/gophertelekomcloud/testhelper"
Expand All @@ -27,9 +29,9 @@ func CreateRDS(t *testing.T, client *golangsdk.ServiceClient, region string) *rd
vpcID := clients.EnvOS.GetEnv("VPC_ID")
subnetID := clients.EnvOS.GetEnv("NETWORK_ID")
kmsID := clients.EnvOS.GetEnv("KMS_ID")
secGroupId := clients.EnvOS.GetEnv("SECURITY_GROUP")
if vpcID == "" || subnetID == "" || secGroupId == "" {
t.Skip("One of OS_VPC_ID or OS_NETWORK_ID or OS_SECURITY_GROUP env vars is missing but RDS test requires using existing network")
secGroupId := openstack.DefaultSecurityGroup(t)
if vpcID == "" || subnetID == "" {
t.Skip("One of OS_VPC_ID or OS_NETWORK_ID env vars is missing but RDS test requires using existing network")
}

createRdsOpts := rdsinstances.CreateRdsOpts{
Expand Down Expand Up @@ -82,34 +84,52 @@ func DeleteRDS(t *testing.T, client *golangsdk.ServiceClient, rdsID string) {
t.Logf("RDSv3 instance deleted: %s", rdsID)
}

func CreateDDMInstance(t *testing.T, client *golangsdk.ServiceClient) *ddminstances.Instance {
func CreateDDMInstance(t *testing.T, client *golangsdk.ServiceClient) *ddminstancesv1.Instance {
vpcID := clients.EnvOS.GetEnv("VPC_ID")
subnetID := clients.EnvOS.GetEnv("NETWORK_ID")
secGroupId := clients.EnvOS.GetEnv("SECURITY_GROUP")
if subnetID == "" || vpcID == "" || secGroupId == "" {
t.Skip("OS_NETWORK_ID or OS_VPC_ID or OS_SECURITY_GROUP env vars are missing but are required for DDM instances")
if subnetID == "" || vpcID == "" {
t.Skip("OS_NETWORK_ID or OS_VPC_ID env vars are missing but are required for DDM instances")
}
secGroupId := openstack.DefaultSecurityGroup(t)

engineId := "367b68a3-b48b-3d8a-b3a1-4c463a75a4b4"
clientV2, err := clients.NewDDMV2Client()
th.AssertNoErr(t, err)
engines, err := ddminstancesv2.QueryEngineInfo(clientV2, ddminstancesv2.QueryEngineOpts{})
th.AssertNoErr(t, err)
if len(engines) != 0 {
engineId = engines[0].ID
}

flavorId := "941b5a6d-3485-329e-902c-ffd49d352f16"
classes, err := ddminstancesv2.QueryNodeClasses(clientV2, ddminstancesv2.QueryNodeClassesOpts{
EngineId: engineId,
})
th.AssertNoErr(t, err)
if len(classes.ComputeFlavorGroups) != 0 {
flavorId = classes.ComputeFlavorGroups[0].ComputeFlavors[0].ID
}

instanceName := tools.RandomString("ddm-instance-", 3)
instanceDetails := ddminstances.CreateInstanceDetail{
instanceDetails := ddminstancesv1.CreateInstanceDetail{
Name: instanceName,
FlavorId: "941b5a6d-3485-329e-902c-ffd49d352f16",
FlavorId: flavorId,
NodeNum: 2,
EngineId: "367b68a3-b48b-3d8a-b3a1-4c463a75a4b4",
EngineId: engineId,
AvailableZones: []string{"eu-de-01", "eu-de-02", "eu-de-03"},
VpcId: vpcID,
SubnetId: subnetID,
SecurityGroupId: secGroupId,
}
createOpts := ddminstances.CreateOpts{
createOpts := ddminstancesv1.CreateOpts{
Instance: instanceDetails,
}

t.Logf("Creating DDM Instance: %s", instanceName)
ddmInstance, err := ddminstances.Create(client, createOpts)
ddmInstance, err := ddminstancesv1.Create(client, createOpts)
th.AssertNoErr(t, err)
err = golangsdk.WaitFor(1200, func() (bool, error) {
instanceDetails, err := ddminstances.QueryInstanceDetails(client, ddmInstance.Id)
instanceDetails, err := ddminstancesv1.QueryInstanceDetails(client, ddmInstance.Id)
if err != nil {
return false, err
}
Expand All @@ -128,20 +148,16 @@ func CreateDDMInstance(t *testing.T, client *golangsdk.ServiceClient) *ddminstan
func DeleteDDMInstance(t *testing.T, client *golangsdk.ServiceClient, instanceId string) {
t.Logf("Attempting to delete DDM Instance with ID: %s", instanceId)

err := golangsdk.WaitFor(1000, func() (bool, error) {
_, err := ddminstances.Delete(client, instanceId, true)
if err != nil {
return false, nil
}
return true, nil
})
_, err := ddminstancesv1.Delete(client, instanceId, true)
th.AssertNoErr(t, err)
err = waitForInstanceDeleted(client, 600, instanceId)
th.AssertNoErr(t, err)
t.Logf("Deleted DDM Instance with ID: %s", instanceId)
}

func WaitForInstanceInRunningState(client *golangsdk.ServiceClient, ddmInstanceId string) error {
func WaitForInstanceInRunningState(client *golangsdk.ServiceClient, instanceID string) error {
return golangsdk.WaitFor(1200, func() (bool, error) {
instanceDetails, err := ddminstances.QueryInstanceDetails(client, ddmInstanceId)
instanceDetails, err := ddminstancesv1.QueryInstanceDetails(client, instanceID)
if err != nil {
return false, err
}
Expand All @@ -152,3 +168,17 @@ func WaitForInstanceInRunningState(client *golangsdk.ServiceClient, ddmInstanceI
return false, nil
})
}

func waitForInstanceDeleted(client *golangsdk.ServiceClient, secs int, instanceID string) error {
return golangsdk.WaitFor(secs, func() (bool, error) {
_, err := ddminstancesv1.QueryInstanceDetails(client, instanceID)
if err != nil {
if _, ok := err.(golangsdk.ErrDefault404); ok {
return true, nil
}
return false, err
}

return false, nil
})
}
33 changes: 17 additions & 16 deletions acceptance/openstack/ddm/v1/instances_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"testing"

"github.com/opentelekomcloud/gophertelekomcloud/acceptance/clients"
"github.com/opentelekomcloud/gophertelekomcloud/acceptance/openstack"
"github.com/opentelekomcloud/gophertelekomcloud/acceptance/tools"
"github.com/opentelekomcloud/gophertelekomcloud/openstack/ddm/v1/instances"

Expand All @@ -20,12 +21,10 @@ func TestDDMQueryInstances(t *testing.T) {
}

func TestDDMInstancesLifecycle(t *testing.T) {

vpcID := clients.EnvOS.GetEnv("VPC_ID")
subnetID := clients.EnvOS.GetEnv("NETWORK_ID")
secGroupId := clients.EnvOS.GetEnv("SECURITY_GROUP")
if subnetID == "" || vpcID == "" || secGroupId == "" {
t.Skip("OS_NETWORK_ID or OS_VPC_ID or OS_SECURITY_GROUP env vars are missing but are required for DDM instances test")
if subnetID == "" || vpcID == "" {
t.Skip("OS_NETWORK_ID or OS_VPC_ID env vars are missing but are required for DDM instances test")
}

// CREATE CLIENT
Expand All @@ -34,7 +33,13 @@ func TestDDMInstancesLifecycle(t *testing.T) {

// CREATE DDM INSTANCE
ddmInstance := CreateDDMInstance(t, client)

t.Logf("Creating Second Security Group")
newSecGroupId := openstack.CreateSecurityGroup(t)
t.Cleanup(func() {
t.Logf("Deleting DDM Instance: %s", ddmInstance.Id)
DeleteDDMInstance(t, client, ddmInstance.Id)
openstack.DeleteSecurityGroup(t, newSecGroupId)
})
// RENAME DDM INSTANCE
newInstanceName := tools.RandomString("ddm-instance-renamed-", 3)
t.Logf("Renaming DDM Instance '%s' to '%s'", ddmInstance.Id, newInstanceName)
Expand All @@ -44,27 +49,23 @@ func TestDDMInstancesLifecycle(t *testing.T) {
t.Logf("Renamed DDM Instance '%s' to '%s'", ddmInstance.Id, newInstanceName)

// MODIFY SECURITY GROUP
newSecGroupId := clients.EnvOS.GetEnv("SECURITY_GROUP_2")
if newSecGroupId != "" {
modifySecGroupOpts := instances.ModifySecurityGroupOpts{
SecurityGroupId: newSecGroupId,
}
modifiedSecGroupID, err := instances.ModifySecurityGroup(client, ddmInstance.Id, modifySecGroupOpts)
th.AssertNoErr(t, err)
th.AssertEquals(t, newSecGroupId, *modifiedSecGroupID)
modifySecGroupOpts := instances.ModifySecurityGroupOpts{
SecurityGroupId: newSecGroupId,
}
modifiedSecGroupID, err := instances.ModifySecurityGroup(client, ddmInstance.Id, modifySecGroupOpts)
th.AssertNoErr(t, err)
th.AssertEquals(t, newSecGroupId, *modifiedSecGroupID)

// QUERY NODES
t.Logf("Quering DDM Nodes")
queryNodeOpts := instances.QueryNodesOpts{}
nodeList, err := instances.QueryNodes(client, ddmInstance.Id, queryNodeOpts)
th.AssertEquals(t, len(nodeList), 2)
th.AssertNoErr(t, err)

// QUERY NODE DETAILS
t.Logf("Quering DDM Node details: %s", nodeList[0].NodeID)
nodeDetails, err := instances.QueryNodeDetails(client, ddmInstance.Id, nodeList[0].NodeID)
th.AssertNoErr(t, err)
th.AssertEquals(t, nodeDetails.NodeID, nodeList[0].NodeID)

// DELETE DDM INSTANCE
DeleteDDMInstance(t, client, ddmInstance.Id)
}
10 changes: 3 additions & 7 deletions acceptance/openstack/ddm/v1/schemas_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,8 @@ import (
func TestDDMSchemasLifecycle(t *testing.T) {
vpcID := clients.EnvOS.GetEnv("VPC_ID")
subnetID := clients.EnvOS.GetEnv("NETWORK_ID")
secGroupId := clients.EnvOS.GetEnv("SECURITY_GROUP")
if subnetID == "" || vpcID == "" || secGroupId == "" {
t.Skip("OS_NETWORK_ID or OS_VPC_ID or OS_SECURITY_GROUP env vars are missing but are required for DDM instances test")
if subnetID == "" || vpcID == "" {
t.Skip("OS_NETWORK_ID or OS_VPC_ID env vars are missing but are required for DDM instances test")
}

// CREATE DDM CLIENT
Expand All @@ -26,14 +25,11 @@ func TestDDMSchemasLifecycle(t *testing.T) {
rdsclient, err := clients.NewRdsV3()
th.AssertNoErr(t, err)

cc, err := clients.CloudAndClient()
th.AssertNoErr(t, err)

// CREATE DDM INSTANCE
ddmInstance := CreateDDMInstance(t, client)
// CREATE RDS INSTANCE
// RDS INSTANCE MUST BE MYSQL 5.7, 8.0 WITH LowerCaseTableNames SET TO 1
rdsInstance := CreateRDS(t, rdsclient, cc.RegionName)
rdsInstance := CreateRDS(t, rdsclient, client.RegionID)

// CLEANUP
t.Cleanup(func() {
Expand Down
41 changes: 29 additions & 12 deletions acceptance/openstack/ddm/v2/instances_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (
)

func TestQueryEngineInfoAndNodeClasses(t *testing.T) {
// CREATE V2 ClIENT
// CREATE V2 CLIENT
client, err := clients.NewDDMV2Client()
th.AssertNoErr(t, err)

Expand All @@ -25,28 +25,45 @@ func TestQueryEngineInfoAndNodeClasses(t *testing.T) {
}

func TestDDMInstancesV2Scaling(t *testing.T) {
//CREATE V1 CLIENT
ddmv1client, err := clients.NewDDMV1Client()
// CREATE V1 CLIENT
ddmV1Client, err := clients.NewDDMV1Client()
th.AssertNoErr(t, err)
// CREATE V2 ClIENT
ddmv2client, err := clients.NewDDMV2Client()
// CREATE V2 CLIENT
ddmV2Client, err := clients.NewDDMV2Client()
th.AssertNoErr(t, err)

// CREATE DDM INSTANCE
ddmInstance := ddmhelper.CreateDDMInstance(t, ddmv1client)
ddmInstance := ddmhelper.CreateDDMInstance(t, ddmV1Client)
t.Cleanup(func() {
ddmhelper.DeleteDDMInstance(t, ddmv1client, ddmInstance.Id)
ddmhelper.DeleteDDMInstance(t, ddmV1Client, ddmInstance.Id)
})

// SCALE OUT
engineId := "367b68a3-b48b-3d8a-b3a1-4c463a75a4b4"
clientV2, err := clients.NewDDMV2Client()
th.AssertNoErr(t, err)
engines, err := instances.QueryEngineInfo(clientV2, instances.QueryEngineOpts{})
th.AssertNoErr(t, err)
if len(engines) != 0 {
engineId = engines[0].ID
}

flavorId := "941b5a6d-3485-329e-902c-ffd49d352f16"
classes, err := instances.QueryNodeClasses(clientV2, instances.QueryNodeClassesOpts{
EngineId: engineId,
})
th.AssertNoErr(t, err)
if len(classes.ComputeFlavorGroups) != 0 {
flavorId = classes.ComputeFlavorGroups[0].ComputeFlavors[0].ID
}
t.Logf("Scaling out DDM Instance %s", ddmInstance.Id)
scaleOutOpts := instances.ScaleOutOpts{
FlavorId: "941b5a6d-3485-329e-902c-ffd49d352f16",
FlavorId: flavorId,
NodeNumber: 1,
}
_, err = instances.ScaleOut(ddmv2client, ddmInstance.Id, scaleOutOpts)
_, err = instances.ScaleOut(ddmV2Client, ddmInstance.Id, scaleOutOpts)
th.AssertNoErr(t, err)
err = ddmhelper.WaitForInstanceInRunningState(ddmv1client, ddmInstance.Id)
err = ddmhelper.WaitForInstanceInRunningState(ddmV1Client, ddmInstance.Id)
th.AssertNoErr(t, err)
t.Logf("Scaled out DDM Instance %s to n+1 nodes", ddmInstance.Id)

Expand All @@ -55,9 +72,9 @@ func TestDDMInstancesV2Scaling(t *testing.T) {
scaleInOpts := instances.ScaleInOpts{
NodeNumber: 1,
}
_, err = instances.ScaleIn(ddmv2client, ddmInstance.Id, scaleInOpts)
_, err = instances.ScaleIn(ddmV2Client, ddmInstance.Id, scaleInOpts)
th.AssertNoErr(t, err)
err = ddmhelper.WaitForInstanceInRunningState(ddmv1client, ddmInstance.Id)
err = ddmhelper.WaitForInstanceInRunningState(ddmV1Client, ddmInstance.Id)
th.AssertNoErr(t, err)
t.Logf("Scaled in DDM Instance %s to n-1 nodes", ddmInstance.Id)

Expand Down
28 changes: 21 additions & 7 deletions acceptance/openstack/ddm/v3/accounts_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,25 +2,28 @@ package v3

import (
"testing"
"time"

golangsdk "github.com/opentelekomcloud/gophertelekomcloud"
"github.com/opentelekomcloud/gophertelekomcloud/acceptance/clients"
ddmhelper "github.com/opentelekomcloud/gophertelekomcloud/acceptance/openstack/ddm/v1"
ddminstancesv1 "github.com/opentelekomcloud/gophertelekomcloud/openstack/ddm/v1/instances"
"github.com/opentelekomcloud/gophertelekomcloud/openstack/ddm/v3/accounts"
th "github.com/opentelekomcloud/gophertelekomcloud/testhelper"
)

func TestDDMAccountsTestV3(t *testing.T) {
//CREATE V1 CLIENT
ddmv1client, err := clients.NewDDMV1Client()
// CREATE V1 CLIENT
ddmV1Client, err := clients.NewDDMV1Client()
th.AssertNoErr(t, err)
// CREATE V3 ClIENT
ddmv3client, err := clients.NewDDMV3Client()
// CREATE V3 CLIENT
ddmV3Client, err := clients.NewDDMV3Client()
th.AssertNoErr(t, err)

// CREATE DDM INSTANCE
ddmInstance := ddmhelper.CreateDDMInstance(t, ddmv1client)
ddmInstance := ddmhelper.CreateDDMInstance(t, ddmV1Client)
t.Cleanup(func() {
ddmhelper.DeleteDDMInstance(t, ddmv1client, ddmInstance.Id)
ddmhelper.DeleteDDMInstance(t, ddmV1Client, ddmInstance.Id)
})

// RESET DDM ACCOUNT PASSWORD
Expand All @@ -29,7 +32,18 @@ func TestDDMAccountsTestV3(t *testing.T) {
Name: "root",
Password: "acc-test-password1!",
}
_, err = accounts.ManageAdminPass(ddmv3client, ddmInstance.Id, manageAdminOpts)
_, err = accounts.ManageAdminPass(ddmV3Client, ddmInstance.Id, manageAdminOpts)
th.AssertNoErr(t, err)
err = golangsdk.WaitFor(600, func() (bool, error) {

Check failure on line 37 in acceptance/openstack/ddm/v3/accounts_test.go

View workflow job for this annotation

GitHub Actions / golangci-lint

ineffectual assignment to err (ineffassign)
instanceDetails, err := ddminstancesv1.QueryInstanceDetails(ddmV1Client, ddmInstance.Id)
if err != nil {
return false, err
}
time.Sleep(5 * time.Second)
if instanceDetails.Status == "RUNNING" {
return true, nil
}
return false, nil
})

}
Loading

0 comments on commit 88144b6

Please sign in to comment.