Fix usage of dependencies

Manila is broken is threee places, so fix them:
1) test 'test_misc' with WebOb 1.5

WebOb 1.5 was released at 2015-10-11. With this new version,
webob.exc.WSGIHTTPException() constructor now fails with a KeyError
when the HTTP status code is 0.

test_exceptions_raise() of test_misc tries to instantiate all
exceptions of manila.exception. The problem is that
ConvertedException uses a default HTTP status code of 0.

Modify the default HTTP status code of ConvertedException to 400 to
fix the unit tests.

2) Add dependency for 'testresources' that is required by migration
tests.

3) Remove 2 unit tests related to testing of oslo.policy lib
functionality that should not be tested in Manila. It started failing
because under-the-hood behaviour was changed in new realese 0.12.0

Closes-Bug: #1505153
Closes-Bug: #1505374

(cherry picked from commit 9c99814ce5)

-- squashed with another change to get tests to pass on stable/liberty --

Fix broken unit tests

With release of six module version 1.10.0 several our unit tests
started to fail because of usage of not strict constructions.

Changes:
1) Manila unit test
"manila.tests.share.test_api.ShareAPITestCase.test_extend_quota_error"
used str for int substitution. So, use int data for int substitution.

2) Module 'manila.share.drivers.hp.hp_3par_mediator' was using
LOG.exception function when no traceback were exist it led to
AttributeError on py34. So, replace all usages of 'LOG.exception'
with 'LOG.error' where no raised exceptions exist.

Change-Id: Ic5b37bfb9d939d03f6ff68bc53d134bf9e5f996e
Closes-Bug: #1503969
(cherry picked from commit f38b8d4efd)

--

Change-Id: I0f28f3c3fb2c7eec1bafc3a617344990f86810cf
This commit is contained in:
Gaurang Tapase 2015-10-12 20:47:19 +05:30 committed by Matt Riedemann
parent 3b79a76b5d
commit f1eded1fbc
5 changed files with 18 additions and 42 deletions

View File

@ -48,7 +48,7 @@ ProcessExecutionError = processutils.ProcessExecutionError
class ConvertedException(webob.exc.WSGIHTTPException):
def __init__(self, code=0, title="", explanation=""):
def __init__(self, code=400, title="", explanation=""):
self.code = code
self.title = title
self.explanation = explanation

View File

