Merge lp:~hazmat/pyjuju/unlocalize-network into lp:pyjuju

Proposed by Kapil Thangavelu
Status: Merged
Approved by: Jim Baker
Approved revision: 408
Merged at revision: 411
Proposed branch: lp:~hazmat/pyjuju/unlocalize-network
Merge into: lp:pyjuju
Diff against target: 117 lines (+18/-12)
2 files modified
juju/providers/local/network.py (+4/-2)
juju/providers/local/tests/test_network.py (+14/-10)
To merge this branch: bzr merge lp:~hazmat/pyjuju/unlocalize-network
Reviewer Review Type Date Requested Status
Jim Baker (community) Approve
Review via email: mp+79476@code.launchpad.net

Description of the change

Libvirt network integration requires unlocalizing to parse output

Else we can't reliably detect the network status, and we end up
trying to start something that's already running.

To post a comment you must log in.
Revision history for this message
Benjamin Saller (bcsaller) wrote :

lgtm +1

Revision history for this message
Jim Baker (jimbaker) wrote :

+1, looks good to me

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'juju/providers/local/network.py'
2--- juju/providers/local/network.py 2011-09-16 21:02:21 +0000
3+++ juju/providers/local/network.py 2011-10-15 16:06:24 +0000
4@@ -100,7 +100,8 @@
5 Parsing the above would return::
6 {"default": True, "juju-test": False, "foobar": False}
7 """
8- output = subprocess.check_output(["virsh", "net-list", "--all"])
9+ output = subprocess.check_output(
10+ ["virsh", "net-list", "--all"], env={"LC_ALL": "C"})
11 networks = {}
12 # Take the header off and normalize whitespace.
13 net_lines = [n.strip() for n in output.splitlines()[2:]]
14@@ -132,7 +133,8 @@
15 </ip>
16 </network>
17 """
18- output = subprocess.check_output(["virsh", "net-dumpxml", name])
19+ output = subprocess.check_output(
20+ ["virsh", "net-dumpxml", name], env={"LC_ALL": "C"})
21 attrs = {}
22 etree = ElementTree.fromstring(output)
23 attrs["name"] = etree.findtext("name")
24
25=== modified file 'juju/providers/local/tests/test_network.py'
26--- juju/providers/local/tests/test_network.py 2011-09-27 16:51:50 +0000
27+++ juju/providers/local/tests/test_network.py 2011-10-15 16:06:24 +0000
28@@ -46,7 +46,8 @@
29 def test_get_network_attributes(self):
30 network_dumpxml_mock = self.mocker.mock()
31 self.patch(subprocess, "check_output", network_dumpxml_mock)
32- network_dumpxml_mock(["virsh", "net-dumpxml", "default"])
33+ network_dumpxml_mock(["virsh", "net-dumpxml", "default"],
34+ env={"LC_ALL": "C"})
35 self.mocker.result(network_dump_xml_default_output)
36 self.mocker.replay()
37
38@@ -81,7 +82,7 @@
39 self.patch(subprocess, "check_output", network_list_mock)
40 self.patch(subprocess, "check_call", network_start_mock)
41
42- network_list_mock(["virsh", "net-list", "--all"])
43+ network_list_mock(["virsh", "net-list", "--all"], env={"LC_ALL": "C"})
44 self.mocker.result(network_list_default_output)
45
46 network_start_mock(MATCH(check_definition))
47@@ -95,7 +96,7 @@
48 def test_start_stoppped_network(self):
49 network_list_mock = self.mocker.mock()
50 self.patch(subprocess, "check_output", network_list_mock)
51- network_list_mock(["virsh", "net-list", "--all"])
52+ network_list_mock(["virsh", "net-list", "--all"], env={"LC_ALL": "C"})
53
54 self.mocker.result(
55 network_list_output_template % dict(
56@@ -113,7 +114,7 @@
57 def test_start_started_network(self):
58 network_list_mock = self.mocker.mock()
59 self.patch(subprocess, "check_output", network_list_mock)
60- network_list_mock(["virsh", "net-list", "--all"])
61+ network_list_mock(["virsh", "net-list", "--all"], env={"LC_ALL": "C"})
62
63 self.mocker.result(
64 network_list_output_template % dict(
65@@ -133,7 +134,7 @@
66 self.patch(subprocess, "check_output", network_list_mock)
67 self.patch(subprocess, "check_call", network_stop_mock)
68
69- network_list_mock(["virsh", "net-list", "--all"])
70+ network_list_mock(["virsh", "net-list", "--all"], env={"LC_ALL": "C"})
71 self.mocker.result(
72 network_list_output_template % dict(
73 name="zoo", state="active", autostart="no"))
74@@ -148,7 +149,7 @@
75 def test_stop_stopped_network(self):
76 network_list_mock = self.mocker.mock()
77 self.patch(subprocess, "check_output", network_list_mock)
78- network_list_mock(["virsh", "net-list", "--all"])
79+ network_list_mock(["virsh", "net-list", "--all"], env={"LC_ALL": "C"})
80
81 self.mocker.result(
82 network_list_output_template % dict(
83@@ -166,7 +167,7 @@
84 def test_stop_nonexistent_network(self):
85 network_list_mock = self.mocker.mock()
86 self.patch(subprocess, "check_output", network_list_mock)
87- network_list_mock(["virsh", "net-list", "--all"])
88+ network_list_mock(["virsh", "net-list", "--all"], env={"LC_ALL": "C"})
89
90 self.mocker.result(
91 network_list_output_template % dict(
92@@ -186,19 +187,22 @@
93 self.patch(subprocess, "check_output", network_list_mock)
94
95 # Network on
96- network_list_mock(["virsh", "net-list", "--all"])
97+ network_list_mock(["virsh", "net-list", "--all"],
98+ env={"LC_ALL": "C"})
99 self.mocker.result(
100 network_list_output_template % (
101 dict(name="foobar", state="active", autostart="off")))
102
103 # Network off
104- network_list_mock(["virsh", "net-list", "--all"])
105+ network_list_mock(["virsh", "net-list", "--all"],
106+ env={"LC_ALL": "C"})
107 self.mocker.result(
108 network_list_output_template % (
109 dict(name="foobar", state="inactive", autostart="off")))
110
111 # Non existent
112- network_list_mock(["virsh", "net-list", "--all"])
113+ network_list_mock(["virsh", "net-list", "--all"],
114+ env={"LC_ALL": "C"})
115 self.mocker.result(
116 network_list_output_template % (
117 dict(name="magic", state="inactive", autostart="off")))

Subscribers

People subscribed via source and target branches

to status/vote changes: