diff --git a/roles/undercloud-ram/molecule/default/Dockerfile.j2 b/roles/undercloud-ram/molecule/default/Dockerfile.j2 new file mode 100644 index 000000000..1b91a0e0b --- /dev/null +++ b/roles/undercloud-ram/molecule/default/Dockerfile.j2 @@ -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"] diff --git a/roles/undercloud-ram/molecule/default/molecule.yml b/roles/undercloud-ram/molecule/default/molecule.yml new file mode 100644 index 000000000..5eb59c254 --- /dev/null +++ b/roles/undercloud-ram/molecule/default/molecule.yml @@ -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 diff --git a/roles/undercloud-ram/molecule/default/playbook.yml b/roles/undercloud-ram/molecule/default/playbook.yml new file mode 100644 index 000000000..2e044c17a --- /dev/null +++ b/roles/undercloud-ram/molecule/default/playbook.yml @@ -0,0 +1,42 @@ +--- +# 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 + + vars: + min_undercloud_ram_gb: 1000000 + + tasks: + - block: + - include_role: + name: undercloud-ram + rescue: + - name: Clear host errors + meta: clear_host_errors + + - debug: + msg: The validation works! End the playbook run + + - name: End play + meta: end_play + + - name: Fail the test + fail: + msg: | + The undercloud-ram role should have detected that there is not + enough RAM diff --git a/roles/undercloud-ram/molecule/default/verify.yml b/roles/undercloud-ram/molecule/default/verify.yml new file mode 100644 index 000000000..dfd4c7352 --- /dev/null +++ b/roles/undercloud-ram/molecule/default/verify.yml @@ -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. diff --git a/roles/undercloud-ram/tasks/main.yml b/roles/undercloud-ram/tasks/main.yml index 2e3b7c9e6..6aeb96d23 100644 --- a/roles/undercloud-ram/tasks/main.yml +++ b/roles/undercloud-ram/tasks/main.yml @@ -1,8 +1,9 @@ --- - name: Verify the RAM requirements - fail: + debug: msg: >- The RAM on the undercloud node is {{ ansible_memtotal_mb }} MB, - the minimal recommended value is {{ min_undercloud_ram_gb|int * 1024 }} MB. + the minimal recommended value is + {{ min_undercloud_ram_gb|int * 1024 }} MB. # NOTE(shadower): converting GB to MB failed_when: "(ansible_memtotal_mb) < min_undercloud_ram_gb|int * 1024" diff --git a/tox.ini b/tox.ini index fdab58438..b47cecdf9 100644 --- a/tox.ini +++ b/tox.ini @@ -1,6 +1,6 @@ [tox] -minversion = 2.0 -envlist = py35,py36,py27,pep8 +minversion = 3.8 +envlist = pep8,py35,py36,py27,molecule skipsdist = True [testenv] @@ -58,3 +58,18 @@ deps = -c{toxinidir}/lower-constraints.txt -r{toxinidir}/test-requirements.txt -r{toxinidir}/requirements.txt + +[testenv:molecule] +deps = + ansi2html + docker>=3.7 + mock + molecule>=2.22rc3 + pytest + pytest-cov + pytest-html + pytest-molecule>=1.0rc1 + pytest-xdist + selinux +commands = + python -m pytest --color=yes --html={envlogdir}/reports.html --self-contained-html {tty:-s} {posargs:roles} diff --git a/zuul.d/layout.yaml b/zuul.d/layout.yaml index 734e300bc..2a8eae1ce 100644 --- a/zuul.d/layout.yaml +++ b/zuul.d/layout.yaml @@ -4,6 +4,7 @@ - openstack-python-jobs - openstack-python35-jobs - openstack-python36-jobs + - openstack-tox-molecule - check-requirements - publish-openstack-docs-pti - release-notes-jobs-python3