mirror of
https://github.com/ansible-collections/community.general.git
synced 2025-07-15 17:40:50 -07:00
Cleanup and enhancements for ansible-test. (#37142)
* Fix type hint typos. * Add one-time cloud env setup after delegation. * Add generate_password to util. * Add username/password support to HttpClient. * Avoid pip requirement for ansible-test shell. * Support provisioning Tower instances.
This commit is contained in:
parent
5de7c9ce8f
commit
b9b8081a87
8 changed files with 82 additions and 13 deletions
|
@ -164,6 +164,7 @@ class CloudBase(ABC):
|
|||
_CONFIG_PATH = 'config_path'
|
||||
_RESOURCE_PREFIX = 'resource_prefix'
|
||||
_MANAGED = 'managed'
|
||||
_SETUP_EXECUTED = 'setup_executed'
|
||||
|
||||
def __init__(self, args):
|
||||
"""
|
||||
|
@ -172,6 +173,20 @@ class CloudBase(ABC):
|
|||
self.args = args
|
||||
self.platform = self.__module__.split('.')[2]
|
||||
|
||||
@property
|
||||
def setup_executed(self):
|
||||
"""
|
||||
:rtype: bool
|
||||
"""
|
||||
return self._get_cloud_config(self._SETUP_EXECUTED, False)
|
||||
|
||||
@setup_executed.setter
|
||||
def setup_executed(self, value):
|
||||
"""
|
||||
:type value: bool
|
||||
"""
|
||||
self._set_cloud_config(self._SETUP_EXECUTED, value)
|
||||
|
||||
@property
|
||||
def config_path(self):
|
||||
"""
|
||||
|
@ -214,11 +229,15 @@ class CloudBase(ABC):
|
|||
"""
|
||||
self._set_cloud_config(self._MANAGED, value)
|
||||
|
||||
def _get_cloud_config(self, key):
|
||||
def _get_cloud_config(self, key, default=None):
|
||||
"""
|
||||
:type key: str
|
||||
:type default: str | int | bool | None
|
||||
:rtype: str | int | bool
|
||||
"""
|
||||
if default is not None:
|
||||
return self.args.metadata.cloud_config[self.platform].get(key, default)
|
||||
|
||||
return self.args.metadata.cloud_config[self.platform][key]
|
||||
|
||||
def _set_cloud_config(self, key, value):
|
||||
|
@ -357,9 +376,21 @@ class CloudProvider(CloudBase):
|
|||
|
||||
class CloudEnvironment(CloudBase):
|
||||
"""Base class for cloud environment plugins. Updates integration test environment after delegation."""
|
||||
def setup_once(self):
|
||||
"""Run setup if it has not already been run."""
|
||||
if self.setup_executed:
|
||||
return
|
||||
|
||||
self.setup()
|
||||
self.setup_executed = True
|
||||
|
||||
def setup(self):
|
||||
"""Setup which should be done once per environment instead of once per test target."""
|
||||
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]
|
||||
"""
|
||||
|
|
|
@ -171,8 +171,8 @@ class AzureCloudEnvironment(CloudEnvironment):
|
|||
|
||||
def get_config(config_path):
|
||||
"""
|
||||
:param config_path: str
|
||||
:return: dict[str, str]
|
||||
: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('#')]
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue