Merge lp:~niedbalski/charms/trusty/swift-storage/backport-fix-lp1510666 into lp:~openstack-charmers-archive/charms/trusty/swift-storage/trunk

Proposed by Jorge Niedbalski
Status: Merged
Merged at revision: 76
Proposed branch: lp:~niedbalski/charms/trusty/swift-storage/backport-fix-lp1510666
Merge into: lp:~openstack-charmers-archive/charms/trusty/swift-storage/trunk
Diff against target: 119 lines (+55/-3)
3 files modified
charmhelpers/contrib/storage/linux/loopback.py (+10/-0)
lib/swift_storage_utils.py (+19/-2)
unit_tests/test_swift_storage_utils.py (+26/-1)
To merge this branch: bzr merge lp:~niedbalski/charms/trusty/swift-storage/backport-fix-lp1510666
Reviewer Review Type Date Requested Status
Billy Olsen Approve
Review via email: mp+277738@code.launchpad.net

Description of the change

Backport of fix for LP: #1510666

To post a comment you must log in.
Revision history for this message
uosci-testing-bot (uosci-testing-bot) wrote :

charm_lint_check #13926 swift-storage for niedbalski mp277738
    LINT OK: passed

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

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

charm_unit_test #12982 swift-storage for niedbalski mp277738
    UNIT OK: passed

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

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

charm_amulet_test #7909 swift-storage for niedbalski mp277738
    AMULET OK: passed

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

Revision history for this message
Billy Olsen (billy-olsen) wrote :

LGTM, Approved.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'charmhelpers/contrib/storage/linux/loopback.py'
2--- charmhelpers/contrib/storage/linux/loopback.py 2015-10-22 13:25:25 +0000
3+++ charmhelpers/contrib/storage/linux/loopback.py 2015-11-17 17:31:05 +0000
4@@ -76,3 +76,13 @@
5 check_call(cmd)
6
7 return create_loopback(path)
8+
9+
10+def is_mapped_loopback_device(device):
11+ """
12+ Checks if a given device name is an existing/mapped loopback device.
13+ :param device: str: Full path to the device (eg, /dev/loop1).
14+ :returns: str: Path to the backing file if is a loopback device
15+ empty string otherwise
16+ """
17+ return loopback_devices().get(device, "")
18
19=== modified file 'lib/swift_storage_utils.py'
20--- lib/swift_storage_utils.py 2015-10-22 13:25:25 +0000
21+++ lib/swift_storage_utils.py 2015-11-17 17:31:05 +0000
22@@ -27,6 +27,7 @@
23 from charmhelpers.core.host import (
24 mkdir,
25 mount,
26+ fstab_add,
27 service_restart,
28 lsb_release
29 )
30@@ -45,6 +46,10 @@
31 is_device_mounted,
32 )
33
34+from charmhelpers.contrib.storage.linux.loopback import (
35+ is_mapped_loopback_device,
36+)
37+
38 from charmhelpers.contrib.openstack.utils import (
39 configure_installation_source,
40 get_os_codename_install_source,
41@@ -253,8 +258,20 @@
42 _dev = os.path.basename(dev)
43 _mp = os.path.join('/srv', 'node', _dev)
44 mkdir(_mp, owner='swift', group='swift')
45- mount(dev, '/srv/node/%s' % _dev, persist=True,
46- filesystem="xfs")
47+
48+ options = None
49+ loopback_device = is_mapped_loopback_device(dev)
50+
51+ if loopback_device:
52+ dev = loopback_device
53+ options = "loop, defaults"
54+
55+ mountpoint = '/srv/node/%s' % _dev
56+ filesystem = "xfs"
57+
58+ mount(dev, mountpoint, filesystem=filesystem)
59+ fstab_add(dev, mountpoint, filesystem, options=options)
60+
61 check_call(['chown', '-R', 'swift:swift', '/srv/node/'])
62 check_call(['chmod', '-R', '0755', '/srv/node/'])
63
64
65=== modified file 'unit_tests/test_swift_storage_utils.py'
66--- unit_tests/test_swift_storage_utils.py 2015-10-22 13:25:25 +0000
67+++ unit_tests/test_swift_storage_utils.py 2015-11-17 17:31:05 +0000
68@@ -28,6 +28,9 @@
69 '_save_script_rc',
70 'lsb_release',
71 'is_paused',
72+ 'fstab_add',
73+ 'mount',
74+ 'is_mapped_loopback_device',
75 ]
76
77
78@@ -218,6 +221,7 @@
79 @patch.object(swift_utils, 'mkfs_xfs')
80 @patch.object(swift_utils, 'determine_block_devices')
81 def test_setup_storage_overwrite(self, determine, mkfs, clean):
82+ self.is_mapped_loopback_device.return_value = None
83 determine.return_value = ['/dev/vdb']
84 self.test_config.set('overwrite', 'True')
85 swift_utils.setup_storage()
86@@ -225,7 +229,10 @@
87 self.mkdir.assert_called_with('/srv/node/vdb', owner='swift',
88 group='swift')
89 self.mount.assert_called_with('/dev/vdb', '/srv/node/vdb',
90- filesystem='xfs', persist=True)
91+ filesystem='xfs')
92+ self.fstab_add.assert_called_with('/dev/vdb', '/srv/node/vdb',
93+ 'xfs',
94+ options=None)
95 calls = [call(['chown', '-R', 'swift:swift', '/srv/node/']),
96 call(['chmod', '-R', '0755', '/srv/node/'])]
97 self.check_call.assert_has_calls(calls)
98@@ -338,3 +345,21 @@
99 swift_utils.OBJECT_SVCS)
100 for service in services:
101 self.assertIn(call(service), self.service_restart.call_args_list)
102+
103+ @patch.object(swift_utils, "mkfs_xfs")
104+ @patch.object(swift_utils, "determine_block_devices")
105+ def test_setup_storage_img(self, determine, mkfs):
106+ determine.return_value = ["/srv/test.img", ]
107+ self.is_mapped_loopback_device.return_value = "/srv/test.img"
108+ swift_utils.setup_storage()
109+ self.mount.assert_called_with(
110+ "/srv/test.img",
111+ "/srv/node/test.img",
112+ filesystem="xfs",
113+ )
114+ self.fstab_add.assert_called_with(
115+ '/srv/test.img',
116+ '/srv/node/test.img',
117+ 'xfs',
118+ options='loop, defaults'
119+ )

Subscribers

People subscribed via source and target branches