Merge lp:~hopem/charms/trusty/swift-proxy/support-rsync-acl into lp:~openstack-charmers-archive/charms/trusty/swift-proxy/next

Proposed by Edward Hope-Morley on 2015-11-24
Status: Superseded
Proposed branch: lp:~hopem/charms/trusty/swift-proxy/support-rsync-acl
Merge into: lp:~openstack-charmers-archive/charms/trusty/swift-proxy/next
Diff against target: 142 lines (+81/-12)
2 files modified
hooks/swift_hooks.py (+50/-11)
unit_tests/test_swift_hooks.py (+31/-1)
To merge this branch: bzr merge lp:~hopem/charms/trusty/swift-proxy/support-rsync-acl
Reviewer Review Type Date Requested Status
James Page 2015-11-24 Needs Fixing on 2015-11-27
Review via email: mp+278426@code.launchpad.net

This proposal has been superseded by a proposal from 2015-11-27.

To post a comment you must log in.
Edward Hope-Morley (hopem) wrote :

Before:
    ubuntu@dev:~$ juju ssh swift-storage-z1/0 "sudo grep 'hosts allow' /etc/rsync-juju.d/050-swift-storage.conf"
    ubuntu@dev:~$
    ubuntu@dev:~$ tmp=`mktemp -d`; rsync -var $tmp swift@`juju-deployer -f swift-storage-z1`::object; rm -rf $tmp
    2015-11-24 12:07:09 Service: swift-storage-z1 address: 10.5.16.232
    sending incremental file list
    tmp.wcuTXHLGnG/

    sent 84 bytes received 20 bytes 208.00 bytes/sec
    total size is 0 speedup is 0.00

After:
    ubuntu@dev:~$ juju ssh swift-storage-z1/0 "sudo grep 'hosts allow' /etc/rsync-juju.d/050-swift-storage.conf"
    hosts allow = 10.5.16.242 10.5.16.243 10.5.16.244
    hosts allow = 10.5.16.242 10.5.16.243 10.5.16.244
    hosts allow = 10.5.16.242 10.5.16.243 10.5.16.244

    ubuntu@dev:~$ tmp=`mktemp -d`; rsync -var $tmp swift@`juju-deployer -f swift-storage-z1`::object; rm -rf $tmp
    2015-11-24 13:02:58 Service: swift-storage-z1 address: 10.5.16.242
    @ERROR: access denied to object from UNKNOWN (10.5.0.3)
    rsync error: error starting client-server protocol (code 5) at main.c(1653) [sender=3.1.0]

charm_lint_check #14308 swift-proxy-next for hopem mp278426
    LINT OK: passed

Build: http://10.245.162.77:8080/job/charm_lint_check/14308/

charm_unit_test #13337 swift-proxy-next for hopem mp278426
    UNIT OK: passed

Build: http://10.245.162.77:8080/job/charm_unit_test/13337/

charm_amulet_test #8026 swift-proxy-next for hopem mp278426
    AMULET OK: passed

Build: http://10.245.162.77:8080/job/charm_amulet_test/8026/

James Page (james-page) :
review: Needs Fixing
Edward Hope-Morley (hopem) :
128. By Edward Hope-Morley on 2015-11-27

remove unit from relation_set

Ryan Beisner (1chb1n) wrote :

FYI, re-running amulet test...

charm_amulet_test #8051 swift-proxy-next for hopem mp278426
    AMULET OK: passed

Build: http://10.245.162.77:8080/job/charm_amulet_test/8051/

Unmerged revisions

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'hooks/swift_hooks.py'
2--- hooks/swift_hooks.py 2015-11-06 18:33:58 +0000
3+++ hooks/swift_hooks.py 2015-11-27 09:48:56 +0000
4@@ -2,6 +2,7 @@
5
6 import os
7 import sys
8+import time
9
10 from subprocess import (
11 check_call,
12@@ -192,6 +193,43 @@
13 mark_www_rings_deleted()
14
15
16+def get_host_ip(rid=None, unit=None):
17+ addr = relation_get('private-address', rid=rid, unit=unit)
18+ if config('prefer-ipv6'):
19+ host_ip = format_ipv6_addr(addr)
20+ if host_ip:
21+ return host_ip
22+ else:
23+ msg = ("Did not get IPv6 address from storage relation "
24+ "(got=%s)" % (addr))
25+ log(msg, level=WARNING)
26+
27+ return openstack.get_host_ip(addr)
28+
29+
30+def update_rsync_acls():
31+ """Get Host IP of each storage unit and broadcast acl to all units."""
32+ hosts = []
33+
34+ if not is_elected_leader(SWIFT_HA_RES):
35+ log("Skipping rsync acl update since not leader", level=DEBUG)
36+ return
37+
38+ # Get all unit addresses
39+ for rid in relation_ids('swift-storage'):
40+ for unit in related_units(rid):
41+ hosts.append(get_host_ip(rid=rid, unit=unit))
42+
43+ rsync_hosts = ' '.join(hosts)
44+ log("Broadcasting acl '%s' to all storage units" % (rsync_hosts),
45+ level=DEBUG)
46+ # We add a timestamp so that the storage units know which is the newest
47+ settings = {'rsync_allowed_hosts': rsync_hosts,
48+ 'timestamp': time.time()}
49+ for rid in relation_ids('swift-storage'):
50+ relation_set(relation_id=rid, **settings)
51+
52+
53 @hooks.hook('swift-storage-relation-changed')
54 @pause_aware_restart_on_change(restart_map())
55 def storage_changed():
56@@ -206,17 +244,13 @@
57 return
58
59 log("Leader established, updating ring builders", level=INFO)
60- addr = relation_get('private-address')
61- if config('prefer-ipv6'):
62- host_ip = format_ipv6_addr(addr)
63- if not host_ip:
64- msg = ("Did not get IPv6 address from storage relation "
65- "(got=%s)" % (addr))
66- log(msg, level=WARNING)
67- host_ip = addr
68- return
69- else:
70- host_ip = openstack.get_host_ip(addr)
71+ host_ip = get_host_ip()
72+ if not host_ip:
73+ log("No host ip found in storage relation - deferring storage "
74+ "relation", level=WARNING)
75+ return
76+
77+ update_rsync_acls()
78
79 zone = get_zone(config('zone-assignment'))
80 node_settings = {
81@@ -540,6 +574,11 @@
82 nrpe_setup.write()
83
84
85+@hooks.hook('upgrade-charm')
86+def upgrade_charm():
87+ update_rsync_acls()
88+
89+
90 def main():
91 try:
92 hooks.execute(sys.argv)
93
94=== added symlink 'hooks/upgrade-charm'
95=== target is u'swift_hooks.py'
96=== modified file 'unit_tests/test_swift_hooks.py'
97--- unit_tests/test_swift_hooks.py 2015-10-13 12:59:52 +0000
98+++ unit_tests/test_swift_hooks.py 2015-11-27 09:48:56 +0000
99@@ -1,8 +1,12 @@
100-from mock import patch
101 import sys
102 import unittest
103 import uuid
104
105+from mock import (
106+ call,
107+ patch,
108+)
109+
110 sys.path.append("hooks")
111 with patch('charmhelpers.core.hookenv.log'):
112 with patch('lib.swift_utils.is_paused') as is_paused:
113@@ -129,3 +133,29 @@
114 requested_roles='Operator,Monitor',
115 relation_id=None
116 )
117+
118+ @patch.object(swift_hooks.time, 'time')
119+ @patch.object(swift_hooks, 'get_host_ip')
120+ @patch.object(swift_hooks, 'is_elected_leader')
121+ @patch.object(swift_hooks, 'related_units')
122+ @patch.object(swift_hooks, 'relation_ids')
123+ @patch.object(swift_hooks, 'relation_set')
124+ def test_update_rsync_acls(self, mock_rel_set, mock_rel_ids,
125+ mock_rel_units, mock_is_leader,
126+ mock_get_host_ip, mock_time):
127+ mock_time.return_value = 1234
128+ mock_is_leader.return_value = True
129+ mock_rel_ids.return_value = ['storage:1']
130+ mock_rel_units.return_value = ['unit/0', 'unit/1']
131+
132+ def fake_get_host_ip(rid, unit):
133+ if unit == 'unit/0':
134+ return '10.0.0.1'
135+ elif unit == 'unit/1':
136+ return '10.0.0.2'
137+
138+ mock_get_host_ip.side_effect = fake_get_host_ip
139+ swift_hooks.update_rsync_acls()
140+ calls = [call(rsync_allowed_hosts='10.0.0.1 10.0.0.2',
141+ relation_id='storage:1', timestamp=1234)]
142+ mock_rel_set.assert_has_calls(calls)

Subscribers

People subscribed via source and target branches