2
"""Test Model Tree Config functionality.
4
Tests that default values can be overwritten and then unset.
6
Ensures that a model config overwrites a controller config and a controller
7
config overwrites a default.
9
Also ensures that when reverting/unsetting the controller config it reverts to
10
the most up to date model config setting.
14
from __future__ import print_function
20
from deploy_stack import (
25
add_basic_testing_arguments,
33
log = logging.getLogger("assess_model_config_tree")
36
def assess_model_config_tree(bs_manager, upload_tools):
37
"""Assess model config tree functionality."""
38
# Need to update the cloud config details here so we can set something that
39
# we can use after boostrap.
40
config = {'ftp-proxy': 'abc.com'}
41
set_clouds_yaml_config(bs_manager.client, config)
43
with bs_manager.booted_context(upload_tools):
44
client = bs_manager.client
45
assert_config_value(client, 'ftp-proxy', 'controller', 'abc.com')
46
client.set_env_option('ftp-proxy', 'abc-model.com')
47
assert_config_value(client, 'ftp-proxy', 'model', 'abc-model.com')
48
client.unset_env_option('ftp-proxy')
49
assert_config_value(client, 'ftp-proxy', 'controller', 'abc.com')
51
assert_config_value(client, 'development', 'default', False)
52
client.set_env_option('development', True)
53
assert_config_value(client, 'development', 'model', True)
54
client.unset_env_option('development')
55
assert_config_value(client, 'development', 'default', False)
58
def assert_config_value(client, attribute, source, value):
59
config_values = client.get_model_config()
61
source_value = config_values[attribute]['source']
62
attr_value = config_values[attribute]['value']
63
if attr_value != value:
64
raise JujuAssertionError(
65
'Unexpected value for {}.\nGot {} instead of {}'.format(
66
attribute, attr_value, value))
68
if source_value != source:
69
raise JujuAssertionError(
70
'Unexpected source for {}.\nGot {} instead of {}'.format(
71
attribute, source_value, source))
73
raise ValueError('Attribute {} not found in config values.'.format(
77
def set_clouds_yaml_config(client, config_details):
78
"""Setup cloud details so it gets written to clouds.yaml at bootstrap."""
79
cloud_name = client.env.get_cloud()
82
'type': client.env.config['type'],
83
'regions': {client.env.get_region(): {}},
84
'config': config_details}
85
client.env.clouds['clouds'][cloud_name] = extra_conf
89
"""Parse all arguments."""
90
parser = argparse.ArgumentParser(description="Test Model Tree Config")
91
add_basic_testing_arguments(parser)
92
return parser.parse_args(argv)
96
args = parse_args(argv)
97
configure_logging(args.verbose)
98
bs_manager = BootstrapManager.from_args(args)
99
assess_model_config_tree(bs_manager, args.upload_tools)
103
if __name__ == '__main__':