diff --git a/shippable.yml b/shippable.yml index f97e08ae131..f84a5f8cf23 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 ad93e3e1232..8db658dbbf7 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 51742ee23f7..18dc30b6c31 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 51742ee23f7..4b3a9b36f86 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 51742ee23f7..4b3a9b36f86 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 51742ee23f7..18dc30b6c31 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 51742ee23f7..4b3a9b36f86 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 51742ee23f7..18dc30b6c31 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 51742ee23f7..18dc30b6c31 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 51742ee23f7..18dc30b6c31 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 51742ee23f7..4b3a9b36f86 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 51742ee23f7..18dc30b6c31 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 51742ee23f7..4b3a9b36f86 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 7c985d4b9a0..dba35f9e56c 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() + + 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() - return False + 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 b5457a99f17..a466ce6febf 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 00000000000..cbed6aa5778 --- /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 00000000000..700ad3edcff --- /dev/null +++ b/test/utils/shippable/hcloud.sh @@ -0,0 +1 @@ +cloud.sh \ No newline at end of file