mirror of
https://github.com/ansible-collections/hetzner.hcloud
synced 2024-11-10 06:34:13 +00:00
test: fix vswitch subnets ip_range (#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.
This commit is contained in:
parent
76ef636f07
commit
4044980477
7 changed files with 102 additions and 91 deletions
|
@ -20,7 +20,6 @@ exclude_paths:
|
||||||
- tests/integration/targets/hcloud_server
|
- tests/integration/targets/hcloud_server
|
||||||
- tests/integration/targets/hcloud_server_network
|
- tests/integration/targets/hcloud_server_network
|
||||||
- tests/integration/targets/hcloud_ssh_key
|
- tests/integration/targets/hcloud_ssh_key
|
||||||
- tests/integration/targets/hcloud_subnetwork
|
|
||||||
- tests/integration/targets/hcloud_volume
|
- tests/integration/targets/hcloud_volume
|
||||||
- tests/integration/targets/setup_selfsigned_certificate
|
- tests/integration/targets/setup_selfsigned_certificate
|
||||||
- tests/integration/targets/setup_ssh_keypair
|
- tests/integration/targets/setup_ssh_keypair
|
||||||
|
|
|
@ -2,4 +2,22 @@
|
||||||
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
|
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
|
||||||
---
|
---
|
||||||
hcloud_network_name: "{{ hcloud_ns }}"
|
hcloud_network_name: "{{ hcloud_ns }}"
|
||||||
hetzner_vswitch_id: 43065
|
# Pool of external Hetzner vSwitch ID, this prevents using the same vSwitch id twice in
|
||||||
|
# different jobs.
|
||||||
|
hetzner_vswitch_ids:
|
||||||
|
- 43065
|
||||||
|
- 44166
|
||||||
|
- 44167
|
||||||
|
- 44168
|
||||||
|
- 44170
|
||||||
|
- 44171
|
||||||
|
- 44172
|
||||||
|
- 44173
|
||||||
|
- 44174
|
||||||
|
- 44175
|
||||||
|
- 44176
|
||||||
|
- 44177
|
||||||
|
- 44178
|
||||||
|
- 44179
|
||||||
|
- 44180
|
||||||
|
- 44181
|
||||||
|
|
|
@ -0,0 +1,5 @@
|
||||||
|
---
|
||||||
|
- name: Cleanup test_network
|
||||||
|
hetzner.hcloud.hcloud_network:
|
||||||
|
name: "{{ hcloud_network_name }}"
|
||||||
|
state: absent
|
|
@ -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 }}"
|
|
@ -1,125 +1,103 @@
|
||||||
# Copyright: (c) 2019, Hetzner Cloud GmbH <info@hetzner-cloud.de>
|
# 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)
|
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
|
||||||
---
|
---
|
||||||
- name: setup
|
- name: Test missing required parameters
|
||||||
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
|
|
||||||
hetzner.hcloud.hcloud_subnetwork:
|
hetzner.hcloud.hcloud_subnetwork:
|
||||||
network: "{{ hcloud_network_name }}"
|
network: "{{ hcloud_network_name }}"
|
||||||
state: present
|
state: present
|
||||||
register: result
|
|
||||||
ignore_errors: true
|
ignore_errors: true
|
||||||
- name: verify fail test missing required parameters on create route
|
register: result
|
||||||
assert:
|
- name: Verify missing required parameters
|
||||||
|
ansible.builtin.assert:
|
||||||
that:
|
that:
|
||||||
- result is failed
|
- result is failed
|
||||||
- 'result.msg == "missing required arguments: ip_range, network_zone, type"'
|
- '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:
|
hetzner.hcloud.hcloud_subnetwork:
|
||||||
network: "{{ hcloud_network_name }}"
|
network: "{{ hcloud_network_name }}"
|
||||||
ip_range: "10.0.0.0/16"
|
network_zone: eu-central
|
||||||
type: "server"
|
type: cloud
|
||||||
network_zone: "eu-central"
|
ip_range: 10.0.0.0/24
|
||||||
state: present
|
state: present
|
||||||
register: result
|
|
||||||
check_mode: true
|
check_mode: true
|
||||||
- name: verify test create subnetwork with checkmode
|
register: result
|
||||||
assert:
|
- name: Verify create with checkmode
|
||||||
|
ansible.builtin.assert:
|
||||||
that:
|
that:
|
||||||
- result is changed
|
- result is changed
|
||||||
|
|
||||||
- name: test create subnetwork
|
- name: Test create
|
||||||
hetzner.hcloud.hcloud_subnetwork:
|
hetzner.hcloud.hcloud_subnetwork:
|
||||||
network: "{{ hcloud_network_name }}"
|
network: "{{ hcloud_network_name }}"
|
||||||
ip_range: "10.0.0.0/16"
|
network_zone: eu-central
|
||||||
type: "cloud"
|
type: cloud
|
||||||
network_zone: "eu-central"
|
ip_range: 10.0.0.0/24
|
||||||
state: present
|
|
||||||
register: subnet
|
|
||||||
- name: verify create subnetwork
|
|
||||||
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"
|
|
||||||
|
|
||||||
- name: test create subnetwork idempotency
|
|
||||||
hetzner.hcloud.hcloud_subnetwork:
|
|
||||||
network: "{{ hcloud_network_name }}"
|
|
||||||
ip_range: "10.0.0.0/16"
|
|
||||||
type: "cloud"
|
|
||||||
network_zone: "eu-central"
|
|
||||||
state: present
|
state: present
|
||||||
register: result
|
register: result
|
||||||
- name: verify create subnetwork idempotency
|
- name: Verify create
|
||||||
assert:
|
ansible.builtin.assert:
|
||||||
|
that:
|
||||||
|
- 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 idempotency
|
||||||
|
hetzner.hcloud.hcloud_subnetwork:
|
||||||
|
network: "{{ hcloud_network_name }}"
|
||||||
|
network_zone: eu-central
|
||||||
|
type: cloud
|
||||||
|
ip_range: 10.0.0.0/24
|
||||||
|
state: present
|
||||||
|
register: result
|
||||||
|
- name: Verify create idempotency
|
||||||
|
ansible.builtin.assert:
|
||||||
that:
|
that:
|
||||||
- result is not changed
|
- result is not changed
|
||||||
|
|
||||||
- name: test absent subnetwork
|
- name: Test delete
|
||||||
hetzner.hcloud.hcloud_subnetwork:
|
hetzner.hcloud.hcloud_subnetwork:
|
||||||
network: "{{ hcloud_network_name }}"
|
network: "{{ hcloud_network_name }}"
|
||||||
ip_range: "10.0.0.0/16"
|
network_zone: eu-central
|
||||||
type: "cloud"
|
type: cloud
|
||||||
network_zone: "eu-central"
|
ip_range: 10.0.0.0/24
|
||||||
state: absent
|
state: absent
|
||||||
register: result
|
register: result
|
||||||
- name: verify test absent subnetwork
|
- name: Verify delete
|
||||||
assert:
|
ansible.builtin.assert:
|
||||||
that:
|
that:
|
||||||
- result is changed
|
- result is changed
|
||||||
|
|
||||||
- name: test vswitch subnetwork
|
- name: Test create with vswitch
|
||||||
hetzner.hcloud.hcloud_subnetwork:
|
hetzner.hcloud.hcloud_subnetwork:
|
||||||
network: "{{ hcloud_network_name }}"
|
network: "{{ hcloud_network_name }}"
|
||||||
ip_range: "10.0.0.0/16"
|
network_zone: eu-central
|
||||||
type: "vswitch"
|
type: vswitch
|
||||||
network_zone: "eu-central"
|
ip_range: 10.0.1.0/24
|
||||||
vswitch_id: "{{ hetzner_vswitch_id }}"
|
vswitch_id: "{{ test_vswitch_id }}"
|
||||||
state: present
|
state: present
|
||||||
register: subnet
|
register: result
|
||||||
- name: verify test vswitch subnetwork
|
- name: Verify create with vswitch
|
||||||
assert:
|
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
|
|
||||||
|
|
||||||
- name: test absent subnetwork
|
|
||||||
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 }}"
|
|
||||||
state: absent
|
|
||||||
register: subnet
|
|
||||||
- name: verify test absent subnetwork
|
|
||||||
assert:
|
|
||||||
that:
|
that:
|
||||||
- result is changed
|
- 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: cleanup
|
- name: Test delete with vswitch
|
||||||
hetzner.hcloud.hcloud_network:
|
hetzner.hcloud.hcloud_subnetwork:
|
||||||
name: "{{hcloud_network_name}}"
|
network: "{{ hcloud_network_name }}"
|
||||||
|
network_zone: eu-central
|
||||||
|
type: vswitch
|
||||||
|
ip_range: 10.0.1.0/24
|
||||||
state: absent
|
state: absent
|
||||||
register: result
|
register: subnet
|
||||||
- name: verify cleanup
|
- name: Verify delete with vswitch
|
||||||
assert:
|
ansible.builtin.assert:
|
||||||
that:
|
that:
|
||||||
- result is success
|
- result is changed
|
||||||
|
|
|
@ -36,7 +36,7 @@ test_group="${entry_point_args[3]:-}"
|
||||||
export PYTHONIOENCODING="utf-8"
|
export PYTHONIOENCODING="utf-8"
|
||||||
export PIP_DISABLE_PIP_VERSION_CHECK=true
|
export PIP_DISABLE_PIP_VERSION_CHECK=true
|
||||||
export PIP_NO_WARN_SCRIPT_LOCATION=false # Negative options are a bit weird: https://pip.pypa.io/en/stable/topics/configuration/#boolean-options
|
export PIP_NO_WARN_SCRIPT_LOCATION=false # Negative options are a bit weird: https://pip.pypa.io/en/stable/topics/configuration/#boolean-options
|
||||||
export ANSIBLE_COLLECTIONS_PATHS="$PWD/../.."
|
export ANSIBLE_COLLECTIONS_PATH="$PWD/../.."
|
||||||
|
|
||||||
command -v python
|
command -v python
|
||||||
python -V
|
python -V
|
||||||
|
@ -82,7 +82,7 @@ fi
|
||||||
pip install rstcheck
|
pip install rstcheck
|
||||||
|
|
||||||
# Ensure we can write other collections to this dir
|
# Ensure we can write other collections to this dir
|
||||||
sudo chown "$(whoami)" "$ANSIBLE_COLLECTIONS_PATHS"
|
sudo chown "$(whoami)" "$ANSIBLE_COLLECTIONS_PATH"
|
||||||
|
|
||||||
pip install -r tests/integration/requirements.txt -c tests/constraints.txt
|
pip install -r tests/integration/requirements.txt -c tests/constraints.txt
|
||||||
ansible-galaxy -vvv collection install -r tests/requirements.yml
|
ansible-galaxy -vvv collection install -r tests/requirements.yml
|
||||||
|
|
|
@ -44,10 +44,10 @@ if [ "${ansible_version}" == "devel" ]; then
|
||||||
else
|
else
|
||||||
retry pip install "https://github.com/ansible/ansible/archive/stable-${ansible_version}.tar.gz" --disable-pip-version-check
|
retry pip install "https://github.com/ansible/ansible/archive/stable-${ansible_version}.tar.gz" --disable-pip-version-check
|
||||||
fi
|
fi
|
||||||
export ANSIBLE_COLLECTIONS_PATHS="${HOME}/.ansible"
|
export ANSIBLE_COLLECTIONS_PATH="${HOME}/.ansible"
|
||||||
# shellcheck disable=SC2034
|
# shellcheck disable=SC2034
|
||||||
SHIPPABLE_RESULT_DIR="$(pwd)/shippable"
|
SHIPPABLE_RESULT_DIR="$(pwd)/shippable"
|
||||||
TEST_DIR="${ANSIBLE_COLLECTIONS_PATHS}/ansible_collections/hetzner/hcloud"
|
TEST_DIR="${ANSIBLE_COLLECTIONS_PATH}/ansible_collections/hetzner/hcloud"
|
||||||
rm -rf "${TEST_DIR}"
|
rm -rf "${TEST_DIR}"
|
||||||
mkdir -p "${TEST_DIR}"
|
mkdir -p "${TEST_DIR}"
|
||||||
cp -r "." "${TEST_DIR}"
|
cp -r "." "${TEST_DIR}"
|
||||||
|
|
Loading…
Reference in a new issue