Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add integration tests using smoker #1005

Merged
merged 3 commits into from Dec 13, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
15 changes: 15 additions & 0 deletions pipelines/install_pipeline.yml
Expand Up @@ -89,3 +89,18 @@
- role: foreman_client_repositories
when: pipeline_type != 'foreman'
- role: foreman_testing

- name: run smoker
hosts:
- "{{ forklift_smoker_name }}"
vars_files:
- vars/install_base.yml
- vars/{{ pipeline_type }}_base.yml
vars:
smoker_base_url: "https://{{ forklift_server_name }}.{{ ansible_domain }}"
smoker_variables:
password: "{{ foreman_installer_admin_password|default('changeme') }}"
roles:
- role: epel_repositories
become: true
- smoker
15 changes: 15 additions & 0 deletions pipelines/upgrade_pipeline.yml
Expand Up @@ -200,3 +200,18 @@
- role: foreman_client_repositories
when: pipeline_type != 'foreman'
- role: foreman_testing

- name: run smoker
hosts:
- "{{ forklift_smoker_name }}"
vars_files:
- vars/install_base.yml
- vars/{{ pipeline_type }}_base.yml
vars:
smoker_base_url: "https://{{ forklift_server_name }}.{{ ansible_domain }}"
smoker_variables:
password: "{{ foreman_installer_admin_password|default('changeme') }}"
roles:
- role: epel_repositories
become: true
- smoker
2 changes: 1 addition & 1 deletion pipelines/vars/foreman_base.yml
Expand Up @@ -8,7 +8,7 @@ server_box:
box: "{{ pipeline_os }}"
memory: 4680
forklift_boxes:
"{{ {forklift_server_name: server_box} }}"
"{{ {forklift_server_name: server_box, forklift_smoker_name: smoker_box} }}"
bats_tests:
- "fb-verify-packages.bats"
- "fb-test-foreman.bats"
Expand Down
4 changes: 4 additions & 0 deletions pipelines/vars/install_base.yml
@@ -1,3 +1,7 @@
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 }}"
forklift_smoker_name: "pipeline-{{ pipeline_type }}-smoker-{{ pipeline_version }}-{{ pipeline_os }}"
smoker_box:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this could be defined in base.yml, no? or do we need different smoker boxes for install and upgrade?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't see a base.yml. Are you suggesting to introduce one?

box: centos7
memory: 2048
2 changes: 1 addition & 1 deletion pipelines/vars/katello_base.yml
Expand Up @@ -7,6 +7,6 @@ proxy_box:
box: "{{ pipeline_os }}"
memory: 3072
forklift_boxes:
"{{ {forklift_server_name: server_box, forklift_proxy_name: proxy_box} }}"
"{{ {forklift_server_name: server_box, forklift_proxy_name: proxy_box, forklift_smoker_name: smoker_box} }}"
bats_tests_additional:
- fb-proxy.bats
2 changes: 1 addition & 1 deletion pipelines/vars/luna_base.yml
Expand Up @@ -8,6 +8,6 @@ proxy_box:
box: "{{ pipeline_os }}"
memory: 3072
forklift_boxes:
"{{ {forklift_server_name: server_box, forklift_proxy_name: proxy_box} }}"
"{{ {forklift_server_name: server_box, forklift_proxy_name: proxy_box, forklift_smoker_name: smoker_box} }}"
bats_tests_additional:
- fb-proxy.bats
6 changes: 5 additions & 1 deletion pipelines/vars/upgrade_base.yml
@@ -1,4 +1,8 @@
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 }}"
forklift_boxes: "{{ {forklift_server_name: server_box} }}"
forklift_smoker_name: "pipeline-{{ pipeline_type }}-smoker-{{ pipeline_version }}-{{ pipeline_os }}"
forklift_boxes: "{{ {forklift_server_name: server_box, forklift_smoker_name: smoker_box} }}"
smoker_box:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same comment as in install_base.yml

box: centos7
memory: 2048
20 changes: 20 additions & 0 deletions roles/pytest_project/defaults/main.yml
@@ -0,0 +1,20 @@
---
# Shared
pytest_project_directory: /tmp/pytest_project
pytest_project_virtualenv_path: "{{ pytest_project_directory }}/venv"

# Install
pytest_project_packages:
- git
- python3
# This should match the ansible_python_interpreter rather than the pytest's python
- python-setuptools
pytest_project_url:
pytest_project_requirements: requirements.txt
pytest_project_virtualenv_command: /usr/bin/python3 -m venv
pytest_project_version: master

# Run
pytest_project_junit_output: junit.xml
pytest_project_markers:
pytest_project_command_args:
21 changes: 21 additions & 0 deletions roles/pytest_project/tasks/install.yml
@@ -0,0 +1,21 @@
---
- name: Install packages
become: true
package:
name: "{{ pytest_project_packages }}"
state: present

- name: Clone project
git:
repo: "{{ pytest_project_url }}"
dest: "{{ pytest_project_directory }}"
version: "{{ pytest_project_version }}"
update: yes
force: yes

