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
|
|
|
|
2020-02-04 20:21:53 +01:00
|
|
|
import os
|
2019-01-07 22:29:01 +01:00
|
|
|
|
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
|
|
|
|
2021-02-02 20:47:38 +01:00
|
|
|
self.uses_config = True
|
2019-01-07 22:29:01 +01:00
|
|
|
|
|
|
|
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()
|
|
|
|
|
2020-02-04 20:21:53 +01:00
|
|
|
if os.path.isfile(self.config_static_path):
|
2019-01-07 22:29:01 +01:00
|
|
|
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,
|
|
|
|
)
|