Browse Source

Adds molecule testing for undercloud-tokenflush

Change-Id: I26275ce12bbb824a24a7d2571d1920208cd34aca
(cherry picked from commit 0cb6d6172e)
changes/40/680940/1
Cédric Jeanneret 1 month ago
parent
commit
21e5256128

+ 37
- 0
roles/undercloud-tokenflush/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"]

+ 51
- 0
roles/undercloud-tokenflush/molecule/default/molecule.yml View File

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

+ 54
- 0
roles/undercloud-tokenflush/molecule/default/playbook.yml View File

@@ -0,0 +1,54 @@
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: undercloud-tokenflush
26
+
27
+    - name: Validate failure
28
+      block:
29
+        - name: Override container_cli
30
+          copy:
31
+            dest: /undercloud.conf
32
+            content: |
33
+              [DEFAULT]
34
+              container_cli = docker
35
+
36
+        - name: run validation
37
+          include_role:
38
+            name: undercloud-tokenflush
39
+      rescue:
40
+        - name: Clear host errors
41
+          meta: clear_host_errors
42
+
43
+        - name: Test output
44
+          debug:
45
+            msg: The validation works! Ending play.
46
+
47
+        - name: End play
48
+          meta: end_play
49
+
50
+    - name: Fail the validation at this point
51
+      fail:
52
+        msg: |
53
+          The undercloud-tokenflush validation failed to detect
54
+          missing cron job.

+ 106
- 0
roles/undercloud-tokenflush/molecule/default/prepare.yml View File

@@ -0,0 +1,106 @@
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: install hiera
24
+      package:
25
+        name: hiera
26
+
27
+    - name: create hiera tree
28
+      file:
29
+        path: /etc/puppet
30
+        state: directory
31
+
32
+    - name: populate hiera.yaml
33
+      copy:
34
+        dest: /etc/puppet/hiera.yaml
35
+        content: |
36
+          :backends:
37
+            - yaml
38
+          :yaml:
39
+            :datadir: "/etc/puppet/"
40
+          :hierarchy:
41
+            - "common"
42
+
43
+    - name: populate hiera content
44
+      copy:
45
+        dest: /etc/puppet/common.yaml
46
+        content: |
47
+          tripleo_undercloud_conf_file: /undercloud.conf
48
+
49
+    - name: populate undercloud.conf
50
+      copy:
51
+        dest: /undercloud.conf
52
+        content: |
53
+          [DEFAULT]
54
+          container_cli = podman
55
+
56
+    - name: Populate successful podman CLI
57
+      copy:
58
+        dest: /usr/bin/podman
59
+        mode: 0755
60
+        content: |
61
+          #!/bin/bash
62
+          action="$1"
63
+          shift
64
+          container="$1"
65
+          shift
66
+          command="$@"
67
+
68
+          case $container in
69
+            'heat_api_cron')
70
+              echo '# This is a comment that should be ignored'
71
+              echo '0 12 14 2 * heat-manage purge_deleted'
72
+              ;;
73
+            'keystone_cron')
74
+              echo '# This is a comment that should be ignored'
75
+              echo '0 12 14 2 * keystone-manage token_flush'
76
+              ;;
77
+            *)
78
+              echo "Unknown container ${container}"
79
+              ;;
80
+          esac
81
+
82
+    - name: Populate buggy docker CLI
83
+      copy:
84
+        dest: /usr/bin/docker
85
+        mode: 0755
86
+        content: |
87
+          #!/bin/bash
88
+          action="$1"
89
+          shift
90
+          container="$1"
91
+          shift
92
+          command="$@"
93
+
94
+          case $container in
95
+            'heat_api_cron')
96
+              echo '# This is a comment that should be ignored'
97
+              echo '0 12 14 2 * some-other command'
98
+              ;;
99
+            'keystone_cron')
100
+              echo '# This is a comment that should be ignored'
101
+              echo '0 12 14 2 * some-other command'
102
+              ;;
103
+            *)
104
+              echo "Unknown container ${container}"
105
+              ;;
106
+          esac

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

@@ -19,6 +19,7 @@
19 19
       - tripleo-validations-centos-7-molecule-image-serve
20 20
       - tripleo-validations-centos-7-molecule-check-network-gateway
21 21
       - tripleo-validations-centos-7-molecule-undercloud-heat-purge-deleted
22
+      - tripleo-validations-centos-7-molecule-undercloud-tokenflush
22 23
     gate:
23 24
       queue: integrated
24 25
       jobs:
@@ -38,6 +39,7 @@
38 39
       - tripleo-validations-centos-7-molecule-image-serve
39 40
       - tripleo-validations-centos-7-molecule-check-network-gateway
40 41
       - tripleo-validations-centos-7-molecule-undercloud-heat-purge-deleted
42
+      - tripleo-validations-centos-7-molecule-undercloud-tokenflush
41 43
     name: tripleo-validations-molecule-jobs
42 44
 - job:
43 45
     files:
@@ -152,3 +154,10 @@
152 154
     parent: tripleo-validations-centos-7-base
153 155
     vars:
154 156
       tripleo_validations_role_name: undercloud-heat-purge-deleted
157
+- job:
158
+    files:
159
+    - ^roles/undercloud-tokenflush/.*
160
+    name: tripleo-validations-centos-7-molecule-undercloud-tokenflush
161
+    parent: tripleo-validations-centos-7-base
162
+    vars:
163
+      tripleo_validations_role_name: undercloud-tokenflush

Loading…
Cancel
Save