Support testing against remote subjects.

It's a severe anti-pattern for a playbook to assume execution always
on a specific host.  The normal/expected pattern is to execute from a
"control host", against an inventory of (possibly-remote) subjects.

This doesn't preclude the inventory from only ever containing
'localhost', it simply means the plays and tasks should not assume
the inventory contents.

This concept is one of the central design-pillars of Ansible's,
and tantamount to it's usefulness and flexibility.  However, in
practice (and by ``integration/readme.md``), plays
specify ``- hosts: all`` but assume inventory_hostname == 'localhost'
(always).

Fix both the playbooks and ``readme.md`` to remove this anti-pattern,
while also allowing the control-host to be the subject-host as needed.
This is accomplished by ensuring low-level Ansible dependencies are
always installed, and writing tasks for steps previously performed
externally (in the CI/automation machinery).

Also update ``readme.md`` to recommend execution occurs through
the ``venv-ansible-playbook.sh`` wrapper to ensure consistent, stable,
version-locked execution dependencies on the control-host.

Remove ``remote_user: root`` from main, since this is better left
to the inventory and command-line.

Signed-off-by: Chris Evich <cevich@redhat.com>
This commit is contained in:
Chris Evich 2017-10-04 10:37:37 -04:00
parent 7bda7213f9
commit 20ca436b8c
8 changed files with 136 additions and 37 deletions

View file

@ -1,21 +1,49 @@
# Fedora and RHEL Integration and End-to-End Tests # Fedora and RHEL Integration and End-to-End Tests
This directory contains playbooks to set up for and run the integration and This directory contains playbooks to set up for and run the integration and
end-to-end tests for CRI-O on RHEL and Fedora hosts. Two entrypoints exist: end-to-end tests for CRI-O on RHEL and Fedora hosts. The expected entry-point
is the ``main.yml`` Ansible playbook.
- `main.yml`: sets up the machine and runs tests The control-host:
- `results.yml`: gathers test output to `/tmp/artifacts`
When running `main.yml`, three tags are present: - May be the subject.
- Is based on either RHEL/CentOS 6 (or later), or Fedora 24 (or later).
- Runs ``main.yml`` from within the cri-o repository already in the
desired state for testing.
- `setup`: run all tasks to set up the system for testing The subject host(s):
- `e2e`: build CRI-O from source and run Kubernetes node E2Es
- `integration`: build CRI-O from source and run the local integration suite
The playbooks assume the following things about your system: - May be the control-host.
- May be executing the ``main.yml`` playbook against itself.
- If RHEL-like, has the ``server``, ``extras``, and ``EPEL`` repositories available
and enabled.
- Has remote password-less ssh configured for direct or sudo access to the root user.
- on RHEL, the server and extras repos are configured and certs are present Execution of the ``main.yml`` playbook:
- `ansible` is installed and the host is boot-strapped to allow `ansible` to run against it
- the `$GOPATH` is set and present for all shells (*e.g.* written in `/etc/environment`) - Should occur through the ``cri-o/contrib/test/venv-ansible-playbook.sh`` wrapper.
- CRI-O is checked out to the correct state at `${GOPATH}/src/github.com/kubernetes-incubator/cri-o` - Execution may target localhost, or one or more subjects via standard Ansible
- the user running the playbook has access to passwordless `sudo` inventory arguments.
- Should use a combination (including none) of the following tags:
- ``setup``: Run all tasks to set up the system for testing. Final state must
be self-contained and independent from other tags (i.e. support
stage-caching).
- ``integration``: Assumes 'setup' previously completed successfully.
May be executed from cached-state of ``setup``.
Not required to execute conicident with other tags.
Must build CRI-O from source and run the
integration test suite.
- ``e2e``: Assumes 'setup' previously completed successfully. May be executed
from cached-state of ``setup``. Not required to execute conicident with
other tags. Must build CRI-O from source and run Kubernetes node
E2E tests.
``cri-o/contrib/test/venv-ansible-playbook.sh`` Wrapper:
- Must accepts all of the valid Ansible command-line options.
- Must use version-locked & hashed dependencies as written in ``requirements.txt``.
- Must fully sandbox it's own execution environment except for the following
required packages (or equivalent): ``python2-virtualenv gcc openssl-devel
redhat-rpm-config libffi-devel python-devel libselinux-python rsync
yum-utils python3-pycurl python-simplejson``.

View file

