diff options
| author | Valerii Ponomarov <vponomar@redhat.com> | 2018-12-20 23:04:22 +0530 |
|---|---|---|
| committer | Valerii Ponomarov <vponomar@redhat.com> | 2018-12-25 20:54:32 +0530 |
| commit | 8b6107b62dacf5edc264f4f0206771d8fa07f7bf (patch) | |
| tree | 775a3755324ea3a272a65ba9eddf100a605208d1 /cns-libs | |
| parent | 418b6a6dd31e70888cfcc343922d43e4646f7184 (diff) | |
Add abstraction between deployment types and gluster commands
Now, it is possible to run glustolibs commands
on both deployment types: containerized and standalone.
It is possible using 'auto_get_gluster_endpoint' as target for
lib function in addition to the '@podcmd.GlustoPod()' decorator.
Example:
"""
from glustolibs.gluster.volume_ops import get_volume_list
from cnslibs.common import heketi_libs
from cnslibs.common import podcmd
class TestExample(heketi_libs.HeketiBaseClass):
@podcmd.GlustoPod()
def test_get_vol_list_either_on_node_or_on_pod(self):
volumes = get_volume_list('auto_get_gluster_endpoint')
"""
Also, delete all the current usages of 'deployment_type' config option,
and delete the option as unneeded anymore.
Change-Id: I281f287c432a5a9efefda588be436ee285188697
Diffstat (limited to 'cns-libs')
| -rw-r--r-- | cns-libs/cnslibs/cns/cns_baseclass.py | 1 | ||||
| -rw-r--r-- | cns-libs/cnslibs/common/heketi_libs.py | 27 | ||||
| -rw-r--r-- | cns-libs/cnslibs/common/openshift_ops.py | 95 | ||||
| -rw-r--r-- | cns-libs/cnslibs/common/podcmd.py | 25 |
4 files changed, 30 insertions, 118 deletions
diff --git a/cns-libs/cnslibs/cns/cns_baseclass.py b/cns-libs/cnslibs/cns/cns_baseclass.py index 234511aa..068c25c3 100644 --- a/cns-libs/cnslibs/cns/cns_baseclass.py +++ b/cns-libs/cnslibs/cns/cns_baseclass.py @@ -49,7 +49,6 @@ class CnsBaseClass(unittest.TestCase): cls.cns_username = g.config['cns']['setup']['cns_username'] cls.cns_password = g.config['cns']['setup']['cns_password'] cls.cns_project_name = g.config['cns']['setup']['cns_project_name'] - cls.deployment_type = g.config['cns']['deployment_type'] # Initializes heketi config variables heketi_config = g.config['cns']['heketi_config'] diff --git a/cns-libs/cnslibs/common/heketi_libs.py b/cns-libs/cnslibs/common/heketi_libs.py index c6529af4..7ac5c6a6 100644 --- a/cns-libs/cnslibs/common/heketi_libs.py +++ b/cns-libs/cnslibs/common/heketi_libs.py @@ -8,8 +8,7 @@ from cnslibs.common.exceptions import ExecutionError, ConfigError from cnslibs.common.heketi_ops import (hello_heketi, heketi_volume_delete, heketi_blockvolume_delete) -from cnslibs.common.openshift_ops import (oc_login, switch_oc_project, - get_ocp_gluster_pod_names) +from cnslibs.common import openshift_ops class HeketiBaseClass(unittest.TestCase): @@ -33,8 +32,6 @@ class HeketiBaseClass(unittest.TestCase): cls.ocp_master_nodes = g.config['ocp_servers']['master'].keys() cls.ocp_master_node = cls.ocp_master_nodes[0] - cls.deployment_type = g.config['cns']['deployment_type'] - heketi_config = g.config['cns']['heketi_config'] cls.heketi_dc_name = heketi_config['heketi_dc_name'] cls.heketi_service_name = heketi_config['heketi_service_name'] @@ -65,19 +62,15 @@ class HeketiBaseClass(unittest.TestCase): raise ConfigError("Heketi server %s is not alive" % cls.heketi_server_url) - if cls.deployment_type == "cns": - if not oc_login(cls.ocp_master_node, cls.cns_username, - cls.cns_password): - raise ExecutionError("Failed to do oc login on node %s" - % cls.ocp_master_node) - - if not switch_oc_project(cls.ocp_master_node, - cls.cns_project_name): - raise ExecutionError("Failed to switch oc project on node %s" - % cls.ocp_master_node) - - cls.gluster_pods = get_ocp_gluster_pod_names(cls.ocp_master_node) - g.pod_name = cls.gluster_pods[0] + # Switch to the storage project + if not openshift_ops.oc_login( + cls.ocp_master_node, cls.cns_username, cls.cns_password): + raise ExecutionError("Failed to do oc login on node %s" + % cls.ocp_master_node) + if not openshift_ops.switch_oc_project( + cls.ocp_master_node, cls.cns_project_name): + raise ExecutionError("Failed to switch oc project on node %s" + % cls.ocp_master_node) # Have a unique string to recognize the test run for logging if 'glustotest_run_id' not in g.config: diff --git a/cns-libs/cnslibs/common/openshift_ops.py b/cns-libs/cnslibs/common/openshift_ops.py index cc84098e..d9511980 100644 --- a/cns-libs/cnslibs/common/openshift_ops.py +++ b/cns-libs/cnslibs/common/openshift_ops.py @@ -10,17 +10,12 @@ import types from glusto.core import Glusto as g from glustolibs.gluster import volume_ops -from glustolibs.gluster.brick_libs import ( - are_bricks_online, - get_all_bricks, - get_online_bricks_list) import mock import yaml from cnslibs.common import command from cnslibs.common import exceptions from cnslibs.common import openshift_version -from cnslibs.common import podcmd from cnslibs.common import utils from cnslibs.common import waiter from cnslibs.common.heketi_ops import ( @@ -1235,96 +1230,6 @@ def get_vol_names_from_pv(hostname, pv_name): return vol_dict -@podcmd.GlustoPod() -def verify_brick_count_gluster_vol(hostname, brick_count, - gluster_vol): - ''' - Verify brick count for gluster volume - Args: - hostname (str): hostname on which we want - to check brick count - brick_count (int): integer value to verify - gluster_vol (str): gluster vol name - Returns: - bool: True, if successful - otherwise raise Exception - ''' - gluster_pod = get_ocp_gluster_pod_names(hostname)[1] - p = podcmd.Pod(hostname, gluster_pod) - out = get_online_bricks_list(p, gluster_vol) - if brick_count == len(out): - g.log.info("successfully verified brick count %s " - "for vol %s" % (brick_count, gluster_vol)) - return True - err_msg = ("verification of brick count %s for vol %s" - "failed, count found %s" % ( - brick_count, gluster_vol, len(out))) - raise AssertionError(err_msg) - - -@podcmd.GlustoPod() -def verify_brick_status_online_gluster_vol(hostname, - gluster_vol): - ''' - Verify if all the bricks are online for the - gluster volume - Args: - hostname (str): hostname on which we want - to check brick status - gluster_vol (str): gluster vol name - Returns: - bool: True, if successful - otherwise raise Exception - ''' - gluster_pod = get_ocp_gluster_pod_names(hostname)[1] - p = podcmd.Pod(hostname, gluster_pod) - brick_list = get_all_bricks(p, gluster_vol) - if brick_list is None: - error_msg = ("failed to get brick list for vol" - " %s" % gluster_vol) - g.log.error(error_msg) - raise exceptions.ExecutionError(error_msg) - out = are_bricks_online(p, gluster_vol, brick_list) - if out: - g.log.info("verification of brick status as online" - " for gluster vol %s successful" - % gluster_vol) - return True - error_msg = ("verification of brick status as online" - " for gluster vol %s failed" % gluster_vol) - - g.log.error(error_msg) - raise exceptions.ExecutionError(error_msg) - - -def verify_gluster_vol_for_pvc(hostname, pvc_name): - ''' - Verify gluster volume has been created for - the corresponding PVC - Also checks if all the bricks of that gluster - volume are online - Args: - hostname (str): hostname on which we want - to find gluster vol - pvc_name (str): pvc_name for which we - want to find corresponding - gluster vol - Returns: - bool: True if successful - otherwise raise Exception - ''' - verify_pvc_status_is_bound(hostname, pvc_name) - pv_name = get_pv_name_from_pvc(hostname, pvc_name) - vol_dict = get_vol_names_from_pv(hostname, pv_name) - gluster_vol = vol_dict["gluster_vol"] - verify_brick_status_online_gluster_vol(hostname, - gluster_vol) - - g.log.info("verification of gluster vol %s for pvc %s is" - "successful" % (gluster_vol, pvc_name)) - return True - - def get_events(hostname, obj_name=None, obj_namespace=None, obj_type=None, event_reason=None, event_type=None): diff --git a/cns-libs/cnslibs/common/podcmd.py b/cns-libs/cnslibs/common/podcmd.py index 0613c206..2673461b 100644 --- a/cns-libs/cnslibs/common/podcmd.py +++ b/cns-libs/cnslibs/common/podcmd.py @@ -51,6 +51,8 @@ import types from glusto.core import Glusto as g +from cnslibs.common import openshift_ops + # Define a namedtuple that allows us to address pods instead of just # hosts, Pod = namedtuple('Pod', 'node podname') @@ -61,11 +63,15 @@ def run(target, command, log_level=None, orig_run=g.run): Wraps glusto's run function. Args: - target (str|Pod): If target is a anything other than a Pod - object the command will be run directly on the target - (hostname or IP). If target is a Pod object it will run - on the named pod, going through the node named in the - Pod object. + target (str|Pod): If target is str object and + it equals to 'auto_get_gluster_endpoint', then + Gluster endpoint gets autocalculated to be any of + Gluster PODs or nodes depending on the deployment type of + a Gluster cluster. + If it is str object with other value, then it is considered to be + an endpoint for command. + If 'target' is of the 'Pod' type, + then command will run on the specified POD. command (str|list): Command to run. log_level (str|None): log level to be passed on to glusto's run method @@ -78,6 +84,15 @@ def run(target, command, log_level=None, orig_run=g.run): # NOTE: orig_run captures the glusto run method at function # definition time in order to capture the method before # any additional monkeypatching by other code + + if target == 'auto_get_gluster_endpoint': + ocp_client_node = list(g.config['ocp_servers']['client'].keys())[0] + gluster_pods = openshift_ops.get_ocp_gluster_pod_names(ocp_client_node) + if gluster_pods: + target = Pod(ocp_client_node, gluster_pods[0]) + else: + target = list(g.config.get("gluster_servers", {}).keys())[0] + if isinstance(target, Pod): prefix = ['oc', 'rsh', target.podname] if isinstance(command, types.StringTypes): |
