mirror of
https://github.com/ansible-collections/community.general.git
synced 2026-05-06 13:22:48 +00:00
Overhaul ansible-test cloud test plugins. (#53044)
This commit is contained in:
@@ -253,7 +253,7 @@ class CloudProvider(CloudBase):
|
||||
"""Base class for cloud provider plugins. Sets up cloud resources before delegation."""
|
||||
TEST_DIR = 'test/integration'
|
||||
|
||||
def __init__(self, args, config_extension='.yml'):
|
||||
def __init__(self, args, config_extension='.ini'):
|
||||
"""
|
||||
:type args: IntegrationConfig
|
||||
:type config_extension: str
|
||||
@@ -390,10 +390,9 @@ class CloudEnvironment(CloudBase):
|
||||
pass
|
||||
|
||||
@abc.abstractmethod
|
||||
def configure_environment(self, env, cmd):
|
||||
"""Configuration which should be done once for each test target.
|
||||
:type env: dict[str, str]
|
||||
:type cmd: list[str]
|
||||
def get_environment_config(self):
|
||||
"""
|
||||
:rtype: CloudEnvironmentConfig
|
||||
"""
|
||||
pass
|
||||
|
||||
@@ -404,9 +403,17 @@ class CloudEnvironment(CloudBase):
|
||||
"""
|
||||
pass
|
||||
|
||||
@property
|
||||
def inventory_hosts(self):
|
||||
|
||||
class CloudEnvironmentConfig(object):
|
||||
"""Configuration for the environment."""
|
||||
def __init__(self, env_vars=None, ansible_vars=None, module_defaults=None, callback_plugins=None):
|
||||
"""
|
||||
:rtype: str | None
|
||||
:type env_vars: dict[str, str] | None
|
||||
:type ansible_vars: dict[str, any] | None
|
||||
:type module_defaults: dict[str, dict[str, any]] | None
|
||||
:type callback_plugins: list[str] | None
|
||||
"""
|
||||
return None
|
||||
self.env_vars = env_vars
|
||||
self.ansible_vars = ansible_vars
|
||||
self.module_defaults = module_defaults
|
||||
self.callback_plugins = callback_plugins
|
||||
|
||||
@@ -7,6 +7,7 @@ import time
|
||||
from lib.cloud import (
|
||||
CloudProvider,
|
||||
CloudEnvironment,
|
||||
CloudEnvironmentConfig,
|
||||
)
|
||||
|
||||
from lib.util import (
|
||||
@@ -37,7 +38,7 @@ class ACMEProvider(CloudProvider):
|
||||
"""
|
||||
:type args: TestConfig
|
||||
"""
|
||||
super(ACMEProvider, self).__init__(args, config_extension='.ini')
|
||||
super(ACMEProvider, self).__init__(args)
|
||||
|
||||
# The simulator must be pinned to a specific version to guarantee CI passes with the version used.
|
||||
if os.environ.get('ANSIBLE_ACME_CONTAINER'):
|
||||
@@ -175,12 +176,14 @@ class ACMEProvider(CloudProvider):
|
||||
|
||||
class ACMEEnvironment(CloudEnvironment):
|
||||
"""ACME environment plugin. Updates integration test environment after delegation."""
|
||||
def configure_environment(self, env, cmd):
|
||||
def get_environment_config(self):
|
||||
"""
|
||||
:type env: dict[str, str]
|
||||
:type cmd: list[str]
|
||||
:rtype: CloudEnvironmentConfig
|
||||
"""
|
||||
ansible_vars = dict(
|
||||
acme_host=self._get_cloud_config('acme_host'),
|
||||
)
|
||||
|
||||
# Send the container IP down to the integration test(s)
|
||||
cmd.append('-e')
|
||||
cmd.append('acme_host=%s' % self._get_cloud_config('acme_host'))
|
||||
return CloudEnvironmentConfig(
|
||||
ansible_vars=ansible_vars,
|
||||
)
|
||||
|
||||
@@ -7,11 +7,13 @@ from lib.util import (
|
||||
ApplicationError,
|
||||
display,
|
||||
is_shippable,
|
||||
ConfigParser,
|
||||
)
|
||||
|
||||
from lib.cloud import (
|
||||
CloudProvider,
|
||||
CloudEnvironment,
|
||||
CloudEnvironmentConfig,
|
||||
)
|
||||
|
||||
from lib.core_ci import (
|
||||
@@ -84,16 +86,22 @@ class AwsCloudProvider(CloudProvider):
|
||||
|
||||
class AwsCloudEnvironment(CloudEnvironment):
|
||||
"""AWS cloud environment plugin. Updates integration test environment after delegation."""
|
||||
def configure_environment(self, env, cmd):
|
||||
def get_environment_config(self):
|
||||
"""
|
||||
:type env: dict[str, str]
|
||||
:type cmd: list[str]
|
||||
:rtype: CloudEnvironmentConfig
|
||||
"""
|
||||
cmd.append('-e')
|
||||
cmd.append('@%s' % self.config_path)
|
||||
parser = ConfigParser()
|
||||
parser.read(self.config_path)
|
||||
|
||||
cmd.append('-e')
|
||||
cmd.append('resource_prefix=%s' % self.resource_prefix)
|
||||
ansible_vars = dict(
|
||||
resource_prefix=self.resource_prefix,
|
||||
)
|
||||
|
||||
ansible_vars.update(dict(parser.items('default')))
|
||||
|
||||
return CloudEnvironmentConfig(
|
||||
ansible_vars=ansible_vars,
|
||||
)
|
||||
|
||||
def on_failure(self, target, tries):
|
||||
"""
|
||||
|
||||
@@ -7,11 +7,13 @@ from lib.util import (
|
||||
ApplicationError,
|
||||
display,
|
||||
is_shippable,
|
||||
ConfigParser,
|
||||
)
|
||||
|
||||
from lib.cloud import (
|
||||
CloudProvider,
|
||||
CloudEnvironment,
|
||||
CloudEnvironmentConfig,
|
||||
)
|
||||
|
||||
from lib.http import (
|
||||
@@ -124,6 +126,8 @@ class AzureCloudProvider(CloudProvider):
|
||||
|
||||
config = '\n'.join('%s: %s' % (key, values[key]) for key in sorted(values))
|
||||
|
||||
config = '[default]\n' + config
|
||||
|
||||
self._write_config(config)
|
||||
|
||||
def _create_ansible_core_ci(self):
|
||||
@@ -135,22 +139,22 @@ class AzureCloudProvider(CloudProvider):
|
||||
|
||||
class AzureCloudEnvironment(CloudEnvironment):
|
||||
"""Azure cloud environment plugin. Updates integration test environment after delegation."""
|
||||
def configure_environment(self, env, cmd):
|
||||
def get_environment_config(self):
|
||||
"""
|
||||
:type env: dict[str, str]
|
||||
:type cmd: list[str]
|
||||
:rtype: CloudEnvironmentConfig
|
||||
"""
|
||||
config = get_config(self.config_path)
|
||||
env_vars = get_config(self.config_path)
|
||||
|
||||
cmd.append('-e')
|
||||
cmd.append('resource_prefix=%s' % self.resource_prefix)
|
||||
cmd.append('-e')
|
||||
cmd.append('resource_group=%s' % config['RESOURCE_GROUP'])
|
||||
cmd.append('-e')
|
||||
cmd.append('resource_group_secondary=%s' % config['RESOURCE_GROUP_SECONDARY'])
|
||||
ansible_vars = dict(
|
||||
resource_prefix=self.resource_prefix,
|
||||
)
|
||||
|
||||
for key in config:
|
||||
env[key] = config[key]
|
||||
ansible_vars.update(dict((key.lower(), value) for key, value in env_vars.items()))
|
||||
|
||||
return CloudEnvironmentConfig(
|
||||
env_vars=env_vars,
|
||||
ansible_vars=ansible_vars,
|
||||
)
|
||||
|
||||
def on_failure(self, target, tries):
|
||||
"""
|
||||
@@ -167,9 +171,10 @@ def get_config(config_path):
|
||||
:type config_path: str
|
||||
:rtype: dict[str, str]
|
||||
"""
|
||||
with open(config_path, 'r') as config_fd:
|
||||
lines = [line for line in config_fd.read().splitlines() if ':' in line and line.strip() and not line.strip().startswith('#')]
|
||||
config = dict((kvp[0].strip(), kvp[1].strip()) for kvp in [line.split(':', 1) for line in lines])
|
||||
parser = ConfigParser()
|
||||
parser.read(config_path)
|
||||
|
||||
config = dict((key.upper(), value) for key, value in parser.items('default'))
|
||||
|
||||
rg_vars = (
|
||||
'RESOURCE_GROUP',
|
||||
|
||||
@@ -11,6 +11,7 @@ from os.path import isfile
|
||||
from lib.cloud import (
|
||||
CloudProvider,
|
||||
CloudEnvironment,
|
||||
CloudEnvironmentConfig,
|
||||
)
|
||||
|
||||
from lib.util import ConfigParser, display
|
||||
@@ -25,7 +26,7 @@ class CloudscaleCloudProvider(CloudProvider):
|
||||
"""
|
||||
:type args: TestConfig
|
||||
"""
|
||||
super(CloudscaleCloudProvider, self).__init__(args, config_extension='.ini')
|
||||
super(CloudscaleCloudProvider, self).__init__(args)
|
||||
|
||||
def filter(self, targets, exclude):
|
||||
"""Filter out the cloud tests when the necessary config and resources are not available.
|
||||
@@ -38,6 +39,7 @@ class CloudscaleCloudProvider(CloudProvider):
|
||||
super(CloudscaleCloudProvider, self).filter(targets, exclude)
|
||||
|
||||
def setup(self):
|
||||
"""Setup the cloud resource before delegation and register a cleanup callback."""
|
||||
super(CloudscaleCloudProvider, self).setup()
|
||||
|
||||
if isfile(self.config_static_path):
|
||||
@@ -46,28 +48,30 @@ class CloudscaleCloudProvider(CloudProvider):
|
||||
verbosity=1)
|
||||
self.config_path = self.config_static_path
|
||||
self.managed = False
|
||||
return True
|
||||
|
||||
return False
|
||||
|
||||
|
||||
class CloudscaleCloudEnvironment(CloudEnvironment):
|
||||
"""Cloudscale cloud environment plugin. Updates integration test environment
|
||||
after delegation.
|
||||
"""
|
||||
def configure_environment(self, env, cmd):
|
||||
def get_environment_config(self):
|
||||
"""
|
||||
:type env: dict[str, str]
|
||||
:type cmd: list[str]
|
||||
:rtype: CloudEnvironmentConfig
|
||||
"""
|
||||
parser = ConfigParser()
|
||||
parser.read(self.config_path)
|
||||
|
||||
changes = dict(
|
||||
env_vars = dict(
|
||||
CLOUDSCALE_API_TOKEN=parser.get('default', 'cloudscale_api_token'),
|
||||
)
|
||||
|
||||
env.update(changes)
|
||||
ansible_vars = dict(
|
||||
cloudscale_resource_prefix=self.resource_prefix,
|
||||
)
|
||||
|
||||
cmd.append('-e')
|
||||
cmd.append('cloudscale_resource_prefix=%s' % self.resource_prefix)
|
||||
ansible_vars.update(dict((key.lower(), value) for key, value in env_vars.items()))
|
||||
|
||||
return CloudEnvironmentConfig(
|
||||
env_vars=env_vars,
|
||||
ansible_vars=ansible_vars,
|
||||
)
|
||||
|
||||
@@ -9,6 +9,7 @@ import time
|
||||
from lib.cloud import (
|
||||
CloudProvider,
|
||||
CloudEnvironment,
|
||||
CloudEnvironmentConfig,
|
||||
)
|
||||
|
||||
from lib.util import (
|
||||
@@ -45,7 +46,7 @@ class CsCloudProvider(CloudProvider):
|
||||
"""
|
||||
:type args: TestConfig
|
||||
"""
|
||||
super(CsCloudProvider, self).__init__(args, config_extension='.ini')
|
||||
super(CsCloudProvider, self).__init__(args)
|
||||
|
||||
# The simulator must be pinned to a specific version to guarantee CI passes with the version used.
|
||||
self.image = 'quay.io/ansible/cloudstack-test-container:1.2.0'
|
||||
@@ -262,16 +263,27 @@ class CsCloudProvider(CloudProvider):
|
||||
|
||||
class CsCloudEnvironment(CloudEnvironment):
|
||||
"""CloudStack cloud environment plugin. Updates integration test environment after delegation."""
|
||||
def configure_environment(self, env, cmd):
|
||||
def get_environment_config(self):
|
||||
"""
|
||||
:type env: dict[str, str]
|
||||
:type cmd: list[str]
|
||||
:rtype: CloudEnvironmentConfig
|
||||
"""
|
||||
changes = dict(
|
||||
CLOUDSTACK_CONFIG=self.config_path,
|
||||
parser = ConfigParser()
|
||||
parser.read(self.config_path)
|
||||
|
||||
config = dict(parser.items('default'))
|
||||
|
||||
env_vars = dict(
|
||||
CLOUDSTACK_ENDPOINT=config['endpoint'],
|
||||
CLOUDSTACK_KEY=config['key'],
|
||||
CLOUDSTACK_SECRET=config['secret'],
|
||||
CLOUDSTACK_TIMEOUT=config['timeout'],
|
||||
)
|
||||
|
||||
env.update(changes)
|
||||
ansible_vars = dict(
|
||||
cs_resource_prefix=self.resource_prefix,
|
||||
)
|
||||
|
||||
cmd.append('-e')
|
||||
cmd.append('cs_resource_prefix=%s' % self.resource_prefix)
|
||||
return CloudEnvironmentConfig(
|
||||
env_vars=env_vars,
|
||||
ansible_vars=ansible_vars,
|
||||
)
|
||||
|
||||
@@ -7,6 +7,7 @@ import os
|
||||
from . import (
|
||||
CloudProvider,
|
||||
CloudEnvironment,
|
||||
CloudEnvironmentConfig,
|
||||
)
|
||||
|
||||
from ..util import (
|
||||
@@ -175,13 +176,15 @@ class ForemanEnvironment(CloudEnvironment):
|
||||
|
||||
Updates integration test environment after delegation.
|
||||
"""
|
||||
|
||||
def configure_environment(self, env, cmd):
|
||||
def get_environment_config(self):
|
||||
"""
|
||||
:type env: dict[str, str]
|
||||
:type cmd: list[str]
|
||||
:rtype: CloudEnvironmentConfig
|
||||
"""
|
||||
env_vars = dict(
|
||||
FOREMAN_HOST=self._get_cloud_config('FOREMAN_HOST'),
|
||||
FOREMAN_PORT=self._get_cloud_config('FOREMAN_PORT'),
|
||||
)
|
||||
|
||||
# Send the container IP down to the integration test(s)
|
||||
env['FOREMAN_HOST'] = self._get_cloud_config('FOREMAN_HOST')
|
||||
env['FOREMAN_PORT'] = self._get_cloud_config('FOREMAN_PORT')
|
||||
return CloudEnvironmentConfig(
|
||||
env_vars=env_vars,
|
||||
)
|
||||
|
||||
@@ -7,11 +7,13 @@ import os
|
||||
|
||||
from lib.util import (
|
||||
display,
|
||||
ConfigParser,
|
||||
)
|
||||
|
||||
from lib.cloud import (
|
||||
CloudProvider,
|
||||
CloudEnvironment,
|
||||
CloudEnvironmentConfig,
|
||||
)
|
||||
|
||||
|
||||
@@ -41,22 +43,19 @@ class GcpCloudProvider(CloudProvider):
|
||||
|
||||
class GcpCloudEnvironment(CloudEnvironment):
|
||||
"""GCP cloud environment plugin. Updates integration test environment after delegation."""
|
||||
def get_environment_config(self):
|
||||
"""
|
||||
:rtype: CloudEnvironmentConfig
|
||||
"""
|
||||
parser = ConfigParser()
|
||||
parser.read(self.config_path)
|
||||
|
||||
def configure_environment(self, env, cmd):
|
||||
"""
|
||||
:type env: dict[str, str]
|
||||
:type cmd: list[str]
|
||||
"""
|
||||
cmd.append('-e')
|
||||
cmd.append('@%s' % self.config_path)
|
||||
ansible_vars = dict(
|
||||
resource_prefix=self.resource_prefix,
|
||||
)
|
||||
|
||||
cmd.append('-e')
|
||||
cmd.append('resource_prefix=%s' % self.resource_prefix)
|
||||
ansible_vars.update(dict(parser.items('default')))
|
||||
|
||||
def on_failure(self, target, tries):
|
||||
"""
|
||||
:type target: TestTarget
|
||||
:type tries: int
|
||||
"""
|
||||
if not tries and self.managed:
|
||||
display.notice('%s failed' % target.name)
|
||||
return CloudEnvironmentConfig(
|
||||
ansible_vars=ansible_vars,
|
||||
)
|
||||
|
||||
@@ -7,6 +7,7 @@ import os
|
||||
from . import (
|
||||
CloudProvider,
|
||||
CloudEnvironment,
|
||||
CloudEnvironmentConfig,
|
||||
)
|
||||
|
||||
from ..util import (
|
||||
@@ -174,12 +175,18 @@ class NiosEnvironment(CloudEnvironment):
|
||||
|
||||
Updates integration test environment after delegation.
|
||||
"""
|
||||
|
||||
def configure_environment(self, env, cmd):
|
||||
def get_environment_config(self):
|
||||
"""
|
||||
:type env: dict[str, str]
|
||||
:type cmd: list[str]
|
||||
:rtype: CloudEnvironmentConfig
|
||||
"""
|
||||
ansible_vars = dict(
|
||||
nios_provider=dict(
|
||||
host=self._get_cloud_config('NIOS_HOST'),
|
||||
username='admin',
|
||||
password='infoblox',
|
||||
),
|
||||
)
|
||||
|
||||
# Send the container IP down to the integration test(s)
|
||||
env['NIOS_HOST'] = self._get_cloud_config('NIOS_HOST')
|
||||
return CloudEnvironmentConfig(
|
||||
ansible_vars=ansible_vars,
|
||||
)
|
||||
|
||||
@@ -2,11 +2,13 @@
|
||||
|
||||
from lib.cloud import (
|
||||
CloudProvider,
|
||||
CloudEnvironment
|
||||
CloudEnvironment,
|
||||
CloudEnvironmentConfig,
|
||||
)
|
||||
|
||||
from lib.util import (
|
||||
display,
|
||||
ConfigParser,
|
||||
)
|
||||
|
||||
|
||||
@@ -43,14 +45,19 @@ class OpenNebulaCloudEnvironment(CloudEnvironment):
|
||||
"""
|
||||
Updates integration test environment after delegation. Will setup the config file as parameter.
|
||||
"""
|
||||
|
||||
def configure_environment(self, env, cmd):
|
||||
def get_environment_config(self):
|
||||
"""
|
||||
:type env: dict[str, str]
|
||||
:type cmd: list[str]
|
||||
:rtype: CloudEnvironmentConfig
|
||||
"""
|
||||
cmd.append('-e')
|
||||
cmd.append('@%s' % self.config_path)
|
||||
parser = ConfigParser()
|
||||
parser.read(self.config_path)
|
||||
|
||||
cmd.append('-e')
|
||||
cmd.append('resource_prefix=%s' % self.resource_prefix)
|
||||
ansible_vars = dict(
|
||||
resource_prefix=self.resource_prefix,
|
||||
)
|
||||
|
||||
ansible_vars.update(dict(parser.items('default')))
|
||||
|
||||
return CloudEnvironmentConfig(
|
||||
ansible_vars=ansible_vars,
|
||||
)
|
||||
|
||||
@@ -9,6 +9,7 @@ import time
|
||||
from lib.cloud import (
|
||||
CloudProvider,
|
||||
CloudEnvironment,
|
||||
CloudEnvironmentConfig,
|
||||
)
|
||||
|
||||
from lib.util import (
|
||||
@@ -211,13 +212,14 @@ class OpenShiftCloudProvider(CloudProvider):
|
||||
|
||||
class OpenShiftCloudEnvironment(CloudEnvironment):
|
||||
"""OpenShift cloud environment plugin. Updates integration test environment after delegation."""
|
||||
def configure_environment(self, env, cmd):
|
||||
def get_environment_config(self):
|
||||
"""
|
||||
:type env: dict[str, str]
|
||||
:type cmd: list[str]
|
||||
:rtype: CloudEnvironmentConfig
|
||||
"""
|
||||
changes = dict(
|
||||
env_vars = dict(
|
||||
K8S_AUTH_KUBECONFIG=self.config_path,
|
||||
)
|
||||
|
||||
env.update(changes)
|
||||
return CloudEnvironmentConfig(
|
||||
env_vars=env_vars,
|
||||
)
|
||||
|
||||
@@ -16,6 +16,7 @@ from lib.util import (
|
||||
from lib.cloud import (
|
||||
CloudProvider,
|
||||
CloudEnvironment,
|
||||
CloudEnvironmentConfig,
|
||||
)
|
||||
|
||||
from lib.core_ci import (
|
||||
@@ -29,7 +30,7 @@ class TowerCloudProvider(CloudProvider):
|
||||
"""
|
||||
:type args: TestConfig
|
||||
"""
|
||||
super(TowerCloudProvider, self).__init__(args, config_extension='.cfg')
|
||||
super(TowerCloudProvider, self).__init__(args)
|
||||
|
||||
self.aci = None
|
||||
self.version = ''
|
||||
@@ -162,14 +163,20 @@ class TowerCloudEnvironment(CloudEnvironment):
|
||||
|
||||
time.sleep(5)
|
||||
|
||||
def configure_environment(self, env, cmd):
|
||||
"""Configuration which should be done once for each test target.
|
||||
:type env: dict[str, str]
|
||||
:type cmd: list[str]
|
||||
def get_environment_config(self):
|
||||
"""
|
||||
:rtype: CloudEnvironmentConfig
|
||||
"""
|
||||
config = TowerConfig.parse(self.config_path)
|
||||
|
||||
env.update(config.environment)
|
||||
env_vars = config.environment
|
||||
|
||||
ansible_vars = dict((key.lower(), value) for key, value in env_vars.items())
|
||||
|
||||
return CloudEnvironmentConfig(
|
||||
env_vars=env_vars,
|
||||
ansible_vars=ansible_vars,
|
||||
)
|
||||
|
||||
|
||||
class TowerConfig(object):
|
||||
@@ -213,7 +220,7 @@ class TowerConfig(object):
|
||||
'password',
|
||||
)
|
||||
|
||||
values = dict((k, parser.get('general', k)) for k in keys)
|
||||
values = dict((k, parser.get('default', k)) for k in keys)
|
||||
config = TowerConfig(values)
|
||||
|
||||
missing = [k for k in keys if not values.get(k)]
|
||||
|
||||
@@ -6,6 +6,7 @@ import os
|
||||
from lib.cloud import (
|
||||
CloudProvider,
|
||||
CloudEnvironment,
|
||||
CloudEnvironmentConfig,
|
||||
)
|
||||
|
||||
from lib.util import (
|
||||
@@ -30,7 +31,7 @@ class VcenterProvider(CloudProvider):
|
||||
"""
|
||||
:type args: TestConfig
|
||||
"""
|
||||
super(VcenterProvider, self).__init__(args, config_extension='.ini')
|
||||
super(VcenterProvider, self).__init__(args)
|
||||
|
||||
# The simulator must be pinned to a specific version to guarantee CI passes with the version used.
|
||||
if os.environ.get('ANSIBLE_VCSIM_CONTAINER'):
|
||||
@@ -144,13 +145,19 @@ class VcenterProvider(CloudProvider):
|
||||
|
||||
class VcenterEnvironment(CloudEnvironment):
|
||||
"""VMware vcenter/esx environment plugin. Updates integration test environment after delegation."""
|
||||
def configure_environment(self, env, cmd):
|
||||
def get_environment_config(self):
|
||||
"""
|
||||
:type env: dict[str, str]
|
||||
:type cmd: list[str]
|
||||
:rtype: CloudEnvironmentConfig
|
||||
"""
|
||||
cmd.append('-e')
|
||||
cmd.append('vcsim=%s' % self._get_cloud_config('vcenter_host'))
|
||||
env_vars = dict(
|
||||
VCENTER_HOST=self._get_cloud_config('vcenter_host'),
|
||||
)
|
||||
|
||||
# Send the container IP down to the integration test(s)
|
||||
env['VCENTER_HOST'] = self._get_cloud_config('vcenter_host')
|
||||
ansible_vars = dict(
|
||||
vcsim=self._get_cloud_config('vcenter_host'),
|
||||
)
|
||||
|
||||
return CloudEnvironmentConfig(
|
||||
env_vars=env_vars,
|
||||
ansible_vars=ansible_vars,
|
||||
)
|
||||
|
||||
@@ -5,7 +5,8 @@ import os
|
||||
|
||||
from lib.cloud import (
|
||||
CloudProvider,
|
||||
CloudEnvironment
|
||||
CloudEnvironment,
|
||||
CloudEnvironmentConfig,
|
||||
)
|
||||
|
||||
from lib.util import ConfigParser
|
||||
@@ -18,7 +19,7 @@ class VultrCloudProvider(CloudProvider):
|
||||
"""
|
||||
:type args: TestConfig
|
||||
"""
|
||||
super(VultrCloudProvider, self).__init__(args, config_extension='.ini')
|
||||
super(VultrCloudProvider, self).__init__(args)
|
||||
|
||||
def filter(self, targets, exclude):
|
||||
"""Filter out the cloud tests when the necessary config and resources are not available.
|
||||
@@ -31,32 +32,34 @@ class VultrCloudProvider(CloudProvider):
|
||||
super(VultrCloudProvider, self).filter(targets, exclude)
|
||||
|
||||
def setup(self):
|
||||
"""Setup the cloud resource before delegation and register a cleanup callback."""
|
||||
super(VultrCloudProvider, self).setup()
|
||||
|
||||
if os.path.isfile(self.config_static_path):
|
||||
self.config_path = self.config_static_path
|
||||
self.managed = False
|
||||
return True
|
||||
return False
|
||||
|
||||
|
||||
class VultrCloudEnvironment(CloudEnvironment):
|
||||
"""
|
||||
Updates integration test environment after delegation. Will setup the config file as parameter.
|
||||
"""
|
||||
|
||||
def configure_environment(self, env, cmd):
|
||||
def get_environment_config(self):
|
||||
"""
|
||||
:type env: dict[str, str]
|
||||
:type cmd: list[str]
|
||||
:rtype: CloudEnvironmentConfig
|
||||
"""
|
||||
parser = ConfigParser()
|
||||
parser.read(self.config_path)
|
||||
|
||||
changes = dict(
|
||||
env_vars = dict(
|
||||
VULTR_API_KEY=parser.get('default', 'key'),
|
||||
)
|
||||
env.update(changes)
|
||||
|
||||
cmd.append('-e')
|
||||
cmd.append('vultr_resource_prefix=%s' % self.resource_prefix)
|
||||
ansible_vars = dict(
|
||||
vultr_resource_prefix=self.resource_prefix,
|
||||
)
|
||||
|
||||
return CloudEnvironmentConfig(
|
||||
env_vars=env_vars,
|
||||
ansible_vars=ansible_vars,
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user