def create_secret(self, secret_name_prefix="autotests-secret-"): secret_name = oc_create_secret(self.ocp_client[0], secret_name_prefix=secret_name_prefix, namespace=(self.sc.get( 'secretnamespace', self.sc.get('restsecretnamespace', 'default'))), data_key=self.heketi_cli_key, secret_type=self.sc.get( 'provisioner', 'kubernetes.io/glusterfs')) self.addCleanup(oc_delete, self.ocp_client[0], 'secret', secret_name) return secret_name
def test_storage_class_mandatory_params_glusterfile(self): """Validate storage-class creation with mandatory parameters""" # create secret self.secret_name = oc_create_secret( self.node, namespace=self.sc.get('secretnamespace', 'default'), data_key=self.heketi_cli_key, secret_type=self.sc.get('provisioner', 'kubernetes.io/glusterfs')) self.addCleanup( oc_delete, self.node, 'secret', self.secret_name) # create storage class with mandatory parameters only sc_name = oc_create_sc( self.node, provisioner='kubernetes.io/glusterfs', resturl=self.sc['resturl'], restuser=self.sc['restuser'], secretnamespace=self.sc['secretnamespace'], secretname=self.secret_name ) self.addCleanup(oc_delete, self.node, 'sc', sc_name) # Create PVC pvc_name = self.create_and_wait_for_pvc(sc_name=sc_name) # Create DC with POD and attached PVC to it. dc_name = oc_create_app_dc_with_io(self.node, pvc_name) self.addCleanup(oc_delete, self.node, 'dc', dc_name) self.addCleanup(scale_dc_pod_amount_and_wait, self.node, dc_name, 0) pod_name = get_pod_name_from_dc(self.node, dc_name) wait_for_pod_be_ready(self.node, pod_name) # Make sure we are able to work with files on the mounted volume filepath = "/mnt/file_for_testing_sc.log" cmd = "dd if=/dev/urandom of=%s bs=1K count=100" % filepath ret, out, err = oc_rsh(self.node, pod_name, cmd) self.assertEqual( ret, 0, "Failed to execute command %s on %s" % (cmd, self.node)) cmd = "ls -lrt %s" % filepath ret, out, err = oc_rsh(self.node, pod_name, cmd) self.assertEqual( ret, 0, "Failed to execute command %s on %s" % (cmd, self.node)) cmd = "rm -rf %s" % filepath ret, out, err = oc_rsh(self.node, pod_name, cmd) self.assertEqual( ret, 0, "Failed to execute command %s on %s" % (cmd, self.node))
def deploy_resouces(self): """Deploys required resources storage class, pvc and user app with continous I/O runnig Returns: sc_name (str): deployed storage class name pvc_name (str): deployed persistent volume claim name dc_name (str): deployed deployment config name secretname (str): created secret file name """ secretname = oc_create_secret(self.oc_node, namespace=self.restsecretnamespace, data_key=self.heketi_cli_key, secret_type=self.provisioner) self.addCleanup(oc_delete, self.oc_node, 'secret', secretname) sc_name = oc_create_sc(self.oc_node, sc_name_prefix=self.prefix, provisioner=self.provisioner, resturl=self.resturl, restuser=self.restuser, restsecretnamespace=self.restsecretnamespace, restsecretname=secretname, volumenameprefix=self.prefix) self.addCleanup(oc_delete, self.oc_node, "sc", sc_name) pvc_name = oc_create_pvc(self.oc_node, sc_name, pvc_name_prefix=self.prefix, pvc_size=self.pvcsize) self.addCleanup(wait_for_resource_absence, self.oc_node, "pvc", pvc_name, timeout=120, interval=5) self.addCleanup(oc_delete, self.oc_node, "pvc", pvc_name) dc_name = oc_create_app_dc_with_io(self.oc_node, pvc_name, dc_name_prefix=self.prefix) self.addCleanup(oc_delete, self.oc_node, "dc", dc_name) self.addCleanup(scale_dc_pod_amount_and_wait, self.oc_node, dc_name, 0) return sc_name, pvc_name, dc_name, secretname
def create_sc_with_parameter(self, vol_type, success=False, parameter={}): """creates storage class, pvc and validates event Args: vol_type (str): storage type either gluster file or block success (bool): if True check for successfull else failure for pvc creation event parameter (dict): dictionary with storage class parameters """ if vol_type == "glusterfile": sc = self.storage_classes.get( 'storage_class1', self.storage_classes.get('file_storage_class')) # Create secret file for usage in storage class self.secret_name = oc_create_secret( self.ocp_master_node[0], namespace=sc.get('secretnamespace', 'default'), data_key=self.heketi_cli_key, secret_type=sc.get('provisioner', 'kubernetes.io/glusterfs')) self.addCleanup(oc_delete, self.ocp_master_node[0], 'secret', self.secret_name) sc_parameter = { "secretnamespace": sc['secretnamespace'], "secretname": self.secret_name, "volumetype": "replicate:3" } elif vol_type == "glusterblock": sc = self.storage_classes.get( 'storage_class2', self.storage_classes.get('block_storage_class')) # Create secret file for usage in storage class self.secret_name = oc_create_secret( self.ocp_master_node[0], namespace=sc.get('restsecretnamespace', 'default'), data_key=self.heketi_cli_key, secret_type=sc.get('provisioner', 'gluster.org/glusterblock')) self.addCleanup(oc_delete, self.ocp_master_node[0], 'secret', self.secret_name) sc_parameter = { "provisioner": "gluster.org/glusterblock", "restsecretnamespace": sc['restsecretnamespace'], "restsecretname": self.secret_name, "hacount": sc['hacount'] } else: err_msg = "invalid vol_type %s" % vol_type g.log.error(err_msg) raise AssertionError(err_msg) sc_parameter['resturl'] = sc['resturl'] sc_parameter['restuser'] = sc['restuser'] sc_parameter.update(parameter) # Create storage class self.sc_name = oc_create_sc(self.ocp_master_node[0], **sc_parameter) self.addCleanup(oc_delete, self.ocp_master_node[0], 'sc', self.sc_name) # Create PVC self.pvc_name = oc_create_pvc(self.ocp_client[0], self.sc_name) self.addCleanup(wait_for_resource_absence, self.ocp_master_node[0], 'pvc', self.pvc_name) self.addCleanup(oc_delete, self.ocp_master_node[0], 'pvc', self.pvc_name) # Wait for event with error event_reason = 'ProvisioningFailed' if success: event_reason = 'ProvisioningSucceeded' wait_for_events(self.ocp_master_node[0], obj_name=self.pvc_name, obj_type='PersistentVolumeClaim', event_reason=event_reason)