From 160e5d2d9f332afe6d6581bed0b590153249fdd2 Mon Sep 17 00:00:00 2001 From: Edward Hope-Morley Date: Tue, 14 May 2019 11:28:39 +0100 Subject: [PATCH] Ensure glance-registry-paste.ini exists for <= Q Change-Id: I84360db1522b735a20f4141235b111700935fe58 Closes-Bug: #1812972 --- hooks/glance_utils.py | 10 ++++++++-- unit_tests/test_glance_utils.py | 20 +++++++++++++++++++- 2 files changed, 27 insertions(+), 3 deletions(-) diff --git a/hooks/glance_utils.py b/hooks/glance_utils.py index 1f02898b..ac4b9774 100644 --- a/hooks/glance_utils.py +++ b/hooks/glance_utils.py @@ -539,12 +539,18 @@ def reinstall_paste_ini(force_reinstall=False): is set to True. ''' db = kv() - if not db.get(PASTE_INI_MARKER) or force_reinstall: + reinstall = not db.get(PASTE_INI_MARKER) or force_reinstall + cmp_release = CompareOpenStackReleases(os_release('glance-common')) + + if not os.path.exists(GLANCE_REGISTRY_PASTE) and cmp_release < 'rocky': + # See LP: #1812972 + reinstall = True + + if reinstall: for paste_file in [GLANCE_REGISTRY_PASTE, GLANCE_API_PASTE]: if os.path.exists(paste_file): os.remove(paste_file) - cmp_release = CompareOpenStackReleases(os_release('glance-common')) # glance-registry is deprecated at queens but still # installed. if cmp_release < 'rocky': diff --git a/unit_tests/test_glance_utils.py b/unit_tests/test_glance_utils.py index 4ce683f8..f597fa2b 100644 --- a/unit_tests/test_glance_utils.py +++ b/unit_tests/test_glance_utils.py @@ -385,15 +385,33 @@ class TestGlanceUtils(CharmTestCase): fatal=True ) + @patch.object(os.path, 'exists') + @patch.object(utils, 'os_release') @patch.object(utils, 'kv') - def test_reinstall_paste_ini_idempotent(self, kv): + def test_reinstall_paste_ini_idempotent(self, kv, mock_os_release, + mock_exists): """Ensure that re-running does not re-install files""" + mock_exists.return_value = True + mock_os_release.return_value = "queens" test_kv = SimpleKV() test_kv.set(utils.PASTE_INI_MARKER, True) kv.return_value = test_kv utils.reinstall_paste_ini() self.assertFalse(self.apt_install.called) + @patch.object(os.path, 'exists') + @patch.object(utils, 'os_release') + @patch.object(utils, 'kv') + def test_reinstall_paste_ini_fix_upgrade(self, kv, mock_os_release, + mock_exists): + mock_exists.return_value = False + mock_os_release.return_value = "queens" + test_kv = SimpleKV() + test_kv.set(utils.PASTE_INI_MARKER, True) + kv.return_value = test_kv + utils.reinstall_paste_ini() + self.assertTrue(self.apt_install.called) + def _test_is_api_ready(self, tgt): fake_config = MagicMock() with patch.object(utils, 'incomplete_relation_data') as ird: