当前位置: 首页>>代码示例>>Python>>正文


Python Glusto.run方法代码示例

本文整理汇总了Python中glusto.core.Glusto.run方法的典型用法代码示例。如果您正苦于以下问题:Python Glusto.run方法的具体用法?Python Glusto.run怎么用?Python Glusto.run使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在glusto.core.Glusto的用法示例。


在下文中一共展示了Glusto.run方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: cmd_run

# 需要导入模块: from glusto.core import Glusto [as 别名]
# 或者: from glusto.core.Glusto import run [as 别名]
def cmd_run(cmd, hostname, raise_on_error=True):
    """Glusto's command runner wrapper.

    Args:
        cmd (str): Shell command to run on the specified hostname.
        hostname (str): hostname where Glusto should run specified command.
        raise_on_error (bool): defines whether we should raise exception
                               in case command execution failed.
    Returns:
        str: Stripped shell command's stdout value if not None.
    """
    ret, out, err = g.run(hostname, cmd, "root")
    if ("no ssh connection" in err.lower() or
            "tls handshake timeout" in err.lower()):
        g.ssh_close_connection(hostname)
        ret, out, err = g.run(hostname, cmd, "root")
    msg = ("Failed to execute command '%s' on '%s' node. Got non-zero "
           "return code '%s'. Err: %s" % (cmd, hostname, ret, err))
    if int(ret) != 0:
        g.log.error(msg)
    if raise_on_error:
        assert int(ret) == 0, msg

    out = out.strip() if out else out

    return out
开发者ID:gluster,项目名称:glusterfs-containers-tests,代码行数:28,代码来源:command.py

示例2: test_transfer

# 需要导入模块: from glusto.core import Glusto [as 别名]
# 或者: from glusto.core.Glusto import run [as 别名]
    def test_transfer(self):
        """Testing SSH transfer() method"""
        print "Running: %s - %s" % (self.id(), self.shortDescription())

        remote_file = '/etc/hosts'
        remote_file_copy = '/tmp/transfer_test_file'
        host1 = self.hosts[0]
        host2 = self.hosts[1]

        # remove remote test file copy(ignore error if not exist)
        g.run(host2, 'rm -f %s' % remote_file_copy)

        # md5sum remote file
        command = 'md5sum %s| awk \'{print $1}\'' % remote_file
        rcode,  rout, _ = g.run(self.primary_host, command)
        if rcode == 0:
            md5sum_orig = rout.strip()

        # transfer it
        g.transfer(host1, remote_file, host2, remote_file_copy)

        # md5sum remote file copy
        command = 'md5sum %s | awk \'{print $1}\'' % remote_file_copy
        rcode, rout, _ = g.run(host2, command)
        if rcode == 0:
            md5sum_copy = rout.strip()

        # compare the md5sums
        self.assertEqual(md5sum_orig, md5sum_copy, 'md5sums do not match')
开发者ID:mbukatov,项目名称:glusto,代码行数:31,代码来源:test_glusto_ssh.py

示例3: test_upload

# 需要导入模块: from glusto.core import Glusto [as 别名]
# 或者: from glusto.core.Glusto import run [as 别名]
 def test_upload(self):
     """Testing SSH upload() method"""
     print "Running: %s - %s" % (self.id(), self.shortDescription())
     g.run(self.primary_host, 'rm -f /tmp/upload_test_file')
     rcode, rout, _ = g.run_local('md5sum /etc/hosts | awk \'{print $1}\'')
     if rcode == 0:
         md5sum = rout.strip()
     g.upload(self.primary_host,
              '/etc/hosts', '/tmp/upload_test_file')
     command = 'md5sum /tmp/upload_test_file | awk \'{print $1}\''
     rcode,  rout, _ = g.run(self.primary_host, command)
     if rcode == 0:
         md5sum_up = rout.strip()
     self.assertEqual(md5sum, md5sum_up, '')
开发者ID:mbukatov,项目名称:glusto,代码行数:16,代码来源:test_glusto_ssh.py

示例4: validate_multipath_pod

