diff --git a/ansible-role-requirements.yml b/ansible-role-requirements.yml new file mode 100644 index 000000000..b07642f4c --- /dev/null +++ b/ansible-role-requirements.yml @@ -0,0 +1,21 @@ +--- +# Copyright 2019 Red Hat, Inc. +# All Rights Reserved. +# +# 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: tripleo-ansible + scm: git + src: https://opendev.org/openstack/tripleo-ansible + version: master + trackbranch: master diff --git a/roles/image_serve/defaults/main.yaml b/roles/image_serve/defaults/main.yaml index 9f5ff6846..6badfc970 100644 --- a/roles/image_serve/defaults/main.yaml +++ b/roles/image_serve/defaults/main.yaml @@ -1,2 +1,3 @@ --- container_registry_port: 8787 +container_registry_httpd_config: "/etc/httpd/conf.d/image-serve.conf" diff --git a/roles/image_serve/molecule/default/converge.yml b/roles/image_serve/molecule/default/converge.yml index 00f835ffc..8b6fa211e 100644 --- a/roles/image_serve/molecule/default/converge.yml +++ b/roles/image_serve/molecule/default/converge.yml @@ -35,8 +35,28 @@ debug: msg: "Detected faulty port!" + - name: Run validation for wrong config file + block: + - name: Run validation for wrong config file + include_role: + name: image_serve + vars: + container_registry_httpd_config: /fake-image-serve.conf + rescue: + - name: Clear host errors + meta: clear_host_errors + + - name: Status message + debug: + msg: "Detected wrong config file!" + - name: Ensure we detect faulty tree block: + - name: Stopping httpd + systemd: + name: httpd + state: stopped + - name: run validation for 404 include_role: name: image_serve diff --git a/roles/image_serve/molecule/default/molecule.yml b/roles/image_serve/molecule/default/molecule.yml index 6138aefd9..0eb863c45 100644 --- a/roles/image_serve/molecule/default/molecule.yml +++ b/roles/image_serve/molecule/default/molecule.yml @@ -7,9 +7,12 @@ log: true platforms: - name: centos7 hostname: centos7 + etc_hosts: + undercloud.ctlplane.mydomain.tld: "127.0.0.1" image: centos:7 override_command: true - command: python -m SimpleHTTPServer 8787 + command: /sbin/init + privileged: true pkg_extras: python-setuptools python-enum34 python-netaddr epel-release ruby PyYAML volumes: - /etc/ci/mirror_info.sh:/etc/ci/mirror_info.sh:ro @@ -21,9 +24,12 @@ platforms: - name: centos8 hostname: centos8 + etc_hosts: + undercloud.ctlplane.mydomain.tld: "127.0.0.1" image: centos:8 override_command: true - command: python3 -m http.server 8787 + command: /sbin/init + privileged: true pkg_extras: python*-setuptools python*-enum34 python*-netaddr ruby epel-release python*-PyYAML volumes: - /etc/ci/mirror_info.sh:/etc/ci/mirror_info.sh:ro @@ -35,7 +41,8 @@ provisioner: log: true env: ANSIBLE_STDOUT_CALLBACK: yaml - ANSIBLE_LIBRARY: "../../../../library" + ANSIBLE_LIBRARY: ../../../../library + ANSIBLE_ROLES_PATH: ../../../../roles/roles.galaxy/tripleo-ansible/tripleo-ansible/tripleo_ansible/roles scenario: test_sequence: diff --git a/roles/image_serve/molecule/default/prepare.yml b/roles/image_serve/molecule/default/prepare.yml index e2dc73221..4140ceddc 100644 --- a/roles/image_serve/molecule/default/prepare.yml +++ b/roles/image_serve/molecule/default/prepare.yml @@ -17,38 +17,9 @@ - name: Prepare hosts: all - gather_facts: false - tasks: - - name: install hiera - package: - name: hiera - - - name: create hiera tree - file: - path: /etc/puppet - state: directory - - - name: populate hiera.yaml - copy: - dest: /etc/puppet/hiera.yaml - content: | - :backends: - - yaml - :yaml: - :datadir: "/etc/puppet/" - :hierarchy: - - "common" - - - name: populate hiera content - copy: - dest: /etc/puppet/common.yaml - content: | - tripleo_undercloud_conf_file: /undercloud.conf - - - name: populate undercloud.conf - copy: - dest: /undercloud.conf - content: | - [DEFAULT] - local_ip = 127.0.0.1 + - name: Container registry installation + include_role: + name: tripleo_image_serve + vars: + tripleo_container_registry_host: undercloud.ctlplane.mydomain.tld diff --git a/roles/image_serve/tasks/main.yaml b/roles/image_serve/tasks/main.yaml index 7ce364241..28413e299 100644 --- a/roles/image_serve/tasks/main.yaml +++ b/roles/image_serve/tasks/main.yaml @@ -1,33 +1,29 @@ --- -- name: Get the path of tripleo undercloud config file - become: true - hiera: - name: "tripleo_undercloud_conf_file" +- name: Ensure we have the httpd config + stat: + path: "{{ container_registry_httpd_config }}" + register: registry_config -- name: Get local_ip value from the undercloud.conf file - become: true - validations_read_ini: - path: "{{ tripleo_undercloud_conf_file }}" - section: DEFAULT - key: local_ip - ignore_missing_file: true - register: local_ip +- name: Fail early if no httpd config is present + when: not registry_config.stat.exists + fail: + msg: "Unable to find vhost config {{ container_registry_httpd_config }}. Exiting now." -- name: Set container registry host - set_fact: - container_registry_host: >- - {{ local_ip.value|default('0.0.0.0', true)|ipaddr('address') }} +- name: Extract vhost name from httpd config + command: | + awk -F '[ >:]*' '/VirtualHost/ {print $2; exit}' {{ container_registry_httpd_config }} + register: virthost_name - name: Ensure port is open wait_for: port: "{{ container_registry_port }}" - host: "{{ container_registry_host }}" + host: "{{ virthost_name.stdout }}" timeout: 10 - name: Ensure registry does answer uri: method: HEAD - url: "http://{{ container_registry_host }}:{{ container_registry_port }}/v2/index.json" + url: "http://{{ virthost_name.stdout }}:{{ container_registry_port }}/v2/index.json" status_code: - 200 - 204 diff --git a/roles/roles.galaxy/.gitkeep b/roles/roles.galaxy/.gitkeep new file mode 100644 index 000000000..e69de29bb diff --git a/zuul.d/playbooks/pre.yml b/zuul.d/playbooks/pre.yml index ac07423c7..92c21c72a 100644 --- a/zuul.d/playbooks/pre.yml +++ b/zuul.d/playbooks/pre.yml @@ -28,5 +28,15 @@ requirements: "{{ ansible_user_dir }}/{{ zuul.project.src_dir }}/molecule-requirements.txt" virtualenv: "{{ ansible_user_dir }}/test-python" virtualenv_site_packages: true + + tasks: + - name: Get Ansible Galaxy roles + command: >- + {{ ansible_user_dir }}/test-python/bin/ansible-galaxy install + -fr + {{ ansible_user_dir }}/{{ zuul.project.src_dir }}/ansible-role-requirements.yml + environment: + ANSIBLE_ROLES_PATH: "{{ ansible_user_dir }}/{{ zuul.project.src_dir }}/roles/roles.galaxy" + roles: - role: ensure-docker diff --git a/zuul.d/playbooks/run.yml b/zuul.d/playbooks/run.yml index 30496ec11..a82b78173 100644 --- a/zuul.d/playbooks/run.yml +++ b/zuul.d/playbooks/run.yml @@ -3,17 +3,32 @@ - hosts: all environment: ANSIBLE_LOG_PATH: "{{ ansible_user_dir }}/zuul-output/logs/ansible-execution.log" + pre_tasks: + + - name: Set project path fact + set_fact: + tripleo_validations_project_path: "{{ ansible_user_dir }}/{{ zuul.projects['opendev.org/openstack/tripleo-validations'].src_dir }}" + + - name: Set role path fact + set_fact: + tripleo_validations_roles_paths: + - "{{ tripleo_validations_project_path }}/roles/roles.galaxy/tripleo-ansible/tripleo_ansible/roles" + - "{{ tripleo_validations_project_path }}/roles/roles.galaxy/tripleo-ansible/tripleo-ansible/tripleo_ansible/roles" + - "{{ tripleo_validations_project_path }}/roles" + - "/usr/share/ansible/roles" + tasks: - name: Run role test job shell: |- . {{ ansible_user_dir }}/test-python/bin/activate - . {{ ansible_user_dir }}/{{ zuul.project.src_dir }}/ansible-test-env.rc + . {{ tripleo_validations_project_path }}/ansible-test-env.rc pytest --color=no \ --html={{ ansible_user_dir }}/zuul-output/logs/reports.html \ --self-contained-html \ --ansible-args='{{ tripleo_job_ansible_args | default("") }}' \ - {{ ansible_user_dir }}/{{ zuul.project.src_dir }}/tests/test_molecule.py + {{ tripleo_validations_project_path }}/tests/test_molecule.py args: - chdir: "{{ ansible_user_dir }}/{{ zuul.project.src_dir }}/roles/{{ tripleo_validations_role_name }}" + chdir: "{{ tripleo_validations_project_path }}/roles/{{ tripleo_validations_role_name }}" executable: /bin/bash - changed_when: false + environment: + ANSIBLE_ROLE_PATH: "{{ tripleo_validations_roles_paths | join(':') }}"