From ff8356b9266a4a6ec216e3aa31e6ff0408212975 Mon Sep 17 00:00:00 2001 From: Rodolfo Carvalho Date: Fri, 4 Nov 2016 16:50:33 +0100 Subject: Move Python unit tests to subdirectory To make room for integration tests. --- test/modify_yaml_tests.py | 37 ------------------------------------- test/unit/modify_yaml_tests.py | 37 +++++++++++++++++++++++++++++++++++++ 2 files changed, 37 insertions(+), 37 deletions(-) delete mode 100644 test/modify_yaml_tests.py create mode 100644 test/unit/modify_yaml_tests.py (limited to 'test') diff --git a/test/modify_yaml_tests.py b/test/modify_yaml_tests.py deleted file mode 100644 index 0dc25df82..000000000 --- a/test/modify_yaml_tests.py +++ /dev/null @@ -1,37 +0,0 @@ -""" Tests for the modify_yaml Ansible module. """ -# pylint: disable=missing-docstring,invalid-name - -import os -import sys -import unittest - -sys.path = [os.path.abspath(os.path.dirname(__file__) + "/../library/")] + sys.path - -# pylint: disable=import-error -from modify_yaml import set_key # noqa: E402 - - -class ModifyYamlTests(unittest.TestCase): - - def test_simple_nested_value(self): - cfg = {"section": {"a": 1, "b": 2}} - changes = set_key(cfg, 'section.c', 3) - self.assertEquals(1, len(changes)) - self.assertEquals(3, cfg['section']['c']) - - # Tests a previous bug where property would land in section above where it should, - # if the destination section did not yet exist: - def test_nested_property_in_new_section(self): - cfg = { - "masterClients": { - "externalKubernetesKubeConfig": "", - "openshiftLoopbackKubeConfig": "openshift-master.kubeconfig", - }, - } - - yaml_key = 'masterClients.externalKubernetesClientConnectionOverrides.acceptContentTypes' - yaml_value = 'application/vnd.kubernetes.protobuf,application/json' - set_key(cfg, yaml_key, yaml_value) - self.assertEquals(yaml_value, cfg['masterClients'] - ['externalKubernetesClientConnectionOverrides'] - ['acceptContentTypes']) diff --git a/test/unit/modify_yaml_tests.py b/test/unit/modify_yaml_tests.py new file mode 100644 index 000000000..65b2db44c --- /dev/null +++ b/test/unit/modify_yaml_tests.py @@ -0,0 +1,37 @@ +""" Tests for the modify_yaml Ansible module. """ +# pylint: disable=missing-docstring,invalid-name + +import os +import sys +import unittest + +sys.path = [os.path.abspath(os.path.dirname(__file__) + "/../../library/")] + sys.path + +# pylint: disable=import-error +from modify_yaml import set_key # noqa: E402 + + +class ModifyYamlTests(unittest.TestCase): + + def test_simple_nested_value(self): + cfg = {"section": {"a": 1, "b": 2}} + changes = set_key(cfg, 'section.c', 3) + self.assertEquals(1, len(changes)) + self.assertEquals(3, cfg['section']['c']) + + # Tests a previous bug where property would land in section above where it should, + # if the destination section did not yet exist: + def test_nested_property_in_new_section(self): + cfg = { + "masterClients": { + "externalKubernetesKubeConfig": "", + "openshiftLoopbackKubeConfig": "openshift-master.kubeconfig", + }, + } + + yaml_key = 'masterClients.externalKubernetesClientConnectionOverrides.acceptContentTypes' + yaml_value = 'application/vnd.kubernetes.protobuf,application/json' + set_key(cfg, yaml_key, yaml_value) + self.assertEquals(yaml_value, cfg['masterClients'] + ['externalKubernetesClientConnectionOverrides'] + ['acceptContentTypes']) -- cgit v1.2.1 From 634a8957e1cc29374a170aaa8c2113b8fbbfe7e4 Mon Sep 17 00:00:00 2001 From: Rodolfo Carvalho Date: Fri, 4 Nov 2016 18:30:34 +0100 Subject: Add stub of preflight integration tests --- test/integration/README.md | 12 +++ .../integration/openshift_health_checker/common.go | 99 ++++++++++++++++++++++ .../example/example_test.go | 26 ++++++ .../example/playbooks/test_fail.yml | 14 +++ .../example/playbooks/test_ping.yml | 14 +++ .../preflight/playbooks/preflight_fail_all.yml | 11 +++ .../preflight/playbooks/setup_container.yml | 23 +++++ .../preflight/preflight_test.go | 24 ++++++ 8 files changed, 223 insertions(+) create mode 100644 test/integration/README.md create mode 100644 test/integration/openshift_health_checker/common.go create mode 100644 test/integration/openshift_health_checker/example/example_test.go create mode 100644 test/integration/openshift_health_checker/example/playbooks/test_fail.yml create mode 100644 test/integration/openshift_health_checker/example/playbooks/test_ping.yml create mode 100644 test/integration/openshift_health_checker/preflight/playbooks/preflight_fail_all.yml create mode 100644 test/integration/openshift_health_checker/preflight/playbooks/setup_container.yml create mode 100644 test/integration/openshift_health_checker/preflight/preflight_test.go (limited to 'test') diff --git a/test/integration/README.md b/test/integration/README.md new file mode 100644 index 000000000..0edbccd74 --- /dev/null +++ b/test/integration/README.md @@ -0,0 +1,12 @@ +# Integration tests + +Integration tests exercise the OpenShift Ansible playbooks by performing +simulated installations in Docker containers. + +## Running the tests + +From the repository root, run with: + +``` +tox -e integration +``` diff --git a/test/integration/openshift_health_checker/common.go b/test/integration/openshift_health_checker/common.go new file mode 100644 index 000000000..aea85342f --- /dev/null +++ b/test/integration/openshift_health_checker/common.go @@ -0,0 +1,99 @@ +package test + +import ( + "bytes" + "os" + "os/exec" + "path/filepath" + "strings" + "syscall" + "testing" +) + +// A PlaybookTest executes a given Ansible playbook and checks the exit code and +// output contents. +type PlaybookTest struct { + // inputs + Path string + // expected outputs + ExitCode int + Output []string // zero or more strings that should be in the output +} + +// Run runs the PlaybookTest. +func (p PlaybookTest) Run(t *testing.T) { + // A PlaybookTest is intended to be run in parallel with other tests. + t.Parallel() + + cmd := exec.Command("ansible-playbook", p.Path) + cmd.Env = append(os.Environ(), "ANSIBLE_FORCE_COLOR=1") + b, err := cmd.CombinedOutput() + + // Check exit code. + if (err == nil) && (p.ExitCode != 0) { + p.checkExitCode(t, 0, p.ExitCode, cmd, b) + } + if (err != nil) && (p.ExitCode == 0) { + got, ok := getExitCode(err) + if !ok { + t.Logf("unexpected error (%T): %[1]v", err) + p.logCmdAndOutput(t, cmd, b) + t.FailNow() + } + p.checkExitCode(t, got, p.ExitCode, cmd, b) + } + + // Check output contents. + var missing []string + for _, s := range p.Output { + if !bytes.Contains(b, []byte(s)) { + missing = append(missing, s) + } + } + if len(missing) > 0 { + t.Logf("missing in output: %q", missing) + p.logCmdAndOutput(t, cmd, b) + t.FailNow() + } +} + +// getExitCode returns an exit code and true if the exit code could be taken +// from err, false otherwise. +// The implementation is GOOS-specific, and currently only supports Linux. +func getExitCode(err error) (int, bool) { + exitErr, ok := err.(*exec.ExitError) + if !ok { + return -1, false + } + waitStatus, ok := exitErr.Sys().(syscall.WaitStatus) + if !ok { + return -1, false + } + return waitStatus.ExitStatus(), true +} + +// checkExitCode marks the test as failed when got is different than want. +func (p PlaybookTest) checkExitCode(t *testing.T, got, want int, cmd *exec.Cmd, output []byte) { + if got == want { + return + } + t.Logf("got exit code %v, want %v", got, want) + p.logCmdAndOutput(t, cmd, output) + t.FailNow() +} + +// logCmdAndOutput logs how to re-run a command and a summary of the output of +// its last execution for debugging. +func (p PlaybookTest) logCmdAndOutput(t *testing.T, cmd *exec.Cmd, output []byte) { + const maxLines = 10 + lines := bytes.Split(bytes.TrimRight(output, "\n"), []byte("\n")) + if len(lines) > maxLines { + lines = append([][]byte{[]byte("...")}, lines[len(lines)-maxLines:len(lines)]...) + } + output = bytes.Join(lines, []byte("\n")) + dir, err := filepath.Abs(cmd.Dir) + if err != nil { + panic(err) + } + t.Logf("\n$ (cd %s && %s)\n%s", dir, strings.Join(cmd.Args, " "), output) +} diff --git a/test/integration/openshift_health_checker/example/example_test.go b/test/integration/openshift_health_checker/example/example_test.go new file mode 100644 index 000000000..f59c21291 --- /dev/null +++ b/test/integration/openshift_health_checker/example/example_test.go @@ -0,0 +1,26 @@ +package example + +import ( + "testing" + + . ".." +) + +// TestPing and TestFail below are just examples of tests that involve running +// 'ansible-playbook' with a given playbook and verifying the outcome. Real +// tests look similar, but call more interesting playbooks. + +func TestPing(t *testing.T) { + PlaybookTest{ + Path: "playbooks/test_ping.yml", + Output: []string{"[test ping]"}, + }.Run(t) +} + +func TestFail(t *testing.T) { + PlaybookTest{ + Path: "playbooks/test_fail.yml", + ExitCode: 2, + Output: []string{"[test fail]", `"msg": "Failed as requested from task"`}, + }.Run(t) +} diff --git a/test/integration/openshift_health_checker/example/playbooks/test_fail.yml b/test/integration/openshift_health_checker/example/playbooks/test_fail.yml new file mode 100644 index 000000000..318f1c507 --- /dev/null +++ b/test/integration/openshift_health_checker/example/playbooks/test_fail.yml @@ -0,0 +1,14 @@ +--- +# This is just a placeholder playbook. Our aim is to make it: +# 1. Build one or more Docker images with a certain interesting state; +# 2. Ensure one or more containers (with random names) are running with the +# latest build of the image; +# 3. Run the byo OpenShift installation playbook targeting the container. +- hosts: localhost + gather_facts: no + tasks: + - name: waste some time + pause: + seconds: 1 + - name: test fail + fail: diff --git a/test/integration/openshift_health_checker/example/playbooks/test_ping.yml b/test/integration/openshift_health_checker/example/playbooks/test_ping.yml new file mode 100644 index 000000000..da31b3d85 --- /dev/null +++ b/test/integration/openshift_health_checker/example/playbooks/test_ping.yml @@ -0,0 +1,14 @@ +--- +# This is just a placeholder playbook. Our aim is to make it: +# 1. Build one or more Docker images with a certain interesting state; +# 2. Ensure one or more containers (with random names) are running with the +# latest build of the image; +# 3. Run the byo OpenShift installation playbook targeting the container. +- hosts: localhost + gather_facts: no + tasks: + - name: waste some time + pause: + seconds: 1 + - name: test ping + ping: diff --git a/test/integration/openshift_health_checker/preflight/playbooks/preflight_fail_all.yml b/test/integration/openshift_health_checker/preflight/playbooks/preflight_fail_all.yml new file mode 100644 index 000000000..e7790a0d4 --- /dev/null +++ b/test/integration/openshift_health_checker/preflight/playbooks/preflight_fail_all.yml @@ -0,0 +1,11 @@ +--- +- include: setup_container.yml + vars: + name: preflight_fail_all + +- name: Run preflight checks + include: ../../../../../playbooks/byo/openshift-preflight/check.yml + +# - include: tasks/teardown_container.yml +# vars: +# name: preflight_fail_all diff --git a/test/integration/openshift_health_checker/preflight/playbooks/setup_container.yml b/test/integration/openshift_health_checker/preflight/playbooks/setup_container.yml new file mode 100644 index 000000000..fff797c27 --- /dev/null +++ b/test/integration/openshift_health_checker/preflight/playbooks/setup_container.yml @@ -0,0 +1,23 @@ +--- +# Required vars: +# * name = name of the container to be started + +- name: Start CentOS 7 container + gather_facts: no + hosts: localhost + connection: local + vars: + container_name: openshift_ansible_test_{{ name }} + tasks: + - name: start container + docker_container: + name: "{{ container_name }}" + image: centos:7 + command: sleep infinity + recreate: yes + - name: add host + add_host: + name: "{{ container_name }}" + ansible_connection: docker + groups: OSEv3,masters,nodes + deployment_type: origin diff --git a/test/integration/openshift_health_checker/preflight/preflight_test.go b/test/integration/openshift_health_checker/preflight/preflight_test.go new file mode 100644 index 000000000..a1b98bf0f --- /dev/null +++ b/test/integration/openshift_health_checker/preflight/preflight_test.go @@ -0,0 +1,24 @@ +package preflight + +import ( + "testing" + + . ".." +) + +func TestPreflightFailAll(t *testing.T) { + PlaybookTest{ + Path: "playbooks/preflight_fail_all.yml", + ExitCode: 2, + Output: []string{ + "Failure summary", + "Cannot install all of the necessary packages", + "origin-clients", + "origin-master", + "origin-node", + "origin-sdn-ovs", + "python-httplib2", + "failed=1", + }, + }.Run(t) +} -- cgit v1.2.1 From 75f0c57654429d3b861d792169a9c1bdf9156bf8 Mon Sep 17 00:00:00 2001 From: Luke Meyer Date: Thu, 30 Mar 2017 13:08:34 -0400 Subject: preflight int tests: generalize; add tests Make the container setup and teardown more reusable. Remove example tests. Add basic package tests. --- .../example/example_test.go | 26 ------ .../example/playbooks/test_fail.yml | 14 --- .../example/playbooks/test_ping.yml | 14 --- .../package_availability_missing_required.yml | 20 ++++ .../playbooks/package_availability_succeeds.yml | 20 ++++ .../playbooks/package_update_dep_missing.yml | 24 +++++ .../playbooks/package_update_repo_broken.yml | 31 +++++++ .../playbooks/package_update_repo_disabled.yml | 21 +++++ .../playbooks/package_update_repo_unreachable.yml | 27 ++++++ .../playbooks/package_version_matches.yml | 24 +++++ .../playbooks/package_version_mismatches.yml | 24 +++++ .../playbooks/package_version_multiple.yml | 26 ++++++ .../preflight/playbooks/package_version_origin.yml | 20 ++++ .../preflight/playbooks/preflight_fail_all.yml | 11 --- .../preflight/playbooks/roles | 1 + .../preflight/playbooks/setup_container.yml | 23 ----- .../preflight/playbooks/tasks/enable_repo.yml | 9 ++ .../preflight/preflight_test.go | 101 +++++++++++++++++++-- .../openshift_health_checker/setup_container.yml | 45 +++++++++ .../teardown_container.yml | 23 +++++ 20 files changed, 406 insertions(+), 98 deletions(-) delete mode 100644 test/integration/openshift_health_checker/example/example_test.go delete mode 100644 test/integration/openshift_health_checker/example/playbooks/test_fail.yml delete mode 100644 test/integration/openshift_health_checker/example/playbooks/test_ping.yml create mode 100644 test/integration/openshift_health_checker/preflight/playbooks/package_availability_missing_required.yml create mode 100644 test/integration/openshift_health_checker/preflight/playbooks/package_availability_succeeds.yml create mode 100644 test/integration/openshift_health_checker/preflight/playbooks/package_update_dep_missing.yml create mode 100644 test/integration/openshift_health_checker/preflight/playbooks/package_update_repo_broken.yml create mode 100644 test/integration/openshift_health_checker/preflight/playbooks/package_update_repo_disabled.yml create mode 100644 test/integration/openshift_health_checker/preflight/playbooks/package_update_repo_unreachable.yml create mode 100644 test/integration/openshift_health_checker/preflight/playbooks/package_version_matches.yml create mode 100644 test/integration/openshift_health_checker/preflight/playbooks/package_version_mismatches.yml create mode 100644 test/integration/openshift_health_checker/preflight/playbooks/package_version_multiple.yml create mode 100644 test/integration/openshift_health_checker/preflight/playbooks/package_version_origin.yml delete mode 100644 test/integration/openshift_health_checker/preflight/playbooks/preflight_fail_all.yml create mode 120000 test/integration/openshift_health_checker/preflight/playbooks/roles delete mode 100644 test/integration/openshift_health_checker/preflight/playbooks/setup_container.yml create mode 100644 test/integration/openshift_health_checker/preflight/playbooks/tasks/enable_repo.yml create mode 100644 test/integration/openshift_health_checker/setup_container.yml create mode 100644 test/integration/openshift_health_checker/teardown_container.yml (limited to 'test') diff --git a/test/integration/openshift_health_checker/example/example_test.go b/test/integration/openshift_health_checker/example/example_test.go deleted file mode 100644 index f59c21291..000000000 --- a/test/integration/openshift_health_checker/example/example_test.go +++ /dev/null @@ -1,26 +0,0 @@ -package example - -import ( - "testing" - - . ".." -) - -// TestPing and TestFail below are just examples of tests that involve running -// 'ansible-playbook' with a given playbook and verifying the outcome. Real -// tests look similar, but call more interesting playbooks. - -func TestPing(t *testing.T) { - PlaybookTest{ - Path: "playbooks/test_ping.yml", - Output: []string{"[test ping]"}, - }.Run(t) -} - -func TestFail(t *testing.T) { - PlaybookTest{ - Path: "playbooks/test_fail.yml", - ExitCode: 2, - Output: []string{"[test fail]", `"msg": "Failed as requested from task"`}, - }.Run(t) -} diff --git a/test/integration/openshift_health_checker/example/playbooks/test_fail.yml b/test/integration/openshift_health_checker/example/playbooks/test_fail.yml deleted file mode 100644 index 318f1c507..000000000 --- a/test/integration/openshift_health_checker/example/playbooks/test_fail.yml +++ /dev/null @@ -1,14 +0,0 @@ ---- -# This is just a placeholder playbook. Our aim is to make it: -# 1. Build one or more Docker images with a certain interesting state; -# 2. Ensure one or more containers (with random names) are running with the -# latest build of the image; -# 3. Run the byo OpenShift installation playbook targeting the container. -- hosts: localhost - gather_facts: no - tasks: - - name: waste some time - pause: - seconds: 1 - - name: test fail - fail: diff --git a/test/integration/openshift_health_checker/example/playbooks/test_ping.yml b/test/integration/openshift_health_checker/example/playbooks/test_ping.yml deleted file mode 100644 index da31b3d85..000000000 --- a/test/integration/openshift_health_checker/example/playbooks/test_ping.yml +++ /dev/null @@ -1,14 +0,0 @@ ---- -# This is just a placeholder playbook. Our aim is to make it: -# 1. Build one or more Docker images with a certain interesting state; -# 2. Ensure one or more containers (with random names) are running with the -# latest build of the image; -# 3. Run the byo OpenShift installation playbook targeting the container. -- hosts: localhost - gather_facts: no - tasks: - - name: waste some time - pause: - seconds: 1 - - name: test ping - ping: diff --git a/test/integration/openshift_health_checker/preflight/playbooks/package_availability_missing_required.yml b/test/integration/openshift_health_checker/preflight/playbooks/package_availability_missing_required.yml new file mode 100644 index 000000000..31d0d521e --- /dev/null +++ b/test/integration/openshift_health_checker/preflight/playbooks/package_availability_missing_required.yml @@ -0,0 +1,20 @@ +--- +- include: ../../setup_container.yml + vars: + image: preflight-aos-package-checks + l_host_vars: + deployment_type: openshift-enterprise + +- name: Fail as required packages cannot be installed + hosts: all + roles: + - openshift_health_checker + tasks: + - block: + + - action: openshift_health_check + args: + checks: [ 'package_availability' ] + + always: # destroy the container whether check passed or not + - include: ../../teardown_container.yml diff --git a/test/integration/openshift_health_checker/preflight/playbooks/package_availability_succeeds.yml b/test/integration/openshift_health_checker/preflight/playbooks/package_availability_succeeds.yml new file mode 100644 index 000000000..16ff41673 --- /dev/null +++ b/test/integration/openshift_health_checker/preflight/playbooks/package_availability_succeeds.yml @@ -0,0 +1,20 @@ +--- +- include: ../../setup_container.yml + vars: + image: preflight-aos-package-checks + l_host_vars: + deployment_type: origin + +- name: Succeeds as Origin packages are public + hosts: all + roles: + - openshift_health_checker + tasks: + - block: + + - action: openshift_health_check + args: + checks: [ 'package_availability' ] + + always: # destroy the container whether check passed or not + - include: ../../teardown_container.yml diff --git a/test/integration/openshift_health_checker/preflight/playbooks/package_update_dep_missing.yml b/test/integration/openshift_health_checker/preflight/playbooks/package_update_dep_missing.yml new file mode 100644 index 000000000..7b6e71f91 --- /dev/null +++ b/test/integration/openshift_health_checker/preflight/playbooks/package_update_dep_missing.yml @@ -0,0 +1,24 @@ +--- +- include: ../../setup_container.yml + vars: + image: preflight-aos-package-checks + l_host_vars: + openshift_deployment_type: openshift-enterprise + openshift_release: 3.2 + +- name: Fails when a dependency required for update is missing + hosts: all + roles: + - openshift_health_checker + tasks: + - block: + + - include: tasks/enable_repo.yml + vars: { repo_name: "break-yum" } + + - action: openshift_health_check + args: + checks: [ 'package_update' ] + + always: # destroy the container whether check passed or not + - include: ../../teardown_container.yml diff --git a/test/integration/openshift_health_checker/preflight/playbooks/package_update_repo_broken.yml b/test/integration/openshift_health_checker/preflight/playbooks/package_update_repo_broken.yml new file mode 100644 index 000000000..c2e9c3866 --- /dev/null +++ b/test/integration/openshift_health_checker/preflight/playbooks/package_update_repo_broken.yml @@ -0,0 +1,31 @@ +--- +- include: ../../setup_container.yml + vars: + image: preflight-aos-package-checks + l_host_vars: + openshift_deployment_type: openshift-enterprise + openshift_release: 3.2 + +- name: Fails when a repo definition is completely broken + hosts: all + roles: + - openshift_health_checker + tasks: + - block: + + - include: tasks/enable_repo.yml + vars: { repo_name: "break-yum" } + + - name: Break the break-yum repo + replace: + dest: /etc/yum.repos.d/break-yum.repo + backup: no + regexp: "^baseurl" + replace: "#baseurl" + + - action: openshift_health_check + args: + checks: [ 'package_update' ] + + always: # destroy the container whether check passed or not + - include: ../../teardown_container.yml diff --git a/test/integration/openshift_health_checker/preflight/playbooks/package_update_repo_disabled.yml b/test/integration/openshift_health_checker/preflight/playbooks/package_update_repo_disabled.yml new file mode 100644 index 000000000..98d41aad4 --- /dev/null +++ b/test/integration/openshift_health_checker/preflight/playbooks/package_update_repo_disabled.yml @@ -0,0 +1,21 @@ +--- +- include: ../../setup_container.yml + vars: + image: preflight-aos-package-checks + l_host_vars: + openshift_deployment_type: openshift-enterprise + openshift_release: 3.2 + +- name: Succeeds when nothing blocks a yum update + hosts: all + roles: + - openshift_health_checker + tasks: + - block: + + - action: openshift_health_check + args: + checks: [ 'package_update' ] + + always: # destroy the container whether check passed or not + - include: ../../teardown_container.yml diff --git a/test/integration/openshift_health_checker/preflight/playbooks/package_update_repo_unreachable.yml b/test/integration/openshift_health_checker/preflight/playbooks/package_update_repo_unreachable.yml new file mode 100644 index 000000000..60ab9942a --- /dev/null +++ b/test/integration/openshift_health_checker/preflight/playbooks/package_update_repo_unreachable.yml @@ -0,0 +1,27 @@ +--- +- include: ../../setup_container.yml + vars: + image: preflight-aos-package-checks + l_host_vars: + openshift_deployment_type: openshift-enterprise + openshift_release: 3.2 + +- name: Fails when repo content is not available + hosts: all + roles: + - openshift_health_checker + tasks: + - block: + + - include: tasks/enable_repo.yml + vars: { repo_name: "break-yum" } + + - name: Remove the local repo entirely + file: path=/mnt/localrepo state=absent + + - action: openshift_health_check + args: + checks: [ 'package_update' ] + + always: # destroy the container whether check passed or not + - include: ../../teardown_container.yml diff --git a/test/integration/openshift_health_checker/preflight/playbooks/package_version_matches.yml b/test/integration/openshift_health_checker/preflight/playbooks/package_version_matches.yml new file mode 100644 index 000000000..cd60dee5a --- /dev/null +++ b/test/integration/openshift_health_checker/preflight/playbooks/package_version_matches.yml @@ -0,0 +1,24 @@ +--- +- include: ../../setup_container.yml + vars: + image: preflight-aos-package-checks + l_host_vars: + deployment_type: openshift-enterprise + openshift_release: 3.2 + +- name: Success when AOS version matches openshift_release + hosts: all + roles: + - openshift_health_checker + tasks: + - block: + + - include: tasks/enable_repo.yml + vars: { repo_name: "ose-3.2" } + + - action: openshift_health_check + args: + checks: [ 'package_version' ] + + always: # destroy the container whether check passed or not + - include: ../../teardown_container.yml diff --git a/test/integration/openshift_health_checker/preflight/playbooks/package_version_mismatches.yml b/test/integration/openshift_health_checker/preflight/playbooks/package_version_mismatches.yml new file mode 100644 index 000000000..5939a1ef1 --- /dev/null +++ b/test/integration/openshift_health_checker/preflight/playbooks/package_version_mismatches.yml @@ -0,0 +1,24 @@ +--- +- include: ../../setup_container.yml + vars: + image: preflight-aos-package-checks + l_host_vars: + deployment_type: openshift-enterprise + openshift_release: 3.3 + +- name: Failure when AOS version doesn't match openshift_release + hosts: all + roles: + - openshift_health_checker + tasks: + - block: + + - include: tasks/enable_repo.yml + vars: { repo_name: "ose-3.2" } + + - action: openshift_health_check + args: + checks: [ 'package_version' ] + + always: # destroy the container whether check passed or not + - include: ../../teardown_container.yml diff --git a/test/integration/openshift_health_checker/preflight/playbooks/package_version_multiple.yml b/test/integration/openshift_health_checker/preflight/playbooks/package_version_multiple.yml new file mode 100644 index 000000000..be0f9bc7a --- /dev/null +++ b/test/integration/openshift_health_checker/preflight/playbooks/package_version_multiple.yml @@ -0,0 +1,26 @@ +--- +- include: ../../setup_container.yml + vars: + image: preflight-aos-package-checks + l_host_vars: + openshift_deployment_type: openshift-enterprise + +- name: Fails when multiple AOS versions are available + hosts: all + roles: + - openshift_health_checker + tasks: + - block: + + - include: tasks/enable_repo.yml + vars: { repo_name: "ose-3.2" } + + - include: tasks/enable_repo.yml + vars: { repo_name: "ose-3.3" } + + - action: openshift_health_check + args: + checks: [ 'package_version' ] + + always: # destroy the container whether check passed or not + - include: ../../teardown_container.yml diff --git a/test/integration/openshift_health_checker/preflight/playbooks/package_version_origin.yml b/test/integration/openshift_health_checker/preflight/playbooks/package_version_origin.yml new file mode 100644 index 000000000..da3f6b844 --- /dev/null +++ b/test/integration/openshift_health_checker/preflight/playbooks/package_version_origin.yml @@ -0,0 +1,20 @@ +--- +- include: ../../setup_container.yml + vars: + image: preflight-aos-package-checks + l_host_vars: + openshift_deployment_type: origin + +- name: Succeeds with Origin although multiple versions are available + hosts: all + roles: + - openshift_health_checker + tasks: + - block: + + - action: openshift_health_check + args: + checks: [ 'package_version' ] + + always: # destroy the container whether check passed or not + - include: ../../teardown_container.yml diff --git a/test/integration/openshift_health_checker/preflight/playbooks/preflight_fail_all.yml b/test/integration/openshift_health_checker/preflight/playbooks/preflight_fail_all.yml deleted file mode 100644 index e7790a0d4..000000000 --- a/test/integration/openshift_health_checker/preflight/playbooks/preflight_fail_all.yml +++ /dev/null @@ -1,11 +0,0 @@ ---- -- include: setup_container.yml - vars: - name: preflight_fail_all - -- name: Run preflight checks - include: ../../../../../playbooks/byo/openshift-preflight/check.yml - -# - include: tasks/teardown_container.yml -# vars: -# name: preflight_fail_all diff --git a/test/integration/openshift_health_checker/preflight/playbooks/roles b/test/integration/openshift_health_checker/preflight/playbooks/roles new file mode 120000 index 000000000..6bc1a7aef --- /dev/null +++ b/test/integration/openshift_health_checker/preflight/playbooks/roles @@ -0,0 +1 @@ +../../../../../roles \ No newline at end of file diff --git a/test/integration/openshift_health_checker/preflight/playbooks/setup_container.yml b/test/integration/openshift_health_checker/preflight/playbooks/setup_container.yml deleted file mode 100644 index fff797c27..000000000 --- a/test/integration/openshift_health_checker/preflight/playbooks/setup_container.yml +++ /dev/null @@ -1,23 +0,0 @@ ---- -# Required vars: -# * name = name of the container to be started - -- name: Start CentOS 7 container - gather_facts: no - hosts: localhost - connection: local - vars: - container_name: openshift_ansible_test_{{ name }} - tasks: - - name: start container - docker_container: - name: "{{ container_name }}" - image: centos:7 - command: sleep infinity - recreate: yes - - name: add host - add_host: - name: "{{ container_name }}" - ansible_connection: docker - groups: OSEv3,masters,nodes - deployment_type: origin diff --git a/test/integration/openshift_health_checker/preflight/playbooks/tasks/enable_repo.yml b/test/integration/openshift_health_checker/preflight/playbooks/tasks/enable_repo.yml new file mode 100644 index 000000000..aaacf205e --- /dev/null +++ b/test/integration/openshift_health_checker/preflight/playbooks/tasks/enable_repo.yml @@ -0,0 +1,9 @@ +--- +- name: Enable {{ repo_name }} repo + # believe it or not we can't use the yum_repository module for this. + # https://github.com/ansible/ansible-modules-extras/issues/2384 + ini_file: + dest: /etc/yum.repos.d/{{ repo_name }}.repo + section: "{{ repo_name }}" + option: enabled + value: 1 diff --git a/test/integration/openshift_health_checker/preflight/preflight_test.go b/test/integration/openshift_health_checker/preflight/preflight_test.go index a1b98bf0f..05ddf139f 100644 --- a/test/integration/openshift_health_checker/preflight/preflight_test.go +++ b/test/integration/openshift_health_checker/preflight/preflight_test.go @@ -6,19 +6,100 @@ import ( . ".." ) -func TestPreflightFailAll(t *testing.T) { +func TestPackageUpdateDepMissing(t *testing.T) { PlaybookTest{ - Path: "playbooks/preflight_fail_all.yml", + Path: "playbooks/package_update_dep_missing.yml", ExitCode: 2, Output: []string{ - "Failure summary", - "Cannot install all of the necessary packages", - "origin-clients", - "origin-master", - "origin-node", - "origin-sdn-ovs", - "python-httplib2", - "failed=1", + "check \"package_update\":", + "Could not perform a yum update.", + "break-yum-update-1.0-2.noarch requires package-that-does-not-exist", + }, + }.Run(t) +} + +func TestPackageUpdateRepoBroken(t *testing.T) { + PlaybookTest{ + Path: "playbooks/package_update_repo_broken.yml", + ExitCode: 2, + Output: []string{ + "check \"package_update\":", + "Error with yum repository configuration: Cannot find a valid baseurl for repo", + }, + }.Run(t) +} + +func TestPackageUpdateRepoDisabled(t *testing.T) { + PlaybookTest{ + Path: "playbooks/package_update_repo_disabled.yml", + ExitCode: 0, + Output: []string{ + "CHECK [package_update", + }, + }.Run(t) +} + +func TestPackageUpdateRepoUnreachable(t *testing.T) { + PlaybookTest{ + Path: "playbooks/package_update_repo_unreachable.yml", + ExitCode: 2, + Output: []string{ + "check \"package_update\":", + "Error getting data from at least one yum repository", + }, + }.Run(t) +} + +func TestPackageVersionMatches(t *testing.T) { + PlaybookTest{ + Path: "playbooks/package_version_matches.yml", + ExitCode: 0, + Output: []string{ + "CHECK [package_version", + }, + }.Run(t) +} + +func TestPackageVersionMismatches(t *testing.T) { + PlaybookTest{ + Path: "playbooks/package_version_mismatches.yml", + ExitCode: 2, + Output: []string{ + "check \"package_version\":", + "Not all of the required packages are available at requested version", + }, + }.Run(t) +} + +func TestPackageVersionMultiple(t *testing.T) { + PlaybookTest{ + Path: "playbooks/package_version_multiple.yml", + ExitCode: 2, + Output: []string{ + "check \"package_version\":", + "Multiple minor versions of these packages are available", + }, + }.Run(t) +} + +func TestPackageAvailabilityMissingRequired(t *testing.T) { + PlaybookTest{ + Path: "playbooks/package_availability_missing_required.yml", + ExitCode: 2, + Output: []string{ + "check \"package_availability\":", + "Cannot install all of the necessary packages.", + "atomic-openshift", + }, + }.Run(t) +} + +func TestPackageAvailabilitySucceeds(t *testing.T) { + PlaybookTest{ + Path: "playbooks/package_availability_succeeds.yml", + ExitCode: 0, + Output: []string{ + "CHECK [package_availability", }, }.Run(t) } diff --git a/test/integration/openshift_health_checker/setup_container.yml b/test/integration/openshift_health_checker/setup_container.yml new file mode 100644 index 000000000..4dd2c4b1e --- /dev/null +++ b/test/integration/openshift_health_checker/setup_container.yml @@ -0,0 +1,45 @@ +--- +# Include this play once for each container you want to create and use as a test host. +# +# Optional parameters on the include are as follows: +# * scenario = unique name for the container to be started +# * image = name of the image to start in the container +# * command = command to run in the container +# * l_groups = host groups that the container should be added to +# * l_host_vars = any variables that should be added to the host + +- name: Start container for specified test host + gather_facts: no + hosts: localhost + connection: local + tasks: + + - set_fact: + # This is a little weird but if we use a var instead of a fact, + # a different random value is generated for each task. See: + # https://opensolitude.com/2015/05/27/ansible-lookups-variables-vs-facts.html + container_name: openshift_ansible_test_{{ scenario | default(100000000000000 | random) }} + + - name: start container + docker_container: + name: "{{ container_name }}" + image: "{{ image | default('test-target-base') }}" + command: "{{ command | default('sleep 1800') }}" + recreate: yes + # NOTE: When/if we need to run containers that are docker hosts as well: + # volumes: [ "/var/run/docker.sock:/var/run/docker.sock:z" ] + + - name: add container as host in inventory + add_host: + ansible_connection: docker + name: "{{ container_name }}" + groups: '{{ l_groups | default("masters,nodes,etcd") }}' + + # There ought to be a better way to transfer the host vars, but see: + # https://groups.google.com/forum/#!topic/Ansible-project/Jwx8RYhqxPA + - name: set host facts per test parameters + set_fact: + "{{ item.key }}": "{{ item.value }}" + delegate_facts: True + delegate_to: "{{ container_name }}" + with_dict: "{{ l_host_vars | default({}) }}" diff --git a/test/integration/openshift_health_checker/teardown_container.yml b/test/integration/openshift_health_checker/teardown_container.yml new file mode 100644 index 000000000..fe11e2617 --- /dev/null +++ b/test/integration/openshift_health_checker/teardown_container.yml @@ -0,0 +1,23 @@ +--- + +# Include this to delete the current test host container. +# +# In order to recover from test exceptions, this cleanup is expected to +# be done in an "always:" task on the same block as the test task(s). So +# it happens in a task "on" the host being tested. In order to delete the +# host's container, the task uses its own hostname (which is same as the +# container name) but delegates the docker action to localhost. + +- block: + + # so handlers don't break the test by trying to run after teardown: + - meta: flush_handlers + + always: + + - name: delete test container + delegate_to: localhost + connection: local + docker_container: + name: "{{ inventory_hostname }}" + state: absent -- cgit v1.2.1 From ce4c2f0cc0b4766eff28f5fa91eb353301ad9c91 Mon Sep 17 00:00:00 2001 From: Luke Meyer Date: Thu, 30 Mar 2017 13:11:45 -0400 Subject: preflight int tests: define image builds to support tests --- .../builds/Dockerfile.test-target-base | 2 + .../builds/aos-package-checks/Dockerfile | 30 +++++++++++++++ .../root/etc/yum.repos.d/break-yum.repo | 5 +++ .../root/etc/yum.repos.d/ose-3.2.repo | 5 +++ .../root/etc/yum.repos.d/ose-3.3.repo | 5 +++ .../root/root/break-yum-update-2.spec | 33 ++++++++++++++++ .../root/root/break-yum-update.spec | 32 ++++++++++++++++ .../aos-package-checks/root/root/ose-3.2.spec | 44 ++++++++++++++++++++++ .../aos-package-checks/root/root/ose-3.3.spec | 44 ++++++++++++++++++++++ .../builds/build-container-images.yml | 19 ++++++++++ 10 files changed, 219 insertions(+) create mode 100644 test/integration/openshift_health_checker/builds/Dockerfile.test-target-base create mode 100644 test/integration/openshift_health_checker/builds/aos-package-checks/Dockerfile create mode 100644 test/integration/openshift_health_checker/builds/aos-package-checks/root/etc/yum.repos.d/break-yum.repo create mode 100644 test/integration/openshift_health_checker/builds/aos-package-checks/root/etc/yum.repos.d/ose-3.2.repo create mode 100644 test/integration/openshift_health_checker/builds/aos-package-checks/root/etc/yum.repos.d/ose-3.3.repo create mode 100644 test/integration/openshift_health_checker/builds/aos-package-checks/root/root/break-yum-update-2.spec create mode 100644 test/integration/openshift_health_checker/builds/aos-package-checks/root/root/break-yum-update.spec create mode 100644 test/integration/openshift_health_checker/builds/aos-package-checks/root/root/ose-3.2.spec create mode 100644 test/integration/openshift_health_checker/builds/aos-package-checks/root/root/ose-3.3.spec create mode 100644 test/integration/openshift_health_checker/builds/build-container-images.yml (limited to 'test') diff --git a/test/integration/openshift_health_checker/builds/Dockerfile.test-target-base b/test/integration/openshift_health_checker/builds/Dockerfile.test-target-base new file mode 100644 index 000000000..39b33c057 --- /dev/null +++ b/test/integration/openshift_health_checker/builds/Dockerfile.test-target-base @@ -0,0 +1,2 @@ +FROM centos/systemd +RUN yum install -y iproute python-dbus PyYAML yum-utils diff --git a/test/integration/openshift_health_checker/builds/aos-package-checks/Dockerfile b/test/integration/openshift_health_checker/builds/aos-package-checks/Dockerfile new file mode 100644 index 000000000..8542029f6 --- /dev/null +++ b/test/integration/openshift_health_checker/builds/aos-package-checks/Dockerfile @@ -0,0 +1,30 @@ +FROM test-target-base + +RUN yum install -y rpm-build rpmdevtools createrepo && \ + rpmdev-setuptree && \ + mkdir -p /mnt/localrepo +ADD root / + +# we will build some RPMs that can be used to break yum update in tests. +RUN cd /root/rpmbuild/SOURCES && \ + mkdir break-yum-update-1.0 && \ + tar zfc foo.tgz break-yum-update-1.0 && \ + rpmbuild -bb /root/break-yum-update.spec && \ + yum install -y /root/rpmbuild/RPMS/noarch/break-yum-update-1.0-1.noarch.rpm && \ + rpmbuild -bb /root/break-yum-update-2.spec && \ + mkdir /mnt/localrepo/break-yum && \ + cp /root/rpmbuild/RPMS/noarch/break-yum-update-1.0-2.noarch.rpm /mnt/localrepo/break-yum && \ + createrepo /mnt/localrepo/break-yum + +# we'll also build some RPMs that can be used to exercise OCP package version tests. +RUN cd /root/rpmbuild/SOURCES && \ + mkdir atomic-openshift-3.2 && \ + mkdir atomic-openshift-3.3 && \ + tar zfc ose.tgz atomic-openshift-3.{2,3} && \ + rpmbuild -bb /root/ose-3.2.spec && \ + rpmbuild -bb /root/ose-3.3.spec && \ + mkdir /mnt/localrepo/ose-3.{2,3} && \ + cp /root/rpmbuild/RPMS/noarch/atomic-openshift*-3.2-1.noarch.rpm /mnt/localrepo/ose-3.2 && \ + createrepo /mnt/localrepo/ose-3.2 && \ + cp /root/rpmbuild/RPMS/noarch/atomic-openshift*-3.3-1.noarch.rpm /mnt/localrepo/ose-3.3 && \ + createrepo /mnt/localrepo/ose-3.3 diff --git a/test/integration/openshift_health_checker/builds/aos-package-checks/root/etc/yum.repos.d/break-yum.repo b/test/integration/openshift_health_checker/builds/aos-package-checks/root/etc/yum.repos.d/break-yum.repo new file mode 100644 index 000000000..f5ccd2d19 --- /dev/null +++ b/test/integration/openshift_health_checker/builds/aos-package-checks/root/etc/yum.repos.d/break-yum.repo @@ -0,0 +1,5 @@ +[break-yum] +name=break-yum +baseurl=file:///mnt/localrepo/break-yum +enabled=0 +gpgcheck=0 diff --git a/test/integration/openshift_health_checker/builds/aos-package-checks/root/etc/yum.repos.d/ose-3.2.repo b/test/integration/openshift_health_checker/builds/aos-package-checks/root/etc/yum.repos.d/ose-3.2.repo new file mode 100644 index 000000000..3064d6dbb --- /dev/null +++ b/test/integration/openshift_health_checker/builds/aos-package-checks/root/etc/yum.repos.d/ose-3.2.repo @@ -0,0 +1,5 @@ +[ose-3.2] +name=ose-3.2 +baseurl=file:///mnt/localrepo/ose-3.2 +enabled=0 +gpgcheck=0 diff --git a/test/integration/openshift_health_checker/builds/aos-package-checks/root/etc/yum.repos.d/ose-3.3.repo b/test/integration/openshift_health_checker/builds/aos-package-checks/root/etc/yum.repos.d/ose-3.3.repo new file mode 100644 index 000000000..1466da476 --- /dev/null +++ b/test/integration/openshift_health_checker/builds/aos-package-checks/root/etc/yum.repos.d/ose-3.3.repo @@ -0,0 +1,5 @@ +[ose-3.3] +name=ose-3.3 +baseurl=file:///mnt/localrepo/ose-3.3 +enabled=0 +gpgcheck=0 diff --git a/test/integration/openshift_health_checker/builds/aos-package-checks/root/root/break-yum-update-2.spec b/test/integration/openshift_health_checker/builds/aos-package-checks/root/root/break-yum-update-2.spec new file mode 100644 index 000000000..ebd7eb443 --- /dev/null +++ b/test/integration/openshift_health_checker/builds/aos-package-checks/root/root/break-yum-update-2.spec @@ -0,0 +1,33 @@ +Name: break-yum-update +Version: 1.0 +Release: 2 +Summary: Package for breaking updates by requiring things that don't exist + +License: NA + +Requires: package-that-does-not-exist +Source0: http://example.com/foo.tgz +BuildArch: noarch + +%description +Package for breaking updates by requiring things that don't exist + + +%prep +%setup -q + + +%build + + +%install +rm -rf $RPM_BUILD_ROOT +mkdir -p $RPM_BUILD_ROOT + + +%files +%doc + + + +%changelog diff --git a/test/integration/openshift_health_checker/builds/aos-package-checks/root/root/break-yum-update.spec b/test/integration/openshift_health_checker/builds/aos-package-checks/root/root/break-yum-update.spec new file mode 100644 index 000000000..c40675f90 --- /dev/null +++ b/test/integration/openshift_health_checker/builds/aos-package-checks/root/root/break-yum-update.spec @@ -0,0 +1,32 @@ +Name: break-yum-update +Version: 1.0 +Release: 1 +Summary: Package for breaking updates by requiring things that don't exist + +License: NA + +Source0: http://example.com/foo.tgz +BuildArch: noarch + +%description +Package for breaking updates by requiring things that don't exist + + +%prep +%setup -q + + +%build + + +%install +rm -rf $RPM_BUILD_ROOT +mkdir -p $RPM_BUILD_ROOT + + +%files +%doc + + + +%changelog diff --git a/test/integration/openshift_health_checker/builds/aos-package-checks/root/root/ose-3.2.spec b/test/integration/openshift_health_checker/builds/aos-package-checks/root/root/ose-3.2.spec new file mode 100644 index 000000000..dbc9f0c8e --- /dev/null +++ b/test/integration/openshift_health_checker/builds/aos-package-checks/root/root/ose-3.2.spec @@ -0,0 +1,44 @@ +Name: atomic-openshift +Version: 3.2 +Release: 1 +Summary: package the critical aos packages + +License: NA + +Source0: http://example.com/ose.tgz +BuildArch: noarch + +%package master +Summary: package the critical aos packages +%package node +Summary: package the critical aos packages + +%description +Package for pretending to provide AOS + +%description master +Package for pretending to provide AOS + +%description node +Package for pretending to provide AOS + +%prep +%setup -q + + +%build + + +%install +rm -rf $RPM_BUILD_ROOT +mkdir -p $RPM_BUILD_ROOT + + +%files +%files master +%files node +%doc + + + +%changelog diff --git a/test/integration/openshift_health_checker/builds/aos-package-checks/root/root/ose-3.3.spec b/test/integration/openshift_health_checker/builds/aos-package-checks/root/root/ose-3.3.spec new file mode 100644 index 000000000..9546e8430 --- /dev/null +++ b/test/integration/openshift_health_checker/builds/aos-package-checks/root/root/ose-3.3.spec @@ -0,0 +1,44 @@ +Name: atomic-openshift +Version: 3.3 +Release: 1 +Summary: package the critical aos packages + +License: NA + +Source0: http://example.com/ose.tgz +BuildArch: noarch + +%package master +Summary: package the critical aos packages +%package node +Summary: package the critical aos packages + +%description +Package for pretending to provide AOS + +%description master +Package for pretending to provide AOS + +%description node +Package for pretending to provide AOS + +%prep +%setup -q + + +%build + + +%install +rm -rf $RPM_BUILD_ROOT +mkdir -p $RPM_BUILD_ROOT + + +%files +%files master +%files node +%doc + + + +%changelog diff --git a/test/integration/openshift_health_checker/builds/build-container-images.yml b/test/integration/openshift_health_checker/builds/build-container-images.yml new file mode 100644 index 000000000..445d73d29 --- /dev/null +++ b/test/integration/openshift_health_checker/builds/build-container-images.yml @@ -0,0 +1,19 @@ +--- +- name: Build all the images we need for running integration tests + hosts: localhost + connection: local + tasks: + + - name: test-target-base + docker_image: + state: present + path: ./ + dockerfile: Dockerfile.test-target-base + name: test-target-base + + - name: preflight-aos-package-checks + docker_image: + state: present + pull: no + path: ./aos-package-checks + name: preflight-aos-package-checks -- cgit v1.2.1 From e5f14b515b07bcfa2079c3e68c35fee3e97970c7 Mon Sep 17 00:00:00 2001 From: Luke Meyer Date: Tue, 4 Apr 2017 12:05:20 -0400 Subject: integration tests: add CI scripts Add some scripts that can be run from Jenkins to build/push test images and to run the tests. Updated README to expand on running tests. --- test/integration/README.md | 35 ++++++- test/integration/build-images.sh | 101 +++++++++++++++++++++ .../builds/Dockerfile.test-target-base | 2 - .../builds/build-container-images.yml | 19 ---- .../builds/test-target-base/Dockerfile | 2 + .../integration/openshift_health_checker/common.go | 2 +- .../openshift_health_checker/setup_container.yml | 2 +- test/integration/run-tests.sh | 80 ++++++++++++++++ 8 files changed, 216 insertions(+), 27 deletions(-) create mode 100755 test/integration/build-images.sh delete mode 100644 test/integration/openshift_health_checker/builds/Dockerfile.test-target-base delete mode 100644 test/integration/openshift_health_checker/builds/build-container-images.yml create mode 100644 test/integration/openshift_health_checker/builds/test-target-base/Dockerfile create mode 100755 test/integration/run-tests.sh (limited to 'test') diff --git a/test/integration/README.md b/test/integration/README.md index 0edbccd74..948e44c50 100644 --- a/test/integration/README.md +++ b/test/integration/README.md @@ -1,12 +1,39 @@ # Integration tests -Integration tests exercise the OpenShift Ansible playbooks by performing -simulated installations in Docker containers. +Integration tests exercise the OpenShift Ansible playbooks by running them +against an inventory with Docker containers as hosts. + +## Requirements + +The tests assume that: + +* docker is running on localhost and the present user has access to use it. +* golang is installed and the go binary is in PATH. +* python and tox are installed. + +## Building images + +The tests rely on images built in the local docker index. You can build them +from the repository root with: + +``` +./test/integration/build-images.sh +``` + +Use the `--help` option to view available options. ## Running the tests -From the repository root, run with: +From the repository root, run the integration tests with: + +``` +./test/integration/run-tests.sh +``` + +Use the `--help` option to view available options. + +You can also run tests more directly, for example to run a specific check: ``` -tox -e integration +go test ./test/integration/... -run TestPackageUpdateDepMissing ``` diff --git a/test/integration/build-images.sh b/test/integration/build-images.sh new file mode 100755 index 000000000..74a55fa51 --- /dev/null +++ b/test/integration/build-images.sh @@ -0,0 +1,101 @@ +#!/bin/bash + +# This is intended to run either locally (in which case a push is not +# necessary) or in a CI job (where the results should be pushed to a +# registry for use in later CI test jobs). Images are tagged locally with +# both the base name (e.g. "test-target-base") and with the prefix given; +# then only the prefixed name is pushed if --push is specified, assuming +# any necessary credentials are available for the push. The same prefix +# can then be used for the testing script. By default a local (non-registry) +# prefix is used and no push can occur. To push to e.g. dockerhub: +# +# ./build-images.sh --push --prefix=docker.io/openshift/ansible-integration- + +set -o errexit +set -o nounset +set -o pipefail + +STARTTIME=$(date +%s) +source_root=$(dirname "${0}") + +prefix="${PREFIX:-openshift-ansible-integration-}" +push=false +verbose=false +build_options="${DOCKER_BUILD_OPTIONS:-}" +help=false + +for args in "$@" +do + case $args in + --prefix=*) + prefix="${args#*=}" + ;; + --push) + push=true + ;; + --no-cache) + build_options="${build_options} --no-cache" + ;; + --verbose) + verbose=true + ;; + --help) + help=true + ;; + esac +done + +if [ "$help" = true ]; then + echo "Builds the docker images for openshift-ansible integration tests" + echo "and pushes them to a central registry." + echo + echo "Options: " + echo " --prefix=PREFIX" + echo " The prefix to use for the image names." + echo " default: openshift-ansible-integration-" + echo + echo " --push" + echo " If set will push the tagged image" + echo + echo " --no-cache" + echo " If set will perform the build without a cache." + echo + echo " --verbose" + echo " Enables printing of the commands as they run." + echo + echo " --help" + echo " Prints this help message" + echo + exit 0 +fi + +if [ "$verbose" = true ]; then + set -x +fi + + +declare -a build_order ; declare -A images +build_order+=( test-target-base ) ; images[test-target-base]=openshift_health_checker/builds/test-target-base +build_order+=( preflight-aos-package-checks ); images[preflight-aos-package-checks]=openshift_health_checker/builds/aos-package-checks +for image in "${build_order[@]}"; do + BUILD_STARTTIME=$(date +%s) + docker_tag=${prefix}${image} + echo + echo "--- Building component '$image' with docker tag '$docker_tag' ---" + docker build ${build_options} -t $image -t $docker_tag "$source_root/${images[$image]}" + echo + BUILD_ENDTIME=$(date +%s); echo "--- build $docker_tag took $(($BUILD_ENDTIME - $BUILD_STARTTIME)) seconds ---" + if [ "$push" = true ]; then + docker push $docker_tag + PUSH_ENDTIME=$(date +%s); echo "--- push $docker_tag took $(($PUSH_ENDTIME - $BUILD_ENDTIME)) seconds ---" + fi +done + +echo +echo +echo "++ Active images" +docker images | grep ${prefix} | sort +echo + + +ret=$?; ENDTIME=$(date +%s); echo "$0 took $(($ENDTIME - $STARTTIME)) seconds"; exit "$ret" diff --git a/test/integration/openshift_health_checker/builds/Dockerfile.test-target-base b/test/integration/openshift_health_checker/builds/Dockerfile.test-target-base deleted file mode 100644 index 39b33c057..000000000 --- a/test/integration/openshift_health_checker/builds/Dockerfile.test-target-base +++ /dev/null @@ -1,2 +0,0 @@ -FROM centos/systemd -RUN yum install -y iproute python-dbus PyYAML yum-utils diff --git a/test/integration/openshift_health_checker/builds/build-container-images.yml b/test/integration/openshift_health_checker/builds/build-container-images.yml deleted file mode 100644 index 445d73d29..000000000 --- a/test/integration/openshift_health_checker/builds/build-container-images.yml +++ /dev/null @@ -1,19 +0,0 @@ ---- -- name: Build all the images we need for running integration tests - hosts: localhost - connection: local - tasks: - - - name: test-target-base - docker_image: - state: present - path: ./ - dockerfile: Dockerfile.test-target-base - name: test-target-base - - - name: preflight-aos-package-checks - docker_image: - state: present - pull: no - path: ./aos-package-checks - name: preflight-aos-package-checks diff --git a/test/integration/openshift_health_checker/builds/test-target-base/Dockerfile b/test/integration/openshift_health_checker/builds/test-target-base/Dockerfile new file mode 100644 index 000000000..39b33c057 --- /dev/null +++ b/test/integration/openshift_health_checker/builds/test-target-base/Dockerfile @@ -0,0 +1,2 @@ +FROM centos/systemd +RUN yum install -y iproute python-dbus PyYAML yum-utils diff --git a/test/integration/openshift_health_checker/common.go b/test/integration/openshift_health_checker/common.go index aea85342f..a92d6861d 100644 --- a/test/integration/openshift_health_checker/common.go +++ b/test/integration/openshift_health_checker/common.go @@ -25,7 +25,7 @@ func (p PlaybookTest) Run(t *testing.T) { // A PlaybookTest is intended to be run in parallel with other tests. t.Parallel() - cmd := exec.Command("ansible-playbook", p.Path) + cmd := exec.Command("ansible-playbook", "-i", "/dev/null", p.Path) cmd.Env = append(os.Environ(), "ANSIBLE_FORCE_COLOR=1") b, err := cmd.CombinedOutput() diff --git a/test/integration/openshift_health_checker/setup_container.yml b/test/integration/openshift_health_checker/setup_container.yml index 4dd2c4b1e..8793d954e 100644 --- a/test/integration/openshift_health_checker/setup_container.yml +++ b/test/integration/openshift_health_checker/setup_container.yml @@ -23,7 +23,7 @@ - name: start container docker_container: name: "{{ container_name }}" - image: "{{ image | default('test-target-base') }}" + image: "{{ lookup('env', 'IMAGE_PREFIX') | default('openshift-ansible-integration-', true) }}{{ image | default('test-target-base') }}" command: "{{ command | default('sleep 1800') }}" recreate: yes # NOTE: When/if we need to run containers that are docker hosts as well: diff --git a/test/integration/run-tests.sh b/test/integration/run-tests.sh new file mode 100755 index 000000000..680b64602 --- /dev/null +++ b/test/integration/run-tests.sh @@ -0,0 +1,80 @@ +#!/bin/bash + +# This script runs the golang integration tests in the directories underneath. +# It should be run from the same directory it is in, or in a directory above. +# Specify the same image prefix used (if any) with build-images.sh +# +# Example: +# ./run-tests.sh --prefix=docker.io/openshift/ansible-integration- --parallel=16 + +set -o errexit +set -o nounset +set -o pipefail + +source_root=$(dirname "${0}") + +prefix="${PREFIX:-openshift-ansible-integration-}" +gotest_options="${GOTEST_OPTIONS:--v}" +push=false +verbose=false +help=false + +for args in "$@" +do + case $args in + --prefix=*) + prefix="${args#*=}" + ;; + --parallel=*) + gotest_options="${gotest_options} -parallel ${args#*=}" + ;; + --verbose) + verbose=true + ;; + --help) + help=true + ;; + esac +done + +if [ "$help" = true ]; then + echo "Runs the openshift-ansible integration tests." + echo + echo "Options: " + echo " --prefix=PREFIX" + echo " The prefix to use for the image names." + echo " default: openshift-ansible-integration-" + echo + echo " --parallel=NUMBER" + echo " Number of tests to run in parallel." + echo " default: GOMAXPROCS (typically, number of processors)" + echo + echo " --verbose" + echo " Enables printing of the commands as they run." + echo + echo " --help" + echo " Prints this help message" + echo + exit 0 +fi + + + +if ! [ -d $source_root/../../.tox/integration ]; then + # have tox create a consistent virtualenv + pushd $source_root/../..; tox -e integration; popd +fi +# use the virtualenv from tox +set +o nounset; source $source_root/../../.tox/integration/bin/activate; set -o nounset + +if [ "$verbose" = true ]; then + set -x +fi + +# Run the tests. NOTE: "go test" requires a relative path for this purpose. +# The PWD trick below will only work if cwd is in/above where this script lives. +retval=0 +IMAGE_PREFIX="${prefix}" env -u GOPATH \ + go test ./${source_root#$PWD}/... ${gotest_options} + + -- cgit v1.2.1