mirror of
https://github.com/ansible-collections/community.general.git
synced 2025-05-02 23:31:25 -07:00
1st part of ansible config, adds ansible-config to view/manage configs (#12797)
* Start of ansible config project moved configuration definitions to external yaml file vs hardcoded * updated constants to be a data strcutures that are looped over and also return origin of setting changed to manager/data scheme for base classes new cli ansible-config to view/manage ansible configuration settings * prints green for default/unchanged and yellow for those that have been overriden * added list action to show all configurable settings and their associated ini and env var names * allows specifying config file to see what result would look like * TBD update, edit and view options removed test for functions that have been removed env_Vars are now list of dicts allows for version_added and deprecation in future added a couple of descriptions for future doc autogeneration ensure test does not fail if delete_me exists normalized 'path expansion' added yaml config to setup packaging removed unused imports better encoding handling updated as per feedback * pep8
This commit is contained in:
parent
4344132a7d
commit
74842adc07
20 changed files with 2032 additions and 575 deletions
|
@ -120,99 +120,3 @@ class TestMkBoolean:
|
|||
assert constants.mk_boolean("yes") is True
|
||||
assert constants.mk_boolean("y") is True
|
||||
assert constants.mk_boolean("on") is True
|
||||
|
||||
|
||||
class TestShellExpand:
|
||||
def test_shell_expand_none(self):
|
||||
assert constants.shell_expand(None) is None
|
||||
|
||||
def test_shell_expand_static_path(self):
|
||||
assert constants.shell_expand(u'/usr/local') == u'/usr/local'
|
||||
|
||||
def test_shell_expand_tilde(self, user):
|
||||
assert constants.shell_expand(u'~/local') == os.path.join(user['home'], 'local')
|
||||
assert constants.shell_expand(u'~%s/local' % user['username']) == os.path.join(user['home'], 'local')
|
||||
|
||||
def test_shell_expand_vars(self, user):
|
||||
assert constants.shell_expand(u'$HOME/local') == os.path.join(user['home'], 'local')
|
||||
|
||||
os.environ['ANSIBLE_TEST_VAR'] = '/srv/ansible'
|
||||
assert constants.shell_expand(u'$ANSIBLE_TEST_VAR/local') == os.path.join('/srv/ansible', 'local')
|
||||
|
||||
os.environ['ANSIBLE_TEST_VAR'] = '~'
|
||||
assert constants.shell_expand(u'$ANSIBLE_TEST_VAR/local') == os.path.join(user['home'], 'local')
|
||||
|
||||
del os.environ['ANSIBLE_TEST_VAR']
|
||||
assert constants.shell_expand(u'$ANSIBLE_TEST_VAR/local') == u'$ANSIBLE_TEST_VAR/local'
|
||||
|
||||
def test_expand_relative_abs_path(self):
|
||||
assert constants.shell_expand('/absolute/path', expand_relative_paths=True) == '/absolute/path'
|
||||
|
||||
def test_expand_relative_path_relative_cfg_file(self, cfg_file):
|
||||
assert constants.shell_expand(u'relative/path', expand_relative_paths=True) == os.path.join(cfg_file, 'relative/path')
|
||||
|
||||
def test_expand_relative_path_relative_cwd(self, cwd, null_cfg_file):
|
||||
assert constants.shell_expand(u'relative/path', expand_relative_paths=True) == os.path.join(cwd, 'relative/path')
|
||||
|
||||
|
||||
# configparser object
|
||||
class TestGetConfig:
|
||||
def test_from_config_file(self, cfgparser):
|
||||
assert constants.get_config(cfgparser, 'defaults', 'defaults_one', 'ANSIBLE_TEST_VAR', 'foo', value_type=None) == 'data_defaults_one'
|
||||
assert constants.get_config(cfgparser, 'level1', 'level1_one', 'ANSIBLE_TEST_VAR', 'foo', value_type=None) == 'data_level1_one'
|
||||
|
||||
def test_from_env_var(self, cfgparser):
|
||||
os.environ['ANSIBLE_TEST_VAR'] = 'bar'
|
||||
|
||||
assert constants.get_config(cfgparser, 'defaults', 'unknown', 'ANSIBLE_TEST_VAR', 'foo', value_type=None) == 'bar'
|
||||
assert constants.get_config(cfgparser, 'unknown', 'defaults_one', 'ANSIBLE_TEST_VAR', 'foo', value_type=None) == 'bar'
|
||||
|
||||
del os.environ['ANSIBLE_TEST_VAR']
|
||||
|
||||
def test_from_default(self, cfgparser):
|
||||
assert constants.get_config(cfgparser, 'defaults', 'unknown', 'ANSIBLE_TEST_VAR', 'foo', value_type=None) == u'foo'
|
||||
assert constants.get_config(cfgparser, 'unknown', 'defaults_one', 'ANSIBLE_TEST_VAR', 'foo', value_type=None) == u'foo'
|
||||
|
||||
def test_value_type_boolean(self, cfgparser):
|
||||
assert constants.get_config(cfgparser, 'defaults', 'unknown', 'ANSIBLE_TEST_VAR', 'on', value_type='boolean') is True
|
||||
assert constants.get_config(cfgparser, 'defaults', 'unknown', 'ANSIBLE_TEST_VAR', True, value_type='boolean') is True
|
||||
assert constants.get_config(cfgparser, 'defaults', 'unknown', 'ANSIBLE_TEST_VAR', 'other', value_type='boolean') is False
|
||||
|
||||
def test_value_type_integer(self, cfgparser):
|
||||
assert constants.get_config(cfgparser, 'defaults', 'unknown', 'ANSIBLE_TEST_VAR', '10', value_type='integer') == 10
|
||||
assert constants.get_config(cfgparser, 'defaults', 'unknown', 'ANSIBLE_TEST_VAR', 10, value_type='integer') == 10
|
||||
|
||||
def test_value_type_float(self, cfgparser):
|
||||
assert constants.get_config(cfgparser, 'defaults', 'unknown', 'ANSIBLE_TEST_VAR', '10', value_type='float') == 10.0
|
||||
assert constants.get_config(cfgparser, 'defaults', 'unknown', 'ANSIBLE_TEST_VAR', 10, value_type='float') == 10.0
|
||||
assert constants.get_config(cfgparser, 'defaults', 'unknown', 'ANSIBLE_TEST_VAR', '11.5', value_type='float') == 11.5
|
||||
assert constants.get_config(cfgparser, 'defaults', 'unknown', 'ANSIBLE_TEST_VAR', 11.5, value_type='float') == 11.5
|
||||
|
||||
def test_value_type_list(self, cfgparser):
|
||||
assert constants.get_config(cfgparser, 'defaults', 'unknown', 'ANSIBLE_TEST_VAR', 'one,two,three', value_type='list') == ['one', 'two', 'three']
|
||||
assert constants.get_config(cfgparser, 'defaults', 'unknown', 'ANSIBLE_TEST_VAR', ['one', 'two', 'three'], value_type='list') == ['one', 'two', 'three']
|
||||
|
||||
def test_value_type_none(self, cfgparser):
|
||||
assert constants.get_config(cfgparser, 'defaults', 'unknown', 'ANSIBLE_TEST_VAR', 'None', value_type='none') is None
|
||||
assert constants.get_config(cfgparser, 'defaults', 'unknown', 'ANSIBLE_TEST_VAR', None, value_type='none') is None
|
||||
|
||||
def test_value_type_path(self, cfgparser, user, cfg_file):
|
||||
assert constants.get_config(cfgparser, 'defaults', 'unknown', 'ANSIBLE_TEST_VAR', '~/local', value_type='path') == os.path.join(user['home'], 'local')
|
||||
assert constants.get_config(cfgparser, 'defaults', 'unknown', 'ANSIBLE_TEST_VAR', 'local', value_type='path') == 'local'
|
||||
assert constants.get_config(cfgparser, 'defaults', 'unknown', 'ANSIBLE_TEST_VAR', 'local', value_type='path', expand_relative_paths=True) \
|
||||
== os.path.join(cfg_file, 'local')
|
||||
|
||||
# Need to implement tests for these
|
||||
# def test_value_type_pathlist(self, cfgparser):
|
||||
# pass
|
||||
#
|
||||
# def test_value_type_string(self, cfgparser):
|
||||
# pass
|
||||
#
|
||||
# def test_value_type_temppath(self, cfgparser):
|
||||
# pass
|
||||
|
||||
|
||||
# Need to test this
|
||||
# def test_load_config_file():
|
||||
# pass
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue