forked from ansible-collections/hetzner.hcloud
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: fix vswitch subnets ip_range (ansible-collections#359)
##### SUMMARY The vswitch subnet validation changed: the subnet ip_range must be smaller than the network ip_range **AND** must not start with the same IP. See https://github.com/ansible-collections/hetzner.hcloud/runs/17672011247 In addition, I reworked the tests to use the new testing framework.
- Loading branch information
Showing
7 changed files
with
94 additions
and
83 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
5 changes: 5 additions & 0 deletions
5
tests/integration/targets/hcloud_subnetwork/tasks/cleanup.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
- name: Cleanup test_network | ||
hetzner.hcloud.hcloud_network: | ||
name: "{{ hcloud_network_name }}" | ||
state: absent |
11 changes: 11 additions & 0 deletions
11
tests/integration/targets/hcloud_subnetwork/tasks/prepare.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
--- | ||
- name: Create test_network | ||
hetzner.hcloud.hcloud_network: | ||
name: "{{ hcloud_network_name }}" | ||
ip_range: "10.0.0.0/16" | ||
state: present | ||
register: test_network | ||
|
||
- name: Select hetzner vswitch id from pool | ||
ansible.builtin.set_fact: | ||
test_vswitch_id: "{{ hetzner_vswitch_ids | random }}" |
132 changes: 55 additions & 77 deletions
132
tests/integration/targets/hcloud_subnetwork/tasks/test.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,125 +1,103 @@ | ||
# Copyright: (c) 2019, Hetzner Cloud GmbH <[email protected]> | ||
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) | ||
--- | ||
- name: setup | ||
hetzner.hcloud.hcloud_network: | ||
name: "{{ hcloud_network_name }}" | ||
ip_range: "10.0.0.0/8" | ||
state: present | ||
register: network | ||
- name: verify setup | ||
assert: | ||
that: | ||
- network is success | ||
|
||
- name: test missing required parameters on create route | ||
- name: Test missing required parameters | ||
hetzner.hcloud.hcloud_subnetwork: | ||
network: "{{ hcloud_network_name }}" | ||
state: present | ||
register: result | ||
ignore_errors: true | ||
- name: verify fail test missing required parameters on create route | ||
assert: | ||
register: result | ||
- name: Verify missing required parameters | ||
ansible.builtin.assert: | ||
that: | ||
- result is failed | ||
- 'result.msg == "missing required arguments: ip_range, network_zone, type"' | ||
|
||
- name: test create subnetwork with checkmode | ||
- name: Test create with checkmode | ||
hetzner.hcloud.hcloud_subnetwork: | ||
network: "{{ hcloud_network_name }}" | ||
ip_range: "10.0.0.0/16" | ||
type: "server" | ||
network_zone: "eu-central" | ||
network_zone: eu-central | ||
type: cloud | ||
ip_range: 10.0.0.0/24 | ||
state: present | ||
register: result | ||
check_mode: true | ||
- name: verify test create subnetwork with checkmode | ||
assert: | ||
register: result | ||
- name: Verify create with checkmode | ||
ansible.builtin.assert: | ||
that: | ||
- result is changed | ||
|
||
- name: test create subnetwork | ||
- name: Test create | ||
hetzner.hcloud.hcloud_subnetwork: | ||
network: "{{ hcloud_network_name }}" | ||
ip_range: "10.0.0.0/16" | ||
type: "cloud" | ||
network_zone: "eu-central" | ||
network_zone: eu-central | ||
type: cloud | ||
ip_range: 10.0.0.0/24 | ||
state: present | ||
register: subnet | ||
- name: verify create subnetwork | ||
assert: | ||
register: result | ||
- name: Verify create | ||
ansible.builtin.assert: | ||
that: | ||
- subnet is changed | ||
- subnet.hcloud_subnetwork.network == "{{ hcloud_network_name }}" | ||
- subnet.hcloud_subnetwork.ip_range == "10.0.0.0/16" | ||
- subnet.hcloud_subnetwork.type == "cloud" | ||
- subnet.hcloud_subnetwork.network_zone == "eu-central" | ||
- result is changed | ||
- result.hcloud_subnetwork.network == "{{ hcloud_network_name }}" | ||
- result.hcloud_subnetwork.network_zone == "eu-central" | ||
- result.hcloud_subnetwork.type == "cloud" | ||
- result.hcloud_subnetwork.ip_range == "10.0.0.0/24" | ||
|
||
- name: test create subnetwork idempotency | ||
- name: Test create idempotency | ||
hetzner.hcloud.hcloud_subnetwork: | ||
network: "{{ hcloud_network_name }}" | ||
ip_range: "10.0.0.0/16" | ||
type: "cloud" | ||
network_zone: "eu-central" | ||
network_zone: eu-central | ||
type: cloud | ||
ip_range: 10.0.0.0/24 | ||
state: present | ||
register: result | ||
- name: verify create subnetwork idempotency | ||
assert: | ||
- name: Verify create idempotency | ||
ansible.builtin.assert: | ||
that: | ||
- result is not changed | ||
|
||
- name: test absent subnetwork | ||
- name: Test delete | ||
hetzner.hcloud.hcloud_subnetwork: | ||
network: "{{ hcloud_network_name }}" | ||
ip_range: "10.0.0.0/16" | ||
type: "cloud" | ||
network_zone: "eu-central" | ||
network_zone: eu-central | ||
type: cloud | ||
ip_range: 10.0.0.0/24 | ||
state: absent | ||
register: result | ||
- name: verify test absent subnetwork | ||
assert: | ||
- name: Verify delete | ||
ansible.builtin.assert: | ||
that: | ||
- result is changed | ||
|
||
- name: test vswitch subnetwork | ||
- name: Test create with vswitch | ||
hetzner.hcloud.hcloud_subnetwork: | ||
network: "{{ hcloud_network_name }}" | ||
ip_range: "10.0.0.0/16" | ||
type: "vswitch" | ||
network_zone: "eu-central" | ||
vswitch_id: "{{ hetzner_vswitch_id }}" | ||
network_zone: eu-central | ||
type: vswitch | ||
ip_range: 10.0.1.0/24 | ||
vswitch_id: "{{ test_vswitch_id }}" | ||
state: present | ||
register: subnet | ||
- name: verify test vswitch subnetwork | ||
assert: | ||
register: result | ||
- name: Verify create with vswitch | ||
ansible.builtin.assert: | ||
that: | ||
- subnet is changed | ||
- subnet.hcloud_subnetwork.network == "{{ hcloud_network_name }}" | ||
- subnet.hcloud_subnetwork.ip_range == "10.0.0.0/16" | ||
- subnet.hcloud_subnetwork.type == "vswitch" | ||
- subnet.hcloud_subnetwork.network_zone == "eu-central" | ||
- subnet.hcloud_subnetwork.vswitch_id == hetzner_vswitch_id | ||
- result is changed | ||
- result.hcloud_subnetwork.network == "{{ hcloud_network_name }}" | ||
- result.hcloud_subnetwork.network_zone == "eu-central" | ||
- result.hcloud_subnetwork.type == "vswitch" | ||
- result.hcloud_subnetwork.ip_range == "10.0.1.0/24" | ||
- result.hcloud_subnetwork.vswitch_id | string == test_vswitch_id | ||
|
||
- name: test absent subnetwork | ||
- name: Test delete with vswitch | ||
hetzner.hcloud.hcloud_subnetwork: | ||
network: "{{ hcloud_network_name }}" | ||
ip_range: "10.0.0.0/16" | ||
type: "vswitch" | ||
network_zone: "eu-central" | ||
vswitch_id: "{{ hetzner_vswitch_id }}" | ||
network_zone: eu-central | ||
type: vswitch | ||
ip_range: 10.0.1.0/24 | ||
state: absent | ||
register: subnet | ||
- name: verify test absent subnetwork | ||
assert: | ||
- name: Verify delete with vswitch | ||
ansible.builtin.assert: | ||
that: | ||
- result is changed | ||
|
||
- name: cleanup | ||
hetzner.hcloud.hcloud_network: | ||
name: "{{hcloud_network_name}}" | ||
state: absent | ||
register: result | ||
- name: verify cleanup | ||
assert: | ||
that: | ||
- result is success |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters