Merge lp:~adam-collard/charms/trusty/swift-proxy/lib-in-python-package into lp:~openstack-charmers-archive/charms/trusty/swift-proxy/next

Proposed by Adam Collard
Status: Merged
Merged at revision: 107
Proposed branch: lp:~adam-collard/charms/trusty/swift-proxy/lib-in-python-package
Merge into: lp:~openstack-charmers-archive/charms/trusty/swift-proxy/next
Diff against target: 396 lines (+120/-52)
13 files modified
.coveragerc (+1/-0)
Makefile (+3/-3)
charm-helpers-hooks.yaml (+1/-1)
charmhelpers/contrib/openstack/utils.py (+4/-0)
charmhelpers/contrib/storage/linux/ceph.py (+2/-11)
charmhelpers/core/kernel.py (+68/-0)
hooks/swift_hooks.py (+1/-1)
lib/swift_context.py (+7/-1)
setup.cfg (+1/-1)
unit_tests/__init__.py (+0/-2)
unit_tests/test_swift_context.py (+7/-7)
unit_tests/test_swift_hooks.py (+2/-1)
unit_tests/test_swift_utils.py (+23/-24)
To merge this branch: bzr merge lp:~adam-collard/charms/trusty/swift-proxy/lib-in-python-package
Reviewer Review Type Date Requested Status
Chris Glass (community) Approve
Landscape Pending
Review via email: mp+270304@code.launchpad.net

Description of the change

With the addition of actions to the OpenStack charms, there's a need to share code between actions and hooks. This branch moves library code to a top-level ./lib/ and then symlinks that into ./hooks/lib, likewise for charm-helpers.

This should be a plain refactor with no change in behaviour, but laying the ground for an actions/lib symlink and an actions/charm-helpers symlink.

