summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJames Page <james.page@ubuntu.com>2018-01-09 14:13:50 +0000
committerJames Page <james.page@ubuntu.com>2018-01-09 16:02:48 +0000
commite007b5265cd30baccb44adb4c2471fe9d6b8db78 (patch)
treeb8aaab4307ef380aae90c68cd028f9a652f1608f
parent1ccf7c2b251819c518f9a88de4f1e8541a0216fc (diff)
py3: Deal with comparison with str and None
Under Python 3, its not possible to compare a float with an object of type str or NoneType; ensure that these conditions are handled in the conditional which waits for the previous unit in the cluster to complete upgrade before the current unit commences. This change also includes a minor change to the way time span assessed in unit tests for this function. Change-Id: I34e3be4c55976d562497257626a339c72efabbad Closes-Bug: 1742079
Notes
Notes (review): Code-Review+2: Chris MacNaughton <chris.macnaughton@canonical.com> Workflow+1: Chris MacNaughton <chris.macnaughton@canonical.com> Verified+2: Zuul Submitted-by: Zuul Submitted-at: Wed, 10 Jan 2018 09:28:58 +0000 Reviewed-on: https://review.openstack.org/532191 Project: openstack/charms.ceph Branch: refs/heads/master
-rw-r--r--ceph/utils.py41
-rw-r--r--unit_tests/test_mon_upgrade_roll.py7
2 files changed, 27 insertions, 21 deletions
diff --git a/ceph/utils.py b/ceph/utils.py
index 9d6cd3c..cc62538 100644
--- a/ceph/utils.py
+++ b/ceph/utils.py
@@ -1799,25 +1799,28 @@ def wait_on_previous_node(upgrade_key, service, previous_node, version):
1799 previous_node_start_time = monitor_key_get( 1799 previous_node_start_time = monitor_key_get(
1800 upgrade_key, 1800 upgrade_key,
1801 "{}_{}_{}_start".format(service, previous_node, version)) 1801 "{}_{}_{}_start".format(service, previous_node, version))
1802 if (current_timestamp - (10 * 60)) > previous_node_start_time: 1802 if (previous_node_start_time is not None and
1803 # Previous node is probably dead. Lets move on 1803 ((current_timestamp - (10 * 60)) >
1804 if previous_node_start_time is not None: 1804 float(previous_node_start_time))):
1805 log( 1805 # NOTE(jamespage):
1806 "Waited 10 mins on node {}. current time: {} > " 1806 # Previous node is probably dead as we've been waiting
1807 "previous node start time: {} Moving on".format( 1807 # for 10 minutes - lets move on and upgrade
1808 previous_node, 1808 log("Waited 10 mins on node {}. current time: {} > "
1809 (current_timestamp - (10 * 60)), 1809 "previous node start time: {} Moving on".format(
1810 previous_node_start_time)) 1810 previous_node,
1811 return 1811 (current_timestamp - (10 * 60)),
1812 else: 1812 previous_node_start_time))
1813 # I have to wait. Sleep a random amount of time and then 1813 return
1814 # check if I can lock,upgrade and roll. 1814 # NOTE(jamespage)
1815 wait_time = random.randrange(5, 30) 1815 # Previous node has not started, or started less than
1816 log('waiting for {} seconds'.format(wait_time)) 1816 # 10 minutes ago - sleep a random amount of time and
1817 time.sleep(wait_time) 1817 # then check again.
1818 previous_node_finished = monitor_key_exists( 1818 wait_time = random.randrange(5, 30)
1819 upgrade_key, 1819 log('waiting for {} seconds'.format(wait_time))
1820 "{}_{}_{}_done".format(service, previous_node, version)) 1820 time.sleep(wait_time)
1821 previous_node_finished = monitor_key_exists(
1822 upgrade_key,
1823 "{}_{}_{}_done".format(service, previous_node, version))
1821 1824
1822 1825
1823def get_upgrade_position(osd_sorted_list, match_name): 1826def get_upgrade_position(osd_sorted_list, match_name):
diff --git a/unit_tests/test_mon_upgrade_roll.py b/unit_tests/test_mon_upgrade_roll.py
index bf5e01d..6544240 100644
--- a/unit_tests/test_mon_upgrade_roll.py
+++ b/unit_tests/test_mon_upgrade_roll.py
@@ -46,7 +46,10 @@ def monitor_key_side_effect(*args):
46 elif args[1] == \ 46 elif args[1] == \
47 'mon_ip-192-168-1-2_0.94.1_start': 47 'mon_ip-192-168-1-2_0.94.1_start':
48 # Return that the previous node started 9 minutes ago 48 # Return that the previous node started 9 minutes ago
49 return previous_node_start_time 49 # NOTE(jamespage):
50 # Pass back as string as this is what we actually get
51 # from the monitor cluster
52 return str(previous_node_start_time)
50 53
51 54
52class UpgradeRollingTestCase(unittest.TestCase): 55class UpgradeRollingTestCase(unittest.TestCase):
@@ -226,4 +229,4 @@ class UpgradeRollingTestCase(unittest.TestCase):
226 [call('Previous node is: ip-192-168-1-2')], 229 [call('Previous node is: ip-192-168-1-2')],
227 [call('ip-192-168-1-2 is not finished. Waiting')], 230 [call('ip-192-168-1-2 is not finished. Waiting')],
228 ) 231 )
229 self.assertEqual(tval[0], previous_node_start_time + 700) 232 self.assertGreaterEqual(tval[0], previous_node_start_time + 600)