Skip to content

Commit

Permalink
CSS updates (#754)
Browse files Browse the repository at this point in the history
* Adding CSS security mode, security group and flavor update functions

* Adding CSS ClusterScaleIn func

* add changeclustername, changepassword, restartcluster implementation and test code

* Adding CSS AddClusterNodes func

* adding small fixes to CSS tests and functions

* Adding adjustments for CSS cluster_update_flavor function to use flavor name

* Optimized css cluster functions and tests

* Updated CSS AddClusterNodes function

* Adding modifications based on feedback

* added wait in TestRestartClusterWorkflow

* Improvements based on suggestion from Muneeb

---------

Co-authored-by: Vineet Pruthi <[email protected]>
Co-authored-by: gerzson <[email protected]>
Co-authored-by: Vineet Pruthi <[email protected]>
Co-authored-by: anton-sidelnikov <[email protected]>
  • Loading branch information
5 people authored Dec 20, 2024
1 parent 94247b8 commit 45892d8
Show file tree
Hide file tree
Showing 17 changed files with 773 additions and 0 deletions.
25 changes: 25 additions & 0 deletions acceptance/openstack/css/v1/change_cluser_name_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package v1

import (
"testing"

"github.com/opentelekomcloud/gophertelekomcloud/acceptance/clients"
"github.com/opentelekomcloud/gophertelekomcloud/acceptance/tools"
"github.com/opentelekomcloud/gophertelekomcloud/openstack/css/v1/clusters"
th "github.com/opentelekomcloud/gophertelekomcloud/testhelper"
)

func TestChangeClusterNameWorkflow(t *testing.T) {
clusterID := clients.EnvOS.GetEnv("CSS_CLUSTER_ID")
if clusterID == "" {
t.Skip("`CSS_CLUSTER_ID` must be defined")
}
client, err := clients.NewCssV1Client()
th.AssertNoErr(t, err)

opts := clusters.ChangeClusterNameOpts{
DisplayName: tools.RandomString("changed-css-", 4),
}
err = clusters.ChangeClusterName(client, clusterID, opts)
th.AssertNoErr(t, err)
}
27 changes: 27 additions & 0 deletions acceptance/openstack/css/v1/change_password_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package v1

import (
"testing"

"github.com/opentelekomcloud/gophertelekomcloud/acceptance/clients"
"github.com/opentelekomcloud/gophertelekomcloud/acceptance/tools"
"github.com/opentelekomcloud/gophertelekomcloud/openstack/css/v1/clusters"
th "github.com/opentelekomcloud/gophertelekomcloud/testhelper"
)

func TestChangePasswordWorkflow(t *testing.T) {
clusterID := clients.EnvOS.GetEnv("CSS_CLUSTER_ID")
if clusterID == "" {
t.Skip("`CSS_CLUSTER_ID` must be defined")
}
client, err := clients.NewCssV1Client()
th.AssertNoErr(t, err)

opts := clusters.ChangePasswordOpts{

NewPassword: tools.RandomString("newpass-css-", 4),
}
err = clusters.ChangePassword(client, clusterID, opts)

th.AssertNoErr(t, err)
}
90 changes: 90 additions & 0 deletions acceptance/openstack/css/v1/cluster_add_nodes_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
package v1

import (
"testing"

"github.com/opentelekomcloud/gophertelekomcloud/acceptance/clients"
"github.com/opentelekomcloud/gophertelekomcloud/openstack/css/v1/clusters"
"github.com/opentelekomcloud/gophertelekomcloud/openstack/css/v1/flavors"
th "github.com/opentelekomcloud/gophertelekomcloud/testhelper"
)

func TestAddClusterClientNodes(t *testing.T) {
clusterID := clients.EnvOS.GetEnv("CSS_CLUSTER_ID")
if clusterID == "" {
t.Skip("`CSS_CLUSTER_ID` must be defined")
}
client, err := clients.NewCssV1Client()
th.AssertNoErr(t, err)

nodeType := "ess-client"
nodeSize := 1
volumeType := "HIGH"

cluster, err := clusters.Get(client, clusterID)
th.AssertNoErr(t, err)

for _, instance := range cluster.Instances {
if instance.Type == nodeType {
t.Skip("Cluster already contains ess-client nodes.")
}
}

Versions, err := flavors.List(client)
th.AssertNoErr(t, err)
filteredVersions := flavors.FilterVersions(Versions, flavors.FilterOpts{
Version: cluster.Datastore.Version,
Type: nodeType,
})

_, err = clusters.AddClusterNodes(client, clusterID, nodeType, clusters.AddNodesOpts{
Flavor: filteredVersions[0].Flavors[0].FlavorID,
NodeSize: nodeSize,
VolumeType: volumeType,
})
th.AssertNoErr(t, err)

timeout := 1200

th.AssertNoErr(t, clusters.WaitForCluster(client, clusterID, timeout))
}

func TestAddClusterMasterNodes(t *testing.T) {
clusterID := clients.EnvOS.GetEnv("CSS_CLUSTER_ID")
if clusterID == "" {
t.Skip("`CSS_CLUSTER_ID` must be defined")
}
client, err := clients.NewCssV1Client()
th.AssertNoErr(t, err)

nodeType := "ess-master"
nodeSize := 3
volumeType := "HIGH"

cluster, err := clusters.Get(client, clusterID)
th.AssertNoErr(t, err)

for _, instance := range cluster.Instances {
if instance.Type == nodeType {
t.Skip("Cluster already contains ess-master nodes.")
}
}

Versions, err := flavors.List(client)
th.AssertNoErr(t, err)
filteredVersions := flavors.FilterVersions(Versions, flavors.FilterOpts{
Version: cluster.Datastore.Version,
Type: nodeType,
})

_, err = clusters.AddClusterNodes(client, clusterID, nodeType, clusters.AddNodesOpts{
Flavor: filteredVersions[0].Flavors[0].FlavorID,
NodeSize: nodeSize,
VolumeType: volumeType,
})
th.AssertNoErr(t, err)

timeout := 1200

th.AssertNoErr(t, clusters.WaitForCluster(client, clusterID, timeout))
}
30 changes: 30 additions & 0 deletions acceptance/openstack/css/v1/cluster_scale_in_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package v1

import (
"testing"

"github.com/opentelekomcloud/gophertelekomcloud/acceptance/clients"
"github.com/opentelekomcloud/gophertelekomcloud/openstack/css/v1/clusters"
th "github.com/opentelekomcloud/gophertelekomcloud/testhelper"
)

func TestScaleInCluster(t *testing.T) {
clusterID := clients.EnvOS.GetEnv("CSS_CLUSTER_ID")
if clusterID == "" {
t.Skip("`CSS_CLUSTER_ID` must be defined")
}
client, err := clients.NewCssV1Client()
th.AssertNoErr(t, err)

err = clusters.ScaleInCluster(client, clusterID, []clusters.ScaleInOpts{
{
Type: "ess",
ReduceNodeNum: 1,
},
})
th.AssertNoErr(t, err)

timeout := 1200

th.AssertNoErr(t, clusters.WaitForCluster(client, clusterID, timeout))
}
113 changes: 113 additions & 0 deletions acceptance/openstack/css/v1/cluster_update_flavor_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
package v1

import (
"testing"

"github.com/opentelekomcloud/gophertelekomcloud/acceptance/clients"
"github.com/opentelekomcloud/gophertelekomcloud/openstack/css/v1/clusters"
"github.com/opentelekomcloud/gophertelekomcloud/openstack/css/v1/flavors"
th "github.com/opentelekomcloud/gophertelekomcloud/testhelper"
)

func TestUpdateClusterFlavor(t *testing.T) {
clusterID := clients.EnvOS.GetEnv("CSS_CLUSTER_ID")
if clusterID == "" {
t.Skip("`CSS_CLUSTER_ID` must be defined")
}
client, err := clients.NewCssV1Client()
th.AssertNoErr(t, err)

cluster, err := clusters.Get(client, clusterID)
th.AssertNoErr(t, err)

var (
currentFlavor string
newFlavorID string
instanceType string = "ess"
)

for _, instance := range cluster.Instances {
if instance.Type == instanceType {
currentFlavor = instance.SpecCode
break
}
}

filterOpts := flavors.FilterOpts{
Version: "7.10.2",
Type: instanceType,
}

versions, err := flavors.List(client)
th.AssertNoErr(t, err)

filteredVersions := flavors.FilterVersions(versions, filterOpts)
if filteredVersions[0].Flavors[0].Name != currentFlavor {
newFlavorID = filteredVersions[0].Flavors[0].FlavorID
} else {
newFlavorID = filteredVersions[0].Flavors[1].FlavorID
}
needCheckReplica := false
err = clusters.UpdateClusterFlavor(client, clusterID, clusters.ClusterFlavorOpts{
NeedCheckReplica: &needCheckReplica,
NewFlavorID: newFlavorID,
})
th.AssertNoErr(t, err)

th.AssertNoErr(t, clusters.WaitForCluster(client, clusterID, timeout))
}

func TestUpdateClusterNodeFlavor(t *testing.T) {
clusterID := clients.EnvOS.GetEnv("CSS_CLUSTER_ID")
if clusterID == "" {
t.Skip("`CSS_CLUSTER_ID` must be defined")
}
client, err := clients.NewCssV1Client()
th.AssertNoErr(t, err)

cluster, err := clusters.Get(client, clusterID)
th.AssertNoErr(t, err)

var (
currentFlavor string
newFlavorID string
instanceType string
)

for _, instance := range cluster.Instances {
if instance.Type == "ess-cold" || instance.Type == "ess-client" || instance.Type == "ess-master" {
currentFlavor = instance.SpecCode
instanceType = instance.Type
break
}
}

if instanceType == "" {
t.Skip("There are no client, cold or master nodes to change the flavor.")
}

filterOpts := flavors.FilterOpts{
Version: "7.10.2",
Type: instanceType,
}

versions, err := flavors.List(client)
th.AssertNoErr(t, err)

filteredVersions := flavors.FilterVersions(versions, filterOpts)
if filteredVersions[0].Flavors[0].Name != currentFlavor {
newFlavorID = filteredVersions[0].Flavors[0].FlavorID
} else {
newFlavorID = filteredVersions[0].Flavors[1].FlavorID
}

needCheckReplica := false
err = clusters.UpdateClusterFlavor(client, clusterID, clusters.ClusterFlavorOpts{
NeedCheckReplica: &needCheckReplica,
NewFlavorID: newFlavorID,
NodeType: instanceType,
})
th.AssertNoErr(t, err)

th.AssertNoErr(t, clusters.WaitForCluster(client, clusterID, timeout))
}
27 changes: 27 additions & 0 deletions acceptance/openstack/css/v1/cluster_update_sg_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package v1

import (
"testing"

"github.com/opentelekomcloud/gophertelekomcloud/acceptance/clients"
"github.com/opentelekomcloud/gophertelekomcloud/acceptance/openstack"
"github.com/opentelekomcloud/gophertelekomcloud/openstack/css/v1/clusters"
th "github.com/opentelekomcloud/gophertelekomcloud/testhelper"
)

func TestUpdateSecurityGroup(t *testing.T) {
clusterID := clients.EnvOS.GetEnv("CSS_CLUSTER_ID")
if clusterID == "" {
t.Skip("`CSS_CLUSTER_ID` must be defined")
}
sgID := openstack.DefaultSecurityGroup(t)
client, err := clients.NewCssV1Client()
th.AssertNoErr(t, err)

err = clusters.UpdateSecurityGroup(client, clusterID, clusters.SecurityGroupOpts{
SecurityGroupID: sgID,
})
th.AssertNoErr(t, err)

th.AssertNoErr(t, clusters.WaitForCluster(client, clusterID, timeout))
}
Loading

0 comments on commit 45892d8

Please sign in to comment.