Browse Source

Adds molecule tests to image-serve and correct validation

This patch does two things:
- ensure we don't rely on systemd within the validation itself
- adds molecule tests

Since molecule tests are running in docker containers, we can't easily
use the "systemd" helpers.
This patch makes sure the validation checks if the port is opened, and
if we get a proper answer from the server.

Change-Id: Id9a1a62e0cfff0b5300af41ec6c7a08f05ddf012
(cherry picked from commit 6ae16f588e)
tags/10.5.1
Cédric Jeanneret 1 month ago
parent
commit
77085bbec2

+ 37
- 0
roles/image-serve/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/image-serve/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

+ 58
- 0
roles/image-serve/molecule/default/playbook.yml View File

@@ -0,0 +1,58 @@
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: detect wrong port
24
+      block:
25
+        - name: run validation for wrong port
26
+          include_role:
27
+            name: image-serve
28
+          vars:
29
+            container_registry_port: 9999
30
+      rescue:
31
+        - name: Clear host errors
32
+          meta: clear_host_errors
33
+
34
+        - name: Status message
35
+          debug:
36
+            msg: "Detected faulty port!"
37
+
38
+    - name: Ensure we detect faulty tree
39
+      block:
40
+        - name: run validation for 404
41
+          include_role:
42
+              name: image-serve
43
+      rescue:
44
+        - name: Clear host errors
45
+          meta: clear_host_errors
46
+
47
+        - name: Status message
48
+          debug:
49
+            msg: "Detected faulty image serve tree!"
50
+
51
+        - name: End play
52
+          meta: end_play
53
+
54
+    - name: Fail the test
55
+      fail:
56
+        msg: |
57
+          The image-serve role should have detected httpd wasn't running or
58
+          index.json is absent.

+ 54
- 0
roles/image-serve/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
+          [DEFAULT]
54
+          local_ip = 127.0.0.1

+ 6
- 11
roles/image-serve/tasks/main.yaml View File

@@ -18,21 +18,16 @@
18 18
     container_registry_host: >-
19 19
       {{ local_ip.value|default('0.0.0.0', true)|ipaddr('address') }}
20 20
 
21
-- name: Get httpd status
22
-  systemd:
23
-    name: httpd
24
-  register: httpd_state
25
-
26
-- name: Ensure httpd is running
27
-  assert:
28
-    that: httpd_state.status['SubState'] == 'running'
29
-    fail_msg: httpd service is not running
30
-    success_msg: httpd service is running as expected
21
+- name: Ensure port is open
22
+  wait_for:
23
+    port: "{{ container_registry_port }}"
24
+    host: "{{ container_registry_host }}"
25
+    timeout: 10
31 26
 
32 27
 - name: Ensure registry does answer
33 28
   uri:
34 29
     method: HEAD
35
-    url: "http://{{ container_registry_host }}:{{ container_registry_port }}/v2/"
30
+    url: "http://{{ container_registry_host }}:{{ container_registry_port }}/v2/index.json"
36 31
     status_code:
37 32
       - 200
38 33
       - 204

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

@@ -16,6 +16,7 @@
16 16
       - tripleo-validations-centos-7-molecule-xfs-check-ftype
17 17
       - tripleo-validations-centos-7-molecule-no-op-firewall-nova-driver
18 18
       - tripleo-validations-centos-7-molecule-nova-status
19
+      - tripleo-validations-centos-7-molecule-image-serve
19 20
     gate:
20 21
       queue: integrated
21 22
       jobs:
@@ -32,6 +33,7 @@
32 33
       - tripleo-validations-centos-7-molecule-xfs-check-ftype
33 34
       - tripleo-validations-centos-7-molecule-no-op-firewall-nova-driver
34 35
       - tripleo-validations-centos-7-molecule-nova-status
36
+      - tripleo-validations-centos-7-molecule-image-serve
35 37
     name: tripleo-validations-molecule-jobs
36 38
 - job:
37 39
     files:
@@ -125,3 +127,10 @@
125 127
     parent: tripleo-validations-centos-7-base
126 128
     vars:
127 129
       tripleo_validations_role_name: nova-status
130
+- job:
131
+    files:
132
+    - ^roles/image-serve/.*
133
+    name: tripleo-validations-centos-7-molecule-image-serve
134
+    parent: tripleo-validations-centos-7-base
135
+    vars:
136
+      tripleo_validations_role_name: image-serve

Loading…
Cancel
Save