From 294b4a0c76508b377ea561d1f0bc6c70ee48df0f Mon Sep 17 00:00:00 2001 From: Travis Truman Date: Wed, 14 Sep 2016 11:57:00 -0400 Subject: [PATCH] Ansible 2.1.1 role testing Change-Id: I8ddf65a83d7e3a7a6b7e108eda67f48b816cda74 --- Vagrantfile | 5 ++- tasks/repo_package_sync.yml | 2 +- tests/host_vars/localhost.yml | 19 +++++++++++ tests/inventory | 4 +-- tests/playbooks | 1 + tests/test-container-create.yml | 54 ------------------------------- tests/test-prepare-containers.yml | 50 ---------------------------- tests/test-prepare-host.yml | 53 ------------------------------ tests/test-prepare-keys.yml | 33 ------------------- tests/test-vars.yml | 1 - tests/test.retry | 1 + tests/test.yml | 8 +---- tox.ini | 5 ++- 13 files changed, 33 insertions(+), 203 deletions(-) create mode 100644 tests/host_vars/localhost.yml create mode 160000 tests/playbooks delete mode 100644 tests/test-container-create.yml delete mode 100644 tests/test-prepare-containers.yml delete mode 100644 tests/test-prepare-host.yml delete mode 100644 tests/test-prepare-keys.yml create mode 100644 tests/test.retry diff --git a/Vagrantfile b/Vagrantfile index 44872e1..ac0866f 100644 --- a/Vagrantfile +++ b/Vagrantfile @@ -1,7 +1,10 @@ Vagrant.configure(2) do |config| + config.vm.provider "virtualbox" do |v| + v.memory = 2048 + v.cpus = 2 + end config.vm.box = "ubuntu/trusty64" config.vm.provision "shell", inline: <<-SHELL - sudo su - cd /vagrant ./run_tests.sh SHELL diff --git a/tasks/repo_package_sync.yml b/tasks/repo_package_sync.yml index 76d61ca..92521e0 100644 --- a/tasks/repo_package_sync.yml +++ b/tasks/repo_package_sync.yml @@ -22,7 +22,7 @@ --rsh 'ssh -l {{ repo_build_service_user_name }} -o stricthostkeychecking=no' --out-format='<>%i %n%L' {{ item }} - {{ repo_build_service_user_name }}@{{ hostvars[groups['repo_all'][0]]['ansible_ssh_host'] }}:{{ repo_build_base_path }} + {{ repo_build_service_user_name }}@{{ hostvars[groups['repo_all'][0]]['ansible_host'] }}:{{ repo_build_base_path }} with_items: - "{{ repo_build_global_links_path }}" - "{{ repo_build_release_path }}" diff --git a/tests/host_vars/localhost.yml b/tests/host_vars/localhost.yml new file mode 100644 index 0000000..65ddeaa --- /dev/null +++ b/tests/host_vars/localhost.yml @@ -0,0 +1,19 @@ +--- +# Copyright 2016, 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. + +bridges: + - "br-mgmt" + +ansible_python_interpreter: "/usr/bin/python2" diff --git a/tests/inventory b/tests/inventory index 4e401b8..1f9f8cd 100644 --- a/tests/inventory +++ b/tests/inventory @@ -1,6 +1,6 @@ [all] -localhost ansible_connection=local ansible_become=True -container1 ansible_ssh_host=10.100.102.101 ansible_host=10.100.102.101 ansible_become=True ansible_user=root +localhost ansible_become=True +container1 ansible_host=10.100.100.2 ansible_become=True ansible_user=root [repo_all] container1 diff --git a/tests/playbooks b/tests/playbooks new file mode 160000 index 0000000..4399a6c --- /dev/null +++ b/tests/playbooks @@ -0,0 +1 @@ +Subproject commit 4399a6c383c688ae3a7d0fd136eb13c0e3214501 diff --git a/tests/test-container-create.yml b/tests/test-container-create.yml deleted file mode 100644 index efca943..0000000 --- a/tests/test-container-create.yml +++ /dev/null @@ -1,54 +0,0 @@ ---- -# 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: Create test containers - hosts: all_containers - connection: local - gather_facts: false - pre_tasks: - - name: Destroy test containers - lxc_container: - name: "{{ container_name }}" - state: "absent" - delegate_to: "{{ physical_host }}" - tags: - - container-destroy - - name: Destroy container service directories - file: - path: "{{ item }}" - state: "absent" - with_items: - - "/openstack/{{ container_name }}" - - "/openstack/backup/{{ container_name }}" - - "/openstack/log/{{ container_name }}" - - "/var/lib/lxc/{{ container_name }}" - - "{{ lxc_container_directory|default('/var/lib/lxc') }}/{{ container_name }}" - delegate_to: "{{ physical_host }}" - tags: - - container-directories - roles: - - role: "lxc_container_create" - lxc_container_release: trusty - lxc_container_backing_store: dir - global_environment_variables: - PATH: "/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin" - post_tasks: - - name: Wait for ssh to be available - local_action: - module: wait_for - port: "{{ ansible_ssh_port | default('22') }}" - host: "{{ ansible_ssh_host | default(inventory_hostname) }}" - search_regex: OpenSSH - delay: 1 diff --git a/tests/test-prepare-containers.yml b/tests/test-prepare-containers.yml deleted file mode 100644 index 9ab9fbb..0000000 --- a/tests/test-prepare-containers.yml +++ /dev/null @@ -1,50 +0,0 @@ ---- -# Copyright 2016, 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: Create test containers - hosts: all_containers - gather_facts: false - pre_tasks: - - name: Destroy test containers - lxc_container: - name: "{{ container_name }}" - state: "absent" - delegate_to: "{{ physical_host }}" - tags: - - container-destroy - - name: Destroy container service directories - file: - path: "{{ item }}" - state: "absent" - with_items: - - "/openstack/{{ container_name }}" - - "/openstack/backup/{{ container_name }}" - - "/openstack/log/{{ container_name }}" - - "/var/lib/lxc/{{ container_name }}" - - "{{ lxc_container_directory|default('/var/lib/lxc') }}/{{ container_name }}" - delegate_to: "{{ physical_host }}" - tags: - - container-directories - roles: - - role: "lxc_container_create" - lxc_container_backing_store: dir - post_tasks: - - name: Wait for ssh to be available - local_action: - module: wait_for - port: "{{ ansible_ssh_port | default('22') }}" - host: "{{ ansible_ssh_host | default(inventory_hostname) }}" - search_regex: OpenSSH - delay: 1 diff --git a/tests/test-prepare-host.yml b/tests/test-prepare-host.yml deleted file mode 100644 index 8ad73f1..0000000 --- a/tests/test-prepare-host.yml +++ /dev/null @@ -1,53 +0,0 @@ ---- -# Copyright 2016, 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: Perform basic LXC host setup - hosts: localhost - pre_tasks: - - name: Ensure apt cache is always refreshed - apt: - update_cache: yes - when: ansible_pkg_mgr == 'apt' - - name: Ensure root's new public ssh key is in authorized_keys - authorized_key: - user: root - key: "{{ hostvars['localhost']['lxc_container_ssh_key'] }}" - manage_dir: no - - set_fact: - lxc_container_ssh_key: "{{ hostvars['localhost']['lxc_container_ssh_key'] }}" - - name: Check if this is an OpenStack-CI nodepool instance - stat: - path: /etc/nodepool/provider - register: nodepool - - name: Set the files to copy into the container cache for OpenStack-CI instances - set_fact: - lxc_container_cache_files: - - { src: '/etc/pip.conf', dest: '/etc/pip.conf' } - when: nodepool.stat.exists | bool - post_tasks: -# The elegant solution: change the bridge everywhere to replicate the standard behaviour - - name: Create br-mgmt bridge - command: /sbin/brctl addbr br-mgmt - - name: IP br-mgmt - command: /sbin/ifconfig br-mgmt 10.100.102.1 netmask 255.255.255.0 - - name: Add iptables rules for lxc natting - command: /usr/local/bin/lxc-system-manage iptables-create - roles: - - role: "lxc_hosts" - lxc_net_address: 10.100.100.1 - lxc_net_dhcp_range: 10.100.100.2,10.100.100.253 - lxc_net_bridge: lxcbr0 - lxc_kernel_options: - - { key: 'fs.inotify.max_user_instances', value: 1024 } diff --git a/tests/test-prepare-keys.yml b/tests/test-prepare-keys.yml deleted file mode 100644 index f4df126..0000000 --- a/tests/test-prepare-keys.yml +++ /dev/null @@ -1,33 +0,0 @@ ---- -# Copyright 2016, 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. - -# NOTE: we use become_user because setting become: no or become: false -# doesn't seem to override the ansible_become=true in the -# inventory -- name: Create ssh key pairs for use with containers - hosts: localhost - become_user: "{{ ansible_ssh_user }}" - tasks: - - name: Create ssh key pair for root - user: - name: "{{ ansible_ssh_user }}" - 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 }}" diff --git a/tests/test-vars.yml b/tests/test-vars.yml index 3144bdf..03c84f0 100644 --- a/tests/test-vars.yml +++ b/tests/test-vars.yml @@ -15,7 +15,6 @@ openstack_release: testing repo_build_release_tag: "{{ openstack_release }}" -galera_client_drop_config_file: false # Test data input for upper constraints validation repo_build_upper_constraints_overrides: diff --git a/tests/test.retry b/tests/test.retry new file mode 100644 index 0000000..4247265 --- /dev/null +++ b/tests/test.retry @@ -0,0 +1 @@ +container1 diff --git a/tests/test.yml b/tests/test.yml index 0db02ac..2047b44 100644 --- a/tests/test.yml +++ b/tests/test.yml @@ -13,14 +13,8 @@ # See the License for the specific language governing permissions and # limitations under the License. -# Prepare the user ssh keys -- include: test-prepare-keys.yml - # Prepare the host -- include: test-prepare-host.yml - -# Run container clean up and build -- include: test-prepare-containers.yml +- include: playbooks/test-setup-host.yml # Install repo server - include: test-install-server.yml diff --git a/tox.ini b/tox.ini index 55a5f11..51b45ad 100644 --- a/tox.ini +++ b/tox.ini @@ -94,7 +94,7 @@ commands = [testenv:ansible] deps = {[testenv]deps} - ansible==1.9.4 + ansible==2.1.1 ansible-lint>=2.7.0,<3.0.0 setenv = {[testenv]setenv} @@ -121,6 +121,9 @@ commands = ansible-galaxy install \ --role-file={toxinidir}/tests/ansible-role-requirements.yml \ --force + rm -rf {toxinidir}/tests/playbooks + git clone https://git.openstack.org/openstack/openstack-ansible-tests \ + {toxinidir}/tests/playbooks [testenv:ansible-syntax]