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
1=== modified file 'charmhelpers/contrib/openstack/utils.py'
2--- charmhelpers/contrib/openstack/utils.py 2015-09-16 14:53:33 +0000
3+++ charmhelpers/contrib/openstack/utils.py 2015-09-25 14:25:06 +0000
4@@ -54,7 +54,8 @@
5 )
6
7 from charmhelpers.contrib.network.ip import (
8- get_ipv6_addr
9+ get_ipv6_addr,
10+ is_ipv6,
11 )
12
13 from charmhelpers.contrib.python.packages import (
14@@ -519,6 +520,12 @@
15 relation_prefix=None):
16 hosts = get_ipv6_addr(dynamic_only=False)
17
18+ if config('vip'):
19+ vips = config('vip').split()
20+ for vip in vips:
21+ if vip and is_ipv6(vip):
22+ hosts.append(vip)
23+
24 kwargs = {'database': database,
25 'username': database_user,
26 'hostname': json.dumps(hosts)}
27
28=== modified file 'tests/contrib/openstack/test_os_utils.py'
29--- tests/contrib/openstack/test_os_utils.py 2014-09-30 10:16:32 +0000
30+++ tests/contrib/openstack/test_os_utils.py 2015-09-25 14:25:06 +0000
31@@ -9,12 +9,15 @@
32 def setUp(self):
33 super(UtilsTests, self).setUp()
34
35+ @mock.patch.object(utils, 'config')
36 @mock.patch('charmhelpers.contrib.openstack.utils.relation_set')
37 @mock.patch('charmhelpers.contrib.openstack.utils.relation_ids')
38 @mock.patch('charmhelpers.contrib.openstack.utils.get_ipv6_addr')
39 def test_sync_db_with_multi_ipv6_addresses(self, mock_get_ipv6_addr,
40 mock_relation_ids,
41- mock_relation_set):
42+ mock_relation_set,
43+ mock_config):
44+ mock_config.return_value = None
45 addr1 = '2001:db8:1:0:f816:3eff:fe45:7c/64'
46 addr2 = '2001:db8:1:0:d0cf:528c:23eb:5000/64'
47 mock_get_ipv6_addr.return_value = [addr1, addr2]
48@@ -27,12 +30,15 @@
49 username='testdbuser',
50 hostname=hosts)
51
52+ @mock.patch.object(utils, 'config')
53 @mock.patch('charmhelpers.contrib.openstack.utils.relation_set')
54 @mock.patch('charmhelpers.contrib.openstack.utils.relation_ids')
55 @mock.patch('charmhelpers.contrib.openstack.utils.get_ipv6_addr')
56 def test_sync_db_with_multi_ipv6_addresses_single(self, mock_get_ipv6_addr,
57 mock_relation_ids,
58- mock_relation_set):
59+ mock_relation_set,
60+ mock_config):
61+ mock_config.return_value = None
62 addr1 = '2001:db8:1:0:f816:3eff:fe45:7c/64'
63 mock_get_ipv6_addr.return_value = [addr1]
64 mock_relation_ids.return_value = ['shared-db']
65@@ -44,13 +50,16 @@
66 username='testdbuser',
67 hostname=hosts)
68
69+ @mock.patch.object(utils, 'config')
70 @mock.patch('charmhelpers.contrib.openstack.utils.relation_set')
71 @mock.patch('charmhelpers.contrib.openstack.utils.relation_ids')
72 @mock.patch('charmhelpers.contrib.openstack.utils.get_ipv6_addr')
73 def test_sync_db_with_multi_ipv6_addresses_w_prefix(self,
74 mock_get_ipv6_addr,
75 mock_relation_ids,
76- mock_relation_set):
77+ mock_relation_set,
78+ mock_config):
79+ mock_config.return_value = None
80 addr1 = '2001:db8:1:0:f816:3eff:fe45:7c/64'
81 mock_get_ipv6_addr.return_value = [addr1]
82 mock_relation_ids.return_value = ['shared-db']
83@@ -62,3 +71,27 @@
84 bungabunga_database='testdb',
85 bungabunga_username='testdbuser',
86 bungabunga_hostname=hosts)
87+
88+ @mock.patch.object(utils, 'config')
89+ @mock.patch('charmhelpers.contrib.openstack.utils.relation_set')
90+ @mock.patch('charmhelpers.contrib.openstack.utils.relation_ids')
91+ @mock.patch('charmhelpers.contrib.openstack.utils.get_ipv6_addr')
92+ def test_sync_db_with_multi_ipv6_addresses_vips(self, mock_get_ipv6_addr,
93+ mock_relation_ids,
94+ mock_relation_set,
95+ mock_config):
96+ addr1 = '2001:db8:1:0:f816:3eff:fe45:7c/64'
97+ addr2 = '2001:db8:1:0:d0cf:528c:23eb:5000/64'
98+ vip1 = '2001:db8:1:0:f816:3eff:32b3:7c'
99+ vip2 = '2001:db8:1:0:f816:3eff:32b3:7d'
100+ mock_config.return_value = '%s 10.0.0.1 %s' % (vip1, vip2)
101+
102+ mock_get_ipv6_addr.return_value = [addr1, addr2]
103+ mock_relation_ids.return_value = ['shared-db']
104+
105+ utils.sync_db_with_multi_ipv6_addresses('testdb', 'testdbuser')
106+ hosts = json.dumps([addr1, addr2, vip1, vip2])
107+ mock_relation_set.assert_called_with(relation_id='shared-db',
108+ database='testdb',
109+ username='testdbuser',
110+ hostname=hosts)

Subscribers

People subscribed via source and target branches