From f58f0c62e1c88d32f913c556e7e91ac00556ae9e Mon Sep 17 00:00:00 2001 From: Marius Gedminas Date: Fri, 16 Oct 2015 09:10:25 +0300 Subject: [PATCH 1/5] Fix test on Python 3: vault code expects bytes --- test/units/parsing/vault/test_vault.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/test/units/parsing/vault/test_vault.py b/test/units/parsing/vault/test_vault.py index ac5a500173..cefe11107c 100644 --- a/test/units/parsing/vault/test_vault.py +++ b/test/units/parsing/vault/test_vault.py @@ -78,17 +78,17 @@ class TestVaultLib(unittest.TestCase): def test_format_output(self): v = VaultLib('ansible') v.cipher_name = "TEST" - sensitive_data = "ansible" + sensitive_data = b"ansible" data = v._format_output(sensitive_data) lines = data.split(b'\n') assert len(lines) > 1, "failed to properly add header" - header = to_unicode(lines[0]) - assert header.endswith(';TEST'), "header does end with cipher name" - header_parts = header.split(';') + header = to_bytes(lines[0]) + assert header.endswith(b';TEST'), "header does end with cipher name" + header_parts = header.split(b';') assert len(header_parts) == 3, "header has the wrong number of parts" - assert header_parts[0] == '$ANSIBLE_VAULT', "header does not start with $ANSIBLE_VAULT" + assert header_parts[0] == b'$ANSIBLE_VAULT', "header does not start with $ANSIBLE_VAULT" assert header_parts[1] == v.b_version, "header version is incorrect" - assert header_parts[2] == 'TEST', "header does end with cipher name" + assert header_parts[2] == b'TEST', "header does end with cipher name" def test_split_header(self): v = VaultLib('ansible') From a1d95536f9c4202015c6f07ea27e97e867d2f3a4 Mon Sep 17 00:00:00 2001 From: Marius Gedminas Date: Fri, 16 Oct 2015 09:11:34 +0300 Subject: [PATCH 2/5] Fix test on Python 3: vault code expects bytes (Different test than the last commit.) --- test/units/parsing/vault/test_vault.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/units/parsing/vault/test_vault.py b/test/units/parsing/vault/test_vault.py index cefe11107c..095a2af4b5 100644 --- a/test/units/parsing/vault/test_vault.py +++ b/test/units/parsing/vault/test_vault.py @@ -97,7 +97,7 @@ class TestVaultLib(unittest.TestCase): lines = rdata.split(b'\n') assert lines[0] == b"ansible" assert v.cipher_name == 'TEST', "cipher name was not set" - assert v.b_version == "9.9" + assert v.b_version == b"9.9" def test_encrypt_decrypt_aes(self): if not HAS_AES or not HAS_COUNTER or not HAS_PBKDF2: From 5c70f932bda1d29331502b6c8c85d6496abc65dc Mon Sep 17 00:00:00 2001 From: Marius Gedminas Date: Fri, 16 Oct 2015 09:12:49 +0300 Subject: [PATCH 3/5] Fix test on Python 3: vault code expects bytes (Third failing test out of four.) --- test/units/parsing/vault/test_vault.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/units/parsing/vault/test_vault.py b/test/units/parsing/vault/test_vault.py index 095a2af4b5..20b6f6bdd6 100644 --- a/test/units/parsing/vault/test_vault.py +++ b/test/units/parsing/vault/test_vault.py @@ -106,9 +106,9 @@ class TestVaultLib(unittest.TestCase): v.cipher_name = u'AES' # AES encryption code has been removed, so this is old output for # AES-encrypted 'foobar' with password 'ansible'. - enc_data = '$ANSIBLE_VAULT;1.1;AES\n53616c7465645f5fc107ce1ef4d7b455e038a13b053225776458052f8f8f332d554809d3f150bfa3\nfe3db930508b65e0ff5947e4386b79af8ab094017629590ef6ba486814cf70f8e4ab0ed0c7d2587e\n786a5a15efeb787e1958cbdd480d076c\n' + enc_data = b'$ANSIBLE_VAULT;1.1;AES\n53616c7465645f5fc107ce1ef4d7b455e038a13b053225776458052f8f8f332d554809d3f150bfa3\nfe3db930508b65e0ff5947e4386b79af8ab094017629590ef6ba486814cf70f8e4ab0ed0c7d2587e\n786a5a15efeb787e1958cbdd480d076c\n' dec_data = v.decrypt(enc_data) - assert dec_data == "foobar", "decryption failed" + assert dec_data == b"foobar", "decryption failed" def test_encrypt_decrypt_aes256(self): if not HAS_AES or not HAS_COUNTER or not HAS_PBKDF2: From ec3ada1cda351bb5b2b8932f3686262354f80782 Mon Sep 17 00:00:00 2001 From: Marius Gedminas Date: Fri, 16 Oct 2015 09:13:46 +0300 Subject: [PATCH 4/5] Fix test on Python 3: vault code expects bytes (All tests now succeed on Python 3.5) --- test/units/parsing/vault/test_vault.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/test/units/parsing/vault/test_vault.py b/test/units/parsing/vault/test_vault.py index 20b6f6bdd6..1b48b07169 100644 --- a/test/units/parsing/vault/test_vault.py +++ b/test/units/parsing/vault/test_vault.py @@ -115,10 +115,10 @@ class TestVaultLib(unittest.TestCase): raise SkipTest v = VaultLib('ansible') v.cipher_name = 'AES256' - enc_data = v.encrypt("foobar") + enc_data = v.encrypt(b"foobar") dec_data = v.decrypt(enc_data) - assert enc_data != "foobar", "encryption failed" - assert dec_data == "foobar", "decryption failed" + assert enc_data != b"foobar", "encryption failed" + assert dec_data == b"foobar", "decryption failed" def test_encrypt_encrypted(self): if not HAS_AES or not HAS_COUNTER or not HAS_PBKDF2: From a412b27604ca78202b700f8865eeb74e5bb00dd5 Mon Sep 17 00:00:00 2001 From: Marius Gedminas Date: Fri, 16 Oct 2015 09:14:36 +0300 Subject: [PATCH 5/5] Enable unit tests on Python 3.5 This enables the tests in tox and in Travis. This ought to prevent regressions in Python 3 support. Note that Python 3.4 isn't supported (yet) because the vault code relies on %-formatting of byte strings, a feature that was ripped out of Python 3.0 and restored in 3.5. Also note that passing tests don't mean that Ansible itself can already be used with Python 3.5: test coverage is only 53%. --- tox.ini | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tox.ini b/tox.ini index ec700764ff..72550f2ced 100644 --- a/tox.ini +++ b/tox.ini @@ -10,4 +10,4 @@ commands = py27: python -m compileall -fq -x 'test|samples' lib test contrib py{34,35}: python -m compileall -fq -x 'lib/ansible/module_utils|lib/ansible/modules' lib test contrib # Unittests need lots of work to make code python3 compatible - py{26,27}: make tests + py{26,27,35}: make tests