14
14
# under the License.
15
15
16
16
from cinderclient import api_versions as cinder_api_versions
17
- from cinderclient import apiclient as cinder_apiclient
18
17
from cinderclient import exceptions as cinder_exception
19
18
from cinderclient .v2 import limits as cinder_limits
20
19
from keystoneauth1 import loading as ks_loading
@@ -546,11 +545,12 @@ def test_attachment_delete_unsupported_api_version(self,
546
545
mock_cinderclient .assert_called_once_with (self .ctx , '3.44' ,
547
546
skip_version_check = True )
548
547
549
- @mock .patch ('nova.volume.cinder.cinderclient' ,
550
- side_effect = cinder_apiclient .exceptions .InternalServerError )
548
+ @mock .patch ('nova.volume.cinder.cinderclient' )
551
549
def test_attachment_delete_internal_server_error (self , mock_cinderclient ):
550
+ mock_cinderclient .return_value .attachments .delete .side_effect = (
551
+ cinder_exception .ClientException (500 ))
552
552
553
- self .assertRaises (cinder_apiclient . exceptions . InternalServerError ,
553
+ self .assertRaises (cinder_exception . ClientException ,
554
554
self .api .attachment_delete ,
555
555
self .ctx , uuids .attachment_id )
556
556
@@ -561,16 +561,17 @@ def test_attachment_delete_internal_server_error_do_not_raise(
561
561
self , mock_cinderclient ):
562
562
# generate exception, and then have a normal return on the next retry
563
563
mock_cinderclient .return_value .attachments .delete .side_effect = [
564
- cinder_apiclient . exceptions . InternalServerError , None ]
564
+ cinder_exception . ClientException ( 500 ) , None ]
565
565
566
566
attachment_id = uuids .attachment
567
567
self .api .attachment_delete (self .ctx , attachment_id )
568
568
569
569
self .assertEqual (2 , mock_cinderclient .call_count )
570
570
571
- @mock .patch ('nova.volume.cinder.cinderclient' ,
572
- side_effect = cinder_exception .BadRequest (code = 400 ))
571
+ @mock .patch ('nova.volume.cinder.cinderclient' )
573
572
def test_attachment_delete_bad_request_exception (self , mock_cinderclient ):
573
+ mock_cinderclient .return_value .attachments .delete .side_effect = (
574
+ cinder_exception .BadRequest (400 ))
574
575
575
576
self .assertRaises (exception .InvalidInput ,
576
577
self .api .attachment_delete ,
@@ -594,7 +595,7 @@ def test_attachment_complete(self, mock_cinderclient):
594
595
@mock .patch ('nova.volume.cinder.cinderclient' )
595
596
def test_attachment_complete_failed (self , mock_cinderclient ):
596
597
mock_cinderclient .return_value .attachments .complete .side_effect = (
597
- cinder_exception .NotFound (404 , '404' ))
598
+ cinder_exception .NotFound (404 ))
598
599
599
600
attachment_id = uuids .attachment
600
601
ex = self .assertRaises (exception .VolumeAttachmentNotFound ,
@@ -667,27 +668,30 @@ def test_detach_no_attachment_id_multiattach(self, mock_cinderclient):
667
668
mock_cinderclient .assert_called_with (self .ctx , microversion = None )
668
669
mock_volumes .detach .assert_called_once_with ('id1' , 'fakeid' )
669
670
670
- @mock .patch ('nova.volume.cinder.cinderclient' ,
671
- side_effect = cinder_apiclient .exceptions .InternalServerError )
671
+ @mock .patch ('nova.volume.cinder.cinderclient' )
672
672
def test_detach_internal_server_error (self , mock_cinderclient ):
673
+ mock_cinderclient .return_value .volumes .detach .side_effect = (
674
+ cinder_exception .ClientException (500 ))
673
675
674
- self .assertRaises (cinder_apiclient . exceptions . InternalServerError ,
676
+ self .assertRaises (cinder_exception . ClientException ,
675
677
self .api .detach ,
676
678
self .ctx , 'id1' , instance_uuid = 'fake_uuid' )
677
679
678
- self .assertEqual (5 , mock_cinderclient .call_count )
680
+ self .assertEqual (
681
+ 5 , mock_cinderclient .return_value .volumes .detach .call_count )
679
682
680
683
@mock .patch ('nova.volume.cinder.cinderclient' )
681
684
def test_detach_internal_server_error_do_not_raise (
682
685
self , mock_cinderclient ):
683
686
# generate exception, and then have a normal return on the next retry
684
687
mock_cinderclient .return_value .volumes .detach .side_effect = [
685
- cinder_apiclient . exceptions . InternalServerError , None ]
688
+ cinder_exception . ClientException ( 500 ) , None ]
686
689
687
690
self .api .detach (self .ctx , 'id1' , instance_uuid = 'fake_uuid' ,
688
691
attachment_id = 'fakeid' )
689
692
690
- self .assertEqual (2 , mock_cinderclient .call_count )
693
+ self .assertEqual (
694
+ 2 , mock_cinderclient .return_value .volumes .detach .call_count )
691
695
692
696
@mock .patch ('nova.volume.cinder.cinderclient' ,
693
697
side_effect = cinder_exception .BadRequest (code = 400 ))
@@ -818,11 +822,13 @@ def test_terminate_connection(self, mock_cinderclient):
818
822
mock_volumes .terminate_connection .assert_called_once_with ('id1' ,
819
823
'connector' )
820
824
821
- @mock .patch ('nova.volume.cinder.cinderclient' ,
822
- side_effect = cinder_apiclient .exceptions .InternalServerError )
825
+ @mock .patch ('nova.volume.cinder.cinderclient' )
823
826
def test_terminate_connection_internal_server_error (
824
827
self , mock_cinderclient ):
825
- self .assertRaises (cinder_apiclient .exceptions .InternalServerError ,
828
+ mock_cinderclient .return_value .volumes .terminate_connection .\
829
+ side_effect = cinder_exception .ClientException (500 )
830
+
831
+ self .assertRaises (cinder_exception .ClientException ,
826
832
self .api .terminate_connection ,
827
833
self .ctx , 'id1' , 'connector' )
828
834
@@ -833,7 +839,7 @@ def test_terminate_connection_internal_server_error_do_not_raise(
833
839
self , mock_cinderclient ):
834
840
# generate exception, and then have a normal return on the next retry
835
841
mock_cinderclient .return_value .volumes .terminate_connection .\
836
- side_effect = [cinder_apiclient . exceptions . InternalServerError ,
842
+ side_effect = [cinder_exception . ClientException ( 500 ) ,
837
843
None ]
838
844
839
845
self .api .terminate_connection (self .ctx , 'id1' , 'connector' )
0 commit comments