Merge lp:~cjohnston/uci-engine/sshuttle-env-check into lp:uci-engine

Proposed by Chris Johnston
Status: Merged
Approved by: Celso Providelo
Approved revision: 574
Merged at revision: 579
Proposed branch: lp:~cjohnston/uci-engine/sshuttle-env-check
Merge into: lp:uci-engine
Diff against target: 232 lines (+130/-17)
4 files modified
juju-deployer/deploy.py (+35/-13)
juju-deployer/test_deploy.py (+49/-2)
juju-deployer/test_run.py (+40/-1)
tests/run.py (+6/-1)
To merge this branch: bzr merge lp:~cjohnston/uci-engine/sshuttle-env-check
Reviewer Review Type Date Requested Status
Celso Providelo (community) Approve
PS Jenkins bot (community) continuous-integration Approve
Evan (community) Needs Fixing
Review via email: mp+222988@code.launchpad.net

Commit message

Determine deployment env in order to determine if sshuttle is needed

To post a comment you must log in.
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :

PASSED: Continuous integration, rev:572
http://s-jenkins.ubuntu-ci:8080/job/uci-engine-ci/849/
Executed test runs:

Click here to trigger a rebuild:
http://s-jenkins.ubuntu-ci:8080/job/uci-engine-ci/849/rebuild

review: Approve (continuous-integration)
Revision history for this message
Celso Providelo (cprov) wrote :

Looks pretty good!

Although, can't we use yaml.dumps() to write the testing juju files ? I think it would make tests much clear than the text blob.

review: Needs Information
Revision history for this message
Chris Johnston (cjohnston) wrote :

Updated.

573. By Chris Johnston

Update tests per review

Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :

PASSED: Continuous integration, rev:573
http://s-jenkins.ubuntu-ci:8080/job/uci-engine-ci/855/
Executed test runs:

Click here to trigger a rebuild:
http://s-jenkins.ubuntu-ci:8080/job/uci-engine-ci/855/rebuild

review: Approve (continuous-integration)
Revision history for this message
Evan (ev) wrote :

Just need a small fix to one of the tests, but it's otherwise good.

review: Needs Fixing
574. By Chris Johnston

Fix test concerns from ev

Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :

PASSED: Continuous integration, rev:574
http://s-jenkins.ubuntu-ci:8080/job/uci-engine-ci/862/
Executed test runs:

Click here to trigger a rebuild:
http://s-jenkins.ubuntu-ci:8080/job/uci-engine-ci/862/rebuild

review: Approve (continuous-integration)
Revision history for this message
Celso Providelo (cprov) wrote :

LGTM!

Land it and re-enable integration tests in the new machine, if anything else is needed we can iterate in new MPs.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'juju-deployer/deploy.py'
2--- juju-deployer/deploy.py 2014-06-11 10:42:39 +0000
3+++ juju-deployer/deploy.py 2014-06-13 13:41:35 +0000
4@@ -134,23 +134,45 @@
5 raise
6
7
8+def _get_juju_home():
9+ default_home = os.path.join(os.path.expanduser('~'), '.juju')
10+ return os.environ.get('JUJU_HOME') or default_home
11+
12+
13+def _get_environments_yaml():
14+ juju_home = _get_juju_home()
15+ with open(os.path.join(juju_home, 'environments.yaml')) as fp:
16+ return yaml.safe_load(fp.read())
17+
18+
19+def _get_juju_env():
20+ # Is it in the environment?
21+ juju_env = os.environ.get('JUJU_ENV')
22+ if juju_env:
23+ return juju_env
24+
25+ # Is it in the current-environment file?
26+ juju_home = _get_juju_home()
27+ current_env = os.path.join(juju_home, 'current-environment')
28+ if os.path.exists(current_env):
29+ with open(current_env) as fp:
30+ juju_env = fp.read().strip('\n')
31+ return juju_env
32+
33+ # Is it defaulted in the environments.yaml file?
34+ juju_env = _get_environments_yaml().get('default')
35+ if juju_env:
36+ return juju_env
37+
38+ log.error('No juju environment specified.')
39+ sys.exit(1)
40+
41+
42 def _get_control_bucket():
43 """Get the name of the bucket in Swift that juju uses for state
44 information."""
45
46- default_home = os.path.join(os.path.expanduser('~'), '.juju')
47- juju_home = os.environ.get('JUJU_HOME') or default_home
48-
49- with open(os.path.join(juju_home, 'environments.yaml')) as fp:
50- envs = yaml.safe_load(fp.read())
51-
52- juju_env = os.environ.get('JUJU_ENV')
53- if juju_env is None:
54- juju_env = envs.get('default')
55- if not juju_env:
56- log.error('No juju environment specified.')
57- sys.exit(1)
58-
59+ juju_env = _get_juju_env()
60 return envs['environments'][juju_env]['control-bucket']
61
62
63
64=== modified file 'juju-deployer/test_deploy.py'
65--- juju-deployer/test_deploy.py 2014-06-02 12:27:29 +0000
66+++ juju-deployer/test_deploy.py 2014-06-13 13:41:35 +0000
67@@ -15,12 +15,12 @@
68 # along with this program. If not, see <http://www.gnu.org/licenses/>.
69
70 import os
71-import sys
72 import mock
73 import tempfile
74 import shutil
75 import subprocess
76 import unittest
77+import yaml
78
79 from novaclient import exceptions
80 import swiftclient
81@@ -33,7 +33,7 @@
82
83 class TestCheckEnvironment(unittest.TestCase):
84
85- DEFAULT_ENV = {
86+ DEFAULT_ENV = {
87 'OS_USERNAME': 'os-user',
88 'OS_AUTH_URL': 'something.stack',
89 'CI_OAUTH_CONSUMER_KEY': 'key',
90@@ -156,6 +156,7 @@
91 @mock.patch('ci_utils.sourcecode.update_sourcecode')
92 def test_install_deployer(self, mocked_us):
93 fixtures.isolate_from_env(self, dict(PYTHONPATH=''))
94+
95 def local_us(*args, **kwargs):
96 os.makedirs('juju-deployer/.bzr')
97 mocked_us.side_effect = local_us
98@@ -459,5 +460,51 @@
99 dcb.assert_called_with()
100
101
102+class TestGetEnvironment(unittest.TestCase):
103+ def setUp(self):
104+ super(TestGetEnvironment, self).setUp()
105+ fixtures.set_uniq_cwd(self)
106+ fixtures.isolate_from_env(
107+ self, dict(HOME=self.uniq_dir, JUJU_HOME=None, JUJU_ENV=None))
108+ os.mkdir('.juju')
109+ self.juju_home = os.path.join(os.environ['HOME'], '.juju')
110+
111+ def test_get_juju_home(self):
112+ juju_home = '~/.juju/'
113+ os.environ['JUJU_HOME'] = juju_home
114+ self.assertEquals(juju_home, deploy._get_juju_home())
115+
116+ def test_get_juju_home_unset(self):
117+ self.assertEquals(self.juju_home, deploy._get_juju_home())
118+
119+ def test_get_juju_env_os_environ_set(self):
120+ env = 'hp'
121+ os.environ['JUJU_ENV'] = env
122+ self.assertEquals(env, deploy._get_juju_env())
123+
124+ def test_get_juju_env_current_env(self):
125+ env = 'hpcloud'
126+ with open(os.path.join(
127+ self.juju_home, 'current-environment'), 'w') as fp:
128+ fp.write(env)
129+ self.assertEquals(env, deploy._get_juju_env())
130+
131+ def test_get_juju_env_default(self):
132+ env = {
133+ 'default': 'hp',
134+ 'environments': {
135+ 'hp': {
136+ 'type': 'openstack',
137+ 'default-series': 'precise',
138+ 'use-floating-ip': False,
139+ },
140+ },
141+ }
142+ with open(os.path.join(
143+ self.juju_home, 'environments.yaml'), 'w') as f:
144+ yaml.safe_dump(env, f)
145+ self.assertEquals('hp', deploy._get_juju_env())
146+
147+
148 if __name__ == '__main__':
149 unittest.main()
150
151=== modified file 'juju-deployer/test_run.py'
152--- juju-deployer/test_run.py 2014-04-16 18:36:03 +0000
153+++ juju-deployer/test_run.py 2014-06-13 13:41:35 +0000
154@@ -31,7 +31,7 @@
155 logging.disable(logging.CRITICAL)
156
157 mydir = os.path.dirname(__file__)
158-sys.path.append(os.path.abspath(os.path.join( mydir, '..', 'tests')))
159+sys.path.append(os.path.abspath(os.path.join(mydir, '..', 'tests')))
160 import run
161
162
163@@ -142,5 +142,44 @@
164 self.assertEqual(result, ['ci-juju-gui/0'])
165
166
167+class TestFloatingIP(unittest.TestCase):
168+
169+ def setUp(self):
170+ super(TestFloatingIP, self).setUp()
171+ fixtures.set_uniq_cwd(self)
172+ fixtures.isolate_from_env(self, dict(HOME=self.uniq_dir))
173+ os.mkdir('.juju')
174+
175+ def test_with_floating_ip(self):
176+ env = {
177+ 'default': 'hp',
178+ 'environments': {
179+ 'hp': {
180+ 'type': 'openstack',
181+ 'default-series': 'precise',
182+ 'use-floating-ip': True,
183+ },
184+ },
185+ }
186+ with open('.juju/environments.yaml', 'w') as f:
187+ yaml.safe_dump(env, f)
188+ self.assertTrue(run.floating_ip_env())
189+
190+ def test_without_floating_ip(self):
191+ env = {
192+ 'default': 'hp',
193+ 'environments': {
194+ 'hp': {
195+ 'type': 'openstack',
196+ 'default-series': 'precise',
197+ 'use-floating-ip': False,
198+ },
199+ },
200+ }
201+ with open('.juju/environments.yaml', 'w') as f:
202+ yaml.safe_dump(env, f)
203+ self.assertFalse(run.floating_ip_env())
204+
205+
206 if __name__ == '__main__':
207 unittest.main()
208
209=== modified file 'tests/run.py'
210--- tests/run.py 2014-06-10 10:23:19 +0000
211+++ tests/run.py 2014-06-13 13:41:35 +0000
212@@ -171,6 +171,11 @@
213 subprocess.check_call(cmd)
214
215
216+def floating_ip_env():
217+ juju_env = deploy._get_juju_env()
218+ juju_yaml = deploy._get_environments_yaml()
219+ return juju_yaml['environments'][juju_env].get('use-floating-ip') == True
220+
221 def check_sudoers(sudoers_path=SUDOERS_FILE):
222 """Check to see if /etc/sudoers.d/sshuttle exists and is of the right
223 form."""
224@@ -234,7 +239,7 @@
225 log.error(msg)
226 sys.exit(1)
227
228- if not check_sudoers():
229+ if not floating_ip_env() and not check_sudoers():
230 msg = 'Please run:\necho "$USER %s" > %s' % (SUDOERS, SUDOERS_FILE)
231 log.error(msg)
232 sys.exit(1)

Subscribers

People subscribed via source and target branches