Browse Source

Modify validation and add Molecule tests for rabbitmq-limits

We can't easily add host variables, meaning we have to modify the
validation in order to accept external variable.

The Molecule test validate it's still working as expected.

Change-Id: I81edce1f949c0ad38d4ccef2a94a45f455cd9a9c
(cherry picked from commit bdf76ad239)
changes/41/680941/1
Cédric Jeanneret 1 month ago
parent
commit
56a3990a31

+ 37
- 0
roles/rabbitmq-limits/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/rabbitmq-limits/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
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
+    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/rabbitmq-limits/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: rabbitmq-limits
26
+
27
+    - name: make validation fail
28
+      block:
29
+        - name: run validation
30
+          include_role:
31
+            name: rabbitmq-limits
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 rabbitmq-limits validation didn't properly detect bad rabbitmq
50
+          setting!

+ 96
- 0
roles/rabbitmq-limits/molecule/default/prepare.yml View File

@@ -0,0 +1,96 @@
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="$1"
32
+          shift
33
+          command="$@"
34
+
35
+          case $action in
36
+            'exec')
37
+              case $container in
38
+                'heat_api_cron')
39
+                  echo '# This is a comment that should be ignored'
40
+                  echo '0 12 14 2 * heat-manage purge_deleted'
41
+                  ;;
42
+                'keystone_cron')
43
+                  echo '# This is a comment that should be ignored'
44
+                  echo '0 12 14 2 * keystone-manage token_flush'
45
+                  ;;
46
+                'rabbitmq')
47
+                  echo 16484
48
+                  ;;
49
+                *)
50
+                  echo "Unknown container ${container}"
51
+                  ;;
52
+              esac
53
+              ;;
54
+            'ps')
55
+              (echo "$@" | grep -q 'name=rabbitmq') && echo 'rabbitmq'
56
+              ;;
57
+            *)
58
+              echo "Unknown action ${action}"
59
+              ;;
60
+          esac
61
+
62
+    - name: Populate buggy docker CLI
63
+      copy:
64
+        dest: /usr/bin/docker
65
+        mode: 0755
66
+        content: |
67
+          #!/bin/bash
68
+          action="$1"
69
+          shift
70
+          container="$1"
71
+          shift
72
+          command="$@"
73
+
74
+          case $action in
75
+            'exec')
76
+              case $container in
77
+                'heat_api_cron')
78
+                  echo '# This is a comment that should be ignored'
79
+                  echo '0 12 14 2 * some-other command'
80
+                  ;;
81
+                'keystone_cron')
82
+                  echo '# This is a comment that should be ignored'
83
+                  echo '0 12 14 2 * some-other command'
84
+                  ;;
85
+                'rabbitmq')
86
+                  echo 1
87
+                  ;;
88
+                *)
89
+                  echo "Unknown container ${container}"
90
+                  ;;
91
+              esac
92
+              ;;
93
+            'ps')
94
+              (echo "$@" | grep -q 'name=rabbitmq') && echo rabbitmq
95
+              ;;
96
+          esac

+ 4
- 3
roles/rabbitmq-limits/tasks/main.yml View File

@@ -1,14 +1,15 @@
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: Get file_descriptors total_limit
7 8
   become: true
8 9
   register: actual_fd_limit
9 10
   shell: >-
10
-    "{{ container_cli|default('podman', true) }}"
11
-    exec $("{{ container_cli|default('podman', true) }}" ps -q --filter "name=rabbitmq" | head -1)
11
+    "{{ container_cli }}"
12
+    exec $("{{ container_cli }}" ps -q --filter "name=rabbitmq" | head -1)
12 13
     rabbitmqctl eval 'proplists:get_value(max_fds, erlang:system_info(check_io)).'
13 14
   changed_when: false
14 15
 

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

@@ -20,6 +20,7 @@
20 20
       - tripleo-validations-centos-7-molecule-check-network-gateway
21 21
       - tripleo-validations-centos-7-molecule-undercloud-heat-purge-deleted
22 22
       - tripleo-validations-centos-7-molecule-undercloud-tokenflush
23
+      - tripleo-validations-centos-7-molecule-rabbitmq-limits
23 24
     gate:
24 25
       queue: integrated
25 26
       jobs:
@@ -40,6 +41,7 @@
40 41
       - tripleo-validations-centos-7-molecule-check-network-gateway
41 42
       - tripleo-validations-centos-7-molecule-undercloud-heat-purge-deleted
42 43
       - tripleo-validations-centos-7-molecule-undercloud-tokenflush
44
+      - tripleo-validations-centos-7-molecule-rabbitmq-limits
43 45
     name: tripleo-validations-molecule-jobs
44 46
 - job:
45 47
     files:
@@ -161,3 +163,10 @@
161 163
     parent: tripleo-validations-centos-7-base
162 164
     vars:
163 165
       tripleo_validations_role_name: undercloud-tokenflush
166
+- job:
167
+    files:
168
+    - ^roles/rabbitmq-limits/.*
169
+    name: tripleo-validations-centos-7-molecule-rabbitmq-limits
170
+    parent: tripleo-validations-centos-7-base
171
+    vars:
172
+      tripleo_validations_role_name: rabbitmq-limits

Loading…
Cancel
Save