Browse Source

Set upgrade level after each upgrade-node

The upgrade_levels:compute parameter have to be set after each deploy
changes operation on controllers otherwise live-migration of instances
will not work properly.

Change-Id: I98a89b51102371f7a50d8a182dc61d671dbf7151
Partial-Bug: #1624341
changes/60/373860/1
Ilya Kharin 2 years ago
parent
commit
b71daaec85

+ 1
- 0
octane/commands/upgrade_node.py View File

@@ -92,6 +92,7 @@ def upgrade_node(env_id, node_ids, isolated=False, provision=True, roles=None,
92 92
     else:
93 93
         env_util.deploy_changes(env, nodes)
94 94
     call_handlers('postdeploy')
95
+    env_util.set_upgrade_levels_for_controllers(env)
95 96
 
96 97
 
97 98
 def copy_patches_folder_to_nailgun():

+ 1
- 1
octane/handlers/upgrade/compute.py View File

@@ -56,7 +56,7 @@ class ComputeUpgrade(upgrade.UpgradeHandler):
56 56
                 controller, False)
57 57
 
58 58
         seed_version = self.env.data["fuel_version"]
59
-        openstack_release = magic_consts.UPGRADE_LEVELS[seed_version]
59
+        openstack_release = nova.get_upgrade_levels(seed_version)
60 60
         node_util.add_compute_upgrade_levels(self.node, openstack_release)
61 61
 
62 62
         ssh.call(["service", "nova-compute", "restart"], node=self.node)

+ 0
- 7
octane/handlers/upgrade/controller.py View File

@@ -17,7 +17,6 @@ from octane.handlers import upgrade
17 17
 from octane.helpers import transformations
18 18
 from octane import magic_consts
19 19
 from octane.util import env as env_util
20
-from octane.util import node as node_util
21 20
 from octane.util import ssh
22 21
 
23 22
 LOG = logging.getLogger(__name__)
@@ -62,12 +61,6 @@ class ControllerUpgrade(upgrade.UpgradeHandler):
62 61
         return magic_consts.SKIP_CONTROLLER_TASKS
63 62
 
64 63
     def postdeploy(self):
65
-        seed_version = self.env.data["fuel_version"]
66
-        openstack_release = magic_consts.UPGRADE_LEVELS[seed_version]
67
-        node_util.add_compute_upgrade_levels(self.node, openstack_release)
68
-
69
-        node_util.restart_nova_services(self.node)
70
-
71 64
         if self.isolated and self.gateway:
72 65
             # From restore_default_gateway