@ -91,7 +91,7 @@ class HP3ParMediator(object):
if self.no_client():
msg = _('You must install hp3parclient before using the 3PAR '
'driver.')
LOG.exception(msg)
LOG.error(msg)
raise exception.HP3ParInvalidClient(message=msg)
self.client_version = hp3parclient.version_tuple
@ -101,7 +101,7 @@ class HP3ParMediator(object):
{'found': '.'.join(map(six.text_type, self.client_version)),
'minimum': '.'.join(map(six.text_type,
MIN_CLIENT_VERSION))})
LOG.exception(msg)
LOG.error(msg)
raise exception.HP3ParInvalidClient(message=msg)
try:
@ -200,12 +200,12 @@ class HP3ParMediator(object):
except Exception as e:
msg = (_('Failed to get capacity for fpg %(fpg)s: %(e)s') %
{'fpg': fpg, 'e': six.text_type(e)})
LOG.exception(msg)
LOG.error(msg)
raise exception.ShareBackendException(msg=msg)
if result['total'] != 1:
msg = (_('Failed to get capacity for fpg %s.') % fpg)
LOG.exception(msg)
LOG.error(msg)
raise exception.ShareBackendException(msg=msg)
member = result['members'][0]
@ -229,7 +229,7 @@ class HP3ParMediator(object):
if provisioning_type not in (THIN, FULL, DEDUPE):
msg = (_('Unexpected provisioning type for FPG %(fpg)s: '
'%(ptype)s.') % {'fpg': fpg, 'ptype': provisioning_type})
LOG.exception(msg)
LOG.error(msg)
raise exception.ShareBackendException(msg=msg)
dedupe = provisioning_type == DEDUPE
@ -259,7 +259,7 @@ class HP3ParMediator(object):
if protocol not in ['smb', 'nfs']:
message = (_('Invalid protocol. Expected nfs or smb. Got %s.') %
protocol)
LOG.exception(message)
LOG.error(message)
raise exception.InvalidInput(message)
return protocol
@ -460,7 +460,7 @@ class HP3ParMediator(object):
msg = (_('Failed to get fshare %(share_name)s after creating it. '
'Expected to get 1 fshare. Got %(total)s.') %
{'share_name': share_name, 'total': result['total']})
LOG.exception(msg)
LOG.error(msg)
raise exception.ShareBackendException(msg)
if protocol == 'nfs':
@ -492,7 +492,7 @@ class HP3ParMediator(object):
'fpg': fpg,
'vfs': vfs,
'tag': snapshot_tag})
LOG.exception(msg)
LOG.error(msg)
raise exception.ShareBackendException(msg)
fstore = snapshot['fstoreName']
@ -594,7 +594,7 @@ class HP3ParMediator(object):
msg = (_('Failed to create snapshot for FPG/VFS/fshare '
'%(fpg)s/%(vfs)s/%(fshare)s: Failed to find fshare.') %
{'fpg': fpg, 'vfs': vfs, 'fshare': orig_share_id})
LOG.exception(msg)
LOG.error(msg)
raise exception.ShareBackendException(msg)
sharedir = fshare.get('shareDir')
@ -603,7 +603,7 @@ class HP3ParMediator(object):
'%(fpg)s/%(vfs)s/%(fshare)s: Share is a read-only '
'share of an existing snapshot.') %
{'fpg': fpg, 'vfs': vfs, 'fshare': orig_share_id})
LOG.exception(msg)
LOG.error(msg)
raise exception.ShareBackendException(msg)
fstore = fshare.get('fstoreName')
@ -702,13 +702,13 @@ class HP3ParMediator(object):
if access_type not in ('ip', 'user'):
msg = (_("Invalid access type. Expected 'ip' or 'user'. "
"Actual '%s'.") % access_type)
LOG.exception(msg)
LOG.error(msg)
raise exception.InvalidInput(msg)
if protocol == 'nfs' and access_type != 'ip':
msg = (_("Invalid NFS access type. HP 3PAR NFS supports 'ip'. "
"Actual '%s'.") % access_type)
LOG.exception(msg)
LOG.error(msg)
raise exception.HP3ParInvalid(msg)
return protocol
@ -892,7 +892,7 @@ class HP3ParMediator(object):
'FPG/VFS/IP/subnet/VLAN '
'%(fspool)s/%(vfs)s/'
'%(address)s/%(prefixLen)s/%(vlanTag)s.') % fsip)
LOG.exception(msg)
LOG.error(msg)
raise exception.ShareBackendException(msg=msg)
def remove_fsip(self, ip, fpg, vfs):
@ -920,5 +920,5 @@ class HP3ParMediator(object):
if self.fsip_exists(fsip):
msg = (_('Failed to remove FSIP for FPG/VFS/IP '
'%(fspool)s/%(vfs)s/%(address)s.') % fsip)
LOG.exception(msg)
LOG.error(msg)
raise exception.ShareBackendException(msg=msg)

View File

@ -1517,8 +1517,8 @@ class ShareAPITestCase(test.TestCase):
share = db_utils.create_share(status=constants.STATUS_AVAILABLE,
size=100)
new_size = 123
usages = {'gigabytes': {'reserved': 'fake', 'in_use': 'fake'}}
quotas = {'gigabytes': 'fake'}
usages = {'gigabytes': {'reserved': 11, 'in_use': 12}}
quotas = {'gigabytes': 13}
exc = exception.OverQuota(usages=usages, quotas=quotas, overs=new_size)
self.mock_object(quota.QUOTAS, 'reserve', mock.Mock(side_effect=exc))

View File

@ -17,11 +17,8 @@
import os.path
import mock
from oslo_config import cfg
from oslo_policy import policy as common_policy
import six
from six.moves.urllib import request as urlrequest
from manila import context
from manila import exception
@ -107,28 +104,6 @@ class PolicyTestCase(test.TestCase):
action = "example:allowed"
policy.enforce(self.context, action, self.target)
def test_enforce_http_true(self):
def fakeurlopen(url, post_data):
return six.StringIO("True")
action = "example:get_http"
target = {}
with mock.patch.object(urlrequest, 'urlopen', fakeurlopen):
result = policy.enforce(self.context, action, target)
self.assertTrue(result)
def test_enforce_http_false(self):
def fakeurlopen(url, post_data):
return six.StringIO("False")
action = "example:get_http"
target = {}
with mock.patch.object(urlrequest, 'urlopen', fakeurlopen):
self.assertRaises(exception.PolicyNotAuthorized, policy.enforce,
self.context, action, target)
def test_templatized_enforcement(self):
target_mine = {'project_id': 'fake'}
target_not_mine = {'project_id': 'another'}

View File

@ -18,4 +18,5 @@ python-subunit>=0.0.18
requests-mock>=0.6.0 # Apache-2.0
sphinx!=1.2.0,!=1.3b1,<1.3,>=1.1.2
testrepository>=0.0.18
testresources>=0.2.4
testtools>=1.4.0