Merge lp:~dpb/charm-tools/fix-test-env-1271745 into lp:charm-tools/1.2

Proposed by David Britton
Status: Merged
Merged at revision: 311
Proposed branch: lp:~dpb/charm-tools/fix-test-env-1271745
Merge into: lp:charm-tools/1.2
Diff against target: 50 lines (+22/-0)
2 files modified
charmtools/test.py (+4/-0)
tests/test_juju_test.py (+18/-0)
To merge this branch: bzr merge lp:~dpb/charm-tools/fix-test-env-1271745
Reviewer Review Type Date Requested Status
Marco Ceppi (community) Approve
Review via email: mp+202880@code.launchpad.net

Description of the change

Simple fix to import current environment into the test conductor. Without doing this, at least the following things break for me:

- I lose connection to the ssh agent
- I don't get a working path so things like "juju ssh service/0" stop working

I included a test case that breaks if my code change is not in place.

Sorry for the bug number in the branch name, it's a different bug with a similar title, ignore it. This is to fix bug #1271803

To post a comment you must log in.
Revision history for this message
Marco Ceppi (marcoceppi) wrote :

I don't like that this sets /all/ the environment variables. I'd rather there be a whitelist of environment variables to pass to the tests as the testing environment will have very limited scope of env variables.

review: Needs Fixing
310. By David Britton

limit to whitelist of env variables.

Revision history for this message
David Britton (dpb) wrote :

On Fri, Jan 24, 2014 at 3:47 PM, Marco Ceppi <email address hidden> wrote:

> Review: Needs Fixing
>
> I don't like that this sets /all/ the environment variables. I'd rather
> there be a whitelist of environment variables to pass to the tests as the
> testing environment will have very limited scope of env variables.
>

Fixed with corresponding test cases.

--
David Britton <email address hidden>

Revision history for this message
Marco Ceppi (marcoceppi) wrote :

LGTM +1 thank you

review: Approve
311. By David Britton

Merging up

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'charmtools/test.py'
2--- charmtools/test.py 2014-01-22 23:06:10 +0000
3+++ charmtools/test.py 2014-01-28 23:58:52 +0000
4@@ -25,6 +25,7 @@
5
6 LOG_LEVELS = [logging.INFO, logging.DEBUG]
7 TEST_RESULT_LEVELV_NUM = 51
8+ENV_WHITELIST = ('PATH', 'SSH_AUTH_SOCK', 'SSH_AGENT_PID')
9
10
11 class NoTests(Exception):
12@@ -64,6 +65,9 @@
13 def __init__(self, arguments=None):
14 self.args = arguments
15 self.env = {'JUJU_HOME': os.path.expanduser('~/.juju')}
16+ for var in ENV_WHITELIST:
17+ if var in os.environ:
18+ self.env[var] = os.environ[var]
19 self.log = logging.getLogger('juju-test.conductor')
20 self.tests = self.find_tests()
21 self.tests_requested = self.args.tests
22
23=== modified file 'tests/test_juju_test.py'
24--- tests/test_juju_test.py 2014-01-21 06:01:15 +0000
25+++ tests/test_juju_test.py 2014-01-28 23:58:52 +0000
26@@ -115,6 +115,24 @@
27 args = Arguments(tests="dummy")
28 self.assertRaises(juju_test.NoTests, juju_test.Conductor, args)
29
30+ def test_conductor_ignores_arbitrary_env(self):
31+ """Ensure that the conductor ignores other env vars."""
32+ os.environ['CHARMTOOLS_TEST'] = 'FOOBAR';
33+ args = Arguments(tests="dummy")
34+ c = juju_test.Conductor(args)
35+ self.assertNotIn('CHARMTOOLS_TEST', c.env)
36+
37+ def test_conductor_keeps_whitelist_env(self):
38+ """Ensure that the conductor copies the environment whitelist."""
39+ os.environ['PATH'] = 'FOOBAR';
40+ os.environ['SSH_AGENT_PID'] = 'FOOBAR';
41+ os.environ['SSH_AUTH_SOCK'] = 'FOOBAR';
42+ args = Arguments(tests="dummy")
43+ c = juju_test.Conductor(args)
44+ self.assertEqual('FOOBAR', c.env['PATH'])
45+ self.assertEqual('FOOBAR', c.env['SSH_AGENT_PID'])
46+ self.assertEqual('FOOBAR', c.env['SSH_AUTH_SOCK'])
47+
48 @patch.object(juju_test.Conductor, 'find_tests')
49 def test_conductor_find_tests_exception(self, mfind_tests):
50 mfind_tests.return_value = None

Subscribers

People subscribed via source and target branches

to all changes: