Skip to content

Commit 503f282

Browse files
committed
Create fake home dir per test user, refs #214.
1 parent 9d75494 commit 503f282

2 files changed

Lines changed: 42 additions & 9 deletions

File tree

client/deis.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1757,8 +1757,11 @@ def providers_discover(self, args): # noqa
17571757
running_vms = ""
17581758
# Vagrant internally names a running VM using the folder name in which the Vagrantfile
17591759
# resides, eg; my-deis-code-folder_default_1383326629
1760-
deis_codebase_folder = self._session.git_root().split('/')[-1]
1761-
if deis_codebase_folder in running_vms:
1760+
try:
1761+
deis_codebase_folder = self._session.git_root().split('/')[-1]
1762+
except EnvironmentError:
1763+
deis_codebase_folder = None
1764+
if deis_codebase_folder and deis_codebase_folder in running_vms:
17621765
print("Discovered locally running Deis Controller VM")
17631766
# In order for the Controller to be able to boot Vagrant VMs it needs to run commands
17641767
# on the host machine. It does this via an SSH server. In order to access that server

client/tests/utils.py

Lines changed: 37 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,9 @@
88
import random
99
import re
1010
import shutil
11+
import stat
1112
import tempfile
13+
from urllib2 import urlparse
1214
from uuid import uuid4
1315

1416
import pexpect
@@ -23,7 +25,8 @@
2325
print 'Error: env var DEIS_SERVER must point to a Deis controller URL.'
2426
DEIS_TEST_FLAVOR = os.environ.get('DEIS_TEST_FLAVOR', 'ec2-us-west-2')
2527
REPOSITORIES = {
26-
# 'Clojure': 'https://github.com/opdemand/example-clojure-ring.git',
28+
# 'example-clojure-ring': ('Clojure', 'https://github.com/opdemand/example-clojure-ring.git'),
29+
'Clojure': 'https://github.com/opdemand/example-clojure-ring.git',
2730
# 'Python': 'https://github.com/opdemand/example-python-django.git',
2831
'Python': 'https://github.com/opdemand/example-python-flask.git',
2932
'Java': 'https://github.com/opdemand/example-java-jetty.git',
@@ -55,11 +58,40 @@ def register():
5558
"""Register a new Deis user from the command line."""
5659
username = "autotester-{}".format(uuid4().hex[:4])
5760
password = 'password'
58-
ssh_path = os.path.expanduser('~/.ssh')
59-
child = pexpect.spawn("ssh-keygen -f /{}/{} -t rsa -N '' -C {}".format(
60-
ssh_path, username, username))
61+
home = os.path.join('/tmp', username)
62+
os.environ['HOME'] = home
63+
os.mkdir(home)
64+
os.chdir(home)
65+
# generate an SSH key
66+
ssh_path = os.path.expandvars('$HOME/.ssh')
67+
os.mkdir(ssh_path, 0700)
68+
key_path = "/{}/{}".format(ssh_path, username)
69+
child = pexpect.spawn("ssh-keygen -f {} -t rsa -N '' -C {}".format(
70+
key_path, username))
6171
child.expect("Your public key has been saved")
6272
child.expect(pexpect.EOF)
73+
# write out ~/.ssh/config
74+
ssh_config_path = os.path.expandvars("$HOME/.ssh/config")
75+
with open(ssh_config_path, 'w') as ssh_config:
76+
# get hostname from DEIS_SERVER
77+
server = urlparse.urlparse(DEIS_SERVER).netloc
78+
ssh_config.write("""\
79+
Hostname {}
80+
IdentitiesOnly yes
81+
IdentityFile {}/.ssh/{}
82+
""".format(server, home, username))
83+
# make a GIT_SSH script to enforce use of our key
84+
git_ssh_path = os.path.expandvars("$HOME/git_ssh.sh")
85+
with open(git_ssh_path, 'w') as git_ssh:
86+
git_ssh.write("""\
87+
#!/bin/sh
88+
89+
SSH_ORIGINAL_COMMAND="ssh $@"
90+
ssh -F {} "$@"
91+
""".format(ssh_config_path))
92+
os.chmod(git_ssh_path, stat.S_IRUSR | stat.S_IRGRP | stat.S_IROTH
93+
| stat.S_IXUSR | stat.S_IXGRP | stat.S_IXOTH)
94+
os.environ['GIT_SSH'] = git_ssh_path
6395
child = pexpect.spawn("{} register {}".format(DEIS, DEIS_SERVER))
6496
child.expect('username: ')
6597
child.sendline(username)
@@ -71,9 +103,7 @@ def register():
71103
child.sendline('autotest@opdemand.com')
72104
child.expect('Which would you like to use with Deis')
73105
for index, key in re.findall('(\d)\) ([ \S]+)', child.before):
74-
# TODO: can't use our generated key--gitosis error!
75-
# if username in key:
76-
if 'id_rsa' in key:
106+
if username in key:
77107
child.sendline(index)
78108
break
79109
opt = child.expect(['Import EC2 credentials\? \(y/n\) :',

0 commit comments

Comments
 (0)