Esempio n. 1
0
    def create_storageclass(
        self,
        blockPool,
        sc_name_prefix="autotests-sc",
        allow_volume_expansion=True,
        reclaim_policy="Delete",
        fstype="xfs",
        clusterNamespace=ocsci.config.ENV_DATA['cluster_namespace'],
    ):
        """
        Creates storage class using data provided

        Args:
            blockPool (str): Name of the block pool
            sc_name_prefix (str): SC name will consist of this prefix and
                                  random str.
            allow_volume_expansion (bool): Either True or False
            reclaim_policy (str): Reclaim Policy type. Either Retain,
                                  Recycle or Delete
            fstype (str): Filesystem type
            clusterNamespace (str): Namespace where rook cluster exists

        Returns:
            str: Name of the storage class created

        Example:
            create_storageclass(
                blockPool,
                sc_name_prefix="autotests-sc",
                allow_volume_expansion=True,
                reclaim_policy="Delete",
                fstype="xfs"
                clusternamespace="openshift-storage",
            )

        """
        if self.name:
            sc_name = self.name
        else:
            sc_name = f"{sc_name_prefix}-{get_random_str()}"

        sc_data = {}
        sc_data['k8s_api_version'] = defaults.STORAGE_API_VERSION
        sc_data['storageclass_name'] = sc_name
        sc_data['volume_expansion'] = allow_volume_expansion
        sc_data['reclaimPolicy'] = reclaim_policy
        sc_data['blockPool'] = blockPool
        sc_data['clusterNamespace'] = clusterNamespace
        sc_data['fstype'] = fstype

        data = generate_yaml_from_jinja2_template_with_data(
            self.template_path, **sc_data)
        self.service_sc.create(body=data)

        return sc_name
Esempio n. 2
0
def create_pv(**kwargs):
    """
    Create a new Persistent Volume
    """
    file_y = templating.generate_yaml_from_jinja2_template_with_data(
        PV_YAML, **kwargs)
    with open(TEMP_YAML_FILE, 'w') as yaml_file:
        yaml.dump(file_y, yaml_file, default_flow_style=False)
        log.info(f"Creating new Persistent Volume")
    assert OCP.create(yaml_file=TEMP_YAML_FILE)
    return OCP.wait_for_resource_status(kwargs['pv_name'], 'Available')
def create_ceph_fs(**kwargs):
    """
    Create a new Ceph File System
    """
    file_y = templating.generate_yaml_from_jinja2_template_with_data(
        PV_YAML, **kwargs)
    with open(TEMP_YAML_FILE, 'w') as yaml_file:
        yaml.dump(file_y, yaml_file, default_flow_style=False)
    log.info(f"Creating a new Ceph FileSystem")
    assert OCP.create(yaml_file=TEMP_YAML_FILE)
    return True
Esempio n. 4
0
def create_storageclass_rbd():
    """
    This Creates a default CSI StorageClass
    """
    file_y = templating.generate_yaml_from_jinja2_template_with_data(
        SC_RBD_YAML)
    with open(TEMP_YAML_FILE, 'w') as yaml_file:
        yaml.dump(file_y, yaml_file, default_flow_style=False)
    log.info(f"Creating a RBD StorageClass with default values")
    assert SC.create(yaml_file=TEMP_YAML_FILE)
    return True
Esempio n. 5
0
def create_pv(**kwargs):
    """
    Create a new Persistent Volume
    """
    from ipdb import set_trace
    set_trace()
    file_y = templating.generate_yaml_from_jinja2_template_with_data(
        PVC_YAML, **kwargs)
    with open(TEMP_YAML_FILE, 'w') as yaml_file:
        yaml.dump(file_y, yaml_file, default_flow_style=False)
        log.info(f"Creating new Persistent Volume")
    assert OCP.v1_service_list.create(yaml_file=TEMP_YAML_FILE)
