From ae1f1e0008062d6a87806a1dbf56d6eb270d1ba1 Mon Sep 17 00:00:00 2001 From: Emilien Macchi Date: Tue, 30 Oct 2018 16:47:48 -0400 Subject: [PATCH] standalone/undercloud: run post_upgrade_tasks when upgrading This changes the upgrade workflow for the standalone and undercloud where we now run the post_upgrade_tasks after the deployment. So the order is upgrade_tasks, deployment steps (docker/puppet), then post_upgrade_tasks which is the same order as the overcloud. It will allow us to execute some specific post upgrade tasks on standalone and undercloud, like removing Docker containers when upgrading to Podman. Change-Id: I311bfa17a3bbe52850092d501d563d53f7095a24 --- ..._undercloud_standalone-d9914f6b52c237ce.yaml | 9 +++++++++ .../tests/v1/tripleo/test_tripleo_upgrade.py | 14 ++++++++++++++ tripleoclient/v1/tripleo_deploy.py | 17 ++++++++++++++++- 3 files changed, 39 insertions(+), 1 deletion(-) create mode 100644 releasenotes/notes/post_upgrade_tasks_undercloud_standalone-d9914f6b52c237ce.yaml diff --git a/releasenotes/notes/post_upgrade_tasks_undercloud_standalone-d9914f6b52c237ce.yaml b/releasenotes/notes/post_upgrade_tasks_undercloud_standalone-d9914f6b52c237ce.yaml new file mode 100644 index 000000000..4a6dddb21 --- /dev/null +++ b/releasenotes/notes/post_upgrade_tasks_undercloud_standalone-d9914f6b52c237ce.yaml @@ -0,0 +1,9 @@ +--- +features: + - | + This changes the upgrade workflow for the standalone and undercloud + where we now run the post_upgrade_tasks after the deployment. + So the order is upgrade_tasks, deployment steps (docker/puppet), + then post_upgrade_tasks which is the same order as the overcloud. + It will allow us to execute some specific post upgrade tasks on standalone + and undercloud, like removing Docker containers when upgrading to Podman. diff --git a/tripleoclient/tests/v1/tripleo/test_tripleo_upgrade.py b/tripleoclient/tests/v1/tripleo/test_tripleo_upgrade.py index cedff6519..7f344ebd3 100644 --- a/tripleoclient/tests/v1/tripleo/test_tripleo_upgrade.py +++ b/tripleoclient/tests/v1/tripleo/test_tripleo_upgrade.py @@ -44,6 +44,20 @@ class TestUpgrade(utils.TestCommand): 'upgrade_steps_playbook.yaml', '--skip-tags', 'validation']) + @mock.patch('tripleoclient.utils.' + 'run_command_and_log', autospec=True) + @mock.patch('os.chdir') + @mock.patch('os.execvp') + def test_launch_ansible_post_upgrade(self, mock_execvp, mock_chdir, + mock_run): + + self.cmd._launch_ansible_post_upgrade('/tmp') + mock_chdir.assert_called_once() + mock_run.assert_called_once_with(self.cmd.log, [ + 'ansible-playbook', '-i', '/tmp/inventory.yaml', + 'post_upgrade_steps_playbook.yaml', + '--skip-tags', 'validation']) + @mock.patch('tripleoclient.v1.tripleo_deploy.Deploy.take_action', autospec=True) def test_take_action(self, mock_deploy): diff --git a/tripleoclient/v1/tripleo_deploy.py b/tripleoclient/v1/tripleo_deploy.py index cd9a029cf..4a163ed8d 100644 --- a/tripleoclient/v1/tripleo_deploy.py +++ b/tripleoclient/v1/tripleo_deploy.py @@ -803,6 +803,16 @@ class Deploy(command.Command): self.log.debug('Running Ansible Upgrade tasks: %s' % (' '.join(cmd))) return utils.run_command_and_log(self.log, cmd) + def _launch_ansible_post_upgrade(self, ansible_dir): + self.log.warning('** Running ansible post-upgrade tasks **') + os.chdir(ansible_dir) + playbook_inventory = os.path.join(ansible_dir, 'inventory.yaml') + cmd = ['ansible-playbook', '-i', playbook_inventory, + 'post_upgrade_steps_playbook.yaml', '--skip-tags', 'validation'] + self.log.debug('Running Ansible Post Upgrade ' + 'tasks: %s' % (' '.join(cmd))) + return utils.run_command_and_log(self.log, cmd) + def get_parser(self, prog_name): parser = argparse.ArgumentParser( description=self.get_description(), @@ -1146,12 +1156,17 @@ class Deploy(command.Command): if not parsed_args.keep_running: self._kill_heat(parsed_args) if not parsed_args.output_only: - # Run Upgrade tasks before the deployment if parsed_args.upgrade: + # Run Upgrade tasks before the deployment rc = self._launch_ansible_upgrade(self.ansible_dir) if rc != 0: raise exceptions.DeploymentError('Upgrade failed') rc = self._launch_ansible_deploy(self.ansible_dir) + if parsed_args.upgrade: + # Run Post Upgrade tasks after the deployment + rc = self._launch_ansible_post_upgrade(self.ansible_dir) + if rc != 0: + raise exceptions.DeploymentError('Post Upgrade failed') except Exception as e: self.log.error("Exception: %s" % six.text_type(e)) self.log.error(traceback.print_exc())