(see https://code.launchpad.net/~adam-collard/charms/precise/swift-storage/lib-in-python-package/+merge/265105 for the equivalent MP for swift-storage)

To post a comment you must log in.
110. By Adam Collard

Add explanatory comment

Revision history for this message
uosci-testing-bot (uosci-testing-bot) wrote :

charm_lint_check #9540 swift-proxy-next for adam-collard mp270304
    LINT OK: passed

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

Revision history for this message
uosci-testing-bot (uosci-testing-bot) wrote :

charm_unit_test #8781 swift-proxy-next for adam-collard mp270304
    UNIT OK: passed

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

Revision history for this message
Chris Glass (tribaal) wrote :

I think this looks good, small comment inline.

111. By Adam Collard

Add missing @property (tribaal's review)

Revision history for this message
Adam Collard (adam-collard) :
Revision history for this message
Chris Glass (tribaal) wrote :

Looks good!

review: Approve
Revision history for this message
uosci-testing-bot (uosci-testing-bot) wrote :

charm_amulet_test #6311 swift-proxy-next for adam-collard mp270304
    AMULET FAIL: amulet-test failed

AMULET Results (max last 2 lines):
make: *** [test] Error 1
ERROR:root:Make target returned non-zero.

Full amulet test output: http://paste.ubuntu.com/12307641/
Build: http://10.245.162.77:8080/job/charm_amulet_test/6311/

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file '.coveragerc'
--- .coveragerc 2013-11-18 11:16:28 +0000
+++ .coveragerc 2015-09-07 14:15:28 +0000
@@ -4,3 +4,4 @@
4 if __name__ == .__main__.:4 if __name__ == .__main__.:
5include=5include=
6 hooks/swift_*6 hooks/swift_*
7 lib/swift_*
78
=== modified file 'Makefile'
--- Makefile 2015-04-16 21:32:07 +0000
+++ Makefile 2015-09-07 14:15:28 +0000
@@ -1,9 +1,7 @@
1#!/usr/bin/make
2PYTHON := /usr/bin/env python1PYTHON := /usr/bin/env python
32
4lint:3lint:
5 @flake8 --exclude hooks/charmhelpers --ignore=E125 hooks4 @flake8 --exclude hooks unit_tests tests lib
6 @flake8 --exclude hooks/charmhelpers --ignore=E125 unit_tests tests
7 @charm proof5 @charm proof
86
9unit_test:7unit_test:
@@ -29,3 +27,5 @@
29publish: lint unit_test27publish: lint unit_test
30 bzr push lp:charms/swift-proxy28 bzr push lp:charms/swift-proxy
31 bzr push lp:charms/trusty/swift-proxy29 bzr push lp:charms/trusty/swift-proxy
30
31.PHONY: lint unit_test test sync publish
3232
=== modified file 'charm-helpers-hooks.yaml'
--- charm-helpers-hooks.yaml 2015-07-31 13:11:02 +0000
+++ charm-helpers-hooks.yaml 2015-09-07 14:15:28 +0000
@@ -1,5 +1,5 @@
1branch: lp:charm-helpers1branch: lp:charm-helpers
2destination: hooks/charmhelpers2destination: charmhelpers
3include:3include:
4 - core4 - core
5 - cli5 - cli
66
=== renamed directory 'hooks/charmhelpers' => 'charmhelpers'
=== modified file 'charmhelpers/contrib/openstack/utils.py'
--- hooks/charmhelpers/contrib/openstack/utils.py 2015-09-03 09:41:22 +0000
+++ charmhelpers/contrib/openstack/utils.py 2015-09-07 14:15:28 +0000
@@ -114,6 +114,7 @@
114 ('2.2.1', 'kilo'),114 ('2.2.1', 'kilo'),
115 ('2.2.2', 'kilo'),115 ('2.2.2', 'kilo'),
116 ('2.3.0', 'liberty'),116 ('2.3.0', 'liberty'),
117 ('2.4.0', 'liberty'),
117])118])
118119
119# >= Liberty version->codename mapping120# >= Liberty version->codename mapping
@@ -142,6 +143,9 @@
142 'glance-common': OrderedDict([143 'glance-common': OrderedDict([
143 ('11.0.0', 'liberty'),144 ('11.0.0', 'liberty'),
144 ]),145 ]),
146 'openstack-dashboard': OrderedDict([
147 ('8.0.0', 'liberty'),
148 ]),
145}149}
146150
147DEFAULT_LOOPBACK_SIZE = '5G'151DEFAULT_LOOPBACK_SIZE = '5G'
148152
=== modified file 'charmhelpers/contrib/storage/linux/ceph.py'
--- hooks/charmhelpers/contrib/storage/linux/ceph.py 2015-07-29 10:47:50 +0000
+++ charmhelpers/contrib/storage/linux/ceph.py 2015-09-07 14:15:28 +0000
@@ -56,6 +56,8 @@
56 apt_install,56 apt_install,
57)57)
5858
59from charmhelpers.core.kernel import modprobe
60
59KEYRING = '/etc/ceph/ceph.client.{}.keyring'61KEYRING = '/etc/ceph/ceph.client.{}.keyring'
60KEYFILE = '/etc/ceph/ceph.client.{}.key'62KEYFILE = '/etc/ceph/ceph.client.{}.key'
6163
@@ -288,17 +290,6 @@
288 os.chown(data_src_dst, uid, gid)290 os.chown(data_src_dst, uid, gid)
289291
290292
291# TODO: re-use
292def modprobe(module):
293 """Load a kernel module and configure for auto-load on reboot."""
294 log('Loading kernel module', level=INFO)
295 cmd = ['modprobe', module]
296 check_call(cmd)
297 with open('/etc/modules', 'r+') as modules:
298 if module not in modules.read():
299 modules.write(module)
300
301
302def copy_files(src, dst, symlinks=False, ignore=None):293def copy_files(src, dst, symlinks=False, ignore=None):
303 """Copy files from src to dst."""294 """Copy files from src to dst."""
304 for item in os.listdir(src):295 for item in os.listdir(src):
305296
=== added file 'charmhelpers/core/kernel.py'
--- charmhelpers/core/kernel.py 1970-01-01 00:00:00 +0000
+++ charmhelpers/core/kernel.py 2015-09-07 14:15:28 +0000
@@ -0,0 +1,68 @@
1#!/usr/bin/env python
2# -*- coding: utf-8 -*-
3
4# Copyright 2014-2015 Canonical Limited.
5#
6# This file is part of charm-helpers.
7#
8# charm-helpers is free software: you can redistribute it and/or modify
9# it under the terms of the GNU Lesser General Public License version 3 as
10# published by the Free Software Foundation.
11#
12# charm-helpers is distributed in the hope that it will be useful,
13# but WITHOUT ANY WARRANTY; without even the implied warranty of
14# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15# GNU Lesser General Public License for more details.
16#
17# You should have received a copy of the GNU Lesser General Public License
18# along with charm-helpers. If not, see <http://www.gnu.org/licenses/>.
19
20__author__ = "Jorge Niedbalski <jorge.niedbalski@canonical.com>"
21
22from charmhelpers.core.hookenv import (
23 log,
24 INFO
25)
26
27from subprocess import check_call, check_output
28import re
29
30
31def modprobe(module, persist=True):
32 """Load a kernel module and configure for auto-load on reboot."""
33 cmd = ['modprobe', module]
34
35 log('Loading kernel module %s' % module, level=INFO)
36
37 check_call(cmd)
38 if persist:
39 with open('/etc/modules', 'r+') as modules:
40 if module not in modules.read():
41 modules.write(module)
42
43
44def rmmod(module, force=False):
45 """Remove a module from the linux kernel"""
46 cmd = ['rmmod']
47 if force:
48 cmd.append('-f')
49 cmd.append(module)
50 log('Removing kernel module %s' % module, level=INFO)
51 return check_call(cmd)
52
53
54def lsmod():
55 """Shows what kernel modules are currently loaded"""
56 return check_output(['lsmod'],
57 universal_newlines=True)
58
59
60def is_module_loaded(module):
61 """Checks if a kernel module is already loaded"""
62 matches = re.findall('^%s[ ]+' % module, lsmod(), re.M)
63 return len(matches) > 0
64
65
66def update_initramfs(version='all'):
67 """Updates an initramfs image"""
68 return check_call(["update-initramfs", "-k", version, "-u"])
069
=== modified file 'hooks/swift_hooks.py'
--- hooks/swift_hooks.py 2015-05-11 08:04:17 +0000
+++ hooks/swift_hooks.py 2015-09-07 14:15:28 +0000
@@ -8,7 +8,7 @@
8 CalledProcessError,8 CalledProcessError,
9)9)
1010
11from swift_utils import (11from lib.swift_utils import (
12 SwiftProxyCharmException,12 SwiftProxyCharmException,
13 register_configs,13 register_configs,
14 restart_map,14 restart_map,
1515
=== added directory 'lib'
=== added file 'lib/__init__.py'
=== renamed file 'hooks/swift_context.py' => 'lib/swift_context.py'
--- hooks/swift_context.py 2015-04-13 22:57:02 +0000
+++ lib/swift_context.py 2015-09-07 14:15:28 +0000
@@ -50,9 +50,15 @@
5050
51class ApacheSSLContext(SSLContext):51class ApacheSSLContext(SSLContext):
52 interfaces = ['https']52 interfaces = ['https']
53 external_ports = [config('bind-port')]
54 service_namespace = 'swift'53 service_namespace = 'swift'
5554
55 # We make this a property so that we avoid import-time
56 # dependencies on config()
57
58 @property
59 def external_ports(self):
60 return [config('bind-port')]
61
5662
57class SwiftRingContext(OSContextGenerator):63class SwiftRingContext(OSContextGenerator):
5864
5965
=== renamed file 'hooks/swift_utils.py' => 'lib/swift_utils.py'
=== modified file 'setup.cfg'
--- setup.cfg 2013-11-18 11:16:28 +0000
+++ setup.cfg 2015-09-07 14:15:28 +0000
@@ -2,4 +2,4 @@
2verbosity=12verbosity=1
3with-coverage=13with-coverage=1
4cover-erase=14cover-erase=1
5cover-package=hooks5cover-package=lib,swift_hooks
66
=== modified file 'unit_tests/__init__.py'
--- unit_tests/__init__.py 2013-11-18 11:16:28 +0000
+++ unit_tests/__init__.py 2015-09-07 14:15:28 +0000
@@ -1,2 +0,0 @@
1import sys
2sys.path.append('hooks')
30
=== modified file 'unit_tests/test_swift_context.py'
--- unit_tests/test_swift_context.py 2014-12-01 23:54:03 +0000
+++ unit_tests/test_swift_context.py 2015-09-07 14:15:28 +0000
@@ -6,12 +6,12 @@
66
77
8with mock.patch('charmhelpers.core.hookenv.config'):8with mock.patch('charmhelpers.core.hookenv.config'):
9 import swift_context9 import lib.swift_context as swift_context
1010
1111
12class SwiftContextTestCase(unittest.TestCase):12class SwiftContextTestCase(unittest.TestCase):
1313
14 @mock.patch('swift_context.config')14 @mock.patch('lib.swift_context.config')
15 def test_get_swift_hash_file(self, mock_config):15 def test_get_swift_hash_file(self, mock_config):
16 expected = '##FILEHASH##'16 expected = '##FILEHASH##'
17 with tempfile.NamedTemporaryFile() as tmpfile:17 with tempfile.NamedTemporaryFile() as tmpfile:
@@ -24,7 +24,7 @@
24 self.assertFalse(mock_config.called)24 self.assertFalse(mock_config.called)
25 self.assertEqual(expected, hash)25 self.assertEqual(expected, hash)
2626
27 @mock.patch('swift_context.config')27 @mock.patch('lib.swift_context.config')
28 def test_get_swift_hash_config(self, mock_config):28 def test_get_swift_hash_config(self, mock_config):
29 expected = '##CFGHASH##'29 expected = '##CFGHASH##'
30 mock_config.return_value = expected30 mock_config.return_value = expected
@@ -38,8 +38,8 @@
38 self.assertTrue(mock_config.called)38 self.assertTrue(mock_config.called)
39 self.assertEqual(expected, hash)39 self.assertEqual(expected, hash)
4040
41 @mock.patch('swift_context.service_name')41 @mock.patch('lib.swift_context.service_name')
42 @mock.patch('swift_context.config')42 @mock.patch('lib.swift_context.config')
43 def test_get_swift_hash_env(self, mock_config, mock_service_name):43 def test_get_swift_hash_env(self, mock_config, mock_service_name):
44 mock_config.return_value = None44 mock_config.return_value = None
45 mock_service_name.return_value = "testsvc"45 mock_service_name.return_value = "testsvc"
@@ -47,10 +47,10 @@
47 swift_context.SWIFT_HASH_FILE = tmpfile47 swift_context.SWIFT_HASH_FILE = tmpfile
48 with mock.patch('swift_context.os.environ.get') as mock_env_get:48 with mock.patch('swift_context.os.environ.get') as mock_env_get:
49 mock_env_get.return_value = str(uuid.uuid4())49 mock_env_get.return_value = str(uuid.uuid4())
50 hash = swift_context.get_swift_hash()50 hash_ = swift_context.get_swift_hash()
51 mock_env_get.assert_called_with('JUJU_ENV_UUID')51 mock_env_get.assert_called_with('JUJU_ENV_UUID')
5252
53 with open(tmpfile, 'r') as fd:53 with open(tmpfile, 'r') as fd:
54 self.assertEqual(hash, fd.read())54 self.assertEqual(hash_, fd.read())
5555
56 self.assertTrue(mock_config.called)56 self.assertTrue(mock_config.called)
5757
=== modified file 'unit_tests/test_swift_hooks.py'
--- unit_tests/test_swift_hooks.py 2015-06-11 23:22:54 +0000
+++ unit_tests/test_swift_hooks.py 2015-09-07 14:15:28 +0000
@@ -1,8 +1,9 @@
1from mock import patch1from mock import patch
2import sys
2import unittest3import unittest
3import uuid4import uuid
45
56sys.path.append("hooks")
6with patch('charmhelpers.core.hookenv.log'):7with patch('charmhelpers.core.hookenv.log'):
7 import swift_hooks8 import swift_hooks
89
910
=== modified file 'unit_tests/test_swift_utils.py'
--- unit_tests/test_swift_utils.py 2014-12-18 11:58:28 +0000
+++ unit_tests/test_swift_utils.py 2015-09-07 14:15:28 +0000
@@ -5,9 +5,8 @@
5import uuid5import uuid
6import unittest6import unittest
77
8
9with mock.patch('charmhelpers.core.hookenv.config'):8with mock.patch('charmhelpers.core.hookenv.config'):
10 import swift_utils9 import lib.swift_utils as swift_utils
1110
1211
13def init_ring_paths(tmpdir):12def init_ring_paths(tmpdir):
@@ -21,16 +20,16 @@
2120
22class SwiftUtilsTestCase(unittest.TestCase):21class SwiftUtilsTestCase(unittest.TestCase):
2322
24 @mock.patch('swift_utils.get_broker_token')23 @mock.patch('lib.swift_utils.get_broker_token')
25 @mock.patch('swift_utils.update_www_rings')24 @mock.patch('lib.swift_utils.update_www_rings')
26 @mock.patch('swift_utils.get_builders_checksum')25 @mock.patch('lib.swift_utils.get_builders_checksum')
27 @mock.patch('swift_utils.get_rings_checksum')26 @mock.patch('lib.swift_utils.get_rings_checksum')
28 @mock.patch('swift_utils.balance_rings')27 @mock.patch('lib.swift_utils.balance_rings')
29 @mock.patch('swift_utils.log')28 @mock.patch('lib.swift_utils.log')
30 @mock.patch('swift_utils.os.path.exists')29 @mock.patch('lib.swift_utils.os.path.exists')
31 @mock.patch('swift_utils.is_elected_leader')30 @mock.patch('lib.swift_utils.is_elected_leader')
32 @mock.patch('swift_utils.get_min_part_hours')31 @mock.patch('lib.swift_utils.get_min_part_hours')
33 @mock.patch('swift_utils.set_min_part_hours')32 @mock.patch('lib.swift_utils.set_min_part_hours')
34 def test_update_rings(self, mock_set_min_hours,33 def test_update_rings(self, mock_set_min_hours,
35 mock_get_min_hours,34 mock_get_min_hours,
36 mock_is_elected_leader, mock_path_exists,35 mock_is_elected_leader, mock_path_exists,
@@ -76,13 +75,13 @@
76 self.assertTrue(mock_set_min_hours.called)75 self.assertTrue(mock_set_min_hours.called)
77 self.assertTrue(mock_balance_rings.called)76 self.assertTrue(mock_balance_rings.called)
7877
79 @mock.patch('swift_utils.get_broker_token')78 @mock.patch('lib.swift_utils.get_broker_token')
80 @mock.patch('swift_utils.balance_rings')79 @mock.patch('lib.swift_utils.balance_rings')
81 @mock.patch('swift_utils.log')80 @mock.patch('lib.swift_utils.log')
82 @mock.patch('swift_utils.is_elected_leader')81 @mock.patch('lib.swift_utils.is_elected_leader')
83 @mock.patch('swift_utils.config')82 @mock.patch('lib.swift_utils.config')
84 @mock.patch('swift_utils.update_www_rings')83 @mock.patch('lib.swift_utils.update_www_rings')
85 @mock.patch('swift_utils.cluster_sync_rings')84 @mock.patch('lib.swift_utils.cluster_sync_rings')
86 def test_sync_builders_and_rings_if_changed(self, mock_cluster_sync_rings,85 def test_sync_builders_and_rings_if_changed(self, mock_cluster_sync_rings,
87 mock_update_www_rings,86 mock_update_www_rings,
88 mock_config,87 mock_config,
@@ -114,7 +113,7 @@
114 self.assertTrue(mock_update_www_rings.called)113 self.assertTrue(mock_update_www_rings.called)
115 self.assertTrue(mock_cluster_sync_rings.called)114 self.assertTrue(mock_cluster_sync_rings.called)
116115
117 @mock.patch('swift_utils.get_www_dir')116 @mock.patch('lib.swift_utils.get_www_dir')
118 def test_mark_www_rings_deleted(self, mock_get_www_dir):117 def test_mark_www_rings_deleted(self, mock_get_www_dir):
119 try:118 try:
120 tmpdir = tempfile.mkdtemp()119 tmpdir = tempfile.mkdtemp()
@@ -123,7 +122,7 @@
123 finally:122 finally:
124 shutil.rmtree(tmpdir)123 shutil.rmtree(tmpdir)
125124
126 @mock.patch('swift_utils.uuid')125 @mock.patch('lib.swift_utils.uuid')
127 def test_cluster_rpc_stop_proxy_request(self, mock_uuid):126 def test_cluster_rpc_stop_proxy_request(self, mock_uuid):
128 mock_uuid.uuid4.return_value = 'test-uuid'127 mock_uuid.uuid4.return_value = 'test-uuid'
129 rpc = swift_utils.SwiftProxyClusterRPC()128 rpc = swift_utils.SwiftProxyClusterRPC()
@@ -147,7 +146,7 @@
147 'stop-proxy-service-ack': None,146 'stop-proxy-service-ack': None,
148 'sync-only-builders': None}, rq)147 'sync-only-builders': None}, rq)
149148
150 @mock.patch('swift_utils.uuid')149 @mock.patch('lib.swift_utils.uuid')
151 def test_cluster_rpc_stop_proxy_ack(self, mock_uuid):150 def test_cluster_rpc_stop_proxy_ack(self, mock_uuid):
152 mock_uuid.uuid4.return_value = 'token2'151 mock_uuid.uuid4.return_value = 'token2'
153 rpc = swift_utils.SwiftProxyClusterRPC()152 rpc = swift_utils.SwiftProxyClusterRPC()
@@ -161,7 +160,7 @@
161 'stop-proxy-service-ack': 'token1',160 'stop-proxy-service-ack': 'token1',
162 'sync-only-builders': None}, rq)161 'sync-only-builders': None}, rq)
163162
164 @mock.patch('swift_utils.uuid')163 @mock.patch('lib.swift_utils.uuid')
165 def test_cluster_rpc_sync_request(self, mock_uuid):164 def test_cluster_rpc_sync_request(self, mock_uuid):
166 mock_uuid.uuid4.return_value = 'token2'165 mock_uuid.uuid4.return_value = 'token2'
167 rpc = swift_utils.SwiftProxyClusterRPC()166 rpc = swift_utils.SwiftProxyClusterRPC()
@@ -175,7 +174,7 @@
175 'stop-proxy-service-ack': None,174 'stop-proxy-service-ack': None,
176 'sync-only-builders': None}, rq)175 'sync-only-builders': None}, rq)
177176
178 @mock.patch('swift_utils.uuid')177 @mock.patch('lib.swift_utils.uuid')
179 def test_cluster_rpc_notify_leader_changed(self, mock_uuid):178 def test_cluster_rpc_notify_leader_changed(self, mock_uuid):
180 mock_uuid.uuid4.return_value = 'token1'179 mock_uuid.uuid4.return_value = 'token1'
181 rpc = swift_utils.SwiftProxyClusterRPC()180 rpc = swift_utils.SwiftProxyClusterRPC()

Subscribers

People subscribed via source and target branches