40
40
self.network = utils.import_object(FLAGS.network_manager)
41
41
FLAGS.instances_path = ''
43
def test_get_uri_and_template(self):
46
instance = {'internal_id': 1,
47
'memory_kb': '1024000',
48
'basepath': '/some/path',
49
'bridge_name': 'br100',
50
'mac_address': '02:12:34:46:56:67',
54
'instance_type': 'm1.small'}
43
test_ip = '10.11.12.13'
44
test_instance = {'memory_kb': '1024000',
45
'basepath': '/some/path',
46
'bridge_name': 'br100',
47
'mac_address': '02:12:34:46:56:67',
51
'instance_type': 'm1.small'}
53
def test_xml_and_uri_no_ramdisk_no_kernel(self):
54
instance_data = dict(self.test_instance)
55
self.do_test_xml_and_uri(instance_data,
56
expect_kernel=False, expect_ramdisk=False)
58
def test_xml_and_uri_no_ramdisk(self):
59
instance_data = dict(self.test_instance)
60
instance_data['kernel_id'] = 'aki-deadbeef'
61
self.do_test_xml_and_uri(instance_data,
62
expect_kernel=True, expect_ramdisk=False)
64
def test_xml_and_uri_no_kernel(self):
65
instance_data = dict(self.test_instance)
66
instance_data['ramdisk_id'] = 'ari-deadbeef'
67
self.do_test_xml_and_uri(instance_data,
68
expect_kernel=False, expect_ramdisk=False)
70
def test_xml_and_uri(self):
71
instance_data = dict(self.test_instance)
72
instance_data['ramdisk_id'] = 'ari-deadbeef'
73
instance_data['kernel_id'] = 'aki-deadbeef'
74
self.do_test_xml_and_uri(instance_data,
75
expect_kernel=True, expect_ramdisk=True)
77
def test_xml_and_uri_rescue(self):
78
instance_data = dict(self.test_instance)
79
instance_data['ramdisk_id'] = 'ari-deadbeef'
80
instance_data['kernel_id'] = 'aki-deadbeef'
81
self.do_test_xml_and_uri(instance_data,
82
expect_kernel=True, expect_ramdisk=True,
85
def do_test_xml_and_uri(self, instance,
86
expect_ramdisk, expect_kernel,
56
88
user_context = context.RequestContext(project=self.project,
58
90
instance_ref = db.instance_create(user_context, instance)
60
92
self.network.set_network_host(context.get_admin_context(),
63
fixed_ip = {'address': ip,
95
fixed_ip = {'address': self.test_ip,
64
96
'network_id': network_ref['id']}
66
98
ctxt = context.get_admin_context()
67
99
fixed_ip_ref = db.fixed_ip_create(ctxt, fixed_ip)
68
db.fixed_ip_update(ctxt, ip, {'allocated': True,
69
'instance_id': instance_ref['id']})
100
db.fixed_ip_update(ctxt, self.test_ip,
102
'instance_id': instance_ref['id']})
71
104
type_uri_map = {'qemu': ('qemu:///system',
72
105
[(lambda t: t.find('.').get('type'), 'qemu'),
78
111
(lambda t: t.find('./devices/emulator'), None)]),
79
112
'uml': ('uml:///system',
80
113
[(lambda t: t.find('.').get('type'), 'uml'),
81
(lambda t: t.find('./os/type').text, 'uml')])}
114
(lambda t: t.find('./os/type').text, 'uml')]),
116
[(lambda t: t.find('.').get('type'), 'xen'),
117
(lambda t: t.find('./os/type').text, 'linux')]),
120
for hypervisor_type in ['qemu', 'kvm', 'xen']:
121
check_list = type_uri_map[hypervisor_type][1]
124
check = (lambda t: t.find('./os/kernel').text.split('/')[1],
126
check_list.append(check)
127
check = (lambda t: t.find('./os/initrd').text.split('/')[1],
129
check_list.append(check)
132
check = (lambda t: t.find('./os/kernel').text.split(
135
check = (lambda t: t.find('./os/kernel'), None)
136
check_list.append(check)
139
check = (lambda t: t.find('./os/initrd').text.split(
142
check = (lambda t: t.find('./os/initrd'), None)
143
check_list.append(check)
84
146
(lambda t: t.find('.').tag, 'domain'),
85
(lambda t: t.find('./devices/interface/filterref/parameter').\
87
(lambda t: t.find('./devices/interface/filterref/parameter').\
88
get('value'), '10.11.12.13')]
148
'./devices/interface/filterref/parameter').get('name'), 'IP'),
150
'./devices/interface/filterref/parameter').get(
151
'value'), '10.11.12.13'),
152
(lambda t: t.findall(
153
'./devices/interface/filterref/parameter')[1].get(
154
'name'), 'DHCPSERVER'),
155
(lambda t: t.findall(
156
'./devices/interface/filterref/parameter')[1].get(
157
'value'), '10.0.0.1'),
158
(lambda t: t.find('./devices/serial/source').get(
159
'path').split('/')[1], 'console.log'),
160
(lambda t: t.find('./memory').text, '2097152')]
164
(lambda t: t.findall('./devices/disk/source')[0].get(
165
'file').split('/')[1], 'rescue-disk'),
166
(lambda t: t.findall('./devices/disk/source')[1].get(
167
'file').split('/')[1], 'disk')]
169
common_checks += [(lambda t: t.findall(
170
'./devices/disk/source')[0].get('file').split('/')[1],
90
173
for (libvirt_type, (expected_uri, checks)) in type_uri_map.iteritems():
91
174
FLAGS.libvirt_type = libvirt_type
92
175
conn = libvirt_conn.LibvirtConnection(True)
94
uri, _template, _rescue = conn.get_uri_and_templates()
95
178
self.assertEquals(uri, expected_uri)
97
xml = conn.to_xml(instance_ref)
180
xml = conn.to_xml(instance_ref, rescue)
98
181
tree = xml_to_tree(xml)
99
182
for i, (check, expected_result) in enumerate(checks):
100
183
self.assertEqual(check(tree),