3. Development

This section only needs to be read by developers of the zhmccli package. People that want to make a fix or develop some extension, and people that want to test the project are also considered developers for the purpose of this section.

3.1. Code of Conduct

Help us keep the zhmccli package open and inclusive. Please read and follow our Code of Conduct.

3.2. Repository

The source code repository for the zhmccli package is on GitHub:

https://github.com/zhmcclient/zhmccli

3.3. Setting up the development environment

The development environment is pretty easy to set up.

Besides having a supported operating system with a supported Python version (see Supported environments), it is recommended that you set up a virtual Python environment.

Then, with a virtual Python environment active, clone the Git repo of this project and prepare the development environment with make develop:

$ git clone git@github.com:zhmcclient/zhmccli.git
$ cd zhmccli
$ make develop

This will install all prerequisites the package needs to run, as well as all prerequisites that you need for development.

Generally, this project uses Make to do things in the currently active Python environment. The command make help (or just make) displays a list of valid Make targets and a short description of what each target does.

3.4. Building the documentation

The ReadTheDocs (RTD) site is used to publish the documentation for the zhmccli package at http://zhmccli.readthedocs.io/

This page automatically gets updated whenever the master branch of the Git repo for this package changes.

In order to build the documentation locally from the Git work directory, issue:

$ make builddoc

The top-level document to open with a web browser will be build_doc/html/docs/index.html.

3.5. Testing

There are two kinds of tests:

  • function tests: Function testcases run against a zhmcclient_mock environment.

  • end2end tests: End2end testcases run against an HMC or set of HMCs defined in an HMC inventory file, with credentials from an HMC vault file.

3.5.1. Running function tests

To run the function tests in the currently active Python environment, issue one of these example variants of make test:

$ make test                                  # Run all function tests
$ TESTCASES=test_info.py make test           # Run only this function test source file
$ TESTCASES=TestInfo make test               # Run only this function test class
$ TESTCASES="test_info_help or test_info_error_no_host" make test  # py.test -k expressions are possible

To run the function tests and some more commands that verify the project is in good shape in all supported Python environments, use Tox:

$ tox                              # Run all function tests on all supported Python versions
$ tox -e py39                      # Run all function tests on Python 3.9
$ tox -e py39 test_info.py         # Run only this function test source file on Python 3.9
$ tox -e py39 TestInfo             # Run only this function test class on Python 3.9
$ tox -e py39 test_info_help or test_info_error_no_host  # py.test -k expressions are possible

The positional arguments of the tox command are passed to py.test using its -k option. Invoke py.test --help for details on the expression syntax of its -k option.

In addition to TESTCASES, the environment variable TESTOPTS can be specified for function tests. Invoke make help for details.

3.5.2. Running end2end tests

To run the end2end tests in the currently active Python environment, you first need to prepare an HMC inventory file that defines real and/or mocked HMCs the tests should be run against, and an HMC vault file with credentials for the real HMCs.

There are examples for these files, that describe their format in the comment header:

To run the end2end tests in the currently active Python environment, issue:

$ make end2end

By default, the HMC inventory file named .zhmc_inventory.yaml in the home directory of the current user is used. A different path name can be specified with the TESTINVENTORY environment variable.

By default, the HMC vault file named .zhmc_vault.yaml in the home directory of the current user is used. A different path name can be specified with the TESTVAULT environment variable.

By default, the tests are run against the group name or HMC nickname default defined in the HMC inventory file. A different group name or HMC nickname can be specified with the TESTHMC environment variable.

To show the defined HMC nicknames and groups that can be used, issue:

$ make end2end_show

Examples:

  • Run against group or HMC nickname ‘default’ using the default HMC inventory and vault files:

    $ make end2end
    
  • Run against group or HMC nickname ‘HMC1’ using the default HMC inventory and vault files:

    $ TESTHMC=HMC1 make end2end
    
  • Run against group or HMC nickname ‘default’ using the specified HMC inventory and vault files:

    $ TESTINVENTORY=./hmc_inventory.yaml TESTVAULT=./hmc_vault.yaml make end2end
    

In addition to TESTHMC, TESTINVENTORY and TESTVAULT, the environment variables TESTCASES, TESTOPTS, TESTRESOURCES and TESTLOG can be specified for end2end tests. Invoke make help for details.

3.6. Contributing

Third party contributions to this project are welcome!

In order to contribute, create a Git pull request, considering this:

  • Test is required.

  • Each commit should only contain one “logical” change.

  • A “logical” change should be put into one commit, and not split over multiple commits.

  • Large new features should be split into stages.

  • The commit message should not only summarize what you have done, but explain why the change is useful.

  • The commit message must follow the format explained below.

