diff --git a/meta/main.yml b/meta/main.yml index da313ca..00f4da5 100644 --- a/meta/main.yml +++ b/meta/main.yml @@ -33,4 +33,5 @@ galaxy_info: - python - development - openstack -dependencies: [] +dependencies: + - plugins diff --git a/tests/ansible-role-requirements.yml b/tests/ansible-role-requirements.yml index ac87a1c..4dd225b 100644 --- a/tests/ansible-role-requirements.yml +++ b/tests/ansible-role-requirements.yml @@ -10,7 +10,11 @@ src: https://git.openstack.org/openstack/openstack-ansible-openstack_hosts scm: git version: master -- name: lxc_hosts - src: https://git.openstack.org/openstack/openstack-ansible-lxc_hosts +- name: nspawn_hosts + src: https://git.openstack.org/openstack/openstack-ansible-nspawn_hosts + scm: git + version: master +- name: plugins + src: https://git.openstack.org/openstack/openstack-ansible-plugins scm: git version: master diff --git a/tests/test-containers-create.yml b/tests/group_vars/all.yml similarity index 61% rename from tests/test-containers-create.yml rename to tests/group_vars/all.yml index a770ad8..a73a21a 100644 --- a/tests/test-containers-create.yml +++ b/tests/group_vars/all.yml @@ -13,13 +13,19 @@ # See the License for the specific language governing permissions and # limitations under the License. -- name: Gather nspawn container host facts - hosts: "localhost" - gather_facts: true +container_networks: + management_address: + address: "{{ ansible_host | default('localhost') }}" + bridge: "br-mgmt" + interface: "eth1" + netmask: "255.255.252.0" + type: "veth" + static_routes: + - cidr: 10.100.100.0/24 + gateway: 10.100.100.1 -- name: Create container(s) - hosts: "{{ container_group|default('all_containers') }}" - gather_facts: false - user: root - roles: - - role: "nspawn_container_create" +bridges: + - name: "br-mgmt" + ip_addr: "172.29.236.100" + netmask: "255.255.252.0" + - name: "br-vlan" diff --git a/tests/group_vars/all_containers.yml b/tests/group_vars/all_containers.yml index 7349858..c5ae6c4 100644 --- a/tests/group_vars/all_containers.yml +++ b/tests/group_vars/all_containers.yml @@ -15,19 +15,8 @@ container_name: "{{ inventory_hostname }}" -container_networks: - management_address: - address: "{{ ansible_host }}" - bridge: "br-mgmt" - interface: "eth1" - netmask: "255.255.252.0" - type: "veth" - static_routes: - - cidr: 10.100.100.0/24 - gateway: 10.100.100.1 - properties: service_name: "{{ inventory_hostname }}" -global_environment_variables: - foo: "bar" +deployment_environment_variables: + foo: bar diff --git a/tests/host_vars/container1.yml b/tests/host_vars/container1.yml index 954aca3..8e1f1ee 100644 --- a/tests/host_vars/container1.yml +++ b/tests/host_vars/container1.yml @@ -4,3 +4,5 @@ ansible_become: True ansible_user: root physical_host: localhost + +container_tech: nspawn diff --git a/tests/host_vars/container2.yml b/tests/host_vars/container2.yml index d004513..dda07e1 100644 --- a/tests/host_vars/container2.yml +++ b/tests/host_vars/container2.yml @@ -4,3 +4,5 @@ ansible_become: True ansible_user: root physical_host: localhost + +container_tech: nspawn diff --git a/tests/host_vars/container3.yml b/tests/host_vars/container3.yml index 6e6a25d..00dc556 100644 --- a/tests/host_vars/container3.yml +++ b/tests/host_vars/container3.yml @@ -4,3 +4,5 @@ ansible_become: True ansible_user: root physical_host: localhost + +container_tech: nspawn diff --git a/tests/host_vars/localhost.yml b/tests/host_vars/localhost.yml index 65ddeaa..0829028 100644 --- a/tests/host_vars/localhost.yml +++ b/tests/host_vars/localhost.yml @@ -17,3 +17,5 @@ bridges: - "br-mgmt" ansible_python_interpreter: "/usr/bin/python2" + +physical_host: localhost diff --git a/tests/templates/test-networks.service.j2 b/tests/templates/test-networks.service.j2 new file mode 100644 index 0000000..69c1665 --- /dev/null +++ b/tests/templates/test-networks.service.j2 @@ -0,0 +1,48 @@ +# {{ ansible_managed }} + +[Unit] +Description=test networks service +After=syslog.target +After=network.target + +[Service] +Type=oneshot +User=root +RemainAfterExit=yes + +{% set seen_start_interfaces = [] %} +{% for item in bridges %} +{% if item is mapping %} +{% if item.name not in seen_start_interfaces %} +{% set _ = seen_start_interfaces.append(item.name) %} + +# Interface [{{ item.name }}] +ExecStart=-/sbin/ip link add dev "{{ item.name }}" type bridge +ExecStart=-/sbin/ip link set dev "{{ item.name }}" up +{% if item.address is defined and item.netmask is defined %} +ExecStart=-/sbin/ip address add "{{ item.address }}/{{ item.netmask }}" dev "{{ item.bridge }}" +{% endif %} +{% if item.veth_peer is defined %} +ExecStart=-/sbin/ip link add "{{ item.name }}-veth" type veth peer name "{{ item.veth_peer }}" +ExecStart=-/sbin/ip link set "{{ item.name }}-veth" up +ExecStart=-/sbin/ip link set "{{ item.veth_peer }}-veth" up +ExecStart=-/sbin/ip link set dev "{{ item.name }}-veth" master "{{ item.name }}" +ExecStop=-/sbin/ip link delete dev "{{ item.veth_peer }}-veth" +ExecStop=-/sbin/ip link delete dev "{{ item.name }}-veth" +{% endif %} +{% endif %} +ExecStop=-/sbin/ip link delete dev "{{ item }}" +{% else %} +{% if item not in seen_start_interfaces %} +{% set _ = seen_start_interfaces.append(item) %} + +# Interface [{{ item }}] +ExecStart=-/sbin/ip link add dev "{{ item }}" type bridge +ExecStart=-/sbin/ip link set dev "{{ item }}" up +ExecStop=-/sbin/ip link delete dev "{{ item }}" +{% endif %} +{% endif %} +{% endfor %} + +[Install] +WantedBy=multi-user.target diff --git a/tests/test.yml b/tests/test.yml index 9db1f68..8889a09 100644 --- a/tests/test.yml +++ b/tests/test.yml @@ -13,11 +13,186 @@ # See the License for the specific language governing permissions and # limitations under the License. -# Prepare the user ssh keys -- include: common/test-prepare-keys.yml +- name: Playbook for role testing + hosts: localhost + connection: local + become: true + pre_tasks: + - name: Show host facts + debug: + var: hostvars -# Prepare the host -- include: common/test-prepare-host.yml + - name: Create test network service + template: + src: "templates/test-networks.service.j2" + dest: "/etc/systemd/system/test-networks.service" -# Test container creation -- include: test-containers-create.yml + - name: Enable test network service + systemd: + name: "test-networks.service" + state: "restarted" + enabled: true + daemon_reload: true + + - 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 root ssh key + slurp: + src: '~/.ssh/id_rsa.pub' + register: _root_ssh_key + + - name: Prepare container ssh key fact + set_fact: + nspawn_container_ssh_key: "{{ _root_ssh_key['content'] | b64decode }}" + + # This is a very dirty hack due to images.linuxcontainers.org + # constantly failing to resolve in openstack-infra. + - name: Implement hard-coded hosts entries for consistently failing name + lineinfile: + path: "/etc/hosts" + line: "{{ item }}" + state: present + with_items: + - "91.189.91.21 images.linuxcontainers.org us.images.linuxcontainers.org" + - "91.189.88.37 images.linuxcontainers.org uk.images.linuxcontainers.org" + + # This is a temporary hack to override the nspawn image source to + # the reverse proxy if the test is run in OpenStack-Infra. + - name: Check if this is an OpenStack-CI nodepool instance + stat: + path: /etc/nodepool/provider + register: nodepool + + - name: Discover the nspawn_image_cache_server value when in nodepool + shell: | + source /etc/ci/mirror_info.sh + echo "${NODEPOOL_MIRROR_HOST}:8080/images.linuxcontainers" + args: + executable: /bin/bash + register: nspawn_reverse_proxy + when: + - nodepool.stat.exists | bool + tags: + - skip_ansible_lint + + - name: Set a fact to override nspawn_image_cache_server value when in nodepool + set_fact: + nspawn_image_cache_server_mirrors: ["http://{{ nspawn_reverse_proxy.stdout.strip('/') }}"] + when: + - nodepool.stat.exists | bool + + roles: + - role: "nspawn_hosts" + +- name: Create container(s) + hosts: all_containers + gather_facts: false + become: true + roles: + - role: "nspawn_container_create" + post_tasks: + - name: Test connectivity to external address + command: ping -i 5 -c 6 8.8.8.8 + tags: + - skip_ansible_lint + +- name: Test containers + hosts: localhost + connection: local + become: true + tasks: + - name: Stop container3 + command: "machinectl poweroff container3" + register: container_stop + changed_when: container_stop.rc == 0 + failed_when: not container_stop.rc in [0, 2] + until: container_stop.rc in [0, 2] + retries: 3 + delay: 2 + + - name: Start container3 + command: "machinectl start container3" + register: container_start + changed_when: container_start.rc == 0 + until: container_start | success + retries: 3 + delay: 2 + + - name: Status check container1 + command: "machinectl status container1" + register: container_status + changed_when: container_status.rc == 0 + until: container_status | success + retries: 3 + delay: 2 + + - name: Clone container2 + command: "machinectl clone container2 test1-container2" + register: container_clone + changed_when: container_clone.rc == 0 + until: container_clone | success + retries: 3 + delay: 2 + + - name: Show image test1-container2 + command: "machinectl show-image test1-container2" + register: container_show + changed_when: container_show.rc == 0 + until: container_show | success + retries: 3 + delay: 2 + + - name: Rename image test1-container2 + command: "machinectl rename test1-container2 test1" + register: container_rename + changed_when: container_rename.rc == 0 + until: container_rename | success + retries: 3 + delay: 2 + + - name: Check Status of test1 image + command: "machinectl image-status test1" + register: container_status + changed_when: container_status.rc == 0 + until: container_status | success + retries: 3 + delay: 2 + + - name: Start test1 container + command: "machinectl start test1" + register: container_start + changed_when: container_start.rc == 0 + until: container_start | success + retries: 3 + delay: 2 + + - name: Poweroff all containers + command: "machinectl poweroff {{ item }}" + with_items: + - container1 + - container2 + - container3 + - test1 + register: container_poweroff + changed_when: container_poweroff.rc == 0 + until: container_poweroff | success + retries: 3 + delay: 2 + + - name: Remove all containers + command: "machinectl remove {{ item }}" + with_items: + - container1 + - container2 + - container3 + - test1 + register: container_remove + changed_when: container_remove.rc == 0 + until: container_remove | success + retries: 3 + delay: 2 diff --git a/zuul.d/jobs.yaml b/zuul.d/jobs.yaml new file mode 100644 index 0000000..c82090c --- /dev/null +++ b/zuul.d/jobs.yaml @@ -0,0 +1,29 @@ +--- +# Copyright 2017, 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. + +- job: + name: openstack-ansible-nspawn-ubuntu-xenial + parent: openstack-ansible-functional + nodeset: ubuntu-xenial + +- job: + name: openstack-ansible-nspawn-centos-7 + parent: openstack-ansible-functional + nodeset: centos-7 + +# - job: +# name: openstack-ansible-nspawn-opensuse-423 +# parent: openstack-ansible-functional +# nodeset: opensuse-423 diff --git a/zuul.d/project.yaml b/zuul.d/project.yaml new file mode 100644 index 0000000..db546c8 --- /dev/null +++ b/zuul.d/project.yaml @@ -0,0 +1,30 @@ +# Copyright 2017, 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. + +- project: + check: + jobs: + - openstack-ansible-linters + - openstack-ansible-nspawn-ubuntu-xenial + - openstack-ansible-nspawn-centos-7 + # - openstack-ansible-nspawn-opensuse-423 + experimental: + jobs: + - openstack-ansible-integrated-deploy-aio + gate: + jobs: + - openstack-ansible-linters + - openstack-ansible-nspawn-ubuntu-xenial + - openstack-ansible-nspawn-centos-7 + # - openstack-ansible-nspawn-opensuse-423