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.
67 lines
1.8 KiB
Python
67 lines
1.8 KiB
Python
6 years ago
|
"""Vultr plugin for integration tests."""
|
||
5 years ago
|
from __future__ import (absolute_import, division, print_function)
|
||
|
__metaclass__ = type
|
||
6 years ago
|
|
||
|
import os
|
||
|
|
||
5 years ago
|
from . import (
|
||
6 years ago
|
CloudProvider,
|
||
6 years ago
|
CloudEnvironment,
|
||
|
CloudEnvironmentConfig,
|
||
6 years ago
|
)
|
||
|
|
||
5 years ago
|
from ..util import ConfigParser
|
||
6 years ago
|
|
||
|
|
||
|
class VultrCloudProvider(CloudProvider):
|
||
|
"""Checks if a configuration file has been passed or fixtures are going to be used for testing"""
|
||
|
|
||
|
def __init__(self, args):
|
||
|
"""
|
||
|
:type args: TestConfig
|
||
|
"""
|
||
6 years ago
|
super(VultrCloudProvider, 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 os.path.isfile(self.config_static_path):
|
||
|
return
|
||
|
|
||
|
super(VultrCloudProvider, 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(VultrCloudProvider, self).setup()
|
||
|
|
||
|
if os.path.isfile(self.config_static_path):
|
||
|
self.config_path = self.config_static_path
|
||
|
self.managed = False
|
||
|
|
||
|
|
||
|
class VultrCloudEnvironment(CloudEnvironment):
|
||
|
"""
|
||
|
Updates integration test environment after delegation. Will setup the config file as parameter.
|
||
|
"""
|
||
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
|
VULTR_API_KEY=parser.get('default', 'key'),
|
||
|
)
|
||
|
|
||
6 years ago
|
ansible_vars = dict(
|
||
|
vultr_resource_prefix=self.resource_prefix,
|
||
|
)
|
||
|
|
||
|
return CloudEnvironmentConfig(
|
||
|
env_vars=env_vars,
|
||
|
ansible_vars=ansible_vars,
|
||
|
)
|