# 需要导入模块: from glusto.core import Glusto [as 别名]
# 或者: from glusto.core.Glusto import run [as 别名]
def validate_multipath_pod(hostname, podname, hacount, mpath=""):
    '''
     This function validates multipath for given app-pod
     Args:
         hostname (str): ocp master node name
         podname (str): app-pod name for which we need to validate
                        multipath. ex : nginx1
         hacount (int): multipath count or HA count. ex: 3
     Returns:
         bool: True if successful,
               otherwise False
    '''
    cmd = "oc get pods -o wide | grep %s | awk '{print $7}'" % podname
    ret, out, err = g.run(hostname, cmd, "root")
    if ret != 0 or out == "":
        g.log.error("failed to exectute cmd %s on %s, err %s"
                    % (cmd, hostname, out))
        return False
    pod_nodename = out.strip()
    active_node_count = 1
    enable_node_count = hacount - 1
    cmd = "multipath -ll %s | grep 'status=active' | wc -l" % mpath
    ret, out, err = g.run(pod_nodename, cmd, "root")
    if ret != 0 or out == "":
        g.log.error("failed to exectute cmd %s on %s, err %s"
                    % (cmd, pod_nodename, out))
        return False
    active_count = int(out.strip())
    if active_node_count != active_count:
        g.log.error("active node count on %s for %s is %s and not 1"
                    % (pod_nodename, podname, active_count))
        return False
    cmd = "multipath -ll %s | grep 'status=enabled' | wc -l" % mpath
    ret, out, err = g.run(pod_nodename, cmd, "root")
    if ret != 0 or out == "":
        g.log.error("failed to exectute cmd %s on %s, err %s"
                    % (cmd, pod_nodename, out))
        return False
    enable_count = int(out.strip())
    if enable_node_count != enable_count:
        g.log.error("passive node count on %s for %s is %s "
                    "and not %s" % (
                        pod_nodename, podname, enable_count,
                        enable_node_count))
        return False

    g.log.info("validation of multipath for %s is successfull"
               % podname)
    return True
开发者ID:vponomaryov,项目名称:glusterfs-containers-tests,代码行数:51,代码来源:openshift_storage_libs.py

示例5: setUpClass

# 需要导入模块: from glusto.core import Glusto [as 别名]
# 或者: from glusto.core.Glusto import run [as 别名]
    def setUpClass(cls):
        """Initialize all the variables necessary for test cases."""
        super(BaseClass, cls).setUpClass()

        # Initializes OCP config variables
        cls.ocp_servers_info = g.config['ocp_servers']
        cls.ocp_master_node = list(g.config['ocp_servers']['master'].keys())
        cls.ocp_master_node_info = g.config['ocp_servers']['master']
        cls.ocp_client = list(g.config['ocp_servers']['client'].keys())
        cls.ocp_client_info = g.config['ocp_servers']['client']
        cls.ocp_nodes = list(g.config['ocp_servers']['nodes'].keys())
        cls.ocp_nodes_info = g.config['ocp_servers']['nodes']

        # Initializes storage project config variables
        openshift_config = g.config.get("cns", g.config.get("openshift"))
        cls.storage_project_name = openshift_config.get(
            'storage_project_name',
            openshift_config.get('setup', {}).get('cns_project_name'))

        # Initializes heketi config variables
        heketi_config = openshift_config['heketi_config']
        cls.heketi_dc_name = heketi_config['heketi_dc_name']
        cls.heketi_service_name = heketi_config['heketi_service_name']
        cls.heketi_client_node = heketi_config['heketi_client_node']
        cls.heketi_server_url = heketi_config['heketi_server_url']
        cls.heketi_cli_user = heketi_config['heketi_cli_user']
        cls.heketi_cli_key = heketi_config['heketi_cli_key']

        cls.gluster_servers = list(g.config['gluster_servers'].keys())
        cls.gluster_servers_info = g.config['gluster_servers']

        cls.storage_classes = openshift_config['dynamic_provisioning'][
            'storage_classes']
        cls.sc = cls.storage_classes.get(
            'storage_class1', cls.storage_classes.get('file_storage_class'))
        cmd = "echo -n %s | base64" % cls.heketi_cli_key
        ret, out, err = g.run(cls.ocp_master_node[0], cmd, "root")
        if ret != 0:
            raise ExecutionError("failed to execute cmd %s on %s out: %s "
                                 "err: %s" % (
                                     cmd, cls.ocp_master_node[0], out, err))
        cls.secret_data_key = out.strip()

        # Checks if heketi server is alive
        if not hello_heketi(cls.heketi_client_node, cls.heketi_server_url):
            raise ConfigError("Heketi server %s is not alive"
                              % cls.heketi_server_url)

        # Switch to the storage project
        if not switch_oc_project(
                cls.ocp_master_node[0], cls.storage_project_name):
            raise ExecutionError("Failed to switch oc project on node %s"
                                 % cls.ocp_master_node[0])

        if 'glustotest_run_id' not in g.config:
            g.config['glustotest_run_id'] = (
                datetime.datetime.now().strftime('%H_%M_%d_%m_%Y'))
        cls.glustotest_run_id = g.config['glustotest_run_id']
        msg = "Setupclass: %s : %s" % (cls.__name__, cls.glustotest_run_id)
        g.log.info(msg)
