Esempio n. 1
0
# variable telling it where to find the custom docl conf which is only
# generated after the test environment is instantiated.


def _docl_proxy(quiet=False):
    env = os.environ.copy()
    env['DOCL_HOME'] = _docl_home()
    result = sh.docl.bake(_env=env)
    if not quiet:
        result = result.bake(_err_to_out=True,
                             _out=lambda l: sys.stdout.write(l),
                             _tee=True)
    return result


_docl = proxy_tools.Proxy(_docl_proxy)
_quiet_docl = proxy_tools.Proxy(partial(_docl_proxy, quiet=True))


def _docl_home():
    from integration_tests.framework import env
    if env.instance:
        return os.path.join(env.instance.test_working_dir, 'docl')
    else:
        # When working outside of the tests framework
        return os.path.expanduser('~/.docl')


def _load_docl_config():
    with open(os.path.join(_docl_home(), 'config.yaml')) as f:
        return yaml.safe_load(f)
Esempio n. 2
0
import proxy_tools
import sh

from docl.configuration import configuration


def bake(cmd):
    return cmd.bake(_err_to_out=True,
                    _out=lambda l: sys.stdout.write(l),
                    _tee=True)


def docker_proxy(quiet=False):
    result = sh.docker.bake('-H', configuration.docker_host)
    if not quiet:
        result = bake(result)
    return result


docker = proxy_tools.Proxy(docker_proxy)
quiet_docker = proxy_tools.Proxy(functools.partial(docker_proxy, quiet=True))
ssh_keygen = sh.Command('ssh-keygen')
ssh_keyscan = sh.Command('ssh-keyscan')
cfy = bake(sh.cfy)
serve = sh.serve
gzip = sh.gzip.bake(_tty_out=False)


def ssh(ip, keypath):
    subprocess.call(['ssh', '-i', keypath, 'root@{}'.format(ip)])