From e824b554f0df86495c147fefa99d85bceec1ca38 Mon Sep 17 00:00:00 2001 From: Artem Roma Date: Fri, 18 Mar 2016 14:16:48 +0200 Subject: [PATCH] Add copying of VIPs to node upgrade procedure According to [1] seed cluster must have assigned nodes in order to copying of VIPs to take an effect. Thus needed command call added to upgrade node procedure. [1]: https://bugs.launchpad.net/fuel/+bug/1549254 Change-Id: I5ce2f50333e8993fde317d2853395e0d83260a51 Depends-On: I33670e8f2561be6fe18cec75bfc7ecc056ae2f6b Partial-Bug: #1552744 --- octane/commands/upgrade_node.py | 6 ++++++ octane/fuelclient/copy_vips.py | 35 +++++++++++++++++++++++++++++++++ octane/tests/test_env.py | 10 ++++++++++ octane/util/env.py | 6 ++++++ setup.cfg | 1 + 5 files changed, 58 insertions(+) create mode 100644 octane/fuelclient/copy_vips.py diff --git a/octane/commands/upgrade_node.py b/octane/commands/upgrade_node.py index 1d885008..09091d58 100644 --- a/octane/commands/upgrade_node.py +++ b/octane/commands/upgrade_node.py @@ -53,6 +53,12 @@ def upgrade_node(env_id, node_ids, isolated=False, network_template=None): call_handlers('preupgrade') call_handlers('prepare') env_util.move_nodes(env, nodes) + + # NOTE(aroma): copying of VIPs must be done after node reassignment + # as according to [1] otherwise the operation will not take any effect + # [1]: https://bugs.launchpad.net/fuel/+bug/1549254 + env_util.copy_vips(env) + call_handlers('predeploy') if network_template: env_util.set_network_template(env, network_template) diff --git a/octane/fuelclient/copy_vips.py b/octane/fuelclient/copy_vips.py new file mode 100644 index 00000000..aceffeec --- /dev/null +++ b/octane/fuelclient/copy_vips.py @@ -0,0 +1,35 @@ +# Licensed under the Apache License, Version 2.0 (the "License"); you may +# not use this file except in compliance with the License. You may obtain +# a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +# License for the specific language governing permissions and limitations +# under the License. + +from fuelclient.commands import base +from fuelclient.commands import environment as env_commands + + +class CopyVIPs(env_commands.EnvMixIn, base.BaseCommand): + """Copy VIPs to seed cluster""" + + def get_parser(self, prog_name): + parser = super(CopyVIPs, self).get_parser(prog_name) + parser.add_argument('env_id', + type=str, + help='ID of the environment') + return parser + + def take_action(self, parsed_args): + # NOTE(aroma): while copying of VIPs procedure is not a part of + # fuelclient.objects.Environment the connection will be called directly + self.client._entity_wrapper.connection.post_request( + "clusters/{0}/upgrade/vips".format(parsed_args.env_id)) + + msg = ('VIPs successfully copied from the original cluster to seed ' + 'cluster {0}'.format(parsed_args.env_id)) + self.app.stdout.write(msg) diff --git a/octane/tests/test_env.py b/octane/tests/test_env.py index d50cacf9..641fdcf8 100644 --- a/octane/tests/test_env.py +++ b/octane/tests/test_env.py @@ -124,3 +124,13 @@ TENANT_GET_SAMPLE = """ | name | services | +-------------+-----------------------------------+ """[1:] + + +def test_copy_vips(mock_subprocess): + env_id = -1 + env = mock.Mock(data={'id': env_id}) + env_util.copy_vips(env) + + mock_subprocess.assert_called_once_with( + ['fuel2', 'env', 'copy', 'vips', str(env_id)] + ) diff --git a/octane/util/env.py b/octane/util/env.py index 0c8ebc42..f89ab135 100644 --- a/octane/util/env.py +++ b/octane/util/env.py @@ -235,6 +235,12 @@ def move_nodes(env, nodes): wait_for_nodes(nodes, "provisioned") +def copy_vips(env): + subprocess.call( + ["fuel2", "env", "copy", "vips", str(env.data['id'])] + ) + + def provision_nodes(env, nodes): env.install_selected_nodes('provision', nodes) LOG.info("Nodes provision started. Please wait...") diff --git a/setup.cfg b/setup.cfg index b8cbd3f0..887893f0 100644 --- a/setup.cfg +++ b/setup.cfg @@ -59,3 +59,4 @@ fuelclient = env_clone = octane.fuelclient.clone_env:EnvClone env_move_node = octane.fuelclient.move_node:EnvMoveNode env_clone-ips = octane.fuelclient.clone_ips:CloneIPs + env_copy_vips = octane.fuelclient.copy_vips:CopyVIPs