From 508047a71ea5d6b1ae3b8a58e9742d48b2b3e7e2 Mon Sep 17 00:00:00 2001 From: Toshio Kuratomi Date: Mar 29 2017 02:30:38 +0000 Subject: 2.2.2.0 final Add new patch to fix unittests --- diff --git a/0001-Fix-for-tests-run-with-no-.ssh-user-dir.patch b/0001-Fix-for-tests-run-with-no-.ssh-user-dir.patch new file mode 100644 index 0000000..8bc97f3 --- /dev/null +++ b/0001-Fix-for-tests-run-with-no-.ssh-user-dir.patch @@ -0,0 +1,68 @@ +From 212a1b305da847798557c73b24417a8615c0245e Mon Sep 17 00:00:00 2001 +From: Toshio Kuratomi +Date: Tue, 28 Mar 2017 16:21:06 -0700 +Subject: [PATCH] Fix for tests run with no .ssh user dir + +When building in automated build systems, there are sometimes cases +where the user doing the building does not have a .ssh directory. In +this case, we need to mock out some os.path functions so that the +add_host_key() function we're testing won't complain or try to create +one. +--- + test/units/module_utils/test_known_hosts.py | 29 ++++++++++++++++++----------- + 1 file changed, 18 insertions(+), 11 deletions(-) + +diff --git a/test/units/module_utils/test_known_hosts.py b/test/units/module_utils/test_known_hosts.py +index 0bc8e55..afd93fc 100644 +--- a/test/units/module_utils/test_known_hosts.py ++++ b/test/units/module_utils/test_known_hosts.py +@@ -16,12 +16,13 @@ + # You should have received a copy of the GNU General Public License + # along with Ansible. If not, see . + +-from ansible.compat.tests import unittest +-from ansible.module_utils import known_hosts +- + import json ++import os.path ++ + import ansible.module_utils.basic +-from ansible.compat.tests.mock import Mock ++from ansible.compat.tests import unittest ++from ansible.compat.tests.mock import Mock, patch ++from ansible.module_utils import known_hosts + from units.mock.procenv import swap_stdin_and_argv + + +@@ -91,15 +92,21 @@ class TestAnsibleModuleKnownHosts(unittest.TestCase): + ansible.module_utils.basic._ANSIBLE_ARGS = None + self.module = ansible.module_utils.basic.AnsibleModule(argument_spec=dict()) + ++ get_bin_path = Mock() ++ get_bin_path.return_value = keyscan_cmd = "/custom/path/ssh-keyscan" ++ self.module.get_bin_path = get_bin_path ++ + run_command = Mock() + run_command.return_value = (0, "Needs output, otherwise thinks ssh-keyscan timed out'", "") + self.module.run_command = run_command + +- get_bin_path = Mock() +- get_bin_path.return_value = keyscan_cmd = "/custom/path/ssh-keyscan" +- self.module.get_bin_path = get_bin_path ++ append_to_file = Mock() ++ append_to_file.return_value = (None,) ++ self.module.append_to_file = append_to_file + +- for u in self.urls: +- if self.urls[u]['is_ssh_url']: +- known_hosts.add_host_key(self.module, self.urls[u]['get_fqdn'], port=self.urls[u]['port']) +- run_command.assert_called_with(keyscan_cmd + self.urls[u]['add_host_key_cmd']) ++ with patch('os.path.isdir', return_value=True): ++ with patch('os.path.exists', return_value=True): ++ for u in self.urls: ++ if self.urls[u]['is_ssh_url']: ++ known_hosts.add_host_key(self.module, self.urls[u]['get_fqdn'], port=self.urls[u]['port']) ++ run_command.assert_called_with(keyscan_cmd + self.urls[u]['add_host_key_cmd']) +-- +2.9.3 + diff --git a/0001-Make-openvswitch-pass-py3-sanity-check.patch b/0001-Make-openvswitch-pass-py3-sanity-check.patch deleted file mode 100644 index 7f5ebbe..0000000 --- a/0001-Make-openvswitch-pass-py3-sanity-check.patch +++ /dev/null @@ -1,70 +0,0 @@ -From 18098ad055c3159adcbe1a151bbd1f3b71b653f5 Mon Sep 17 00:00:00 2001 -From: Toshio Kuratomi -Date: Wed, 8 Mar 2017 12:32:47 -0800 -Subject: [PATCH] Make openvswitch* pass py3 sanity check - -(cherry picked from 7f4fdba0c6ab1a00e8be2fc517173d898f305a23) - -diff --git a/network/openvswitch_bridge.py b/network/openvswitch_bridge.py -index 68528dd..abe89df 100644 ---- a/lib/ansible/modules/extras/network/openvswitch_bridge.py -+++ b/lib/ansible/modules/extras/network/openvswitch_bridge.py -@@ -143,7 +143,8 @@ class OVSBridge(object): - changed = True - elif self.state == 'present' and not self.exists(): - changed = True -- except Exception, earg: -+ except Exception: -+ earg = get_exception() - self.module.fail_json(msg=str(earg)) - - # pylint: enable=W0703 -@@ -189,7 +190,8 @@ class OVSBridge(object): - self.set_external_id(key, None)): - changed = True - -- except Exception, earg: -+ except Exception: -+ earg = get_exception() - self.module.fail_json(msg=str(earg)) - # pylint: enable=W0703 - self.module.exit_json(changed=changed) -@@ -267,4 +269,5 @@ def main(): - - # import module snippets - from ansible.module_utils.basic import * -+from ansible.module_utils.pycompat24 import get_exception - main() -diff --git a/network/openvswitch_port.py b/network/openvswitch_port.py -index c2224b5..d2bf31a 100644 ---- a/lib/ansible/modules/extras/network/openvswitch_port.py -+++ b/lib/ansible/modules/extras/network/openvswitch_port.py -@@ -204,7 +204,8 @@ class OVSPort(object): - changed = True - else: - changed = False -- except Exception, earg: -+ except Exception: -+ earg = get_exception() - self.module.fail_json(msg=str(earg)) - self.module.exit_json(changed=changed) - -@@ -235,7 +236,8 @@ class OVSPort(object): - external_id = fmt_opt % (self.port, key, value) - changed = self.set(external_id) or changed - ## -- except Exception, earg: -+ except Exception: -+ earg = get_exception() - self.module.fail_json(msg=str(earg)) - self.module.exit_json(changed=changed) - -@@ -269,4 +271,5 @@ def main(): - - # import module snippets - from ansible.module_utils.basic import * -+from ansible.module_utils.pycompat24 import get_exception - main() --- -2.9.3 - diff --git a/ansible.spec b/ansible.spec index 0f36176..6959cd2 100644 --- a/ansible.spec +++ b/ansible.spec @@ -20,11 +20,11 @@ BuildRoot: %{_tmppath}/%{name}-%{version}-%{release}-buildroot Name: ansible Summary: SSH-based configuration management, deployment, and task execution system Version: 2.2.2.0 -Release: 0.4.rc1%{?dist} +Release: 1%{?dist} Group: Development/Libraries License: GPLv3+ -Source0: http://releases.ansible.com/ansible/%{name}-%{version}-0.1.rc1.tar.gz +Source0: http://releases.ansible.com/ansible/%{name}-%{version}.tar.gz # To retrieve the unittests, run: # ./get-unittests.sh 2.2.2.0 v2.2.2.0-1 # Replace the first parameter with the version you want in the tarball name @@ -41,7 +41,9 @@ Patch0: ansible-2.1.0.0-control_path.patch Patch1: 0001-Handle-downstream-version-additions.patch # Upstream change to fix python3 compilation for openvswitch modules -Patch2: 0001-Make-openvswitch-pass-py3-sanity-check.patch +#Patch2: 0001-Make-openvswitch-pass-py3-sanity-check.patch +# Upstream fix to a unittest +Patch2: 0001-Fix-for-tests-run-with-no-.ssh-user-dir.patch # Patch to utilize a newer jinja2 package on epel6 # Non-upstreamable as it creates a dependency on a specific version of jinja. @@ -74,6 +76,7 @@ BuildRequires: python-paramiko BuildRequires: python-keyczar BuildRequires: python-six BuildRequires: python-nose +BuildRequires: python-pytest BuildRequires: python-coverage BuildRequires: python-mock BuildRequires: python-boto3 @@ -197,6 +200,9 @@ This package installs versions of ansible that execute on Python3. %prep %setup -q +# Unittests +tar -xJvf %{SOURCE1} + # RHEL7 doesn't have a recent enough ssh client to use this patch (needs to # support %C in ControlPath). So only apply it on Fedora. %if 0%{?fedora} @@ -210,9 +216,6 @@ This package installs versions of ansible that execute on Python3. %patch100 -p1 %endif -# Unittests -tar -xJvf %{SOURCE1} - %if 0%{?with_python3} rm -rf %{py3dir} cp -a . %{py3dir} @@ -286,6 +289,10 @@ rm -rf $RPM_BUILD_ROOT %doc %{_mandir}/man1/ansible* %changelog +* Tue Mar 28 2017 Toshio Kuratomi - - 2.2.2.0-1 +- 2.2.2.0 final +- Add new patch to fix unittests + * Mon Mar 27 2017 Toshio Kuratomi - - 2.2.2.0-0.4.rc1 - Add python-crypto and python3-crypto as explicit requirements