test: setup new temporary project service for integration tests (#316)

##### SUMMARY

Setup new temporary project service for integration tests.

- Use the hc-integrations-test.de domain for certificates creation
- Use new Hetzner account vSwitch
- Use new Hetzner account server IP
- Create snapshots during setup (instead of "always-there-snapshot")
This commit is contained in:
Jonas L 2023-09-08 09:37:43 +02:00 committed by GitHub
parent a953b12c5c
commit 62ab0570c8
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
10 changed files with 58 additions and 10 deletions

View file

@ -2,4 +2,4 @@
# 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_certificate_name: "{{ hcloud_ns }}" hcloud_certificate_name: "{{ hcloud_ns }}"
hcloud_dns_test_domain: "{{ hcloud_ns }}-{{ 100 | random }}.hc-certs.de" hcloud_dns_test_domain: "{{ (hcloud_ns + 100 | random | string) | md5 }}.hc-integrations-test.de"

View file

@ -1,6 +1,6 @@
# 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)
--- ---
hcloud_snapshot_id: 10164049 hcloud_server_name: "{{ hcloud_ns }}"
hcloud_snapshot_name: always-there-snapshot hcloud_snapshot_name: "{{ hcloud_ns }}"
hcloud_image_name: ubuntu-22.04 hcloud_image_name: ubuntu-22.04

View file

@ -0,0 +1,3 @@
---
dependencies:
- setup_hcloud_cli

View file

@ -0,0 +1,5 @@
---
- name: Cleanup test_server
hetzner.hcloud.hcloud_server:
name: "{{ hcloud_server_name }}"
state: absent

View file

@ -0,0 +1,23 @@
---
- name: Create test_server
hetzner.hcloud.hcloud_server:
name: "{{ hcloud_server_name }}"
server_type: cx11
image: ubuntu-22.04
state: stopped
register: test_server
- name: Create test_snapshot
ansible.builtin.script:
cmd: >
{{ hcloud_cli_path }} server create-image
--type snapshot
--description "{{ hcloud_snapshot_name }}"
--label key=value
"{{ test_server.hcloud_server.id }}"
| awk '{print $2}'
register: test_snapshot
- name: Set test_snapshot_id
ansible.builtin.set_fact:
test_snapshot_id: "{{ test_snapshot.stdout_lines[0] }}"

View file

@ -30,7 +30,7 @@
- name: Gather hcloud_image_info with correct id - name: Gather hcloud_image_info with correct id
hetzner.hcloud.hcloud_image_info: hetzner.hcloud.hcloud_image_info:
id: "{{ hcloud_snapshot_id }}" id: "{{ test_snapshot_id }}"
type: snapshot type: snapshot
register: result register: result
- name: Verify hcloud_image_info with correct id - name: Verify hcloud_image_info with correct id
@ -40,7 +40,7 @@
- name: Gather hcloud_image_info with wrong id - name: Gather hcloud_image_info with wrong id
hetzner.hcloud.hcloud_image_info: hetzner.hcloud.hcloud_image_info:
id: "{{ hcloud_snapshot_id }}4321" id: "{{ test_snapshot_id }}4321"
type: snapshot type: snapshot
ignore_errors: true ignore_errors: true
register: result register: result

View file

@ -3,4 +3,5 @@
--- ---
hcloud_server_name: "{{ hcloud_ns }}" hcloud_server_name: "{{ hcloud_ns }}"
hcloud_load_balancer_name: "{{ hcloud_ns }}" hcloud_load_balancer_name: "{{ hcloud_ns }}"
hcloud_testing_ip: "176.9.59.39"
hetzner_server_ip: 142.132.203.104

View file

@ -122,8 +122,8 @@
- name: test create ip target - name: test create ip target
hetzner.hcloud.hcloud_load_balancer_target: hetzner.hcloud.hcloud_load_balancer_target:
type: "ip" type: "ip"
load_balancer: "{{hcloud_load_balancer_name}}" load_balancer: "{{ hcloud_load_balancer_name }}"
ip: "{{hcloud_testing_ip}}" ip: "{{ hetzner_server_ip }}"
state: present state: present
register: load_balancer_target register: load_balancer_target
- name: verify create ip target - name: verify create ip target
@ -131,7 +131,7 @@
that: that:
- load_balancer_target is changed - load_balancer_target is changed
- load_balancer_target.hcloud_load_balancer_target.type == "ip" - load_balancer_target.hcloud_load_balancer_target.type == "ip"
- load_balancer_target.hcloud_load_balancer_target.ip == hcloud_testing_ip - load_balancer_target.hcloud_load_balancer_target.ip == hetzner_server_ip
- load_balancer_target.hcloud_load_balancer_target.load_balancer == hcloud_load_balancer_name - load_balancer_target.hcloud_load_balancer_target.load_balancer == hcloud_load_balancer_name
- name: cleanup load_balancer - name: cleanup load_balancer

View file

@ -2,4 +2,4 @@
# 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: 15311 hetzner_vswitch_id: 43065

View file

@ -0,0 +1,16 @@
---
- name: Create temporary file for hcloud_cli_path
ansible.builtin.tempfile:
state: directory
register: _tmp_hcloud_cli
- name: Download hcloud cli from Github releases
ansible.builtin.unarchive:
src: https://github.com/hetznercloud/cli/releases/download/v1.37.0/hcloud-linux-amd64.tar.gz
dest: "{{ _tmp_hcloud_cli.path }}"
remote_src: true
extra_opts: [hcloud]
- name: Set hcloud_cli_path
ansible.builtin.set_fact:
hcloud_cli_path: "{{ _tmp_hcloud_cli.path }}/hcloud"