- name: Install requirements
pip:
requirements: "{{ pytest_project_directory }}/{{ pytest_project_requirements }}"
virtualenv: "{{ pytest_project_virtualenv_path }}"
virtualenv_command: "{{ pytest_project_virtualenv_command }}"
chdir: "{{ pytest_project_directory }}"
14 changes: 14 additions & 0 deletions roles/pytest_project/tasks/run.yml
@@ -0,0 +1,14 @@
---
- name: 'Build command'
set_fact:
pytest_project_command: "{{ pytest_project_virtualenv_path }}/bin/py.test --junit-xml={{ pytest_project_junit_output }} {{ pytest_project_command_args }}"

- name: 'Limit to markers'
set_fact:
pytest_project_command: "{{ pytest_project_command }} -m '{{ pytest_project_markers }}'"
when: pytest_project_markers|bool

- name: 'Run tests'
command: "{{ pytest_project_command }}"
args:
chdir: "{{ pytest_project_directory }}"
10 changes: 9 additions & 1 deletion roles/robottelo/defaults/main.yml
@@ -1,7 +1,15 @@
---
robottelo_packages:
- gcc
- git
- libffi-devel
- openssl-devel
- rh-python36-python-devel
- rh-python36-python-virtualenv
robottelo_url: https://github.com/SatelliteQE/robottelo.git
robottelo_directory: /root/robottelo
robottelo_virtualenv_path: /root/robottelo/venv
robottelo_requirements: requirements.txt
robottelo_virtualenv_command: /opt/rh/rh-python36/root/bin/virtualenv
robottelo_version: master
robottelo_junit_file: results.xml
robottelo_test_type: endtoend # one of [tier1|tier2|tier3|destructive|upgrade|endtoend]
Expand Down
26 changes: 0 additions & 26 deletions roles/robottelo/tasks/install.yml

This file was deleted.

28 changes: 21 additions & 7 deletions roles/robottelo/tasks/main.yml
@@ -1,6 +1,17 @@
---
- name: 'Install Robottelo via pytest_project'
include_role:
name: pytest_project
tasks_from: install
vars:
pytest_project_packages: "{{ robottelo_packages }}"
pytest_project_url: "{{ robottelo_url }}"
pytest_project_directory: "{{ robottelo_directory }}"
pytest_project_requirements: "{{ robottelo_requirements }}"
pytest_project_virtualenv_command: "{{ robottelo_virtualenv_command }}"
pytest_project_version: "{{ robottelo_version }}"

- include_tasks: ssh.yml
- include_tasks: install.yml

- name: robottelo properties file
shell: cp robottelo.properties.sample robottelo.properties
Expand Down Expand Up @@ -34,9 +45,12 @@
regexp: "^level=DEBUG"
replace: "level=INFO"

- name: Run tests
command: "{{ robottelo_virtualenv_path }}/bin/py.test --junit-xml={{ robottelo_junit_file }}
-m '{{ robottelo_test_options[robottelo_test_type] | default(robottelo_test_options.default) }}'
{{ robottelo_test_path[robottelo_test_type] | default(robottelo_test_path.default) }}"
args:
chdir: "{{ robottelo_directory }}"
- name: 'Run Robottelo via pytest_project'
include_role:
name: pytest_project
tasks_from: run
vars:
pytest_project_directory: "{{ robottelo_directory }}"
pytest_project_junit_output: "{{ robottelo_junit_file }}"
pytest_project_markers: "{{ robottelo_test_options[robottelo_test_type] | default(robottelo_test_options.default) }}"
pytest_project_command_args: "{{ robottelo_test_path[robottelo_test_type] | default(robottelo_test_path.default) }}"
12 changes: 12 additions & 0 deletions roles/smoker/defaults/main.yml
@@ -0,0 +1,12 @@
---
smoker_url: https://github.com/theforeman/smoker
smoker_version: master
smoker_directory: "{{ ansible_env.HOME }}/smoker"
smoker_variables: {}
smoker_variables_path: "{{ smoker_directory }}/variables.json"
smoker_base_url:
smoker_command_args: "--driver chrome --variables '{{ smoker_variables_path }}' --base-url '{{ smoker_base_url }}'"
smoker_markers:
smoker_browser_packages:
- chromium
- chromedriver
32 changes: 32 additions & 0 deletions roles/smoker/tasks/main.yml
@@ -0,0 +1,32 @@
---
- name: 'Install browser'
become: true
package:
name: '{{ smoker_browser_packages }}'

- name: 'Install Smoker via pytest_project'
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's the reasoning behind importing separate task files from the role instead of the whole role?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Both Robottelo and smoker need to do additional configuration. Technically smoker could drop its variables.json anywhere since it's an absolute path but Robottelo modifies files in the cloned repo. Since I started with Robottelo, I continued this way. And do sort of a callback where I provided a role/task with setup was even worse IMHO. If you know a clean way to do this in Ansible, I'd love to hear it.

include_role:
name: pytest_project
tasks_from: install
vars:
pytest_project_url: "{{ smoker_url }}"
pytest_project_version: "{{ smoker_version }}"
pytest_project_directory: "{{ smoker_directory }}"

- name: "Show variables"
debug:
var: smoker_variables

- name: 'Write variables.json'
copy:
dest: "{{ smoker_variables_path }}"
content: "{{ smoker_variables|to_json }}"

- name: 'Run Smoker via pytest_project'
include_role:
name: pytest_project
tasks_from: run
vars:
pytest_project_directory: "{{ smoker_directory }}"
pytest_project_markers: "{{ smoker_markers }}"
pytest_project_command_args: "{{ smoker_command_args }}"