Merge lp:~rackspace-titan/nova/nuke_naughty_mox into lp:~hudson-openstack/nova/trunk

Proposed by Dan Prince
Status: Merged
Approved by: Brian Lamar
Approved revision: 1561
Merged at revision: 1569
Proposed branch: lp:~rackspace-titan/nova/nuke_naughty_mox
Merge into: lp:~hudson-openstack/nova/trunk
Diff against target: 164 lines (+63/-55)
2 files modified
nova/tests/fake_network.py (+30/-0)
nova/tests/test_libvirt.py (+33/-55)
To merge this branch: bzr merge lp:~rackspace-titan/nova/nuke_naughty_mox
Reviewer Review Type Date Requested Status
Brian Lamar (community) Approve
Sandy Walsh (community) Approve
Devin Carlen (community) Approve
Review via email: mp+75245@code.launchpad.net

Description of the change

Update test_libvirt so that flags and fakes are used instead of mocks for utils.import_class and utils.import_object. Fixes #lp849329.

To post a comment you must log in.
Revision history for this message
Devin Carlen (devcamcar) wrote :

lgtm

review: Approve
1561. By Dan Prince

pep8 fixes.

Revision history for this message
Sandy Walsh (sandy-walsh) wrote :

Good lord I'm so happy you fixed this. I spent about 8hrs investigating it and found it stemmed from a bad 'paste' library (apt-get vs. pip vs. easy_install) against python 2.6.6. This is a much better solution.

I'll pull the branch and confirm tests then approve.

Revision history for this message
Sandy Walsh (sandy-walsh) wrote :

Getting a pep8, but not as a result of this branch.

I wish I still had the error showing up on my dev machine so I could ensure it was fixed, but generally lgtm.

review: Approve
Revision history for this message
Brian Lamar (blamar) wrote :

Good stuff, thanks Dan!

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'nova/tests/fake_network.py'
2--- nova/tests/fake_network.py 2011-09-07 21:06:35 +0000
3+++ nova/tests/fake_network.py 2011-09-14 00:40:28 +0000
4@@ -25,6 +25,36 @@
5 FLAGS = flags.FLAGS
6
7
8+class FakeIptablesFirewallDriver(object):
9+ def __init__(self, **kwargs):
10+ pass
11+
12+ def setattr(self, key, val):
13+ self.__setattr__(key, val)
14+
15+ def apply_instance_filter(self, instance, network_info):
16+ pass
17+
18+
19+class FakeVIFDriver(object):
20+
21+ def __init__(self, **kwargs):
22+ pass
23+
24+ def setattr(self, key, val):
25+ self.__setattr__(key, val)
26+
27+ def plug(self, instance, network, mapping):
28+ return {
29+ 'id': 'fake',
30+ 'bridge_name': 'fake',
31+ 'mac_address': 'fake',
32+ 'ip_address': 'fake',
33+ 'dhcp_server': 'fake',
34+ 'extra_params': 'fake',
35+ }
36+
37+
38 class FakeModel(dict):
39 """Represent a model from the db"""
40 def __init__(self, *args, **kwargs):
41
42=== modified file 'nova/tests/test_libvirt.py'
43--- nova/tests/test_libvirt.py 2011-09-13 21:29:26 +0000
44+++ nova/tests/test_libvirt.py 2011-09-14 00:40:28 +0000
45@@ -52,6 +52,32 @@
46 done.send()
47
48
49+class FakeVirtDomain(object):
50+
51+ def __init__(self, fake_xml=None):
52+ if fake_xml:
53+ self._fake_dom_xml = fake_xml
54+ else:
55+ self._fake_dom_xml = """
56+ <domain type='kvm'>
57+ <devices>
58+ <disk type='file'>
59+ <source file='filename'/>
60+ </disk>
61+ </devices>
62+ </domain>
63+ """
64+
65+ def snapshotCreateXML(self, *args):
66+ return None
67+
68+ def createWithFlags(self, launch_flags):
69+ pass
70+
71+ def XMLDesc(self, *args):
72+ return self._fake_dom_xml
73+
74+
75 class CacheConcurrencyTestCase(test.TestCase):
76 def setUp(self):
77 super(CacheConcurrencyTestCase, self).setUp()
78@@ -153,70 +179,24 @@
79
80 # A fake libvirt.virConnect
81 class FakeLibvirtConnection(object):
82- pass
83-
84- # A fake connection.IptablesFirewallDriver
85- class FakeIptablesFirewallDriver(object):
86-
87- def __init__(self, **kwargs):
88- pass
89-
90- def setattr(self, key, val):
91- self.__setattr__(key, val)
92-
93- # A fake VIF driver
94- class FakeVIFDriver(object):
95-
96- def __init__(self, **kwargs):
97- pass
98-
99- def setattr(self, key, val):
100- self.__setattr__(key, val)
101-
102- def plug(self, instance, network, mapping):
103- return {
104- 'id': 'fake',
105- 'bridge_name': 'fake',
106- 'mac_address': 'fake',
107- 'ip_address': 'fake',
108- 'dhcp_server': 'fake',
109- 'extra_params': 'fake',
110- }
111+ def defineXML(self, xml):
112+ return FakeVirtDomain()
113
114 # Creating mocks
115 fake = FakeLibvirtConnection()
116- fakeip = FakeIptablesFirewallDriver
117- fakevif = FakeVIFDriver()
118 # Customizing above fake if necessary
119 for key, val in kwargs.items():
120 fake.__setattr__(key, val)
121
122- # Inevitable mocks for connection.LibvirtConnection
123- self.mox.StubOutWithMock(connection.utils, 'import_class')
124- connection.utils.import_class(mox.IgnoreArg()).AndReturn(fakeip)
125- self.mox.StubOutWithMock(connection.utils, 'import_object')
126- connection.utils.import_object(mox.IgnoreArg()).AndReturn(fakevif)
127+ self.flags(image_service='nova.image.fake.FakeImageService')
128+ fw_driver = "nova.tests.fake_network.FakeIptablesFirewallDriver"
129+ self.flags(firewall_driver=fw_driver)
130+ self.flags(libvirt_vif_driver="nova.tests.fake_network.FakeVIFDriver")
131+
132 self.mox.StubOutWithMock(connection.LibvirtConnection, '_conn')
133 connection.LibvirtConnection._conn = fake
134
135 def fake_lookup(self, instance_name):
136-
137- class FakeVirtDomain(object):
138-
139- def snapshotCreateXML(self, *args):
140- return None
141-
142- def XMLDesc(self, *args):
143- return """
144- <domain type='kvm'>
145- <devices>
146- <disk type='file'>
147- <source file='filename'/>
148- </disk>
149- </devices>
150- </domain>
151- """
152-
153 return FakeVirtDomain()
154
155 def fake_execute(self, *args):
156@@ -798,8 +778,6 @@
157 shutil.rmtree(os.path.join(FLAGS.instances_path, instance.name))
158 shutil.rmtree(os.path.join(FLAGS.instances_path, '_base'))
159
160- self.assertTrue(count)
161-
162 def test_get_host_ip_addr(self):
163 conn = connection.LibvirtConnection(False)
164 ip = conn.get_host_ip_addr()