openstack-ansible-lxc_conta.../tests/test-containers-functional.yml

91 lines
3.9 KiB
YAML

---
# Copyright 2015, Rackspace US, Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
- 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.2
# container2 10.100.100.3, 172.16.12.4
assert:
that:
- lxc_container_list.stdout | search("container1\s+(\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3},\s+)*10.100.100.2(,\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.3(,\s+\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})*\s+")
- lxc_container_list.stdout | search("container3\s+(\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3},\s+)*10.100.100.4(,\s+\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})*\s+")
- name: Check for the presence of the right aa_profile for container1
command: grep "^lxc.aa_profile = lxc-openstack$" /var/lib/lxc/container1/config
register: container1_profile
failed_when: container1_profile.rc != 0
- name: Check for the presence of the right aa_profile for container2
command: grep "^lxc.aa_profile = unconfined$" /var/lib/lxc/container2/config
register: container2_profile
failed_when: container2_profile.rc != 0
- name: Check for the lack of presence of an aa_profile for container3
command: grep "lxc.aa_profile" /var/lib/lxc/container3/config
register: container3_profile
failed_when: container3_profile.rc == 0
- name: Check for the presence of the right bound mount for container1
command: grep "lxc.mount.entry = /openstack/container1 opt/test1 none bind 0 0" /var/lib/lxc/container1/config
- name: Check for the presence of the right bound mount for container2
command: grep "lxc.mount.entry = /openstack/container2/test2 opt/test2 none bind 0 0" /var/lib/lxc/container2/config
- name: Check for the presence of the default bound mount for container3
command: grep "lxc.mount.entry = /openstack/backup/container3" /var/lib/lxc/container3/config
- name: Check for the bind mount in container1
hosts: container1
remote_user: root
tasks:
- name: Check for the presence of /opt/test1
command: ls -1 /opt/test1
register: container1_test_dir
failed_when: container1_test_dir.rc != 0
- name: Test the containers themselves
hosts: all_containers
remote_user: root
tasks:
- name: Open /etc/environment file
slurp:
src: /etc/environment
register: environment_file
- name: Set /etc/environment contents fact
set_fact:
environment_content: "{{ environment_file.content | b64decode }}"
- name: Check /etc/enviroment matches expectations
assert:
that:
- "'/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games' in environment_content"
- name: Test connectivity to external address
shell: ping -c 3 8.8.8.8
register: ping_external_address
ignore_errors: true
- name: Verify connectivity to external address
assert:
that:
- ping_external_address.rc == 0