What comprises a “logical” change is subject to sound judgement. Sometimes, it makes sense to produce a set of commits for a feature (even if not large). For example, a first commit may introduce a (presumably) compatible API change without exploitation of that feature. With only this commit applied, it should be demonstrable that everything is still working as before. The next commit may be the exploitation of the feature in other components.

For further discussion of good and bad practices regarding commits, see:

3.7. Format of commit messages

A commit message must start with a short summary line, followed by a blank line.

Optionally, the summary line may start with an identifier that helps identifying the type of change or the component that is affected, followed by a colon.

It can include a more detailed description after the summary line. This is where you explain why the change was done, and summarize what was done.

It must end with the DCO (Developer Certificate of Origin) sign-off line in the format shown in the example below, using your name and a valid email address of yours. The DCO sign-off line certifies that you followed the rules stated in DCO 1.1. In short, you certify that you wrote the patch or otherwise have the right to pass it on as an open-source patch.

We use GitCop during creation of a pull request to check whether the commit messages in the pull request comply to this format. If the commit messages do not comply, GitCop will add a comment to the pull request with a description of what was wrong.

Example commit message:

cookies: Add support for delivering cookies

Cookies are important for many people. This change adds a pluggable API for
delivering cookies to the user, and provides a default implementation.

Signed-off-by: Random J Developer <random@developer.org>

Use git commit --amend to edit the commit message, if you need to.

Use the --signoff (-s) option of git commit to append a sign-off line to the commit message with your name and email as known by Git.

If you like filling out the commit message in an editor instead of using the -m option of git commit, you can automate the presence of the sign-off line by using a commit template file:

  • Create a file outside of the repo (say, ~/.git-signoff.template) that contains, for example:

    <one-line subject>
    
    <detailed description>
    
    Signed-off-by: Random J Developer <random@developer.org>
    
  • Configure Git to use that file as a commit template for your repo:

    git config commit.template ~/.git-signoff.template
    

3.8. Releasing a version

This section shows the steps for releasing a version to PyPI.

It covers all variants of versions that can be released:

  • Releasing a new major version (Mnew.0.0) based on the master branch

  • Releasing a new minor version (M.Nnew.0) based on the master branch

  • Releasing a new update version (M.N.Unew) based on the stable branch of its minor version

This description assumes that you are authorized to push to the remote repo at https://github.com/zhmcclient/zhmccli and that the remote repo has the remote name origin in your local clone.

Any commands in the following steps are executed in the main directory of your local clone of the zhmccli Git repo.

  1. On GitHub, verify open items in milestone M.N.U.

    Verify that milestone M.N.U has no open issues or PRs anymore. If there are open PRs or open issues, make a decision for each of those whether or not it should go into version M.N.U you are about to release.

    If there are open issues or PRs that should go into this version, abandon the release process.

    If none of the open issues or PRs should go into this version, change their milestones to a future version, and proceed with the release process. You may need to create the milestone for the future version.

  2. Set shell variables for the version that is being released and the branch it is based on:

    • MNU - Full version M.N.U that is being released

    • MN - Major and minor version M.N of that full version

    • BRANCH - Name of the branch the version that is being released is based on

    When releasing a new major version (e.g. 1.0.0) based on the master branch:

    MNU=1.0.0
    MN=1.0
    BRANCH=master
    

    When releasing a new minor version (e.g. 0.9.0) based on the master branch:

    MNU=0.9.0
    MN=0.9
    BRANCH=master
    

    When releasing a new update version (e.g. 0.8.1) based on the stable branch of its minor version:

    MNU=0.8.1
    MN=0.8
    BRANCH=stable_${MN}
    
  3. Create a topic branch for the version that is being released:

    git checkout ${BRANCH}
    git pull
    git checkout -b release_${MNU}
    
  4. Edit the version file:

    vi zhmccli/_version.py
    

    and set the __version__ variable to the version that is being released:

    __version__ = 'M.N.U'
    
  5. Edit the change log:

    vi docs/changes.rst
    

    and make the following changes in the section of the version that is being released:

    • Finalize the version.

    • Change the release date to today’s date.

    • Make sure that all changes are described.

    • Make sure the items shown in the change log are relevant for and understandable by users.

    • In the “Known issues” list item, remove the link to the issue tracker and add text for any known issues you want users to know about.

    • Remove all empty list items.

  6. Update the authors:

    make authors
    
  7. Run the Safety tool:

    RUN_TYPE=release make safety
    

    When releasing a version, the safety run for all dependencies will fail if there are any safety issues reported. In normal and scheduled runs, safety issues reported for all dependencies will be ignored.

    If the safety run fails, you need to fix the safety issues that are reported.

  8. Commit your changes and push the topic branch to the remote repo:

    git commit -asm "Release ${MNU}"
    git push --set-upstream origin release_${MNU}
    
  9. On GitHub, create a Pull Request for branch release_M.N.U.

    Important: When creating Pull Requests, GitHub by default targets the master branch. When releasing based on a stable branch, you need to change the target branch of the Pull Request to stable_M.N.

    Set the milestone of that PR to version M.N.U.

    This PR should normally be set to be reviewed by at least one of the maintainers.

    The PR creation will cause the “test” workflow to run. That workflow runs tests for all defined environments, since it discovers by the branch name that this is a PR for a release.

  10. On GitHub, once the checks for that Pull Request have succeeded, merge the Pull Request (no review is needed). This automatically deletes the branch on GitHub.

    If the PR did not succeed, fix the issues.

  11. On GitHub, close milestone M.N.U.

    Verify that the milestone has no open items anymore. If it does have open items, investigate why and fix. If the milestone does not have open items anymore, close the milestone.

  12. Publish the package

    git checkout ${BRANCH}
    git pull
    git branch -D release_${MNU}
    git branch -D -r origin/release_${MNU}
    git tag -f ${MNU}
    git push -f --tags
    

    Pushing the new tag will cause the “publish” workflow to run. That workflow builds the package, publishes it on PyPI, creates a release for it on Github, and finally creates a new stable branch on Github if the master branch was released.

  13. Verify the publishing

    Wait for the “publish” workflow for the new release to have completed: https://github.com/zhmcclient/zhmccli/actions/workflows/publish.yml

    Then, perform the following verifications:

