Browse Source

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
Gaurang Tapase 3 years ago
parent
commit
f1eded1fbc

+ 1
- 1
manila/exception.py View File

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

+ 14
- 14
manila/share/drivers/hp/hp_3par_mediator.py View File

@@ -91,7 +91,7 @@ class HP3ParMediator(object):
91 91
         if self.no_client():
92 92
             msg = _('You must install hp3parclient before using the 3PAR '
93 93
                     'driver.')
94
-            LOG.exception(msg)
94
+            LOG.error(msg)
95 95
             raise exception.HP3ParInvalidClient(message=msg)
96 96
 
97 97
         self.client_version = hp3parclient.version_tuple
@@ -101,7 +101,7 @@ class HP3ParMediator(object):
101 101
                    {'found': '.'.join(map(six.text_type, self.client_version)),
102 102
                     'minimum': '.'.join(map(six.text_type,
103 103
                                             MIN_CLIENT_VERSION))})
104
-            LOG.exception(msg)
104
+            LOG.error(msg)
105 105
             raise exception.HP3ParInvalidClient(message=msg)
106 106
 
107 107
         try:
@@ -200,12 +200,12 @@ class HP3ParMediator(object):
200 200
         except Exception as e:
201 201
             msg = (_('Failed to get capacity for fpg %(fpg)s: %(e)s') %
202 202
                    {'fpg': fpg, 'e': six.text_type(e)})
203
-            LOG.exception(msg)
203
+            LOG.error(msg)
204 204
             raise exception.ShareBackendException(msg=msg)
205 205
 
206 206
         if result['total'] != 1:
207 207
             msg = (_('Failed to get capacity for fpg %s.') % fpg)
208
-            LOG.exception(msg)
208
+            LOG.error(msg)
209 209
             raise exception.ShareBackendException(msg=msg)
210 210
 
211 211
         member = result['members'][0]
@@ -229,7 +229,7 @@ class HP3ParMediator(object):
229 229
         if provisioning_type not in (THIN, FULL, DEDUPE):
230 230
             msg = (_('Unexpected provisioning type for FPG %(fpg)s: '
231 231
                      '%(ptype)s.') % {'fpg': fpg, 'ptype': provisioning_type})
232
-            LOG.exception(msg)
232
+            LOG.error(msg)
233 233
             raise exception.ShareBackendException(msg=msg)
234 234
 
235 235
         dedupe = provisioning_type == DEDUPE
@@ -259,7 +259,7 @@ class HP3ParMediator(object):
259 259
         if protocol not in ['smb', 'nfs']:
260 260
             message = (_('Invalid protocol. Expected nfs or smb. Got %s.') %
261 261
                        protocol)
262
-            LOG.exception(message)
262
+            LOG.error(message)
263 263
             raise exception.InvalidInput(message)
264 264
         return protocol
265 265
 
@@ -460,7 +460,7 @@ class HP3ParMediator(object):
460 460
             msg = (_('Failed to get fshare %(share_name)s after creating it. '
461 461
                      'Expected to get 1 fshare.  Got %(total)s.') %
462 462
                    {'share_name': share_name, 'total': result['total']})
463
-            LOG.exception(msg)
463
+            LOG.error(msg)
464 464
             raise exception.ShareBackendException(msg)
465 465
 
466 466
         if protocol == 'nfs':
@@ -492,7 +492,7 @@ class HP3ParMediator(object):
492 492
                        'fpg': fpg,
493 493
                        'vfs': vfs,
494 494
                        'tag': snapshot_tag})
495
-            LOG.exception(msg)
495
+            LOG.error(msg)
496 496
             raise exception.ShareBackendException(msg)
497 497
 
498 498
         fstore = snapshot['fstoreName']
@@ -594,7 +594,7 @@ class HP3ParMediator(object):
594 594
             msg = (_('Failed to create snapshot for FPG/VFS/fshare '
595 595
                      '%(fpg)s/%(vfs)s/%(fshare)s: Failed to find fshare.') %
596 596
                    {'fpg': fpg, 'vfs': vfs, 'fshare': orig_share_id})
597
-            LOG.exception(msg)
597
+            LOG.error(msg)
598 598
             raise exception.ShareBackendException(msg)