@ -1,42 +1,42 @@
--- ---
- name: stat the expected cri-o directory - name: stat the expected cri-o directory and Makefile exists
stat: stat:
path: "{{ ansible_env.GOPATH }}/src/github.com/kubernetes-incubator/cri-o" path: "{{ cri_o_dest_path }}/Makefile"
register: dir_stat register: dir_stat
- name: expect cri-o to be cloned already - name: Verify cri-o Makefile exists in expected location
fail: fail:
msg: "Expected cri-o to be cloned at {{ ansible_env.GOPATH }}/src/github.com/kubernetes-incubator/cri-o but it wasn't!" msg: "Expected cri-o to be cloned at {{ cri_o_dest_path }} but it wasn't!"
when: not dir_stat.stat.exists when: not dir_stat.stat.exists or not dir_stat.stat.isreg
- name: install cri-o tools - name: install cri-o tools
make: make:
target: install.tools target: install.tools
chdir: "{{ ansible_env.GOPATH }}/src/github.com/kubernetes-incubator/cri-o" chdir: "{{ cri_o_dest_path }}"
- name: build cri-o - name: build cri-o
make: make:
chdir: "{{ ansible_env.GOPATH }}/src/github.com/kubernetes-incubator/cri-o" chdir: "{{ cri_o_dest_path }}"
- name: install cri-o - name: install cri-o
make: make:
target: install target: install
chdir: "{{ ansible_env.GOPATH }}/src/github.com/kubernetes-incubator/cri-o" chdir: "{{ cri_o_dest_path }}"
- name: install cri-o systemd files - name: install cri-o systemd files
make: make:
target: install.systemd target: install.systemd
chdir: "{{ ansible_env.GOPATH }}/src/github.com/kubernetes-incubator/cri-o" chdir: "{{ cri_o_dest_path }}"
- name: install cri-o config - name: install cri-o config
make: make:
target: install.config target: install.config
chdir: "{{ ansible_env.GOPATH }}/src/github.com/kubernetes-incubator/cri-o" chdir: "{{ cri_o_dest_path }}"
- name: install configs - name: install configs
copy: copy:
src: "{{ ansible_env.GOPATH }}/src/github.com/kubernetes-incubator/cri-o/{{ item.src }}" src: "{{ cri_o_dest_path }}/{{ item.src }}"
dest: "{{ item.dest }}" dest: "{{ item.dest }}"
remote_src: yes remote_src: yes
with_items: with_items:

View file

@ -0,0 +1,27 @@
---
- name: Verify expectations
assert:
that:
- 'cri_o_dest_path is defined'
- 'cri_o_src_path is defined'
- name: The cri-o repository directory exists
file:
path: "{{ cri_o_dest_path }}"
state: directory
mode: 0777
- name: Synchronize cri-o from control-host to remote subject
synchronize:
archive: False
checksum: True
delete: True
dest: "{{ cri_o_dest_path }}/"
links: True
recursive: True
src: "{{ cri_o_src_path }}/"
times: True
# This task is excessively noisy, logging every change to every file :(
no_log: True

View file

@ -1,5 +1,27 @@
- hosts: all ---
remote_user: root
- hosts: '{{ subjects | default("all") }}'
gather_facts: False # Requires low-level ansible-dependencies
tasks:
- name: Ensure low-level ansible-dependencies are installed
raw: $(type -P dnf || type -P yum) install -y python2 python2-dnf libselinux-python git rsync
- name: Gather only networking facts for speed
setup:
gather_subset: network
- hosts: '{{ subjects | default("none") }}'
vars_files:
- "{{ playbook_dir }}/vars.yml"
tags:
- setup
tasks:
- name: CRI-O source is available on every subject
include: github.yml
- hosts: '{{ subjects | default("all") }}'
vars_files: vars_files:
- "{{ playbook_dir }}/vars.yml" - "{{ playbook_dir }}/vars.yml"
tags: tags:
@ -26,19 +48,18 @@
- name: clone build and install networking plugins - name: clone build and install networking plugins
include: "build/plugins.yml" include: "build/plugins.yml"
- hosts: all
remote_user: root - hosts: '{{ subjects | default("all") }}'
vars_files: vars_files:
- "{{ playbook_dir }}/vars.yml" - "{{ playbook_dir }}/vars.yml"
tags: tags:
- integration - integration
- e2e - e2e
tasks: tasks:
- name: clone build and install cri-o - name: Build and install cri-o
include: "build/cri-o.yml" include: "build/cri-o.yml"
- hosts: all - hosts: '{{ subjects | default("all") }}'
remote_user: root
vars_files: vars_files:
- "{{ playbook_dir }}/vars.yml" - "{{ playbook_dir }}/vars.yml"
tags: tags:
@ -47,8 +68,7 @@
- name: run cri-o integration tests - name: run cri-o integration tests
include: test.yml include: test.yml
- hosts: all - hosts: '{{ subjects | default("all") }}'
remote_user: root
vars_files: vars_files:
- "{{ playbook_dir }}/vars.yml" - "{{ playbook_dir }}/vars.yml"
tags: tags:

