openstack-ansible-openstack.../tests/test.yml

101 lines
3.5 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.
# Add some data to use for verification later
- name: Playbook for test setup
hosts: localhost
connection: local
become: true
gather_facts: false
pre_tasks:
# NOTE(mhayden): We skip this task when we're running the final
# idempotence check because this task will always mess with the hosts
# file and cause related tasks to show as `changed`.
- name: Add entries to hosts file
blockinfile:
dest: /etc/hosts
block: |
127.111.111.102 test2
127.111.111.103 test3.openstack.local
127.111.111.103 test3.additional
marker: ""
changed_when: false
when:
- "'idempotence' not in lookup('env', 'ANSIBLE_LOG_PATH')"
# Prepare the user ssh keys
- import_playbook: common/test-prepare-keys.yml
# Set nodepool variables when running in the OpenStack CI environment
- import_playbook: common/setting-nodepool-variables.yml
# Execute the role
- import_playbook: common/test-install-openstack-hosts.yml
- name: Playbook for role testing
hosts: localhost
become: true
gather_facts: true
tasks:
- name: Open modules file
slurp:
src: "{{ openstack_host_module_file }}"
register: modules_file
- name: Open sysctl file
slurp:
src: /etc/sysctl.conf
register: sysctl_file
- name: Open hosts file
slurp:
src: /etc/hosts
register: hosts_file
- name: Open /etc/environment file
slurp:
src: /etc/environment
register: environment_file
- name: Read files
set_fact:
modules_content: "{{ modules_file.content | b64decode }}"
sysctl_content: "{{ sysctl_file.content | b64decode }}"
hosts_content: "{{ hosts_file.content | b64decode }}"
environment_content: "{{ environment_file.content | b64decode }}"
- name: Check for release file
stat:
path: /etc/openstack-release
register: release_file
- name: Check for systat file
stat:
path: "{{ openstack_host_sysstat_file }}"
register: systat_file
- name: Check for ssh dir
stat:
path: "{{ ansible_env.HOME}}/.ssh"
register: ssh_dir
- name: Check role functions
assert:
that:
- "'dm_multipath' in modules_content"
- "'ebtables' in modules_content"
- "'vm.swappiness' in sysctl_content"
- "'127.111.111.101 test1.openstack.local test1' in hosts_content"
- "'127.111.111.102 test2.openstack.local test2' in hosts_content"
- "'127.111.111.103 test3.openstack.local test3' in hosts_content"
- "'127.111.111.103 test3.additional' not in hosts_content"
- "'127.0.1.1 localhost.openstack.local localhost' in hosts_content"
- "release_file.stat.exists"
- "systat_file.stat.exists"
- "'PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin' in environment_content"
- "ssh_dir.stat.isdir"