def test_get_ignored_files(git, repo_path): with contextmanagers.chdir(repo_path): with open('.gitignore', 'w') as f: f.write('a\n') assert not os.system('mkdir a && touch a/1.txt a/2.txt') assert set(git.get_ignored_files()) == set( [os.path.join(repo_path, 'a/1.txt'), os.path.join(repo_path, 'a/2.txt')])
def create(stack): """Create a new Deis cluster. """ deisctl = path_utils.executable_path('deisctl') subprocess.check_call(['ssh-add', path_utils.ssh_path('deis')]) with contextmanagers.chdir(os.path.join(get_project_path(), 'deis')): subprocess.check_call(['make', 'discovery-url']) click.echo('Provisioning machines.') with contextmanagers.chdir('contrib/aws'): subprocess.check_call(['./provision-aws-cluster.sh', stack]) ec2 = boto3.resource('ec2') instances = ec2.instances.filter(Filters=[ { 'Name': 'instance-state-name', 'Values': ['running'], }, { 'Name': 'tag:aws:cloudformation:stack-name', 'Values': [stack], }, ]).limit(1) ip = None for i in instances: ip = i.public_ip_address assert ip is not None click.echo('Machines provisioned. An IP address is {}.'.format(ip)) env = {'DEISCTL_TUNNEL': ip} env.update(os.environ) click.echo('Installing Deis.') subprocess.check_call([ deisctl, 'config', 'platform', 'set', 'sshPrivateKey=' + path_utils.ssh_path('deis') ], env=env) subprocess.check_call([ deisctl, 'config', 'platform', 'set', 'domain=' + settings.DOMAIN_NAME ], env=env) subprocess.check_call([deisctl, 'refresh-units'], env=env) subprocess.check_call([deisctl, 'install', 'platform'], env=env) subprocess.check_call([deisctl, 'start', 'platform'], env=env)
def test_clone_project(): path = default_project_path() assert not os.path.exists(path) with contextmanagers.temp_dir() as temp_dir: with contextmanagers.chdir(temp_dir): assert not os.system('git init') assert not os.system('touch a && git add . && git commit -m a') with mock.patch('deploy.settings.PROJECT_REMOTE', new=temp_dir): clone_project() assert os.path.exists(path) assert os.path.exists(os.path.join(path, 'a'))
def secret(ctx, commands): """Executes git commands in the secret directory. This literally forwards all the arguments to git. tigerhost-deploy secret push origin master becomes: git push origin master in the secret directory. """ with contextmanagers.chdir(secret_dir.secret_dir_path()): ret = subprocess.call(['git'] + list(commands)) ctx.exit(code=ret)
def _install_deis(): script = requests.get(settings.DEIS_INSTALL_URL).text with contextmanagers.chdir(private_dir.private_dir_path( settings.APP_NAME)): subprocess.check_call(['bash', '-c', script, 'install.sh', '1.12.3']) os.chmod(path_utils.executable_path('deis'), stat.S_IRWXU)
def temp_path(): with contextmanagers.temp_dir() as temp: with contextmanagers.chdir(temp): yield temp
def fake_git_remote(): with temp_dir() as temp: with chdir(temp): assert not os.system('git init') assert not os.system('touch a && git add . && git commit -m a') yield temp
def test_path_is_ignored(git, repo_path): with contextmanagers.chdir(repo_path): with open('.gitignore', 'w') as f: f.write('a\n') assert git.path_is_ignored('a') assert not git.path_is_ignored('b')
def robotdir(tmpdir): with tmpdir.as_cwd(): shutil.copytree(ROBOTEXAMPLE, 'robotexample') with chdir('robotexample'): yield None
def test_chdir(temp_dir): current = os.getcwd() with contextmanagers.chdir(temp_dir): assert os.path.realpath(os.getcwd()) == os.path.realpath(temp_dir) assert os.getcwd() == current