View file

@ -1,7 +1,7 @@
--- ---
# vim-syntax: ansible # vim-syntax: ansible
- hosts: '{{ hosts | default("all") }}' - hosts: '{{ subjects | default("all") }}'
vars_files: vars_files:
- "{{ playbook_dir }}/vars.yml" - "{{ playbook_dir }}/vars.yml"
vars: vars:

View file

@ -70,6 +70,7 @@
state: present state: present
with_items: with_items:
- btrfs-progs-devel - btrfs-progs-devel
- python2-virtualenv
when: ansible_distribution in ['Fedora'] when: ansible_distribution in ['Fedora']
- name: Check / setup swap - name: Check / setup swap
@ -110,3 +111,17 @@
- name: Update the kernel cmdline to include quota support - name: Update the kernel cmdline to include quota support
command: grubby --update-kernel=ALL --args="rootflags=pquota" command: grubby --update-kernel=ALL --args="rootflags=pquota"
when: ansible_distribution in ['RedHat', 'CentOS'] when: ansible_distribution in ['RedHat', 'CentOS']
- name: Configure the GOPATH environment variable for all users
blockinfile:
path: /etc/environment
block: "GOPATH={{ go_path }}"
create: True
follow: True
- name: Reset the ansible connection to incorporate /etc/environment changes
meta: reset_connection
- name: Refresh facts to incorporate /etc/environment changes
setup:
gather_subset: network

View file

@ -15,7 +15,7 @@
extra_storage_opts: " --storage-opt overlay.override_kernel_check=1" extra_storage_opts: " --storage-opt overlay.override_kernel_check=1"
when: ansible_distribution == 'RedHat' or ansible_distribution == 'CentOS' when: ansible_distribution == 'RedHat' or ansible_distribution == 'CentOS'
- name: ensure directory exists for e2e reports - name: ensure directory exists for integration results
file: file:
path: "{{ artifacts }}" path: "{{ artifacts }}"
state: directory state: directory
@ -31,9 +31,9 @@
when: not integration_selinux_enabled when: not integration_selinux_enabled
- name: run integration tests - name: run integration tests
shell: "CGROUP_MANAGER=cgroupfs STORAGE_OPTIONS='--storage-driver=overlay{{ extra_storage_opts | default('') }}' make localintegration >& {{ artifacts }}/testout.txt" shell: "CGROUP_MANAGER=cgroupfs STORAGE_OPTS='--storage-driver=overlay{{ extra_storage_opts | default('') }}' make localintegration >& {{ artifacts }}/testout.txt"
args: args:
chdir: "{{ ansible_env.GOPATH }}/src/github.com/kubernetes-incubator/cri-o" chdir: "{{ cri_o_dest_path }}"
async: 5400 async: 5400
poll: 30 poll: 30

View file

@ -13,6 +13,15 @@ e2e_swap_enabled: True
integration_selinux_enabled: True integration_selinux_enabled: True
e2e_selinux_enabled: False e2e_selinux_enabled: False
# Path to encode into /etc/environment on all hosts
go_path: "/go"
# Absolute path on control-host where the cri-o source exists
cri_o_src_path: "{{ playbook_dir }}/../../../"
# Absolute path on subjects where cri-o source is expected
cri_o_dest_path: "{{ go_path }}/src/github.com/kubernetes-incubator/cri-o"
# For results.yml Paths use rsync 'source' conventions # For results.yml Paths use rsync 'source' conventions
artifacts: "/tmp/artifacts" # Base-directory for collection artifacts: "/tmp/artifacts" # Base-directory for collection
crio_integration_filepath: "{{ artifacts }}/testout.txt" crio_integration_filepath: "{{ artifacts }}/testout.txt"