From 3e465ba4f8e3522a27c20dc74d93f5cb5a57984b Mon Sep 17 00:00:00 2001 From: Chris Holcombe Date: Thu, 21 Jul 2016 13:10:14 -0700 Subject: [PATCH] Fix directory ownership as part of upgrade This change ensures that when ceph is upgraded from an older version that uses root to a newer version that uses ceph as the process owner that all directories are chowned. Closes-Bug: 1600338 Change-Id: Ifac8cde6e6ea6f3a366fb40b9ffd261036720310 --- hooks/ceph_hooks.py | 9 +++++++-- unit_tests/test_upgrade_roll.py | 7 +++++++ 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/hooks/ceph_hooks.py b/hooks/ceph_hooks.py index d6240fbb..f2b18bd6 100755 --- a/hooks/ceph_hooks.py +++ b/hooks/ceph_hooks.py @@ -44,8 +44,8 @@ from charmhelpers.core.host import ( mkdir, cmp_pkgrevno, service_stop, - service_start -) + service_start, + chownr) from charmhelpers.fetch import ( add_source, apt_install, @@ -258,6 +258,11 @@ def upgrade_osd(): else: service_stop('ceph-osd-all') apt_install(packages=ceph.PACKAGES, fatal=True) + + # Ensure the ownership of Ceph's directories is correct + chownr(path=os.path.join(os.sep, "var", "lib", "ceph"), + owner=ceph.ceph_user(), + group=ceph.ceph_user()) if ceph.systemd(): for osd_id in ceph.get_local_osd_ids(): service_start('ceph-osd@{}'.format(osd_id)) diff --git a/unit_tests/test_upgrade_roll.py b/unit_tests/test_upgrade_roll.py index a3535b5c..a3a6f260 100644 --- a/unit_tests/test_upgrade_roll.py +++ b/unit_tests/test_upgrade_roll.py @@ -35,6 +35,7 @@ TO_PATCH = [ 'service_stop', 'socket', 'status_set', + 'chownr', ] @@ -87,6 +88,7 @@ class UpgradeRollingTestCase(test_utils.CharmTestCase): def test_upgrade_osd(self): self.config.side_effect = config_side_effect self.ceph.get_version.return_value = "0.80" + self.ceph.ceph_user.return_value = "ceph" self.ceph.systemd.return_value = False ceph_hooks.upgrade_osd() self.service_stop.assert_called_with('ceph-osd-all') @@ -94,6 +96,11 @@ class UpgradeRollingTestCase(test_utils.CharmTestCase): self.status_set.assert_has_calls([ call('maintenance', 'Upgrading osd'), ]) + self.chownr.assert_has_calls( + [ + call(group='ceph', owner='ceph', path='/var/lib/ceph') + ] + ) @patch('ceph_hooks.lock_and_roll') @patch('ceph_hooks.get_upgrade_position')