From 85ae8f5258f23f2bc049b81599c5533e114f6e02 Mon Sep 17 00:00:00 2001 From: Matt Clay Date: Tue, 9 Apr 2019 13:29:30 -0700 Subject: [PATCH] Add Hetzner Cloud to CI integration tests. --- shippable.yml | 3 + .../cloud-config-hcloud.ini.template | 9 ++- .../targets/hcloud_datacenter_facts/aliases | 2 +- .../targets/hcloud_floating_ip_facts/aliases | 3 +- .../targets/hcloud_image_facts/aliases | 3 +- .../targets/hcloud_location_facts/aliases | 2 +- .../integration/targets/hcloud_server/aliases | 3 +- .../targets/hcloud_server_facts/aliases | 2 +- .../targets/hcloud_server_type_facts/aliases | 2 +- .../targets/hcloud_ssh_key/aliases | 2 +- .../targets/hcloud_ssh_key_facts/aliases | 3 +- .../integration/targets/hcloud_volume/aliases | 2 +- .../targets/hcloud_volume_facts/aliases | 3 +- test/runner/lib/cloud/hcloud.py | 57 ++++++++++++++++--- test/runner/lib/core_ci.py | 1 + .../requirements/integration.cloud.hcloud.txt | 1 + test/utils/shippable/hcloud.sh | 1 + 17 files changed, 78 insertions(+), 21 deletions(-) create mode 100644 test/runner/requirements/integration.cloud.hcloud.txt create mode 120000 test/utils/shippable/hcloud.sh diff --git a/shippable.yml b/shippable.yml index f97e08ae13..f84a5f8cf2 100644 --- a/shippable.yml +++ b/shippable.yml @@ -161,6 +161,9 @@ matrix: - env: T=cloud/2.7/1 - env: T=cloud/3.6/1 + + - env: T=hcloud/2.7/1 + - env: T=hcloud/3.6/1 branches: except: - "*-patch-*" diff --git a/test/integration/cloud-config-hcloud.ini.template b/test/integration/cloud-config-hcloud.ini.template index ad93e3e123..8db658dbbf 100644 --- a/test/integration/cloud-config-hcloud.ini.template +++ b/test/integration/cloud-config-hcloud.ini.template @@ -3,10 +3,13 @@ # You do not need this template if you are: # # 1) Running integration tests without using ansible-test. +# 2) Using the automatically provisioned Hetzner Cloud credentials in ansible-test. # -# If you want to test against the Hetzner Cloud public API, -# fill in the values below and save this file without the .template extension. -# This will cause ansible-test to use the given configuration. +# If you do not want to use the automatically provisioned temporary Hetzner Cloud credentials, +# fill in the @VAR placeholders below and save this file without the .template extension. +# This will cause ansible-test to use the given configuration instead of temporary credentials. +# +# NOTE: Automatic provisioning of Hetzner Cloud credentials requires an ansible-core-ci API key. [default] hcloud_api_token= @TOKEN diff --git a/test/integration/targets/hcloud_datacenter_facts/aliases b/test/integration/targets/hcloud_datacenter_facts/aliases index 51742ee23f..18dc30b6c3 100644 --- a/test/integration/targets/hcloud_datacenter_facts/aliases +++ b/test/integration/targets/hcloud_datacenter_facts/aliases @@ -1,2 +1,2 @@ cloud/hcloud -unsupported +shippable/hcloud/group1 diff --git a/test/integration/targets/hcloud_floating_ip_facts/aliases b/test/integration/targets/hcloud_floating_ip_facts/aliases index 51742ee23f..4b3a9b36f8 100644 --- a/test/integration/targets/hcloud_floating_ip_facts/aliases +++ b/test/integration/targets/hcloud_floating_ip_facts/aliases @@ -1,2 +1,3 @@ cloud/hcloud -unsupported +shippable/hcloud/group1 +disabled diff --git a/test/integration/targets/hcloud_image_facts/aliases b/test/integration/targets/hcloud_image_facts/aliases index 51742ee23f..4b3a9b36f8 100644 --- a/test/integration/targets/hcloud_image_facts/aliases +++ b/test/integration/targets/hcloud_image_facts/aliases @@ -1,2 +1,3 @@ cloud/hcloud -unsupported +shippable/hcloud/group1 +disabled diff --git a/test/integration/targets/hcloud_location_facts/aliases b/test/integration/targets/hcloud_location_facts/aliases index 51742ee23f..18dc30b6c3 100644 --- a/test/integration/targets/hcloud_location_facts/aliases +++ b/test/integration/targets/hcloud_location_facts/aliases @@ -1,2 +1,2 @@ cloud/hcloud -unsupported +shippable/hcloud/group1 diff --git a/test/integration/targets/hcloud_server/aliases b/test/integration/targets/hcloud_server/aliases index 51742ee23f..4b3a9b36f8 100644 --- a/test/integration/targets/hcloud_server/aliases +++ b/test/integration/targets/hcloud_server/aliases @@ -1,2 +1,3 @@ cloud/hcloud -unsupported +shippable/hcloud/group1 +disabled diff --git a/test/integration/targets/hcloud_server_facts/aliases b/test/integration/targets/hcloud_server_facts/aliases index 51742ee23f..18dc30b6c3 100644 --- a/test/integration/targets/hcloud_server_facts/aliases +++ b/test/integration/targets/hcloud_server_facts/aliases @@ -1,2 +1,2 @@ cloud/hcloud -unsupported +shippable/hcloud/group1 diff --git a/test/integration/targets/hcloud_server_type_facts/aliases b/test/integration/targets/hcloud_server_type_facts/aliases index 51742ee23f..18dc30b6c3 100644 --- a/test/integration/targets/hcloud_server_type_facts/aliases +++ b/test/integration/targets/hcloud_server_type_facts/aliases @@ -1,2 +1,2 @@ cloud/hcloud -unsupported +shippable/hcloud/group1 diff --git a/test/integration/targets/hcloud_ssh_key/aliases b/test/integration/targets/hcloud_ssh_key/aliases index 51742ee23f..18dc30b6c3 100644 --- a/test/integration/targets/hcloud_ssh_key/aliases +++ b/test/integration/targets/hcloud_ssh_key/aliases @@ -1,2 +1,2 @@ cloud/hcloud -unsupported +shippable/hcloud/group1 diff --git a/test/integration/targets/hcloud_ssh_key_facts/aliases b/test/integration/targets/hcloud_ssh_key_facts/aliases index 51742ee23f..4b3a9b36f8 100644 --- a/test/integration/targets/hcloud_ssh_key_facts/aliases +++ b/test/integration/targets/hcloud_ssh_key_facts/aliases @@ -1,2 +1,3 @@ cloud/hcloud -unsupported +shippable/hcloud/group1 +disabled diff --git a/test/integration/targets/hcloud_volume/aliases b/test/integration/targets/hcloud_volume/aliases index 51742ee23f..18dc30b6c3 100644 --- a/test/integration/targets/hcloud_volume/aliases +++ b/test/integration/targets/hcloud_volume/aliases @@ -1,2 +1,2 @@ cloud/hcloud -unsupported +shippable/hcloud/group1 diff --git a/test/integration/targets/hcloud_volume_facts/aliases b/test/integration/targets/hcloud_volume_facts/aliases index 51742ee23f..4b3a9b36f8 100644 --- a/test/integration/targets/hcloud_volume_facts/aliases +++ b/test/integration/targets/hcloud_volume_facts/aliases @@ -1,2 +1,3 @@ cloud/hcloud -unsupported +shippable/hcloud/group1 +disabled diff --git a/test/runner/lib/cloud/hcloud.py b/test/runner/lib/cloud/hcloud.py index 7c985d4b9a..dba35f9e56 100644 --- a/test/runner/lib/cloud/hcloud.py +++ b/test/runner/lib/cloud/hcloud.py @@ -1,7 +1,13 @@ """Hetzner Cloud plugin for integration tests.""" from __future__ import absolute_import, print_function -from os.path import isfile +import os + +from lib.util import ( + display, + is_shippable, + ConfigParser, +) from lib.cloud import ( CloudProvider, @@ -9,7 +15,9 @@ from lib.cloud import ( CloudEnvironmentConfig, ) -from lib.util import ConfigParser, display +from lib.core_ci import ( + AnsibleCoreCI, +) class HcloudCloudProvider(CloudProvider): @@ -28,7 +36,15 @@ class HcloudCloudProvider(CloudProvider): :type targets: tuple[TestTarget] :type exclude: list[str] """ - if isfile(self.config_static_path): + if os.path.isfile(self.config_static_path): + return + + aci = self._create_ansible_core_ci() + + if os.path.isfile(aci.ci_key): + return + + if is_shippable(): return super(HcloudCloudProvider, self).filter(targets, exclude) @@ -37,11 +53,38 @@ class HcloudCloudProvider(CloudProvider): """Setup the cloud resource before delegation and register a cleanup callback.""" super(HcloudCloudProvider, self).setup() - if isfile(self.config_static_path): - self.config_path = self.config_static_path - return True + if not self._use_static_config(): + self._setup_dynamic() - return False + def _setup_dynamic(self): + """Request Hetzner credentials through the Ansible Core CI service.""" + display.info('Provisioning %s cloud environment.' % self.platform, verbosity=1) + + config = self._read_config_template() + + aci = self._create_ansible_core_ci() + + response = aci.start() + + if not self.args.explain: + token = response['hetzner']['token'] + + display.sensitive.add(token) + display.info('Hetzner Cloud Token: %s' % token, verbosity=1) + + values = dict( + TOKEN=token, + ) + + config = self._populate_config_template(config, values) + + self._write_config(config) + + def _create_ansible_core_ci(self): + """ + :rtype: AnsibleCoreCI + """ + return AnsibleCoreCI(self.args, 'hetzner', 'hetzner', persist=False, stage=self.args.remote_stage, provider=self.args.remote_provider) class HcloudCloudEnvironment(CloudEnvironment): diff --git a/test/runner/lib/core_ci.py b/test/runner/lib/core_ci.py index b5457a99f1..a466ce6feb 100644 --- a/test/runner/lib/core_ci.py +++ b/test/runner/lib/core_ci.py @@ -71,6 +71,7 @@ class AnsibleCoreCI(object): 'ios', 'tower', 'rhel', + 'hetzner', ), azure=( 'azure', diff --git a/test/runner/requirements/integration.cloud.hcloud.txt b/test/runner/requirements/integration.cloud.hcloud.txt new file mode 100644 index 0000000000..cbed6aa577 --- /dev/null +++ b/test/runner/requirements/integration.cloud.hcloud.txt @@ -0,0 +1 @@ +hcloud diff --git a/test/utils/shippable/hcloud.sh b/test/utils/shippable/hcloud.sh new file mode 120000 index 0000000000..700ad3edcf --- /dev/null +++ b/test/utils/shippable/hcloud.sh @@ -0,0 +1 @@ +cloud.sh \ No newline at end of file