Merge lp:~andrewjbeach/juju-ci-tools/bootstrap-args into lp:juju-ci-tools

Proposed by Andrew James Beach
Status: Merged
Merged at revision: 1631
Proposed branch: lp:~andrewjbeach/juju-ci-tools/bootstrap-args
Merge into: lp:juju-ci-tools
Diff against target: 124 lines (+58/-9)
2 files modified
jujupy.py (+25/-9)
tests/test_jujupy.py (+33/-0)
To merge this branch: bzr merge lp:~andrewjbeach/juju-ci-tools/bootstrap-args
Reviewer Review Type Date Requested Status
Aaron Bentley (community) Approve
Review via email: mp+307587@code.launchpad.net

Description of the change

Added a new parameter to get_bootstrap_args: agent_version. It also appears
in the bootstrap methods so you can pass in the value.

This conficts with upload_tools, if both are given an exception is raised.

Modified get_bootstrap_args and bootstrap methods in EnvJujuClient.
Added tests for the new parameter in test_jujupy.py.

To post a comment you must log in.
Revision history for this message
Aaron Bentley (abentley) wrote :

I don't see any handling for juju 1.x. Did you test it?

Since EnvJujuClient's bootstrap implementation is used by EnvJujuClient1X, but its get_bootstrap_args has not been updated, I expect to fail because too many parameters are supplied.

I would expect EnvJujuClient1X.get_bootstrap_args to:
1. always have a signature matching EnvJujuClient.get_bootstrap_args, so it would accept agent_version, defaulted to None (like EnvJujuClient2B2.get_bootstrap_args)
2. raise an exception (e.g. ValueError) if agent_version is not None.

review: Needs Information
1638. By Andrew James Beach

Added checks to make sure the versions that don't support the new bootstrap arguments don't get them.

Revision history for this message
Andrew James Beach (andrewjbeach) wrote :

EnvJujuClient1X doesn't use EnvJujuClient's bootstrap, it uses the one in from 2A2. I instead did that to 2B2, which does use EnvJujuClient's bootstrap. If you think it is important I could repeat the process on other versions.

Revision history for this message
Aaron Bentley (abentley) wrote :

Thanks for explaining. Sorry I missed the EnvJujuClient2A2 implementation. Ideally that would have the same signature as the EnvJujuClient implementation, but it seems to have diverged considerably without causing actual problems, so I guess we don't need to address that right now.

Aside from a couple of typos, this is good to land. I do have a couple of suggestions for the get_bootstrap_args logic, but they're not required.

review: Approve
1639. By Andrew James Beach

