Merge lp:~abentley/juju-ci-tools/iter-new-machines-containers into lp:juju-ci-tools

Proposed by Aaron Bentley
Status: Merged
Merged at revision: 1916
Proposed branch: lp:~abentley/juju-ci-tools/iter-new-machines-containers
Merge into: lp:juju-ci-tools
Diff against target: 82 lines (+43/-5)
3 files modified
jujupy/client.py (+4/-3)
jujupy/fake.py (+3/-2)
jujupy/tests/test_client.py (+36/-0)
To merge this branch: bzr merge lp:~abentley/juju-ci-tools/iter-new-machines-containers
Reviewer Review Type Date Requested Status
Curtis Hovey (community) code Approve
Review via email: mp+318542@code.launchpad.net

Commit message

Optionally include containers when iterating through new machines.

Description of the change

This branch adds the ability to list new containers.

It updates iter_new_machines with a 'containers' flag that is passed through to iter_machines. It also changes the way old machines are determined, so that it also uses iter_machines.

As a driveby, it improves the fake's handling of containers so that they have a 'juju-status' field, like normal machines do. This is sufficient to get client.wait_for_started working when the fake has containers.

To post a comment you must log in.
Revision history for this message
Curtis Hovey (sinzui) wrote :

Thank you.

review: Approve (code)

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'jujupy/client.py'
2--- jujupy/client.py 2017-02-28 20:34:53 +0000
3+++ jujupy/client.py 2017-02-28 21:43:44 +0000
4@@ -881,9 +881,10 @@
5 for contained, unit in machine.get('containers', {}).items():
6 yield contained, unit
7
8- def iter_new_machines(self, old_status):
9- for machine, data in self.iter_machines():
10- if machine in old_status.status['machines']:
11+ def iter_new_machines(self, old_status, containers=False):
12+ old = dict(old_status.iter_machines(containers=containers))
13+ for machine, data in self.iter_machines(containers=containers):
14+ if machine in old:
15 continue
16 yield machine, data
17
18
19=== modified file 'jujupy/fake.py'
20--- jujupy/fake.py 2017-02-23 17:28:46 +0000
21+++ jujupy/fake.py 2017-02-28 21:43:44 +0000
22@@ -259,10 +259,11 @@
23 machine_dict['controller-member-status'] = 'has-vote'
24 for host, containers in self.containers.items():
25 container_dict = dict((c, {}) for c in containers)
26- for container in containers:
27+ for container, subdict in container_dict.items():
28+ subdict.update({'juju-status': {'current': 'idle'}})
29 dns_name = self.machine_host_names.get(container)
30 if dns_name is not None:
31- container_dict[container]['dns-name'] = dns_name
32+ subdict['dns-name'] = dns_name
33
34 machines[host]['containers'] = container_dict
35 services = {}
36
37=== modified file 'jujupy/tests/test_client.py'
38--- jujupy/tests/test_client.py 2017-02-28 20:34:53 +0000
39+++ jujupy/tests/test_client.py 2017-02-28 21:43:44 +0000
40@@ -4589,6 +4589,42 @@
41 self.assertItemsEqual(new_status.iter_new_machines(old_status),
42 [('foo', 'foo_info')])
43
44+ def test_iter_new_machines_no_containers(self):
45+ bar_info = {'containers': {'bar/lxd/1': {}}}
46+ old_status = Status({
47+ 'machines': {
48+ 'bar': bar_info,
49+ }
50+ }, '')
51+ foo_info = {'containers': {'foo/lxd/1': {}}}
52+ new_status = Status({
53+ 'machines': {
54+ 'foo': foo_info,
55+ 'bar': bar_info,
56+ }
57+ }, '')
58+ self.assertItemsEqual(new_status.iter_new_machines(old_status,
59+ containers=False),
60+ [('foo', foo_info)])
61+
62+ def test_iter_new_machines_with_containers(self):
63+ bar_info = {'containers': {'bar/lxd/1': {}}}
64+ old_status = Status({
65+ 'machines': {
66+ 'bar': bar_info,
67+ }
68+ }, '')
69+ foo_info = {'containers': {'foo/lxd/1': {}}}
70+ new_status = Status({
71+ 'machines': {
72+ 'foo': foo_info,
73+ 'bar': bar_info,
74+ }
75+ }, '')
76+ self.assertItemsEqual(new_status.iter_new_machines(old_status,
77+ containers=True),
78+ [('foo', foo_info), ('foo/lxd/1', {})])
79+
80 def test_get_instance_id(self):
81 status = Status({
82 'machines': {

Subscribers

People subscribed via source and target branches