Fix order of arguments in assertEqual

Fix incorrect order assertEqual(observed, expected) as below.
  assertEqual(observed, expected) => assertEqual(expected, observed)

Target of this patch:
  manila/tests/share/*

Note:
I also fix following asserts around above fixed parts.
  assertEqual(xx, True), assertEqual(True, xx) => assertTrue(xx)

As for assertFalse,
I do not convert assertEqual(xx, False) to assertFalse(xx)
because assertFalse(None) does not raise exception.

Change-Id: I56688105ab3b77e4f71bde472763a9c02c43664b
Partial-Bug: #1259292
This commit is contained in:
Yusuke Hayashi 2015-10-04 03:43:17 +09:00
parent 0c9bb4be3b
commit 8ce1530e21
9 changed files with 76 additions and 76 deletions

View File

@ -433,7 +433,7 @@ class IsilonApiTest(test.TestCase):
r = self.isilon_api.delete_nfs_share(share_number) r = self.isilon_api.delete_nfs_share(share_number)
self.assertEqual(1, len(m.request_history)) self.assertEqual(1, len(m.request_history))
self.assertEqual(r, expected_return_value) self.assertEqual(expected_return_value, r)
@ddt.data((204, True), (404, False)) @ddt.data((204, True), (404, False))
def test_delete_smb_shares(self, data): def test_delete_smb_shares(self, data):
@ -449,7 +449,7 @@ class IsilonApiTest(test.TestCase):
r = self.isilon_api.delete_smb_share(share_name) r = self.isilon_api.delete_smb_share(share_name)
self.assertEqual(1, len(m.request_history)) self.assertEqual(1, len(m.request_history))
self.assertEqual(r, expected_return_value) self.assertEqual(expected_return_value, r)
@requests_mock.mock() @requests_mock.mock()
def test_delete_snapshot(self, m): def test_delete_snapshot(self, m):

View File

@ -1347,7 +1347,7 @@ class EMCShareDriverVNXTestCase(test.TestCase):
ssh_calls = [mock.call(TD.create_nfs_export(vdm_name, '/fakename'))] ssh_calls = [mock.call(TD.create_nfs_export(vdm_name, '/fakename'))]
helper.XMLAPIConnector.request.assert_has_calls(expected_calls) helper.XMLAPIConnector.request.assert_has_calls(expected_calls)
helper.SSHConnector.run_ssh.assert_has_calls(ssh_calls) helper.SSHConnector.run_ssh.assert_has_calls(ssh_calls)
self.assertEqual(location, '192.168.1.1:/%s' % share['name'], self.assertEqual('192.168.1.1:/%s' % share['name'], location,
"NFS export path is incorrect") "NFS export path is incorrect")
@ddt.data(fake_share.fake_share(), @ddt.data(fake_share.fake_share(),
@ -1489,7 +1489,7 @@ class EMCShareDriverVNXTestCase(test.TestCase):
] ]
helper.XMLAPIConnector.request.assert_has_calls(expected_calls) helper.XMLAPIConnector.request.assert_has_calls(expected_calls)
helper.SSHConnector.run_ssh.assert_has_calls(ssh_calls) helper.SSHConnector.run_ssh.assert_has_calls(ssh_calls)
self.assertEqual(location, '\\\\192.168.1.2\\%s' % share['name'], self.assertEqual('\\\\192.168.1.2\\%s' % share['name'], location,
"CIFS export path is incorrect") "CIFS export path is incorrect")
def test_delete_cifs_share_default(self): def test_delete_cifs_share_default(self):

View File

@ -247,7 +247,7 @@ class GenericShareDriverTestCase(test.TestCase):
self._driver._ssh_exec, self._driver._ssh_exec,
self.fake_conf self.fake_conf
) )
self.assertEqual(len(self._driver._helpers), 1) self.assertEqual(1, len(self._driver._helpers))
def test_setup_helpers_no_helpers(self): def test_setup_helpers_no_helpers(self):
self._driver._helpers = {} self._driver._helpers = {}
@ -292,7 +292,7 @@ class GenericShareDriverTestCase(test.TestCase):
result = self._driver.create_share( result = self._driver.create_share(
self._context, self.share, share_server=self.server) self._context, self.share, share_server=self.server)
self.assertEqual(result, 'fakelocation') self.assertEqual('fakelocation', result)
self._driver._allocate_container.assert_called_once_with( self._driver._allocate_container.assert_called_once_with(
self._driver.admin_context, self.share) self._driver.admin_context, self.share)
self._driver._attach_volume.assert_called_once_with( self._driver._attach_volume.assert_called_once_with(
@ -422,18 +422,18 @@ class GenericShareDriverTestCase(test.TestCase):
self._driver._unmount_device(self.share, self.server) self._driver._unmount_device(self.share, self.server)
self.assertEqual(1, time.sleep.call_count) self.assertEqual(1, time.sleep.call_count)
self.assertEqual(self._driver._get_mount_path.mock_calls, self.assertEqual([mock.call(self.share) for i in moves.range(2)],
[mock.call(self.share) for i in moves.range(2)]) self._driver._get_mount_path.mock_calls)
self.assertEqual(self._driver._is_device_mounted.mock_calls, self.assertEqual([mock.call(mount_path,
[mock.call(mount_path, self.server) for i in moves.range(2)],
self.server) for i in moves.range(2)]) self._driver._is_device_mounted.mock_calls)
self._driver._sync_mount_temp_and_perm_files.assert_called_once_with( self._driver._sync_mount_temp_and_perm_files.assert_called_once_with(
self.server) self.server)
self.assertEqual( self.assertEqual(
self._driver._ssh_exec.mock_calls,
[mock.call(self.server, ['sudo umount', mount_path, [mock.call(self.server, ['sudo umount', mount_path,
'&& sudo rmdir', mount_path]) '&& sudo rmdir', mount_path])
for i in moves.range(2)] for i in moves.range(2)],
self._driver._ssh_exec.mock_calls,
) )
def test_unmount_device_not_present(self): def test_unmount_device_not_present(self):
@ -464,7 +464,7 @@ class GenericShareDriverTestCase(test.TestCase):
self._driver._ssh_exec.assert_called_once_with( self._driver._ssh_exec.assert_called_once_with(
self.server, ['sudo', 'mount']) self.server, ['sudo', 'mount'])
self.assertEqual(result, True) self.assertTrue(result)
def test_is_device_mounted_true_no_volume_provided(self): def test_is_device_mounted_true_no_volume_provided(self):
mount_path = '/fake/mount/path' mount_path = '/fake/mount/path'
@ -476,7 +476,7 @@ class GenericShareDriverTestCase(test.TestCase):
self._driver._ssh_exec.assert_called_once_with( self._driver._ssh_exec.assert_called_once_with(
self.server, ['sudo', 'mount']) self.server, ['sudo', 'mount'])
self.assertEqual(result, True) self.assertTrue(result)
def test_is_device_mounted_false(self): def test_is_device_mounted_false(self):
mount_path = '/fake/mount/path' mount_path = '/fake/mount/path'
@ -491,7 +491,7 @@ class GenericShareDriverTestCase(test.TestCase):
self._driver._ssh_exec.assert_called_once_with( self._driver._ssh_exec.assert_called_once_with(
self.server, ['sudo', 'mount']) self.server, ['sudo', 'mount'])
self.assertEqual(result, False) self.assertEqual(False, result)
def test_is_device_mounted_false_no_volume_provided(self): def test_is_device_mounted_false_no_volume_provided(self):
mount_path = '/fake/mount/path' mount_path = '/fake/mount/path'
@ -505,7 +505,7 @@ class GenericShareDriverTestCase(test.TestCase):
self._driver._ssh_exec.assert_called_once_with( self._driver._ssh_exec.assert_called_once_with(
self.server, ['sudo', 'mount']) self.server, ['sudo', 'mount'])
self.assertEqual(result, False) self.assertEqual(False, result)
def test_sync_mount_temp_and_perm_files(self): def test_sync_mount_temp_and_perm_files(self):
self.mock_object(self._driver, '_ssh_exec') self.mock_object(self._driver, '_ssh_exec')
@ -549,8 +549,8 @@ class GenericShareDriverTestCase(test.TestCase):
def test_get_mount_path(self): def test_get_mount_path(self):
result = self._driver._get_mount_path(self.share) result = self._driver._get_mount_path(self.share)
self.assertEqual(result, os.path.join(CONF.share_mount_path, self.assertEqual(os.path.join(CONF.share_mount_path,
self.share['name'])) self.share['name']), result)
def test_attach_volume_not_attached(self): def test_attach_volume_not_attached(self):
available_volume = fake_volume.FakeVolume() available_volume = fake_volume.FakeVolume()
@ -567,7 +567,7 @@ class GenericShareDriverTestCase(test.TestCase):
available_volume['id']) available_volume['id'])
self._driver.volume_api.get.assert_called_once_with( self._driver.volume_api.get.assert_called_once_with(
self._context, attached_volume['id']) self._context, attached_volume['id'])
self.assertEqual(result, attached_volume) self.assertEqual(attached_volume, result)
def test_attach_volume_attached_correct(self): def test_attach_volume_attached_correct(self):
fake_server = fake_compute.FakeServer() fake_server = fake_compute.FakeServer()
@ -578,7 +578,7 @@ class GenericShareDriverTestCase(test.TestCase):
result = self._driver._attach_volume(self._context, self.share, result = self._driver._attach_volume(self._context, self.share,
fake_server, attached_volume) fake_server, attached_volume)
self.assertEqual(result, attached_volume) self.assertEqual(attached_volume, result)
def test_attach_volume_attached_incorrect(self): def test_attach_volume_attached_incorrect(self):
fake_server = fake_compute.FakeServer() fake_server = fake_compute.FakeServer()
@ -620,7 +620,7 @@ class GenericShareDriverTestCase(test.TestCase):
result = self._driver._attach_volume(self._context, self.share, result = self._driver._attach_volume(self._context, self.share,
fake_server, attached_volume) fake_server, attached_volume)
self.assertEqual(result, in_use_volume) self.assertEqual(in_use_volume, result)
self.assertEqual( self.assertEqual(
2, self._driver.compute_api.instance_volume_attach.call_count) 2, self._driver.compute_api.instance_volume_attach.call_count)
@ -642,7 +642,7 @@ class GenericShareDriverTestCase(test.TestCase):
self.mock_object(self._driver.volume_api, 'get_all', self.mock_object(self._driver.volume_api, 'get_all',
mock.Mock(return_value=[volume])) mock.Mock(return_value=[volume]))
result = self._driver._get_volume(self._context, self.share['id']) result = self._driver._get_volume(self._context, self.share['id'])
self.assertEqual(result, volume) self.assertEqual(volume, result)
self._driver.volume_api.get_all.assert_called_once_with( self._driver.volume_api.get_all.assert_called_once_with(
self._context, {'all_tenants': True, 'name': volume['name']}) self._context, {'all_tenants': True, 'name': volume['name']})
@ -655,7 +655,7 @@ class GenericShareDriverTestCase(test.TestCase):
result = self._driver._get_volume(self._context, self.share['id']) result = self._driver._get_volume(self._context, self.share['id'])
self.assertEqual(result, volume) self.assertEqual(volume, result)
self._driver.volume_api.get.assert_called_once_with( self._driver.volume_api.get.assert_called_once_with(
self._context, volume['id']) self._context, volume['id'])
self.fake_private_storage.get.assert_called_once_with( self.fake_private_storage.get.assert_called_once_with(
@ -693,7 +693,7 @@ class GenericShareDriverTestCase(test.TestCase):
mock.Mock(return_value=[volume_snapshot])) mock.Mock(return_value=[volume_snapshot]))
result = self._driver._get_volume_snapshot(self._context, result = self._driver._get_volume_snapshot(self._context,
self.snapshot['id']) self.snapshot['id'])
self.assertEqual(result, volume_snapshot) self.assertEqual(volume_snapshot, result)
self._driver.volume_api.get_all_snapshots.assert_called_once_with( self._driver.volume_api.get_all_snapshots.assert_called_once_with(
self._context, {'name': volume_snapshot['name']}) self._context, {'name': volume_snapshot['name']})
@ -705,7 +705,7 @@ class GenericShareDriverTestCase(test.TestCase):
mock.Mock(return_value=volume_snapshot['id'])) mock.Mock(return_value=volume_snapshot['id']))
result = self._driver._get_volume_snapshot(self._context, result = self._driver._get_volume_snapshot(self._context,
self.snapshot['id']) self.snapshot['id'])
self.assertEqual(result, volume_snapshot) self.assertEqual(volume_snapshot, result)
self._driver.volume_api.get_snapshot.assert_called_once_with( self._driver.volume_api.get_snapshot.assert_called_once_with(
self._context, volume_snapshot['id']) self._context, volume_snapshot['id'])
self.fake_private_storage.get.assert_called_once_with( self.fake_private_storage.get.assert_called_once_with(
@ -784,7 +784,7 @@ class GenericShareDriverTestCase(test.TestCase):
mock.Mock(return_value=fake_vol)) mock.Mock(return_value=fake_vol))
result = self._driver._allocate_container(self._context, self.share) result = self._driver._allocate_container(self._context, self.share)
self.assertEqual(result, fake_vol) self.assertEqual(fake_vol, result)
self._driver.volume_api.create.assert_called_once_with( self._driver.volume_api.create.assert_called_once_with(
self._context, self._context,
self.share['size'], self.share['size'],
@ -805,7 +805,7 @@ class GenericShareDriverTestCase(test.TestCase):
result = self._driver._allocate_container(self._context, result = self._driver._allocate_container(self._context,
self.share, self.share,
self.snapshot) self.snapshot)
self.assertEqual(result, fake_vol) self.assertEqual(fake_vol, result)
self._driver.volume_api.create.assert_called_once_with( self._driver.volume_api.create.assert_called_once_with(
self._context, self._context,
self.share['size'], self.share['size'],
@ -933,7 +933,7 @@ class GenericShareDriverTestCase(test.TestCase):
self.snapshot, self.snapshot,
share_server=self.server) share_server=self.server)
self.assertEqual(result, 'fakelocation') self.assertEqual('fakelocation', result)
self._driver._allocate_container.assert_called_once_with( self._driver._allocate_container.assert_called_once_with(
self._driver.admin_context, self.share, self.snapshot) self._driver.admin_context, self.share, self.snapshot)
self._driver._attach_volume.assert_called_once_with( self._driver._attach_volume.assert_called_once_with(
@ -2028,7 +2028,7 @@ class NFSHelperTestCase(test.TestCase):
expected_location = ':'.join([self.server['public_address'], expected_location = ':'.join([self.server['public_address'],
os.path.join(CONF.share_mount_path, os.path.join(CONF.share_mount_path,
self.share_name)]) self.share_name)])
self.assertEqual(ret, expected_location) self.assertEqual(expected_location, ret)
@ddt.data(const.ACCESS_LEVEL_RW, const.ACCESS_LEVEL_RO) @ddt.data(const.ACCESS_LEVEL_RW, const.ACCESS_LEVEL_RO)
def test_allow_access(self, data): def test_allow_access(self, data):
@ -2179,7 +2179,7 @@ class CIFSHelperTestCase(test.TestCase):
ret = self._helper.create_export(self.server_details, self.share_name) ret = self._helper.create_export(self.server_details, self.share_name)
expected_location = '\\\\%s\\%s' % ( expected_location = '\\\\%s\\%s' % (
self.server_details['public_address'], self.share_name) self.server_details['public_address'], self.share_name)
self.assertEqual(ret, expected_location) self.assertEqual(expected_location, ret)
share_path = os.path.join( share_path = os.path.join(
self._helper.configuration.share_mount_path, self._helper.configuration.share_mount_path,
self.share_name) self.share_name)
@ -2203,7 +2203,7 @@ class CIFSHelperTestCase(test.TestCase):
recreate=True) recreate=True)
expected_location = '\\\\%s\\%s' % ( expected_location = '\\\\%s\\%s' % (
self.server_details['public_address'], self.share_name) self.server_details['public_address'], self.share_name)
self.assertEqual(ret, expected_location) self.assertEqual(expected_location, ret)
share_path = os.path.join( share_path = os.path.join(
self._helper.configuration.share_mount_path, self._helper.configuration.share_mount_path,
self.share_name) self.share_name)

View File

@ -383,14 +383,14 @@ class ServiceInstanceManagerTestCase(test.TestCase):
net_name = self._manager.get_config_option('service_network_name') net_name = self._manager.get_config_option('service_network_name')
fake_server = dict(networks={net_name: [ip]}) fake_server = dict(networks={net_name: [ip]})
result = self._manager._get_server_ip(fake_server, net_name) result = self._manager._get_server_ip(fake_server, net_name)
self.assertEqual(result, ip) self.assertEqual(ip, result)
def test_get_server_ip_found_in_addresses_section(self): def test_get_server_ip_found_in_addresses_section(self):
ip = '10.0.0.1' ip = '10.0.0.1'
net_name = self._manager.get_config_option('service_network_name') net_name = self._manager.get_config_option('service_network_name')
fake_server = dict(addresses={net_name: [dict(addr=ip, version=4)]}) fake_server = dict(addresses={net_name: [dict(addr=ip, version=4)]})
result = self._manager._get_server_ip(fake_server, net_name) result = self._manager._get_server_ip(fake_server, net_name)
self.assertEqual(result, ip) self.assertEqual(ip, result)
@ddt.data( @ddt.data(
{}, {},
@ -419,7 +419,7 @@ class ServiceInstanceManagerTestCase(test.TestCase):
mock.Mock(return_value=[fake_secgroup, ])) mock.Mock(return_value=[fake_secgroup, ]))
result = self._manager._get_or_create_security_group( result = self._manager._get_or_create_security_group(
self._manager.admin_context) self._manager.admin_context)
self.assertEqual(result, fake_secgroup) self.assertEqual(fake_secgroup, result)
self._manager.get_config_option.assert_has_calls([ self._manager.get_config_option.assert_has_calls([
mock.call('service_instance_security_group'), mock.call('service_instance_security_group'),
]) ])
@ -444,7 +444,7 @@ class ServiceInstanceManagerTestCase(test.TestCase):
name=None, name=None,
description=desc, description=desc,
) )
self.assertEqual(result, fake_secgroup) self.assertEqual(fake_secgroup, result)
self._manager.compute_api.security_group_list.assert_called_once_with( self._manager.compute_api.security_group_list.assert_called_once_with(
self._manager.admin_context) self._manager.admin_context)
self._manager.compute_api.security_group_create.\ self._manager.compute_api.security_group_create.\
@ -469,7 +469,7 @@ class ServiceInstanceManagerTestCase(test.TestCase):
self._manager.compute_api.security_group_create.\ self._manager.compute_api.security_group_create.\
assert_called_once_with( assert_called_once_with(
self._manager.admin_context, name, mock.ANY) self._manager.admin_context, name, mock.ANY)
self.assertEqual(result, fake_secgroup) self.assertEqual(fake_secgroup, result)
def test_security_group_two_sg_in_list(self): def test_security_group_two_sg_in_list(self):
name = "fake_name" name = "fake_name"
@ -688,12 +688,12 @@ class ServiceInstanceManagerTestCase(test.TestCase):
def test_get_key_keypath_to_public_not_set(self): def test_get_key_keypath_to_public_not_set(self):
self._manager.path_to_public_key = None self._manager.path_to_public_key = None
result = self._manager._get_key(self._manager.admin_context) result = self._manager._get_key(self._manager.admin_context)
self.assertEqual(result, (None, None)) self.assertEqual((None, None), result)
def test_get_key_keypath_to_private_not_set(self): def test_get_key_keypath_to_private_not_set(self):
self._manager.path_to_private_key = None self._manager.path_to_private_key = None
result = self._manager._get_key(self._manager.admin_context) result = self._manager._get_key(self._manager.admin_context)
self.assertEqual(result, (None, None)) self.assertEqual((None, None), result)
def test_get_key_incorrect_keypath_to_public(self): def test_get_key_incorrect_keypath_to_public(self):
def exists_side_effect(path): def exists_side_effect(path):
@ -705,7 +705,7 @@ class ServiceInstanceManagerTestCase(test.TestCase):
with mock.patch.object(os.path, 'expanduser', with mock.patch.object(os.path, 'expanduser',
mock.Mock(side_effect=lambda value: value)): mock.Mock(side_effect=lambda value: value)):
result = self._manager._get_key(self._manager.admin_context) result = self._manager._get_key(self._manager.admin_context)
self.assertEqual(result, (None, None)) self.assertEqual((None, None), result)
def test_get_key_incorrect_keypath_to_private(self): def test_get_key_incorrect_keypath_to_private(self):
def exists_side_effect(path): def exists_side_effect(path):
@ -717,7 +717,7 @@ class ServiceInstanceManagerTestCase(test.TestCase):
with mock.patch.object(os.path, 'expanduser', with mock.patch.object(os.path, 'expanduser',
mock.Mock(side_effect=lambda value: value)): mock.Mock(side_effect=lambda value: value)):
result = self._manager._get_key(self._manager.admin_context) result = self._manager._get_key(self._manager.admin_context)
self.assertEqual(result, (None, None)) self.assertEqual((None, None), result)
def test_get_service_image(self): def test_get_service_image(self):
fake_image1 = fake_compute.FakeImage( fake_image1 = fake_compute.FakeImage(
@ -1962,7 +1962,7 @@ class NeutronNetworkHelperTestCase(test.TestCase):
host_id='fake_host') host_id='fake_host')
service_instance.socket.gethostname.assert_called_once_with() service_instance.socket.gethostname.assert_called_once_with()
self.assertFalse(instance.neutron_api.update_port_fixed_ips.called) self.assertFalse(instance.neutron_api.update_port_fixed_ips.called)
self.assertEqual(result, fake_service_port) self.assertEqual(fake_service_port, result)
def test__get_service_port_one_exist(self): def test__get_service_port_one_exist(self):
instance = self._init_neutron_network_plugin() instance = self._init_neutron_network_plugin()
@ -1980,7 +1980,7 @@ class NeutronNetworkHelperTestCase(test.TestCase):
device_id='manila-share') device_id='manila-share')
self.assertFalse(instance.neutron_api.create_port.called) self.assertFalse(instance.neutron_api.create_port.called)
self.assertFalse(instance.neutron_api.update_port_fixed_ips.called) self.assertFalse(instance.neutron_api.update_port_fixed_ips.called)
self.assertEqual(result, fake_service_port) self.assertEqual(fake_service_port, result)
def test__get_service_port_two_exist(self): def test__get_service_port_two_exist(self):
instance = self._init_neutron_network_plugin() instance = self._init_neutron_network_plugin()

View File

@ -210,7 +210,7 @@ class WindowsSMBDriverTestCase(test.TestCase):
mock.sentinel.mount_path, mock.sentinel.mount_path,
mock.sentinel.server) mock.sentinel.server)
self.assertEqual(share_size, fake_size_gb) self.assertEqual(fake_size_gb, share_size)
def test_get_consumed_space(self): def test_get_consumed_space(self):
fake_size_gb = 2 fake_size_gb = 2

View File

@ -298,7 +298,7 @@ class ShareAPITestCase(test.TestCase):
ctx, sort_dir='desc', sort_key='created_at', ctx, sort_dir='desc', sort_key='created_at',
project_id='fake_pid_1', filters={}, is_public=False project_id='fake_pid_1', filters={}, is_public=False
) )
self.assertEqual(shares, _FAKE_LIST_OF_ALL_SHARES[0]) self.assertEqual(_FAKE_LIST_OF_ALL_SHARES[0], shares)
def test_get_all_admin_filter_by_all_tenants(self): def test_get_all_admin_filter_by_all_tenants(self):
ctx = context.RequestContext('fake_uid', 'fake_pid_1', is_admin=True) ctx = context.RequestContext('fake_uid', 'fake_pid_1', is_admin=True)
@ -309,7 +309,7 @@ class ShareAPITestCase(test.TestCase):
ctx, 'share', 'get_all') ctx, 'share', 'get_all')
db_api.share_get_all.assert_called_once_with( db_api.share_get_all.assert_called_once_with(
ctx, sort_dir='desc', sort_key='created_at', filters={}) ctx, sort_dir='desc', sort_key='created_at', filters={})
self.assertEqual(shares, _FAKE_LIST_OF_ALL_SHARES) self.assertEqual(_FAKE_LIST_OF_ALL_SHARES, shares)
def test_get_all_non_admin_filter_by_share_server(self): def test_get_all_non_admin_filter_by_share_server(self):
@ -351,7 +351,7 @@ class ShareAPITestCase(test.TestCase):
) )
db_api.share_get_all_by_project.assert_has_calls([]) db_api.share_get_all_by_project.assert_has_calls([])
db_api.share_get_all.assert_has_calls([]) db_api.share_get_all.assert_has_calls([])
self.assertEqual(shares, _FAKE_LIST_OF_ALL_SHARES[2:]) self.assertEqual(_FAKE_LIST_OF_ALL_SHARES[2:], shares)
def test_get_all_admin_filter_by_name(self): def test_get_all_admin_filter_by_name(self):
ctx = context.RequestContext('fake_uid', 'fake_pid_2', is_admin=True) ctx = context.RequestContext('fake_uid', 'fake_pid_2', is_admin=True)
@ -365,7 +365,7 @@ class ShareAPITestCase(test.TestCase):
ctx, sort_dir='desc', sort_key='created_at', ctx, sort_dir='desc', sort_key='created_at',
project_id='fake_pid_2', filters={}, is_public=False project_id='fake_pid_2', filters={}, is_public=False
) )
self.assertEqual(shares, _FAKE_LIST_OF_ALL_SHARES[1::2]) self.assertEqual(_FAKE_LIST_OF_ALL_SHARES[1::2], shares)
def test_get_all_admin_filter_by_name_and_all_tenants(self): def test_get_all_admin_filter_by_name_and_all_tenants(self):
ctx = context.RequestContext('fake_uid', 'fake_pid_2', is_admin=True) ctx = context.RequestContext('fake_uid', 'fake_pid_2', is_admin=True)
@ -377,7 +377,7 @@ class ShareAPITestCase(test.TestCase):
]) ])
db_api.share_get_all.assert_called_once_with( db_api.share_get_all.assert_called_once_with(
ctx, sort_dir='desc', sort_key='created_at', filters={}) ctx, sort_dir='desc', sort_key='created_at', filters={})
self.assertEqual(shares, _FAKE_LIST_OF_ALL_SHARES[::2]) self.assertEqual(_FAKE_LIST_OF_ALL_SHARES[::2], shares)
def test_get_all_admin_filter_by_status(self): def test_get_all_admin_filter_by_status(self):
ctx = context.RequestContext('fake_uid', 'fake_pid_2', is_admin=True) ctx = context.RequestContext('fake_uid', 'fake_pid_2', is_admin=True)
@ -391,7 +391,7 @@ class ShareAPITestCase(test.TestCase):
ctx, sort_dir='desc', sort_key='created_at', ctx, sort_dir='desc', sort_key='created_at',
project_id='fake_pid_2', filters={}, is_public=False project_id='fake_pid_2', filters={}, is_public=False
) )
self.assertEqual(shares, _FAKE_LIST_OF_ALL_SHARES[2::4]) self.assertEqual(_FAKE_LIST_OF_ALL_SHARES[2::4], shares)
def test_get_all_admin_filter_by_status_and_all_tenants(self): def test_get_all_admin_filter_by_status_and_all_tenants(self):
ctx = context.RequestContext('fake_uid', 'fake_pid_2', is_admin=True) ctx = context.RequestContext('fake_uid', 'fake_pid_2', is_admin=True)
@ -404,7 +404,7 @@ class ShareAPITestCase(test.TestCase):
]) ])
db_api.share_get_all.assert_called_once_with( db_api.share_get_all.assert_called_once_with(
ctx, sort_dir='desc', sort_key='created_at', filters={}) ctx, sort_dir='desc', sort_key='created_at', filters={})
self.assertEqual(shares, _FAKE_LIST_OF_ALL_SHARES[1::2]) self.assertEqual(_FAKE_LIST_OF_ALL_SHARES[1::2], shares)
def test_get_all_non_admin_filter_by_all_tenants(self): def test_get_all_non_admin_filter_by_all_tenants(self):
# Expected share list only by project of non-admin user # Expected share list only by project of non-admin user
@ -419,7 +419,7 @@ class ShareAPITestCase(test.TestCase):
ctx, sort_dir='desc', sort_key='created_at', ctx, sort_dir='desc', sort_key='created_at',
project_id='fake_pid_2', filters={}, is_public=False project_id='fake_pid_2', filters={}, is_public=False
) )
self.assertEqual(shares, _FAKE_LIST_OF_ALL_SHARES[1:]) self.assertEqual(_FAKE_LIST_OF_ALL_SHARES[1:], shares)
def test_get_all_non_admin_with_name_and_status_filters(self): def test_get_all_non_admin_with_name_and_status_filters(self):
ctx = context.RequestContext('fake_uid', 'fake_pid_2', is_admin=False) ctx = context.RequestContext('fake_uid', 'fake_pid_2', is_admin=False)
@ -436,12 +436,12 @@ class ShareAPITestCase(test.TestCase):
) )
# two items expected, one filtered # two items expected, one filtered
self.assertEqual(shares, _FAKE_LIST_OF_ALL_SHARES[1::2]) self.assertEqual(_FAKE_LIST_OF_ALL_SHARES[1::2], shares)
# one item expected, two filtered # one item expected, two filtered
shares = self.api.get_all( shares = self.api.get_all(
ctx, {'name': 'foo', 'status': constants.STATUS_AVAILABLE}) ctx, {'name': 'foo', 'status': constants.STATUS_AVAILABLE})
self.assertEqual(shares, _FAKE_LIST_OF_ALL_SHARES[2::4]) self.assertEqual(_FAKE_LIST_OF_ALL_SHARES[2::4], shares)
share_api.policy.check_policy.assert_has_calls([ share_api.policy.check_policy.assert_has_calls([
mock.call(ctx, 'share', 'get_all'), mock.call(ctx, 'share', 'get_all'),
mock.call(ctx, 'share', 'get_all'), mock.call(ctx, 'share', 'get_all'),
@ -996,7 +996,7 @@ class ShareAPITestCase(test.TestCase):
with mock.patch.object(db_api, 'share_snapshot_get', with mock.patch.object(db_api, 'share_snapshot_get',
mock.Mock(return_value=fake_get_snap)): mock.Mock(return_value=fake_get_snap)):
rule = self.api.get_snapshot(self.context, 'fakeid') rule = self.api.get_snapshot(self.context, 'fakeid')
self.assertEqual(rule, fake_get_snap) self.assertEqual(fake_get_snap, rule)
share_api.policy.check_policy.assert_called_once_with( share_api.policy.check_policy.assert_called_once_with(
self.context, 'share', 'get_snapshot') self.context, 'share', 'get_snapshot')
db_api.share_snapshot_get.assert_called_once_with( db_api.share_snapshot_get.assert_called_once_with(
@ -1145,7 +1145,7 @@ class ShareAPITestCase(test.TestCase):
with mock.patch.object(db_api, 'share_get', with mock.patch.object(db_api, 'share_get',
mock.Mock(return_value=share)): mock.Mock(return_value=share)):
result = self.api.get(self.context, 'fakeid') result = self.api.get(self.context, 'fakeid')
self.assertEqual(result, share) self.assertEqual(share, result)
share_api.policy.check_policy.assert_called_once_with( share_api.policy.check_policy.assert_called_once_with(
self.context, 'share', 'get', share) self.context, 'share', 'get', share)
db_api.share_get.assert_called_once_with( db_api.share_get.assert_called_once_with(
@ -1422,7 +1422,7 @@ class ShareAPITestCase(test.TestCase):
with mock.patch.object(db_api, 'share_access_get', with mock.patch.object(db_api, 'share_access_get',
mock.Mock(return_value='fake')): mock.Mock(return_value='fake')):
rule = self.api.access_get(self.context, 'fakeid') rule = self.api.access_get(self.context, 'fakeid')
self.assertEqual(rule, 'fake') self.assertEqual('fake', rule)
share_api.policy.check_policy.assert_called_once_with( share_api.policy.check_policy.assert_called_once_with(
self.context, 'share', 'access_get') self.context, 'share', 'access_get')
db_api.share_access_get.assert_called_once_with( db_api.share_access_get.assert_called_once_with(

View File

@ -40,7 +40,7 @@ class DriverPrivateDataTestCase(test.TestCase):
def test_custom_storage_driver(self): def test_custom_storage_driver(self):
private_data = pd.DriverPrivateData(storage=self.fake_storage) private_data = pd.DriverPrivateData(storage=self.fake_storage)
self.assertEqual(private_data._storage, self.fake_storage) self.assertEqual(self.fake_storage, private_data._storage)
def test_invalid_parameters(self): def test_invalid_parameters(self):
self.assertRaises(ValueError, pd.DriverPrivateData) self.assertRaises(ValueError, pd.DriverPrivateData)

View File

@ -395,8 +395,8 @@ class ShareManagerTestCase(test.TestCase):
share_id).id) share_id).id)
shr = db.share_get(self.context, share_id) shr = db.share_get(self.context, share_id)
self.assertEqual(shr['status'], constants.STATUS_AVAILABLE) self.assertEqual(constants.STATUS_AVAILABLE, shr['status'])
self.assertEqual(shr['share_server_id'], server['id']) self.assertEqual(server['id'], shr['share_server_id'])
def test_create_share_instance_from_snapshot_with_server_not_found(self): def test_create_share_instance_from_snapshot_with_server_not_found(self):
"""Test creation from snapshot fails if server not found.""" """Test creation from snapshot fails if server not found."""
@ -415,7 +415,7 @@ class ShareManagerTestCase(test.TestCase):
) )
shr = db.share_get(self.context, share_id) shr = db.share_get(self.context, share_id)
self.assertEqual(shr['status'], constants.STATUS_ERROR) self.assertEqual(constants.STATUS_ERROR, shr['status'])
def test_create_share_instance_from_snapshot(self): def test_create_share_instance_from_snapshot(self):
"""Test share can be created from snapshot.""" """Test share can be created from snapshot."""
@ -430,7 +430,7 @@ class ShareManagerTestCase(test.TestCase):
share_id).id) share_id).id)
shr = db.share_get(self.context, share_id) shr = db.share_get(self.context, share_id)
self.assertEqual(shr['status'], constants.STATUS_AVAILABLE) self.assertEqual(constants.STATUS_AVAILABLE, shr['status'])
self.assertTrue(len(shr['export_location']) > 0) self.assertTrue(len(shr['export_location']) > 0)
self.assertEqual(2, len(shr['export_locations'])) self.assertEqual(2, len(shr['export_locations']))
@ -456,7 +456,7 @@ class ShareManagerTestCase(test.TestCase):
snapshot_id).share_id) snapshot_id).share_id)
snap = db.share_snapshot_get(self.context, snapshot_id) snap = db.share_snapshot_get(self.context, snapshot_id)
self.assertEqual(snap['status'], constants.STATUS_AVAILABLE) self.assertEqual(constants.STATUS_AVAILABLE, snap['status'])
self.share_manager.delete_snapshot(self.context, snapshot_id) self.share_manager.delete_snapshot(self.context, snapshot_id)
self.assertRaises(exception.NotFound, self.assertRaises(exception.NotFound,
@ -485,7 +485,7 @@ class ShareManagerTestCase(test.TestCase):
self.context, share_id, snapshot_id) self.context, share_id, snapshot_id)
snap = db.share_snapshot_get(self.context, snapshot_id) snap = db.share_snapshot_get(self.context, snapshot_id)
self.assertEqual(snap['status'], constants.STATUS_ERROR) self.assertEqual(constants.STATUS_ERROR, snap['status'])
self.assertRaises(exception.NotFound, self.assertRaises(exception.NotFound,
self.share_manager.delete_snapshot, self.share_manager.delete_snapshot,
@ -517,7 +517,7 @@ class ShareManagerTestCase(test.TestCase):
self.share_manager.delete_snapshot(self.context, snapshot_id) self.share_manager.delete_snapshot(self.context, snapshot_id)
snap = db.share_snapshot_get(self.context, snapshot_id) snap = db.share_snapshot_get(self.context, snapshot_id)
self.assertEqual(snap['status'], constants.STATUS_AVAILABLE) self.assertEqual(constants.STATUS_AVAILABLE, snap['status'])
self.share_manager.driver.delete_snapshot.assert_called_once_with( self.share_manager.driver.delete_snapshot.assert_called_once_with(
utils.IsAMatcher(context.RequestContext), utils.IsAMatcher(context.RequestContext),
utils.IsAMatcher(models.ShareSnapshotInstance), utils.IsAMatcher(models.ShareSnapshotInstance),
@ -642,7 +642,7 @@ class ShareManagerTestCase(test.TestCase):
) )
manager.LOG.error.assert_called_with(mock.ANY, share.instance['id']) manager.LOG.error.assert_called_with(mock.ANY, share.instance['id'])
shr = db.share_get(self.context, share_id) shr = db.share_get(self.context, share_id)
self.assertEqual(shr['status'], constants.STATUS_ERROR) self.assertEqual(constants.STATUS_ERROR, shr['status'])
def test_create_share_instance_with_share_network_server_exists(self): def test_create_share_instance_with_share_network_server_exists(self):
"""Test share can be created with existing share server.""" """Test share can be created with existing share server."""
@ -715,8 +715,8 @@ class ShareManagerTestCase(test.TestCase):
self.assertEqual(share_id, db.share_get(context.get_admin_context(), self.assertEqual(share_id, db.share_get(context.get_admin_context(),
share_id).id) share_id).id)
shr = db.share_get(self.context, share_id) shr = db.share_get(self.context, share_id)
self.assertEqual(shr['status'], constants.STATUS_AVAILABLE) self.assertEqual(constants.STATUS_AVAILABLE, shr['status'])
self.assertEqual(shr['share_server_id'], 'fake_srv_id') self.assertEqual('fake_srv_id', shr['share_server_id'])
db.share_server_create.assert_called_once_with( db.share_server_create.assert_called_once_with(
utils.IsAMatcher(context.RequestContext), mock.ANY) utils.IsAMatcher(context.RequestContext), mock.ANY)
self.share_manager._setup_server.assert_called_once_with( self.share_manager._setup_server.assert_called_once_with(
@ -741,14 +741,14 @@ class ShareManagerTestCase(test.TestCase):
share.instance['id']) share.instance['id'])
shr = db.share_get(self.context, share_id) shr = db.share_get(self.context, share_id)
self.assertEqual(shr['status'], constants.STATUS_ERROR) self.assertEqual(constants.STATUS_ERROR, shr['status'])
self.assertRaises(exception.NotFound, self.assertRaises(exception.NotFound,
self.share_manager.delete_share_instance, self.share_manager.delete_share_instance,
self.context, self.context,
share.instance['id']) share.instance['id'])
shr = db.share_get(self.context, share_id) shr = db.share_get(self.context, share_id)
self.assertEqual(shr['status'], constants.STATUS_ERROR_DELETING) self.assertEqual(constants.STATUS_ERROR_DELETING, shr['status'])
self.share_manager.driver.create_share.assert_called_once_with( self.share_manager.driver.create_share.assert_called_once_with(
utils.IsAMatcher(context.RequestContext), utils.IsAMatcher(context.RequestContext),
utils.IsAMatcher(models.ShareInstance), utils.IsAMatcher(models.ShareInstance),
@ -1322,7 +1322,7 @@ class ShareManagerTestCase(test.TestCase):
access_id) access_id)
acs = db.share_access_get(self.context, access_id) acs = db.share_access_get(self.context, access_id)
self.assertEqual(acs['state'], constants.STATUS_ERROR) self.assertEqual(constants.STATUS_ERROR, acs['state'])
self.assertRaises(exception.NotFound, self.assertRaises(exception.NotFound,
self.share_manager.deny_access, self.share_manager.deny_access,
@ -1331,7 +1331,7 @@ class ShareManagerTestCase(test.TestCase):
access_id) access_id)
acs = db.share_access_get(self.context, access_id) acs = db.share_access_get(self.context, access_id)
self.assertEqual(acs['state'], constants.STATUS_ERROR) self.assertEqual(constants.STATUS_ERROR, acs['state'])
def test_setup_server(self): def test_setup_server(self):
# Setup required test data # Setup required test data

View File

@ -113,7 +113,7 @@ class ShareRpcAPITestCase(test.TestCase):
def _fake_prepare_method(*args, **kwds): def _fake_prepare_method(*args, **kwds):
for kwd in kwds: for kwd in kwds:
self.assertEqual(kwds[kwd], target[kwd]) self.assertEqual(target[kwd], kwds[kwd])
return self.rpcapi.client return self.rpcapi.client
def _fake_rpc_method(*args, **kwargs): def _fake_rpc_method(*args, **kwargs):
@ -127,13 +127,13 @@ class ShareRpcAPITestCase(test.TestCase):
retval = getattr(self.rpcapi, method)(self.ctxt, **kwargs) retval = getattr(self.rpcapi, method)(self.ctxt, **kwargs)
self.assertEqual(retval, expected_retval) self.assertEqual(expected_retval, retval)
expected_args = [self.ctxt, method] expected_args = [self.ctxt, method]
for arg, expected_arg in zip(self.fake_args, expected_args): for arg, expected_arg in zip(self.fake_args, expected_args):
self.assertEqual(arg, expected_arg) self.assertEqual(expected_arg, arg)
for kwarg, value in six.iteritems(self.fake_kwargs): for kwarg, value in six.iteritems(self.fake_kwargs):
self.assertEqual(value, expected_msg[kwarg]) self.assertEqual(expected_msg[kwarg], value)
def test_create_share_instance(self): def test_create_share_instance(self):
self._test_share_api('create_share_instance', self._test_share_api('create_share_instance',