From 598b9c6b7ccdbbc78c1450a404e723ff991bd8d6 Mon Sep 17 00:00:00 2001 From: Richard C Isaacson Date: Wed, 12 Feb 2014 10:01:10 -0600 Subject: [PATCH] Cleanup per notes. Some small changes to per notes from @mpdehann. --- .../runner/action_plugins/unarchive.py | 2 +- library/files/unarchive | 12 +++---- test/TestPlayBook.py | 6 ++-- test/playbook-unarchive.yml | 36 ++++++++++++------- 4 files changed, 34 insertions(+), 22 deletions(-) diff --git a/lib/ansible/runner/action_plugins/unarchive.py b/lib/ansible/runner/action_plugins/unarchive.py index eecae9f551..3e5f98ccae 100644 --- a/lib/ansible/runner/action_plugins/unarchive.py +++ b/lib/ansible/runner/action_plugins/unarchive.py @@ -63,7 +63,7 @@ class ActionModule(object): remote_md5 = self.runner._remote_md5(conn, tmp, dest) if remote_md5 != '3': - result = dict(failed=True, msg="dest must be an existing dir", rc=remote_md5) + result = dict(failed=True, msg="dest must be an existing dir") return ReturnData(conn=conn, result=result) if copy: diff --git a/library/files/unarchive b/library/files/unarchive index ceb0f353bb..661f389969 100644 --- a/library/files/unarchive +++ b/library/files/unarchive @@ -69,7 +69,7 @@ import os # class to handle .zip files -class _zipfile(object): +class ZipFile(object): def __init__(self, src, dest, module): self.src = src @@ -93,7 +93,7 @@ class _zipfile(object): # class to handle gzipped tar files -class _tgzfile(object): +class TgzFile(object): def __init__(self, src, dest, module): self.src = src @@ -124,7 +124,7 @@ class _tgzfile(object): # class to handle tar files that aren't compressed -class _tarfile(_tgzfile): +class TarFile(TgzFile): def __init__(self, src, dest, module): self.src = src self.dest = dest @@ -133,7 +133,7 @@ class _tarfile(_tgzfile): # class to handle bzip2 compressed tar files -class _tarbzip(_tgzfile): +class TarBzip(TgzFile): def __init__(self, src, dest, module): self.src = src self.dest = dest @@ -142,7 +142,7 @@ class _tarbzip(_tgzfile): # class to handle xz compressed tar files -class _tarxz(_tgzfile): +class TarXz(TgzFile): def __init__(self, src, dest, module): self.src = src self.dest = dest @@ -152,7 +152,7 @@ class _tarxz(_tgzfile): # try handlers in order and return the one that works or bail if none work def pick_handler(src, dest, module): - handlers = [_tgzfile, _zipfile, _tarfile, _tarbzip, _tarxz] + handlers = [TgzFile, ZipFile, TarFile, TarBzip, TarXz] for handler in handlers: obj = handler(src, dest, module) if obj.can_handle_archive(): diff --git a/test/TestPlayBook.py b/test/TestPlayBook.py index 775b84fe7f..ab61812acf 100644 --- a/test/TestPlayBook.py +++ b/test/TestPlayBook.py @@ -416,10 +416,10 @@ class TestPlaybook(unittest.TestCase): expected = { "localhost": { - "changed": 41, + "changed": 29, "failures": 0, - "ok": 45, - "skipped": 0, + "ok": 33, + "skipped": 12, "unreachable": 0 } } diff --git a/test/playbook-unarchive.yml b/test/playbook-unarchive.yml index 078cfb7720..f92a489476 100644 --- a/test/playbook-unarchive.yml +++ b/test/playbook-unarchive.yml @@ -14,10 +14,12 @@ - unarchive: src={{filesdir}}/test.tar dest={{testdir}} register: res - command: test -f {{testdir}}/foo - - command: test "{{res.changed}}" = "True" + - fail: msg="Resource was expected to be changed." + when: not res|changed - unarchive: src={{filesdir}}/test.tar dest={{testdir}} register: res - - command: test "{{res.changed}}" = "False" + - fail: msg="Resource was not expected to be changed." + when: res|changed - name: "Simple tar.gz unarchive." command: rm -rf {{testdir}} @@ -25,10 +27,12 @@ - unarchive: src={{filesdir}}/test.tar.gz dest={{testdir}} register: res - command: test -f {{testdir}}/foo - - command: test "{{res.changed}}" = "True" + - fail: msg="Resource was expected to be changed." + when: not res|changed - unarchive: src={{filesdir}}/test.tar.gz dest={{testdir}} register: res - - command: test "{{res.changed}}" = "False" + - fail: msg="Resource was not expected to be changed." + when: res|changed - name: "Simple zip unarchive." command: rm -rf {{testdir}} @@ -36,10 +40,12 @@ - unarchive: src={{filesdir}}/test.zip dest={{testdir}} register: res - command: test -f {{testdir}}/foo - - command: test "{{res.changed}}" = "True" + - fail: msg="Resource was expected to be changed." + when: not res|changed - unarchive: src={{filesdir}}/test.zip dest={{testdir}} register: res - - command: test "{{res.changed}}" = "True" + - fail: msg="Resource was expected to be changed." + when: not res|changed - name: "Unarchive a local tar file." command : rm -rf {{testdir}} @@ -48,10 +54,12 @@ - unarchive: src={{testdir}}/test.tar dest={{testdir}} register: res - command: test -f {{testdir}}/foo - - command: test "{{res.changed}}" = "True" + - fail: msg="Resource was expected to be changed." + when: not res|changed - unarchive: src={{testdir}}/test.tar dest={{testdir}} register: res - - command: test "{{res.changed}}" = "False" + - fail: msg="Resource was not expected to be changed." + when: res|changed - name: "Unarchive a local tar.gz file." command : rm -rf {{testdir}} @@ -60,10 +68,12 @@ - unarchive: src={{testdir}}/test.tar.gz dest={{testdir}} register: res - command: test -f {{testdir}}/foo - - command: test "{{res.changed}}" = "True" + - fail: msg="Resource was expected to be changed." + when: not res|changed - unarchive: src={{testdir}}/test.tar.gz dest={{testdir}} register: res - - command: test "{{res.changed}}" = "False" + - fail: msg="Resource was not expected to be changed." + when: res|changed - name: "Unarchive a local zip file." command : rm -rf {{testdir}} @@ -72,7 +82,9 @@ - unarchive: src={{testdir}}/test.zip dest={{testdir}} register: res - command: test -f {{testdir}}/foo - - command: test "{{res.changed}}" = "True" + - fail: msg="Resource was expected to be changed." + when: not res|changed - unarchive: src={{testdir}}/test.zip dest={{testdir}} register: res - - command: test "{{res.changed}}" = "True" + - fail: msg="Resource was expected to be changed." + when: not res|changed