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
=== modified file 'juju-deployer/deploy.py'
--- juju-deployer/deploy.py 2014-06-11 10:42:39 +0000
+++ juju-deployer/deploy.py 2014-06-13 13:41:35 +0000
@@ -134,23 +134,45 @@
134 raise134 raise
135135
136136
137def _get_juju_home():
138 default_home = os.path.join(os.path.expanduser('~'), '.juju')
139 return os.environ.get('JUJU_HOME') or default_home
140
141
142def _get_environments_yaml():
143 juju_home = _get_juju_home()
144 with open(os.path.join(juju_home, 'environments.yaml')) as fp:
145 return yaml.safe_load(fp.read())
146
147
148def _get_juju_env():
149 # Is it in the environment?
150 juju_env = os.environ.get('JUJU_ENV')
151 if juju_env:
152 return juju_env
153
154 # Is it in the current-environment file?
155 juju_home = _get_juju_home()
156 current_env = os.path.join(juju_home, 'current-environment')
157 if os.path.exists(current_env):
158 with open(current_env) as fp:
159 juju_env = fp.read().strip('\n')
160 return juju_env
161
162 # Is it defaulted in the environments.yaml file?
163 juju_env = _get_environments_yaml().get('default')
164 if juju_env:
165 return juju_env
166
167 log.error('No juju environment specified.')
168 sys.exit(1)
169
170
137def _get_control_bucket():171def _get_control_bucket():
138 """Get the name of the bucket in Swift that juju uses for state172 """Get the name of the bucket in Swift that juju uses for state
139 information."""173 information."""
140174
141 default_home = os.path.join(os.path.expanduser('~'), '.juju')175 juju_env = _get_juju_env()
142 juju_home = os.environ.get('JUJU_HOME') or default_home
143
144 with open(os.path.join(juju_home, 'environments.yaml')) as fp:
145 envs = yaml.safe_load(fp.read())
146
147 juju_env = os.environ.get('JUJU_ENV')
148 if juju_env is None:
149 juju_env = envs.get('default')
150 if not juju_env:
151 log.error('No juju environment specified.')
152 sys.exit(1)
153
154 return envs['environments'][juju_env]['control-bucket']176 return envs['environments'][juju_env]['control-bucket']
155177
156178
157179
=== modified file 'juju-deployer/test_deploy.py'
--- juju-deployer/test_deploy.py 2014-06-02 12:27:29 +0000
+++ juju-deployer/test_deploy.py 2014-06-13 13:41:35 +0000
@@ -15,12 +15,12 @@
15# along with this program. If not, see <http://www.gnu.org/licenses/>.15# along with this program. If not, see <http://www.gnu.org/licenses/>.
1616
17import os17import os
18import sys
19import mock18import mock
20import tempfile19import tempfile
21import shutil20import shutil
22import subprocess21import subprocess
23import unittest22import unittest
23import yaml
2424
25from novaclient import exceptions25from novaclient import exceptions
26import swiftclient26import swiftclient
@@ -33,7 +33,7 @@
3333
34class TestCheckEnvironment(unittest.TestCase):34class TestCheckEnvironment(unittest.TestCase):
3535
36 DEFAULT_ENV = {36 DEFAULT_ENV = {
37 'OS_USERNAME': 'os-user',37 'OS_USERNAME': 'os-user',
38 'OS_AUTH_URL': 'something.stack',38 'OS_AUTH_URL': 'something.stack',
39 'CI_OAUTH_CONSUMER_KEY': 'key',39 'CI_OAUTH_CONSUMER_KEY': 'key',
@@ -156,6 +156,7 @@
156 @mock.patch('ci_utils.sourcecode.update_sourcecode')156 @mock.patch('ci_utils.sourcecode.update_sourcecode')
157 def test_install_deployer(self, mocked_us):157 def test_install_deployer(self, mocked_us):
158 fixtures.isolate_from_env(self, dict(PYTHONPATH=''))158 fixtures.isolate_from_env(self, dict(PYTHONPATH=''))
159
159 def local_us(*args, **kwargs):160 def local_us(*args, **kwargs):
160 os.makedirs('juju-deployer/.bzr')161 os.makedirs('juju-deployer/.bzr')
161 mocked_us.side_effect = local_us162 mocked_us.side_effect = local_us
@@ -459,5 +460,51 @@
459 dcb.assert_called_with()460 dcb.assert_called_with()
460461
461462
463class TestGetEnvironment(unittest.TestCase):
464 def setUp(self):
465 super(TestGetEnvironment, self).setUp()
466 fixtures.set_uniq_cwd(self)
467 fixtures.isolate_from_env(
468 self, dict(HOME=self.uniq_dir, JUJU_HOME=None, JUJU_ENV=None))
469 os.mkdir('.juju')
470 self.juju_home = os.path.join(os.environ['HOME'], '.juju')
471
472 def test_get_juju_home(self):
473 juju_home = '~/.juju/'
474 os.environ['JUJU_HOME'] = juju_home
475 self.assertEquals(juju_home, deploy._get_juju_home())
476
477 def test_get_juju_home_unset(self):
478 self.assertEquals(self.juju_home, deploy._get_juju_home())
479
480 def test_get_juju_env_os_environ_set(self):
481 env = 'hp'
482 os.environ['JUJU_ENV'] = env
483 self.assertEquals(env, deploy._get_juju_env())
484
485 def test_get_juju_env_current_env(self):
486 env = 'hpcloud'
487 with open(os.path.join(
488 self.juju_home, 'current-environment'), 'w') as fp:
489 fp.write(env)
490 self.assertEquals(env, deploy._get_juju_env())
491
492 def test_get_juju_env_default(self):
493 env = {
494 'default': 'hp',
495 'environments': {
496 'hp': {
497 'type': 'openstack',
498 'default-series': 'precise',
499 'use-floating-ip': False,
500 },
501 },
502 }
503 with open(os.path.join(
504 self.juju_home, 'environments.yaml'), 'w') as f:
505 yaml.safe_dump(env, f)
506 self.assertEquals('hp', deploy._get_juju_env())
507
508
462if __name__ == '__main__':509if __name__ == '__main__':
463 unittest.main()510 unittest.main()
464511
=== modified file 'juju-deployer/test_run.py'
--- juju-deployer/test_run.py 2014-04-16 18:36:03 +0000
+++ juju-deployer/test_run.py 2014-06-13 13:41:35 +0000
@@ -31,7 +31,7 @@
31logging.disable(logging.CRITICAL)31logging.disable(logging.CRITICAL)
3232
33mydir = os.path.dirname(__file__)33mydir = os.path.dirname(__file__)
34sys.path.append(os.path.abspath(os.path.join( mydir, '..', 'tests')))34sys.path.append(os.path.abspath(os.path.join(mydir, '..', 'tests')))
35import run35import run
3636
3737
@@ -142,5 +142,44 @@
142 self.assertEqual(result, ['ci-juju-gui/0'])142 self.assertEqual(result, ['ci-juju-gui/0'])
143143
144144
145class TestFloatingIP(unittest.TestCase):
146
147 def setUp(self):
148 super(TestFloatingIP, self).setUp()
149 fixtures.set_uniq_cwd(self)
150 fixtures.isolate_from_env(self, dict(HOME=self.uniq_dir))
151 os.mkdir('.juju')
152
153 def test_with_floating_ip(self):
154 env = {
155 'default': 'hp',
156 'environments': {
157 'hp': {
158 'type': 'openstack',
159 'default-series': 'precise',
160 'use-floating-ip': True,
161 },
162 },
163 }
164 with open('.juju/environments.yaml', 'w') as f:
165 yaml.safe_dump(env, f)
166 self.assertTrue(run.floating_ip_env())
167
168 def test_without_floating_ip(self):
169 env = {
170 'default': 'hp',
171 'environments': {
172 'hp': {
173 'type': 'openstack',
174 'default-series': 'precise',
175 'use-floating-ip': False,
176 },
177 },
178 }
179 with open('.juju/environments.yaml', 'w') as f:
180 yaml.safe_dump(env, f)
181 self.assertFalse(run.floating_ip_env())
182
183
145if __name__ == '__main__':184if __name__ == '__main__':
146 unittest.main()185 unittest.main()
147186
=== modified file 'tests/run.py'
--- tests/run.py 2014-06-10 10:23:19 +0000
+++ tests/run.py 2014-06-13 13:41:35 +0000
@@ -171,6 +171,11 @@
171 subprocess.check_call(cmd)171 subprocess.check_call(cmd)
172172
173173
174def floating_ip_env():
175 juju_env = deploy._get_juju_env()
176 juju_yaml = deploy._get_environments_yaml()
177 return juju_yaml['environments'][juju_env].get('use-floating-ip') == True
178
174def check_sudoers(sudoers_path=SUDOERS_FILE):179def check_sudoers(sudoers_path=SUDOERS_FILE):
175 """Check to see if /etc/sudoers.d/sshuttle exists and is of the right180 """Check to see if /etc/sudoers.d/sshuttle exists and is of the right
176 form."""181 form."""
@@ -234,7 +239,7 @@
234 log.error(msg)239 log.error(msg)
235 sys.exit(1)240 sys.exit(1)
236241
237 if not check_sudoers():242 if not floating_ip_env() and not check_sudoers():
238 msg = 'Please run:\necho "$USER %s" > %s' % (SUDOERS, SUDOERS_FILE)243 msg = 'Please run:\necho "$USER %s" > %s' % (SUDOERS, SUDOERS_FILE)
239 log.error(msg)244 log.error(msg)
240 sys.exit(1)245 sys.exit(1)

Subscribers

People subscribed via source and target branches