88
88
'virtual_interface_id': vif_ref['id']}
89
89
db.fixed_ip_create(ctxt, fixed_ip)
90
90
db.fixed_ip_update(ctxt, ip, {'allocated': True,
91
'instance_id': instance_id})
91
'instance_id': instance_id})
94
94
class CacheConcurrencyTestCase(test.TestCase):
177
177
self.context = context.get_admin_context()
178
178
FLAGS.instances_path = ''
179
179
self.call_libvirt_dependant_setup = False
180
self.test_ip = '10.11.12.13'
181
182
def tearDown(self):
182
183
self.manager.delete_project(self.project)
183
184
self.manager.delete_user(self.user)
184
185
super(LibvirtConnTestCase, self).tearDown()
186
test_ip = '10.11.12.13'
187
187
test_instance = {'memory_kb': '1024000',
188
188
'basepath': '/some/path',
189
189
'bridge_name': 'br100',
232
232
def setattr(self, key, val):
233
233
self.__setattr__(key, val)
235
def plug(self, instance, network, mapping):
238
'bridge_name': 'fake',
239
'mac_address': 'fake',
240
'ip_address': 'fake',
241
'dhcp_server': 'fake',
242
'extra_params': 'fake'
236
246
fake = FakeLibvirtConnection()
237
247
fakeip = FakeIptablesFirewallDriver
281
291
return db.service_create(context.get_admin_context(), service_ref)
283
@test.skip_test("Please review this test to ensure intent")
284
293
def test_preparing_xml_info(self):
285
294
conn = connection.LibvirtConnection(True)
286
295
instance_ref = db.instance_create(self.context, self.test_instance)
296
305
_create_network_info(2))
297
306
self.assertTrue(len(result['nics']) == 2)
299
@test.skip_test("skipping libvirt tests depends on get_network_info shim")
300
308
def test_xml_and_uri_no_ramdisk_no_kernel(self):
301
309
instance_data = dict(self.test_instance)
302
310
self._check_xml_and_uri(instance_data,
303
311
expect_kernel=False, expect_ramdisk=False)
305
@test.skip_test("skipping libvirt tests depends on get_network_info shim")
306
313
def test_xml_and_uri_no_ramdisk(self):
307
314
instance_data = dict(self.test_instance)
308
315
instance_data['kernel_id'] = 'aki-deadbeef'
309
316
self._check_xml_and_uri(instance_data,
310
317
expect_kernel=True, expect_ramdisk=False)
312
@test.skip_test("skipping libvirt tests depends on get_network_info shim")
313
319
def test_xml_and_uri_no_kernel(self):
314
320
instance_data = dict(self.test_instance)
315
321
instance_data['ramdisk_id'] = 'ari-deadbeef'
316
322
self._check_xml_and_uri(instance_data,
317
323
expect_kernel=False, expect_ramdisk=False)
319
@test.skip_test("skipping libvirt tests depends on get_network_info shim")
320
325
def test_xml_and_uri(self):
321
326
instance_data = dict(self.test_instance)
322
327
instance_data['ramdisk_id'] = 'ari-deadbeef'
324
329
self._check_xml_and_uri(instance_data,
325
330
expect_kernel=True, expect_ramdisk=True)
327
@test.skip_test("skipping libvirt tests depends on get_network_info shim")
328
332
def test_xml_and_uri_rescue(self):
329
333
instance_data = dict(self.test_instance)
330
334
instance_data['ramdisk_id'] = 'ari-deadbeef'
332
336
self._check_xml_and_uri(instance_data, expect_kernel=True,
333
337
expect_ramdisk=True, rescue=True)
335
@test.skip_test("skipping libvirt tests depends on get_network_info shim")
336
339
def test_lxc_container_and_uri(self):
337
340
instance_data = dict(self.test_instance)
338
341
self._check_xml_and_container(instance_data)
441
444
user_context = context.RequestContext(project=self.project,
443
446
instance_ref = db.instance_create(user_context, instance)
444
# Re-get the instance so it's bound to an actual session
445
instance_ref = db.instance_get(user_context, instance_ref['id'])
446
network_ref = db.project_get_networks(context.get_admin_context(),
449
vif = {'address': '56:12:12:12:12:12',
450
'network_id': network_ref['id'],
451
'instance_id': instance_ref['id']}
452
vif_ref = db.virtual_interface_create(self.context, vif)
453
fixed_ip = {'address': self.test_ip,
454
'network_id': network_ref['id'],
455
'virtual_interface_id': vif_ref['id']}
457
ctxt = context.get_admin_context()
458
fixed_ip_ref = db.fixed_ip_create(ctxt, fixed_ip)
459
db.fixed_ip_update(ctxt, self.test_ip,
461
'instance_id': instance_ref['id']})
447
_setup_networking(instance_ref['id'], self.test_ip)
463
449
self.flags(libvirt_type='lxc')
464
450
conn = connection.LibvirtConnection(True)
490
476
network_ref = db.project_get_networks(context.get_admin_context(),
491
477
self.project.id)[0]
493
_setup_networking(instance_ref['id'], ip=self.test_ip)
479
_setup_networking(instance_ref['id'], self.test_ip)
495
481
type_uri_map = {'qemu': ('qemu:///system',
496
482
[(lambda t: t.find('.').get('type'), 'qemu'),
752
738
db.volume_destroy(self.context, volume_ref['id'])
753
739
db.instance_destroy(self.context, instance_ref['id'])
755
@test.skip_test("test needs rewrite: instance no longer has mac_address")
756
741
def test_spawn_with_network_info(self):
757
742
# Skip if non-libvirt environment
758
743
if not self.lazy_load_library_exists():
771
756
conn.firewall_driver.setattr('setup_basic_filtering', fake_none)
772
757
conn.firewall_driver.setattr('prepare_instance_filter', fake_none)
774
network = db.project_get_networks(context.get_admin_context(),
776
ip_dict = {'ip': self.test_ip,
777
'netmask': network['netmask'],
779
mapping = {'label': network['label'],
780
'gateway': network['gateway'],
781
'mac': instance['mac_address'],
782
'dns': [network['dns']],
784
network_info = [(network, mapping)]
759
network_info = _create_network_info()
787
762
conn.spawn(instance, network_info)
904
880
'project_id': 'fake',
905
881
'instance_type_id': 1})
907
@test.skip_test("skipping libvirt tests depends on get_network_info shim")
908
883
def test_static_filters(self):
909
884
instance_ref = self._create_instance_ref()
912
network_ref = db.project_get_networks(self.context,
915
vif = {'address': '56:12:12:12:12:12',
916
'network_id': network_ref['id'],
917
'instance_id': instance_ref['id']}
918
vif_ref = db.virtual_interface_create(self.context, vif)
920
fixed_ip = {'address': ip,
921
'network_id': network_ref['id'],
922
'virtual_interface_id': vif_ref['id']}
885
_setup_networking(instance_ref['id'], self.test_ip)
923
887
admin_ctxt = context.get_admin_context()
924
db.fixed_ip_create(admin_ctxt, fixed_ip)
925
db.fixed_ip_update(admin_ctxt, ip, {'allocated': True,
926
'instance_id': instance_ref['id']})
928
888
secgroup = db.security_group_create(admin_ctxt,
929
889
{'user_id': 'fake',
930
890
'project_id': 'fake',
1056
1016
self.assertEquals(ipv6_network_rules,
1057
1017
ipv6_rules_per_network * networks_count)
1059
@test.skip_test("skipping libvirt tests")
1060
1019
def test_do_refresh_security_group_rules(self):
1061
1020
instance_ref = self._create_instance_ref()
1062
1021
self.mox.StubOutWithMock(self.fw,
1081
1039
self.fw.nwfilter._conn.nwfilterLookupByName =\
1082
1040
fakefilter.nwfilterLookupByName
1083
1041
instance_ref = self._create_instance_ref()
1084
inst_id = instance_ref['id']
1085
instance = db.instance_get(self.context, inst_id)
1088
network_ref = db.project_get_network(self.context, 'fake')
1089
fixed_ip = {'address': ip, 'network_id': network_ref['id']}
1090
db.fixed_ip_create(admin_ctxt, fixed_ip)
1091
db.fixed_ip_update(admin_ctxt, ip, {'allocated': True,
1092
'instance_id': inst_id})
1093
self.fw.setup_basic_filtering(instance)
1094
self.fw.prepare_instance_filter(instance)
1095
self.fw.apply_instance_filter(instance)
1043
_setup_networking(instance_ref['id'], self.test_ip)
1044
self.fw.setup_basic_filtering(instance_ref)
1045
self.fw.prepare_instance_filter(instance_ref)
1046
self.fw.apply_instance_filter(instance_ref)
1096
1047
original_filter_count = len(fakefilter.filters)
1097
self.fw.unfilter_instance(instance)
1048
self.fw.unfilter_instance(instance_ref)
1099
1050
# should undefine just the instance filter
1100
1051
self.assertEqual(original_filter_count - len(fakefilter.filters), 1)
1102
1053
db.instance_destroy(admin_ctxt, instance_ref['id'])
1104
@test.skip_test("skip libvirt test project_get_network no longer exists")
1105
1055
def test_provider_firewall_rules(self):
1106
1056
# setup basic instance data
1107
1057
instance_ref = self._create_instance_ref()
1108
1058
nw_info = _create_network_info(1)
1110
network_ref = db.project_get_network(self.context, 'fake')
1111
admin_ctxt = context.get_admin_context()
1112
fixed_ip = {'address': ip, 'network_id': network_ref['id']}
1113
db.fixed_ip_create(admin_ctxt, fixed_ip)
1114
db.fixed_ip_update(admin_ctxt, ip, {'allocated': True,
1115
'instance_id': instance_ref['id']})
1059
_setup_networking(instance_ref['id'], self.test_ip)
1116
1060
# FRAGILE: peeks at how the firewall names chains
1117
1061
chain_name = 'inst-%s' % instance_ref['id']
1124
1068
if rule.chain == 'provider']
1125
1069
self.assertEqual(0, len(rules))
1071
admin_ctxt = context.get_admin_context()
1127
1072
# add a rule and send the update message, check for 1 rule
1128
1073
provider_fw0 = db.provider_fw_rule_create(admin_ctxt,
1129
1074
{'protocol': 'tcp',
1268
1214
inst.update(params)
1269
1215
return db.instance_type_create(context, inst)['id']
1271
@test.skip_test('Skipping this test')
1272
1217
def test_creates_base_rule_first(self):
1273
1218
# These come pre-defined by libvirt
1274
1219
self.defined_filters = ['no-mac-spoofing',
1300
1245
instance_ref = self._create_instance()
1301
1246
inst_id = instance_ref['id']
1305
#network_ref = db.project_get_networks(self.context, 'fake')[0]
1306
#fixed_ip = {'address': ip, 'network_id': network_ref['id']}
1308
#admin_ctxt = context.get_admin_context()
1309
#db.fixed_ip_create(admin_ctxt, fixed_ip)
1310
#db.fixed_ip_update(admin_ctxt, ip, {'allocated': True,
1311
# 'instance_id': inst_id})
1313
self._setup_networking(instance_ref['id'], ip=ip)
1248
_setup_networking(instance_ref['id'], self.test_ip)
1315
1250
def _ensure_all_called():
1316
1251
instance_filter = 'nova-instance-%s-%s' % (instance_ref['name'],
1318
1253
secgroup_filter = 'nova-secgroup-%s' % self.security_group['id']
1319
1254
for required in [secgroup_filter, 'allow-dhcp-server',
1320
1255
'no-arp-spoofing', 'no-ip-spoofing',
1335
1270
self.fw.apply_instance_filter(instance)
1336
1271
_ensure_all_called()
1337
1272
self.teardown_security_group()
1338
db.instance_destroy(admin_ctxt, instance_ref['id'])
1273
db.instance_destroy(context.get_admin_context(), instance_ref['id'])
1340
1275
def test_create_network_filters(self):
1341
1276
instance_ref = self._create_instance()
1364
1298
instance = db.instance_get(self.context, inst_id)
1367
network_ref = db.project_get_network(self.context, 'fake')
1368
fixed_ip = {'address': ip, 'network_id': network_ref['id']}
1369
db.fixed_ip_create(admin_ctxt, fixed_ip)
1370
db.fixed_ip_update(admin_ctxt, ip, {'allocated': True,
1371
'instance_id': inst_id})
1300
_setup_networking(instance_ref['id'], self.test_ip)
1372
1301
self.fw.setup_basic_filtering(instance)
1373
1302
self.fw.prepare_instance_filter(instance)
1374
1303
self.fw.apply_instance_filter(instance)