mirror of
https://github.com/ansible-collections/hetzner.hcloud.git
synced 2026-02-04 08:01:49 +00:00
Fixes #203 The namespace used to differentiate the resources between CI pipelines, CI stages or even between test targets was broken and resulted in conflicting resource names. This PR ensure the resources names don't collide with each other by making sure we use the entire hcloud_prefix value as md5sum, and by including the target role names inside the resource names. Create a setup/teardown framework to handle testing resources used by the tests. To simplify the review process, additional changes such as splitting the setup/teardown task in the prepare.yml and cleanup.yml files will be done in future PRs (many files were renamed, and git will not preserve the file history after the PR squash). * chore: move integrations targets files * test: create integration common files * test: fix resources name namespace using the magic hcloud_ns * test: simplify requirements install * test: rename hcloud_server test taskfiles
116 lines
4 KiB
YAML
116 lines
4 KiB
YAML
# Copyright: (c) 2019, Hetzner Cloud GmbH <info@hetzner-cloud.de>
|
|
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
|
|
---
|
|
- name: setup ensure network is absent
|
|
hetzner.hcloud.hcloud_network:
|
|
name: "{{ hcloud_network_name }}"
|
|
state: absent
|
|
register: result
|
|
|
|
- name: create network
|
|
hetzner.hcloud.hcloud_network:
|
|
name: "{{ hcloud_network_name }}"
|
|
ip_range: "10.0.0.0/16"
|
|
labels:
|
|
key: value
|
|
register: main_network
|
|
- name: verify create network
|
|
assert:
|
|
that:
|
|
- main_network is changed
|
|
- main_network.hcloud_network.name == "{{ hcloud_network_name }}"
|
|
- main_network.hcloud_network.ip_range == "10.0.0.0/16"
|
|
- main_network.hcloud_network.expose_routes_to_vswitch is false
|
|
- name: create subnetwork
|
|
hetzner.hcloud.hcloud_subnetwork:
|
|
network: "{{ hcloud_network_name }}"
|
|
type: server
|
|
network_zone: eu-central
|
|
ip_range: "10.0.1.0/24"
|
|
register: main_subnetwork
|
|
- name: verify create subnetwork
|
|
assert:
|
|
that:
|
|
- main_subnetwork is changed
|
|
- main_subnetwork.hcloud_subnetwork.network == "{{ hcloud_network_name }}"
|
|
- name: create route
|
|
hetzner.hcloud.hcloud_route:
|
|
network: "{{ hcloud_network_name }}"
|
|
destination: "10.0.3.0/24"
|
|
gateway: "10.0.2.1"
|
|
register: main_route
|
|
- name: verify create route
|
|
assert:
|
|
that:
|
|
- main_route is changed
|
|
- main_route.hcloud_route.network == "{{ hcloud_network_name }}"
|
|
|
|
- name: test gather hcloud network info in check mode
|
|
hetzner.hcloud.hcloud_network_info:
|
|
check_mode: true
|
|
register: hcloud_network
|
|
- name: verify test gather hcloud network info in check mode
|
|
assert:
|
|
that:
|
|
- hcloud_network.hcloud_network_info | selectattr('name','equalto','{{ hcloud_network_name }}') | list | count >= 1
|
|
|
|
- name: test gather hcloud network info with correct label selector
|
|
hetzner.hcloud.hcloud_network_info:
|
|
label_selector: "key=value"
|
|
register: hcloud_network
|
|
- name: verify test gather hcloud network with correct label selector
|
|
assert:
|
|
that:
|
|
- hcloud_network.hcloud_network_info | selectattr('name','equalto','{{ hcloud_network_name }}') | list | count >= 1
|
|
|
|
- name: test gather hcloud network info with wrong label selector
|
|
hetzner.hcloud.hcloud_network_info:
|
|
label_selector: "key!=value"
|
|
register: hcloud_network
|
|
- name: verify test gather hcloud network with wrong label selector
|
|
assert:
|
|
that:
|
|
- hcloud_network.hcloud_network_info | list | count == 0
|
|
|
|
- name: test gather hcloud network info with correct name
|
|
hetzner.hcloud.hcloud_network_info:
|
|
name: "{{hcloud_network_name}}"
|
|
register: hcloud_network
|
|
- name: verify test gather hcloud network with correct name
|
|
assert:
|
|
that:
|
|
- hcloud_network.hcloud_network_info | selectattr('name','equalto','{{ hcloud_network_name }}') | list | count == 1
|
|
- hcloud_network.hcloud_network_info[0].subnetworks | list | count >= 1
|
|
- hcloud_network.hcloud_network_info[0].routes | list | count >= 1
|
|
|
|
- name: test gather hcloud network info with wrong name
|
|
hetzner.hcloud.hcloud_network_info:
|
|
name: "{{hcloud_network_name}}1"
|
|
register: hcloud_network
|
|
- name: verify test gather hcloud network with wrong name
|
|
assert:
|
|
that:
|
|
- hcloud_network.hcloud_network_info | list | count == 0
|
|
|
|
- name: test gather hcloud network info with correct id
|
|
hetzner.hcloud.hcloud_network_info:
|
|
id: "{{main_network.hcloud_network.id}}"
|
|
register: hcloud_network
|
|
- name: verify test gather hcloud network with correct id
|
|
assert:
|
|
that:
|
|
- hcloud_network.hcloud_network_info | selectattr('name','equalto','{{ hcloud_network_name }}') | list | count == 1
|
|
|
|
- name: test gather hcloud network info with wrong id
|
|
hetzner.hcloud.hcloud_network_info:
|
|
name: "4711"
|
|
register: hcloud_network
|
|
- name: verify test gather hcloud network with wrong id
|
|
assert:
|
|
that:
|
|
- hcloud_network.hcloud_network_info | list | count == 0
|
|
|
|
- name: cleanup
|
|
hetzner.hcloud.hcloud_network:
|
|
name: "{{ hcloud_network_name }}"
|
|
state: absent
|