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