Merge "Correct "repos" validation and adds Molecule tests" into stable/stein

This commit is contained in:
Zuul 2019-08-13 19:10:22 +00:00 committed by Gerrit Code Review
commit 6f827f5ff8
5 changed files with 184 additions and 14 deletions

View File

@ -0,0 +1,37 @@
# Molecule managed
# 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.
{% if item.registry is defined %}
FROM {{ item.registry.url }}/{{ item.image }}
{% else %}
FROM {{ item.image }}
{% endif %}
RUN if [ $(command -v apt-get) ]; then apt-get update && apt-get install -y python sudo bash ca-certificates && apt-get clean; \
elif [ $(command -v dnf) ]; then dnf makecache && dnf --assumeyes install python sudo python-devel python*-dnf bash {{ item.pkg_extras | default('') }} && dnf clean all; \
elif [ $(command -v yum) ]; then yum makecache fast && yum install -y python sudo yum-plugin-ovl python-setuptools bash {{ item.pkg_extras | default('') }} && sed -i 's/plugins=0/plugins=1/g' /etc/yum.conf && yum clean all; \
elif [ $(command -v zypper) ]; then zypper refresh && zypper install -y python sudo bash python-xml {{ item.pkg_extras | default('') }} && zypper clean -a; \
elif [ $(command -v apk) ]; then apk update && apk add --no-cache python sudo bash ca-certificates {{ item.pkg_extras | default('') }}; \
elif [ $(command -v xbps-install) ]; then xbps-install -Syu && xbps-install -y python sudo bash ca-certificates {{ item.pkg_extras | default('') }} && xbps-remove -O; fi
{% for pkg in item.easy_install | default([]) %}
# install pip for centos where there is no python-pip rpm in default repos
RUN easy_install {{ pkg }}
{% endfor %}
CMD ["sh", "-c", "while true; do sleep 10000; done"]

View File

@ -0,0 +1,46 @@
---
driver:
name: docker
log: true
platforms:
- name: centos7
hostname: centos7
image: centos:7
pkg_extras: python-setuptools
easy_install:
- pip
environment: &env
http_proxy: "{{ lookup('env', 'http_proxy') }}"
https_proxy: "{{ lookup('env', 'https_proxy') }}"
- name: fedora28
hostname: fedora28
image: fedora:28
pkg_extras: python*-setuptools
environment:
<<: *env
provisioner:
name: ansible
log: true
env:
ANSIBLE_STDOUT_CALLBACK: yaml
scenario:
test_sequence:
- destroy
- create
- prepare
- converge
- verify
- destroy
lint:
enabled: false
verifier:
name: testinfra
lint:
name: flake8

View File

@ -0,0 +1,79 @@
---
# 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: Converge
hosts: all
tasks:
- name: test role without failure
include_role:
name: repos
- name: run with failure
block:
- name: inject faulty repository
yum_repository:
name: faulty
description: really faulty repository
baseurl: http://this.repository.do-not.exists/like-not-at-all
enabled: yes
- name: execute role
include_role:
name: repos
rescue:
- name: clean host error
meta: clear_host_errors
- name: Molecule output
debug:
msg: Successfully detected first broken repository
- name: run with another failure
block:
- name: remove faulty repository
yum_repository:
name: faulty
state: absent
- name: push another faulty repository with working DNS
yum_repository:
name: faulty-bis
description: faulty repository with working DNS
baseurl: http://download.fedoraproject.org/pub/fedora/blah
enabled: yes
- name: execute role
include_role:
name: repos
rescue:
- name: clean host error
meta: clear_host_errors
- name: Molecule output
debug:
msg: Successfully detected second faulty repository. Exiting!
- name: End play
meta: end_play
- name: Fail the test
fail:
msg: |
The repos validation failed detecting broken/non-working repository

View File

@ -0,0 +1,15 @@
---
# 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.

View File

@ -1,26 +1,19 @@
---
- name: List repositories
become: True
command: '{{ ansible_pkg_mgr }} repolist -v'
shell: |
{{ ansible_pkg_mgr }} repolist enabled -v 2>&1 || exit 0
args:
warn: no
changed_when: False
register: repositories
- name: Find repository URLs
shell: 'echo "{{ repositories.stdout }}" | grep Repo-baseurl | sed "s/Repo-baseurl.*\(http[^ ]*\).*/\1/g"'
register: repository_urls
changed_when: False
- name: Check if there is at least one repository baseurl
- name: Fail if we detect error in repolist output
fail:
msg: No repository found in {{ ansible_pkg_mgr }} repolist
when: repository_urls.stdout_lines|length < 1
- name: Call repository URLs
uri:
url: "{{ item }}"
with_items: "{{ repository_urls.stdout_lines }}"
msg: |
One or more repositories are either broken or unreachable. Please correct.
when:
repositories.stdout is regex('(cannot|could not|failure)', ignorecase=True)
- name: Find repository IDs
changed_when: False