def test_verify_all_fields_in_sc_yaml_with_oc_describe(self, interface): """ Test function to create RBD and CephFS SC, and match with oc describe sc output """ log.info(f"Creating a {interface} storage class") self.sc_data = templating.load_yaml( getattr(constants, f"CSI_{interface}_STORAGECLASS_YAML")) self.sc_data['metadata']['name'] = ( helpers.create_unique_resource_name('test', f'csi-{interface.lower()}')) global SC_OBJ SC_OBJ = OCS(**self.sc_data) assert SC_OBJ.create() log.info( f"{interface}Storage class: {SC_OBJ.name} created successfully") log.info(self.sc_data) # Get oc describe sc output describe_out = SC_OBJ.get("sc") log.info(describe_out) # Confirm that sc yaml details matches oc describe sc output value = { k: describe_out[k] for k in set(describe_out) - set(self.sc_data) } assert len(value) == 1 and value['volumeBindingMode'] == 'Immediate', ( "OC describe sc output didn't match storage class yaml") log.info("OC describe sc output matches storage class yaml") # Delete Storage Class log.info(f"Deleting Storageclass: {SC_OBJ.name}") assert SC_OBJ.delete() log.info(f"Storage Class: {SC_OBJ.name} deleted successfully") del SC_OBJ
def reclaim_policy(self): """ Returns the reclaim policy of pvc in namespace Returns: str: Reclaim policy Reclaim or Delete """ data = dict() data['api_version'] = self.api_version data['kind'] = 'StorageClass' data['metadata'] = { 'name': self.backed_sc, 'namespace': self.namespace } sc_obj = OCS(**data) sc_obj.reload() return sc_obj.get().get('reclaimPolicy')
def test_scale_down_rgw(self, scale_down_to): """ Scale down RGW deployment and do sanity validations - Scale down the RGW deployment replicas to 1 or 0 - If scaled down to 1, check Noobaa health - Scale up the RGW replicas back to 2 - Check Noobaa health """ rgw_deployment = pod.get_deployments_having_label( constants.RGW_APP_LABEL, defaults.ROOK_CLUSTER_NAMESPACE)[0] rgw_deployment = OCS(**rgw_deployment) current_replicas = rgw_deployment.get()["spec"]["replicas"] rgw_deployment.ocp.exec_oc_cmd( f"scale --replicas={str(scale_down_to)} deployment/{rgw_deployment.name}" ) if scale_down_to > 0: self.cl_obj.wait_for_noobaa_health_ok() rgw_deployment.ocp.exec_oc_cmd( f"scale --replicas={str(current_replicas)} deployment/{rgw_deployment.name}" ) self.cl_obj.wait_for_noobaa_health_ok()
class QuayOperator(object): """ Quay operator class """ def __init__(self): """ Quay operator initializer function """ self.namespace = constants.OPENSHIFT_OPERATORS self.ocp_obj = ocp.OCP(namespace=self.namespace) self.quay_operator = None self.quay_registry = None self.quay_registry_secret = None self.quay_pod_obj = OCP(kind=constants.POD, namespace=self.namespace) self.quay_registry_name = "" self.quay_operator_csv = "" self.quay_registry_secret_name = "" self.sc_default = False self.sc_name = (constants.DEFAULT_EXTERNAL_MODE_STORAGECLASS_RBD if storagecluster_independent_check() else constants.DEFAULT_STORAGECLASS_RBD) def setup_quay_operator(self): """ Deploys Quay operator """ quay_operator_data = templating.load_yaml(file=constants.QUAY_SUB) self.quay_operator = OCS(**quay_operator_data) logger.info(f"Installing Quay operator: {self.quay_operator.name}") self.quay_operator.create() for quay_pod in TimeoutSampler(300, 10, get_pod_name_by_pattern, constants.QUAY_OPERATOR, self.namespace): if quay_pod: self.quay_pod_obj.wait_for_resource( condition=constants.STATUS_RUNNING, resource_name=quay_pod[0], sleep=30, timeout=600, ) break self.quay_operator_csv = get_csvs_start_with_prefix( csv_prefix=constants.QUAY_OPERATOR, namespace=self.namespace, )[0]["metadata"]["name"] def create_quay_registry(self): """ Creates Quay registry """ if not helpers.get_default_storage_class(): patch = ' \'{"metadata": {"annotations":{"storageclass.kubernetes.io/is-default-class":"true"}}}\' ' run_cmd(f"oc patch storageclass {self.sc_name} " f"-p {patch} " f"--request-timeout=120s") self.sc_default = True self.quay_registry_secret_name = create_unique_resource_name( "quay-user", "secret") logger.info( f"Creating Quay registry config for super-user access: {self.quay_registry_secret_name}" ) self.quay_registry_secret = self.ocp_obj.exec_oc_cmd( command= f"create secret generic --from-file config.yaml={constants.QUAY_SUPER_USER} " f"{self.quay_registry_secret_name}") quay_registry_data = templating.load_yaml(file=constants.QUAY_REGISTRY) self.quay_registry_name = quay_registry_data["metadata"]["name"] quay_registry_data["spec"][ "configBundleSecret"] = self.quay_registry_secret_name self.quay_registry = OCS(**quay_registry_data) logger.info(f"Creating Quay registry: {self.quay_registry.name}") self.quay_registry.create() logger.info("Waiting for 15s for registry to get initialized") sleep(15) self.wait_for_quay_endpoint() def wait_for_quay_endpoint(self): """ Waits for quay registry endpoint """ logger.info("Waiting for quay registry endpoint to be up") sample = TimeoutSampler( timeout=300, sleep=15, func=self.check_quay_registry_endpoint, ) if not sample.wait_for_func_status(result=True): logger.error("Quay registry endpoint did not get created.") raise TimeoutExpiredError else: logger.info("Quay registry endpoint is up") def check_quay_registry_endpoint(self): """ Checks if quay registry endpoint is up Returns: bool: True if quay endpoint is up else False """ return (True if self.quay_registry.get().get("status").get("registryEndpoint") else False) def get_quay_endpoint(self): """ Returns quay endpoint """ return self.quay_registry.get().get("status").get("registryEndpoint") def teardown(self): """ Quay operator teardown """ if self.sc_default: patch = ' \'{"metadata": {"annotations":{"storageclass.kubernetes.io/is-default-class":"false"}}}\' ' run_cmd(f"oc patch storageclass {self.sc_name} " f"-p {patch} " f"--request-timeout=120s") if self.quay_registry_secret: self.ocp_obj.exec_oc_cmd( f"delete secret {self.quay_registry_secret_name}") if self.quay_registry: self.quay_registry.delete() if self.quay_operator: self.quay_operator.delete() if self.quay_operator_csv: self.ocp_obj.exec_oc_cmd( f"delete {constants.CLUSTER_SERVICE_VERSION} " f"{self.quay_operator_csv}")