ocs_ci/deployment/deployment.py
def deploy_ocs(self):
        """
        Handle OCS deployment, since OCS deployment steps are common to any
        platform, implementing OCS deployment here in base class.
        """
        _templating = templating.Templating()

        ceph_cluster = ocp.OCP(
            kind='CephCluster', namespace=self.namespace
        )
        try:
            ceph_cluster.get().get('items')[0]
            logger.warning("OCS cluster already exists")
            return
        except (IndexError, CommandFailed):
            logger.info("Running OCS basic installation")

        if not self.ocs_operator_deployment:
            create_oc_resource(
                'common.yaml', self.cluster_path, _templating, config.ENV_DATA
            )
            run_cmd(
                f'oc label namespace {config.ENV_DATA["cluster_namespace"]} '
                f'"openshift.io/cluster-monitoring=true"'
            )
            run_cmd(
                f"oc policy add-role-to-user view "
                f"system:serviceaccount:openshift-monitoring:prometheus-k8s "
                f"-n {self.namespace}"
            )
            # HACK: If you would like to drop this hack, make sure that you
            # also updated docs and write appropriate unit/integration tests
            # for config processing.
            if config.ENV_DATA.get('monitoring_enabled') in (
                "true", "True", True
            ):
                # RBAC rules for monitoring, based on documentation change in
                # rook:
                # https://github.com/rook/rook/commit/1b6fe840f6ae7372a9675ba727ecc65326708aa8
                # HACK: This should be dropped when OCS is managed by OLM
                apply_oc_resource(
                    'rbac.yaml',
                    self.cluster_path,
                    _templating,
                    config.ENV_DATA,
                    template_dir="monitoring"
                )
            # Increased to 15 seconds as 10 is not enough
            # TODO: do the sampler function and check if resource exist
            wait_time = 15
            logger.info(f"Waiting {wait_time} seconds...")
            time.sleep(wait_time)
            create_oc_resource(
                'operator-openshift.yaml', self.cluster_path,
                _templating, config.ENV_DATA
            )
            logger.info(f"Waiting {wait_time} seconds...")
            time.sleep(wait_time)
            run_cmd(
                f"oc wait --for condition=ready pod "
                f"-l app=rook-ceph-operator "
                f"-n {self.namespace} "
                f"--timeout=120s"
            )
            run_cmd(
                f"oc wait --for condition=ready pod "
                f"-l app=rook-discover "
                f"-n {self.namespace} "
                f"--timeout=120s"
            )
            create_oc_resource(
                'cluster.yaml', self.cluster_path, _templating, config.ENV_DATA
            )
        else:
            self.deploy_ocs_via_operator()

        pod = ocp.OCP(
            kind=constants.POD, namespace=self.namespace
        )
        cfs = ocp.OCP(
            kind=constants.CEPHFILESYSTEM,
            namespace=self.namespace
        )
        # Check for Ceph pods
        assert pod.wait_for_resource(
            condition='Running', selector='app=rook-ceph-mon',
            resource_count=3, timeout=600
        )
        assert pod.wait_for_resource(
            condition='Running', selector='app=rook-ceph-mgr',
            timeout=600
        )
        assert pod.wait_for_resource(
            condition='Running', selector='app=rook-ceph-osd',
            resource_count=3, timeout=600
        )

        if not self.ocs_operator_deployment:
            # Creatig toolbox pod
            create_oc_resource(
                'toolbox.yaml', self.cluster_path, _templating,
                config.ENV_DATA,
            )
        assert pod.wait_for_resource(
            condition=constants.STATUS_RUNNING,
            selector='app=rook-ceph-tools', resource_count=1, timeout=600
        )

        if not self.ocs_operator_deployment:
            logger.info(f"Waiting {wait_time} seconds...")
            time.sleep(wait_time)
            # HACK: This should be dropped (including service-monitor.yaml and
            # prometheus-rules.yaml files) when OCS is managed by OLM
            if config.ENV_DATA.get('monitoring_enabled') not in (
                "true", "True", True
            ):
                # HACK: skip creation of rook-ceph-mgr service monitor when
                # monitoring is enabled (if this were not skipped, the step
                # would fail because rook would create the service monitor at
                # this point already)
                create_oc_resource(
                    "service-monitor.yaml", self.cluster_path, _templating,
                    config.ENV_DATA
                )
                # HACK: skip creation of prometheus-rules, rook-ceph is
                # concerned with it's setup now, based on clarification from
                # Umanga Chapagain
                create_oc_resource(
                    "prometheus-rules.yaml", self.cluster_path, _templating,
                    config.ENV_DATA
                )
            logger.info(f"Waiting {wait_time} seconds...")
            time.sleep(wait_time)

            # Create MDS pods for CephFileSystem
            fs_data = templating.load_yaml(constants.CEPHFILESYSTEM_YAML)
            fs_data['metadata']['namespace'] = self.namespace

            ceph_obj = OCS(**fs_data)
            ceph_obj.create()
            assert pod.wait_for_resource(
                condition=constants.STATUS_RUNNING, selector='app=rook-ceph-mds',
                resource_count=2, timeout=600
            )

        # Check for CephFilesystem creation in ocp
        cfs_data = cfs.get()
        cfs_name = cfs_data['items'][0]['metadata']['name']

        if helpers.validate_cephfilesystem(cfs_name):
            logger.info(f"MDS deployment is successful!")
            defaults.CEPHFILESYSTEM_NAME = cfs_name
        else:
            logger.error(
                f"MDS deployment Failed! Please check logs!"
            )

        # Verify health of ceph cluster
        # TODO: move destroy cluster logic to new CLI usage pattern?
        logger.info("Done creating rook resources, waiting for HEALTH_OK")
        assert ceph_health_check(
            namespace=self.namespace
        )
        # patch gp2/thin storage class as 'non-default'
        self.patch_default_sc_to_non_default()

        Handle OCS deployment, since OCS deployment steps are common to any
        platform, implementing OCS deployment here in base class.
        