Last bit of pollish.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'jujupy.py'
2--- jujupy.py 2016-10-03 13:12:25 +0000
3+++ jujupy.py 2016-10-04 18:45:33 +0000
4@@ -1143,9 +1143,10 @@
5 return cloud
6 return '{}/{}'.format(cloud, region)
7
8- def get_bootstrap_args(self, upload_tools, config_filename,
9- bootstrap_series=None, credential=None,
10- auto_upgrade=False, metadata_source=None, to=None):
11+ def get_bootstrap_args(
12+ self, upload_tools, config_filename, bootstrap_series=None,
13+ credential=None, auto_upgrade=False, metadata_source=None,
14+ to=None, agent_version=None):
15 """Return the bootstrap arguments for the substrate."""
16 if self.env.joyent:
17 # Only accept kvm packages by requiring >1 cpu core, see lp:1446264
18@@ -1158,9 +1159,14 @@
19 cloud_region, '--config', config_filename,
20 '--default-model', self.env.environment]
21 if upload_tools:
22+ if agent_version is not None:
23+ raise ValueError(
24+ 'agent-version may not be given with upload-tools.')
25 args.insert(0, '--upload-tools')
26 else:
27- args.extend(['--agent-version', self.get_matching_agent_version()])
28+ if agent_version is None:
29+ agent_version = self.get_matching_agent_version()
30+ args.extend(['--agent-version', agent_version])
31 if bootstrap_series is not None:
32 args.extend(['--bootstrap-series', bootstrap_series])
33 if credential is not None:
34@@ -1236,13 +1242,13 @@
35
36 def bootstrap(self, upload_tools=False, bootstrap_series=None,
37 credential=None, auto_upgrade=False, metadata_source=None,
38- to=None):
39+ to=None, agent_version=None):
40 """Bootstrap a controller."""
41 self._check_bootstrap()
42 with self._bootstrap_config() as config_filename:
43 args = self.get_bootstrap_args(
44 upload_tools, config_filename, bootstrap_series, credential,
45- auto_upgrade, metadata_source, to)
46+ auto_upgrade, metadata_source, to, agent_version)
47 self.update_user_name()
48 self.juju('bootstrap', args, include_e=False)
49
50@@ -2296,10 +2302,20 @@
51
52 class EnvJujuClient2B2(EnvJujuClient2B3):
53
54- def get_bootstrap_args(self, upload_tools, config_filename,
55- bootstrap_series=None, credential=None,
56- auto_upgrade=False, metadata_source=None, to=None):
57+ def get_bootstrap_args(
58+ self, upload_tools, config_filename, bootstrap_series=None,
59+ credential=None, auto_upgrade=False, metadata_source=None,
60+ to=None, agent_version=None):
61 """Return the bootstrap arguments for the substrate."""
62+ err_fmt = 'EnvJujuClient2B2 does not support bootstrap argument {}'
63+ if auto_upgrade:
64+ raise ValueError(err_fmt.format('auto_upgrade'))
65+ if metadata_source is not None:
66+ raise ValueError(err_fmt.format('metadata_source'))
67+ if to is not None:
68+ raise ValueError(err_fmt.format('to'))
69+ if agent_version is not None:
70+ raise ValueError(err_fmt.format('agent_version'))
71 if self.env.joyent:
72 # Only accept kvm packages by requiring >1 cpu core, see lp:1446264
73 constraints = 'mem=2G cpu-cores=1'
74
75=== modified file 'tests/test_jujupy.py'
76--- tests/test_jujupy.py 2016-10-03 13:12:25 +0000
77+++ tests/test_jujupy.py 2016-10-04 18:45:33 +0000
78@@ -1046,6 +1046,24 @@
79 '--config', 'config', '--default-model', 'foo',
80 '--bootstrap-series', 'angsty'))
81
82+ def test_get_bootstrap_args_agent_version(self):
83+ env = JujuData('foo', {'type': 'bar', 'region': 'baz'})
84+ client = EnvJujuClient(env, '2.0-zeta1', None)
85+ args = client.get_bootstrap_args(upload_tools=False,
86+ config_filename='config',
87+ agent_version='2.0-lambda1')
88+ self.assertEqual(('--constraints', 'mem=2G', 'foo', 'bar/baz',
89+ '--config', 'config', '--default-model', 'foo',
90+ '--agent-version', '2.0-lambda1'), args)
91+
92+ def test_get_bootstrap_args_upload_tools_and_agent_version(self):
93+ env = JujuData('foo', {'type': 'bar', 'region': 'baz'})
94+ client = EnvJujuClient(env, '2.0-zeta1', None)
95+ with self.assertRaises(ValueError):
96+ client.get_bootstrap_args(upload_tools=True,
97+ config_filename='config',
98+ agent_version='2.0-lambda1')
99+
100 def test_add_model_hypenated_controller(self):
101 self.do_add_model(
102 'kill-controller', 'add-model', ('-c', 'foo'))
103@@ -3553,6 +3571,21 @@
104 '--upload-tools', '--constraints', 'mem=2G', 'foo', 'bar/baz',
105 '--config', 'config', '--bootstrap-series', 'angsty'))
106
107+ def test_get_bootstrap_args_reject_new_args(self):
108+ env = JujuData('foo', {'type': 'bar', 'region': 'baz'})
109+ client = EnvJujuClient2B2(env, '2.0-zeta1', None)
110+ base_args = {'upload_tools': True,
111+ 'config_filename': 'config',
112+ 'bootstrap_series': 'angsty'}
113+ with self.assertRaises(ValueError):
114+ client.get_bootstrap_args(auto_upgrade=True, **base_args)
115+ with self.assertRaises(ValueError):
116+ client.get_bootstrap_args(metadata_source='/foo', **base_args)
117+ with self.assertRaises(ValueError):
118+ client.get_bootstrap_args(to='cur', **base_args)
119+ with self.assertRaises(ValueError):
120+ client.get_bootstrap_args(agent_version='1.0.0', **base_args)
121+
122 def test_bootstrap_upload_tools(self):
123 env = JujuData('foo', {'type': 'foo', 'region': 'baz'})
124 client = EnvJujuClient2B2(env, '2.0-zeta1', None)

Subscribers

People subscribed via source and target branches