2019-01-07 22:29:01 +01:00
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
#
|
|
|
|
# (c) 2018, Gaudenz Steinlin <gaudenz.steinlin@cloudscale.ch>
|
|
|
|
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
|
|
|
|
|
|
|
|
"""Cloudscale plugin for integration tests."""
|
2019-07-12 08:46:20 +02:00
|
|
|
from __future__ import (absolute_import, division, print_function)
|
|
|
|
__metaclass__ = type
|
2019-01-07 22:29:01 +01:00
|
|
|
|
|
|
|
from os.path import isfile
|
|
|
|
|
2019-08-06 23:43:29 +02:00
|
|
|
from . import (
|
2019-01-07 22:29:01 +01:00
|
|
|
CloudProvider,
|
|
|
|
CloudEnvironment,
|
2019-03-01 03:25:49 +01:00
|
|
|
CloudEnvironmentConfig,
|
2019-01-07 22:29:01 +01:00
|
|
|
)
|
|
|
|
|
2019-08-06 23:43:29 +02:00
|
|
|
from ..util import ConfigParser, display
|
2019-01-07 22:29:01 +01:00
|
|
|
|
|
|
|
|
|
|
|
class CloudscaleCloudProvider(CloudProvider):
|
|
|
|
"""Cloudscale cloud provider plugin. Sets up cloud resources before
|
|
|
|
delegation.
|
|
|
|
"""
|
|
|
|
|
|
|
|
def __init__(self, args):
|
|
|
|
"""
|
|
|
|
:type args: TestConfig
|
|
|
|
"""
|
2019-03-01 03:25:49 +01:00
|
|
|
super(CloudscaleCloudProvider, self).__init__(args)
|
2019-01-07 22:29:01 +01:00
|
|
|
|
|
|
|
def filter(self, targets, exclude):
|
|
|
|
"""Filter out the cloud tests when the necessary config and resources are not available.
|
|
|
|
:type targets: tuple[TestTarget]
|
|
|
|
:type exclude: list[str]
|
|
|
|
"""
|
|
|
|
if isfile(self.config_static_path):
|
|
|
|
return
|
|
|
|
|
|
|
|
super(CloudscaleCloudProvider, self).filter(targets, exclude)
|
|
|
|
|
|
|
|
def setup(self):
|
2019-03-01 03:25:49 +01:00
|
|
|
"""Setup the cloud resource before delegation and register a cleanup callback."""
|
2019-01-07 22:29:01 +01:00
|
|
|
super(CloudscaleCloudProvider, self).setup()
|
|
|
|
|
|
|
|
if isfile(self.config_static_path):
|
|
|
|
display.info('Using existing %s cloud config: %s'
|
|
|
|
% (self.platform, self.config_static_path),
|
|
|
|
verbosity=1)
|
|
|
|
self.config_path = self.config_static_path
|
|
|
|
self.managed = False
|
|
|
|
|
|
|
|
|
|
|
|
class CloudscaleCloudEnvironment(CloudEnvironment):
|
|
|
|
"""Cloudscale cloud environment plugin. Updates integration test environment
|
|
|
|
after delegation.
|
|
|
|
"""
|
2019-03-01 03:25:49 +01:00
|
|
|
def get_environment_config(self):
|
2019-01-07 22:29:01 +01:00
|
|
|
"""
|
2019-03-01 03:25:49 +01:00
|
|
|
:rtype: CloudEnvironmentConfig
|
2019-01-07 22:29:01 +01:00
|
|
|
"""
|
|
|
|
parser = ConfigParser()
|
|
|
|
parser.read(self.config_path)
|
|
|
|
|
2019-03-01 03:25:49 +01:00
|
|
|
env_vars = dict(
|
2019-01-07 22:29:01 +01:00
|
|
|
CLOUDSCALE_API_TOKEN=parser.get('default', 'cloudscale_api_token'),
|
|
|
|
)
|
|
|
|
|
2019-09-17 06:01:37 +02:00
|
|
|
display.sensitive.add(env_vars['CLOUDSCALE_API_TOKEN'])
|
|
|
|
|
2019-03-01 03:25:49 +01:00
|
|
|
ansible_vars = dict(
|
|
|
|
cloudscale_resource_prefix=self.resource_prefix,
|
|
|
|
)
|
|
|
|
|
|
|
|
ansible_vars.update(dict((key.lower(), value) for key, value in env_vars.items()))
|
2019-01-07 22:29:01 +01:00
|
|
|
|
2019-03-01 03:25:49 +01:00
|
|
|
return CloudEnvironmentConfig(
|
|
|
|
env_vars=env_vars,
|
|
|
|
ansible_vars=ansible_vars,
|
|
|
|
)
|