diff --git a/.testr.conf b/.testr.conf new file mode 100644 index 00000000..c6836400 --- /dev/null +++ b/.testr.conf @@ -0,0 +1,8 @@ +[DEFAULT] +test_command=OS_STDOUT_CAPTURE=${OS_STDOUT_CAPTURE:-1} \ + OS_STDERR_CAPTURE=${OS_STDERR_CAPTURE:-1} \ + OS_TEST_TIMEOUT=${OS_TEST_TIMEOUT:-160} \ + ${PYTHON:-python} -m subunit.run discover -t ./ ./cloudbaseinit/tests $LISTOPT $IDOPTION + +test_id_option=--load-list $IDFILE +test_list_option=--list diff --git a/cloudbaseinit/exception.py b/cloudbaseinit/exception.py index e78aa442..147611b9 100644 --- a/cloudbaseinit/exception.py +++ b/cloudbaseinit/exception.py @@ -9,7 +9,8 @@ # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific +# License for the specific language governing permissions and limitations +# under the License. class CloudbaseInitException(Exception): diff --git a/cloudbaseinit/metadata/services/base.py b/cloudbaseinit/metadata/services/base.py index 7d4b8424..c4b0735a 100644 --- a/cloudbaseinit/metadata/services/base.py +++ b/cloudbaseinit/metadata/services/base.py @@ -62,7 +62,7 @@ class BaseMetadataService(object): return action() except NotExistingMetadataException: raise - except: + except Exception: if self._enable_retry and i < CONF.retry_count: i += 1 time.sleep(CONF.retry_count_interval) diff --git a/cloudbaseinit/plugins/windows/createuser.py b/cloudbaseinit/plugins/windows/createuser.py index 16fdcb12..ce17c81f 100644 --- a/cloudbaseinit/plugins/windows/createuser.py +++ b/cloudbaseinit/plugins/windows/createuser.py @@ -2,14 +2,14 @@ # Copyright 2012 Cloudbase Solutions Srl # -# Licensed under the Apache License, Version 2.0 (the 'License'); you may +# Licensed under the Apache License, Version 2.0 (the "License"); you may # not use this file except in compliance with the License. You may obtain # a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an 'AS IS' BASIS, WITHOUT +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the # License for the specific language governing permissions and limitations # under the License. diff --git a/cloudbaseinit/plugins/windows/networkconfig.py b/cloudbaseinit/plugins/windows/networkconfig.py index ba2c9234..64037bb3 100644 --- a/cloudbaseinit/plugins/windows/networkconfig.py +++ b/cloudbaseinit/plugins/windows/networkconfig.py @@ -50,7 +50,7 @@ class NetworkConfigPlugin(base.BasePlugin): LOG.debug('network config content:\n%s' % debian_network_conf) - # TODO (alexpilotti): implement a proper grammar + # TODO(alexpilotti): implement a proper grammar m = re.search(r'iface eth0 inet static\s+' r'address\s+(?P
[^\s]+)\s+' r'netmask\s+(?P[^\s]+)\s+' diff --git a/cloudbaseinit/plugins/windows/setuserpassword.py b/cloudbaseinit/plugins/windows/setuserpassword.py index ac18614a..287966ff 100644 --- a/cloudbaseinit/plugins/windows/setuserpassword.py +++ b/cloudbaseinit/plugins/windows/setuserpassword.py @@ -2,14 +2,14 @@ # Copyright 2013 Cloudbase Solutions Srl # -# Licensed under the Apache License, Version 2.0 (the 'License'); you may +# Licensed under the Apache License, Version 2.0 (the "License"); you may # not use this file except in compliance with the License. You may obtain # a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an 'AS IS' BASIS, WITHOUT +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the # License for the specific language governing permissions and limitations # under the License. diff --git a/cloudbaseinit/plugins/windows/winrmcertificateauth.py b/cloudbaseinit/plugins/windows/winrmcertificateauth.py index 5d66bef2..727a129a 100644 --- a/cloudbaseinit/plugins/windows/winrmcertificateauth.py +++ b/cloudbaseinit/plugins/windows/winrmcertificateauth.py @@ -2,14 +2,14 @@ # Copyright 2013 Cloudbase Solutions Srl # -# Licensed under the Apache License, Version 2.0 (the 'License'); you may +# Licensed under the Apache License, Version 2.0 (the "License"); you may # not use this file except in compliance with the License. You may obtain # a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an 'AS IS' BASIS, WITHOUT +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the # License for the specific language governing permissions and limitations # under the License. diff --git a/cloudbaseinit/plugins/windows/winrmlistener.py b/cloudbaseinit/plugins/windows/winrmlistener.py index 6f7544ba..76770f23 100644 --- a/cloudbaseinit/plugins/windows/winrmlistener.py +++ b/cloudbaseinit/plugins/windows/winrmlistener.py @@ -2,14 +2,14 @@ # Copyright 2013 Cloudbase Solutions Srl # -# Licensed under the Apache License, Version 2.0 (the 'License'); you may +# Licensed under the Apache License, Version 2.0 (the "License"); you may # not use this file except in compliance with the License. You may obtain # a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an 'AS IS' BASIS, WITHOUT +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the # License for the specific language governing permissions and limitations # under the License. diff --git a/cloudbaseinit/tests/metadata/services/test_maasservice.py b/cloudbaseinit/tests/metadata/services/test_maasservice.py index e9dae179..02285b9a 100644 --- a/cloudbaseinit/tests/metadata/services/test_maasservice.py +++ b/cloudbaseinit/tests/metadata/services/test_maasservice.py @@ -17,23 +17,30 @@ import mock import os import posixpath +import sys import unittest from oslo.config import cfg from six.moves.urllib import error from cloudbaseinit.metadata.services import base -from cloudbaseinit.metadata.services import maasservice from cloudbaseinit.utils import x509constants +if sys.version_info < (3, 0): + # TODO(alexpilotti) replace oauth with a Python 3 compatible module + from cloudbaseinit.metadata.services import maasservice + CONF = cfg.CONF class MaaSHttpServiceTest(unittest.TestCase): def setUp(self): - self.mock_oauth = mock.MagicMock() - maasservice.oauth = self.mock_oauth - self._maasservice = maasservice.MaaSHttpService() + if sys.version_info < (3, 0): + self.mock_oauth = mock.MagicMock() + maasservice.oauth = self.mock_oauth + self._maasservice = maasservice.MaaSHttpService() + else: + self.skipTest("Python 3 is not yet supported for maasservice") @mock.patch("cloudbaseinit.metadata.services.maasservice.MaaSHttpService" "._get_data") diff --git a/cloudbaseinit/tests/plugins/windows/test_winrmcertificateauth.py b/cloudbaseinit/tests/plugins/windows/test_winrmcertificateauth.py index 94358707..33c048cd 100644 --- a/cloudbaseinit/tests/plugins/windows/test_winrmcertificateauth.py +++ b/cloudbaseinit/tests/plugins/windows/test_winrmcertificateauth.py @@ -2,14 +2,14 @@ # Copyright 2013 Cloudbase Solutions Srl # -# Licensed under the Apache License, Version 2.0 (the 'License'); you may +# Licensed under the Apache License, Version 2.0 (the "License"); you may # not use this file except in compliance with the License. You may obtain # a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an 'AS IS' BASIS, WITHOUT +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the # License for the specific language governing permissions and limitations # under the License. diff --git a/cloudbaseinit/tests/plugins/windows/test_winrmlistener.py b/cloudbaseinit/tests/plugins/windows/test_winrmlistener.py index 698725e1..7eb736e3 100644 --- a/cloudbaseinit/tests/plugins/windows/test_winrmlistener.py +++ b/cloudbaseinit/tests/plugins/windows/test_winrmlistener.py @@ -2,14 +2,14 @@ # Copyright 2013 Cloudbase Solutions Srl # -# Licensed under the Apache License, Version 2.0 (the 'License'); you may +# Licensed under the Apache License, Version 2.0 (the "License"); you may # not use this file except in compliance with the License. You may obtain # a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an 'AS IS' BASIS, WITHOUT +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the # License for the specific language governing permissions and limitations # under the License. diff --git a/cloudbaseinit/tests/utils/windows/test_winrmconfig.py b/cloudbaseinit/tests/utils/windows/test_winrmconfig.py index fc7de516..3b352ff8 100644 --- a/cloudbaseinit/tests/utils/windows/test_winrmconfig.py +++ b/cloudbaseinit/tests/utils/windows/test_winrmconfig.py @@ -18,11 +18,19 @@ import importlib import mock import unittest +from cloudbaseinit import exception + + +class FakeComError(Exception): + def __init__(self): + super(FakeComError, self).__init__() + self.excepinfo = [None, None, None, None, None, -2144108544] + class WinRMConfigTests(unittest.TestCase): - def setUp(self): self._pywintypes_mock = mock.MagicMock() + self._pywintypes_mock.com_error = FakeComError self._win32com_mock = mock.MagicMock() self._module_patcher = mock.patch.dict( 'sys.modules', @@ -179,8 +187,9 @@ class WinRMConfigTests(unittest.TestCase): fake_session.Get.side_effect = [resource] mock_get_wsman_session.return_value = fake_session - if resource is Exception: - self.assertRaises(Exception, self._winrmconfig._get_resource, + if resource is exception.CloudbaseInitException: + self.assertRaises(exception.CloudbaseInitException, + self._winrmconfig._get_resource, fake_uri) else: response = self._winrmconfig._get_resource(fake_uri) @@ -193,7 +202,7 @@ class WinRMConfigTests(unittest.TestCase): self._test_get_resource(resource='fake resource') def test_get_resource_exception(self): - self._test_get_resource(resource=Exception) + self._test_get_resource(resource=exception.CloudbaseInitException) @mock.patch('cloudbaseinit.utils.windows.winrmconfig.WinRMConfig.' '_get_wsman_session') diff --git a/cloudbaseinit/utils/crypt.py b/cloudbaseinit/utils/crypt.py index c125e66b..ece1f422 100644 --- a/cloudbaseinit/utils/crypt.py +++ b/cloudbaseinit/utils/crypt.py @@ -193,6 +193,6 @@ class CryptManager(object): raise OpenSSLException() return RSAWrapper(rsa_p) - except: + except Exception: openssl.RSA_free(rsa_p) raise diff --git a/cloudbaseinit/utils/network.py b/cloudbaseinit/utils/network.py index d95f4d9a..4864038e 100644 --- a/cloudbaseinit/utils/network.py +++ b/cloudbaseinit/utils/network.py @@ -37,9 +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/doc/source/conf.py b/doc/source/conf.py new file mode 100644 index 00000000..1610bf42 --- /dev/null +++ b/doc/source/conf.py @@ -0,0 +1 @@ +# Temporary placeholder diff --git a/requirements.txt b/requirements.txt index 03a31c9c..dfd19515 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,9 +1,7 @@ pbr>=0.5.22,!=0.5.23,<1.0 -pywin32 -comtypes -wmi iso8601 eventlet +netaddr>=0.7.6 pyserial oslo.config six>=1.7.0 diff --git a/setup.cfg b/setup.cfg index a0ee8fd9..92d634aa 100644 --- a/setup.cfg +++ b/setup.cfg @@ -28,6 +28,9 @@ packages = setup-hooks = pbr.hooks.setup_hook +[build_sphinx] +source-dir = doc/source + [entry_points] console_scripts = cloudbase-init = cloudbaseinit.shell:main diff --git a/setup.py b/setup.py index 4163c22d..4dd2e778 100644 --- a/setup.py +++ b/setup.py @@ -15,7 +15,13 @@ # under the License. import setuptools +import sys + +if sys.platform == 'win32': + platform_requirements = ['pywin32', 'comtypes', 'wmi'] +else: + platform_requirements = [] setuptools.setup( - setup_requires=['pbr>=0.5.22,!=0.5.23'], + setup_requires=['pbr>=0.5.22,!=0.5.23'] + platform_requirements, pbr=True) diff --git a/test-requirements.txt b/test-requirements.txt index 03340308..7d168255 100644 --- a/test-requirements.txt +++ b/test-requirements.txt @@ -2,4 +2,7 @@ hacking>=0.5.6,<0.8 coverage>=3.6 fixtures>=0.3.14 mock>=1.0 +sphinx>=1.1.2,<1.1.999 +oslosphinx testtools>=0.9.32 +testrepository>=0.0.18