~simonklb/charm-helpers/JUJU_CHARM_DIR

« back to all changes in this revision

Viewing changes to tests/contrib/openstack/test_os_contexts.py

  • Committer: Jorge Niedbalski
  • Date: 2017-03-03 15:24:01 UTC
  • mfrom: (694.2.3 charm-helpers.lp1642430)
  • Revision ID: jorge.niedbalski@canonical.com-20170303152401-b1y19h4xf0atp3dt
[freyes, r=chris.macnaughton,niedbalski] Partial fix for #1642430.

Show diffs side-by-side

added added

removed removed

Lines of Context:
275
275
    }
276
276
}
277
277
 
 
278
CEPH_REL_WITH_PUBLIC_ADDR_PORT = {
 
279
    'ceph:0': {
 
280
        'ceph/0': {
 
281
            'ceph-public-address': '192.168.1.10:1234',
 
282
            'private-address': 'ceph_node1',
 
283
            'auth': 'foo',
 
284
            'key': 'bar',
 
285
        },
 
286
        'ceph/1': {
 
287
            'ceph-public-address': '192.168.1.11:4321',
 
288
            'private-address': 'ceph_node2',
 
289
            'auth': 'foo',
 
290
            'key': 'bar',
 
291
        },
 
292
    }
 
293
}
 
294
 
 
295
CEPH_REL_WITH_PUBLIC_IPv6_ADDR = {
 
296
    'ceph:0': {
 
297
        'ceph/0': {
 
298
            'ceph-public-address': '2001:5c0:9168::1',
 
299
            'private-address': 'ceph_node1',
 
300
            'auth': 'foo',
 
301
            'key': 'bar',
 
302
        },
 
303
        'ceph/1': {
 
304
            'ceph-public-address': '2001:5c0:9168::2',
 
305
            'private-address': 'ceph_node2',
 
306
            'auth': 'foo',
 
307
            'key': 'bar',
 
308
        },
 
309
    }
 
310
}
 
311
 
 
312
CEPH_REL_WITH_PUBLIC_IPv6_ADDR_PORT = {
 
313
    'ceph:0': {
 
314
        'ceph/0': {
 
315
            'ceph-public-address': '[2001:5c0:9168::1]:1234',
 
316
            'private-address': 'ceph_node1',
 
317
            'auth': 'foo',
 
318
            'key': 'bar',
 
319
        },
 
320
        'ceph/1': {
 
321
            'ceph-public-address': '[2001:5c0:9168::2]:4321',
 
322
            'private-address': 'ceph_node2',
 
323
            'auth': 'foo',
 
324
            'key': 'bar',
 
325
        },
 
326
    }
 
327
}
 
328
 
 
329
CEPH_REL_WITH_MULTI_PUBLIC_ADDR = {
 
330
    'ceph:0': {
 
331
        'ceph/0': {
 
332
            'ceph-public-address': '192.168.1.10 192.168.1.20',
 
333
            'private-address': 'ceph_node1',
 
334
            'auth': 'foo',
 
335
            'key': 'bar',
 
336
        },
 
337
        'ceph/1': {
 
338
            'ceph-public-address': '192.168.1.11 192.168.1.21',
 
339
            'private-address': 'ceph_node2',
 
340
            'auth': 'foo',
 
341
            'key': 'bar',
 
342
        },
 
343
    }
 
344
}
 
345
 