开发者ID:gluster,项目名称:glusterfs-containers-tests,代码行数:62,代码来源:baseclass.py

示例6: test_return_code

# 需要导入模块: from glusto.core import Glusto [as 别名]
# 或者: from glusto.core.Glusto import run [as 别名]
 def test_return_code(self):
     """Testing the return code"""
     print "Running: %s - %s" % (self.id(), self.shortDescription())
     rcode, rout, rerr = g.run(self.masternode, "cat /etc/fstab")
     self.assertEqual(rcode, 0)
     self.assertTrue(rout)
     self.assertFalse(rerr)
开发者ID:loadtheaccumulator,项目名称:glusto,代码行数:9,代码来源:test_glusto_pytest.py

示例7: test_stderr

# 需要导入模块: from glusto.core import Glusto [as 别名]
# 或者: from glusto.core.Glusto import run [as 别名]
 def test_stderr(self):
     """Testing output to stderr"""
     print "Running: %s - %s" % (self.id(), self.shortDescription())
     rcode, rout, rerr = g.run(self.masternode, "uname -a >&2")
     self.assertEqual(rcode, 0)
     self.assertFalse(rout)
     self.assertTrue(rerr)
开发者ID:loadtheaccumulator,项目名称:glusto,代码行数:9,代码来源:test_glusto_pytest.py

示例8: test_download

# 需要导入模块: from glusto.core import Glusto [as 别名]
# 或者: from glusto.core.Glusto import run [as 别名]
    def test_download(self):
        """Testing SSH download() method"""
        print "Running: %s - %s" % (self.id(), self.shortDescription())

        remote_file = '/etc/hosts'
        local_file = '/tmp/download_test_file'

        # remove local test file (ignore error if not exist)
        g.run_local('rm -f %s' % local_file)

        # md5sum remote file
        command = 'md5sum %s| awk \'{print $1}\'' % remote_file
        rcode,  rout, _ = g.run(self.primary_host, command)
        if rcode == 0:
            md5sum_up = rout.strip()

        # download it
        g.download(self.primary_host,
                   '/etc/hosts', '/tmp/download_test_file')

        # md5sum local copy
        command = 'md5sum %s | awk \'{print $1}\'' % local_file
        rcode, rout, _ = g.run_local(command)
        if rcode == 0:
            md5sum_down = rout.strip()

        # compare the md5sums
        self.assertEqual(md5sum_down, md5sum_up, 'md5sums do not match')
开发者ID:mbukatov,项目名称:glusto,代码行数:30,代码来源:test_glusto_ssh.py

示例9: test_run

# 需要导入模块: from glusto.core import Glusto [as 别名]
# 或者: from glusto.core.Glusto import run [as 别名]
 def test_run(self):
     """Testing SSH run() method"""
     print "Running: %s - %s" % (self.id(), self.shortDescription())
     rcode, rout, rerr = g.run(self.primary_host,
                               'echo -n %s' % self.test_string)
     self.assertEqual(rcode, 0)
     self.assertEqual(rout, self.test_string)
     print rout
     self.assertEqual(rerr, '')
