From cf4128e240273f1e4a29a0d9d2ef95010b5fa4e2 Mon Sep 17 00:00:00 2001 From: Ewoud Kohl van Wijngaarden Date: Thu, 28 Nov 2019 14:14:51 +0100 Subject: [PATCH] Convert pipelines to obsah --- bin/forklift | 51 +++++++++++ docs/testing.md | 90 ++++++++++--------- .../install.yaml} | 33 +++---- pipelines/install/metadata.obsah.yaml | 18 ++++ .../vars/base.yml} | 1 + pipelines/upgrade/metadata.obsah.yaml | 18 ++++ .../upgrade.yaml} | 60 ++++++------- .../vars/base.yml} | 1 + 8 files changed, 184 insertions(+), 88 deletions(-) create mode 100755 bin/forklift rename pipelines/{install_pipeline.yml => install/install.yaml} (79%) create mode 100644 pipelines/install/metadata.obsah.yaml rename pipelines/{vars/install_base.yml => install/vars/base.yml} (82%) create mode 100644 pipelines/upgrade/metadata.obsah.yaml rename pipelines/{upgrade_pipeline.yml => upgrade/upgrade.yaml} (82%) rename pipelines/{vars/upgrade_base.yml => upgrade/vars/base.yml} (85%) diff --git a/bin/forklift b/bin/forklift new file mode 100755 index 000000000..945c675bf --- /dev/null +++ b/bin/forklift @@ -0,0 +1,51 @@ +#!/usr/bin/env python3 +# PYTHON_ARGCOMPLETE_OK + +from pathlib import Path + +import obsah + + +class ApplicationConfig(obsah.ApplicationConfig): + """ + A class describing the where to find various files + """ + + @staticmethod + def name() -> str: + """ + Return the name as shown to the user in the ArgumentParser + """ + return 'forklift' + + @staticmethod + def target_name() -> str: + """ + Return the name of the target in the playbook if the playbook takes a parameter. + """ + return 'pipeline' + + @staticmethod + def data_path() -> Path: + """ + Returns the root of the project + """ + return Path(__file__).absolute().parent.parent + + @classmethod + def playbooks_path(cls) -> str: + """ + Return the data path. Houses playbooks and configs. + """ + return (cls.data_path() / 'pipelines').as_posix() + + @classmethod + def inventory_path(cls) -> str: + """ + Return the inventory path + """ + return (cls.data_path() / 'inventories').as_posix() + + +if __name__ == '__main__': + obsah.main(application_config=ApplicationConfig) diff --git a/docs/testing.md b/docs/testing.md index cfc37d9e8..7e80751d0 100644 --- a/docs/testing.md +++ b/docs/testing.md @@ -61,57 +61,63 @@ centos7-foreman-bats-ci: ## Pipeline Testing -Under `pipelines` are a series of playbooks designed around testing scenarios for various version of the Foreman and Katello stack. To run one: +Under `pipelines` are a series of playbooks designed around testing scenarios for various version of the Foreman and Katello stack. Use `./bin/forklift --help` to find out which ones and their aguments. - ansible-playbook pipelines/.yml -e forklift_state=up -e +```console +$ ./bin/forklift --help +usage: forklift [-h] action ... -When you are finished with the test, you can tear down the associated infrastructure: +positional arguments: + action which action to execute + install Run an install pipeline + upgrade Run an upgrade pipeline - ansible-playbook pipelines/.yml -e forklift_state=destroy -e - -### Existing Pipelines - -* `install_pipeline` - Installs a Server and a Proxy VMs and runs the `foreman_testing` role to verify the setup. - Expects the `pipeline_os` variable to be set to a known OS (currently: centos7, debian9) - Expects the `pipeline_type` variable to be set to a known type (currently: foreman, katello, luna) - Expects the `pipeline_version` variable to be set to a known version (currently: 3.8, 3.9, 3.10, 3.11, nightly) -* `upgrade_pipeline` - Installs a VM, upgrades it twice and runs the `foreman_testing` role to verify the final upgrade. - Expects the `pipeline_os` variable to be set to a known OS (currently: centos7, debian9) - Expects the `pipeline_type` variable to be set to a known type (currently: foreman, katello, luna) - Expects the `pipeline_version` variable to be set to a known version (currently: 3.8, 3.9, 3.10, 3.11, nightly). - -#### Examples - - ansible-playbook pipelines/install_pipeline.yml -e forklift_state=up -e pipeline_os=debian9 -e pipeline_type=foreman -e pipeline_version=nightly - ansible-playbook pipelines/upgrade_pipeline.yml -e forklift_state=up -e pipeline_os=centos7 -e pipeline_type=katello -e pipeline_version=3.10 +optional arguments: + -h, --help show this help message and exit +``` -### Creating Pipelines +Individual pipelines also have help texts: +```console +$ ./bin/forklift install --help +usage: forklift install [-h] [-v] [-e EXTRA_VARS] [--state FORKLIFT_STATE] + [--os PIPELINE_OS] [--type PIPELINE_TYPE] + [--version PIPELINE_VERSION] + +Run an install pipeline + +optional arguments: + -h, --help show this help message and exit + -v, --verbose verbose output + --state FORKLIFT_STATE + Forklift state to ensure + --os PIPELINE_OS Operating system to install, like centos7, debian10 or + ubuntu1804 + --type PIPELINE_TYPE Type of pipeline, like foreman, katello or luna + --version PIPELINE_VERSION + Version to install, like nightly, 1.24 or 3.14 + +advanced arguments: + -e EXTRA_VARS, --extra-vars EXTRA_VARS + set additional variables as key=value or YAML/JSON, if + filename prepend with @ +``` -If you wish to add a new version of an existing pipeline (e.g. a new Katello release), you only have to add the corresponding vars files to `pipelines/vars/`. +Pipelines typically have a state which defaults to `up`. Other valid values are `rebuild` and `destroy`. The latter one is useful to clean up which pipelines don't do by themselves. -For Katello 3.11, you'd be adding the following two files: +For example to run a Foreman Nightly installation pipeline on Debian Buster: -`pipelines/vars/katello_3.11.yml`: -```yaml -forklift_name: pipeline-katello-3.11 -forklift_boxes: - pipeline-katello-3.11-centos7: - box: centos7 - memory: 8192 - pipeline-proxy-3.11-centos7: - box: centos7 - memory: 3072 -katello_repositories_version: '3.11' -katello_repositories_pulp_version: '2.19' -foreman_repositories_version: '1.21' -foreman_client_repositories_version: "{{ foreman_repositories_version }}" +```console +$ ./bin/forklift install --os debian10 --type foreman --version nightly +... lots of output +$ ./bin/forklift install --os debian10 --type foreman --version nightly --state destroy ``` -`pipelines/vars/katello_upgrade_3.11.yml`: -```yaml -katello_version_start: '3.9' -katello_version_intermediate: '3.10' -katello_version_final: '{{ katello_version }}' +Similarly a Katello Nightly upgrade pipeline on CentOS 7: + +```console +$ ./bin/forklift upgrade --os centos7 --type katello --version nightly +... lots of output +$ ./bin/forklift upgrade --os centos7 --type katello --version nightly --state destroy ``` ## Running Robottelo Tests diff --git a/pipelines/install_pipeline.yml b/pipelines/install/install.yaml similarity index 79% rename from pipelines/install_pipeline.yml rename to pipelines/install/install.yaml index 1d7483ea4..8d7ddcee1 100644 --- a/pipelines/install_pipeline.yml +++ b/pipelines/install/install.yaml @@ -1,8 +1,9 @@ - name: create vagrant boxes - hosts: localhost + hosts: + - localhost vars_files: - - vars/install_base.yml - - vars/{{ pipeline_type }}_base.yml + - vars/base.yml + - ../vars/{{ pipeline_type }}_base.yml roles: - forklift @@ -14,9 +15,9 @@ vars: foreman_installer_skip_installer: true vars_files: - - vars/install_base.yml - - vars/{{ pipeline_type }}_base.yml - - vars/{{ pipeline_type }}_base_staging.yml + - vars/base.yml + - ../vars/{{ pipeline_type }}_base.yml + - ../vars/{{ pipeline_type }}_base_staging.yml roles: - role: forklift_versions scenario: "{{ pipeline_type }}" @@ -34,10 +35,10 @@ - "{{ forklift_server_name }}" become: yes vars_files: - - vars/install_base.yml - - vars/{{ pipeline_type }}_base.yml - - vars/{{ pipeline_type }}_base_staging.yml - - vars/{{ pipeline_type }}_server.yml + - vars/base.yml + - ../vars/{{ pipeline_type }}_base.yml + - ../vars/{{ pipeline_type }}_base_staging.yml + - ../vars/{{ pipeline_type }}_server.yml roles: - role: forklift_versions scenario: "{{ pipeline_type }}" @@ -49,9 +50,9 @@ - "{{ forklift_proxy_name }}" become: yes vars_files: - - vars/install_base.yml - - vars/{{ pipeline_type }}_base_staging.yml - - vars/{{ pipeline_type }}_proxy.yml + - vars/base.yml + - ../vars/{{ pipeline_type }}_base_staging.yml + - ../vars/{{ pipeline_type }}_proxy.yml vars: foreman_proxy_content_server: "{{ forklift_server_name }}" foreman_installer_scenario: foreman-proxy-content @@ -77,9 +78,9 @@ - "{{ forklift_server_name }}" become: true vars_files: - - vars/install_base.yml - - vars/{{ pipeline_type }}_base.yml - - vars/{{ pipeline_type }}_base_staging.yml + - vars/base.yml + - ../vars/{{ pipeline_type }}_base.yml + - ../vars/{{ pipeline_type }}_base_staging.yml environment: FOREMAN_EXPECTED_VERSION: "{{ foreman_expected_version | default('') }}" roles: diff --git a/pipelines/install/metadata.obsah.yaml b/pipelines/install/metadata.obsah.yaml new file mode 100644 index 000000000..3a60e67d9 --- /dev/null +++ b/pipelines/install/metadata.obsah.yaml @@ -0,0 +1,18 @@ +help: | + Run an install pipeline +variables: + forklift_state: + parameter: --state + help: Forklift state to ensure + # TODO: up/rebuild/destroy + pipeline_os: + parameter: --os + help: Operating system to install, like centos7, debian10 or ubuntu1804 + pipeline_type: + parameter: --type + help: Type of pipeline, like foreman, katello or luna + # TODO: choices: foreman/katello/luna + pipeline_version: + parameter: --version + help: Version to install, like nightly, 1.24 or 3.14 + diff --git a/pipelines/vars/install_base.yml b/pipelines/install/vars/base.yml similarity index 82% rename from pipelines/vars/install_base.yml rename to pipelines/install/vars/base.yml index 9e8659126..03ced2691 100644 --- a/pipelines/vars/install_base.yml +++ b/pipelines/install/vars/base.yml @@ -1,3 +1,4 @@ +forklift_directory: "{{ playbook_dir | dirname | dirname }}" forklift_name: "pipeline-{{ pipeline_type }}-{{ pipeline_version }}-{{ pipeline_os }}" forklift_server_name: "pipeline-{{ pipeline_type }}-server-{{ pipeline_version }}-{{ pipeline_os }}" forklift_proxy_name: "pipeline-{{ pipeline_type }}-proxy-{{ pipeline_version }}-{{ pipeline_os }}" diff --git a/pipelines/upgrade/metadata.obsah.yaml b/pipelines/upgrade/metadata.obsah.yaml new file mode 100644 index 000000000..73ec64425 --- /dev/null +++ b/pipelines/upgrade/metadata.obsah.yaml @@ -0,0 +1,18 @@ +help: | + Run an upgrade pipeline +variables: + forklift_state: + parameter: --state + help: Forklift state to ensure + # TODO: up/rebuild/destroy + pipeline_os: + parameter: --os + help: Operating system to install, like centos7, debian10 or ubuntu1804 + pipeline_type: + parameter: --type + help: Type of pipeline, like foreman, katello or luna + # TODO: choices: foreman/katello/luna + pipeline_version: + parameter: --version + help: Version to install, like nightly, 1.24 or 3.14 + diff --git a/pipelines/upgrade_pipeline.yml b/pipelines/upgrade/upgrade.yaml similarity index 82% rename from pipelines/upgrade_pipeline.yml rename to pipelines/upgrade/upgrade.yaml index 116b35680..d1348ca42 100644 --- a/pipelines/upgrade_pipeline.yml +++ b/pipelines/upgrade/upgrade.yaml @@ -1,8 +1,8 @@ - name: create vagrant boxes hosts: localhost vars_files: - - vars/upgrade_base.yml - - vars/{{ pipeline_type }}_base.yml + - vars/base.yml + - ../vars/{{ pipeline_type }}_base.yml roles: - forklift @@ -14,9 +14,9 @@ vars: foreman_installer_skip_installer: true vars_files: - - vars/upgrade_base.yml - - vars/{{ pipeline_type }}_base.yml - - vars/{{ pipeline_type }}_base_release.yml + - vars/base.yml + - ../vars/{{ pipeline_type }}_base.yml + - ../vars/{{ pipeline_type }}_base_release.yml roles: - role: forklift_versions scenario: "{{ pipeline_type }}" @@ -39,10 +39,10 @@ - "{{ forklift_server_name }}" become: yes vars_files: - - vars/upgrade_base.yml - - vars/{{ pipeline_type }}_base.yml - - vars/{{ pipeline_type }}_base_release.yml - - vars/{{ pipeline_type }}_server.yml + - vars/base.yml + - ../vars/{{ pipeline_type }}_base.yml + - ../vars/{{ pipeline_type }}_base_release.yml + - ../vars/{{ pipeline_type }}_server.yml roles: - role: forklift_versions scenario: "{{ pipeline_type }}" @@ -58,8 +58,8 @@ - "{{ forklift_proxy_name }}" become: yes vars_files: - - vars/upgrade_base.yml - - vars/{{ pipeline_type }}_proxy.yml + - vars/base.yml + - ../vars/{{ pipeline_type }}_proxy.yml vars: foreman_proxy_content_server: "{{ forklift_server_name }}" foreman_installer_disable_system_checks: true @@ -88,10 +88,10 @@ - "{{ forklift_server_name }}" become: true vars_files: - - vars/upgrade_base.yml - - vars/{{ pipeline_type }}_base.yml - - vars/{{ pipeline_type }}_base_release.yml - - vars/{{ pipeline_type }}_server.yml + - vars/base.yml + - ../vars/{{ pipeline_type }}_base.yml + - ../vars/{{ pipeline_type }}_base_release.yml + - ../vars/{{ pipeline_type }}_server.yml vars: foreman_installer_upgrade: True roles: @@ -111,10 +111,10 @@ - "{{ forklift_proxy_name }}" become: true vars_files: - - vars/upgrade_base.yml - - vars/{{ pipeline_type }}_base.yml - - vars/{{ pipeline_type }}_base_release.yml - - vars/{{ pipeline_type }}_proxy.yml + - vars/base.yml + - ../vars/{{ pipeline_type }}_base.yml + - ../vars/{{ pipeline_type }}_base_release.yml + - ../vars/{{ pipeline_type }}_proxy.yml vars: foreman_installer_upgrade: True foreman_proxy_content_upgrade: True @@ -139,10 +139,10 @@ vars: foreman_installer_upgrade: True vars_files: - - vars/upgrade_base.yml - - vars/{{ pipeline_type }}_base.yml - - vars/{{ pipeline_type }}_base_staging.yml - - vars/{{ pipeline_type }}_server.yml + - vars/base.yml + - ../vars/{{ pipeline_type }}_base.yml + - ../vars/{{ pipeline_type }}_base_staging.yml + - ../vars/{{ pipeline_type }}_server.yml roles: - role: forklift_versions scenario: "{{ pipeline_type }}" @@ -163,10 +163,10 @@ foreman_proxy_content_upgrade: True foreman_proxy_content_server: "{{ forklift_server_name }}" vars_files: - - vars/upgrade_base.yml - - vars/{{ pipeline_type }}_base.yml - - vars/{{ pipeline_type }}_base_staging.yml - - vars/{{ pipeline_type }}_proxy.yml + - vars/base.yml + - ../vars/{{ pipeline_type }}_base.yml + - ../vars/{{ pipeline_type }}_base_staging.yml + - ../vars/{{ pipeline_type }}_proxy.yml roles: - role: forklift_versions scenario: "{{ pipeline_type }}" @@ -184,9 +184,9 @@ - "{{ forklift_server_name }}" become: yes vars_files: - - vars/upgrade_base.yml - - vars/{{ pipeline_type }}_base.yml - - vars/{{ pipeline_type }}_base_staging.yml + - vars/base.yml + - ../vars/{{ pipeline_type }}_base.yml + - ../vars/{{ pipeline_type }}_base_staging.yml environment: FOREMAN_EXPECTED_VERSION: "{{ foreman_expected_version | default('') }}" roles: diff --git a/pipelines/vars/upgrade_base.yml b/pipelines/upgrade/vars/base.yml similarity index 85% rename from pipelines/vars/upgrade_base.yml rename to pipelines/upgrade/vars/base.yml index dae989bcc..b40b4acd2 100644 --- a/pipelines/vars/upgrade_base.yml +++ b/pipelines/upgrade/vars/base.yml @@ -1,3 +1,4 @@ +forklift_directory: "{{ playbook_dir | dirname | dirname }}" forklift_name: "pipeline-upgrade-{{ pipeline_type }}-{{ pipeline_version}}-{{ pipeline_os }}" forklift_server_name: "pipeline-upgrade-{{ pipeline_type }}-{{ pipeline_version}}-{{ pipeline_os }}" forklift_proxy_name: "pipeline-upgrade-{{ pipeline_type }}-proxy-{{ pipeline_version}}-{{ pipeline_os }}"