From d3cf8bb3aba40f588de63a13531a4d36c84dc09a Mon Sep 17 00:00:00 2001 From: Chris MacNaughton Date: Thu, 16 Feb 2017 14:59:46 -0500 Subject: [PATCH] Only check for upgrades if bootstrapped Only check for upgrade requests if the local unit is installed and bootstrapped, avoiding attempts to upgrade on initial execution of config-changed for trusty UCA pockets. Note that the upgrade process relies on a running ceph cluster. Change-Id: Ia3efe2f8cfdac4317809681e7d169725c6bd9ef2 Closes-Bug: 1662943 --- hooks/ceph_hooks.py | 4 ++++ unit_tests/test_upgrade.py | 35 ++++++++++++++++++++++++++++++++++- 2 files changed, 38 insertions(+), 1 deletion(-) diff --git a/hooks/ceph_hooks.py b/hooks/ceph_hooks.py index 28ccac1..93d58dc 100755 --- a/hooks/ceph_hooks.py +++ b/hooks/ceph_hooks.py @@ -108,6 +108,10 @@ def pretty_print_upgrade_paths(): def check_for_upgrade(): + if not ceph.is_bootstrapped(): + log("Ceph is not bootstrapped, skipping upgrade checks.") + return + release_info = host.lsb_release() if not release_info['DISTRIB_CODENAME'] == 'trusty': log("Invalid upgrade path from {}. Only trusty is currently " diff --git a/unit_tests/test_upgrade.py b/unit_tests/test_upgrade.py index c277405..2d5d7ff 100644 --- a/unit_tests/test_upgrade.py +++ b/unit_tests/test_upgrade.py @@ -17,6 +17,8 @@ def config_side_effect(*args): class UpgradeRollingTestCase(unittest.TestCase): + + @patch('ceph_hooks.ceph.is_bootstrapped') @patch('ceph_hooks.log') @patch('ceph_hooks.ceph.roll_monitor_cluster') @patch('ceph_hooks.ceph.wait_for_all_monitors_to_upgrade') @@ -29,7 +31,9 @@ class UpgradeRollingTestCase(unittest.TestCase): hookenv, wait_for_mons, roll_monitor_cluster, - log): + log, + is_bootstrapped): + is_bootstrapped.return_value = True host.lsb_release.return_value = { 'DISTRIB_CODENAME': 'trusty', } @@ -60,3 +64,32 @@ class UpgradeRollingTestCase(unittest.TestCase): 'upgrade path. Proceeding.') ] ) + + @patch('ceph_hooks.ceph.is_bootstrapped') + @patch('ceph_hooks.log') + @patch('ceph_hooks.ceph.roll_monitor_cluster') + @patch('ceph_hooks.ceph.wait_for_all_monitors_to_upgrade') + @patch('ceph_hooks.hookenv') + @patch('ceph_hooks.host') + @patch('ceph_hooks.ceph.roll_osd_cluster') + def test_check_for_upgrade_not_bootstrapped(self, + roll_osd_cluster, + host, + hookenv, + wait_for_mons, + roll_monitor_cluster, + log, + is_bootstrapped): + is_bootstrapped.return_value = False + host.lsb_release.return_value = { + 'DISTRIB_CODENAME': 'trusty', + } + previous_mock = MagicMock().return_value + previous_mock.previous.return_value = "cloud:trusty-juno" + hookenv.config.side_effect = [previous_mock, + config_side_effect('source')] + check_for_upgrade() + + roll_osd_cluster.assert_not_called() + + roll_monitor_cluster.assert_not_called()