mirror of https://github.com/ansible/ansible.git
You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
79 lines
2.3 KiB
Python
79 lines
2.3 KiB
Python
6 years ago
|
# -*- 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."""
|
||
5 years ago
|
from __future__ import (absolute_import, division, print_function)
|
||
|
__metaclass__ = type
|
||
6 years ago
|
|
||
|
from os.path import isfile
|
||
|
|
||
5 years ago
|
from . import (
|
||
6 years ago
|
CloudProvider,
|
||
|
CloudEnvironment,
|
||
6 years ago
|
CloudEnvironmentConfig,
|
||
6 years ago
|
)
|
||
|
|
||
5 years ago
|
from ..util import ConfigParser, display
|
||
6 years ago
|
|
||
|
|
||
|
class CloudscaleCloudProvider(CloudProvider):
|
||
|
"""Cloudscale cloud provider plugin. Sets up cloud resources before
|
||
|
delegation.
|
||
|
"""
|
||
|
|
||
|
def __init__(self, args):
|
||
|
"""
|
||
|
:type args: TestConfig
|
||
|
"""
|
||
6 years ago
|
super(CloudscaleCloudProvider, self).__init__(args)
|
||
6 years ago
|
|
||
|
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):
|
||
6 years ago
|
"""Setup the cloud resource before delegation and register a cleanup callback."""
|
||
6 years ago
|
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.
|
||
|
"""
|
||
6 years ago
|
def get_environment_config(self):
|
||
6 years ago
|
"""
|
||
6 years ago
|
:rtype: CloudEnvironmentConfig
|
||
6 years ago
|
"""
|
||
|
parser = ConfigParser()
|
||
|
parser.read(self.config_path)
|
||
|
|
||
6 years ago
|
env_vars = dict(
|
||
6 years ago
|
CLOUDSCALE_API_TOKEN=parser.get('default', 'cloudscale_api_token'),
|
||
|
)
|
||
|
|
||
6 years ago
|
ansible_vars = dict(
|
||
|
cloudscale_resource_prefix=self.resource_prefix,
|
||
|
)
|
||
|
|
||
|
ansible_vars.update(dict((key.lower(), value) for key, value in env_vars.items()))
|
||
6 years ago
|
|
||
6 years ago
|
return CloudEnvironmentConfig(
|
||
|
env_vars=env_vars,
|
||
|
ansible_vars=ansible_vars,
|
||
|
)
|