~0x44/nova/bug838466

« back to all changes in this revision

Viewing changes to nova/tests/test_libvirt.py

  • Committer: Tarmac
  • Author(s): Vishvananda Ishaya
  • Date: 2011-07-27 21:17:07 UTC
  • mfrom: (1130.8.7 fix-libvirt-skips)
  • Revision ID: tarmac-20110727211707-bckc3o6q26m5739w
Fix all of the skipped libvirt tests.

Show diffs side-by-side

added added

removed removed

Lines of Context:
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})
92
92
 
93
93
 
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'
180
181
 
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()
185
186
 
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)
234
234
 
 
235
            def plug(self, instance, network, mapping):
 
236
                return {
 
237
                    'id': 'fake',
 
238
                    'bridge_name': 'fake',
 
239
                    'mac_address': 'fake',
 
240
                    'ip_address': 'fake',
 
241
                    'dhcp_server': 'fake',
 
242
                    'extra_params': 'fake'
 
243
                }
 
244
 
235
245
        # Creating mocks
236
246
        fake = FakeLibvirtConnection()
237
247
        fakeip = FakeIptablesFirewallDriver
280
290
 
281
291
        return db.service_create(context.get_admin_context(), service_ref)
282
292
 
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)
298
307
 
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)
304
312
 
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)
311
318
 
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)
318
324
 
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)
326
331
 
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)
334
338
 
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,
442
445
                                              user=self.user)
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(),
447
 
                                             self.project.id)[0]
448
 
 
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']}
456
 
 
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,
460
 
                                 {'allocated': True,
461
 
                                  'instance_id': instance_ref['id']})
 
447
        _setup_networking(instance_ref['id'], self.test_ip)
462
448
 
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]
492
478
 
493
 
        _setup_networking(instance_ref['id'], ip=self.test_ip)
 
479
        _setup_networking(instance_ref['id'], self.test_ip)
494
480
 
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'])
754
740
 
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)
773
758
 
774
 
        network = db.project_get_networks(context.get_admin_context(),
775
 
                                          self.project.id)[0]
776
 
        ip_dict = {'ip': self.test_ip,
777
 
                   'netmask': network['netmask'],
778
 
                   'enabled': '1'}
779
 
        mapping = {'label': network['label'],
780
 
                   'gateway': network['gateway'],
781
 
                   'mac': instance['mac_address'],
782
 
                   'dns': [network['dns']],
783
 
                   'ips': [ip_dict]}
784
 
        network_info = [(network, mapping)]
 
759
        network_info = _create_network_info()
785
760
 
786
761
        try:
787
762
            conn.spawn(instance, network_info)
839
814
                """setup_basic_rules in nwfilter calls this."""
840
815
                pass
841
816
        self.fake_libvirt_connection = FakeLibvirtConnection()
 
817
        self.test_ip = '10.11.12.13'
842
818
        self.fw = firewall.IptablesFirewallDriver(
843
819
                      get_connection=lambda: self.fake_libvirt_connection)
844
820
 
904
880
                                   'project_id': 'fake',
905
881
                                   'instance_type_id': 1})
906
882
 
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()
910
 
        ip = '10.11.12.13'
911
 
 
912
 
        network_ref = db.project_get_networks(self.context,
913
 
                                               'fake',
914
 
                                               associate=True)[0]
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)
919
 
 
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)
 
886
 
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']})
927
 
 
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)
1058
1018
 
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,
1067
1026
        self.mox.ReplayAll()
1068
1027
        self.fw.do_refresh_security_group_rules("fake")
1069
1028
 
1070
 
    @test.skip_test("skip libvirt test project_get_network no longer exists")
1071
1029
    def test_unfilter_instance_undefines_nwfilter(self):
1072
1030
        # Skip if non-libvirt environment
1073
1031
        if not self.lazy_load_library_exists():
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)
1086
1042
 
1087
 
        ip = '10.11.12.13'
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)
1098
1049
 
1099
1050
        # should undefine just the instance filter
1100
1051
        self.assertEqual(original_filter_count - len(fakefilter.filters), 1)
1101
1052
 
1102
1053
        db.instance_destroy(admin_ctxt, instance_ref['id'])
1103
1054
 
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)
1109
 
        ip = '10.11.12.13'
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']
1118
1062
 
1124
1068
                      if rule.chain == 'provider']
1125
1069
        self.assertEqual(0, len(rules))
1126
1070
 
 
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',
1182
1127
 
1183
1128
        self.fake_libvirt_connection = Mock()
1184
1129
 
 
1130
        self.test_ip = '10.11.12.13'
1185
1131
        self.fw = firewall.NWFilterFirewall(
1186
1132
                                         lambda: self.fake_libvirt_connection)
1187
1133
 
1268
1214
        inst.update(params)
1269
1215
        return db.instance_type_create(context, inst)['id']
1270
1216
 
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']
1302
1247
 
1303
 
        ip = '10.11.12.13'
1304
 
 
1305
 
        #network_ref = db.project_get_networks(self.context, 'fake')[0]
1306
 
        #fixed_ip = {'address': ip, 'network_id': network_ref['id']}
1307
 
 
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})
1312
 
 
1313
 
        self._setup_networking(instance_ref['id'], ip=ip)
 
1248
        _setup_networking(instance_ref['id'], self.test_ip)
1314
1249
 
1315
1250
        def _ensure_all_called():
1316
1251
            instance_filter = 'nova-instance-%s-%s' % (instance_ref['name'],
1317
 
                                                       '00A0C914C829')
 
1252
                                                       '561212121212')
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'])
1339
1274
 
1340
1275
    def test_create_network_filters(self):
1341
1276
        instance_ref = self._create_instance()
1345
1280
                                                 "fake")
1346
1281
        self.assertEquals(len(result), 3)
1347
1282
 
1348
 
    @test.skip_test("skip libvirt test project_get_network no longer exists")
1349
1283
    def test_unfilter_instance_undefines_nwfilters(self):
1350
1284
        admin_ctxt = context.get_admin_context()
1351
1285
 
1363
1297
 
1364
1298
        instance = db.instance_get(self.context, inst_id)
1365
1299
 
1366
 
        ip = '10.11.12.13'
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)