3.9. Starting a new version

This section shows the steps for starting development of a new version.

This section covers all variants of new versions:

  • Starting a new major version (Mnew.0.0) based on the master branch

  • Starting a new minor version (M.Nnew.0) based on the master branch

  • Starting a new update version (M.N.Unew) based on the stable branch of its minor version

This description assumes that you are authorized to push to the remote repo at https://github.com/zhmcclient/zhmccli and that the remote repo has the remote name origin in your local clone.

Any commands in the following steps are executed in the main directory of your local clone of the zhmccli Git repo.

  1. Set shell variables for the version that is being started and the branch it is based on:

    • MNU - Full version M.N.U that is being started

    • MN - Major and minor version M.N of that full version

    • BRANCH - Name of the branch the version that is being started is based on

    When starting a new major version (e.g. 1.0.0) based on the master branch:

    MNU=1.0.0
    MN=1.0
    BRANCH=master
    

    When starting a new minor version (e.g. 0.9.0) based on the master branch:

    MNU=0.9.0
    MN=0.9
    BRANCH=master
    

    When starting a new minor version (e.g. 0.8.1) based on the stable branch of its minor version:

    MNU=0.8.1
    MN=0.8
    BRANCH=stable_${MN}
    
  2. Create a topic branch for the version that is being started:

    git fetch origin
    git checkout ${BRANCH}
    git pull
    git checkout -b start_${MNU}
    
  3. Edit the version file:

    vi zhmccli/_version.py
    

    and update the version to a draft version of the version that is being started:

    __version__ = 'M.N.U.dev1'
    
  4. Edit the change log:

    vi docs/changes.rst
    

    and insert the following section before the top-most section:

    Version M.N.U.dev1
    ^^^^^^^^^^^^^^^^^^
    
    This version contains all fixes up to version M.N-1.x.
    
    Released: not yet
    
    **Incompatible changes:**
    
    **Deprecations:**
    
    **Bug fixes:**
    
    **Enhancements:**
    
    **Cleanup:**
    
    **Known issues:**
    
    * See `list of open issues`_.
    
    .. _`list of open issues`: https://github.com/zhmcclient/zhmccli/issues
    
  5. Commit your changes and push them to the remote repo:

    git commit -asm "Start ${MNU}"
    git push --set-upstream origin start_${MNU}
    
  6. On GitHub, create a milestone for the new version M.N.U.

    You can create a milestone in GitHub via Issues -> Milestones -> New Milestone.

  7. On GitHub, create a Pull Request for branch start_M.N.U.

    Important: When creating Pull Requests, GitHub by default targets the master branch. When starting a version based on a stable branch, you need to change the target branch of the Pull Request to stable_M.N.

    No review is needed for this PR.

    Set the milestone of that PR to the new version M.N.U.

  8. On GitHub, go through all open issues and pull requests that still have milestones for previous releases set, and either set them to the new milestone, or to have no milestone.

    Note that when the release process has been performed as described, there should not be any such issues or pull requests anymore. So this step here is just an additional safeguard.

  9. On GitHub, once the checks for the Pull Request for branch start_M.N.U have succeeded, merge the Pull Request (no review is needed). This automatically deletes the branch on GitHub.

  10. Update and clean up the local repo:

    git checkout ${BRANCH}
    git pull
    git branch -D start_${MNU}
    git branch -D -r origin/start_${MNU}