599 599
 
600 600
         sharedir = fshare.get('shareDir')
@@ -603,7 +603,7 @@ class HP3ParMediator(object):
603 603
                      '%(fpg)s/%(vfs)s/%(fshare)s: Share is a read-only '
604 604
                      'share of an existing snapshot.') %
605 605
                    {'fpg': fpg, 'vfs': vfs, 'fshare': orig_share_id})
606
-            LOG.exception(msg)
606
+            LOG.error(msg)
607 607
             raise exception.ShareBackendException(msg)
608 608
 
609 609
         fstore = fshare.get('fstoreName')
@@ -702,13 +702,13 @@ class HP3ParMediator(object):
702 702
         if access_type not in ('ip', 'user'):
703 703
             msg = (_("Invalid access type.  Expected 'ip' or 'user'.  "
704 704
                      "Actual '%s'.") % access_type)
705
-            LOG.exception(msg)
705
+            LOG.error(msg)
706 706
             raise exception.InvalidInput(msg)
707 707
 
708 708
         if protocol == 'nfs' and access_type != 'ip':
709 709
             msg = (_("Invalid NFS access type.  HP 3PAR NFS supports 'ip'. "
710 710
                      "Actual '%s'.") % access_type)
711
-            LOG.exception(msg)
711
+            LOG.error(msg)
712 712
             raise exception.HP3ParInvalid(msg)
713 713
 
714 714
         return protocol
@@ -892,7 +892,7 @@ class HP3ParMediator(object):
892 892
                      'FPG/VFS/IP/subnet/VLAN '
893 893
                      '%(fspool)s/%(vfs)s/'
894 894
                      '%(address)s/%(prefixLen)s/%(vlanTag)s.') % fsip)
895
-            LOG.exception(msg)
895
+            LOG.error(msg)
896 896
             raise exception.ShareBackendException(msg=msg)
897 897
 
898 898
     def remove_fsip(self, ip, fpg, vfs):
@@ -920,5 +920,5 @@ class HP3ParMediator(object):
920 920
         if self.fsip_exists(fsip):
921 921
             msg = (_('Failed to remove FSIP for FPG/VFS/IP '
922 922
                      '%(fspool)s/%(vfs)s/%(address)s.') % fsip)
923
-            LOG.exception(msg)
923
+            LOG.error(msg)
924 924
             raise exception.ShareBackendException(msg=msg)

+ 2
- 2
manila/tests/share/test_api.py View File

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

+ 0
- 25
manila/tests/test_policy.py View File

@@ -17,11 +17,8 @@
17 17
 
18 18
 import os.path
19 19
 
20
-import mock
21 20
 from oslo_config import cfg
22 21
 from oslo_policy import policy as common_policy
23
-import six
24
-from six.moves.urllib import request as urlrequest
25 22
 
26 23
 from manila import context
27 24
 from manila import exception
@@ -107,28 +104,6 @@ class PolicyTestCase(test.TestCase):
107 104
         action = "example:allowed"
108 105
         policy.enforce(self.context, action, self.target)
109 106
 
110
-    def test_enforce_http_true(self):
111
-
112
-        def fakeurlopen(url, post_data):
113
-            return six.StringIO("True")
114
-
115
-        action = "example:get_http"
116
-        target = {}
117
-        with mock.patch.object(urlrequest, 'urlopen', fakeurlopen):
118
-            result = policy.enforce(self.context, action, target)
119
-        self.assertTrue(result)
120
-
121
-    def test_enforce_http_false(self):
122
-
123
-        def fakeurlopen(url, post_data):
124
-            return six.StringIO("False")
125
-
126
-        action = "example:get_http"
127
-        target = {}
128
-        with mock.patch.object(urlrequest, 'urlopen', fakeurlopen):
129
-            self.assertRaises(exception.PolicyNotAuthorized, policy.enforce,
130
-                              self.context, action, target)
131
-
132 107
     def test_templatized_enforcement(self):
133 108
         target_mine = {'project_id': 'fake'}
134 109
         target_not_mine = {'project_id': 'another'}

+ 1
- 0
test-requirements.txt View File

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

Loading…
Cancel
Save