From 23830066ad908bc28a37ae4cd9086f11dc00d101 Mon Sep 17 00:00:00 2001 From: Jesse Pretorius Date: Fri, 4 Mar 2016 10:05:09 +0000 Subject: [PATCH] Test container creation based on IP address This test executes an LXC container listing from the LXC host, then verifies that the container is present by name and IP address. The test will work whether there is one or more IP addresses in each containers created. This patch also includes the following in order to unblock testing for this role: - A forced apt-get update - A base other-requirements.txt file to ensure that the OpenStack-CI fallback requirements aren't used, which conflict with LXC and cause the instance to hang. Change-Id: I2619b1090300a161c108fcc3f65059e8d50c851e --- other-requirements.txt | 16 ++++++++++++++++ tests/test.yml | 30 ++++++++++++++++++------------ 2 files changed, 34 insertions(+), 12 deletions(-) create mode 100644 other-requirements.txt diff --git a/other-requirements.txt b/other-requirements.txt new file mode 100644 index 0000000..6eac5c2 --- /dev/null +++ b/other-requirements.txt @@ -0,0 +1,16 @@ +# This file facilitates OpenStack-CI package installation +# before the execution of any tests. +# +# See the following for details: +# - http://docs.openstack.org/infra/bindep/ +# - https://github.com/openstack-infra/bindep +# +# Even if the role does not make use of this facility, it +# is better to have this file empty, otherwise OpenStack-CI +# will fall back to installing its default packages which +# will potentially be detrimental to the tests executed. + +# OpenStack-CI's Jenkins needs curl +# TODO(odyssey4me) remove this once https://review.openstack.org/288634 has merged +# and the disk images are rebuilt and redeployed. +curl diff --git a/tests/test.yml b/tests/test.yml index d1d2f28..14e7a7d 100644 --- a/tests/test.yml +++ b/tests/test.yml @@ -17,6 +17,9 @@ hosts: localhost connection: local pre_tasks: + - name: First ensure apt cache is always refreshed + apt: + update_cache: yes - name: Ensure root ssh key user: name: "{{ ansible_env.USER | default('root') }}" @@ -84,17 +87,20 @@ lxc_container_backing_store: dir global_environment_variables: PATH: "/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin" - post_tasks: - - name: Confirm containers were created - command: lxc-ls -f - register: lxc_containers - - name: Format output - set_fact: - _lxc_output: "{{ lxc_containers.stdout.split() | lower }}" - - set_fact: - lxc_output: "{{ _lxc_output | join(' ') }}" - - name: Check role functions + +- name: Test whether the role produced expected results + hosts: localhost + tasks: + - name: List the running LXC containers present on the host + command: lxc-ls -1 --fancy --fancy-format name,ipv4 --running + register: lxc_container_list + - name: Verify that the expected containers are present with the correct addresses + # Example stdout: + # NAME IPV4 + # --------------------------------------- + # container1 172.16.12.3, 10.100.100.101 + # container2 10.100.100.102, 172.16.12.4 assert: that: - - "'container1 running 10.100.100.101' in lxc_output" - - "'container2 running 10.100.100.102' in lxc_output" + - lxc_container_list.stdout | search("container1\s+(\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3},\s+)*10.100.100.101(,\s+\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})*\s+") + - lxc_container_list.stdout | search("container2\s+(\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3},\s+)*10.100.100.102(,\s+\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})*\s+")