openstack-ansible-lxc_hosts/tests/test.yml
Jesse Pretorius aca3d5e01d Make the LXC cache prep use the host package source config
Currently the container cache preparation process uses a pre-prepared
LXC base image which includes its own package repository configuration.

This presents a few problems:
- The first packages installed will make use of the base image's
  package repo configuration, resulting in a bypass of local mirrors
  to install the first set of packages.
- A set of vars need to be set in order to have the containers use a
  local mirror, otherwise it'll use the mirrors set in the role's vars
  files. This is counterintuitive.

Another problem introduced by I95c210c83ca968d11ba6f6a36b634bb798fa291f
as a result of the package repository vars moving from the role defaults
to the vars files is that the precedence has changed. The change in
precedence means that a task which sets a fact can't be used to override
the defaults set in the vars file. This method is used in all the role
tests to ensure that the OpenStack-CI repositories can be discovered from
the host and then used.

This patch changes the image cache preparation process to ensure that
the container package repository configuration matches the host
configuration. This is simpler and more intuitive.

Additionally the copy task from the deployment host into the container
cache is set to assume the same destination in the container as the
source (to reduce configuration verbosity), appropriately sets the
leading '0' for the mode (to prevent unexpected surprises), and
appropriately quotes the variable (to ensure forward compatibility
with Ansible 2.0).

Finally, the use of lxc_container_caches in the test configuration
has been removed as it is no longer used.

Change-Id: I420382fd3bbbb5fcae90ae0c6160233202a1a51a
2016-05-18 18:14:17 +01:00

90 lines
3.2 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: Playbook for role testing
hosts: localhost
connection: local
pre_tasks:
- name: Show host facts
debug:
var: hostvars
- name: First ensure apt cache is always refreshed
apt:
update_cache: yes
when:
- ansible_pkg_mgr == 'apt'
- name: Ensure root ssh key
user:
name: "{{ ansible_env.USER | default('root') }}"
generate_ssh_key: "yes"
ssh_key_bits: 2048
ssh_key_file: ".ssh/id_rsa"
- name: get the calling users key
command: cat ~/.ssh/id_rsa.pub
register: key_get
- set_fact:
lxc_container_ssh_key: key_get.stdout
roles:
- role: "{{ rolename | basename }}"
lxc_net_address: 10.100.100.1
lxc_net_bridge: lxcbr0
lxc_kernel_options:
- { key: 'fs.inotify.max_user_instances', value: 1024 }
lxc_container_cache_files:
- src: files/container-file-copy-test.txt
dest: /tmp/file-copied-from-deployment-host.txt
post_tasks:
- name: Get sysctl content
shell: |
cat /etc/sysctl.conf
register: sysctl_content
- name: Check for lxc bridge
stat:
path: /sys/class/net/lxcbr0/bridge/bridge_id
register: lxc_bridge_file
- name: Check dnsmasq is running
shell: ps auxfww | grep -w 'dnsmasq -u lxc-dnsmasq'
- name: DEBIAN - Get deployed interface file contents, without Ansible managed line
shell: |
cat /etc/network/interfaces.d/lxc-net-bridge.cfg | tail -n +3
register: _debian_interface_file
when: ansible_os_family | lower == "debian"
- name: DEBIAN - interface file fact
set_fact:
interface_file: "{{ _debian_interface_file.stdout }}"
when: ansible_os_family | lower == "debian"
- name: RHEL - Get deployed interface file contents, without Ansible managed line
shell: |
cat /etc/sysconfig/network-scripts/ifcfg-lxcbr0 | tail -n +3
register: _rhel_interface_file
when: ansible_os_family | lower == "redhat"
- name: RHEL - interface file fact
set_fact:
interface_file: "{{ _rhel_interface_file.stdout }}"
when: ansible_os_family | lower == "redhat"
- name: Get bridge interface facts
setup:
filter: ansible_lxcbr0
register: lxcbr0_facts
- name: Check role functions
assert:
that:
- interface_file | search('.*lxcbr0.*')
- interface_file | search('.*10.100.100.1.*')
- interface_file | search('.*255.255.255.0.*')
- sysctl_content.stdout | search('fs.inotify.max_user_instances.*')
- "lxc_bridge_file.stat.exists"
- "lxcbr0_facts.ansible_facts.ansible_lxcbr0.ipv4.address | match('10.100.100.1')"