Browse Source

Add molecule tests for the undercloud-cpu role

Change-Id: I1951ea46bd426b55157d6b1b863fd8a46c110755
Signed-off-by: Gael Chamoulaud <gchamoul@redhat.com>
(cherry picked from commit 5f0e39a7fe)
tags/10.5.1
Gael Chamoulaud 2 months ago
parent
commit
0e5c743925

+ 37
- 0
roles/undercloud-cpu/molecule/default/Dockerfile.j2 View File

@@ -0,0 +1,37 @@
1
+# Molecule managed
2
+# Copyright 2019 Red Hat, Inc.
3
+# All Rights Reserved.
4
+#
5
+# Licensed under the Apache License, Version 2.0 (the "License"); you may
6
+# not use this file except in compliance with the License. You may obtain
7
+# a copy of the License at
8
+#
9
+#     http://www.apache.org/licenses/LICENSE-2.0
10
+#
11
+# Unless required by applicable law or agreed to in writing, software
12
+# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
13
+# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
14
+# License for the specific language governing permissions and limitations
15
+# under the License.
16
+
17
+
18
+{% if item.registry is defined %}
19
+FROM {{ item.registry.url }}/{{ item.image }}
20
+{% else %}
21
+FROM {{ item.image }}
22
+{% endif %}
23
+
24
+RUN if [ $(command -v apt-get) ]; then apt-get update && apt-get install -y python sudo bash ca-certificates && apt-get clean; \
25
+    elif [ $(command -v dnf) ]; then dnf makecache && dnf --assumeyes install python sudo python-devel python*-dnf bash {{ item.pkg_extras | default('') }} && dnf clean all; \
26
+    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; \
27
+    elif [ $(command -v zypper) ]; then zypper refresh && zypper install -y python sudo bash python-xml {{ item.pkg_extras | default('') }} && zypper clean -a; \
28
+    elif [ $(command -v apk) ]; then apk update && apk add --no-cache python sudo bash ca-certificates {{ item.pkg_extras | default('') }}; \
29
+    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
30
+
31
+{% for pkg in item.easy_install | default([]) %}
32
+# install pip for centos where there is no python-pip rpm in default repos
33
+RUN easy_install {{ pkg }}
34
+{% endfor %}
35
+
36
+
37
+CMD ["sh", "-c", "while true; do sleep 10000; done"]

+ 46
- 0
roles/undercloud-cpu/molecule/default/molecule.yml View File

@@ -0,0 +1,46 @@
1
+---
2
+driver:
3
+  name: docker
4
+
5
+log: true
6
+
7
+platforms:
8
+  - name: centos7
9
+    hostname: centos7
10
+    image: centos:7
11
+    pkg_extras: python-setuptools
12
+    easy_install:
13
+      - pip
14
+    environment: &env
15
+      http_proxy: "{{ lookup('env', 'http_proxy') }}"
16
+      https_proxy: "{{ lookup('env', 'https_proxy') }}"
17
+
18
+  - name: fedora28
19
+    hostname: fedora28
20
+    image: fedora:28
21
+    pkg_extras: python*-setuptools
22
+    environment:
23
+      <<: *env
24
+
25
+provisioner:
26
+  name: ansible
27
+  log: true
28
+  env:
29
+    ANSIBLE_STDOUT_CALLBACK: yaml
30
+
31
+scenario:
32
+  test_sequence:
33
+    - destroy
34
+    - create
35
+    - prepare
36
+    - converge
37
+    - verify
38
+    - destroy
39
+
40
+lint:
41
+  enabled: false
42
+
43
+verifier:
44
+  name: testinfra
45
+  lint:
46
+    name: flake8

+ 42
- 0
roles/undercloud-cpu/molecule/default/playbook.yml View File

@@ -0,0 +1,42 @@
1
+---
2
+# Copyright 2019 Red Hat, Inc.
3
+# All Rights Reserved.
4
+#
5
+# Licensed under the Apache License, Version 2.0 (the "License"); you may
6
+# not use this file except in compliance with the License. You may obtain
7
+# a copy of the License at
8
+#
9
+#     http://www.apache.org/licenses/LICENSE-2.0
10
+#
11
+# Unless required by applicable law or agreed to in writing, software
12
+# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
13
+# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
14
+# License for the specific language governing permissions and limitations
15
+# under the License.
16
+
17
+
18
+- name: Converge
19
+  hosts: all
20
+
21
+  vars:
22
+    min_undercloud_cpu_count: 100
23
+
24
+  tasks:
25
+    - block:
26
+        - include_role:
27
+            name: undercloud-cpu
28
+      rescue:
29
+        - name: Clear host errors
30
+          meta: clear_host_errors
31
+
32
+        - debug:
33
+            msg: The validation works! End the playbook run
34
+
35
+        - name: End play
36
+          meta: end_play
37
+
38
+    - name: Fail the test
39
+      fail:
40
+        msg: |
41
+          The undercloud-cpu role should have detected that there is not
42
+          enough CPU

Loading…
Cancel
Save