开发者ID:mbukatov,项目名称:glusto,代码行数:11,代码来源:test_glusto_ssh.py

示例10: test_stdout

# 需要导入模块: from glusto.core import Glusto [as 别名]
# 或者: from glusto.core.Glusto import run [as 别名]
 def test_stdout(self):
     """Testing output to stdout"""
     print "Running: %s - %s" % (self.id(), self.shortDescription())
     # add a cleanup method to run after tearDown()
     self.addCleanup(self.cleanup_remote_commands)
     for node in g.config["nodes"]:
         rcode, rout, rerr = g.run(node, "ls -ld /etc")
     self.assertEqual(rcode, 0)
     self.assertTrue(rout)
     self.assertFalse(rerr)
开发者ID:loadtheaccumulator,项目名称:glusto,代码行数:12,代码来源:test_glusto_pytest.py

示例11: _node_reboot

# 需要导入模块: from glusto.core import Glusto [as 别名]
# 或者: from glusto.core.Glusto import run [as 别名]
    def _node_reboot(self):
        storage_hostname = (g.config["gluster_servers"]
                            [self.gluster_servers[0]]["storage"])

        cmd = "sleep 3; /sbin/shutdown -r now 'Reboot triggered by Glusto'"
        ret, out, err = g.run(storage_hostname, cmd)

        self.addCleanup(self._wait_for_gluster_pod_to_be_ready)

        if ret != 255:
            err_msg = "failed to reboot host %s error: %s" % (
                storage_hostname, err)
            g.log.error(err_msg)
            raise AssertionError(err_msg)

        try:
            g.ssh_close_connection(storage_hostname)
        except Exception as e:
            g.log.error("failed to close connection with host %s"
                        " with error: %s" % (storage_hostname, e))
            raise

        # added sleep as node will restart after 3 sec
        time.sleep(3)

        for w in Waiter(timeout=600, interval=10):
            try:
                if g.rpyc_get_connection(storage_hostname, user="root"):
                    g.rpyc_close_connection(storage_hostname, user="root")
                    break
            except Exception as err:
                g.log.info("exception while getting connection: '%s'" % err)

        if w.expired:
            error_msg = ("exceeded timeout 600 sec, node '%s' is "
                         "not reachable" % storage_hostname)
            g.log.error(error_msg)
            raise ExecutionError(error_msg)

        # wait for the gluster pod to be in 'Running' state
        self._wait_for_gluster_pod_to_be_ready()

        # glusterd and gluster-blockd service should be up and running
        service_names = ("glusterd", "gluster-blockd", "tcmu-runner")
        for gluster_pod in self.gluster_pod_list:
            for service in service_names:
                g.log.info("gluster_pod - '%s' : gluster_service '%s'" % (
                    gluster_pod, service))
                check_service_status_on_pod(
                    self.oc_node, gluster_pod, service, "running"
                )
开发者ID:gluster,项目名称:glusterfs-containers-tests,代码行数:53,代码来源:test_node_restart.py

示例12: test_stress_stderr

# 需要导入模块: from glusto.core import Glusto [as 别名]
# 或者: from glusto.core.Glusto import run [as 别名]
 def test_stress_stderr(self):
     """Send load of text output to stderr"""
     command = '''ls -Rail /etc > /tmp/railetc
         for i in $(seq 1 1000)
         do
             cat /tmp/railetc >&2
         done
         echo "Complete" >&2
         '''
     g.disable_log_levels('INFO')
     rcode, rout, rerr = g.run(self.primary_host, command)
     g.reset_log_levels()
     self.assertEqual(rcode, 0, 'stressing stderr failed')
     self.assertEqual(rout, '', 'sdtout has content.')
     self.assertNotEqual(rerr, '', 'stderr has no content.')
开发者ID:mbukatov,项目名称:glusto,代码行数:17,代码来源:test_glusto_ssh.py

示例13: run

# 需要导入模块: from glusto.core import Glusto [as 别名]
# 或者: from glusto.core.Glusto import run [as 别名]
def run(target, command, user=None, log_level=None, orig_run=g.run):
    """Function that runs a command on a host or in a pod via a host.
    Wraps glusto's run function.

    Args:
        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.
        user (str|None): user to be passed on to glusto's run method
        log_level (str|None): log level to be passed on to glusto's run method
        orig_run (function): The default implementation of the
            run method. Will be used when target is not a pod.

    Returns:
        A tuple of the command's return code, stdout, and stderr.
    """
    # 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, six.string_types):
            cmd = ' '.join(prefix + [command])
        else:
            cmd = prefix + command

        # unpack the tuple to make sure our return value exactly matches
        # our docstring
        return g.run(target.node, cmd, user=user, log_level=log_level)
    else:
        return orig_run(target, command, user=user, log_level=log_level)
开发者ID:gluster,项目名称:glusterfs-containers-tests,代码行数:49,代码来源:podcmd.py

示例14: test_glusterblock_logs_presence_verification

# 需要导入模块: from glusto.core import Glusto [as 别名]
# 或者: from glusto.core.Glusto import run [as 别名]
    def test_glusterblock_logs_presence_verification(self):
        """Validate presence of glusterblock provisioner POD and it's status"""
        gb_prov_cmd = ("oc get pods --all-namespaces "
                       "-l glusterfs=block-%s-provisioner-pod "
                       "-o=custom-columns=:.metadata.name,:.status.phase" % (
                           self.storage_project_name))
        ret, out, err = g.run(self.ocp_client[0], gb_prov_cmd, "root")

        self.assertEqual(ret, 0, "Failed to get Glusterblock provisioner POD.")
        gb_prov_name, gb_prov_status = out.split()
        self.assertEqual(gb_prov_status, 'Running')

        # Create Secret, SC and PVC
        self.create_storage_class()
        self.create_and_wait_for_pvc()

        # Get list of Gluster nodes
        g_hosts = list(g.config.get("gluster_servers", {}).keys())
        self.assertGreater(
            len(g_hosts), 0,
            "We expect, at least, one Gluster Node/POD:\n %s" % g_hosts)

        # Perform checks on Gluster nodes/PODs
        logs = ("gluster-block-configshell", "gluster-blockd")

        gluster_pods = oc_get_pods(
            self.ocp_client[0], selector="glusterfs-node=pod")
        if gluster_pods:
            cmd = "tail -n 5 /var/log/glusterfs/gluster-block/%s.log"
        else:
            cmd = "tail -n 5 /var/log/gluster-block/%s.log"
        for g_host in g_hosts:
            for log in logs:
                out = cmd_run_on_gluster_pod_or_node(
                    self.ocp_client[0], cmd % log, gluster_node=g_host)
                self.assertTrue(out, "Command '%s' output is empty." % cmd)
开发者ID:vponomaryov,项目名称:glusterfs-containers-tests,代码行数:38,代码来源:test_dynamic_provisioning_block.py

示例15: _get_openshift_version_str

# 需要导入模块: from glusto.core import Glusto [as 别名]
# 或者: from glusto.core.Glusto import run [as 别名]
def _get_openshift_version_str(hostname=None):
    """Gets OpenShift version from 'oc version' command.

    Args:
        hostname (str): Node on which the ocp command should run.
    Returns:
        str : oc version, i.e. 'v3.10.47'
    Raises: 'exceptions.ExecutionError' if failed to get version
    """
    if not hostname:
        hostname = list(g.config['ocp_servers']['client'].keys())[0]
    cmd = "oc version | grep openshift | cut -d ' ' -f 2"
    ret, out, err = g.run(hostname, cmd, "root")
    if ret != 0:
        msg = "Failed to get oc version. \n'err': %s\n 'out': %s" % (err, out)
        g.log.error(msg)
        raise AssertionError(msg)
    out = out.strip()
    if not out:
        error_msg = "Empty output from 'oc version' command: '%s'" % out
        g.log.error(error_msg)
        raise exceptions.ExecutionError(error_msg)

    return out
开发者ID:gluster,项目名称:glusterfs-containers-tests,代码行数:26,代码来源:openshift_version.py


注:本文中的glusto.core.Glusto.run方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。