From 217ff4498c6ac75e51e8e80021c2afef4e34e865 Mon Sep 17 00:00:00 2001 From: Pilou Date: Wed, 17 Jan 2018 15:33:33 +0100 Subject: [PATCH] ansible-config: add simple tests (#34900) * Revert "Fix ansible-config with python3 (#34673)" This reverts commit 2a9daaa45b0252cd935c48b5d0ab4b581aa16e32. * ansible-config: add simple tests * Fix ansible-config with python3 * ansible-test: don't quote "unusual" characters --- lib/ansible/cli/config.py | 4 ++-- lib/ansible/config/manager.py | 2 +- test/integration/targets/ansible/ansible-testé.cfg | 2 ++ test/integration/targets/ansible/runme.sh | 10 +++++++++- test/runner/lib/git.py | 7 +++++-- 5 files changed, 19 insertions(+), 6 deletions(-) create mode 100644 test/integration/targets/ansible/ansible-testé.cfg diff --git a/lib/ansible/cli/config.py b/lib/ansible/cli/config.py index e22a607df10..17a67584f9a 100644 --- a/lib/ansible/cli/config.py +++ b/lib/ansible/cli/config.py @@ -68,11 +68,11 @@ class ConfigCLI(CLI): super(ConfigCLI, self).run() if self.options.config_file: - self.config_file = to_bytes(unfrackpath(self.options.config_file, follow=False)) + self.config_file = unfrackpath(self.options.config_file, follow=False) self.config = ConfigManager(self.config_file) else: self.config = ConfigManager() - self.config_file = to_bytes(find_ini_config_file()) + self.config_file = find_ini_config_file() try: if not os.path.exists(self.config_file): raise AnsibleOptionsError("%s does not exist or is not accessible" % (self.config_file)) diff --git a/lib/ansible/config/manager.py b/lib/ansible/config/manager.py index db9e08b57f0..49972adb68a 100644 --- a/lib/ansible/config/manager.py +++ b/lib/ansible/config/manager.py @@ -116,7 +116,7 @@ def get_config_type(cfile): ftype = None if cfile is not None: - ext = to_text(os.path.splitext(cfile)[-1]) + ext = os.path.splitext(cfile)[-1] if ext in ('.ini', '.cfg'): ftype = 'ini' elif ext in ('.yaml', '.yml'): diff --git a/test/integration/targets/ansible/ansible-testé.cfg b/test/integration/targets/ansible/ansible-testé.cfg new file mode 100644 index 00000000000..61a99f48bbd --- /dev/null +++ b/test/integration/targets/ansible/ansible-testé.cfg @@ -0,0 +1,2 @@ +[defaults] +remote_user = admin diff --git a/test/integration/targets/ansible/runme.sh b/test/integration/targets/ansible/runme.sh index 537351ffb3f..5fada97789c 100755 --- a/test/integration/targets/ansible/runme.sh +++ b/test/integration/targets/ansible/runme.sh @@ -1,9 +1,17 @@ #!/usr/bin/env bash -set -eux +set -eux -o pipefail ansible --version ansible --help ansible testhost -i ../../inventory -m ping "$@" ansible testhost -i ../../inventory -m setup "$@" + +ansible-config -c ./ansible-testé.cfg view | grep 'remote_user = admin' +ansible-config -c ./ansible-testé.cfg dump | grep 'DEFAULT_REMOTE_USER([^)]*) = admin\>' +ANSIBLE_REMOTE_USER=administrator ansible-config dump| grep 'DEFAULT_REMOTE_USER([^)]*) = administrator\>' +ansible-config list | grep 'DEFAULT_REMOTE_USER' + +# 'view' command must fail when config file is missing +ansible-config -c ./ansible-non-existent.cfg view && exit 1 || echo 'Failure is expected' diff --git a/test/runner/lib/git.py b/test/runner/lib/git.py index f34b0ee42d9..9fbc91c0241 100644 --- a/test/runner/lib/git.py +++ b/test/runner/lib/git.py @@ -18,13 +18,16 @@ class Git(object): self.args = args self.git = 'git' - def get_diff(self, args): + def get_diff(self, args, git_options=None): """ :type args: list[str] + :type options: list[str] :rtype: list[str] """ cmd = ['diff'] + args - return self.run_git_split(cmd, '\n', str_errors='replace') + if git_options is None: + git_options = ['-c', 'core.quotePath='] + return self.run_git_split(git_options + cmd, '\n', str_errors='replace') def get_diff_names(self, args): """