From dd426903471f28eff8e357bac2ca0889ffcff4b9 Mon Sep 17 00:00:00 2001 From: James Page Date: Wed, 4 Jul 2018 04:57:33 +0100 Subject: [PATCH] Skip udev rule install in containers Ensure that udev rules are not installed and reloaded when running in a container; this is not permitted and the udev rules are used for block devices, which are not supported within container based deployments. Change-Id: I9a580172fcbbf8cec63af7adccb0808915184658 Closes-Bug: 1776713 --- hooks/ceph_hooks.py | 5 +++++ unit_tests/test_ceph_hooks.py | 14 +++++++++++++- 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/hooks/ceph_hooks.py b/hooks/ceph_hooks.py index ce2aba9e..47379f05 100755 --- a/hooks/ceph_hooks.py +++ b/hooks/ceph_hooks.py @@ -55,6 +55,7 @@ from charmhelpers.core.host import ( add_to_updatedb_prunepath, restart_on_change, write_file, + is_container, ) from charmhelpers.fetch import ( add_source, @@ -225,6 +226,10 @@ def install_udev_rules(): Install and reload udev rules for ceph-volume LV permissions """ + if is_container(): + log('Skipping udev rule installation ' + 'as unit is in a container', level=DEBUG) + return for x in glob.glob('files/udev/*'): shutil.copy(x, '/lib/udev/rules.d') subprocess.check_call(['udevadm', 'control', diff --git a/unit_tests/test_ceph_hooks.py b/unit_tests/test_ceph_hooks.py index f2cfa28e..9b660c3a 100644 --- a/unit_tests/test_ceph_hooks.py +++ b/unit_tests/test_ceph_hooks.py @@ -471,9 +471,11 @@ class CephHooksTestCase(unittest.TestCase): config.assert_called_with('availability_zone') environ.get.assert_called_with('JUJU_AVAILABILITY_ZONE') + @patch.object(ceph_hooks, 'is_container') @patch.object(ceph_hooks, 'subprocess') @patch.object(ceph_hooks, 'shutil') - def test_install_udev_rules(self, shutil, subprocess): + def test_install_udev_rules(self, shutil, subprocess, is_container): + is_container.return_value = False ceph_hooks.install_udev_rules() shutil.copy.assert_called_once_with( 'files/udev/95-charm-ceph-osd.rules', @@ -483,6 +485,16 @@ class CephHooksTestCase(unittest.TestCase): ['udevadm', 'control', '--reload-rules'] ) + @patch.object(ceph_hooks, 'is_container') + @patch.object(ceph_hooks, 'subprocess') + @patch.object(ceph_hooks, 'shutil') + def test_install_udev_rules_container(self, shutil, subprocess, + is_container): + is_container.return_value = True + ceph_hooks.install_udev_rules() + shutil.copy.assert_not_called() + subprocess.check_call.assert_not_called() + @patch.object(ceph_hooks, 'config') @patch.object(ceph_hooks, 'cmp_pkgrevno') def test_use_short_objects(self, mock_cmp_pkgrevno, mock_config):