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


Python SSHClient.run_comment方法代码示例

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


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

示例1: UiCoveragePlugin

# 需要导入模块: from utils.ssh import SSHClient [as 别名]
# 或者: from utils.ssh.SSHClient import run_comment [as 别名]
class UiCoveragePlugin(object):
    def __init__(self):
        self.ssh_client = SSHClient()

    # trylast so that terminalreporter's been configured before ui-coverage
    @pytest.mark.trylast
    def pytest_configure(self, config):
        # Eventually, the setup/teardown work for coverage should be handled by
        # utils.appliance.Appliance to make multi-appliance support easy
        self.reporter = config.pluginmanager.getplugin('terminalreporter')
        self.reporter.write_sep('-', 'Setting up UI coverage reporting')
        self.install_simplecov()
        self.install_coverage_hook()
        self.restart_evm()
        self.touch_all_the_things()
        check_appliance_ui(base_url())

    def pytest_unconfigure(self, config):
        self.reporter.write_sep('-', 'Waiting for coverage to finish and collecting reports')
        self.stop_touching_all_the_things()
        self.merge_reports()
        self.collect_reports()
        self.print_report()

    def install_simplecov(self):
        logger.info('Installing coverage gems on appliance')
        self.ssh_client.put_file(gemfile.strpath, rails_root.strpath)
        x, out = self.ssh_client.run_command('cd {}; bundle'.format(rails_root))
        return x == 0

    def install_coverage_hook(self):
        logger.info('Installing coverage hook on appliance')
        # Put the coverage hook in the miq lib path
        self.ssh_client.put_file(
            coverage_hook.strpath, rails_root.join('..', 'lib', coverage_hook.basename).strpath
        )
        replacements = {
            'require': r"require 'coverage_hook'",
            'config': rails_root.join('config').strpath
        }
        # grep/echo to try to add the require line only once
        # This goes in preinitializer after the miq lib path is set up,
        # which makes it so ruby can actually require the hook
        command_template = (
            'cd {config};'
            'grep -q "{require}" preinitializer.rb || echo -e "\\n{require}" >> preinitializer.rb'
        )
        x, out = self.ssh_client.run_command(command_template.format(**replacements))
        return x == 0

    def restart_evm(self, rude=True):
        logger.info('Restarting EVM to enable coverage reporting')
        # This is rude by default (issuing a kill -9 on ruby procs), since the most common use-case
        # will be to set up coverage on a freshly provisioned appliance in a jenkins run
        if rude:
            x, out = self.ssh_client.run_command('killall -9 ruby; service evmserverd start')
        else:
            x, out = self.ssh_client.run_comment('service evmserverd restart')
        return x == 0

    def touch_all_the_things(self):
        logger.info('Establishing baseline overage by requiring ALL THE THINGS')
        # send over the thing toucher
        self.ssh_client.put_file(
            thing_toucher.strpath, rails_root.join(thing_toucher.basename).strpath
        )
        # start it in an async process so we can go one testing while this takes place
        self._thing_toucher_proc = Process(target=_thing_toucher_mp_handler, args=[self.ssh_client])
        self._thing_toucher_proc.start()

    def stop_touching_all_the_things(self):
        logger.info('Waiting for baseline coverage generator to finish')
        # block while the thing toucher is still running
        self._thing_toucher_proc.join()
        return self._thing_toucher_proc.exitcode == 0

    def merge_reports(self):
        logger.info("Merging coverage reports on appliance")
        # install the merger script
        self.ssh_client.put_file(
            coverage_merger.strpath, rails_root.join(coverage_merger.basename).strpath
        )
        # don't async this one since it's happening in unconfigure
        # merge/clean up the coverage reports
        x, out = self.ssh_client.run_rails_command('coverage_merger.rb')
        return x == 0

    def collect_reports(self):
        coverage_dir = log_path.join('coverage')
        # clean out old coverage dir if it exists
        if coverage_dir.check():
            coverage_dir.remove(rec=True, ignore_errors=True)
        # Then ensure the the empty dir exists
        coverage_dir.ensure(dir=True)
        # then copy the remote coverage dir into it
        logger.info("Collecting coverage reports to {}".format(coverage_dir.strpath))
        logger.info("Report collection can take several minutes")
        self.ssh_client.get_file(
            rails_root.join('coverage').strpath,
            log_path.strpath,
#.........这里部分代码省略.........
开发者ID:jkrocil,项目名称:cfme_tests,代码行数:103,代码来源:ui_coverage.py


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