Merge lp:~sinzui/juju-ci-tools/run-instance-with-series into lp:juju-ci-tools

Proposed by Curtis Hovey
Status: Merged
Merged at revision: 1093
Proposed branch: lp:~sinzui/juju-ci-tools/run-instance-with-series
Merge into: lp:juju-ci-tools
Diff against target: 100 lines (+32/-7)
3 files modified
deploy_stack.py (+1/-1)
substrate.py (+11/-2)
test_substrate.py (+20/-4)
To merge this branch: bzr merge lp:~sinzui/juju-ci-tools/run-instance-with-series
Reviewer Review Type Date Requested Status
Martin Packman (community) Approve
Review via email: mp+271197@code.launchpad.net

Description of the change

Create manual instances that match the series under test.

substrate.run_instances() only makes precise instances. The get_ami() is always passed "precise". This branch adds a series argument to run_instances(). There was only one call site, so I chose to make this a required argument. All the caller may have been given a series of None, we require a guard to assume precise. While every caller of boot_context should be passing series, we really don't know if every caller is explicitly passing series as they should.

To post a comment you must log in.
Revision history for this message
Martin Packman (gz) wrote :

Looks good!

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'deploy_stack.py'
2--- deploy_stack.py 2015-08-25 20:58:39 +0000
3+++ deploy_stack.py 2015-09-15 20:29:47 +0000
4@@ -408,7 +408,7 @@
5 running_domains = dict()
6 try:
7 if client.env.config['type'] == 'manual' and bootstrap_host is None:
8- instances = run_instances(3, temp_env_name)
9+ instances = run_instances(3, temp_env_name, series)
10 created_machines = True
11 bootstrap_host = instances[0][1]
12 machines.extend(i[1] for i in instances[1:])
13
14=== modified file 'substrate.py'
15--- substrate.py 2015-07-02 00:59:47 +0000
16+++ substrate.py 2015-09-15 20:29:47 +0000
17@@ -543,9 +543,18 @@
18 yield fields[1], fields[3]
19
20
21-def run_instances(count, job_name):
22+def run_instances(count, job_name, series):
23+ """create a number of instances in ec2 and tag them.
24+
25+ :param count: The number of instances to create.
26+ :param job_name: The name of job that owns the instances (used as a tag).
27+ :param series: The series to run in the instance.
28+ If None, Precise will be used.
29+ """
30+ if series is None:
31+ series = 'precise'
32 environ = dict(os.environ)
33- ami = get_ami.query_ami("precise", "amd64")
34+ ami = get_ami.query_ami(series, "amd64")
35 command = [
36 'euca-run-instances', '-k', 'id_rsa', '-n', '%d' % count,
37 '-t', 'm1.large', '-g', 'manual-juju-test', ami]
38
39=== modified file 'test_substrate.py'
40--- test_substrate.py 2015-06-12 18:54:52 +0000
41+++ test_substrate.py 2015-09-15 20:29:47 +0000
42@@ -852,7 +852,7 @@
43 self.assertEqual(
44 [('i-foo', 'bar-0'), ('i-baz', 'bar-1')], [d for d in description])
45
46- def test_run_instances(self):
47+ def test_run_instances_without_series(self):
48 euca_data = dedent("""
49 header
50 INSTANCE\ti-foo\tblah\tbar-0
51@@ -867,7 +867,7 @@
52 return_value=description, autospec=True) as di_mock:
53 with patch('get_ami.query_ami',
54 return_value=ami, autospec=True) as qa_mock:
55- run_instances(2, 'qux')
56+ run_instances(2, 'qux', None)
57 co_mock.assert_called_once_with(
58 ['euca-run-instances', '-k', 'id_rsa', '-n', '2',
59 '-t', 'm1.large', '-g', 'manual-juju-test', ami],
60@@ -878,6 +878,22 @@
61 di_mock.assert_called_once_with(['i-foo', 'i-baz'], env=os.environ)
62 qa_mock.assert_called_once_with('precise', 'amd64')
63
64+ @patch('get_ami.query_ami', autospec=True)
65+ @patch('substrate.describe_instances', autospec=True)
66+ @patch('subprocess.check_call', autospec=True)
67+ @patch('subprocess.check_output', autospec=True)
68+ def test_run_instances_with_series(self,
69+ co_mock, cc_mock, di_mock, qa_mock):
70+ co_mock.return_value = dedent("""
71+ header
72+ INSTANCE\ti-foo\tblah\tbar-0
73+ INSTANCE\ti-baz\tblah\tbar-1
74+ """)
75+ di_mock.return_value = [('i-foo', 'bar-0'), ('i-baz', 'bar-1')]
76+ qa_mock.return_value = "ami-atest"
77+ run_instances(2, 'qux', 'wily')
78+ qa_mock.assert_called_once_with('wily', 'amd64')
79+
80 def test_run_instances_tagging_failed(self):
81 euca_data = 'INSTANCE\ti-foo\tblah\tbar-0'
82 description = [('i-foo', 'bar-0')]
83@@ -889,7 +905,7 @@
84 return_value=description, autospec=True):
85 with patch('subprocess.call', autospec=True) as c_mock:
86 with self.assertRaises(CalledProcessError):
87- run_instances(1, 'qux')
88+ run_instances(1, 'qux', 'trusty')
89 c_mock.assert_called_with(['euca-terminate-instances', 'i-foo'])
90
91 def test_run_instances_describe_failed(self):
92@@ -900,7 +916,7 @@
93 side_effect=CalledProcessError('', '')):
94 with patch('subprocess.call', autospec=True) as c_mock:
95 with self.assertRaises(CalledProcessError):
96- run_instances(1, 'qux')
97+ run_instances(1, 'qux', 'trusty')
98 c_mock.assert_called_with(['euca-terminate-instances', 'i-foo'])
99
100 def test_destroy_job_instances_none(self):

Subscribers

People subscribed via source and target branches