73 66
             LOG.info("Deleting default route at node %s",

+ 18
- 0
octane/tests/test_env.py View File

@@ -348,3 +348,21 @@ def test_util_env(mocker, api, modified, nodes):
348 348
     env.get_default_facts.return_value = api
349 349
     assert modified == env_util.get_node_default_facts(env, nodes)
350 350
     env.get_default_facts.assert_called_once_with('deployment', nodes=nodes)
351
+
352
+
353
+def test_set_upgrade_levels_for_controllers(mocker):
354
+    env = mock.Mock(data={"fuel_version": "9.1"})
355
+    node = mock.Mock()
356
+
357
+    mock_get_levels = mocker.patch("octane.util.nova.get_upgrade_levels")
358
+    mock_get_levels.return_value = "liberty"
359
+    mock_get_conts = mocker.patch("octane.util.env.get_controllers")
360
+    mock_get_conts.return_value = [node]
361
+    mock_add = mocker.patch("octane.util.node.add_compute_upgrade_levels")
362
+    mock_restart = mocker.patch("octane.util.node.restart_nova_services")
363
+
364
+    env_util.set_upgrade_levels_for_controllers(env)
365
+
366
+    mock_get_levels.assert_called_once_with("9.1")
367
+    mock_add.assert_called_once_with(node, "liberty")
368
+    mock_restart.assert_called_once_with(node)

+ 3
- 0
octane/tests/test_upgrade_node.py View File

@@ -76,6 +76,8 @@ def test_upgrade_node(mocker, node_ids, isolated, provision, roles,
76 76
     mock_deploy_nodes = mocker.patch(
77 77
         "octane.util.env.deploy_nodes_without_tasks"
78 78
     )
79
+    mock_upgrade_levels = mocker.patch(
80
+        "octane.util.env.set_upgrade_levels_for_controllers")
79 81
     mock_deploy_changes = mocker.patch("octane.util.env.deploy_changes")
80 82
     mock_check_isolation = mocker.patch(
81 83
         "octane.commands.upgrade_node.check_isolation")
@@ -102,6 +104,7 @@ def test_upgrade_node(mocker, node_ids, isolated, provision, roles,
102 104
     else:
103 105
         mock_deploy_changes.assert_called_once_with(mock_env, mock_nodes_list)
104 106
         not mock_deploy_nodes.called
107
+    mock_upgrade_levels.assert_called_once_with(mock_env)
105 108
 
106 109
 
107 110
 @pytest.mark.parametrize('node_data,expected_error', [

+ 16
- 0
octane/tests/test_util_nova.py View File

@@ -218,3 +218,19 @@ def test_get_active_instances(mocker, cmd_out, result, node_fqdn):
218 218
         "--status", "ACTIVE",
219 219
         "--minimal"],
220 220
         controller)
221
+
222
+
223
+@pytest.mark.parametrize(("levels", "version", "result", "error"), [
224
+    ({"9.1": "liberty"}, "9.1", "liberty", False),
225
+    ({"9.1": "liberty", "8.0": "kilo"}, "8.0", "kilo", False),
226
+    ({}, "9.1", None, True),
227
+])
228
+def test_get_upgrade_levels(mocker, levels, version, result, error):
229
+    mocker.patch.dict("octane.magic_consts.UPGRADE_LEVELS", levels, clear=True)
230
+    if error:
231
+        msg = ("Could not find suitable upgrade_levels for the "
232
+               "{version} release.".format(version=version))
233
+        with pytest.raises(KeyError, message=msg):
234
+            nova.get_upgrade_levels(version)
235
+    else:
236
+        assert nova.get_upgrade_levels(version) == result

+ 10
- 0
octane/util/env.py View File

@@ -30,6 +30,8 @@ from octane.helpers import transformations
30 30
 from octane import magic_consts
31 31
 from octane.util import disk
32 32
 from octane.util import helpers
33
+from octane.util import node as node_util
34
+from octane.util import nova
33 35
 from octane.util import ssh
34 36
 from octane.util import subprocess
35 37
 
@@ -412,3 +414,11 @@ def copy_fuel_keys(source_env_id, seed_env_id):
412 414
 def get_generated(env_id):
413 415
     return environment_obj.Environment.connection.get_request(
414 416
         'clusters/{0}/generated'.format(env_id))
417
+
418
+
419
+def set_upgrade_levels_for_controllers(env):
420
+    version = env.data["fuel_version"]
421
+    openstack_release = nova.get_upgrade_levels(version)
422
+    for node in get_controllers(env):
423
+        node_util.add_compute_upgrade_levels(node, openstack_release)
424
+        node_util.restart_nova_services(node)

+ 12
- 0
octane/util/nova.py View File

@@ -13,6 +13,7 @@
13 13
 import logging
14 14
 import time
15 15
 
16
+from octane import magic_consts
16 17
 from octane.util import ssh
17 18
 
18 19
 LOG = logging.getLogger(__name__)
@@ -103,3 +104,14 @@ def get_active_instances(controller, node_fqdn):
103 104
         controller)
104 105
     instances = nova_stdout_parser(instances_stdout)
105 106
     return [i["ID"] for i in instances]
107
+
108
+
109
+def get_upgrade_levels(version):
110
+    try:
111
+        release = magic_consts.UPGRADE_LEVELS[version]
112
+    except KeyError:
113
+        LOG.error("Could not find suitable upgrade_levels for the "
114
+                  "{version} release.".format(version=version))
115
+        raise
116
+    else:
117
+        return release

Loading…
Cancel
Save