示例#1
0
文件: conftest.py 项目: pyrates/usine
def connection():
    with connect(hostname=os.environ.get('USINE_TEST_HOST')):
        with sudo():
            run('useradd -N usinetest -d /srv/usine/ '
                '|| echo "usinetest exists"')
            yield
            run('userdel usinetest')
示例#2
0
def patch_client(monkeypatch):
    def call(self, cmd, **kwargs):
        return self._build_command(cmd, **kwargs)

    def open_(self, *args, **kwargs):
        pass

    def close(self, *args, **kwargs):
        pass

    monkeypatch.setattr('usine.Client.__call__', call)
    monkeypatch.setattr('usine.Client.open', open_)
    monkeypatch.setattr('usine.Client.close', close)
    with usine.connect(hostname='foo@bar'):
        yield
示例#3
0
def wrapper(hostname, configpath, source_dir):
    config.source_dir = Path(source_dir or os.environ.get('SOURCE_DIR')
                             or config.source_dir or 'src')
    with connect(hostname=hostname, configpath=configpath):
        yield
示例#4
0
    with env(FOO='bar'):
        run('echo $FOO')
    with sudo(user='******'), env(FOO='baz'):
        run('echo $FOO')


@minicli.cli
def put_file():
    with sudo(user='******'):
        put('README.md', '/tmp/foobarbaz')
        ls('/tmp/foobarbaz')
        run('cat /tmp/foobarbaz')
        put(StringIO('foobarbazéé'), '/tmp/foobarbaz')
        run('cat /tmp/foobarbaz')


@minicli.cli
def with_screen(name='usine', target='8.8.8.8'):
    with screen(name):
        run(f'ping {target}')


@minicli.cli
def python():
    run('python')


if __name__ == '__main__':
    with connect('usine'):
        minicli.run()
示例#5
0
def test_proxy_command():
    config.proxy_command = 'ssh -q usine -W 127.0.0.1:22'
    with connect(hostname='[email protected]'):
        assert 'ubuntu' in run('whoami')
示例#6
0
def wrapper(hostname, dry_run):
    with connect(hostname=hostname, dry_run=dry_run):
        yield
示例#7
0
def wrapper(hostname, configpath):
    configpath = ['remote/commons/config.yml', configpath]
    with connect(hostname=hostname, configpath=configpath):
        yield