278
346
IDENTITY_RELATION_NO_CERT = {
279
347
    'identity-service:0': {
280
348
        'keystone/0': {
513
581
    'get_netmask_for_address',
514
582
    'local_unit',
515
583
    'get_ipv6_addr',
516
 
    'format_ipv6_addr',
517
584
    'mkdir',
518
585
    'write_file',
519
586
    'get_host_ip',
570
637
        self.relation_ids.return_value = ['foo:0']
571
638
        self.related_units.return_value = ['foo/0']
572
639
        self.local_unit.return_value = 'localunit'
573
 
        self.format_ipv6_addr.return_value = None
574
640
        self.get_host_ip.side_effect = lambda hostname: hostname
575
641
        self.kv.side_effect = TestDB
576
642
        self.pwgen.return_value = 'testpassword'
704
770
                     'database_host': 'bar',
705
771
                     'database_type': 'mysql'})
706
772
 
707
 
    def test_shared_db_context_with_ipv6(self):
 
773
    @patch('charmhelpers.contrib.openstack.context.format_ipv6_addr')
 
774
    def test_shared_db_context_with_ipv6(self, format_ipv6_addr):
708
775
        '''Test shared-db context with ipv6'''
709
776
        shared_db = context.SharedDBContext(
710
777
            database='quantum', user='quantum', relation_prefix='quantum')
711
778
        relation = FakeRelation(relation_data=SHARED_DB_RELATION_NAMESPACED)
712
779
        self.relation_get.side_effect = relation.get
713
 
        self.format_ipv6_addr.return_value = '[2001:db8:1::1]'
 
780
        format_ipv6_addr.return_value = '[2001:db8:1::1]'
714
781
        result = shared_db()
715
782
        self.assertIn(
716
783
            call(rid='foo:0', unit='foo/0'),
903
970
        }
904
971
        self.assertEquals(result, expected)
905
972
 
906
 
    def test_identity_service_context_with_ipv6(self):
 
973
    @patch('charmhelpers.contrib.openstack.context.format_ipv6_addr')
 
974
    def test_identity_service_context_with_ipv6(self, format_ipv6_addr):
907
975
        '''Test identity-service context with ipv6'''
908
976
        relation = FakeRelation(relation_data=IDENTITY_SERVICE_RELATION_HTTP)
909
977
        self.relation_get.side_effect = relation.get
910
 
        self.format_ipv6_addr.return_value = '[2001:db8:1::1]'
 
978
        format_ipv6_addr.return_value = '[2001:db8:1::1]'
911
979
        identity_service = context.IdentityServiceContext()
912
980
        result = identity_service()
913
981
        expected = {
1072
1140
        amqp = context.AMQPContext()
1073
1141
        self.assertRaises(context.OSContextError, amqp)
1074
1142
 
1075
 
    def test_amqp_context_with_ipv6(self):
 
1143
    @patch('charmhelpers.contrib.openstack.context.format_ipv6_addr')
 
1144
    def test_amqp_context_with_ipv6(self, format_ipv6_addr):
1076
1145
        '''Test amqp context with ipv6'''
1077
1146
        relation_data = copy(AMQP_AA_RELATION)
1078
1147
        relation = FakeRelation(relation_data=relation_data)
1079
1148
        self.relation_get.side_effect = relation.get
1080
1149
        self.relation_ids.side_effect = relation.relation_ids
1081
1150
        self.related_units.side_effect = relation.relation_units
1082
 
        self.format_ipv6_addr.return_value = '[2001:db8:1::1]'
 
1151
        format_ipv6_addr.return_value = '[2001:db8:1::1]'
1083
1152
        self.config.return_value = AMQP_CONFIG
1084
1153
        amqp = context.AMQPContext()
1085
1154
        result = amqp()
1251
1320
    @patch('os.path.isdir')
1252
1321
    @patch('os.mkdir')
1253
1322
    @patch.object(context, 'ensure_packages')
 
1323
    def test_ceph_context_with_public_addr_and_port(
 
1324
            self, ensure_packages, mkdir, isdir, mock_config):
 
1325
        '''Test ceph context in host with multiple networks with all
 
1326
        relation data'''
 
1327
        isdir.return_value = False
 
1328
        config_dict = {'use-syslog': True}
 
1329
 
 
1330
        def fake_config(key):
 
1331
            return config_dict.get(key)
 
1332
 
 
1333
        mock_config.side_effect = fake_config
 
1334
        relation = FakeRelation(relation_data=CEPH_REL_WITH_PUBLIC_ADDR_PORT)
 
1335
        self.relation_get.side_effect = relation.get
 
1336
        self.relation_ids.side_effect = relation.relation_ids
 
1337
        self.related_units.side_effect = relation.relation_units
 
1338
        ceph = context.CephContext()
 
1339
        result = ceph()
 
1340
        expected = {
 
1341
            'mon_hosts': '192.168.1.10:1234 192.168.1.11:4321',
 
1342
            'auth': 'foo',
 
1343
            'key': 'bar',
 
1344
            'use_syslog': 'true',
 
1345
        }
 
1346
        self.assertEquals(result, expected)
 
1347
        ensure_packages.assert_called_with(['ceph-common'])
 
1348
        mkdir.assert_called_with('/etc/ceph')
 
1349
 
 
1350
    @patch.object(context, 'config')
 
1351
    @patch('os.path.isdir')
 
1352
    @patch('os.mkdir')
 
1353
    @patch.object(context, 'ensure_packages')
 
1354
    def test_ceph_context_with_public_ipv6_addr(self, ensure_packages, mkdir,
 
1355
                                                isdir, mock_config):
 
1356
        '''Test ceph context in host with multiple networks with all
 
1357
        relation data'''
 
1358
        isdir.return_value = False
 
1359
        config_dict = {'use-syslog': True}
 
1360
 
 
1361
        def fake_config(key):
 
1362
            return config_dict.get(key)
 
1363
 
 
1364
        mock_config.side_effect = fake_config
 
1365
        relation = FakeRelation(relation_data=CEPH_REL_WITH_PUBLIC_IPv6_ADDR)
 
1366
        self.relation_get.side_effect = relation.get
 
1367
        self.relation_ids.side_effect = relation.relation_ids
 
1368
        self.related_units.side_effect = relation.relation_units
 
1369
        ceph = context.CephContext()
 
1370
        result = ceph()
 
1371
        expected = {
 
1372
            'mon_hosts': '[2001:5c0:9168::1] [2001:5c0:9168::2]',
 
1373
            'auth': 'foo',
 
1374
            'key': 'bar',
 
1375
            'use_syslog': 'true',
 
1376
        }
 
1377
        self.assertEquals(result, expected)
 
1378
        ensure_packages.assert_called_with(['ceph-common'])
 
1379
        mkdir.assert_called_with('/etc/ceph')
 
1380
 
 
1381
    @patch.object(context, 'config')
 
1382
    @patch('os.path.isdir')
 
1383
    @patch('os.mkdir')
 
1384
    @patch.object(context, 'ensure_packages')
 
1385
    def test_ceph_context_with_public_ipv6_addr_port(
 
1386
            self, ensure_packages, mkdir, isdir, mock_config):
 
1387
        '''Test ceph context in host with multiple networks with all
 
1388
        relation data'''
 
1389
        isdir.return_value = False
 
1390
        config_dict = {'use-syslog': True}
 
1391
 
 
1392
        def fake_config(key):
 
1393
            return config_dict.get(key)
 
1394
 
 
1395
        mock_config.side_effect = fake_config
 
1396
        relation = FakeRelation(
 
1397
            relation_data=CEPH_REL_WITH_PUBLIC_IPv6_ADDR_PORT)
 
1398
        self.relation_get.side_effect = relation.get
 
1399
        self.relation_ids.side_effect = relation.relation_ids
 
1400
        self.related_units.side_effect = relation.relation_units
 
1401
        ceph = context.CephContext()
 
1402
        result = ceph()
 
1403
        expected = {
 
1404
            'mon_hosts': '[2001:5c0:9168::1]:1234 [2001:5c0:9168::2]:4321',
 
1405
            'auth': 'foo',
 
1406
            'key': 'bar',
 
1407
            'use_syslog': 'true',
 
1408
        }
 
1409
        self.assertEquals(result, expected)
 
1410
        ensure_packages.assert_called_with(['ceph-common'])
 
1411
        mkdir.assert_called_with('/etc/ceph')
 
1412
 
 
1413
    @patch.object(context, 'config')
 
1414
    @patch('os.path.isdir')
 
1415
    @patch('os.mkdir')
 
1416
    @patch.object(context, 'ensure_packages')
 
1417
    def test_ceph_context_with_multi_public_addr(
 
1418
            self, ensure_packages, mkdir, isdir, mock_config):
 
1419
        '''Test ceph context in host with multiple networks with all
 
1420
        relation data'''
 
1421
        isdir.return_value = False
 
1422
        config_dict = {'use-syslog': True}
 
1423
 
 
1424
        def fake_config(key):
 
1425
            return config_dict.get(key)
 
1426
 
 
1427
        mock_config.side_effect = fake_config
 
1428
        relation = FakeRelation(relation_data=CEPH_REL_WITH_MULTI_PUBLIC_ADDR)
 
1429
        self.relation_get.side_effect = relation.get
 
1430
        self.relation_ids.side_effect = relation.relation_ids
 
1431
        self.related_units.side_effect = relation.relation_units
 
1432
        ceph = context.CephContext()
 
1433
        result = ceph()
 
1434
        expected = {
 
1435
            'mon_hosts': '192.168.1.10 192.168.1.11 192.168.1.20 192.168.1.21',
 
1436
            'auth': 'foo',
 
1437
            'key': 'bar',
 
1438
            'use_syslog': 'true',
 
1439
        }
 
1440
        self.assertEquals(result, expected)
 
1441
        ensure_packages.assert_called_with(['ceph-common'])
 
1442
        mkdir.assert_called_with('/etc/ceph')
 
1443
 
 
1444
    @patch.object(context, 'config')
 
1445
    @patch('os.path.isdir')
 
1446
    @patch('os.mkdir')
 
1447
    @patch.object(context, 'ensure_packages')
1254
1448
    def test_ceph_context_with_rbd_cache(self, ensure_packages, mkdir, isdir,
1255
1449
                                         mock_config):
1256
1450
        isdir.return_value = False