Add Hetzner Cloud to CI integration tests.

pull/55063/head
Matt Clay 6 years ago
parent 16c4df439a
commit 85ae8f5258

@ -161,6 +161,9 @@ matrix:
- env: T=cloud/2.7/1 - env: T=cloud/2.7/1
- env: T=cloud/3.6/1 - env: T=cloud/3.6/1
- env: T=hcloud/2.7/1
- env: T=hcloud/3.6/1
branches: branches:
except: except:
- "*-patch-*" - "*-patch-*"

@ -3,10 +3,13 @@
# You do not need this template if you are: # You do not need this template if you are:
# #
# 1) Running integration tests without using ansible-test. # 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, # If you do not want to use the automatically provisioned temporary Hetzner Cloud credentials,
# fill in the values below and save this file without the .template extension. # fill in the @VAR placeholders below and save this file without the .template extension.
# This will cause ansible-test to use the given configuration. # 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] [default]
hcloud_api_token= @TOKEN hcloud_api_token= @TOKEN

@ -1,2 +1,2 @@
cloud/hcloud cloud/hcloud
unsupported shippable/hcloud/group1

@ -1,2 +1,3 @@
cloud/hcloud cloud/hcloud
unsupported shippable/hcloud/group1
disabled

@ -1,2 +1,3 @@
cloud/hcloud cloud/hcloud
unsupported shippable/hcloud/group1
disabled

@ -1,2 +1,2 @@
cloud/hcloud cloud/hcloud
unsupported shippable/hcloud/group1

@ -1,2 +1,3 @@
cloud/hcloud cloud/hcloud
unsupported shippable/hcloud/group1
disabled

@ -1,2 +1,2 @@
cloud/hcloud cloud/hcloud
unsupported shippable/hcloud/group1

@ -1,2 +1,2 @@
cloud/hcloud cloud/hcloud
unsupported shippable/hcloud/group1

@ -1,2 +1,2 @@
cloud/hcloud cloud/hcloud
unsupported shippable/hcloud/group1

@ -1,2 +1,3 @@
cloud/hcloud cloud/hcloud
unsupported shippable/hcloud/group1
disabled

@ -1,2 +1,2 @@
cloud/hcloud cloud/hcloud
unsupported shippable/hcloud/group1

@ -1,2 +1,3 @@
cloud/hcloud cloud/hcloud
unsupported shippable/hcloud/group1
disabled

@ -1,7 +1,13 @@
"""Hetzner Cloud plugin for integration tests.""" """Hetzner Cloud plugin for integration tests."""
from __future__ import absolute_import, print_function 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 ( from lib.cloud import (
CloudProvider, CloudProvider,
@ -9,7 +15,9 @@ from lib.cloud import (
CloudEnvironmentConfig, CloudEnvironmentConfig,
) )
from lib.util import ConfigParser, display from lib.core_ci import (
AnsibleCoreCI,
)
class HcloudCloudProvider(CloudProvider): class HcloudCloudProvider(CloudProvider):
@ -28,7 +36,15 @@ class HcloudCloudProvider(CloudProvider):
:type targets: tuple[TestTarget] :type targets: tuple[TestTarget]
:type exclude: list[str] :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 return
super(HcloudCloudProvider, self).filter(targets, exclude) super(HcloudCloudProvider, self).filter(targets, exclude)
@ -37,11 +53,38 @@ class HcloudCloudProvider(CloudProvider):
"""Setup the cloud resource before delegation and register a cleanup callback.""" """Setup the cloud resource before delegation and register a cleanup callback."""
super(HcloudCloudProvider, self).setup() super(HcloudCloudProvider, self).setup()
if isfile(self.config_static_path): if not self._use_static_config():
self.config_path = self.config_static_path self._setup_dynamic()
return True
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): class HcloudCloudEnvironment(CloudEnvironment):

@ -71,6 +71,7 @@ class AnsibleCoreCI(object):
'ios', 'ios',
'tower', 'tower',
'rhel', 'rhel',
'hetzner',
), ),
azure=( azure=(
'azure', 'azure',

Loading…
Cancel
Save