Skip to content

Commit

Permalink
Add marvin test for CKS clusters with different offerings per node type
Browse files Browse the repository at this point in the history
  • Loading branch information
nvazquez committed Jan 9, 2025
1 parent 7501b74 commit 397f25d
Showing 1 changed file with 76 additions and 8 deletions.
84 changes: 76 additions & 8 deletions test/integration/smoke/test_kubernetes_clusters.py
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,25 @@ def setUpClass(cls):
cls.apiclient,
cks_offering_data
)
cks_offering_data["name"] = 'CKS-Worker-Offering-' + random_gen()
cls.cks_worker_nodes_offering = ServiceOffering.create(
cls.apiclient,
cks_offering_data
)
cks_offering_data["name"] = 'CKS-Control-Offering-' + random_gen()
cls.cks_control_nodes_offering = ServiceOffering.create(
cls.apiclient,
cks_offering_data
)
cks_offering_data["name"] = 'CKS-Etcd-Offering-' + random_gen()
cls.cks_etcd_nodes_offering = ServiceOffering.create(
cls.apiclient,
cks_offering_data
)
cls._cleanup.append(cls.cks_service_offering)
cls._cleanup.append(cls.cks_worker_nodes_offering)
cls._cleanup.append(cls.cks_control_nodes_offering)
cls._cleanup.append(cls.cks_etcd_nodes_offering)
cls.domain = get_domain(cls.apiclient)
cls.account = Account.create(
cls.apiclient,
Expand Down Expand Up @@ -644,6 +662,30 @@ def test_11_test_unmanaged_cluster_lifecycle(self):
self.deleteKubernetesClusterAndVerify(cluster.id)
return

@attr(tags=["advanced", "smoke", "nicolocal"], required_hardware="true")
def test_12_test_deploy_cluster_different_offerings_per_node_type(self):
"""Test creating a CKS cluster with different offerings per node type
# Validate the following:
"""
cluster = self.getValidKubernetesCluster(worker_offering=self.cks_worker_nodes_offering,
control_offering=self.cks_control_nodes_offering)
self.assertEqual(
cluster.workerofferingid,
self.cks_worker_nodes_offering.id,
"Check Worker Nodes Offering {}, {}".format(cluster.workerofferingid, self.cks_worker_nodes_offering.id)
)
self.assertEqual(
cluster.controlofferingid,
self.cks_control_nodes_offering.id,
"Check Control Nodes Offering {}, {}".format(cluster.workerofferingid, self.cks_worker_nodes_offering.id)
)
self.assertEqual(
cluster.etcdnodes,
0,
"No Etcd Nodes expected but got {}".format(cluster.etcdnodes)
)

def addVirtualMachinesToKubernetesCluster(self, cluster_id, vm_list):
cmd = addVirtualMachinesToKubernetesCluster.addVirtualMachinesToKubernetesClusterCmd()
cmd.id = cluster_id
Expand All @@ -658,8 +700,8 @@ def removeVirtualMachinesFromKubernetesCluster(self, cluster_id, vm_list):

return self.apiclient.removeVirtualMachinesFromKubernetesCluster(cmd)


def createKubernetesCluster(self, name, version_id, size=1, control_nodes=1, cluster_type='CloudManaged'):
def createKubernetesCluster(self, name, version_id, size=1, control_nodes=1, etcd_nodes=0, cluster_type='CloudManaged',
workers_offering=None, control_offering=None, etcd_offering=None):
createKubernetesClusterCmd = createKubernetesCluster.createKubernetesClusterCmd()
createKubernetesClusterCmd.name = name
createKubernetesClusterCmd.description = name + "-description"
Expand All @@ -672,6 +714,22 @@ def createKubernetesCluster(self, name, version_id, size=1, control_nodes=1, clu
createKubernetesClusterCmd.account = self.account.name
createKubernetesClusterCmd.domainid = self.domain.id
createKubernetesClusterCmd.clustertype = cluster_type
if workers_offering:
createKubernetesClusterCmd.nodeofferings.append({
"node": "WORKER",
"offering": workers_offering.id
})
if control_offering:
createKubernetesClusterCmd.nodeofferings.append({
"node": "CONTROL",
"offering": control_offering.id
})
if etcd_nodes > 0 and etcd_offering:
createKubernetesClusterCmd.etcdnodes = etcd_nodes
createKubernetesClusterCmd.nodeofferings.append({
"node": "ETCD",
"offering": etcd_offering.id
})
if self.default_network:
createKubernetesClusterCmd.networkid = self.default_network.id
clusterResponse = self.apiclient.createKubernetesCluster(createKubernetesClusterCmd)
Expand Down Expand Up @@ -735,15 +793,18 @@ def waitForAutoscalerPodInRunningState(self, cluster_id, retries=5, interval=60)
retries = retries - 1
return False

def getValidKubernetesCluster(self, size=1, control_nodes=1, version={}):
def getValidKubernetesCluster(self, size=1, control_nodes=1, version={}, etcd_nodes=0,
worker_offering=None, control_offering=None, etcd_offering=None):
cluster = k8s_cluster

# Does a cluster already exist ?
if cluster == None or cluster.id == None:
if not version:
version = self.kubernetes_version_v2
self.debug("No existing cluster available, k8s_cluster: %s" % cluster)
return self.createNewKubernetesCluster(version, size, control_nodes)
return self.createNewKubernetesCluster(version, size, control_nodes, etcd_nodes=etcd_nodes,
worker_offering=worker_offering, control_offering=control_offering,
etcd_offering=etcd_offering)

# Is the existing cluster what is needed ?
valid = cluster.size == size and cluster.controlnodes == control_nodes
Expand All @@ -759,7 +820,9 @@ def getValidKubernetesCluster(self, size=1, control_nodes=1, version={}):
if cluster == None:
# Looks like the cluster disappeared !
self.debug("Existing cluster, k8s_cluster ID: %s not returned by list API" % cluster_id)
return self.createNewKubernetesCluster(version, size, control_nodes)
return self.createNewKubernetesCluster(version, size, control_nodes, etcd_nodes=etcd_nodes,
worker_offering=worker_offering, control_offering=control_offering,
etcd_offering=etcd_offering)

if valid:
try:
Expand All @@ -775,13 +838,18 @@ def getValidKubernetesCluster(self, size=1, control_nodes=1, version={}):
self.deleteKubernetesClusterAndVerify(cluster.id, False, True)

self.debug("No valid cluster, need to deploy a new one")
return self.createNewKubernetesCluster(version, size, control_nodes)
return self.createNewKubernetesCluster(version, size, control_nodes, etcd_nodes=etcd_nodes,
worker_offering=worker_offering, control_offering=control_offering,
etcd_offering=etcd_offering)

def createNewKubernetesCluster(self, version, size, control_nodes) :
def createNewKubernetesCluster(self, version, size, control_nodes, etcd_nodes=0,
worker_offering=None, control_offering=None, etcd_offering=None):
name = 'testcluster-' + random_gen()
self.debug("Creating for Kubernetes cluster with name %s" % name)
try:
cluster = self.createKubernetesCluster(name, version.id, size, control_nodes)
cluster = self.createKubernetesCluster(name, version.id, size, control_nodes, etcd_nodes=etcd_nodes,
workers_offering=worker_offering, control_offering=control_offering,
etcd_offering=etcd_offering)
self.verifyKubernetesCluster(cluster, name, version.id, size, control_nodes)
except Exception as ex:
cluster = self.listKubernetesCluster(cluster_name = name)
Expand Down

0 comments on commit 397f25d

Please sign in to comment.