Skip to content

Commit

Permalink
Fixes requirements on Linux
Browse files Browse the repository at this point in the history
Platform specific requirements can not be included in requirements.txt

Includes also:

* testr configuration file
* PEP8 fixes
* Unit test fixes for passing OpenStack Jenkins checks

Change-Id: I6f3f367f3316e0b506bb62e66d7671f9e52c72b5
Closes-Bug: #1376816
  • Loading branch information
alexpilotti committed Oct 5, 2014
1 parent 5c15cbf commit 23ddd33
Show file tree
Hide file tree
Showing 19 changed files with 65 additions and 31 deletions.
8 changes: 8 additions & 0 deletions .testr.conf
Original file line number Diff line number Diff line change
@@ -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
3 changes: 2 additions & 1 deletion cloudbaseinit/exception.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
2 changes: 1 addition & 1 deletion cloudbaseinit/metadata/services/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ def _exec_with_retry(self, action):
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)
Expand Down
4 changes: 2 additions & 2 deletions cloudbaseinit/plugins/windows/createuser.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion cloudbaseinit/plugins/windows/networkconfig.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ def execute(self, service, shared_data):

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<address>[^\s]+)\s+'
r'netmask\s+(?P<netmask>[^\s]+)\s+'
Expand Down
4 changes: 2 additions & 2 deletions cloudbaseinit/plugins/windows/setuserpassword.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
4 changes: 2 additions & 2 deletions cloudbaseinit/plugins/windows/winrmcertificateauth.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
4 changes: 2 additions & 2 deletions cloudbaseinit/plugins/windows/winrmlistener.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
15 changes: 11 additions & 4 deletions cloudbaseinit/tests/metadata/services/test_maasservice.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
4 changes: 2 additions & 2 deletions cloudbaseinit/tests/plugins/windows/test_winrmlistener.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
17 changes: 13 additions & 4 deletions cloudbaseinit/tests/utils/windows/test_winrmconfig.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,19 @@
import mock
import unittest

from cloudbaseinit import exception

class WinRMConfigTests(unittest.TestCase):

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',
Expand Down Expand Up @@ -179,8 +187,9 @@ def _test_get_resource(self, mock_get_wsman_session, resource):
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)
Expand All @@ -193,7 +202,7 @@ def test_get_resource(self):
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')
Expand Down
2 changes: 1 addition & 1 deletion cloudbaseinit/utils/crypt.py
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,6 @@ def load_ssh_rsa_public_key(self, ssh_pub_key):
raise OpenSSLException()

return RSAWrapper(rsa_p)
except:
except Exception:
openssl.RSA_free(rsa_p)
raise
4 changes: 1 addition & 3 deletions cloudbaseinit/utils/network.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
1 change: 1 addition & 0 deletions doc/source/conf.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# Temporary placeholder
4 changes: 1 addition & 3 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -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
Expand Down
3 changes: 3 additions & 0 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -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
8 changes: 7 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
3 changes: 3 additions & 0 deletions test-requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 23ddd33

Please sign in to comment.