Browse Source

Add Molecule tests for check-network-gateway

Change-Id: I3923fb89ac6e43de3e24b8c649dcfd30a72682b6
(cherry picked from commit 6dffc61d94)
changes/38/680938/1
Cédric Jeanneret 1 month ago
parent
commit
a1d01a941f

+ 37
- 0
roles/check-network-gateway/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/check-network-gateway/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 python-netaddr epel-release ruby
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 python*-netaddr ruby iputils
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

+ 68
- 0
roles/check-network-gateway/molecule/default/playbook.yml View File

@@ -0,0 +1,68 @@
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: successful check with ctlplane-subnet
24
+      include_role:
25
+        name: check-network-gateway
26
+
27
+    - name: override undercloud.conf
28
+      copy:
29
+        dest: /undercloud.conf
30
+        content: |
31
+          [DEFAULT]
32
+          local_subnet = 192.168.254.0/24
33
+          [192.168.254.0/24]
34
+          gateway = 8.8.8.8
35
+
36
+    - name: successful check with local_ip
37
+      include_role:
38
+        name: check-network-gateway
39
+
40
+    - name: fail the validation
41
+      block:
42
+        - name: override undercloud.conf
43
+          copy:
44
+            dest: /undercloud.conf
45
+            content: |
46
+              [ctlplane-subnet]
47
+              gateway = 192.168.254.254
48
+
49
+        - name: run the validation
50
+          include_role:
51
+            name: check-network-gateway
52
+
53
+      rescue:
54
+        - name: Clear host error
55
+          meta: clear_host_errors
56
+
57
+        - name: Validation output
58
+          debug:
59
+            msg: The validation works! End the playbook run
60
+
61
+        - name: End play
62
+          meta: end_play
63
+
64
+    - name: Fail the test
65
+      fail:
66
+        msg: |
67
+          The check-network-gateway validation didn't properly detect faulty
68
+          gateway!

+ 54
- 0
roles/check-network-gateway/molecule/default/prepare.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: 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
+          [ctlplane-subnet]
54
+          gateway = 8.8.8.8

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

@@ -17,6 +17,7 @@
17 17
       - tripleo-validations-centos-7-molecule-no-op-firewall-nova-driver
18 18
       - tripleo-validations-centos-7-molecule-nova-status
19 19
       - tripleo-validations-centos-7-molecule-image-serve
20
+      - tripleo-validations-centos-7-molecule-check-network-gateway
20 21
     gate:
21 22
       queue: integrated
22 23
       jobs:
@@ -34,6 +35,7 @@
34 35
       - tripleo-validations-centos-7-molecule-no-op-firewall-nova-driver
35 36
       - tripleo-validations-centos-7-molecule-nova-status
36 37
       - tripleo-validations-centos-7-molecule-image-serve
38
+      - tripleo-validations-centos-7-molecule-check-network-gateway
37 39
     name: tripleo-validations-molecule-jobs
38 40
 - job:
39 41
     files:
@@ -134,3 +136,10 @@
134 136
     parent: tripleo-validations-centos-7-base
135 137
     vars:
136 138
       tripleo_validations_role_name: image-serve
139
+- job:
140
+    files:
141
+    - ^roles/check-network-gateway/.*
142
+    name: tripleo-validations-centos-7-molecule-check-network-gateway
143
+    parent: tripleo-validations-centos-7-base
144
+    vars:
145
+      tripleo_validations_role_name: check-network-gateway

Loading…
Cancel
Save