Fix params order in assertEqual

Fix params order to correspond to real signature:
    assertEqual(expected, actual)

Change-Id: I129aad5d8bb7ca0541c07913cb5edd8eef9e90ba
Closes-Bug: #1277104
This commit is contained in:
Kan 2016-01-12 09:03:19 +00:00
parent 43a149d5ea
commit 2b07976b94
6 changed files with 85 additions and 86 deletions

View File

@ -95,7 +95,7 @@ class TestStandbyExtension(test_base.BaseTestCase):
def test_image_location(self):
image_info = _build_fake_image_info()
location = standby._image_location(image_info)
self.assertEqual(location, '/tmp/fake_id')
self.assertEqual('/tmp/fake_id', location)
@mock.patch(OPEN_FUNCTION_NAME, autospec=True)
@mock.patch('ironic_python_agent.utils.execute', autospec=True)
@ -219,7 +219,7 @@ class TestStandbyExtension(test_base.BaseTestCase):
write = file_mock.write
write.assert_any_call('some')
write.assert_any_call('content')
self.assertEqual(write.call_count, 2)
self.assertEqual(2, write.call_count)
@mock.patch('hashlib.md5')
@mock.patch(OPEN_FUNCTION_NAME)
@ -249,7 +249,7 @@ class TestStandbyExtension(test_base.BaseTestCase):
write = file_mock.write
write.assert_any_call('some')
write.assert_any_call('content')
self.assertEqual(write.call_count, 2)
self.assertEqual(2, write.call_count)
@mock.patch('requests.get', autospec=True)
def test_download_image_bad_status(self, requests_mock):
@ -305,8 +305,8 @@ class TestStandbyExtension(test_base.BaseTestCase):
download_mock.assert_called_once_with(image_info)
write_mock.assert_called_once_with(image_info, 'manager')
dispatch_mock.assert_called_once_with('get_os_install_device')
self.assertEqual(self.agent_extension.cached_image_id,
image_info['id'])
self.assertEqual(image_info['id'],
self.agent_extension.cached_image_id)
self.assertEqual('SUCCEEDED', async_result.command_status)
self.assertTrue('result' in async_result.command_result.keys())
cmd_result = ('cache_image: image ({0}) cached to device {1}'
@ -333,8 +333,8 @@ class TestStandbyExtension(test_base.BaseTestCase):
download_mock.assert_called_once_with(image_info)
write_mock.assert_called_once_with(image_info, 'manager')
dispatch_mock.assert_called_once_with('get_os_install_device')
self.assertEqual(self.agent_extension.cached_image_id,
image_info['id'])
self.assertEqual(image_info['id'],
self.agent_extension.cached_image_id)
self.assertEqual('SUCCEEDED', async_result.command_status)
self.assertTrue('result' in async_result.command_result.keys())
cmd_result = ('cache_image: image ({0}) cached to device {1}'
@ -359,8 +359,8 @@ class TestStandbyExtension(test_base.BaseTestCase):
self.assertFalse(download_mock.called)
self.assertFalse(write_mock.called)
dispatch_mock.assert_called_once_with('get_os_install_device')
self.assertEqual(self.agent_extension.cached_image_id,
image_info['id'])
self.assertEqual(image_info['id'],
self.agent_extension.cached_image_id)
self.assertEqual('SUCCEEDED', async_result.command_status)
self.assertTrue('result' in async_result.command_result.keys())
cmd_result = ('cache_image: image ({0}) already present on device {1}'
@ -419,8 +419,8 @@ class TestStandbyExtension(test_base.BaseTestCase):
)
async_result.join()
self.assertEqual(download_mock.call_count, 0)
self.assertEqual(write_mock.call_count, 0)
self.assertEqual(0, download_mock.call_count)
self.assertEqual(0, write_mock.call_count)
configdrive_copy_mock.assert_called_once_with('configdrive_data',
'manager')
@ -460,7 +460,7 @@ class TestStandbyExtension(test_base.BaseTestCase):
write_mock.assert_called_once_with(image_info, 'manager')
dispatch_mock.assert_called_once_with('get_os_install_device')
self.assertEqual(configdrive_copy_mock.call_count, 0)
self.assertEqual(0, configdrive_copy_mock.call_count)
self.assertEqual('SUCCEEDED', async_result.command_status)
self.assertTrue('result' in async_result.command_result.keys())
cmd_result = ('prepare_image: image ({0}) written to device {1}'

View File

@ -121,7 +121,7 @@ class TestHeartbeater(test_base.BaseTestCase):
# Validate expectations
self.assertEqual(expected_poll_calls,
mock_poll.return_value.poll.call_args_list)
self.assertEqual(self.heartbeater.error_delay, 2.7)
self.assertEqual(2.7, self.heartbeater.error_delay)
class TestBaseAgent(test_base.BaseTestCase):
@ -160,10 +160,9 @@ class TestBaseAgent(test_base.BaseTestCase):
status = self.agent.get_status()
self.assertTrue(isinstance(status, agent.IronicPythonAgentStatus))
self.assertEqual(status.started_at, started_at)
self.assertEqual(status.version,
pkg_resources.get_distribution('ironic-python-agent')
.version)
self.assertEqual(started_at, status.started_at)
self.assertEqual(pkg_resources.get_distribution('ironic-python-agent')
.version, status.version)
@mock.patch('wsgiref.simple_server.make_server', autospec=True)
@mock.patch.object(hardware.HardwareManager, 'list_hardware_info')
@ -292,7 +291,7 @@ class TestBaseAgent(test_base.BaseTestCase):
'command_result': None,
'command_error': None,
}
self.assertEqualEncoded(result, expected_result)
self.assertEqualEncoded(expected_result, result)
result.start()
result.join()
@ -301,7 +300,7 @@ class TestBaseAgent(test_base.BaseTestCase):
expected_result['command_result'] = {'result': ('foo_command: command '
'execution succeeded')}
self.assertEqualEncoded(result, expected_result)
self.assertEqualEncoded(expected_result, result)
def test_async_command_failure(self):
result = base.AsyncCommandResult('foo_command', {'fail': True},
@ -316,7 +315,7 @@ class TestBaseAgent(test_base.BaseTestCase):
'command_result': None,
'command_error': None,
}
self.assertEqualEncoded(result, expected_result)
self.assertEqualEncoded(expected_result, result)
result.start()
result.join()
@ -325,7 +324,7 @@ class TestBaseAgent(test_base.BaseTestCase):
expected_result['command_error'] = errors.CommandExecutionError(
str(EXPECTED_ERROR))
self.assertEqualEncoded(result, expected_result)
self.assertEqualEncoded(expected_result, result)
def test_get_node_uuid(self):
self.agent.node = {'uuid': 'fake-node'}

View File

@ -156,7 +156,7 @@ class TestIronicAPI(test_base.BaseTestCase):
def test_root(self):
response = self.get_json('/', path_prefix='')
data = response.json
self.assertEqual(data['name'], 'OpenStack Ironic Python Agent API')
self.assertEqual('OpenStack Ironic Python Agent API', data['name'])
def test_v1_root(self):
response = self.get_json('/v1', path_prefix='')
@ -172,10 +172,10 @@ class TestIronicAPI(test_base.BaseTestCase):
response = self.get_json('/status')
self.mock_agent.get_status.assert_called_once_with()
self.assertEqual(response.status_code, 200)
self.assertEqual(200, response.status_code)
data = response.json
self.assertEqual(data['started_at'], status.started_at)
self.assertEqual(data['version'], status.version)
self.assertEqual(status.started_at, data['started_at'])
self.assertEqual(status.version, data['version'])
def test_execute_agent_command_success_no_wait(self):
command = {
@ -194,15 +194,15 @@ class TestIronicAPI(test_base.BaseTestCase):
response = self.post_json('/commands', command)
self.assertFalse(join_mock.called)
self.assertEqual(response.status_code, 200)
self.assertEqual(200, response.status_code)
self.assertEqual(self.mock_agent.execute_command.call_count, 1)
self.assertEqual(1, self.mock_agent.execute_command.call_count)
args, kwargs = self.mock_agent.execute_command.call_args
self.assertEqual(args, ('do_things',))
self.assertEqual(kwargs, {'key': 'value'})
self.assertEqual(('do_things',), args)
self.assertEqual({'key': 'value'}, kwargs)
expected_result = result.serialize()
data = response.json
self.assertEqual(data, expected_result)
self.assertEqual(expected_result, data)
def test_execute_agent_command_success_with_true_wait(self):
command = {
@ -221,14 +221,14 @@ class TestIronicAPI(test_base.BaseTestCase):
response = self.post_json('/commands?wait=true', command)
join_mock.assert_called_once_with()
self.assertEqual(response.status_code, 200)
self.assertEqual(self.mock_agent.execute_command.call_count, 1)
self.assertEqual(200, response.status_code)
self.assertEqual(1, self.mock_agent.execute_command.call_count)
args, kwargs = self.mock_agent.execute_command.call_args
self.assertEqual(args, ('do_things',))
self.assertEqual(kwargs, {'key': 'value'})
self.assertEqual(('do_things',), args)
self.assertEqual({'key': 'value'}, kwargs)
expected_result = result.serialize()
data = response.json
self.assertEqual(data, expected_result)
self.assertEqual(expected_result, data)
def test_execute_agent_command_success_with_false_wait(self):
command = {
@ -247,21 +247,21 @@ class TestIronicAPI(test_base.BaseTestCase):
response = self.post_json('/commands?wait=false', command)
self.assertFalse(join_mock.called)
self.assertEqual(response.status_code, 200)
self.assertEqual(self.mock_agent.execute_command.call_count, 1)
self.assertEqual(200, response.status_code)
self.assertEqual(1, self.mock_agent.execute_command.call_count)
args, kwargs = self.mock_agent.execute_command.call_args
self.assertEqual(args, ('do_things',))
self.assertEqual(kwargs, {'key': 'value'})
self.assertEqual(('do_things',), args)
self.assertEqual({'key': 'value'}, kwargs)
expected_result = result.serialize()
data = response.json
self.assertEqual(data, expected_result)
self.assertEqual(expected_result, data)
def test_execute_agent_command_validation(self):
invalid_command = {}
response = self.post_json('/commands',
invalid_command,
expect_errors=True)
self.assertEqual(response.status_code, 400)
self.assertEqual(400, response.status_code)
data = response.json
msg = 'Invalid input for field/attribute name.'
self.assertTrue(msg in data['faultstring'])
@ -273,7 +273,7 @@ class TestIronicAPI(test_base.BaseTestCase):
response = self.post_json('/commands',
invalid_command,
expect_errors=True)
self.assertEqual(response.status_code, 400)
self.assertEqual(400, response.status_code)
data = response.json
# this message is actually much longer, but I'm ok with this
msg = 'Invalid input for field/attribute params.'
@ -290,12 +290,12 @@ class TestIronicAPI(test_base.BaseTestCase):
]
response = self.get_json('/commands')
self.assertEqual(response.status_code, 200)
self.assertEqual(response.json, {
self.assertEqual(200, response.status_code)
self.assertEqual({
u'commands': [
cmd_result.serialize(),
],
})
}, response.json)
def test_get_command_result(self):
cmd_result = base.SyncCommandResult('do_things',
@ -307,6 +307,6 @@ class TestIronicAPI(test_base.BaseTestCase):
self.mock_agent.get_command_result.return_value = cmd_result
response = self.get_json('/commands/abc123')
self.assertEqual(response.status_code, 200)
self.assertEqual(200, response.status_code)
data = response.json
self.assertEqual(data, serialized_cmd_result)
self.assertEqual(serialized_cmd_result, data)

View File

@ -278,15 +278,15 @@ class TestGenericHardwareManager(test_base.BaseTestCase):
netifaces.AF_INET: [{'addr': '192.168.1.2'}]
}
interfaces = self.hardware.list_network_interfaces()
self.assertEqual(len(interfaces), 1)
self.assertEqual(interfaces[0].name, 'eth0')
self.assertEqual(interfaces[0].mac_address, '00:0c:29:8c:11:b1')
self.assertEqual(interfaces[0].ipv4_address, '192.168.1.2')
self.assertEqual(1, len(interfaces))
self.assertEqual('eth0', interfaces[0].name)
self.assertEqual('00:0c:29:8c:11:b1', interfaces[0].mac_address)
self.assertEqual('192.168.1.2', interfaces[0].ipv4_address)
@mock.patch.object(utils, 'execute')
def test_get_os_install_device(self, mocked_execute):
mocked_execute.return_value = (BLK_DEVICE_TEMPLATE, '')
self.assertEqual(self.hardware.get_os_install_device(), '/dev/sdb')
self.assertEqual('/dev/sdb', self.hardware.get_os_install_device())
mocked_execute.assert_called_once_with(
'lsblk', '-Pbdi', '-oKNAME,MODEL,SIZE,ROTA,TYPE',
check_exit_code=[0])
@ -382,22 +382,22 @@ class TestGenericHardwareManager(test_base.BaseTestCase):
mocked_execute.return_value = LSCPU_OUTPUT, ''
cpus = self.hardware.get_cpus()
self.assertEqual(cpus.model_name,
'Intel(R) Xeon(R) CPU E5-2609 0 @ 2.40GHz')
self.assertEqual(cpus.frequency, '2400.0000')
self.assertEqual(cpus.count, 4)
self.assertEqual(cpus.architecture, 'x86_64')
self.assertEqual('Intel(R) Xeon(R) CPU E5-2609 0 @ 2.40GHz',
cpus.model_name)
self.assertEqual('2400.0000', cpus.frequency)
self.assertEqual(4, cpus.count)
self.assertEqual('x86_64', cpus.architecture)
@mock.patch.object(utils, 'execute')
def test_get_cpus2(self, mocked_execute):
mocked_execute.return_value = LSCPU_OUTPUT_NO_MAX_MHZ, ''
cpus = self.hardware.get_cpus()
self.assertEqual(cpus.model_name,
'Intel(R) Xeon(R) CPU E5-1650 v3 @ 3.50GHz')
self.assertEqual(cpus.frequency, '1794.433')
self.assertEqual(cpus.count, 12)
self.assertEqual(cpus.architecture, 'x86_64')
self.assertEqual('Intel(R) Xeon(R) CPU E5-1650 v3 @ 3.50GHz',
cpus.model_name)
self.assertEqual('1794.433', cpus.frequency)
self.assertEqual(12, cpus.count)
self.assertEqual('x86_64', cpus.architecture)
@mock.patch('psutil.version_info', (2, 0))
@mock.patch('psutil.phymem_usage', autospec=True)
@ -411,8 +411,8 @@ class TestGenericHardwareManager(test_base.BaseTestCase):
mem = self.hardware.get_memory()
self.assertEqual(mem.total, 3952 * 1024 * 1024)
self.assertEqual(mem.physical_mb, 4096)
self.assertEqual(3952 * 1024 * 1024, mem.total)
self.assertEqual(4096, mem.physical_mb)
def test_list_hardware_info(self):
self.hardware.list_network_interfaces = mock.Mock()
@ -438,12 +438,12 @@ class TestGenericHardwareManager(test_base.BaseTestCase):
]
hardware_info = self.hardware.list_hardware_info()
self.assertEqual(hardware_info['memory'], self.hardware.get_memory())
self.assertEqual(hardware_info['cpu'], self.hardware.get_cpus())
self.assertEqual(hardware_info['disks'],
self.hardware.list_block_devices())
self.assertEqual(hardware_info['interfaces'],
self.hardware.list_network_interfaces())
self.assertEqual(self.hardware.get_memory(), hardware_info['memory'])
self.assertEqual(self.hardware.get_cpus(), hardware_info['cpu'])
self.assertEqual(self.hardware.list_block_devices(),
hardware_info['disks'])
self.assertEqual(self.hardware.list_network_interfaces(),
hardware_info['interfaces'])
@mock.patch.object(hardware, 'list_all_block_devices')
def test_list_block_devices(self, list_mock):

View File

@ -68,8 +68,8 @@ class TestBaseIronicPythonAgent(test_base.BaseTestCase):
heartbeat_path = 'v1/nodes/deadbeef-dabb-ad00-b105-f00d00bab10c/' \
'vendor_passthru/heartbeat'
request_args = self.api_client.session.request.call_args[0]
self.assertEqual(request_args[0], 'POST')
self.assertEqual(request_args[1], API_URL + heartbeat_path)
self.assertEqual('POST', request_args[0])
self.assertEqual(API_URL + heartbeat_path, request_args[1])
def test_heartbeat_requests_exception(self):
self.api_client.session.request = mock.Mock()
@ -137,14 +137,14 @@ class TestBaseIronicPythonAgent(test_base.BaseTestCase):
url = '{api_url}v1/drivers/{driver}/vendor_passthru/lookup'.format(
api_url=API_URL, driver=DRIVER)
request_args = self.api_client.session.request.call_args[0]
self.assertEqual(request_args[0], 'POST')
self.assertEqual(request_args[1], url)
self.assertEqual('POST', request_args[0])
self.assertEqual(url, request_args[1])
data = self.api_client.session.request.call_args[1]['data']
content = json.loads(data)
self.assertNotIn('node_uuid', content)
self.assertEqual(content['version'], self.api_client.payload_version)
self.assertEqual(content['inventory'], {
self.assertEqual(self.api_client.payload_version, content['version'])
self.assertEqual({
u'interfaces': [
{
u'mac_address': u'00:0c:29:8c:11:b1',
@ -195,7 +195,7 @@ class TestBaseIronicPythonAgent(test_base.BaseTestCase):
u'total': u'8675309',
u'physical_mb': u'8675'
},
})
}, content['inventory'])
def test_do_lookup_bad_response_code(self):
response = FakeResponse(status_code=400, content={
@ -272,14 +272,14 @@ class TestBaseIronicPythonAgent(test_base.BaseTestCase):
url = '{api_url}v1/drivers/{driver}/vendor_passthru/lookup'.format(
api_url=API_URL, driver=DRIVER)
request_args = self.api_client.session.request.call_args[0]
self.assertEqual(request_args[0], 'POST')
self.assertEqual(request_args[1], url)
self.assertEqual('POST', request_args[0])
self.assertEqual(url, request_args[1])
data = self.api_client.session.request.call_args[1]['data']
content = json.loads(data)
self.assertEqual(content['node_uuid'], 'uuid')
self.assertEqual(content['version'], self.api_client.payload_version)
self.assertEqual(content['inventory'], {
self.assertEqual('uuid', content['node_uuid'])
self.assertEqual(self.api_client.payload_version, content['version'])
self.assertEqual({
u'interfaces': [
{
u'mac_address': u'00:0c:29:8c:11:b1',
@ -330,4 +330,4 @@ class TestBaseIronicPythonAgent(test_base.BaseTestCase):
u'total': u'8675309',
u'physical_mb': u'8675'
},
})
}, content['inventory'])

View File

@ -139,7 +139,7 @@ class GetAgentParamsTestCase(test_base.BaseTestCase):
def test__read_params_from_file_fail(self, logger_mock, open_mock):
open_mock.side_effect = Exception
params = utils._read_params_from_file('file-path')
self.assertEqual(params, {})
self.assertEqual({}, params)
@mock.patch(OPEN_FUNCTION_NAME)
def test__read_params_from_file(self, open_mock):
@ -151,8 +151,8 @@ class GetAgentParamsTestCase(test_base.BaseTestCase):
params = utils._read_params_from_file('file-path')
open_mock.assert_called_once_with('file-path')
read_mock.assert_called_once_with()
self.assertEqual(params['api-url'], 'http://localhost:9999')
self.assertEqual(params['foo'], 'bar')
self.assertEqual('http://localhost:9999', params['api-url'])
self.assertEqual('bar', params['foo'])
self.assertFalse('baz' in params)
@mock.patch.object(utils, '_set_cached_params')