From 5d1536a7c509fd3ce292442e2dcf45d42a68e4f1 Mon Sep 17 00:00:00 2001 From: Juha Litola Date: Fri, 25 Jan 2013 13:29:39 +0200 Subject: [PATCH 1/2] Fixed add_key stalling indefinitely, and test code leaking into production setting --- apt_key | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/apt_key b/apt_key index dcc4d12717f..8e521a4751a 100644 --- a/apt_key +++ b/apt_key @@ -105,7 +105,7 @@ def download_key(url): def add_key(key): - return call("apt-key add -", shell=True, stdin=PIPE, stdout=PIPE, stderr=PIPE) + p = Popen("apt-key add -", shell=True, stdin=PIPE, stdout=PIPE, stderr=PIPE) (_, _) = p.communicate(key) return p.returncode == 0 @@ -163,12 +163,12 @@ if 'ANSIBLE_TEST_APT_KEY' in environ: return extra -if environ.get('ANSIBLE_TEST_APT_KEY') == 'none': - def key_present(key_id): - return False -else: - def key_present(key_id): - return key_id == environ['ANSIBLE_TEST_APT_KEY'] + if environ.get('ANSIBLE_TEST_APT_KEY') == 'none': + def key_present(key_id): + return False + else: + def key_present(key_id): + return key_id == environ['ANSIBLE_TEST_APT_KEY'] def main(): From 6e2d401a01beab3e36ac940549ca5b2c6b62b160 Mon Sep 17 00:00:00 2001 From: Juha Litola Date: Fri, 25 Jan 2013 17:10:04 +0200 Subject: [PATCH 2/2] Removed apt_key tests, as they didn't test the real functionality. Tests used heavily mocked version of the apt_key code, which meant that it didn't properly test real life scenario. --- apt_key | 50 -------------------------------------------------- 1 file changed, 50 deletions(-) diff --git a/apt_key b/apt_key index 8e521a4751a..14d1b734fda 100644 --- a/apt_key +++ b/apt_key @@ -121,56 +121,6 @@ def return_values(tb=False): else: return {} - -# use cues from the environment to mock out functions for testing -if 'ANSIBLE_TEST_APT_KEY' in environ: - orig_download_key = download_key - KEY_ADDED=0 - KEY_REMOVED=0 - KEY_DOWNLOADED=0 - - - def download_key(url): - global KEY_DOWNLOADED - KEY_DOWNLOADED += 1 - return orig_download_key(url) - - - def find_missing_binaries(): - return [] - - - def add_key(key): - global KEY_ADDED - KEY_ADDED += 1 - return True - - - def remove_key(key_id): - global KEY_REMOVED - KEY_REMOVED += 1 - return True - - - def return_values(tb=False): - extra = dict( - added=KEY_ADDED, - removed=KEY_REMOVED, - downloaded=KEY_DOWNLOADED - ) - if tb: - extra['exception'] = format_exc() - return extra - - - if environ.get('ANSIBLE_TEST_APT_KEY') == 'none': - def key_present(key_id): - return False - else: - def key_present(key_id): - return key_id == environ['ANSIBLE_TEST_APT_KEY'] - - def main(): module = AnsibleModule( argument_spec=dict(