Exemple #1
0
def get_cephblockpool_name():
    """
    Function for getting all CephBlockPool

    Returns:
         list: list of cephblockpool name
    """
    POOL = ocp.OCP(kind=constants.CEPHBLOCKPOOL,
                   namespace=defaults.ROOK_CLUSTER_NAMESPACE)
    sc_obj = POOL.get()
    sample = sc_obj['items']
    pool_list = [item.get('metadata').get('name') for item in sample]
    return pool_list
Exemple #2
0
def delete_all_cephfilesystem():
    """
    Function to Delete CephFileSysem

    Returns:
        bool: True if deletion of CephFileSystem is successful
    """
    CFS = ocp.OCP(kind=constants.CEPHFILESYSTEM,
                  namespace=defaults.ROOK_CLUSTER_NAMESPACE)
    result = CFS.get()
    cephfs_dict = result['items']
    for item in cephfs_dict:
        assert CFS.delete(resource_name=item.get('metadata').get('name'))
    return True
Exemple #3
0
def delete_cephblockpool():
    """
    Function for deleting CephBlockPool

    Returns:
        bool: True if deletion of CephBlockPool is successful
    """
    POOL = ocp.OCP(kind=constants.CEPHBLOCKPOOL,
                   namespace=defaults.ROOK_CLUSTER_NAMESPACE)
    pool_list = get_cephblockpool_name()
    for item in pool_list:
        logger.info(f"Deleting CephBlockPool with name {item}")
        assert POOL.delete(resource_name=item)
    return True
Exemple #4
0
def delete_all_storageclass():
    """"
    Function for Deleting all storageclass

    Returns:
        bool: True if deletion is successful
    """

    SC = ocp.OCP(kind=constants.STORAGECLASS,
                 namespace=defaults.ROOK_CLUSTER_NAMESPACE)
    storageclass_list = get_all_storageclass_name()
    for item in storageclass_list:
        logger.info(f"Deleting StorageClass with name {item}")
        assert SC.delete(resource_name=item)
    return True
Exemple #5
0
def get_all_storageclass_name():
    """
    Function for getting all storageclass

    Returns:
         list: list of storageclass name
    """
    SC = ocp.OCP(kind=constants.STORAGECLASS,
                 namespace=defaults.ROOK_CLUSTER_NAMESPACE)
    sc_obj = SC.get()
    sample = sc_obj['items']

    storageclass = [
        item.get('metadata').get('name') for item in sample
        if (item.get('metadata').get('name') not in constants.IGNORE_SC)
    ]
    return storageclass
Exemple #6
0
def validate_cephfilesystem(fs_name):
    """
     Verify CephFileSystem exists at ceph and k8s

     Args:
        fs_name (str): The name of the Ceph FileSystem

     Returns:
         bool: True if CephFileSystem is created at ceph and k8s side else
            will return False with valid msg i.e Failure cause
    """
    CFS = ocp.OCP(
        kind=constants.CEPHFILESYSTEM,
        namespace=defaults.ROOK_CLUSTER_NAMESPACE
    )
    ct_pod = pod.get_ceph_tools_pod()
    ceph_validate = False
    k8s_validate = False
    cmd = "ceph fs ls"
    logger.info(fs_name)
    out = ct_pod.exec_ceph_cmd(ceph_cmd=cmd)
    if out:
        out = out[0]['name']
        logger.info(out)
        if out == fs_name:
            logger.info("FileSystem got created from Ceph Side")
            ceph_validate = True
        else:
            logger.error("FileSystem was not present at Ceph Side")
            return False
    result = CFS.get(resource_name=fs_name)
    if result['metadata']['name']:
        logger.info(f"Filesystem got created from kubernetes Side")
        k8s_validate = True
    else:
        logger.error("Filesystem was not create at Kubernetes Side")
        return False
    return True if (ceph_validate and k8s_validate) else False
import logging
import ocs.defaults as defaults
import yaml

from ocs import exceptions
from ocs import ocp
from utility import utils, templating
from ocsci.enums import TestStatus

log = logging.getLogger(__name__)

PV_YAML = os.path.join("templates/ocs-deployment", "PersistentVolume.yaml")
TEMP_YAML_FILE = 'test.yaml'
VOLUME_DELETED = 'persistentvolume "{volume_name}" deleted'

OCP = ocp.OCP(kind='PersistentVolume',
              namespace=defaults.ROOK_CLUSTER_NAMESPACE)


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')

Exemple #8
0
# This is just example of test for pytest
import logging
import pytest

from ocs import ocp
from ocsci.config import ENV_DATA
from ocsci.testlib import run_this, EcosystemTest, tier1


logger = logging.getLogger(__name__)

OCP = ocp.OCP(
    kind='pods', namespace=ENV_DATA['cluster_namespace']
)

EXAMPLE_MSG = "THIS IS JUST AN EXAMPLE OF PYTEST TEST, WE WON'T RUN IT!"


@pytest.mark.skip(EXAMPLE_MSG)
@run_this
def test_not_run_me_fail_pass():
    logger.info("Hey from test which should pass")
    logger.info(
        "You can easily access data from ENV_DATA like cluster_name: %s",
        ENV_DATA['cluster_name']
    )
    assert 1 == 1, "This will not reach this message"


@pytest.mark.skip(EXAMPLE_MSG)
@tier1
import yaml

from ocsci import config
from ocs import exceptions
from ocs import ocp
from ocs.constants import TEMPLATE_PV_PVC_DIR
from ocsci.testlib import tier1, ManageTest
from utility import utils, templating

log = logging.getLogger(__name__)

PV_YAML = os.path.join(TEMPLATE_PV_PVC_DIR, "PersistentVolume.yaml")
TEMP_YAML_FILE = 'test.yaml'
VOLUME_DELETED = 'persistentvolume "{volume_name}" deleted'

OCP = ocp.OCP(kind='PersistentVolume',
              namespace=config.ENV_DATA['cluster_namespace'])


@pytest.fixture(scope='class')
def test_fixture(request):
    """
    Create disks
    """
    self = request.node.cls

    def finalizer():
        teardown(self)

    request.addfinalizer(finalizer)

import yaml
import os

from ocs import ocp
from munch import munchify
from ocs import exceptions
from ocsci.enums import TestStatus
from utility import utils, templating

log = logging.getLogger(__name__)

PV_YAML = os.path.join("templates/ocs-deployment", "cephfilesystem.yaml")
TEMP_YAML_FILE = 'test_cephfilesystem.yaml'
CEPHFS_DELETED = '"{cephfs_name}" deleted'

OCP = ocp.OCP(kind='CephFilesystem', namespace=defaults.ROOK_CLUSTER_NAMESPACE)


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

Exemple #11
0
from utility import utils, templating
from ocs import ocp
from ocsci import EcosystemTest, tier1
import logging

log = logging.getLogger(__name__)

RBD_POOL_YAML = os.path.join("templates/ocs-deployment/csi/rbd", "pool.yaml")
SC_RBD_YAML = os.path.join("templates/ocs-deployment/csi/rbd",
                           "storageclass-csi-rbd.yaml")
SECRET_RBD_YAML = os.path.join("templates/ocs-deployment/csi/rbd",
                               "secret_rbd.yaml")
PVC_RBD_YAML = os.path.join("templates/ocs-deployment/csi/rbd", "pvc-rbd.yaml")
TEMP_YAML_FILE = 'test_csi_rbd.yaml'

SC = ocp.OCP(kind='StorageClass', namespace=defaults.ROOK_CLUSTER_NAMESPACE)
POOL = ocp.OCP(kind='CephBlockPool', namespace=defaults.ROOK_CLUSTER_NAMESPACE)
SECRET = ocp.OCP(kind='Secret', namespace="default")
PVC = ocp.OCP(kind='PersistentVolumeClaim',
              namespace=defaults.ROOK_CLUSTER_NAMESPACE)


@pytest.fixture(scope='class')
def test_fixture(request):
    """
    Create disks
    """
    self = request.node.cls

    def finalizer():
        teardown(self)
Exemple #12
0
A test for creating a CephFS
"""
import logging
import pytest

from ocs import ocp, defaults, constants
from ocsci.config import ENV_DATA
from ocsci.testlib import tier1, ManageTest
from resources.ocs import OCS
from tests import helpers

log = logging.getLogger(__name__)

CEPHFS_DELETED = '"{cephfs_name}" deleted'

POD = ocp.OCP(kind=constants.POD, namespace=ENV_DATA['cluster_namespace'])
CEPH_OBJ = None


@pytest.fixture(scope='class')
def test_fixture(request):
    """
    Create disks
    """
    self = request.node.cls

    def finalizer():
        teardown()

    request.addfinalizer(finalizer)
    setup(self)
Exemple #13
0
import logging
import pytest

from ocs import ocp, defaults, constants
from ocsci.config import ENV_DATA
from ocsci.testlib import tier1, ManageTest
from resources.ocs import OCS
from resources.pod import get_admin_key_from_ceph_tools
from resources.pvc import PVC
from tests import helpers

log = logging.getLogger(__name__)

POD = ocp.OCP(kind='Pod', namespace=ENV_DATA['cluster_namespace'])
CEPH_OBJ = None


@pytest.fixture()
def test_fixture(request):
    """
    Create disks
    """
    self = request.node.cls
    setup_fs(self)
    yield
    teardown_fs()


def setup_fs(self):
    """
    Setting up the environment for the test
"""
Util for environment check before and after test to compare and find stale
leftovers
"""
import logging
import pytest

from ocs import ocp, constants, exceptions
from ocsci.pytest_customization.marks import (deployment, destroy,
                                              ignore_leftovers)
from deepdiff import DeepDiff

log = logging.getLogger(__name__)

POD = ocp.OCP(kind=constants.POD)
SC = ocp.OCP(kind=constants.STORAGECLASS)
CEPHFILESYSTEM = ocp.OCP(kind=constants.CEPHFILESYSTEM)
CEPHBLOCKPOOL = ocp.OCP(kind=constants.CEPHBLOCKPOOL)
PV = ocp.OCP(kind=constants.PV)
PVC = ocp.OCP(kind=constants.PVC)
SECRET = ocp.OCP(kind=constants.SECRET)
NS = ocp.OCP(kind=constants.NAMESPACE)

ADDED_RESOURCE = 'iterable_item_added'
REMOVED_RESOURCE = 'iterable_item_removed'

ENV_STATUS_PRE = {}
ENV_STATUS_POST = {}

# List of marks for which we will ignore the leftover checker
MARKS_TO_IGNORE = [m.mark for m in [deployment, destroy, ignore_leftovers]]
from ocsci import config
from ocsci.testlib import deployment, EcosystemTest
import pytest
from utility import templating
from utility.aws import AWS
from utility.retry import retry
from utility.utils import run_cmd, get_openshift_installer, get_openshift_client
from ocs.parallel import parallel
from ocs import ocp, defaults, constants
from resources.ocs import OCS
from tests import helpers


log = logging.getLogger(__name__)

POD = ocp.OCP(kind=constants.POD, namespace=config.ENV_DATA['cluster_namespace'])
CFS = ocp.OCP(
    kind=constants.CEPHFILESYSTEM, namespace=config.ENV_DATA['cluster_namespace']
)
CEPH_OBJ = None


@deployment
class TestDeployment(EcosystemTest):
    def test_deployment(self):
        log.info("Running OCS basic installation")
        cluster_path = config.ENV_DATA['cluster_path']
        # Test cluster access and if exist just skip the deployment.
        if config.RUN['cli_params'].get('cluster_path') and OCP.set_kubeconfig(
            os.path.join(cluster_path, config.RUN.get('kubeconfig_location'))
        ):