@@ -1007,3 +1007,129 @@ def test_snapshot_list_with_userid(self, mock_print_list):
10071007 columns = ['ID' , 'Volume ID' , 'Status' , 'Name' , 'Size' , 'User ID' ]
10081008 mock_print_list .assert_called_once_with (mock .ANY , columns ,
10091009 sortby_index = 0 )
1010+
1011+ @mock .patch ('cinderclient.v3.volumes.Volume.migrate_volume' )
1012+ def test_migrate_volume_before_3_16 (self , v3_migrate_mock ):
1013+ self .run_command ('--os-volume-api-version 3.15 '
1014+ 'migrate 1234 fakehost' )
1015+
1016+ v3_migrate_mock .assert_called_once_with (
1017+ 'fakehost' , False , False , None )
1018+
1019+ @mock .patch ('cinderclient.v3.volumes.Volume.migrate_volume' )
1020+ def test_migrate_volume_3_16 (self , v3_migrate_mock ):
1021+ self .run_command ('--os-volume-api-version 3.16 '
1022+ 'migrate 1234 fakehost' )
1023+ self .assertEqual (4 , len (v3_migrate_mock .call_args [0 ]))
1024+
1025+ def test_migrate_volume_with_cluster_before_3_16 (self ):
1026+ self .assertRaises (exceptions .UnsupportedAttribute ,
1027+ self .run_command ,
1028+ '--os-volume-api-version 3.15 '
1029+ 'migrate 1234 fakehost --cluster fakecluster' )
1030+
1031+ @mock .patch ('cinderclient.shell.CinderClientArgumentParser.error' )
1032+ def test_migrate_volume_mutual_exclusion (self , error_mock ):
1033+ error_mock .side_effect = SystemExit
1034+ self .assertRaises (SystemExit ,
1035+ self .run_command ,
1036+ '--os-volume-api-version 3.16 '
1037+ 'migrate 1234 fakehost --cluster fakecluster' )
1038+ msg = 'argument --cluster: not allowed with argument <host>'
1039+ error_mock .assert_called_once_with (msg )
1040+
1041+ @mock .patch ('cinderclient.shell.CinderClientArgumentParser.error' )
1042+ def test_migrate_volume_missing_required (self , error_mock ):
1043+ error_mock .side_effect = SystemExit
1044+ self .assertRaises (SystemExit ,
1045+ self .run_command ,
1046+ '--os-volume-api-version 3.16 '
1047+ 'migrate 1234' )
1048+ msg = 'one of the arguments <host> --cluster is required'
1049+ error_mock .assert_called_once_with (msg )
1050+
1051+ def test_migrate_volume_host (self ):
1052+ self .run_command ('--os-volume-api-version 3.16 '
1053+ 'migrate 1234 fakehost' )
1054+ expected = {'os-migrate_volume' : {'force_host_copy' : False ,
1055+ 'lock_volume' : False ,
1056+ 'host' : 'fakehost' }}
1057+ self .assert_called ('POST' , '/volumes/1234/action' , body = expected )
1058+
1059+ def test_migrate_volume_cluster (self ):
1060+ self .run_command ('--os-volume-api-version 3.16 '
1061+ 'migrate 1234 --cluster mycluster' )
1062+ expected = {'os-migrate_volume' : {'force_host_copy' : False ,
1063+ 'lock_volume' : False ,
1064+ 'cluster' : 'mycluster' }}
1065+ self .assert_called ('POST' , '/volumes/1234/action' , body = expected )
1066+
1067+ def test_migrate_volume_bool_force (self ):
1068+ self .run_command ('--os-volume-api-version 3.16 '
1069+ 'migrate 1234 fakehost --force-host-copy '
1070+ '--lock-volume' )
1071+ expected = {'os-migrate_volume' : {'force_host_copy' : True ,
1072+ 'lock_volume' : True ,
1073+ 'host' : 'fakehost' }}
1074+ self .assert_called ('POST' , '/volumes/1234/action' , body = expected )
1075+
1076+ def test_migrate_volume_bool_force_false (self ):
1077+ # Set both --force-host-copy and --lock-volume to False.
1078+ self .run_command ('--os-volume-api-version 3.16 '
1079+ 'migrate 1234 fakehost --force-host-copy=False '
1080+ '--lock-volume=False' )
1081+ expected = {'os-migrate_volume' : {'force_host_copy' : 'False' ,
1082+ 'lock_volume' : 'False' ,
1083+ 'host' : 'fakehost' }}
1084+ self .assert_called ('POST' , '/volumes/1234/action' , body = expected )
1085+
1086+ # Do not set the values to --force-host-copy and --lock-volume.
1087+ self .run_command ('--os-volume-api-version 3.16 '
1088+ 'migrate 1234 fakehost' )
1089+ expected = {'os-migrate_volume' : {'force_host_copy' : False ,
1090+ 'lock_volume' : False ,
1091+ 'host' : 'fakehost' }}
1092+ self .assert_called ('POST' , '/volumes/1234/action' ,
1093+ body = expected )
1094+
1095+ @ddt .data ({'bootable' : False , 'by_id' : False , 'cluster' : None },
1096+ {'bootable' : True , 'by_id' : False , 'cluster' : None },
1097+ {'bootable' : False , 'by_id' : True , 'cluster' : None },
1098+ {'bootable' : True , 'by_id' : True , 'cluster' : None },
1099+ {'bootable' : True , 'by_id' : True , 'cluster' : 'clustername' })
1100+ @ddt .unpack
1101+ def test_volume_manage (self , bootable , by_id , cluster ):
1102+ cmd = ('--os-volume-api-version 3.16 '
1103+ 'manage host1 some_fake_name --name foo --description bar '
1104+ '--volume-type baz --availability-zone az '
1105+ '--metadata k1=v1 k2=v2' )
1106+ if by_id :
1107+ cmd += ' --id-type source-id'
1108+ if bootable :
1109+ cmd += ' --bootable'
1110+ if cluster :
1111+ cmd += ' --cluster ' + cluster
1112+
1113+ self .run_command (cmd )
1114+ ref = 'source-id' if by_id else 'source-name'
1115+ expected = {'volume' : {'host' : 'host1' ,
1116+ 'ref' : {ref : 'some_fake_name' },
1117+ 'name' : 'foo' ,
1118+ 'description' : 'bar' ,
1119+ 'volume_type' : 'baz' ,
1120+ 'availability_zone' : 'az' ,
1121+ 'metadata' : {'k1' : 'v1' , 'k2' : 'v2' },
1122+ 'bootable' : bootable }}
1123+ if cluster :
1124+ expected ['cluster' ] = cluster
1125+ self .assert_called_anytime ('POST' , '/os-volume-manage' , body = expected )
1126+
1127+ def test_volume_manage_before_3_16 (self ):
1128+ """Cluster optional argument was not acceptable."""
1129+ self .assertRaises (exceptions .UnsupportedAttribute ,
1130+ self .run_command ,
1131+ 'manage host1 some_fake_name '
1132+ '--cluster clustername'
1133+ '--name foo --description bar --bootable '
1134+ '--volume-type baz --availability-zone az '
1135+ '--metadata k1=v1 k2=v2' )
0 commit comments