Skip to content

Commit

Permalink
Add Hetzner Cloud to CI integration tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
mattclay committed Apr 9, 2019
1 parent 16c4df4 commit 85ae8f5
Show file tree
Hide file tree
Showing 17 changed files with 78 additions and 21 deletions.
3 changes: 3 additions & 0 deletions shippable.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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-*"
Expand Down
9 changes: 6 additions & 3 deletions test/integration/cloud-config-hcloud.ini.template
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 1 addition & 1 deletion test/integration/targets/hcloud_datacenter_facts/aliases
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
cloud/hcloud
unsupported
shippable/hcloud/group1
3 changes: 2 additions & 1 deletion test/integration/targets/hcloud_floating_ip_facts/aliases
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
cloud/hcloud
unsupported
shippable/hcloud/group1
disabled
3 changes: 2 additions & 1 deletion test/integration/targets/hcloud_image_facts/aliases
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
cloud/hcloud
unsupported
shippable/hcloud/group1
disabled
2 changes: 1 addition & 1 deletion test/integration/targets/hcloud_location_facts/aliases
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
cloud/hcloud
unsupported
shippable/hcloud/group1
3 changes: 2 additions & 1 deletion test/integration/targets/hcloud_server/aliases
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
cloud/hcloud
unsupported
shippable/hcloud/group1
disabled
2 changes: 1 addition & 1 deletion test/integration/targets/hcloud_server_facts/aliases
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
cloud/hcloud
unsupported
shippable/hcloud/group1
2 changes: 1 addition & 1 deletion test/integration/targets/hcloud_server_type_facts/aliases
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
cloud/hcloud
unsupported
shippable/hcloud/group1
2 changes: 1 addition & 1 deletion test/integration/targets/hcloud_ssh_key/aliases
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
cloud/hcloud
unsupported
shippable/hcloud/group1
3 changes: 2 additions & 1 deletion test/integration/targets/hcloud_ssh_key_facts/aliases
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
cloud/hcloud
unsupported
shippable/hcloud/group1
disabled
2 changes: 1 addition & 1 deletion test/integration/targets/hcloud_volume/aliases
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
cloud/hcloud
unsupported
shippable/hcloud/group1
3 changes: 2 additions & 1 deletion test/integration/targets/hcloud_volume_facts/aliases
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
cloud/hcloud
unsupported
shippable/hcloud/group1
disabled
57 changes: 50 additions & 7 deletions test/runner/lib/cloud/hcloud.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,23 @@
"""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,
CloudEnvironment,
CloudEnvironmentConfig,
)

from lib.util import ConfigParser, display
from lib.core_ci import (
AnsibleCoreCI,
)


class HcloudCloudProvider(CloudProvider):
Expand All @@ -28,7 +36,15 @@ def filter(self, targets, exclude):
: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)
Expand All @@ -37,11 +53,38 @@ def setup(self):
"""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):
Expand Down
1 change: 1 addition & 0 deletions test/runner/lib/core_ci.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ def __init__(self, args, platform, version, stage='prod', persist=True, load=Tru
'ios',
'tower',
'rhel',
'hetzner',
),
azure=(
'azure',
Expand Down
1 change: 1 addition & 0 deletions test/runner/requirements/integration.cloud.hcloud.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
hcloud
1 change: 1 addition & 0 deletions test/utils/shippable/hcloud.sh

0 comments on commit 85ae8f5

Please sign in to comment.