-
Notifications
You must be signed in to change notification settings - Fork 42
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Updating tests to use real and fake broker_settings.yaml #216
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,7 @@ | ||
import os | ||
import click | ||
import inspect | ||
import uuid | ||
from pathlib import Path | ||
from dynaconf import Dynaconf, Validator | ||
from dynaconf.validator import ValidationError | ||
|
@@ -91,19 +92,27 @@ def init_settings(settings_path, interactive=False): | |
for k in vault_vars: | ||
del os.environ[k] | ||
|
||
settings = Dynaconf( | ||
settings_file=str(settings_path.absolute()), | ||
ENVVAR_PREFIX_FOR_DYNACONF="BROKER", | ||
validators=validators, | ||
) | ||
# to make doubly sure, remove the vault loader if set somehow | ||
settings._loaders = [loader for loader in settings._loaders if "vault" not in loader] | ||
os.environ.update(vault_vars) | ||
|
||
try: | ||
settings.validators.validate() | ||
except ValidationError as err: | ||
raise ConfigurationError( | ||
f"Configuration error in {settings_path.absolute()}: {err.args[0]}" | ||
settings = Dynaconf(ENVVAR_PREFIX_FOR_DYNACONF="BROKER", validators=validators) | ||
settings._loaders = [loader for loader in settings._loaders if "vault" not in loader] | ||
def load_settings(settings_path): | ||
_settings = Dynaconf( | ||
settings_file=str(settings_path.absolute()), | ||
ENVVAR_PREFIX_FOR_DYNACONF="BROKER", | ||
validators=validators, | ||
) | ||
# to make doubly sure, remove the vault loader if set somehow | ||
_settings._loaders = [loader for loader in _settings._loaders if "vault" not in loader] | ||
|
||
os.environ.update(vault_vars) | ||
try: | ||
_settings.validators.validate() | ||
except ValidationError as err: | ||
raise ConfigurationError( | ||
f"Configuration error in {settings_path.absolute()}: {err.args[0]}" | ||
) | ||
settings.clean() | ||
settings.update(_settings.as_dict()) | ||
Comment on lines
+114
to
+115
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is there a reason to have There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm not sure I understand the question. The reason for having the two here is that |
||
settings._broker_settings_id = str(uuid.uuid4()) | ||
|
||
load_settings(settings_path) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,7 @@ | ||
import os | ||
import pytest | ||
from broker.settings import settings_path, inventory_path, load_settings | ||
import shutil | ||
|
||
|
||
@pytest.fixture | ||
|
@@ -15,3 +17,21 @@ def set_envars(request): | |
os.environ[request.param[0]] = request.param[1] | ||
yield | ||
del os.environ[request.param[0]] | ||
|
||
@pytest.fixture(scope="module") | ||
def temp_settings_and_inventory(): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What about using the tmp_path fixture and creating the new files in it? Then setting There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We could try it if you think that's an improvement over this implementation. @JacobCallahan any thoughts since you helped me with our current solution? |
||
"""Temporarily move the local inventory and settings files, then move them back when done""" | ||
inv_backup_path = None | ||
if inventory_path.exists(): | ||
inv_backup_path = inventory_path.rename(f"{inventory_path.absolute()}.bak") | ||
settings_backup_path = settings_path.rename(f"{settings_path.absolute()}.bak") | ||
shutil.copyfile('tests/data/broker_settings.yaml', f'{settings_path.parent}/broker_settings.yaml') | ||
inventory_path.touch() | ||
load_settings(settings_path) | ||
yield | ||
inventory_path.unlink() | ||
settings_path.unlink() | ||
if inv_backup_path: | ||
inv_backup_path.rename(inventory_path) | ||
settings_backup_path.rename(settings_path) | ||
load_settings(settings_path) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
# Broker settings | ||
# different log levels for file and stdout | ||
logging: | ||
console_level: info | ||
file_level: debug | ||
# Host Settings | ||
# These can be left alone if you're not using Broker as a library | ||
host_username: root | ||
host_password: "<password>" | ||
host_ssh_port: 22 | ||
host_ssh_key_filename: "</path/to/the/ssh-key>" | ||
# Provider settings | ||
TestProvider: | ||
instances: | ||
- test1: | ||
foo: "bar" | ||
default: True | ||
- test2: | ||
foo: "baz" | ||
override_envars: True | ||
- bad: | ||
nothing: False | ||
config_value: "something" | ||
AnsibleTower: | ||
base_url: "https://<ansible tower host>/" | ||
# Username is required for both token and password-based authentication | ||
username: "<username>" | ||
# token is the preferred authentication method | ||
token: "<AT personal access token>" | ||
# password: "<plain text password>" | ||
inventory: "inventory name" | ||
release_workflow: "remove-vm" | ||
extend_workflow: "extend-vm" | ||
new_expire_time: "+172800" | ||
workflow_timeout: 3600 | ||
results_limit: 50 | ||
Container: | ||
host_username: "<username>" | ||
host_password: "<plain text password>" | ||
host_port: None | ||
default: True | ||
runtime: 'docker' | ||
# name used to prefix container names, used to distinguish yourself | ||
# if not set, then your local username will be used | ||
# name_prefix: test | ||
results_limit: 50 | ||
auto_map_ports: False | ||
# You can set a nickname as a shortcut for arguments | ||
nicks: | ||
test_nick: | ||
test_action: "fake" | ||
arg1: "abc" | ||
arg2: 123 | ||
arg3: True |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
workflow: deploy-base-rhel | ||
workflow: deploy-rhel |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
workflow: deploy-sat-jenkins | ||
workflow: deploy-satellite |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,2 @@ | ||
workflow: deploy-base-rhel | ||
workflow: deploy-rhel | ||
deploy_rhel_version: "7.8" |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
workflow: deploy-satellite | ||
deploy_sat_version: "6.13" |
This file was deleted.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What is the case when we need to reload the settings?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For running the test suite we need to change the settings file being used. Now that we automatically look for settings in
~/.broker
we need to change it to our broker_settings for testing when the tests are running.