diff --git a/.gitignore b/.gitignore index 51ab4183..78ac9337 100644 --- a/.gitignore +++ b/.gitignore @@ -5,6 +5,7 @@ *.pyc *.swo *.swp +*.orig *.sqlite .autogenerated .coverage diff --git a/cloudbaseinit/init.py b/cloudbaseinit/init.py index c5331fc3..b5370c2d 100644 --- a/cloudbaseinit/init.py +++ b/cloudbaseinit/init.py @@ -1,5 +1,3 @@ -# vim: tabstop=4 shiftwidth=4 softtabstop=4 - # Copyright 2012 Cloudbase Solutions Srl # # Licensed under the Apache License, Version 2.0 (the "License"); you may diff --git a/cloudbaseinit/metadata/factory.py b/cloudbaseinit/metadata/factory.py index 1d6070b4..f132fcf6 100644 --- a/cloudbaseinit/metadata/factory.py +++ b/cloudbaseinit/metadata/factory.py @@ -1,5 +1,3 @@ -# vim: tabstop=4 shiftwidth=4 softtabstop=4 - # Copyright 2012 Cloudbase Solutions Srl # # Licensed under the Apache License, Version 2.0 (the "License"); you may diff --git a/cloudbaseinit/metadata/services/configdrive.py b/cloudbaseinit/metadata/services/configdrive.py index 3f01263e..0ab3914e 100644 --- a/cloudbaseinit/metadata/services/configdrive.py +++ b/cloudbaseinit/metadata/services/configdrive.py @@ -1,5 +1,3 @@ -# vim: tabstop=4 shiftwidth=4 softtabstop=4 - # Copyright 2012 Cloudbase Solutions Srl # # Licensed under the Apache License, Version 2.0 (the "License"); you may @@ -40,6 +38,7 @@ LOG = logging.getLogger(__name__) class ConfigDriveService(baseopenstackservice.BaseOpenStackService): + def __init__(self): super(ConfigDriveService, self).__init__() self._metadata_path = None diff --git a/cloudbaseinit/metadata/services/httpservice.py b/cloudbaseinit/metadata/services/httpservice.py index 0f7abaf2..fef1e3c4 100644 --- a/cloudbaseinit/metadata/services/httpservice.py +++ b/cloudbaseinit/metadata/services/httpservice.py @@ -1,5 +1,3 @@ -# vim: tabstop=4 shiftwidth=4 softtabstop=4 - # Copyright 2012 Cloudbase Solutions Srl # # Licensed under the Apache License, Version 2.0 (the "License"); you may diff --git a/cloudbaseinit/metadata/services/osconfigdrive/base.py b/cloudbaseinit/metadata/services/osconfigdrive/base.py index e4ec3d6b..71009a59 100644 --- a/cloudbaseinit/metadata/services/osconfigdrive/base.py +++ b/cloudbaseinit/metadata/services/osconfigdrive/base.py @@ -16,6 +16,7 @@ import abc class BaseConfigDriveManager(object): + @abc.abstractmethod def get_config_drive_files(self, target_path, check_raw_hhd=True, check_cdrom=True): diff --git a/cloudbaseinit/metadata/services/osconfigdrive/windows.py b/cloudbaseinit/metadata/services/osconfigdrive/windows.py index b2500367..161310dd 100644 --- a/cloudbaseinit/metadata/services/osconfigdrive/windows.py +++ b/cloudbaseinit/metadata/services/osconfigdrive/windows.py @@ -1,5 +1,3 @@ -# vim: tabstop=4 shiftwidth=4 softtabstop=4 - # Copyright 2012 Cloudbase Solutions Srl # # Licensed under the Apache License, Version 2.0 (the "License"); you may diff --git a/cloudbaseinit/osutils/base.py b/cloudbaseinit/osutils/base.py index c0061fc4..46af54ad 100644 --- a/cloudbaseinit/osutils/base.py +++ b/cloudbaseinit/osutils/base.py @@ -1,5 +1,3 @@ -# vim: tabstop=4 shiftwidth=4 softtabstop=4 - # Copyright 2012 Cloudbase Solutions Srl # # Licensed under the Apache License, Version 2.0 (the "License"); you may diff --git a/cloudbaseinit/osutils/factory.py b/cloudbaseinit/osutils/factory.py index d5853e17..fa1326a9 100644 --- a/cloudbaseinit/osutils/factory.py +++ b/cloudbaseinit/osutils/factory.py @@ -1,5 +1,3 @@ -# vim: tabstop=4 shiftwidth=4 softtabstop=4 - # Copyright 2012 Cloudbase Solutions Srl # # Licensed under the Apache License, Version 2.0 (the "License"); you may diff --git a/cloudbaseinit/osutils/posix.py b/cloudbaseinit/osutils/posix.py index 66c47eaa..01e4281d 100644 --- a/cloudbaseinit/osutils/posix.py +++ b/cloudbaseinit/osutils/posix.py @@ -1,5 +1,3 @@ -# vim: tabstop=4 shiftwidth=4 softtabstop=4 - # Copyright 2012 Cloudbase Solutions Srl # # Licensed under the Apache License, Version 2.0 (the "License"); you may @@ -20,5 +18,6 @@ from cloudbaseinit.osutils import base class PosixUtil(base.BaseOSUtils): + def reboot(self): os.system('reboot') diff --git a/cloudbaseinit/plugins/base.py b/cloudbaseinit/plugins/base.py index d027c8fe..2d8c59e5 100644 --- a/cloudbaseinit/plugins/base.py +++ b/cloudbaseinit/plugins/base.py @@ -1,5 +1,3 @@ -# vim: tabstop=4 shiftwidth=4 softtabstop=4 - # Copyright 2012 Cloudbase Solutions Srl # # Licensed under the Apache License, Version 2.0 (the "License"); you may @@ -19,6 +17,7 @@ PLUGIN_EXECUTE_ON_NEXT_BOOT = 2 class BasePlugin(object): + def get_name(self): return self.__class__.__name__ diff --git a/cloudbaseinit/plugins/constants.py b/cloudbaseinit/plugins/constants.py index 66ec8cfb..54983427 100644 --- a/cloudbaseinit/plugins/constants.py +++ b/cloudbaseinit/plugins/constants.py @@ -1,5 +1,3 @@ -# vim: tabstop=4 shiftwidth=4 softtabstop=4 - # Copyright 2013 Cloudbase Solutions Srl # # Licensed under the Apache License, Version 2.0 (the "License"); you may diff --git a/cloudbaseinit/plugins/factory.py b/cloudbaseinit/plugins/factory.py index a3e2827f..943e78aa 100644 --- a/cloudbaseinit/plugins/factory.py +++ b/cloudbaseinit/plugins/factory.py @@ -1,5 +1,3 @@ -# vim: tabstop=4 shiftwidth=4 softtabstop=4 - # Copyright 2012 Cloudbase Solutions Srl # # Licensed under the Apache License, Version 2.0 (the "License"); you may diff --git a/cloudbaseinit/plugins/windows/createuser.py b/cloudbaseinit/plugins/windows/createuser.py index ce17c81f..a08c9661 100644 --- a/cloudbaseinit/plugins/windows/createuser.py +++ b/cloudbaseinit/plugins/windows/createuser.py @@ -1,5 +1,3 @@ -# vim: tabstop=4 shiftwidth=4 softtabstop=4 - # Copyright 2012 Cloudbase Solutions Srl # # Licensed under the Apache License, Version 2.0 (the "License"); you may @@ -36,6 +34,7 @@ LOG = logging.getLogger(__name__) class CreateUserPlugin(base.BasePlugin): + def _get_password(self, osutils): # Generate a temporary random password to be replaced # by SetUserPasswordPlugin (starting from Grizzly) diff --git a/cloudbaseinit/plugins/windows/extendvolumes.py b/cloudbaseinit/plugins/windows/extendvolumes.py index 6143e92e..97287d96 100644 --- a/cloudbaseinit/plugins/windows/extendvolumes.py +++ b/cloudbaseinit/plugins/windows/extendvolumes.py @@ -1,5 +1,3 @@ -# vim: tabstop=4 shiftwidth=4 softtabstop=4 - # Copyright (c) 2013 Cloudbase Solutions Srl # # Licensed under the Apache License, Version 2.0 (the "License"); you may @@ -44,6 +42,7 @@ LOG = logging.getLogger(__name__) class ExtendVolumesPlugin(base.BasePlugin): + def _extend_volumes(self, pack, volume_idxs=None): enum = pack.QueryVolumes() while True: diff --git a/cloudbaseinit/plugins/windows/licensing.py b/cloudbaseinit/plugins/windows/licensing.py index 47886882..c4e82343 100644 --- a/cloudbaseinit/plugins/windows/licensing.py +++ b/cloudbaseinit/plugins/windows/licensing.py @@ -33,6 +33,7 @@ LOG = logging.getLogger(__name__) class WindowsLicensingPlugin(base.BasePlugin): + def _run_slmgr(self, osutils, args): if osutils.check_sysnative_dir_exists(): cscript_dir = osutils.get_sysnative_dir() diff --git a/cloudbaseinit/plugins/windows/sethostname.py b/cloudbaseinit/plugins/windows/sethostname.py index 59a8941e..ed72d2ad 100644 --- a/cloudbaseinit/plugins/windows/sethostname.py +++ b/cloudbaseinit/plugins/windows/sethostname.py @@ -1,5 +1,3 @@ -# vim: tabstop=4 shiftwidth=4 softtabstop=4 - # Copyright 2012 Cloudbase Solutions Srl # # Licensed under the Apache License, Version 2.0 (the "License"); you may diff --git a/cloudbaseinit/plugins/windows/setuserpassword.py b/cloudbaseinit/plugins/windows/setuserpassword.py index c407ba70..1d6658c4 100644 --- a/cloudbaseinit/plugins/windows/setuserpassword.py +++ b/cloudbaseinit/plugins/windows/setuserpassword.py @@ -1,5 +1,3 @@ -# vim: tabstop=4 shiftwidth=4 softtabstop=4 - # Copyright 2013 Cloudbase Solutions Srl # # Licensed under the Apache License, Version 2.0 (the "License"); you may @@ -24,6 +22,7 @@ from cloudbaseinit.plugins import base from cloudbaseinit.plugins import constants from cloudbaseinit.utils import crypt + opts = [ cfg.BoolOpt('inject_user_password', default=True, help='Set the password ' 'provided in the configuration. If False or no password is ' @@ -38,6 +37,7 @@ LOG = logging.getLogger(__name__) class SetUserPasswordPlugin(base.BasePlugin): + def _encrypt_password(self, ssh_pub_key, password): cm = crypt.CryptManager() with cm.load_ssh_rsa_public_key(ssh_pub_key) as rsa: diff --git a/cloudbaseinit/plugins/windows/sshpublickeys.py b/cloudbaseinit/plugins/windows/sshpublickeys.py index a53bcfce..56dbb4fc 100644 --- a/cloudbaseinit/plugins/windows/sshpublickeys.py +++ b/cloudbaseinit/plugins/windows/sshpublickeys.py @@ -1,5 +1,3 @@ -# vim: tabstop=4 shiftwidth=4 softtabstop=4 - # Copyright 2012 Cloudbase Solutions Srl # # Licensed under the Apache License, Version 2.0 (the "License"); you may @@ -29,6 +27,7 @@ LOG = logging.getLogger(__name__) class SetUserSSHPublicKeysPlugin(base.BasePlugin): + def execute(self, service, shared_data): public_keys = service.get_public_keys() if not public_keys: diff --git a/cloudbaseinit/plugins/windows/userdata.py b/cloudbaseinit/plugins/windows/userdata.py index 4b151775..ef8f73b2 100644 --- a/cloudbaseinit/plugins/windows/userdata.py +++ b/cloudbaseinit/plugins/windows/userdata.py @@ -1,5 +1,3 @@ -# vim: tabstop=4 shiftwidth=4 softtabstop=4 - # Copyright 2012 Cloudbase Solutions Srl # # Licensed under the Apache License, Version 2.0 (the "License"); you may @@ -25,6 +23,7 @@ from cloudbaseinit.plugins.windows.userdataplugins import factory from cloudbaseinit.plugins.windows import userdatautils from cloudbaseinit.utils import encoding + LOG = logging.getLogger(__name__) diff --git a/cloudbaseinit/plugins/windows/userdataplugins/base.py b/cloudbaseinit/plugins/windows/userdataplugins/base.py index 3368de1b..60bcc92a 100644 --- a/cloudbaseinit/plugins/windows/userdataplugins/base.py +++ b/cloudbaseinit/plugins/windows/userdataplugins/base.py @@ -16,6 +16,7 @@ import abc class BaseUserDataPlugin(object): + def __init__(self, mime_type): self._mime_type = mime_type diff --git a/cloudbaseinit/plugins/windows/userdataplugins/cloudboothook.py b/cloudbaseinit/plugins/windows/userdataplugins/cloudboothook.py index ddedd061..064fbdc0 100644 --- a/cloudbaseinit/plugins/windows/userdataplugins/cloudboothook.py +++ b/cloudbaseinit/plugins/windows/userdataplugins/cloudboothook.py @@ -19,6 +19,7 @@ LOG = logging.getLogger(__name__) class CloudBootHookPlugin(base.BaseUserDataPlugin): + def __init__(self): super(CloudBootHookPlugin, self).__init__("text/cloud-boothook") diff --git a/cloudbaseinit/plugins/windows/userdataplugins/multipartmixed.py b/cloudbaseinit/plugins/windows/userdataplugins/multipartmixed.py index b2f07279..3e8bdc2b 100644 --- a/cloudbaseinit/plugins/windows/userdataplugins/multipartmixed.py +++ b/cloudbaseinit/plugins/windows/userdataplugins/multipartmixed.py @@ -16,6 +16,7 @@ from cloudbaseinit.plugins.windows.userdataplugins import base class MultipartMixedPlugin(base.BaseUserDataPlugin): + def __init__(self): super(MultipartMixedPlugin, self).__init__("multipart/mixed") diff --git a/cloudbaseinit/plugins/windows/userdataplugins/parthandler.py b/cloudbaseinit/plugins/windows/userdataplugins/parthandler.py index e615c0f4..59290d6a 100644 --- a/cloudbaseinit/plugins/windows/userdataplugins/parthandler.py +++ b/cloudbaseinit/plugins/windows/userdataplugins/parthandler.py @@ -24,6 +24,7 @@ LOG = logging.getLogger(__name__) class PartHandlerPlugin(base.BaseUserDataPlugin): + def __init__(self): super(PartHandlerPlugin, self).__init__("text/part-handler") diff --git a/cloudbaseinit/plugins/windows/userdataplugins/shellscript.py b/cloudbaseinit/plugins/windows/userdataplugins/shellscript.py index fad0f4c5..0a441e40 100644 --- a/cloudbaseinit/plugins/windows/userdataplugins/shellscript.py +++ b/cloudbaseinit/plugins/windows/userdataplugins/shellscript.py @@ -25,6 +25,7 @@ LOG = logging.getLogger(__name__) class ShellScriptPlugin(base.BaseUserDataPlugin): + def __init__(self): super(ShellScriptPlugin, self).__init__("text/x-shellscript") diff --git a/cloudbaseinit/plugins/windows/userdatautils.py b/cloudbaseinit/plugins/windows/userdatautils.py index 233d95f8..409bb6f1 100644 --- a/cloudbaseinit/plugins/windows/userdatautils.py +++ b/cloudbaseinit/plugins/windows/userdatautils.py @@ -18,6 +18,7 @@ import re from cloudbaseinit.openstack.common import log as logging from cloudbaseinit.plugins.common import execcmd + LOG = logging.getLogger(__name__) # Avoid 80+ length by using a local variable, which diff --git a/cloudbaseinit/plugins/windows/winrmcertificateauth.py b/cloudbaseinit/plugins/windows/winrmcertificateauth.py index 937ef79b..4d7f8ff0 100644 --- a/cloudbaseinit/plugins/windows/winrmcertificateauth.py +++ b/cloudbaseinit/plugins/windows/winrmcertificateauth.py @@ -1,5 +1,3 @@ -# vim: tabstop=4 shiftwidth=4 softtabstop=4 - # Copyright 2013 Cloudbase Solutions Srl # # Licensed under the Apache License, Version 2.0 (the "License"); you may @@ -23,10 +21,12 @@ from cloudbaseinit.utils.windows import security from cloudbaseinit.utils.windows import winrmconfig from cloudbaseinit.utils.windows import x509 + LOG = logging.getLogger(__name__) class ConfigWinRMCertificateAuthPlugin(base.BasePlugin): + def _get_credentials(self, shared_data): user_name = shared_data.get(constants.SHARED_DATA_USERNAME) if not user_name: diff --git a/cloudbaseinit/plugins/windows/winrmlistener.py b/cloudbaseinit/plugins/windows/winrmlistener.py index 3e0689e8..ff7ffc0c 100644 --- a/cloudbaseinit/plugins/windows/winrmlistener.py +++ b/cloudbaseinit/plugins/windows/winrmlistener.py @@ -1,5 +1,3 @@ -# vim: tabstop=4 shiftwidth=4 softtabstop=4 - # Copyright 2013 Cloudbase Solutions Srl # # Licensed under the Apache License, Version 2.0 (the "License"); you may @@ -23,6 +21,7 @@ from cloudbaseinit.utils.windows import security from cloudbaseinit.utils.windows import winrmconfig from cloudbaseinit.utils.windows import x509 + LOG = logging.getLogger(__name__) opts = [ diff --git a/cloudbaseinit/shell.py b/cloudbaseinit/shell.py index 3fe03808..f41762a3 100644 --- a/cloudbaseinit/shell.py +++ b/cloudbaseinit/shell.py @@ -1,5 +1,3 @@ -# vim: tabstop=4 shiftwidth=4 softtabstop=4 - # Copyright 2012 Cloudbase Solutions Srl # # Licensed under the Apache License, Version 2.0 (the "License"); you may diff --git a/cloudbaseinit/tests/__init__.py b/cloudbaseinit/tests/__init__.py index 7227b295..46e21cba 100644 --- a/cloudbaseinit/tests/__init__.py +++ b/cloudbaseinit/tests/__init__.py @@ -1,5 +1,3 @@ -# vim: tabstop=4 shiftwidth=4 softtabstop=4 - # Copyright 2013 Cloudbase Solutions Srl # # Licensed under the Apache License, Version 2.0 (the "License"); you may diff --git a/cloudbaseinit/tests/fake.py b/cloudbaseinit/tests/fake.py index 64b1870f..33dc5106 100644 --- a/cloudbaseinit/tests/fake.py +++ b/cloudbaseinit/tests/fake.py @@ -14,6 +14,7 @@ class FakeComError(Exception): + def __init__(self): super(FakeComError, self).__init__() self.excepinfo = [None, None, None, None, None, -2144108544] diff --git a/cloudbaseinit/tests/metadata/__init__.py b/cloudbaseinit/tests/metadata/__init__.py index 7227b295..46e21cba 100644 --- a/cloudbaseinit/tests/metadata/__init__.py +++ b/cloudbaseinit/tests/metadata/__init__.py @@ -1,5 +1,3 @@ -# vim: tabstop=4 shiftwidth=4 softtabstop=4 - # Copyright 2013 Cloudbase Solutions Srl # # Licensed under the Apache License, Version 2.0 (the "License"); you may diff --git a/cloudbaseinit/tests/metadata/services/__init__.py b/cloudbaseinit/tests/metadata/services/__init__.py index 7227b295..46e21cba 100644 --- a/cloudbaseinit/tests/metadata/services/__init__.py +++ b/cloudbaseinit/tests/metadata/services/__init__.py @@ -1,5 +1,3 @@ -# vim: tabstop=4 shiftwidth=4 softtabstop=4 - # Copyright 2013 Cloudbase Solutions Srl # # Licensed under the Apache License, Version 2.0 (the "License"); you may diff --git a/cloudbaseinit/tests/metadata/services/osconfigdrive/__init__.py b/cloudbaseinit/tests/metadata/services/osconfigdrive/__init__.py index 73be5543..93daace9 100644 --- a/cloudbaseinit/tests/metadata/services/osconfigdrive/__init__.py +++ b/cloudbaseinit/tests/metadata/services/osconfigdrive/__init__.py @@ -1,5 +1,3 @@ -# vim: tabstop=4 shiftwidth=4 softtabstop=4 - # Copyright 2014 Cloudbase Solutions Srl # # Licensed under the Apache License, Version 2.0 (the "License"); you may diff --git a/cloudbaseinit/tests/metadata/services/osconfigdrive/test_factory.py b/cloudbaseinit/tests/metadata/services/osconfigdrive/test_factory.py index 7b9637f6..93ec80a1 100644 --- a/cloudbaseinit/tests/metadata/services/osconfigdrive/test_factory.py +++ b/cloudbaseinit/tests/metadata/services/osconfigdrive/test_factory.py @@ -1,5 +1,3 @@ -# vim: tabstop=4 shiftwidth=4 softtabstop=4 - # Copyright 2014 Cloudbase Solutions Srl # # Licensed under the Apache License, Version 2.0 (the "License"); you may @@ -14,10 +12,14 @@ # License for the specific language governing permissions and limitations # under the License. -import mock import sys import unittest +try: + import unittest.mock as mock +except ImportError: + import mock + from cloudbaseinit.metadata.services.osconfigdrive import factory diff --git a/cloudbaseinit/tests/metadata/services/osconfigdrive/test_windows.py b/cloudbaseinit/tests/metadata/services/osconfigdrive/test_windows.py index ecb0de73..c60ac1c3 100644 --- a/cloudbaseinit/tests/metadata/services/osconfigdrive/test_windows.py +++ b/cloudbaseinit/tests/metadata/services/osconfigdrive/test_windows.py @@ -1,5 +1,3 @@ -# vim: tabstop=4 shiftwidth=4 softtabstop=4 - # Copyright 2014 Cloudbase Solutions Srl # # Licensed under the Apache License, Version 2.0 (the "License"); you may @@ -15,10 +13,13 @@ # under the License. import importlib -import mock import os import unittest +try: + import unittest.mock as mock +except ImportError: + import mock from oslo.config import cfg from cloudbaseinit import exception diff --git a/cloudbaseinit/tests/metadata/services/test_baseopenstackservice.py b/cloudbaseinit/tests/metadata/services/test_baseopenstackservice.py index 0569e4bc..0e53eae8 100644 --- a/cloudbaseinit/tests/metadata/services/test_baseopenstackservice.py +++ b/cloudbaseinit/tests/metadata/services/test_baseopenstackservice.py @@ -17,7 +17,10 @@ import functools import posixpath import unittest -import mock +try: + import unittest.mock as mock +except ImportError: + import mock from oslo.config import cfg from cloudbaseinit.metadata.services import base diff --git a/cloudbaseinit/tests/metadata/services/test_cloudstack.py b/cloudbaseinit/tests/metadata/services/test_cloudstack.py index 07cb9f2c..05cdc7f0 100644 --- a/cloudbaseinit/tests/metadata/services/test_cloudstack.py +++ b/cloudbaseinit/tests/metadata/services/test_cloudstack.py @@ -12,9 +12,12 @@ # License for the specific language governing permissions and limitations # under the License. -import mock import unittest +try: + import unittest.mock as mock +except ImportError: + import mock from oslo.config import cfg from six.moves import urllib diff --git a/cloudbaseinit/tests/metadata/services/test_configdrive.py b/cloudbaseinit/tests/metadata/services/test_configdrive.py index bb1f8867..24325e43 100644 --- a/cloudbaseinit/tests/metadata/services/test_configdrive.py +++ b/cloudbaseinit/tests/metadata/services/test_configdrive.py @@ -1,5 +1,3 @@ -# vim: tabstop=4 shiftwidth=4 softtabstop=4 - # Copyright 2013 Cloudbase Solutions Srl # # Licensed under the Apache License, Version 2.0 (the "License"); you may @@ -15,17 +13,21 @@ # under the License. import importlib -import mock import os import unittest import uuid +try: + import unittest.mock as mock +except ImportError: + import mock from oslo.config import cfg CONF = cfg.CONF class ConfigDriveServiceTest(unittest.TestCase): + def setUp(self): self._win32com_mock = mock.MagicMock() self._ctypes_mock = mock.MagicMock() diff --git a/cloudbaseinit/tests/metadata/services/test_ec2service.py b/cloudbaseinit/tests/metadata/services/test_ec2service.py index 148d6400..b25e6c9c 100644 --- a/cloudbaseinit/tests/metadata/services/test_ec2service.py +++ b/cloudbaseinit/tests/metadata/services/test_ec2service.py @@ -1,5 +1,3 @@ -# vim: tabstop=4 shiftwidth=4 softtabstop=4 - # Copyright 2014 Cloudbase Solutions Srl # # Licensed under the Apache License, Version 2.0 (the "License"); you may @@ -14,10 +12,13 @@ # License for the specific language governing permissions and limitations # under the License. -import mock import posixpath import unittest +try: + import unittest.mock as mock +except ImportError: + import mock from oslo.config import cfg from six.moves.urllib import error @@ -28,6 +29,7 @@ CONF = cfg.CONF class EC2ServiceTest(unittest.TestCase): + def setUp(self): CONF.set_override('retry_count_interval', 0) self._service = ec2service.EC2Service() diff --git a/cloudbaseinit/tests/metadata/services/test_httpservice.py b/cloudbaseinit/tests/metadata/services/test_httpservice.py index 48b44825..2c1973e8 100644 --- a/cloudbaseinit/tests/metadata/services/test_httpservice.py +++ b/cloudbaseinit/tests/metadata/services/test_httpservice.py @@ -1,5 +1,3 @@ -# vim: tabstop=4 shiftwidth=4 softtabstop=4 - # Copyright 2014 Cloudbase Solutions Srl # # Licensed under the Apache License, Version 2.0 (the "License"); you may @@ -14,10 +12,13 @@ # License for the specific language governing permissions and limitations # under the License. -import mock import os import unittest +try: + import unittest.mock as mock +except ImportError: + import mock from oslo.config import cfg from six.moves.urllib import error @@ -28,6 +29,7 @@ CONF = cfg.CONF class HttpServiceTest(unittest.TestCase): + def setUp(self): CONF.set_override('retry_count_interval', 0) self._httpservice = httpservice.HttpService() diff --git a/cloudbaseinit/tests/metadata/services/test_maasservice.py b/cloudbaseinit/tests/metadata/services/test_maasservice.py index 02285b9a..5c398cc9 100644 --- a/cloudbaseinit/tests/metadata/services/test_maasservice.py +++ b/cloudbaseinit/tests/metadata/services/test_maasservice.py @@ -1,5 +1,3 @@ -# vim: tabstop=4 shiftwidth=4 softtabstop=4 - # Copyright 2014 Cloudbase Solutions Srl # # Licensed under the Apache License, Version 2.0 (the "License"); you may @@ -14,12 +12,15 @@ # License for the specific language governing permissions and limitations # under the License. -import mock import os import posixpath import sys import unittest +try: + import unittest.mock as mock +except ImportError: + import mock from oslo.config import cfg from six.moves.urllib import error @@ -34,6 +35,7 @@ CONF = cfg.CONF class MaaSHttpServiceTest(unittest.TestCase): + def setUp(self): if sys.version_info < (3, 0): self.mock_oauth = mock.MagicMock() diff --git a/cloudbaseinit/tests/metadata/services/test_opennebulaservice.py b/cloudbaseinit/tests/metadata/services/test_opennebulaservice.py index 86dd495f..149df3b7 100644 --- a/cloudbaseinit/tests/metadata/services/test_opennebulaservice.py +++ b/cloudbaseinit/tests/metadata/services/test_opennebulaservice.py @@ -17,7 +17,10 @@ import re import textwrap import unittest -import mock +try: + import unittest.mock as mock +except ImportError: + import mock from cloudbaseinit.metadata.services import base from cloudbaseinit.metadata.services import opennebulaservice diff --git a/cloudbaseinit/tests/metadata/test_factory.py b/cloudbaseinit/tests/metadata/test_factory.py index e5779705..3f72c2c1 100644 --- a/cloudbaseinit/tests/metadata/test_factory.py +++ b/cloudbaseinit/tests/metadata/test_factory.py @@ -1,5 +1,3 @@ -# vim: tabstop=4 shiftwidth=4 softtabstop=4 - # Copyright 2013 Cloudbase Solutions Srl # # Licensed under the Apache License, Version 2.0 (the "License"); you may @@ -17,9 +15,9 @@ import unittest try: - import mock -except ImportError: import unittest.mock as mock +except ImportError: + import mock from cloudbaseinit import exception from cloudbaseinit.metadata import factory diff --git a/cloudbaseinit/tests/osutils/__init__.py b/cloudbaseinit/tests/osutils/__init__.py index 7227b295..46e21cba 100644 --- a/cloudbaseinit/tests/osutils/__init__.py +++ b/cloudbaseinit/tests/osutils/__init__.py @@ -1,5 +1,3 @@ -# vim: tabstop=4 shiftwidth=4 softtabstop=4 - # Copyright 2013 Cloudbase Solutions Srl # # Licensed under the Apache License, Version 2.0 (the "License"); you may diff --git a/cloudbaseinit/tests/osutils/test_base.py b/cloudbaseinit/tests/osutils/test_base.py index d47cc0fd..956714c0 100755 --- a/cloudbaseinit/tests/osutils/test_base.py +++ b/cloudbaseinit/tests/osutils/test_base.py @@ -1,5 +1,3 @@ -# vim: tabstop=4 shiftwidth=4 softtabstop=4 - # Copyright 2014 Cloudbase Solutions Srl # # Licensed under the Apache License, Version 2.0 (the "License"); you may @@ -14,11 +12,15 @@ # License for the specific language governing permissions and limitations # under the License. -import mock import subprocess import sys import unittest +try: + import unittest.mock as mock +except ImportError: + import mock + from cloudbaseinit.osutils import base diff --git a/cloudbaseinit/tests/osutils/test_factory.py b/cloudbaseinit/tests/osutils/test_factory.py index 1d65ae43..51b0ad6d 100644 --- a/cloudbaseinit/tests/osutils/test_factory.py +++ b/cloudbaseinit/tests/osutils/test_factory.py @@ -1,5 +1,3 @@ -# vim: tabstop=4 shiftwidth=4 softtabstop=4 - # Copyright 2013 Cloudbase Solutions Srl # # Licensed under the Apache License, Version 2.0 (the "License"); you may @@ -14,10 +12,14 @@ # License for the specific language governing permissions and limitations # under the License. -import mock import os import unittest +try: + import unittest.mock as mock +except ImportError: + import mock + from cloudbaseinit.osutils import factory diff --git a/cloudbaseinit/tests/osutils/test_windows.py b/cloudbaseinit/tests/osutils/test_windows.py index 57ff703e..89a04d4f 100644 --- a/cloudbaseinit/tests/osutils/test_windows.py +++ b/cloudbaseinit/tests/osutils/test_windows.py @@ -17,7 +17,10 @@ import importlib import os import unittest -import mock +try: + import unittest.mock as mock +except ImportError: + import mock from oslo.config import cfg import six diff --git a/cloudbaseinit/tests/plugins/__init__.py b/cloudbaseinit/tests/plugins/__init__.py index 7227b295..46e21cba 100644 --- a/cloudbaseinit/tests/plugins/__init__.py +++ b/cloudbaseinit/tests/plugins/__init__.py @@ -1,5 +1,3 @@ -# vim: tabstop=4 shiftwidth=4 softtabstop=4 - # Copyright 2013 Cloudbase Solutions Srl # # Licensed under the Apache License, Version 2.0 (the "License"); you may diff --git a/cloudbaseinit/tests/plugins/common/test_execcmd.py b/cloudbaseinit/tests/plugins/common/test_execcmd.py index 669180e3..9c924e20 100644 --- a/cloudbaseinit/tests/plugins/common/test_execcmd.py +++ b/cloudbaseinit/tests/plugins/common/test_execcmd.py @@ -15,7 +15,10 @@ import os import unittest -import mock +try: + import unittest.mock as mock +except ImportError: + import mock from cloudbaseinit.plugins.common import execcmd from cloudbaseinit.tests import testutils diff --git a/cloudbaseinit/tests/plugins/test_factory.py b/cloudbaseinit/tests/plugins/test_factory.py index 985b90b5..4e92c944 100644 --- a/cloudbaseinit/tests/plugins/test_factory.py +++ b/cloudbaseinit/tests/plugins/test_factory.py @@ -1,5 +1,3 @@ -# vim: tabstop=4 shiftwidth=4 softtabstop=4 - # Copyright 2013 Cloudbase Solutions Srl # # Licensed under the Apache License, Version 2.0 (the "License"); you may @@ -14,9 +12,12 @@ # License for the specific language governing permissions and limitations # under the License. -import mock import unittest +try: + import unittest.mock as mock +except ImportError: + import mock from oslo.config import cfg from cloudbaseinit.plugins import factory diff --git a/cloudbaseinit/tests/plugins/windows/__init__.py b/cloudbaseinit/tests/plugins/windows/__init__.py index 7227b295..46e21cba 100644 --- a/cloudbaseinit/tests/plugins/windows/__init__.py +++ b/cloudbaseinit/tests/plugins/windows/__init__.py @@ -1,5 +1,3 @@ -# vim: tabstop=4 shiftwidth=4 softtabstop=4 - # Copyright 2013 Cloudbase Solutions Srl # # Licensed under the Apache License, Version 2.0 (the "License"); you may diff --git a/cloudbaseinit/tests/plugins/windows/test_createuser.py b/cloudbaseinit/tests/plugins/windows/test_createuser.py index eb54f705..68805102 100644 --- a/cloudbaseinit/tests/plugins/windows/test_createuser.py +++ b/cloudbaseinit/tests/plugins/windows/test_createuser.py @@ -1,5 +1,3 @@ -# vim: tabstop=4 shiftwidth=4 softtabstop=4 - # Copyright 2013 Cloudbase Solutions Srl # # Licensed under the Apache License, Version 2.0 (the "License"); you may @@ -14,9 +12,12 @@ # License for the specific language governing permissions and limitations # under the License. -import mock import unittest +try: + import unittest.mock as mock +except ImportError: + import mock from oslo.config import cfg from cloudbaseinit.plugins import base diff --git a/cloudbaseinit/tests/plugins/windows/test_extendvolumes.py b/cloudbaseinit/tests/plugins/windows/test_extendvolumes.py index 554f19cf..81f4aa0b 100644 --- a/cloudbaseinit/tests/plugins/windows/test_extendvolumes.py +++ b/cloudbaseinit/tests/plugins/windows/test_extendvolumes.py @@ -1,5 +1,3 @@ -# vim: tabstop=4 shiftwidth=4 softtabstop=4 - # Copyright (c) 2013 Cloudbase Solutions Srl # # Licensed under the Apache License, Version 2.0 (the "License"); you may @@ -15,10 +13,13 @@ # under the License. import importlib -import mock import re import unittest +try: + import unittest.mock as mock +except ImportError: + import mock from oslo.config import cfg CONF = cfg.CONF diff --git a/cloudbaseinit/tests/plugins/windows/test_fileexecutils.py b/cloudbaseinit/tests/plugins/windows/test_fileexecutils.py index 9e9977c6..940167d1 100644 --- a/cloudbaseinit/tests/plugins/windows/test_fileexecutils.py +++ b/cloudbaseinit/tests/plugins/windows/test_fileexecutils.py @@ -14,7 +14,10 @@ import unittest -import mock +try: + import unittest.mock as mock +except ImportError: + import mock from cloudbaseinit.plugins.common import execcmd from cloudbaseinit.plugins.windows import fileexecutils diff --git a/cloudbaseinit/tests/plugins/windows/test_licensing.py b/cloudbaseinit/tests/plugins/windows/test_licensing.py index 89d0074d..9f830102 100644 --- a/cloudbaseinit/tests/plugins/windows/test_licensing.py +++ b/cloudbaseinit/tests/plugins/windows/test_licensing.py @@ -1,5 +1,3 @@ -# vim: tabstop=4 shiftwidth=4 softtabstop=4 - # Copyright 2014 Cloudbase Solutions Srl # # Licensed under the Apache License, Version 2.0 (the "License"); you may @@ -14,10 +12,13 @@ # License for the specific language governing permissions and limitations # under the License. -import mock import os import unittest +try: + import unittest.mock as mock +except ImportError: + import mock from oslo.config import cfg from cloudbaseinit import exception diff --git a/cloudbaseinit/tests/plugins/windows/test_localscripts.py b/cloudbaseinit/tests/plugins/windows/test_localscripts.py index 3bfdd176..74f820d5 100644 --- a/cloudbaseinit/tests/plugins/windows/test_localscripts.py +++ b/cloudbaseinit/tests/plugins/windows/test_localscripts.py @@ -12,10 +12,14 @@ # License for the specific language governing permissions and limitations # under the License. -import mock import os import unittest +try: + import unittest.mock as mock +except ImportError: + import mock + from cloudbaseinit.plugins import base from cloudbaseinit.plugins.windows import localscripts from oslo.config import cfg diff --git a/cloudbaseinit/tests/plugins/windows/test_mtu.py b/cloudbaseinit/tests/plugins/windows/test_mtu.py index a70aa5e4..ac146e41 100644 --- a/cloudbaseinit/tests/plugins/windows/test_mtu.py +++ b/cloudbaseinit/tests/plugins/windows/test_mtu.py @@ -14,7 +14,10 @@ import unittest -import mock +try: + import unittest.mock as mock +except ImportError: + import mock import six from cloudbaseinit.plugins import base diff --git a/cloudbaseinit/tests/plugins/windows/test_networkconfig.py b/cloudbaseinit/tests/plugins/windows/test_networkconfig.py index 879e496b..fb97a2a1 100644 --- a/cloudbaseinit/tests/plugins/windows/test_networkconfig.py +++ b/cloudbaseinit/tests/plugins/windows/test_networkconfig.py @@ -16,7 +16,10 @@ import functools import unittest -import mock +try: + import unittest.mock as mock +except ImportError: + import mock from cloudbaseinit import exception from cloudbaseinit.metadata.services import base as service_base diff --git a/cloudbaseinit/tests/plugins/windows/test_ntpclient.py b/cloudbaseinit/tests/plugins/windows/test_ntpclient.py index e1c474b2..d569db50 100644 --- a/cloudbaseinit/tests/plugins/windows/test_ntpclient.py +++ b/cloudbaseinit/tests/plugins/windows/test_ntpclient.py @@ -12,9 +12,12 @@ # License for the specific language governing permissions and limitations # under the License. -import mock import unittest +try: + import unittest.mock as mock +except ImportError: + import mock from oslo.config import cfg from cloudbaseinit import exception diff --git a/cloudbaseinit/tests/plugins/windows/test_sethostname.py b/cloudbaseinit/tests/plugins/windows/test_sethostname.py index 945f7121..87a188be 100644 --- a/cloudbaseinit/tests/plugins/windows/test_sethostname.py +++ b/cloudbaseinit/tests/plugins/windows/test_sethostname.py @@ -1,5 +1,3 @@ -# vim: tabstop=4 shiftwidth=4 softtabstop=4 - # Copyright 2013 Cloudbase Solutions Srl # # Licensed under the Apache License, Version 2.0 (the "License"); you may @@ -14,9 +12,12 @@ # License for the specific language governing permissions and limitations # under the License. -import mock import unittest +try: + import unittest.mock as mock +except ImportError: + import mock from oslo.config import cfg from cloudbaseinit.plugins import base diff --git a/cloudbaseinit/tests/plugins/windows/test_setuserpassword.py b/cloudbaseinit/tests/plugins/windows/test_setuserpassword.py index 4ccfad7b..0f6699b7 100644 --- a/cloudbaseinit/tests/plugins/windows/test_setuserpassword.py +++ b/cloudbaseinit/tests/plugins/windows/test_setuserpassword.py @@ -1,5 +1,3 @@ -# vim: tabstop=4 shiftwidth=4 softtabstop=4 - # Copyright 2013 Cloudbase Solutions Srl # # Licensed under the Apache License, Version 2.0 (the "License"); you may @@ -14,9 +12,12 @@ # License for the specific language governing permissions and limitations # under the License. -import mock import unittest +try: + import unittest.mock as mock +except ImportError: + import mock from oslo.config import cfg from cloudbaseinit.plugins import constants diff --git a/cloudbaseinit/tests/plugins/windows/test_sshpublickeys.py b/cloudbaseinit/tests/plugins/windows/test_sshpublickeys.py index 1baa1100..e0dfdb59 100644 --- a/cloudbaseinit/tests/plugins/windows/test_sshpublickeys.py +++ b/cloudbaseinit/tests/plugins/windows/test_sshpublickeys.py @@ -1,5 +1,3 @@ -# vim: tabstop=4 shiftwidth=4 softtabstop=4 - # Copyright 2013 Cloudbase Solutions Srl # # Licensed under the Apache License, Version 2.0 (the "License"); you may @@ -14,10 +12,13 @@ # License for the specific language governing permissions and limitations # under the License. -import mock import os import unittest +try: + import unittest.mock as mock +except ImportError: + import mock from oslo.config import cfg from cloudbaseinit import exception diff --git a/cloudbaseinit/tests/plugins/windows/test_userdata.py b/cloudbaseinit/tests/plugins/windows/test_userdata.py index bd4501bc..8f3cd489 100644 --- a/cloudbaseinit/tests/plugins/windows/test_userdata.py +++ b/cloudbaseinit/tests/plugins/windows/test_userdata.py @@ -1,5 +1,3 @@ -# vim: tabstop=4 shiftwidth=4 softtabstop=4 - # Copyright 2013 Cloudbase Solutions Srl # # Licensed under the Apache License, Version 2.0 (the "License"); you may @@ -14,9 +12,12 @@ # License for the specific language governing permissions and limitations # under the License. -import mock import unittest +try: + import unittest.mock as mock +except ImportError: + import mock from oslo.config import cfg from cloudbaseinit.metadata.services import base as metadata_services_base diff --git a/cloudbaseinit/tests/plugins/windows/test_userdatautils.py b/cloudbaseinit/tests/plugins/windows/test_userdatautils.py index 5cccee81..4b98c36e 100644 --- a/cloudbaseinit/tests/plugins/windows/test_userdatautils.py +++ b/cloudbaseinit/tests/plugins/windows/test_userdatautils.py @@ -15,7 +15,10 @@ import os import unittest -import mock +try: + import unittest.mock as mock +except ImportError: + import mock from cloudbaseinit.plugins.common import execcmd from cloudbaseinit.plugins.windows import userdatautils diff --git a/cloudbaseinit/tests/plugins/windows/test_winrmcertificateauth.py b/cloudbaseinit/tests/plugins/windows/test_winrmcertificateauth.py index 1eed1b72..c22c4854 100644 --- a/cloudbaseinit/tests/plugins/windows/test_winrmcertificateauth.py +++ b/cloudbaseinit/tests/plugins/windows/test_winrmcertificateauth.py @@ -1,5 +1,3 @@ -# vim: tabstop=4 shiftwidth=4 softtabstop=4 - # Copyright 2013 Cloudbase Solutions Srl # # Licensed under the Apache License, Version 2.0 (the "License"); you may @@ -15,19 +13,24 @@ # under the License. import importlib -import mock import unittest +try: + import unittest.mock as mock +except ImportError: + import mock +from oslo.config import cfg + from cloudbaseinit import exception from cloudbaseinit.plugins import base from cloudbaseinit.plugins import constants -from oslo.config import cfg CONF = cfg.CONF class ConfigWinRMCertificateAuthPluginTests(unittest.TestCase): + def setUp(self): self._ctypes_mock = mock.MagicMock() self._win32com_mock = mock.MagicMock() diff --git a/cloudbaseinit/tests/plugins/windows/test_winrmlistener.py b/cloudbaseinit/tests/plugins/windows/test_winrmlistener.py index 0bcf20e7..9f131901 100644 --- a/cloudbaseinit/tests/plugins/windows/test_winrmlistener.py +++ b/cloudbaseinit/tests/plugins/windows/test_winrmlistener.py @@ -1,5 +1,3 @@ -# vim: tabstop=4 shiftwidth=4 softtabstop=4 - # Copyright 2013 Cloudbase Solutions Srl # # Licensed under the Apache License, Version 2.0 (the "License"); you may @@ -15,16 +13,22 @@ # under the License. import importlib -import mock import unittest -from cloudbaseinit.plugins import base +try: + import unittest.mock as mock +except ImportError: + import mock from oslo.config import cfg +from cloudbaseinit.plugins import base + + CONF = cfg.CONF class ConfigWinRMListenerPluginTests(unittest.TestCase): + def setUp(self): self._mock_wintypes = mock.MagicMock() self._mock_pywintypes = mock.MagicMock() diff --git a/cloudbaseinit/tests/plugins/windows/userdataplugins/__init__.py b/cloudbaseinit/tests/plugins/windows/userdataplugins/__init__.py index 7227b295..46e21cba 100644 --- a/cloudbaseinit/tests/plugins/windows/userdataplugins/__init__.py +++ b/cloudbaseinit/tests/plugins/windows/userdataplugins/__init__.py @@ -1,5 +1,3 @@ -# vim: tabstop=4 shiftwidth=4 softtabstop=4 - # Copyright 2013 Cloudbase Solutions Srl # # Licensed under the Apache License, Version 2.0 (the "License"); you may diff --git a/cloudbaseinit/tests/plugins/windows/userdataplugins/test_cloudboothook.py b/cloudbaseinit/tests/plugins/windows/userdataplugins/test_cloudboothook.py index 05e93395..2ce5e25e 100644 --- a/cloudbaseinit/tests/plugins/windows/userdataplugins/test_cloudboothook.py +++ b/cloudbaseinit/tests/plugins/windows/userdataplugins/test_cloudboothook.py @@ -1,5 +1,3 @@ -# vim: tabstop=4 shiftwidth=4 softtabstop=4 - # Copyright 2014 Cloudbase Solutions Srl # # Licensed under the Apache License, Version 2.0 (the "License"); you may @@ -14,9 +12,12 @@ # License for the specific language governing permissions and limitations # under the License. -import mock import unittest +try: + import unittest.mock as mock +except ImportError: + import mock from oslo.config import cfg from cloudbaseinit.plugins.windows.userdataplugins import cloudboothook diff --git a/cloudbaseinit/tests/plugins/windows/userdataplugins/test_cloudconfig.py b/cloudbaseinit/tests/plugins/windows/userdataplugins/test_cloudconfig.py index cc4e7804..941fadf1 100644 --- a/cloudbaseinit/tests/plugins/windows/userdataplugins/test_cloudconfig.py +++ b/cloudbaseinit/tests/plugins/windows/userdataplugins/test_cloudconfig.py @@ -1,5 +1,3 @@ -# vim: tabstop=4 shiftwidth=4 softtabstop=4 - # Copyright 2014 Cloudbase Solutions Srl # # Licensed under the Apache License, Version 2.0 (the "License"); you may @@ -15,9 +13,12 @@ # under the License. import importlib -import mock import unittest +try: + import unittest.mock as mock +except ImportError: + import mock from oslo.config import cfg CONF = cfg.CONF diff --git a/cloudbaseinit/tests/plugins/windows/userdataplugins/test_factory.py b/cloudbaseinit/tests/plugins/windows/userdataplugins/test_factory.py index 50bcba8a..fa93ee95 100644 --- a/cloudbaseinit/tests/plugins/windows/userdataplugins/test_factory.py +++ b/cloudbaseinit/tests/plugins/windows/userdataplugins/test_factory.py @@ -1,5 +1,3 @@ -# vim: tabstop=4 shiftwidth=4 softtabstop=4 - # Copyright 2014 Cloudbase Solutions Srl # # Licensed under the Apache License, Version 2.0 (the "License"); you may @@ -14,9 +12,12 @@ # License for the specific language governing permissions and limitations # under the License. -import mock import unittest +try: + import unittest.mock as mock +except ImportError: + import mock from oslo.config import cfg from cloudbaseinit.plugins.windows.userdataplugins import factory diff --git a/cloudbaseinit/tests/plugins/windows/userdataplugins/test_heat.py b/cloudbaseinit/tests/plugins/windows/userdataplugins/test_heat.py index 27a0b74e..6c3839f0 100644 --- a/cloudbaseinit/tests/plugins/windows/userdataplugins/test_heat.py +++ b/cloudbaseinit/tests/plugins/windows/userdataplugins/test_heat.py @@ -1,5 +1,3 @@ -# vim: tabstop=4 shiftwidth=4 softtabstop=4 - # Copyright 2013 Cloudbase Solutions Srl # # Licensed under the Apache License, Version 2.0 (the "License"); you may @@ -14,10 +12,13 @@ # License for the specific language governing permissions and limitations # under the License. -import mock import os import unittest +try: + import unittest.mock as mock +except ImportError: + import mock from oslo.config import cfg from cloudbaseinit.plugins.windows.userdataplugins import heat diff --git a/cloudbaseinit/tests/plugins/windows/userdataplugins/test_parthandler.py b/cloudbaseinit/tests/plugins/windows/userdataplugins/test_parthandler.py index 2191d31b..8cb259e3 100644 --- a/cloudbaseinit/tests/plugins/windows/userdataplugins/test_parthandler.py +++ b/cloudbaseinit/tests/plugins/windows/userdataplugins/test_parthandler.py @@ -1,5 +1,3 @@ -# vim: tabstop=4 shiftwidth=4 softtabstop=4 - # Copyright 2013 Cloudbase Solutions Srl # # Licensed under the Apache License, Version 2.0 (the "License"); you may @@ -14,10 +12,13 @@ # License for the specific language governing permissions and limitations # under the License. -import mock import os import unittest +try: + import unittest.mock as mock +except ImportError: + import mock from oslo.config import cfg from cloudbaseinit.plugins.windows.userdataplugins import parthandler diff --git a/cloudbaseinit/tests/plugins/windows/userdataplugins/test_shellscript.py b/cloudbaseinit/tests/plugins/windows/userdataplugins/test_shellscript.py index 71680aef..448378e4 100644 --- a/cloudbaseinit/tests/plugins/windows/userdataplugins/test_shellscript.py +++ b/cloudbaseinit/tests/plugins/windows/userdataplugins/test_shellscript.py @@ -12,10 +12,14 @@ # License for the specific language governing permissions and limitations # under the License. -import mock import os import unittest +try: + import unittest.mock as mock +except ImportError: + import mock + from cloudbaseinit.plugins.windows.userdataplugins import shellscript diff --git a/cloudbaseinit/tests/test_init.py b/cloudbaseinit/tests/test_init.py index 7b254686..ee146e2f 100644 --- a/cloudbaseinit/tests/test_init.py +++ b/cloudbaseinit/tests/test_init.py @@ -1,5 +1,3 @@ -# vim: tabstop=4 shiftwidth=4 softtabstop=4 - # Copyright 2013 Cloudbase Solutions Srl # # Licensed under the Apache License, Version 2.0 (the "License"); you may @@ -14,10 +12,13 @@ # License for the specific language governing permissions and limitations # under the License. -import mock import sys import unittest +try: + import unittest.mock as mock +except ImportError: + import mock from oslo.config import cfg from cloudbaseinit import init @@ -27,6 +28,7 @@ CONF = cfg.CONF class InitManagerTest(unittest.TestCase): + def setUp(self): self._win32com_mock = mock.MagicMock() self._comtypes_mock = mock.MagicMock() diff --git a/cloudbaseinit/tests/utils/__init__.py b/cloudbaseinit/tests/utils/__init__.py index 73be5543..93daace9 100644 --- a/cloudbaseinit/tests/utils/__init__.py +++ b/cloudbaseinit/tests/utils/__init__.py @@ -1,5 +1,3 @@ -# vim: tabstop=4 shiftwidth=4 softtabstop=4 - # Copyright 2014 Cloudbase Solutions Srl # # Licensed under the Apache License, Version 2.0 (the "License"); you may diff --git a/cloudbaseinit/tests/utils/test_dhcp.py b/cloudbaseinit/tests/utils/test_dhcp.py index 8de6bd5e..bc5b281a 100644 --- a/cloudbaseinit/tests/utils/test_dhcp.py +++ b/cloudbaseinit/tests/utils/test_dhcp.py @@ -12,12 +12,16 @@ # License for the specific language governing permissions and limitations # under the License. -import mock import netifaces import socket import struct import unittest +try: + import unittest.mock as mock +except ImportError: + import mock + from cloudbaseinit.utils import dhcp diff --git a/cloudbaseinit/tests/utils/test_log.py b/cloudbaseinit/tests/utils/test_log.py index 1c872305..0f470beb 100644 --- a/cloudbaseinit/tests/utils/test_log.py +++ b/cloudbaseinit/tests/utils/test_log.py @@ -1,5 +1,3 @@ -# vim: tabstop=4 shiftwidth=4 softtabstop=4 - # Copyright 2014 Cloudbase Solutions Srl # # Licensed under the Apache License, Version 2.0 (the "License"); you may @@ -15,16 +13,20 @@ # under the License. import importlib -import mock -import six import unittest +try: + import unittest.mock as mock +except ImportError: + import mock from oslo.config import cfg +import six CONF = cfg.CONF class SerialPortHandlerTests(unittest.TestCase): + def setUp(self): self._serial = mock.MagicMock() self._stream = mock.MagicMock() diff --git a/cloudbaseinit/tests/utils/test_network.py b/cloudbaseinit/tests/utils/test_network.py index df3ed67d..96af623c 100644 --- a/cloudbaseinit/tests/utils/test_network.py +++ b/cloudbaseinit/tests/utils/test_network.py @@ -1,5 +1,3 @@ -# vim: tabstop=4 shiftwidth=4 softtabstop=4 - # Copyright 2013 Cloudbase Solutions Srl # # Licensed under the Apache License, Version 2.0 (the "License"); you may @@ -14,10 +12,13 @@ # License for the specific language governing permissions and limitations # under the License. -import mock import sys import unittest +try: + import unittest.mock as mock +except ImportError: + import mock from oslo.config import cfg from cloudbaseinit.utils import network @@ -26,6 +27,7 @@ CONF = cfg.CONF class NetworkUtilsTest(unittest.TestCase): + @mock.patch('cloudbaseinit.osutils.factory.get_os_utils') @mock.patch('six.moves.urllib.parse.urlparse') def _test_check_metadata_ip_route(self, mock_urlparse, mock_get_os_utils, diff --git a/cloudbaseinit/tests/utils/windows/__init__.py b/cloudbaseinit/tests/utils/windows/__init__.py index b1fc4995..822cfcac 100644 --- a/cloudbaseinit/tests/utils/windows/__init__.py +++ b/cloudbaseinit/tests/utils/windows/__init__.py @@ -1,5 +1,3 @@ -# vim: tabstop=4 shiftwidth=4 softtabstop=4 - # Copyright 2012 Cloudbase Solutions Srl # # Licensed under the Apache License, Version 2.0 (the "License"); you may diff --git a/cloudbaseinit/tests/utils/windows/test_network.py b/cloudbaseinit/tests/utils/windows/test_network.py index 1a50ad59..5c511c60 100644 --- a/cloudbaseinit/tests/utils/windows/test_network.py +++ b/cloudbaseinit/tests/utils/windows/test_network.py @@ -13,9 +13,13 @@ # under the License. import importlib -import mock import unittest +try: + import unittest.mock as mock +except ImportError: + import mock + from cloudbaseinit import exception as cbinit_exception diff --git a/cloudbaseinit/tests/utils/windows/test_physical_disk.py b/cloudbaseinit/tests/utils/windows/test_physical_disk.py index ab410c57..7ceb4714 100644 --- a/cloudbaseinit/tests/utils/windows/test_physical_disk.py +++ b/cloudbaseinit/tests/utils/windows/test_physical_disk.py @@ -13,9 +13,13 @@ # under the License. import importlib -import mock import unittest +try: + import unittest.mock as mock +except ImportError: + import mock + from cloudbaseinit import exception as cbinit_exception diff --git a/cloudbaseinit/tests/utils/windows/test_security.py b/cloudbaseinit/tests/utils/windows/test_security.py index bb85c1ee..c7734335 100644 --- a/cloudbaseinit/tests/utils/windows/test_security.py +++ b/cloudbaseinit/tests/utils/windows/test_security.py @@ -13,12 +13,17 @@ # under the License. import importlib -import mock import unittest +try: + import unittest.mock as mock +except ImportError: + import mock + class FakeWindowsError(Exception): """WindowsError is available on Windows only.""" + def __init__(self, errno): self.errno = errno diff --git a/cloudbaseinit/tests/utils/windows/test_vds.py b/cloudbaseinit/tests/utils/windows/test_vds.py index 55e40dfe..ea234911 100644 --- a/cloudbaseinit/tests/utils/windows/test_vds.py +++ b/cloudbaseinit/tests/utils/windows/test_vds.py @@ -13,9 +13,13 @@ # under the License. import importlib -import mock import unittest +try: + import unittest.mock as mock +except ImportError: + import mock + class WindowsVdsUtilsTests(unittest.TestCase): diff --git a/cloudbaseinit/tests/utils/windows/test_virtual_disk.py b/cloudbaseinit/tests/utils/windows/test_virtual_disk.py index fdef303b..4a86f319 100644 --- a/cloudbaseinit/tests/utils/windows/test_virtual_disk.py +++ b/cloudbaseinit/tests/utils/windows/test_virtual_disk.py @@ -13,9 +13,13 @@ # under the License. import importlib -import mock import unittest +try: + import unittest.mock as mock +except ImportError: + import mock + from cloudbaseinit import exception diff --git a/cloudbaseinit/tests/utils/windows/test_winrmconfig.py b/cloudbaseinit/tests/utils/windows/test_winrmconfig.py index cadde828..000e6b19 100644 --- a/cloudbaseinit/tests/utils/windows/test_winrmconfig.py +++ b/cloudbaseinit/tests/utils/windows/test_winrmconfig.py @@ -1,5 +1,3 @@ -# vim: tabstop=4 shiftwidth=4 softtabstop=4 - # Copyright 2013 Cloudbase Solutions Srl # # Licensed under the Apache License, Version 2.0 (the "License"); you may @@ -15,14 +13,19 @@ # under the License. import importlib -import mock import unittest +try: + import unittest.mock as mock +except ImportError: + import mock + from cloudbaseinit import exception from cloudbaseinit.tests import fake class WinRMConfigTests(unittest.TestCase): + def setUp(self): self._pywintypes_mock = mock.MagicMock() self._pywintypes_mock.com_error = fake.FakeComError diff --git a/cloudbaseinit/tests/utils/windows/test_ws2_32.py b/cloudbaseinit/tests/utils/windows/test_ws2_32.py index 1ac95255..fe821168 100644 --- a/cloudbaseinit/tests/utils/windows/test_ws2_32.py +++ b/cloudbaseinit/tests/utils/windows/test_ws2_32.py @@ -13,9 +13,13 @@ # under the License. import importlib -import mock import unittest +try: + import unittest.mock as mock +except ImportError: + import mock + class WS2_32UtilsTests(unittest.TestCase): diff --git a/cloudbaseinit/tests/utils/windows/test_x509.py b/cloudbaseinit/tests/utils/windows/test_x509.py index e5298082..6423545a 100644 --- a/cloudbaseinit/tests/utils/windows/test_x509.py +++ b/cloudbaseinit/tests/utils/windows/test_x509.py @@ -1,5 +1,3 @@ -# vim: tabstop=4 shiftwidth=4 softtabstop=4 - # Copyright 2013 Cloudbase Solutions Srl # # Licensed under the Apache License, Version 2.0 (the "License"); you may @@ -15,10 +13,14 @@ # under the License. import importlib -import mock import six import unittest +try: + import unittest.mock as mock +except ImportError: + import mock + from cloudbaseinit.utils import x509constants diff --git a/cloudbaseinit/utils/classloader.py b/cloudbaseinit/utils/classloader.py index e7ce0e41..2519fbd4 100644 --- a/cloudbaseinit/utils/classloader.py +++ b/cloudbaseinit/utils/classloader.py @@ -1,5 +1,3 @@ -# vim: tabstop=4 shiftwidth=4 softtabstop=4 - # Copyright 2012 Cloudbase Solutions Srl # # Licensed under the Apache License, Version 2.0 (the "License"); you may @@ -23,6 +21,7 @@ LOG = logging.getLogger(__name__) class ClassLoader(object): + def load_class(self, class_path): LOG.debug('Loading class \'%s\'' % class_path) parts = class_path.rsplit('.', 1) diff --git a/cloudbaseinit/utils/crypt.py b/cloudbaseinit/utils/crypt.py index 3557603d..28203598 100644 --- a/cloudbaseinit/utils/crypt.py +++ b/cloudbaseinit/utils/crypt.py @@ -1,5 +1,3 @@ -# vim: tabstop=4 shiftwidth=4 softtabstop=4 - # Copyright 2013 Cloudbase Solutions Srl # # Licensed under the Apache License, Version 2.0 (the "License"); you may @@ -103,6 +101,7 @@ class CryptException(Exception): class OpenSSLException(CryptException): + def __init__(self): message = self._get_openssl_error_msg() super(OpenSSLException, self).__init__(message) @@ -116,6 +115,7 @@ class OpenSSLException(CryptException): class RSAWrapper(object): + def __init__(self, rsa_p): self._rsa_p = rsa_p @@ -145,6 +145,7 @@ class RSAWrapper(object): class CryptManager(object): + def load_ssh_rsa_public_key(self, ssh_pub_key): ssh_rsa_prefix = "ssh-rsa " diff --git a/cloudbaseinit/utils/encoding.py b/cloudbaseinit/utils/encoding.py index 7a09e90d..dec6bc3a 100644 --- a/cloudbaseinit/utils/encoding.py +++ b/cloudbaseinit/utils/encoding.py @@ -1,5 +1,3 @@ -# vim: tabstop=4 shiftwidth=4 softtabstop=4 - # Copyright 2014 Cloudbase Solutions Srl # # Licensed under the Apache License, Version 2.0 (the "License"); you may diff --git a/cloudbaseinit/utils/log.py b/cloudbaseinit/utils/log.py index 10cd2614..4e6d530d 100644 --- a/cloudbaseinit/utils/log.py +++ b/cloudbaseinit/utils/log.py @@ -35,7 +35,9 @@ LOG = openstack_logging.getLogger(__name__) class SerialPortHandler(logging.StreamHandler): + class _UnicodeToBytesStream(object): + def __init__(self, stream): self._stream = stream diff --git a/cloudbaseinit/utils/network.py b/cloudbaseinit/utils/network.py index 4864038e..f3a651f1 100644 --- a/cloudbaseinit/utils/network.py +++ b/cloudbaseinit/utils/network.py @@ -37,7 +37,7 @@ def check_url(url, retries_count=MAX_URL_CHECK_RETRIES): def check_metadata_ip_route(metadata_url): - #Workaround for: https://bugs.launchpad.net/quantum/+bug/1174657 + # Workaround for: https://bugs.launchpad.net/quantum/+bug/1174657 osutils = osutils_factory.get_os_utils() if sys.platform == 'win32' and osutils.check_os_version(6, 0): diff --git a/cloudbaseinit/utils/windows/cryptoapi.py b/cloudbaseinit/utils/windows/cryptoapi.py index 76b12ddf..86a27e9f 100644 --- a/cloudbaseinit/utils/windows/cryptoapi.py +++ b/cloudbaseinit/utils/windows/cryptoapi.py @@ -1,5 +1,3 @@ -# vim: tabstop=4 shiftwidth=4 softtabstop=4 - # Copyright 2013 Cloudbase Solutions Srl # # Licensed under the Apache License, Version 2.0 (the "License"); you may @@ -21,6 +19,7 @@ from ctypes import wintypes class CryptoAPIException(Exception): + def __init__(self): message = self._get_windows_error() super(CryptoAPIException, self).__init__(message) diff --git a/cloudbaseinit/utils/windows/physical_disk.py b/cloudbaseinit/utils/windows/physical_disk.py index 04feb135..cd52e075 100644 --- a/cloudbaseinit/utils/windows/physical_disk.py +++ b/cloudbaseinit/utils/windows/physical_disk.py @@ -1,5 +1,3 @@ -# vim: tabstop=4 shiftwidth=4 softtabstop=4 - # Copyright 2012 Cloudbase Solutions Srl # # Licensed under the Apache License, Version 2.0 (the "License"); you may diff --git a/cloudbaseinit/utils/windows/vds.py b/cloudbaseinit/utils/windows/vds.py index 6c62e982..315f33dc 100644 --- a/cloudbaseinit/utils/windows/vds.py +++ b/cloudbaseinit/utils/windows/vds.py @@ -1,5 +1,3 @@ -# vim: tabstop=4 shiftwidth=4 softtabstop=4 - # Copyright (c) 2013 Cloudbase Solutions Srl # # Licensed under the Apache License, Version 2.0 (the "License"); you may diff --git a/cloudbaseinit/utils/windows/virtual_disk.py b/cloudbaseinit/utils/windows/virtual_disk.py index c7693723..db266330 100644 --- a/cloudbaseinit/utils/windows/virtual_disk.py +++ b/cloudbaseinit/utils/windows/virtual_disk.py @@ -1,5 +1,3 @@ -# vim: tabstop=4 shiftwidth=4 softtabstop=4 - # Copyright 2012 Cloudbase Solutions Srl # # Licensed under the Apache License, Version 2.0 (the "License"); you may diff --git a/cloudbaseinit/utils/windows/winrmconfig.py b/cloudbaseinit/utils/windows/winrmconfig.py index da25e023..9505152a 100644 --- a/cloudbaseinit/utils/windows/winrmconfig.py +++ b/cloudbaseinit/utils/windows/winrmconfig.py @@ -1,5 +1,3 @@ -# vim: tabstop=4 shiftwidth=4 softtabstop=4 - # Copyright 2012 Cloudbase Solutions Srl # # Licensed under the Apache License, Version 2.0 (the "License"); you may diff --git a/setup.py b/setup.py index 014dd5dc..e53e1dad 100644 --- a/setup.py +++ b/setup.py @@ -1,5 +1,3 @@ -# vim: tabstop=4 shiftwidth=4 softtabstop=4 - # Copyright 2012 Cloudbase Solutions Srl # # Licensed under the Apache License, Version 2.0 (the "License"); you may