From ef0edf3a34acccf294ac0af5117f487fe8a97c42 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ond=C5=99ej=20Ezr?= Date: Mon, 14 Dec 2020 14:50:10 +0100 Subject: [PATCH] Enable testing local puppet modules Add posibility to use local modules for installer. This helps if we need to test change we dont want to push to git just yet. For various reasons like shame or more seriously security bugs testing. --- docs/development.md | 28 ++++++++++++--- roles/foreman_installer/defaults/main.yml | 2 ++ roles/foreman_installer/tasks/main.yml | 2 +- .../foreman_installer/tasks/module_local.yml | 35 +++++++++++++++++++ roles/foreman_installer/tasks/module_prs.yml | 7 ++++ vagrant/lib/forklift/box_distributor.rb | 2 +- 6 files changed, 70 insertions(+), 6 deletions(-) create mode 100644 roles/foreman_installer/tasks/module_local.yml diff --git a/docs/development.md b/docs/development.md index c74c14038..221de7301 100644 --- a/docs/development.md +++ b/docs/development.md @@ -9,7 +9,7 @@ This covers how to setup and configure a development environment using the Forkl * [Customizing the Development Environment](#customizing-the-development-environment) * [Reviewing Pull Requests](#reviewing-pull-requests) * [Use Koji Scratch Builds](#koji-scratch-builds) - * [Test Puppet Module Pull Requests](#test-puppet-module) + * [Test Installer Puppet Module](#test-installer-puppet-module) * [Hammer Development](#hammer-development) * [Capsule Development](#capsule-development) * [Client Development](#client-development) @@ -69,7 +69,7 @@ When spinning up a Katello development environment locally, it can take a while The Katello development stable box is named `centos7-katello-devel-stable`. Please see the [documentation on stable boxes](./stable_boxes.md) for more information on how to use this box. -After spinning up `centos7-katello-devel-stable`, it's a good idea to pull the latest git branches and update gems and npm packages after spinning up a stable box. If a stable box image hasn't been published in a while, these can be out-of-date. +After spinning up `centos7-katello-devel-stable`, it's a good idea to pull the latest git branches and update gems and npm packages after spinning up a stable box. If a stable box image hasn't been published in a while, these can be out-of-date. At this moment, you will have to manually configure any personal customizations such as github remotes. @@ -206,7 +206,7 @@ The Koji role and task ID variable can be added to download and configure a repo - katello ``` -## Test Puppet Module +## Test Installer Puppet Module ### Pull Requests @@ -250,6 +250,26 @@ ansible: - myfork/foreman/add-puma ``` +### Local changes + +As an alternative you can use modules from local directories for testing out local changes before push. +For the machine in `99-local.yaml` + +```yaml +synced_folders: + - path: /home/myprojects/path/foreman-installer + mount_point: '/vagrant/foreman-installer' + options: + type: rsync +ansible: + variables: + foreman_installer_module_locals: + - name: dhcp + path: '/vagrant/foreman-installer/puppet-dhcp/' + - name: foreman_proxy + path: '/vagrant/foreman-installer/puppet-foreman_proxy/' +``` + ## Hammer Development Hammer is the command line interface (CLI) to Foreman and Katello. It supports plugins @@ -348,7 +368,7 @@ In the vagrant box, the dynflow repository is cloned to `/home/vagrant/dynflow`. The testing tool [smoker](https://github.com/theforeman/smoker) can be set up with the `centos7-foreman-smoker` box and tests can be run against a separate Foreman/Katello instance. To use: -1. Ensure that you have a running instance of Foreman/Katello. +1. Ensure that you have a running instance of Foreman/Katello. 2. Follow the example box definition in `vagrant/boxes.d/99-local.yaml.example` for `centos7-foreman-smoker` and update the `smoker_base_url` variable. With `pytest_run_tests` set to false, smoker tests will not be run by the playbook, but the box will be set up with pytest and the smoker repository will be cloned to the `vagrant` user's home directory. 3. Run `vagrant up centos7-foreman-smoker`. A debug message will print showing the command to run smoker tests and the alias that has been set up. The alias is defined in `~/.bash_profile` on the box itself. 4. You can then ssh into the smoker box. Ensure the hostname of the Foreman/Katello instance can be reached by the smoker box. diff --git a/roles/foreman_installer/defaults/main.yml b/roles/foreman_installer/defaults/main.yml index 97b4b1cdb..14a893f08 100644 --- a/roles/foreman_installer/defaults/main.yml +++ b/roles/foreman_installer/defaults/main.yml @@ -19,6 +19,8 @@ foreman_installer_module_prs_strategy: "merge" # Comma-separated list of "organization/module/branch", e.g. "theforeman/foreman/foo,theforeman/katello/bar" foreman_installer_module_branches: [] +foreman_installer_module_locals: [] + # There are two options, so a user can supply their own, and a playbook can # specify theirs. For example, foreman-proxy needs "--foreman-proxy-foreman-url" # so we put it in internal_use_only in a role or playbook. diff --git a/roles/foreman_installer/tasks/main.yml b/roles/foreman_installer/tasks/main.yml index 9fa538d8b..9ceae72f2 100644 --- a/roles/foreman_installer/tasks/main.yml +++ b/roles/foreman_installer/tasks/main.yml @@ -5,7 +5,7 @@ when: ansible_os_family == 'Debian' - include_tasks: module_prs.yml - when: (foreman_installer_module_prs|length > 0) or (foreman_installer_module_branches|length > 0) + when: (foreman_installer_module_prs|length > 0) or (foreman_installer_module_branches|length > 0) or (foreman_installer_module_locals|length > 0) - include_tasks: custom_hiera.yml when: foreman_installer_custom_hiera != "" diff --git a/roles/foreman_installer/tasks/module_local.yml b/roles/foreman_installer/tasks/module_local.yml new file mode 100644 index 000000000..e229d7181 --- /dev/null +++ b/roles/foreman_installer/tasks/module_local.yml @@ -0,0 +1,35 @@ +--- +- name: find puppet module + find: + paths: /usr/share/foreman-installer/modules + patterns: "{{ module.name }}" + file_type: any + register: foreman_module + +- name: find puppet module + find: + paths: /usr/share/katello-installer-base/modules + patterns: "{{ module.name }}" + file_type: any + register: katello_module + +- name: define module_dir for foreman + set_fact: + module_dir: /usr/share/foreman-installer/modules + when: foreman_module.matched > 0 + +- name: define module_dir for katello + set_fact: + module_dir: /usr/share/katello-installer-base/modules + when: katello_module.matched > 0 + +- name: Delete old module + file: + state: absent + path: "{{ module_dir }}/{{ module.name }}" + +- name: Create a symbolic link + file: + src: "{{ module.path }}" + dest: "{{ module_dir }}/{{ module.name }}" + state: link diff --git a/roles/foreman_installer/tasks/module_prs.yml b/roles/foreman_installer/tasks/module_prs.yml index 2149f85cb..950d9a78a 100644 --- a/roles/foreman_installer/tasks/module_prs.yml +++ b/roles/foreman_installer/tasks/module_prs.yml @@ -38,3 +38,10 @@ loop_var: module tags: - packages + +- include_tasks: module_local.yml + loop: "{{ foreman_installer_module_locals }}" + loop_control: + loop_var: module + tags: + - packages diff --git a/vagrant/lib/forklift/box_distributor.rb b/vagrant/lib/forklift/box_distributor.rb index c0877818a..32c46305e 100644 --- a/vagrant/lib/forklift/box_distributor.rb +++ b/vagrant/lib/forklift/box_distributor.rb @@ -218,7 +218,7 @@ def configure_synced_folders(machine, box) return if synced_folders.empty? synced_folders.each do |folder| - options = symbolized_options(folder['options']) + options = symbolized_options(folder['options'] || {}) machine.vm.synced_folder folder['path'], folder['mount_point'], options end end