Browse Source

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
changes/91/532191/6
James Page 1 year ago
parent
commit
e007b5265c
2 changed files with 27 additions and 21 deletions
  1. 22
    19
      ceph/utils.py
  2. 5
    2
      unit_tests/test_mon_upgrade_roll.py

+ 22
- 19
ceph/utils.py View File

@@ -1799,25 +1799,28 @@ def wait_on_previous_node(upgrade_key, service, previous_node, version):
1799 1799
         previous_node_start_time = monitor_key_get(
1800 1800
             upgrade_key,
1801 1801
             "{}_{}_{}_start".format(service, previous_node, version))
1802
-        if (current_timestamp - (10 * 60)) > previous_node_start_time:
1803
-            # Previous node is probably dead. Lets move on
1804
-            if previous_node_start_time is not None:
1805
-                log(
1806
-                    "Waited 10 mins on node {}. current time: {} > "
1807
-                    "previous node start time: {} Moving on".format(
1808
-                        previous_node,
1809
-                        (current_timestamp - (10 * 60)),
1810
-                        previous_node_start_time))
1811
-                return
1812
-        else:
1813
-            # I have to wait. Sleep a random amount of time and then
1814
-            # check if I can lock,upgrade and roll.
1815
-            wait_time = random.randrange(5, 30)
1816
-            log('waiting for {} seconds'.format(wait_time))
1817
-            time.sleep(wait_time)
1818
-            previous_node_finished = monitor_key_exists(
1819
-                upgrade_key,
1820
-                "{}_{}_{}_done".format(service, previous_node, version))
1802
+        if (previous_node_start_time is not None and
1803
+                ((current_timestamp - (10 * 60)) >
1804
+                 float(previous_node_start_time))):
1805
+            # NOTE(jamespage):
1806
+            # Previous node is probably dead as we've been waiting
1807
+            # for 10 minutes - lets move on and upgrade
1808
+            log("Waited 10 mins on node {}. current time: {} > "
1809
+                "previous node start time: {} Moving on".format(
1810
+                    previous_node,
1811
+                    (current_timestamp - (10 * 60)),
1812
+                    previous_node_start_time))
1813
+            return
1814
+        # NOTE(jamespage)
1815
+        # Previous node has not started, or started less than
1816
+        # 10 minutes ago - sleep a random amount of time and
1817
+        # then check again.
1818
+        wait_time = random.randrange(5, 30)
1819
+        log('waiting for {} seconds'.format(wait_time))
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
 
1823 1826
 def get_upgrade_position(osd_sorted_list, match_name):

+ 5
- 2
unit_tests/test_mon_upgrade_roll.py View File

@@ -46,7 +46,10 @@ def monitor_key_side_effect(*args):
46 46
     elif args[1] == \
47 47
             'mon_ip-192-168-1-2_0.94.1_start':
48 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
 
52 55
 class UpgradeRollingTestCase(unittest.TestCase):
@@ -226,4 +229,4 @@ class UpgradeRollingTestCase(unittest.TestCase):
226 229
             [call('Previous node is: ip-192-168-1-2')],
227 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)

Loading…
Cancel
Save