Browse Source

Adds molecule tests for the nova-status validation

Change-Id: Iee2f85b05ab6f36dfae8844c44f436ea3ac69274
Signed-off-by: Gael Chamoulaud <gchamoul@redhat.com>
(cherry picked from commit b0ee177f0a)
tags/10.5.1
Gael Chamoulaud 1 month ago
parent
commit
a522405617

+ 37
- 0
roles/nova-status/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"]

+ 47
- 0
roles/nova-status/molecule/default/molecule.yml View File

@@ -0,0 +1,47 @@
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 python-enum34
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 python*-enum
22
+    environment:
23
+      <<: *env
24
+
25
+provisioner:
26
+  name: ansible
27
+  log: true
28
+  env:
29
+    ANSIBLE_STDOUT_CALLBACK: yaml
30
+    ANSIBLE_LIBRARY: "../../../../library"
31
+
32
+scenario:
33
+  test_sequence:
34
+    - destroy
35
+    - create
36
+    - prepare
37
+    - converge
38
+    - verify
39
+    - destroy
40
+
41
+lint:
42
+  enabled: false
43
+
44
+verifier:
45
+  name: testinfra
46
+  lint:
47
+    name: flake8

+ 50
- 0
roles/nova-status/molecule/default/playbook.yml View File

@@ -0,0 +1,50 @@
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
+  gather_facts: no
21
+
22
+  tasks:
23
+    - name: working detection
24
+      include_role:
25
+        name: nova-status
26
+
27
+    - name: make validation fail
28
+      block:
29
+        - name: run validation
30
+          include_role:
31
+            name: nova-status
32
+          vars:
33
+            container_cli: docker
34
+
35
+      rescue:
36
+        - name: Clear host errors
37
+          meta: clear_host_errors
38
+
39
+        - name: Test output
40
+          debug:
41
+            msg: The validation works! End play
42
+
43
+        - name: End play
44
+          meta: end_play
45
+
46
+    - name: Fail playbook if reached
47
+      fail:
48
+        msg: |
49
+          The nova-status validation didn't properly detect bad upgrade
50
+          status check!

+ 79
- 0
roles/nova-status/molecule/default/prepare.yml View File

@@ -0,0 +1,79 @@
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: Prepare
19
+  hosts: all
20
+  gather_facts: no
21
+
22
+  tasks:
23
+    - name: Populate successful podman CLI
24
+      copy:
25
+        dest: /usr/bin/podman
26
+        mode: 0755
27
+        content: |
28
+          #!/bin/bash
29
+          action="$1"
30
+          shift
31
+          container="$3"
32
+          shift
33
+          command="$@"
34
+
35
+          case $container in
36
+            'heat_api_cron')
37
+              echo '# This is a comment that should be ignored'
38
+              echo '0 12 14 2 * heat-manage purge_deleted'
39
+              ;;
40
+            'keystone_cron')
41
+              echo '# This is a comment that should be ignored'
42
+              echo '0 12 14 2 * keystone-manage token_flush'
43
+              ;;
44
+            'nova_api')
45
+              exit 0
46
+              ;;
47
+            *)
48
+              echo "Unknown container ${container}"
49
+              ;;
50
+          esac
51
+
52
+    - name: Populate buggy docker CLI
53
+      copy:
54
+        dest: /usr/bin/docker
55
+        mode: 0755
56
+        content: |
57
+          #!/bin/bash
58
+          action="$1"
59
+          shift
60
+          container="$3"
61
+          shift
62
+          command="$@"
63
+
64
+          case $container in
65
+            'heat_api_cron')
66
+              echo '# This is a comment that should be ignored'
67
+              echo '0 12 14 2 * some-other command'
68
+              ;;
69
+            'keystone_cron')
70
+              echo '# This is a comment that should be ignored'
71
+              echo '0 12 14 2 * some-other command'
72
+              ;;
73
+            'nova_api')
74
+              exit 2
75
+              ;;
76
+            *)
77
+              echo "Unknown container ${container}"
78
+              ;;
79
+          esac

+ 2
- 1
roles/nova-status/tasks/main.yml View File

@@ -1,7 +1,8 @@
1 1
 ---
2 2
 - name: Set container_cli fact from the inventory
3 3
   set_fact:
4
-    container_cli: "{{ hostvars[inventory_hostname].container_cli }}"
4
+    container_cli: "{{ hostvars[inventory_hostname].container_cli | default('podman', true) }}"
5
+  when: container_cli is not defined
5 6
 
6 7
 - name: Check nova upgrade status
7 8
   become: true

+ 9
- 0
zuul.d/molecule.yaml View File

@@ -15,6 +15,7 @@
15 15
       - tripleo-validations-centos-7-molecule-undercloud-disk-space
16 16
       - tripleo-validations-centos-7-molecule-xfs-check-ftype
17 17
       - tripleo-validations-centos-7-molecule-no-op-firewall-nova-driver
18
+      - tripleo-validations-centos-7-molecule-nova-status
18 19
     gate:
19 20
       queue: integrated
20 21
       jobs:
@@ -30,6 +31,7 @@
30 31
       - tripleo-validations-centos-7-molecule-undercloud-disk-space
31 32
       - tripleo-validations-centos-7-molecule-xfs-check-ftype
32 33
       - tripleo-validations-centos-7-molecule-no-op-firewall-nova-driver
34
+      - tripleo-validations-centos-7-molecule-nova-status
33 35
     name: tripleo-validations-molecule-jobs
34 36
 - job:
35 37
     files:
@@ -116,3 +118,10 @@
116 118
     parent: tripleo-validations-centos-7-base
117 119
     vars:
118 120
       tripleo_validations_role_name: no-op-firewall-nova-driver
121
+- job:
122
+    files:
123
+    - ^roles/nova-status/.*
124
+    name: tripleo-validations-centos-7-molecule-nova-status
125
+    parent: tripleo-validations-centos-7-base
126
+    vars:
127
+      tripleo_validations_role_name: nova-status

Loading…
Cancel
Save