From c523448420fe2038823de7d63746c093334a3672 Mon Sep 17 00:00:00 2001 From: rallytime Date: Tue, 3 Feb 2015 11:15:45 -0700 Subject: [PATCH 1/8] Python 3 compatability for schedule.py --- salt/utils/schedule.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/salt/utils/schedule.py b/salt/utils/schedule.py index dd7bd8c5b5..6f5320754a 100644 --- a/salt/utils/schedule.py +++ b/salt/utils/schedule.py @@ -233,6 +233,7 @@ from salt.utils.process import os_is_running # Import 3rd-party libs import yaml import salt.ext.six as six + # pylint: disable=import-error try: import dateutil.parser as dateutil_parser @@ -522,7 +523,7 @@ class Schedule(object): argspec = salt.utils.args.get_function_argspec(self.functions[func]) if argspec.keywords: # this function accepts **kwargs, pack in the publish data - for key, val in ret.iteritems(): + for key, val in six.iteritems(ret): kwargs['__pub_{0}'.format(key)] = val try: From fab28bb1edceef27ed2f316b47c68eb8c2e2e449 Mon Sep 17 00:00:00 2001 From: rallytime Date: Tue, 3 Feb 2015 11:22:51 -0700 Subject: [PATCH 2/8] Python 3 compat for mixins.py --- salt/client/mixins.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/salt/client/mixins.py b/salt/client/mixins.py index df3ab12804..2a68b1411c 100644 --- a/salt/client/mixins.py +++ b/salt/client/mixins.py @@ -72,7 +72,7 @@ class ClientFuncsDict(collections.MutableMapping): } pub_data = {} # pull out pub_data if you have it - for k, v in kwargs.items(): + for k, v in list(kwargs.items()): if k.startswith('__pub_'): pub_data[k] = kwargs.pop(k) From 79e6ea90b129d9561661555646f7743d2c2c9e9e Mon Sep 17 00:00:00 2001 From: rallytime Date: Tue, 3 Feb 2015 11:25:24 -0700 Subject: [PATCH 3/8] Python 3 compat for sudo.py --- salt/modules/sudo.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/salt/modules/sudo.py b/salt/modules/sudo.py index 40cd069bfc..634579cf5d 100644 --- a/salt/modules/sudo.py +++ b/salt/modules/sudo.py @@ -2,8 +2,11 @@ ''' Allow for the calling of execution modules via sudo ''' + # Import python libs +from __future__ import absolute_import import json + # Import salt libs import salt.utils import salt.syspaths From d2d42e522f6c434e5da5fb54f1743b88f6303c04 Mon Sep 17 00:00:00 2001 From: rallytime Date: Tue, 3 Feb 2015 11:28:03 -0700 Subject: [PATCH 4/8] Python 3 compat and additions to ldapmod_test --- tests/unit/modules/ldapmod_test.py | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/tests/unit/modules/ldapmod_test.py b/tests/unit/modules/ldapmod_test.py index a05240e04a..2e3a3ef4b2 100644 --- a/tests/unit/modules/ldapmod_test.py +++ b/tests/unit/modules/ldapmod_test.py @@ -3,6 +3,10 @@ :codeauthor: :email:`Jayesh Kariya ` ''' +# Import python libs +from __future__ import absolute_import +import time + # Import Salt Testing Libs from salttesting import TestCase, skipIf from salttesting.mock import ( @@ -11,13 +15,13 @@ from salttesting.mock import ( NO_MOCK, NO_MOCK_REASON ) +from salttesting.helpers import ensure_in_syspath + +ensure_in_syspath('../../') # Import Salt Libs from salt.modules import ldapmod -# Import Python Libs -import time - # Globals ldapmod.__salt__ = {} From 244ba09cfc89167d91e1add28aca1336838511b2 Mon Sep 17 00:00:00 2001 From: rallytime Date: Tue, 3 Feb 2015 11:34:49 -0700 Subject: [PATCH 5/8] Python 3 compat for several new test files --- tests/unit/modules/etcd_mod_test.py | 6 ++++++ tests/unit/modules/introspect_test.py | 6 ++++++ tests/unit/modules/iptables_test.py | 8 +++++++- tests/unit/modules/locate_test.py | 6 ++++++ tests/unit/modules/logrotate_test.py | 6 ++++++ tests/unit/modules/munin_test.py | 6 ++++++ 6 files changed, 37 insertions(+), 1 deletion(-) diff --git a/tests/unit/modules/etcd_mod_test.py b/tests/unit/modules/etcd_mod_test.py index 353b658bab..65e8105a99 100644 --- a/tests/unit/modules/etcd_mod_test.py +++ b/tests/unit/modules/etcd_mod_test.py @@ -3,6 +3,9 @@ :codeauthor: :email:`Jayesh Kariya ` ''' +# Import Python Libs +from __future__ import absolute_import + # Import Salt Testing Libs from salttesting import TestCase, skipIf from salttesting.mock import ( @@ -11,6 +14,9 @@ from salttesting.mock import ( NO_MOCK, NO_MOCK_REASON ) +from salttesting.helpers import ensure_in_syspath + +ensure_in_syspath('../../') # Import Salt Libs from salt.modules import etcd_mod diff --git a/tests/unit/modules/introspect_test.py b/tests/unit/modules/introspect_test.py index 63f159ba71..6245774005 100644 --- a/tests/unit/modules/introspect_test.py +++ b/tests/unit/modules/introspect_test.py @@ -3,6 +3,9 @@ :codeauthor: :email:`Jayesh Kariya ` ''' +# Import Python Libs +from __future__ import absolute_import + # Import Salt Testing Libs from salttesting import TestCase, skipIf from salttesting.mock import ( @@ -11,6 +14,9 @@ from salttesting.mock import ( NO_MOCK, NO_MOCK_REASON ) +from salttesting.helpers import ensure_in_syspath + +ensure_in_syspath('../../') # Import Salt Libs from salt.modules import introspect diff --git a/tests/unit/modules/iptables_test.py b/tests/unit/modules/iptables_test.py index 0998349ea3..f4c00a1165 100644 --- a/tests/unit/modules/iptables_test.py +++ b/tests/unit/modules/iptables_test.py @@ -3,6 +3,10 @@ :codeauthor: :email:`Jayesh Kariya ` ''' +# Import Python Libs +from __future__ import absolute_import +import uuid + # Import Salt Testing Libs from salttesting import TestCase, skipIf from salttesting.mock import ( @@ -11,7 +15,9 @@ from salttesting.mock import ( NO_MOCK, NO_MOCK_REASON ) -import uuid +from salttesting.helpers import ensure_in_syspath + +ensure_in_syspath('../../') # Import Salt Libs from salt.modules import iptables diff --git a/tests/unit/modules/locate_test.py b/tests/unit/modules/locate_test.py index 8e286c8484..ab1a698056 100644 --- a/tests/unit/modules/locate_test.py +++ b/tests/unit/modules/locate_test.py @@ -3,6 +3,9 @@ :codeauthor: :email:`Jayesh Kariya ` ''' +# Import Python Libs +from __future__ import absolute_import + # Import Salt Testing Libs from salttesting import TestCase, skipIf from salttesting.mock import ( @@ -11,6 +14,9 @@ from salttesting.mock import ( NO_MOCK, NO_MOCK_REASON ) +from salttesting.helpers import ensure_in_syspath + +ensure_in_syspath('../../') # Import Salt Libs from salt.modules import locate diff --git a/tests/unit/modules/logrotate_test.py b/tests/unit/modules/logrotate_test.py index f7a2d69d29..c9a09d2efd 100644 --- a/tests/unit/modules/logrotate_test.py +++ b/tests/unit/modules/logrotate_test.py @@ -3,6 +3,9 @@ :codeauthor: :email:`Jayesh Kariya ` ''' +# Import Python Libs +from __future__ import absolute_import + # Import Salt Testing Libs from salttesting import TestCase, skipIf from salttesting.mock import ( @@ -11,6 +14,9 @@ from salttesting.mock import ( NO_MOCK, NO_MOCK_REASON ) +from salttesting.helpers import ensure_in_syspath + +ensure_in_syspath('../../') # Import Salt Libs from salt.modules import logrotate diff --git a/tests/unit/modules/munin_test.py b/tests/unit/modules/munin_test.py index a95d8ffb4e..18b140bf51 100644 --- a/tests/unit/modules/munin_test.py +++ b/tests/unit/modules/munin_test.py @@ -3,6 +3,9 @@ :codeauthor: :email:`Jayesh Kariya ` ''' +# Import Python Libs +from __future__ import absolute_import + # Import Salt Testing Libs from salttesting import TestCase, skipIf from salttesting.mock import ( @@ -11,6 +14,9 @@ from salttesting.mock import ( NO_MOCK, NO_MOCK_REASON ) +from salttesting.helpers import ensure_in_syspath + +ensure_in_syspath('../..') # Import Salt Libs from salt.modules import munin From 2f9dc14af15129d6c1ba1efb93234d7b23b4ff45 Mon Sep 17 00:00:00 2001 From: rallytime Date: Tue, 3 Feb 2015 11:40:27 -0700 Subject: [PATCH 6/8] More Python 3 compat changes to new test modules --- tests/unit/modules/keyboard_test.py | 6 ++++++ tests/unit/modules/memcached_test.py | 6 ++++++ tests/unit/modules/moosefs_test.py | 9 ++++++--- 3 files changed, 18 insertions(+), 3 deletions(-) diff --git a/tests/unit/modules/keyboard_test.py b/tests/unit/modules/keyboard_test.py index d1d2ecee1a..84ff1e6848 100644 --- a/tests/unit/modules/keyboard_test.py +++ b/tests/unit/modules/keyboard_test.py @@ -3,6 +3,9 @@ :codeauthor: :email:`Jayesh Kariya ` ''' +# Import Python Libs +from __future__ import absolute_import + # Import Salt Testing Libs from salttesting import TestCase, skipIf from salttesting.mock import ( @@ -11,6 +14,9 @@ from salttesting.mock import ( NO_MOCK, NO_MOCK_REASON ) +from salttesting.helpers import ensure_in_syspath + +ensure_in_syspath('../../') # Import Salt Libs from salt.modules import keyboard diff --git a/tests/unit/modules/memcached_test.py b/tests/unit/modules/memcached_test.py index 5ebea5b54f..368f4c99d5 100644 --- a/tests/unit/modules/memcached_test.py +++ b/tests/unit/modules/memcached_test.py @@ -3,6 +3,9 @@ :codeauthor: :email:`Jayesh Kariya ` ''' +# Import Python Libs +from __future__ import absolute_import + # Import Salt Testing Libs from salttesting import TestCase, skipIf from salttesting.mock import ( @@ -11,6 +14,9 @@ from salttesting.mock import ( NO_MOCK, NO_MOCK_REASON ) +from salttesting.helpers import ensure_in_syspath + +ensure_in_syspath('../../') # Import Salt Libs from salt.modules import memcached diff --git a/tests/unit/modules/moosefs_test.py b/tests/unit/modules/moosefs_test.py index 2071fb97cc..39bff085f3 100644 --- a/tests/unit/modules/moosefs_test.py +++ b/tests/unit/modules/moosefs_test.py @@ -3,6 +3,9 @@ :codeauthor: :email:`Jayesh Kariya ` ''' +# Import Python Libs +from __future__ import absolute_import + # Import Salt Testing Libs from salttesting import TestCase, skipIf from salttesting.mock import ( @@ -11,15 +14,15 @@ from salttesting.mock import ( NO_MOCK, NO_MOCK_REASON ) +from salttesting.helpers import ensure_in_syspath + +ensure_in_syspath('../../') # Import Salt Libs from salt.modules import moosefs # Globals -# moosefs.__grains__ = {} moosefs.__salt__ = {} -# moosefs.__context__ = {} -# moosefs.__opts__ = {} @skipIf(NO_MOCK, NO_MOCK_REASON) From ec25dc10470ca278b82a540fc32bf7cc24e892d1 Mon Sep 17 00:00:00 2001 From: rallytime Date: Tue, 3 Feb 2015 12:22:05 -0700 Subject: [PATCH 7/8] Python 3 compat for mixins.py and http.py --- salt/client/mixins.py | 2 +- salt/utils/http.py | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/salt/client/mixins.py b/salt/client/mixins.py index 2a68b1411c..6c05caae18 100644 --- a/salt/client/mixins.py +++ b/salt/client/mixins.py @@ -72,7 +72,7 @@ class ClientFuncsDict(collections.MutableMapping): } pub_data = {} # pull out pub_data if you have it - for k, v in list(kwargs.items()): + for k, v in six.iteritems(kwargs.items()): if k.startswith('__pub_'): pub_data[k] = kwargs.pop(k) diff --git a/salt/utils/http.py b/salt/utils/http.py index cd1437f7a8..2a3fda4836 100644 --- a/salt/utils/http.py +++ b/salt/utils/http.py @@ -28,7 +28,6 @@ except ImportError: HAS_MATCHHOSTNAME = False import socket import urllib2 -import httplib # Import salt libs import salt.utils @@ -37,6 +36,7 @@ import salt.loader import salt.config from salt.template import compile_template from salt import syspaths +import salt.ext.six.moves.http_client # Import 3rd party libs try: @@ -297,7 +297,7 @@ def query(url, } if len(cert) > 1: cert_kwargs['key_file'] = cert[1] - handlers[0] = httplib.HTTPSConnection(**cert_kwargs) + handlers[0] = salt.ext.six.moves.http_client.HTTPSConnection(**cert_kwargs) opener = urllib2.build_opener(*handlers) for header in header_dict: From a55001565bed6bff0a4c418a25badc510fe66bca Mon Sep 17 00:00:00 2001 From: rallytime Date: Tue, 3 Feb 2015 12:54:49 -0700 Subject: [PATCH 8/8] Add list to six.iteritems --- salt/client/mixins.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/salt/client/mixins.py b/salt/client/mixins.py index 6c05caae18..63ec795b9a 100644 --- a/salt/client/mixins.py +++ b/salt/client/mixins.py @@ -72,7 +72,7 @@ class ClientFuncsDict(collections.MutableMapping): } pub_data = {} # pull out pub_data if you have it - for k, v in six.iteritems(kwargs.items()): + for k, v in six.iteritems(list(kwargs.items())): if k.startswith('__pub_'): pub_data[k] = kwargs.pop(k)