Handle OCS deployment, since OCS deployment steps are common to any
platform, implementing OCS deployment here in base class.
Handle OCS deployment since OCS deployment steps are common to any platform implementing OCS deployment here in base class .
def deploy_ocs(self):
        _templating = templating.Templating()
        ceph_cluster = ocp.OCP(
            kind='CephCluster', namespace=self.namespace
        )
        try:
            ceph_cluster.get().get('items')[0]
            logger.warning("OCS cluster already exists")
            return
        except (IndexError, CommandFailed):
            logger.info("Running OCS basic installation")
        if not self.ocs_operator_deployment:
            create_oc_resource(
                'common.yaml', self.cluster_path, _templating, config.ENV_DATA
            )
            run_cmd(
                f'oc label namespace {config.ENV_DATA["cluster_namespace"]} '
                f'"openshift.io/cluster-monitoring=true"'
            )
            run_cmd(
                f"oc policy add-role-to-user view "
                f"system:serviceaccount:openshift-monitoring:prometheus-k8s "
                f"-n {self.namespace}"
            )
            if config.ENV_DATA.get('monitoring_enabled') in (
                "true", "True", True
            ):
                apply_oc_resource(
                    'rbac.yaml',
                    self.cluster_path,
                    _templating,
                    config.ENV_DATA,
                    template_dir="monitoring"
                )
            wait_time = 15
            logger.info(f"Waiting {wait_time} seconds...")
            time.sleep(wait_time)
            create_oc_resource(
                'operator-openshift.yaml', self.cluster_path,
                _templating, config.ENV_DATA
            )
            logger.info(f"Waiting {wait_time} seconds...")
            time.sleep(wait_time)
            run_cmd(
                f"oc wait --for condition=ready pod "
                f"-l app=rook-ceph-operator "
                f"-n {self.namespace} "
                f"--timeout=120s"
            )
            run_cmd(
                f"oc wait --for condition=ready pod "
                f"-l app=rook-discover "
                f"-n {self.namespace} "
                f"--timeout=120s"
            )
            create_oc_resource(
                'cluster.yaml', self.cluster_path, _templating, config.ENV_DATA
            )
        else:
            self.deploy_ocs_via_operator()
        pod = ocp.OCP(
            kind=constants.POD, namespace=self.namespace
        )
        cfs = ocp.OCP(
            kind=constants.CEPHFILESYSTEM,
            namespace=self.namespace
        )
        assert pod.wait_for_resource(
            condition='Running', selector='app=rook-ceph-mon',
            resource_count=3, timeout=600
        )
        assert pod.wait_for_resource(
            condition='Running', selector='app=rook-ceph-mgr',
            timeout=600
        )
        assert pod.wait_for_resource(
            condition='Running', selector='app=rook-ceph-osd',
            resource_count=3, timeout=600
        )
        if not self.ocs_operator_deployment:
            create_oc_resource(
                'toolbox.yaml', self.cluster_path, _templating,
                config.ENV_DATA,
            )
        assert pod.wait_for_resource(
            condition=constants.STATUS_RUNNING,
            selector='app=rook-ceph-tools', resource_count=1, timeout=600
        )
        if not self.ocs_operator_deployment:
            logger.info(f"Waiting {wait_time} seconds...")
            time.sleep(wait_time)
            if config.ENV_DATA.get('monitoring_enabled') not in (
                "true", "True", True
            ):
                create_oc_resource(
                    "service-monitor.yaml", self.cluster_path, _templating,
                    config.ENV_DATA
                )
                create_oc_resource(
                    "prometheus-rules.yaml", self.cluster_path, _templating,
                    config.ENV_DATA
                )
            logger.info(f"Waiting {wait_time} seconds...")
            time.sleep(wait_time)
            fs_data = templating.load_yaml(constants.CEPHFILESYSTEM_YAML)
            fs_data['metadata']['namespace'] = self.namespace
            ceph_obj = OCS(**fs_data)
            ceph_obj.create()
            assert pod.wait_for_resource(
                condition=constants.STATUS_RUNNING, selector='app=rook-ceph-mds',
                resource_count=2, timeout=600
            )
        cfs_data = cfs.get()
        cfs_name = cfs_data['items'][0]['metadata']['name']
        if helpers.validate_cephfilesystem(cfs_name):
            logger.info(f"MDS deployment is successful!")
            defaults.CEPHFILESYSTEM_NAME = cfs_name
        else:
            logger.error(
                f"MDS deployment Failed! Please check logs!"
            )
        logger.info("Done creating rook resources, waiting for HEALTH_OK")
        assert ceph_health_check(
            namespace=self.namespace
        )
        self.patch_default_sc_to_non_default()
def deploy_ocs ( self ) : _templating = templating . Templating ( ) ceph_cluster = ocp . OCP ( kind = 'CephCluster' , namespace = self . namespace ) try : ceph_cluster . get ( ) . get ( 'items' ) [ 0 ] logger . warning ( "OCS cluster already exists" ) return except ( IndexError , CommandFailed ) : logger . info ( "Running OCS basic installation" ) if not self . ocs_operator_deployment : create_oc_resource ( 'common.yaml' , self . cluster_path , _templating , config . ENV_DATA ) run_cmd ( f'oc label namespace {config.ENV_DATA["cluster_namespace"]} ' f'"openshift.io/cluster-monitoring=true"' ) run_cmd ( f"oc policy add-role-to-user view " f"system:serviceaccount:openshift-monitoring:prometheus-k8s " f"-n {self.namespace}" ) if config . ENV_DATA . get ( 'monitoring_enabled' ) in ( "true" , "True" , True ) : apply_oc_resource ( 'rbac.yaml' , self . cluster_path , _templating , config . ENV_DATA , template_dir = "monitoring" ) wait_time = 15 logger . info ( f"Waiting {wait_time} seconds..." ) time . sleep ( wait_time ) create_oc_resource ( 'operator-openshift.yaml' , self . cluster_path , _templating , config . ENV_DATA ) logger . info ( f"Waiting {wait_time} seconds..." ) time . sleep ( wait_time ) run_cmd ( f"oc wait --for condition=ready pod " f"-l app=rook-ceph-operator " f"-n {self.namespace} " f"--timeout=120s" ) run_cmd ( f"oc wait --for condition=ready pod " f"-l app=rook-discover " f"-n {self.namespace} " f"--timeout=120s" ) create_oc_resource ( 'cluster.yaml' , self . cluster_path , _templating , config . ENV_DATA ) else : self . deploy_ocs_via_operator ( ) pod = ocp . OCP ( kind = constants . POD , namespace = self . namespace ) cfs = ocp . OCP ( kind = constants . CEPHFILESYSTEM , namespace = self . namespace ) assert pod . wait_for_resource ( condition = 'Running' , selector = 'app=rook-ceph-mon' , resource_count = 3 , timeout = 600 ) assert pod . wait_for_resource ( condition = 'Running' , selector = 'app=rook-ceph-mgr' , timeout = 600 ) assert pod . wait_for_resource ( condition = 'Running' , selector = 'app=rook-ceph-osd' , resource_count = 3 , timeout = 600 ) if not self . ocs_operator_deployment : create_oc_resource ( 'toolbox.yaml' , self . cluster_path , _templating , config . ENV_DATA , ) assert pod . wait_for_resource ( condition = constants . STATUS_RUNNING , selector = 'app=rook-ceph-tools' , resource_count = 1 , timeout = 600 ) if not self . ocs_operator_deployment : logger . info ( f"Waiting {wait_time} seconds..." ) time . sleep ( wait_time ) if config . ENV_DATA . get ( 'monitoring_enabled' ) not in ( "true" , "True" , True ) : create_oc_resource ( "service-monitor.yaml" , self . cluster_path , _templating , config . ENV_DATA ) create_oc_resource ( "prometheus-rules.yaml" , self . cluster_path , _templating , config . ENV_DATA ) logger . info ( f"Waiting {wait_time} seconds..." ) time . sleep ( wait_time ) fs_data = templating . load_yaml ( constants . CEPHFILESYSTEM_YAML ) fs_data [ 'metadata' ] [ 'namespace' ] = self . namespace ceph_obj = OCS ( ** fs_data ) ceph_obj . create ( ) assert pod . wait_for_resource ( condition = constants . STATUS_RUNNING , selector = 'app=rook-ceph-mds' , resource_count = 2 , timeout = 600 ) cfs_data = cfs . get ( ) cfs_name = cfs_data [ 'items' ] [ 0 ] [ 'metadata' ] [ 'name' ] if helpers . validate_cephfilesystem ( cfs_name ) : logger . info ( f"MDS deployment is successful!" ) defaults . CEPHFILESYSTEM_NAME = cfs_name else : logger . error ( f"MDS deployment Failed! Please check logs!" ) logger . info ( "Done creating rook resources, waiting for HEALTH_OK" ) assert ceph_health_check ( namespace = self . namespace ) self . patch_default_sc_to_non_default ( )
Handle OCS deployment, since OCS deployment steps are common to any
platform, implementing OCS deployment here in base class.
Handle OCS deployment since OCS deployment steps are common to any platform implementing OCS deployment here in base class .
"""
        Handle OCS deployment, since OCS deployment steps are common to any
        platform, implementing OCS deployment here in base class.
        """ # HACK: If you would like to drop this hack, make sure that you # also updated docs and write appropriate unit/integration tests # for config processing. # RBAC rules for monitoring, based on documentation change in # rook: # https://github.com/rook/rook/commit/1b6fe840f6ae7372a9675ba727ecc65326708aa8 # HACK: This should be dropped when OCS is managed by OLM # Increased to 15 seconds as 10 is not enough # TODO: do the sampler function and check if resource exist # Check for Ceph pods # Creatig toolbox pod # HACK: This should be dropped (including service-monitor.yaml and # prometheus-rules.yaml files) when OCS is managed by OLM # HACK: skip creation of rook-ceph-mgr service monitor when # monitoring is enabled (if this were not skipped, the step # would fail because rook would create the service monitor at # this point already) # HACK: skip creation of prometheus-rules, rook-ceph is # concerned with it's setup now, based on clarification from # Umanga Chapagain # Create MDS pods for CephFileSystem # Check for CephFilesystem creation in ocp # Verify health of ceph cluster # TODO: move destroy cluster logic to new CLI usage pattern? # patch gp2/thin storage class as 'non-default'
self