Merge lp:~soren/nova/better-virt-tests into lp:~hudson-openstack/nova/trunk

Proposed by Soren Hansen
Status: Merged
Approved by: Rick Clark
Approved revision: 324
Merged at revision: 340
Proposed branch: lp:~soren/nova/better-virt-tests
Merge into: lp:~hudson-openstack/nova/trunk
Diff against target: 108 lines (+45/-21)
2 files modified
nova/tests/virt_unittest.py (+44/-21)
run_tests.py (+1/-0)
To merge this branch: bzr merge lp:~soren/nova/better-virt-tests
Reviewer Review Type Date Requested Status
Jay Pipes (community) Approve
Review via email: mp+37566@code.launchpad.net

Description of the change

Improve the virt unit tests.

To post a comment you must log in.
Revision history for this message
Jay Pipes (jaypipes) wrote :

Yup, nice cleanup. Would be good to get more unit tests for the virtualization layer...perhaps we can work on that at the summit.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'nova/tests/virt_unittest.py'
2--- nova/tests/virt_unittest.py 2010-08-13 21:46:44 +0000
3+++ nova/tests/virt_unittest.py 2010-10-05 08:09:44 +0000
4@@ -14,36 +14,52 @@
5 # License for the specific language governing permissions and limitations
6 # under the License.
7
8+from xml.etree.ElementTree import fromstring as parseXml
9+
10 from nova import flags
11 from nova import test
12+from nova.auth import manager
13+# Needed to get FLAGS.instances_path defined:
14+from nova.compute import manager as compute_manager
15 from nova.virt import libvirt_conn
16
17 FLAGS = flags.FLAGS
18
19-
20 class LibvirtConnTestCase(test.TrialTestCase):
21+ def setUp(self):
22+ self.manager = manager.AuthManager()
23+ self.user = self.manager.create_user('fake', 'fake', 'fake', admin=True)
24+ self.project = self.manager.create_project('fake', 'fake', 'fake')
25+ FLAGS.instances_path = ''
26+
27 def test_get_uri_and_template(self):
28- class MockDataModel(object):
29- def __init__(self):
30- self.datamodel = { 'name' : 'i-cafebabe',
31- 'memory_kb' : '1024000',
32- 'basepath' : '/some/path',
33- 'bridge_name' : 'br100',
34- 'mac_address' : '02:12:34:46:56:67',
35- 'vcpus' : 2 }
36+ instance = { 'name' : 'i-cafebabe',
37+ 'id' : 'i-cafebabe',
38+ 'memory_kb' : '1024000',
39+ 'basepath' : '/some/path',
40+ 'bridge_name' : 'br100',
41+ 'mac_address' : '02:12:34:46:56:67',
42+ 'vcpus' : 2,
43+ 'project_id' : 'fake',
44+ 'ip_address' : '10.11.12.13',
45+ 'bridge' : 'br101',
46+ 'instance_type' : 'm1.small'}
47
48 type_uri_map = { 'qemu' : ('qemu:///system',
49- [lambda s: '<domain type=\'qemu\'>' in s,
50- lambda s: 'type>hvm</type' in s,
51- lambda s: 'emulator>/usr/bin/kvm' not in s]),
52+ [(lambda t: t.find('.').tag, 'domain'),
53+ (lambda t: t.find('.').get('type'), 'qemu'),
54+ (lambda t: t.find('./os/type').text, 'hvm'),
55+ (lambda t: t.find('./devices/emulator'), None)]),
56 'kvm' : ('qemu:///system',
57- [lambda s: '<domain type=\'kvm\'>' in s,
58- lambda s: 'type>hvm</type' in s,
59- lambda s: 'emulator>/usr/bin/qemu<' not in s]),
60+ [(lambda t: t.find('.').tag, 'domain'),
61+ (lambda t: t.find('.').get('type'), 'kvm'),
62+ (lambda t: t.find('./os/type').text, 'hvm'),
63+ (lambda t: t.find('./devices/emulator'), None)]),
64 'uml' : ('uml:///system',
65- [lambda s: '<domain type=\'uml\'>' in s,
66- lambda s: 'type>uml</type' in s]),
67- }
68+ [(lambda t: t.find('.').tag, 'domain'),
69+ (lambda t: t.find('.').get('type'), 'uml'),
70+ (lambda t: t.find('./os/type').text, 'uml')]),
71+ }
72
73 for (libvirt_type,(expected_uri, checks)) in type_uri_map.iteritems():
74 FLAGS.libvirt_type = libvirt_type
75@@ -52,9 +68,12 @@
76 uri, template = conn.get_uri_and_template()
77 self.assertEquals(uri, expected_uri)
78
79- for i, check in enumerate(checks):
80- xml = conn.toXml(MockDataModel())
81- self.assertTrue(check(xml), '%s failed check %d' % (xml, i))
82+ xml = conn.to_xml(instance)
83+ tree = parseXml(xml)
84+ for i, (check, expected_result) in enumerate(checks):
85+ self.assertEqual(check(tree),
86+ expected_result,
87+ '%s failed check %d' % (xml, i))
88
89 # Deliberately not just assigning this string to FLAGS.libvirt_uri and
90 # checking against that later on. This way we make sure the
91@@ -67,3 +86,7 @@
92 uri, template = conn.get_uri_and_template()
93 self.assertEquals(uri, testuri)
94
95+
96+ def tearDown(self):
97+ self.manager.delete_project(self.project)
98+ self.manager.delete_user(self.user)
99
100=== modified file 'run_tests.py'
101--- run_tests.py 2010-09-21 20:58:08 +0000
102+++ run_tests.py 2010-10-05 08:09:44 +0000
103@@ -63,6 +63,7 @@
104 from nova.tests.scheduler_unittest import *
105 from nova.tests.service_unittest import *
106 from nova.tests.validator_unittest import *
107+from nova.tests.virt_unittest import *
108 from nova.tests.volume_unittest import *
109
110