Zack Williams | e695dea | 2020-11-19 17:17:40 -0700 | [diff] [blame] | 1 | --- |
| 2 | # netprep molecule/default/verify.yml |
| 3 | # |
| 4 | # SPDX-FileCopyrightText: © 2020 Open Networking Foundation <support@opennetworking.org> |
| 5 | # SPDX-License-Identifier: Apache-2.0 |
| 6 | |
| 7 | - name: Verify |
| 8 | hosts: all |
Wei-Yu Chen | 6509d74 | 2021-07-29 21:14:51 +0800 | [diff] [blame] | 9 | become: true |
| 10 | vars: |
| 11 | nginx_static_dir: "/srv/sites" |
Zack Williams | e695dea | 2020-11-19 17:17:40 -0700 | [diff] [blame] | 12 | tasks: |
Wei-Yu Chen | 6509d74 | 2021-07-29 21:14:51 +0800 | [diff] [blame] | 13 | - name: Create a test file to be served for port 8080, 8081 nginx server |
| 14 | lineinfile: |
| 15 | path: "{{ nginx_static_dir }}/{{ item }}.example.com/index.html" |
| 16 | line: "This file is served from {{ item }}.example.com" |
| 17 | mode: 0644 |
| 18 | create: true |
| 19 | with_items: |
| 20 | - "port8080" |
| 21 | - "port8081" |
| 22 | - name: Create Docker container script |
| 23 | file: |
| 24 | dest: /tmp/docker_script.sh |
| 25 | state: touch |
| 26 | - name: Write content into Docker container script |
| 27 | lineinfile: |
| 28 | dest: /tmp/docker_script.sh |
| 29 | line: "{{ item }}" |
| 30 | with_items: |
| 31 | - "curl 172.17.0.1:8080 --connect-timeout 1 || exit 1" |
| 32 | - "curl 172.17.0.1:8081 --connect-timeout 1 || exit 1" |
| 33 | - "curl 172.27.0.1:8080 --connect-timeout 1 || exit 1" |
| 34 | - "curl 172.27.0.1:8081 --connect-timeout 1 && exit 1" |
| 35 | - "sleep 3600" |
| 36 | - name: Start a testing container |
| 37 | docker_container: |
| 38 | name: curl |
| 39 | image: curlimages/curl |
| 40 | state: started |
| 41 | entrypoint: "sh script.sh" |
| 42 | networks: |
| 43 | - name: bridge |
| 44 | - name: limited_network |
| 45 | volumes: |
| 46 | - /tmp/docker_script.sh:/script.sh |
| 47 | - name: Sleep for 5 seconds for curl execution |
| 48 | wait_for: |
| 49 | timeout: 5 |
| 50 | - name: Get container's information |
| 51 | docker_container_info: |
| 52 | name: curl |
| 53 | register: result |
| 54 | - name: Check container is live (it'll be live if test pass) |
| 55 | docker_container_info: |
| 56 | name: curl |
| 57 | failed_when: result.container["State"]["Running"] != true |