Esempio n. 6
0
    def create_cephblockpool(self, cephblockpool_name, namespace, service_cbp,
                             failureDomain, replica_count):
        """
        Creates cephblock pool

        Args:
            cephblockpool_name (str): Name of cephblockpool
            namespace (str): Namespace to create cephblockpool
            service_cbp (class):  Dynamic client resource of kind cephblockpool
            failureDomain (str): The failure domain across which the
                                   replicas or chunks of data will be spread
            replica_count (int): The number of copies of the data in the pool.

        Returns:
            bool : True if cephblockpool created sucessfully

        Raises:
            Exception when error occured

        Examples:
            create_cephblockpool(
                cephblockpool_name",
                service_cbp,
                failureDomain="host",
                replica_count=3
            )

        """
        _rc = False
        template_path = os.path.join(constants.TEMPLATE_DEPLOYMENT_DIR,
                                     "cephblockpool.yaml")
        # overwrite the namespace with openshift-storage, since cephblockpool
        # is tied-up with openshift-storage
        namespace = config.ENV_DATA['cluster_namespace']

        cephblockpool_data = {}
        cephblockpool_data['cephblockpool_name'] = cephblockpool_name
        cephblockpool_data['rook_api_version'] = defaults.ROOK_API_VERSION
        cephblockpool_data['failureDomain'] = failureDomain
        cephblockpool_data['replica_count'] = replica_count

        data = generate_yaml_from_jinja2_template_with_data(
            template_path, **cephblockpool_data)
        try:
            service_cbp.create(body=data, namespace=namespace)
            _rc = True
        except Exception as err:
            logger.error("Error while creating cephblockpool %s",
                         cephblockpool_name)
            raise Exception(err)

        return _rc
Esempio n. 7
0
def create_rbd_pool(pool_name):
    """
    Create Blockpool with default values
    """
    pool_data = {}
    pool_data['pool_name'] = pool_name
    file_y = templating.generate_yaml_from_jinja2_template_with_data(
        RBD_POOL_YAML, **pool_data)
    with open(TEMP_YAML_FILE, 'w') as yaml_file:
        yaml.dump(file_y, yaml_file, default_flow_style=False)
    log.info(f"Creating a new CephBlockPool with default name")
    assert POOL.create(yaml_file=TEMP_YAML_FILE)
    return True
Esempio n. 8
0
def create_pvc(pvc_name):
    """
    This will create PVC with default value

    :return:
    """
    pvc_data = {}
    pvc_data['pvc_name'] = pvc_name
    file_y = templating.generate_yaml_from_jinja2_template_with_data(
        PVC_RBD_YAML, **pvc_data)
    with open(TEMP_YAML_FILE, 'w') as yaml_file:
        yaml.dump(file_y, yaml_file, default_flow_style=False)
    assert PVC.create(yaml_file=TEMP_YAML_FILE)
    return PVC.wait_for_resource(condition='Bound', resource_name=pvc_name)
Esempio n. 9
0
    def create_pvc(self,
                   storageclass,
                   accessmode="ReadWriteOnce",
                   pvc_name_prefix="autotests-pvc",
                   pvc_size=3):
        """
        Creates PVC using data provided

        Args:
            storageclass (str): Name of storageclass to create PVC
            accessmode (str): Access mode for PVC
            pvc_name_prefix (str): Prefix given to PVC name
            pvc_size (int): Size of PVC in Gb

        Returns:
            str: Name of the pvc created

        Examples:
            create_pvc(
                storageclass,
                accessmode="ReadWriteOnce",
                pvc_size=3
            )
            create_pvc(
                storageclass,
                accessmode="ReadWriteOnce ReadOnlyMany",
                pvc_size=5
            )

        """
        if self.name:
            pvc_name = self.name
        else:
            pvc_name = f"{pvc_name_prefix}-{get_random_str()}"
        pvc_size = f"{pvc_size}Gi"
        accessmode = accessmode.split()

        pvc_data = {}
        pvc_data['pvc_name'] = pvc_name
        pvc_data['cluster_namespace'] = self.namespace
        pvc_data['storageclass_namespace'] = storageclass
        pvc_data['storage'] = pvc_size
        pvc_data['access_mode'] = accessmode

        data = generate_yaml_from_jinja2_template_with_data(
            self.template_path, **pvc_data)
        self.service_pvc.create(body=data, namespace=self.namespace)

        return pvc_name
Esempio n. 10
0
def create_secret_rbd(admin_key):
    """
    This will create Secret file which will be used for creating StorageClass

    :return:
    """
    secret_data = {}
    secret_data['base64_encoded_admin_password'] = admin_key
    assert create_secret_rbd(**secret_data)

    file_y = templating.generate_yaml_from_jinja2_template_with_data(
        SECRET_RBD_YAML, **secret_data)
    with open(TEMP_YAML_FILE, 'w') as yaml_file:
        yaml.dump(file_y, yaml_file, default_flow_style=False)
    assert SECRET.create(yaml_file=TEMP_YAML_FILE)
    return True