Merge lp:~hopem/charm-helpers/lp1499643 into lp:charm-helpers

Proposed by Edward Hope-Morley
Status: Merged
Merged at revision: 456
Proposed branch: lp:~hopem/charm-helpers/lp1499643
Merge into: lp:charm-helpers
Diff against target: 110 lines (+44/-4)
2 files modified
charmhelpers/contrib/openstack/utils.py (+8/-1)
tests/contrib/openstack/test_os_utils.py (+36/-3)
To merge this branch: bzr merge lp:~hopem/charm-helpers/lp1499643
Reviewer Review Type Date Requested Status
Liam Young (community) Approve
OpenStack Charmers Pending
Review via email: mp+272405@code.launchpad.net
To post a comment you must log in.
Revision history for this message
Liam Young (gnuoy) wrote :

Approve

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'charmhelpers/contrib/openstack/utils.py'
--- charmhelpers/contrib/openstack/utils.py 2015-09-16 14:53:33 +0000
+++ charmhelpers/contrib/openstack/utils.py 2015-09-25 14:25:06 +0000
@@ -54,7 +54,8 @@
54)54)
5555
56from charmhelpers.contrib.network.ip import (56from charmhelpers.contrib.network.ip import (
57 get_ipv6_addr57 get_ipv6_addr,
58 is_ipv6,
58)59)
5960
60from charmhelpers.contrib.python.packages import (61from charmhelpers.contrib.python.packages import (
@@ -519,6 +520,12 @@
519 relation_prefix=None):520 relation_prefix=None):
520 hosts = get_ipv6_addr(dynamic_only=False)521 hosts = get_ipv6_addr(dynamic_only=False)
521522
523 if config('vip'):
524 vips = config('vip').split()
525 for vip in vips:
526 if vip and is_ipv6(vip):
527 hosts.append(vip)
528
522 kwargs = {'database': database,529 kwargs = {'database': database,
523 'username': database_user,530 'username': database_user,
524 'hostname': json.dumps(hosts)}531 'hostname': json.dumps(hosts)}
525532
=== modified file 'tests/contrib/openstack/test_os_utils.py'
--- tests/contrib/openstack/test_os_utils.py 2014-09-30 10:16:32 +0000
+++ tests/contrib/openstack/test_os_utils.py 2015-09-25 14:25:06 +0000
@@ -9,12 +9,15 @@
9 def setUp(self):9 def setUp(self):
10 super(UtilsTests, self).setUp()10 super(UtilsTests, self).setUp()
1111
12 @mock.patch.object(utils, 'config')
12 @mock.patch('charmhelpers.contrib.openstack.utils.relation_set')13 @mock.patch('charmhelpers.contrib.openstack.utils.relation_set')
13 @mock.patch('charmhelpers.contrib.openstack.utils.relation_ids')14 @mock.patch('charmhelpers.contrib.openstack.utils.relation_ids')
14 @mock.patch('charmhelpers.contrib.openstack.utils.get_ipv6_addr')15 @mock.patch('charmhelpers.contrib.openstack.utils.get_ipv6_addr')
15 def test_sync_db_with_multi_ipv6_addresses(self, mock_get_ipv6_addr,16 def test_sync_db_with_multi_ipv6_addresses(self, mock_get_ipv6_addr,
16 mock_relation_ids,17 mock_relation_ids,
17 mock_relation_set):18 mock_relation_set,
19 mock_config):
20 mock_config.return_value = None
18 addr1 = '2001:db8:1:0:f816:3eff:fe45:7c/64'21 addr1 = '2001:db8:1:0:f816:3eff:fe45:7c/64'
19 addr2 = '2001:db8:1:0:d0cf:528c:23eb:5000/64'22 addr2 = '2001:db8:1:0:d0cf:528c:23eb:5000/64'
20 mock_get_ipv6_addr.return_value = [addr1, addr2]23 mock_get_ipv6_addr.return_value = [addr1, addr2]
@@ -27,12 +30,15 @@
27 username='testdbuser',30 username='testdbuser',
28 hostname=hosts)31 hostname=hosts)
2932
33 @mock.patch.object(utils, 'config')
30 @mock.patch('charmhelpers.contrib.openstack.utils.relation_set')34 @mock.patch('charmhelpers.contrib.openstack.utils.relation_set')
31 @mock.patch('charmhelpers.contrib.openstack.utils.relation_ids')35 @mock.patch('charmhelpers.contrib.openstack.utils.relation_ids')
32 @mock.patch('charmhelpers.contrib.openstack.utils.get_ipv6_addr')36 @mock.patch('charmhelpers.contrib.openstack.utils.get_ipv6_addr')
33 def test_sync_db_with_multi_ipv6_addresses_single(self, mock_get_ipv6_addr,37 def test_sync_db_with_multi_ipv6_addresses_single(self, mock_get_ipv6_addr,
34 mock_relation_ids,38 mock_relation_ids,
35 mock_relation_set):39 mock_relation_set,
40 mock_config):
41 mock_config.return_value = None
36 addr1 = '2001:db8:1:0:f816:3eff:fe45:7c/64'42 addr1 = '2001:db8:1:0:f816:3eff:fe45:7c/64'
37 mock_get_ipv6_addr.return_value = [addr1]43 mock_get_ipv6_addr.return_value = [addr1]
38 mock_relation_ids.return_value = ['shared-db']44 mock_relation_ids.return_value = ['shared-db']
@@ -44,13 +50,16 @@
44 username='testdbuser',50 username='testdbuser',
45 hostname=hosts)51 hostname=hosts)
4652
53 @mock.patch.object(utils, 'config')
47 @mock.patch('charmhelpers.contrib.openstack.utils.relation_set')54 @mock.patch('charmhelpers.contrib.openstack.utils.relation_set')
48 @mock.patch('charmhelpers.contrib.openstack.utils.relation_ids')55 @mock.patch('charmhelpers.contrib.openstack.utils.relation_ids')
49 @mock.patch('charmhelpers.contrib.openstack.utils.get_ipv6_addr')56 @mock.patch('charmhelpers.contrib.openstack.utils.get_ipv6_addr')
50 def test_sync_db_with_multi_ipv6_addresses_w_prefix(self,57 def test_sync_db_with_multi_ipv6_addresses_w_prefix(self,
51 mock_get_ipv6_addr,58 mock_get_ipv6_addr,
52 mock_relation_ids,59 mock_relation_ids,
53 mock_relation_set):60 mock_relation_set,
61 mock_config):
62 mock_config.return_value = None
54 addr1 = '2001:db8:1:0:f816:3eff:fe45:7c/64'63 addr1 = '2001:db8:1:0:f816:3eff:fe45:7c/64'
55 mock_get_ipv6_addr.return_value = [addr1]64 mock_get_ipv6_addr.return_value = [addr1]
56 mock_relation_ids.return_value = ['shared-db']65 mock_relation_ids.return_value = ['shared-db']
@@ -62,3 +71,27 @@
62 bungabunga_database='testdb',71 bungabunga_database='testdb',
63 bungabunga_username='testdbuser',72 bungabunga_username='testdbuser',
64 bungabunga_hostname=hosts)73 bungabunga_hostname=hosts)
74
75 @mock.patch.object(utils, 'config')
76 @mock.patch('charmhelpers.contrib.openstack.utils.relation_set')
77 @mock.patch('charmhelpers.contrib.openstack.utils.relation_ids')
78 @mock.patch('charmhelpers.contrib.openstack.utils.get_ipv6_addr')
79 def test_sync_db_with_multi_ipv6_addresses_vips(self, mock_get_ipv6_addr,
80 mock_relation_ids,
81 mock_relation_set,
82 mock_config):
83 addr1 = '2001:db8:1:0:f816:3eff:fe45:7c/64'
84 addr2 = '2001:db8:1:0:d0cf:528c:23eb:5000/64'
85 vip1 = '2001:db8:1:0:f816:3eff:32b3:7c'
86 vip2 = '2001:db8:1:0:f816:3eff:32b3:7d'
87 mock_config.return_value = '%s 10.0.0.1 %s' % (vip1, vip2)
88
89 mock_get_ipv6_addr.return_value = [addr1, addr2]
90 mock_relation_ids.return_value = ['shared-db']
91
92 utils.sync_db_with_multi_ipv6_addresses('testdb', 'testdbuser')
93 hosts = json.dumps([addr1, addr2, vip1, vip2])
94 mock_relation_set.assert_called_with(relation_id='shared-db',
95 database='testdb',
96 username='testdbuser',
97 hostname=hosts)

Subscribers

People subscribed via source and target branches