Automating Undercloud backups and a Mistral introduction for creating workbooks, workflows and actions

The goal of this developer documentation is to address the automated process
of backing up a TripleO Undercloud and to give developers a complete description
about how to integrate Mistral workbooks, workflows and actions into the Python
TripleO client.

Creating Mistral workflows for the new python-tripleoclient CLI command.

Give support for new Mistral environment variables when installing the
undercloud.

Show how to test locally the changes in python-tripleoclient and
tripleo-common.

Give elevated privileges to specific Mistral actions that need to run with
elevated privileges.

Debugging actions

Unit tests

Why all previous sections are related to Upgrades?

1. Introduction and prerequisites

Let’s assume you have a TripleO development environment healthy and working
properly. All the commands and customization we are going to run will run in
the Undercloud, as usual logged in as the stack user and having sourced the
stackrc file.

Then let’s proceed by cloning the repositories we are going to work with in a
temporary folder:

In this case, we will create a loop within the tripleoclient and wait until we receive
a message from the Mistral workflow tripleo.undercloud_backup.v1.prepare_environment
that indicates if the invoked workflow ended correctly.

4. Creating Mistral workflows for the new python-tripleoclient CLI command.

The next step is to define the
tripleo.undercloud_backup.v1.prepare_environment Mistral workflow, all the
Mistral workbooks, workflows and actions will be defined in the
tripleo-common repository.

The workflow its self explanatory, the only not so clear part might be the last
one as the workflow uses an action to send a message stating that the workflow
ended correctly. Passing as the message the output of the previous task, in
this case the result of the create_backup_dir.

5. Give support for new Mistral environment variables when installing the undercloud.

Sometimes is needed to use additional values inside a Mistral task. For example,
if we need to create a dump of a database we might need another that the
Mistral user credentials for authentication purposes.

Initially when the Undercloud is installed it’s
created a Mistral environment called
tripleo.undercloud-config.
This environment variable will have all required configuration details that we
can get from Mistral. This is defined in the instack-undercloud repository.

Let’s get into the repository and check the content of the file
instack_undercloud/undercloud.py.

This file defines a set of methods to interact with the Undercloud,
specifically the method called _create_mistral_config_environment allows to
configure additional environment variables when installing the Undercloud.

For additional testing, you can use the
Python snippet
to call Mistral client from the Undercloud node
available in gist.github.com.

6. Show how to test locally the changes in python-tripleoclient and tripleo-common.

If it’s needed a local test of a change in python-tripleoclient or
tripleo-common, the following procedures allow to test it locally.

For a change in python-tripleoclient, assuming you already have downloaded
the change you want to test, execute:

7. Give elevated privileges to specific Mistral actions that need to run with elevated privileges.

Sometimes its is not possible to execute some restricted actions from the
Mistral user, for example, when creating the Undercloud backup we won’t be able
to access the /home/stack/ folder to create a tarball of it. For this
cases it’s possible to execute elevates actions from the Mistral user:

This is the content of the sudoers in the root of the tripleo-common
repository at the time of the creatino of this guide.