Merge "ironic/tests/drivers: Add autospec=True and spec_set="

This commit is contained in:
Jenkins
2015-05-11 19:36:19 +00:00
committed by Gerrit Code Review
20 changed files with 971 additions and 776 deletions
+63 -49
View File
@@ -50,7 +50,7 @@ class TestAgentMethods(db_base.DbTestCase):
self.assertEqual('fake_agent', options['ipa-driver-name'])
self.assertEqual(0, options['coreos.configdrive'])
@mock.patch.object(keystone, 'get_service_url')
@mock.patch.object(keystone, 'get_service_url', autospec=True)
def test_build_agent_options_keystone(self, get_url_mock):
self.config(api_url=None, group='conductor')
@@ -68,7 +68,7 @@ class TestAgentMethods(db_base.DbTestCase):
self.assertEqual('fake_agent', options['ipa-driver-name'])
self.assertEqual('model=fake_model', options['root_device'])
@mock.patch.object(image_service, 'GlanceImageService')
@mock.patch.object(image_service, 'GlanceImageService', autospec=True)
def test_build_instance_info_for_deploy_glance_image(self, glance_mock):
i_info = self.node.instance_info
i_info['image_source'] = '733d1c44-a2ea-414b-aca7-69decf20d810'
@@ -77,7 +77,8 @@ class TestAgentMethods(db_base.DbTestCase):
image_info = {'checksum': 'aa', 'disk_format': 'qcow2',
'container_format': 'bare'}
glance_mock.return_value.show = mock.Mock(return_value=image_info)
glance_mock.return_value.show = mock.MagicMock(spec_set=[],
return_value=image_info)
mgr_utils.mock_the_extension_manager(driver='fake_agent')
with task_manager.acquire(
@@ -92,7 +93,8 @@ class TestAgentMethods(db_base.DbTestCase):
glance_mock.return_value.swift_temp_url.assert_called_once_with(
image_info)
@mock.patch.object(image_service.HttpImageService, 'validate_href')
@mock.patch.object(image_service.HttpImageService, 'validate_href',
autospec=True)
def test_build_instance_info_for_deploy_nonglance_image(self,
validate_href_mock):
i_info = self.node.instance_info
@@ -109,9 +111,11 @@ class TestAgentMethods(db_base.DbTestCase):
self.assertEqual(self.node.instance_info['image_source'],
info['image_url'])
validate_href_mock.assert_called_once_with('http://image-ref')
validate_href_mock.assert_called_once_with(
mock.ANY, 'http://image-ref')
@mock.patch.object(image_service.HttpImageService, 'validate_href')
@mock.patch.object(image_service.HttpImageService, 'validate_href',
autospec=True)
def test_build_instance_info_for_deploy_nonsupported_image(self,
validate_href_mock):
validate_href_mock.side_effect = exception.ImageRefValidationFailed(
@@ -207,10 +211,10 @@ class TestAgentDeploy(db_base.DbTestCase):
self.assertRaises(exception.InvalidParameterValue,
task.driver.deploy.validate, task)
@mock.patch.object(agent, '_cache_tftp_images')
@mock.patch.object(pxe_utils, 'create_pxe_config')
@mock.patch.object(agent, '_build_pxe_config_options')
@mock.patch.object(agent, '_get_tftp_image_info')
@mock.patch.object(agent, '_cache_tftp_images', autospec=True)
@mock.patch.object(pxe_utils, 'create_pxe_config', autospec=True)
@mock.patch.object(agent, '_build_pxe_config_options', autospec=True)
@mock.patch.object(agent, '_get_tftp_image_info', autospec=True)
def test__prepare_pxe_boot(self, pxe_info_mock, options_mock,
create_mock, cache_mock):
with task_manager.acquire(
@@ -223,10 +227,10 @@ class TestAgentDeploy(db_base.DbTestCase):
cache_mock.assert_called_once_with(task.context, task.node,
mock.ANY)
@mock.patch.object(agent, '_cache_tftp_images')
@mock.patch.object(pxe_utils, 'create_pxe_config')
@mock.patch.object(agent, '_build_pxe_config_options')
@mock.patch.object(agent, '_get_tftp_image_info')
@mock.patch.object(agent, '_cache_tftp_images', autospec=True)
@mock.patch.object(pxe_utils, 'create_pxe_config', autospec=True)
@mock.patch.object(agent, '_build_pxe_config_options', autospec=True)
@mock.patch.object(agent, '_get_tftp_image_info', autospec=True)
def test__prepare_pxe_boot_manage_tftp_false(
self, pxe_info_mock, options_mock, create_mock, cache_mock):
self.config(manage_tftp=False, group='agent')
@@ -238,21 +242,21 @@ class TestAgentDeploy(db_base.DbTestCase):
self.assertFalse(create_mock.called)
self.assertFalse(cache_mock.called)
@mock.patch.object(dhcp_factory.DHCPFactory, 'update_dhcp')
@mock.patch('ironic.conductor.utils.node_set_boot_device')
@mock.patch('ironic.conductor.utils.node_power_action')
@mock.patch.object(dhcp_factory.DHCPFactory, 'update_dhcp', autospec=True)
@mock.patch('ironic.conductor.utils.node_set_boot_device', autospec=True)
@mock.patch('ironic.conductor.utils.node_power_action', autospec=True)
def test_deploy(self, power_mock, bootdev_mock, dhcp_mock):
with task_manager.acquire(
self.context, self.node['uuid'], shared=False) as task:
dhcp_opts = pxe_utils.dhcp_options_for_instance(task)
driver_return = self.driver.deploy(task)
self.assertEqual(driver_return, states.DEPLOYWAIT)
dhcp_mock.assert_called_once_with(task, dhcp_opts, None)
dhcp_mock.assert_called_once_with(mock.ANY, task, dhcp_opts, None)
bootdev_mock.assert_called_once_with(task, 'pxe', persistent=True)
power_mock.assert_called_once_with(task,
states.REBOOT)
@mock.patch('ironic.conductor.utils.node_power_action')
@mock.patch('ironic.conductor.utils.node_power_action', autospec=True)
def test_tear_down(self, power_mock):
with task_manager.acquire(
self.context, self.node['uuid'], shared=False) as task:
@@ -260,10 +264,10 @@ class TestAgentDeploy(db_base.DbTestCase):
power_mock.assert_called_once_with(task, states.POWER_OFF)
self.assertEqual(driver_return, states.DELETED)
@mock.patch.object(pxe_utils, 'clean_up_pxe_config')
@mock.patch.object(agent, 'AgentTFTPImageCache')
@mock.patch('ironic.common.utils.unlink_without_raise')
@mock.patch.object(agent, '_get_tftp_image_info')
@mock.patch.object(pxe_utils, 'clean_up_pxe_config', autospec=True)
@mock.patch.object(agent, 'AgentTFTPImageCache', autospec=True)
@mock.patch('ironic.common.utils.unlink_without_raise', autospec=True)
@mock.patch.object(agent, '_get_tftp_image_info', autospec=True)
def test__clean_up_pxe(self, info_mock, unlink_mock, cache_mock,
clean_mock):
info_mock.return_value = {'label': ['fake1', 'fake2']}
@@ -274,10 +278,10 @@ class TestAgentDeploy(db_base.DbTestCase):
unlink_mock.assert_called_once_with('fake2')
clean_mock.assert_called_once_with(task)
@mock.patch.object(pxe_utils, 'clean_up_pxe_config')
@mock.patch.object(agent.AgentTFTPImageCache, 'clean_up')
@mock.patch('ironic.common.utils.unlink_without_raise')
@mock.patch.object(agent, '_get_tftp_image_info')
@mock.patch.object(pxe_utils, 'clean_up_pxe_config', autospec=True)
@mock.patch.object(agent.AgentTFTPImageCache, 'clean_up', autospec=True)
@mock.patch('ironic.common.utils.unlink_without_raise', autospec=True)
@mock.patch.object(agent, '_get_tftp_image_info', autospec=True)
def test__clean_up_pxe_manage_tftp_false(
self, info_mock, unlink_mock, cache_mock, clean_mock):
self.config(manage_tftp=False, group='agent')
@@ -290,10 +294,13 @@ class TestAgentDeploy(db_base.DbTestCase):
self.assertFalse(cache_mock.called)
self.assertFalse(clean_mock.called)
@mock.patch('ironic.dhcp.neutron.NeutronDHCPApi.delete_cleaning_ports')
@mock.patch('ironic.dhcp.neutron.NeutronDHCPApi.create_cleaning_ports')
@mock.patch('ironic.drivers.modules.agent._do_pxe_boot')
@mock.patch('ironic.drivers.modules.agent._prepare_pxe_boot')
@mock.patch('ironic.dhcp.neutron.NeutronDHCPApi.delete_cleaning_ports',
autospec=True)
@mock.patch('ironic.dhcp.neutron.NeutronDHCPApi.create_cleaning_ports',
autospec=True)
@mock.patch('ironic.drivers.modules.agent._do_pxe_boot', autospec=True)
@mock.patch('ironic.drivers.modules.agent._prepare_pxe_boot',
autospec=True)
def test_prepare_cleaning(self, prepare_mock, boot_mock, create_mock,
delete_mock):
ports = [{'ports': self.ports}]
@@ -304,21 +311,23 @@ class TestAgentDeploy(db_base.DbTestCase):
self.driver.prepare_cleaning(task))
prepare_mock.assert_called_once_with(task)
boot_mock.assert_called_once_with(task, ports)
create_mock.assert_called_once_with(task)
delete_mock.assert_called_once_with(task)
create_mock.assert_called_once_with(mock.ANY, task)
delete_mock.assert_called_once_with(mock.ANY, task)
@mock.patch('ironic.dhcp.neutron.NeutronDHCPApi.delete_cleaning_ports')
@mock.patch('ironic.drivers.modules.agent._clean_up_pxe')
@mock.patch('ironic.conductor.utils.node_power_action')
@mock.patch('ironic.dhcp.neutron.NeutronDHCPApi.delete_cleaning_ports',
autospec=True)
@mock.patch('ironic.drivers.modules.agent._clean_up_pxe', autospec=True)
@mock.patch('ironic.conductor.utils.node_power_action', autospec=True)
def test_tear_down_cleaning(self, power_mock, cleanup_mock, neutron_mock):
with task_manager.acquire(
self.context, self.node['uuid'], shared=False) as task:
self.assertIsNone(self.driver.tear_down_cleaning(task))
power_mock.assert_called_once_with(task, states.POWER_OFF)
cleanup_mock.assert_called_once_with(task)
neutron_mock.assert_called_once_with(task)
neutron_mock.assert_called_once_with(mock.ANY, task)
@mock.patch('ironic.drivers.modules.deploy_utils.agent_get_clean_steps')
@mock.patch('ironic.drivers.modules.deploy_utils.agent_get_clean_steps',
autospec=True)
def test_get_clean_steps(self, mock_get_clean_steps):
# Test getting clean steps
mock_steps = [{'priority': 10, 'interface': 'deploy',
@@ -329,7 +338,8 @@ class TestAgentDeploy(db_base.DbTestCase):
mock_get_clean_steps.assert_called_once_with(task)
self.assertEqual(mock_steps, steps)
@mock.patch('ironic.drivers.modules.deploy_utils.agent_get_clean_steps')
@mock.patch('ironic.drivers.modules.deploy_utils.agent_get_clean_steps',
autospec=True)
def test_get_clean_steps_config_priority(self, mock_get_clean_steps):
# Test that we can override the priority of get clean steps
# Use 0 because it is an edge case (false-y) and used in devstack
@@ -372,7 +382,7 @@ class TestAgentVendor(db_base.DbTestCase):
'container_format': 'bare',
}
client_mock = mock.Mock()
client_mock = mock.MagicMock(spec_set=['prepare_image'])
self.passthru._client = client_mock
with task_manager.acquire(self.context, self.node.uuid,
@@ -398,7 +408,7 @@ class TestAgentVendor(db_base.DbTestCase):
'container_format': 'bare',
}
client_mock = mock.Mock()
client_mock = mock.MagicMock(spec_set=['prepare_image'])
self.passthru._client = client_mock
with task_manager.acquire(self.context, self.node.uuid,
@@ -411,10 +421,10 @@ class TestAgentVendor(db_base.DbTestCase):
self.assertEqual(states.ACTIVE,
task.node.target_provision_state)
@mock.patch('ironic.conductor.utils.node_power_action')
@mock.patch('ironic.conductor.utils.node_set_boot_device')
@mock.patch('ironic.conductor.utils.node_power_action', autospec=True)
@mock.patch('ironic.conductor.utils.node_set_boot_device', autospec=True)
@mock.patch('ironic.drivers.modules.agent.AgentVendorInterface'
'.check_deploy_success')
'.check_deploy_success', autospec=True)
def test_reboot_to_instance(self, check_deploy_mock, bootdev_mock,
power_mock):
check_deploy_mock.return_value = None
@@ -427,33 +437,37 @@ class TestAgentVendor(db_base.DbTestCase):
shared=False) as task:
self.passthru.reboot_to_instance(task)
check_deploy_mock.assert_called_once_with(task.node)
check_deploy_mock.assert_called_once_with(mock.ANY, task.node)
bootdev_mock.assert_called_once_with(task, 'disk', persistent=True)
power_mock.assert_called_once_with(task, states.REBOOT)
self.assertEqual(states.ACTIVE, task.node.provision_state)
self.assertEqual(states.NOSTATE, task.node.target_provision_state)
@mock.patch.object(agent_client.AgentClient, 'get_commands_status')
@mock.patch.object(agent_client.AgentClient, 'get_commands_status',
autospec=True)
def test_deploy_is_done(self, mock_get_cmd):
with task_manager.acquire(self.context, self.node.uuid) as task:
mock_get_cmd.return_value = [{'command_name': 'prepare_image',
'command_status': 'SUCCESS'}]
self.assertTrue(self.passthru.deploy_is_done(task))
@mock.patch.object(agent_client.AgentClient, 'get_commands_status')
@mock.patch.object(agent_client.AgentClient, 'get_commands_status',
autospec=True)
def test_deploy_is_done_empty_response(self, mock_get_cmd):
with task_manager.acquire(self.context, self.node.uuid) as task:
mock_get_cmd.return_value = []
self.assertFalse(self.passthru.deploy_is_done(task))
@mock.patch.object(agent_client.AgentClient, 'get_commands_status')
@mock.patch.object(agent_client.AgentClient, 'get_commands_status',
autospec=True)
def test_deploy_is_done_race(self, mock_get_cmd):
with task_manager.acquire(self.context, self.node.uuid) as task:
mock_get_cmd.return_value = [{'command_name': 'some_other_command',
'command_status': 'SUCCESS'}]
self.assertFalse(self.passthru.deploy_is_done(task))
@mock.patch.object(agent_client.AgentClient, 'get_commands_status')
@mock.patch.object(agent_client.AgentClient, 'get_commands_status',
autospec=True)
def test_deploy_is_done_still_running(self, mock_get_cmd):
with task_manager.acquire(self.context, self.node.uuid) as task:
mock_get_cmd.return_value = [{'command_name': 'prepare_image',
+72 -48
View File
@@ -15,6 +15,8 @@
# License for the specific language governing permissions and limitations
# under the License.
import types
import mock
from ironic.common import boot_devices
@@ -85,7 +87,7 @@ class TestBaseAgentVendor(db_base.DbTestCase):
**kwargs)
@mock.patch('ironic.drivers.modules.agent_base_vendor.BaseAgentVendor'
'._find_node_by_macs')
'._find_node_by_macs', autospec=True)
def test_lookup_v2(self, find_mock):
kwargs = {
'version': '2',
@@ -129,7 +131,8 @@ class TestBaseAgentVendor(db_base.DbTestCase):
version='2',
inventory={'interfaces': []})
@mock.patch.object(objects.Port, 'get_by_address')
@mock.patch.object(objects.port.Port, 'get_by_address',
spec_set=types.FunctionType)
def test_find_ports_by_macs(self, mock_get_port):
fake_port = object_utils.get_test_port(self.context)
mock_get_port.return_value = fake_port
@@ -143,7 +146,8 @@ class TestBaseAgentVendor(db_base.DbTestCase):
self.assertEqual(fake_port.uuid, ports[0].uuid)
self.assertEqual(fake_port.node_id, ports[0].node_id)
@mock.patch.object(objects.Port, 'get_by_address')
@mock.patch.object(objects.port.Port, 'get_by_address',
spec_set=types.FunctionType)
def test_find_ports_by_macs_bad_params(self, mock_get_port):
mock_get_port.side_effect = exception.PortNotFound(port="123")
@@ -153,11 +157,12 @@ class TestBaseAgentVendor(db_base.DbTestCase):
empty_ids = self.passthru._find_ports_by_macs(task, macs)
self.assertEqual([], empty_ids)
@mock.patch('ironic.objects.node.Node.get_by_id')
@mock.patch('ironic.objects.node.Node.get_by_id',
spec_set=types.FunctionType)
@mock.patch('ironic.drivers.modules.agent_base_vendor.BaseAgentVendor'
'._get_node_id')
'._get_node_id', autospec=True)
@mock.patch('ironic.drivers.modules.agent_base_vendor.BaseAgentVendor'
'._find_ports_by_macs')
'._find_ports_by_macs', autospec=True)
def test_find_node_by_macs(self, ports_mock, node_id_mock, node_mock):
ports_mock.return_value = object_utils.get_test_port(self.context)
node_id_mock.return_value = '1'
@@ -170,7 +175,7 @@ class TestBaseAgentVendor(db_base.DbTestCase):
self.assertEqual(node, node)
@mock.patch('ironic.drivers.modules.agent_base_vendor.BaseAgentVendor'
'._find_ports_by_macs')
'._find_ports_by_macs', autospec=True)
def test_find_node_by_macs_no_ports(self, ports_mock):
ports_mock.return_value = []
@@ -182,11 +187,12 @@ class TestBaseAgentVendor(db_base.DbTestCase):
task,
macs)
@mock.patch('ironic.objects.node.Node.get_by_uuid')
@mock.patch('ironic.objects.node.Node.get_by_uuid',
spec_set=types.FunctionType)
@mock.patch('ironic.drivers.modules.agent_base_vendor.BaseAgentVendor'
'._get_node_id')
'._get_node_id', autospec=True)
@mock.patch('ironic.drivers.modules.agent_base_vendor.BaseAgentVendor'
'._find_ports_by_macs')
'._find_ports_by_macs', autospec=True)
def test_find_node_by_macs_nodenotfound(self, ports_mock, node_id_mock,
node_mock):
port = object_utils.get_test_port(self.context)
@@ -264,9 +270,10 @@ class TestBaseAgentVendor(db_base.DbTestCase):
self.assertRaises(exception.MissingParameterValue,
self.passthru.heartbeat, task, **kwargs)
@mock.patch.object(deploy_utils, 'set_failed_state')
@mock.patch.object(agent_base_vendor.BaseAgentVendor, 'deploy_is_done')
@mock.patch.object(agent_base_vendor.LOG, 'exception')
@mock.patch.object(deploy_utils, 'set_failed_state', autospec=True)
@mock.patch.object(agent_base_vendor.BaseAgentVendor, 'deploy_is_done',
autospec=True)
@mock.patch.object(agent_base_vendor.LOG, 'exception', autospec=True)
def test_heartbeat_deploy_done_fails(self, log_mock, done_mock,
failed_mock):
kwargs = {
@@ -284,10 +291,12 @@ class TestBaseAgentVendor(db_base.DbTestCase):
'1be26c0b-03f2-4d2e-ae87-c02d7f33c123: Failed checking if deploy '
'is done. exception: LlamaException')
@mock.patch.object(agent_base_vendor.BaseAgentVendor, 'continue_deploy')
@mock.patch.object(agent_base_vendor.BaseAgentVendor, 'reboot_to_instance')
@mock.patch.object(agent_base_vendor.BaseAgentVendor, 'continue_deploy',
autospec=True)
@mock.patch.object(agent_base_vendor.BaseAgentVendor, 'reboot_to_instance',
autospec=True)
@mock.patch.object(agent_base_vendor.BaseAgentVendor,
'_notify_conductor_resume_clean')
'_notify_conductor_resume_clean', autospec=True)
def test_heartbeat_noops_maintenance_mode(self, ncrc_mock, rti_mock,
cd_mock):
"""Ensures that heartbeat() no-ops for a maintenance node."""
@@ -323,7 +332,7 @@ class TestBaseAgentVendor(db_base.DbTestCase):
self.assertIsInstance(driver_routes, dict)
self.assertEqual(expected, list(driver_routes))
@mock.patch.object(manager_utils, 'node_power_action')
@mock.patch.object(manager_utils, 'node_power_action', autospec=True)
def test_reboot_and_finish_deploy_success(self, node_power_action_mock):
self.node.provision_state = states.DEPLOYING
self.node.target_provision_state = states.ACTIVE
@@ -335,7 +344,7 @@ class TestBaseAgentVendor(db_base.DbTestCase):
self.assertEqual(states.ACTIVE, task.node.provision_state)
self.assertEqual(states.NOSTATE, task.node.target_provision_state)
@mock.patch.object(manager_utils, 'node_power_action')
@mock.patch.object(manager_utils, 'node_power_action', autospec=True)
def test_reboot_and_finish_deploy_reboot_failure(self,
node_power_action_mock):
exc = exception.PowerStateFailure(pstate=states.REBOOT)
@@ -351,8 +360,9 @@ class TestBaseAgentVendor(db_base.DbTestCase):
self.assertEqual(states.DEPLOYFAIL, task.node.provision_state)
self.assertEqual(states.ACTIVE, task.node.target_provision_state)
@mock.patch.object(agent_client.AgentClient, 'install_bootloader')
@mock.patch.object(deploy_utils, 'try_set_boot_device')
@mock.patch.object(agent_client.AgentClient, 'install_bootloader',
autospec=True)
@mock.patch.object(deploy_utils, 'try_set_boot_device', autospec=True)
def test_configure_local_boot(self, try_set_boot_device_mock,
install_bootloader_mock):
install_bootloader_mock.return_value = {
@@ -365,11 +375,12 @@ class TestBaseAgentVendor(db_base.DbTestCase):
try_set_boot_device_mock.assert_called_once_with(
task, boot_devices.DISK)
install_bootloader_mock.assert_called_once_with(
task.node, root_uuid='some-root-uuid',
mock.ANY, task.node, root_uuid='some-root-uuid',
efi_system_part_uuid=None)
@mock.patch.object(agent_client.AgentClient, 'install_bootloader')
@mock.patch.object(deploy_utils, 'try_set_boot_device')
@mock.patch.object(agent_client.AgentClient, 'install_bootloader',
autospec=True)
@mock.patch.object(deploy_utils, 'try_set_boot_device', autospec=True)
def test_configure_local_boot_uefi(self, try_set_boot_device_mock,
install_bootloader_mock):
install_bootloader_mock.return_value = {
@@ -383,11 +394,12 @@ class TestBaseAgentVendor(db_base.DbTestCase):
try_set_boot_device_mock.assert_called_once_with(
task, boot_devices.DISK)
install_bootloader_mock.assert_called_once_with(
task.node, root_uuid='some-root-uuid',
mock.ANY, task.node, root_uuid='some-root-uuid',
efi_system_part_uuid='efi-system-part-uuid')
@mock.patch.object(deploy_utils, 'try_set_boot_device')
@mock.patch.object(agent_client.AgentClient, 'install_bootloader')
@mock.patch.object(deploy_utils, 'try_set_boot_device', autospec=True)
@mock.patch.object(agent_client.AgentClient, 'install_bootloader',
autospec=True)
def test_configure_local_boot_whole_disk_image(
self, install_bootloader_mock, try_set_boot_device_mock):
with task_manager.acquire(self.context, self.node['uuid'],
@@ -397,8 +409,9 @@ class TestBaseAgentVendor(db_base.DbTestCase):
try_set_boot_device_mock.assert_called_once_with(
task, boot_devices.DISK)
@mock.patch.object(deploy_utils, 'try_set_boot_device')
@mock.patch.object(agent_client.AgentClient, 'install_bootloader')
@mock.patch.object(deploy_utils, 'try_set_boot_device', autospec=True)
@mock.patch.object(agent_client.AgentClient, 'install_bootloader',
autospec=True)
def test_configure_local_boot_no_root_uuid(
self, install_bootloader_mock, try_set_boot_device_mock):
with task_manager.acquire(self.context, self.node['uuid'],
@@ -409,7 +422,8 @@ class TestBaseAgentVendor(db_base.DbTestCase):
try_set_boot_device_mock.assert_called_once_with(
task, boot_devices.DISK)
@mock.patch.object(agent_client.AgentClient, 'install_bootloader')
@mock.patch.object(agent_client.AgentClient, 'install_bootloader',
autospec=True)
def test_configure_local_boot_boot_loader_install_fail(
self, install_bootloader_mock):
install_bootloader_mock.return_value = {
@@ -424,13 +438,14 @@ class TestBaseAgentVendor(db_base.DbTestCase):
self.passthru.configure_local_boot,
task, root_uuid='some-root-uuid')
install_bootloader_mock.assert_called_once_with(
task.node, root_uuid='some-root-uuid',
mock.ANY, task.node, root_uuid='some-root-uuid',
efi_system_part_uuid=None)
self.assertEqual(states.DEPLOYFAIL, task.node.provision_state)
self.assertEqual(states.ACTIVE, task.node.target_provision_state)
@mock.patch.object(deploy_utils, 'try_set_boot_device')
@mock.patch.object(agent_client.AgentClient, 'install_bootloader')
@mock.patch.object(deploy_utils, 'try_set_boot_device', autospec=True)
@mock.patch.object(agent_client.AgentClient, 'install_bootloader',
autospec=True)
def test_configure_local_boot_set_boot_device_fail(
self, install_bootloader_mock, try_set_boot_device_mock):
install_bootloader_mock.return_value = {
@@ -446,7 +461,7 @@ class TestBaseAgentVendor(db_base.DbTestCase):
self.passthru.configure_local_boot,
task, root_uuid='some-root-uuid')
install_bootloader_mock.assert_called_once_with(
task.node, root_uuid='some-root-uuid',
mock.ANY, task.node, root_uuid='some-root-uuid',
efi_system_part_uuid=None)
try_set_boot_device_mock.assert_called_once_with(
task, boot_devices.DISK)
@@ -454,8 +469,9 @@ class TestBaseAgentVendor(db_base.DbTestCase):
self.assertEqual(states.ACTIVE, task.node.target_provision_state)
@mock.patch.object(agent_base_vendor.BaseAgentVendor,
'_notify_conductor_resume_clean')
@mock.patch.object(agent_client.AgentClient, 'get_commands_status')
'_notify_conductor_resume_clean', autospec=True)
@mock.patch.object(agent_client.AgentClient, 'get_commands_status',
autospec=True)
def test_continue_cleaning(self, status_mock, notify_mock):
# Test a successful execute clean step on the agent
self.node.clean_step = {
@@ -475,11 +491,12 @@ class TestBaseAgentVendor(db_base.DbTestCase):
with task_manager.acquire(self.context, self.node['uuid'],
shared=False) as task:
self.passthru.continue_cleaning(task)
notify_mock.assert_called_once_with(task)
notify_mock.assert_called_once_with(mock.ANY, task)
@mock.patch.object(agent_base_vendor.BaseAgentVendor,
'_notify_conductor_resume_clean')
@mock.patch.object(agent_client.AgentClient, 'get_commands_status')
'_notify_conductor_resume_clean', autospec=True)
@mock.patch.object(agent_client.AgentClient, 'get_commands_status',
autospec=True)
def test_continue_cleaning_old_command(self, status_mock, notify_mock):
# Test when a second execute_clean_step happens to the agent, but
# the new step hasn't started yet.
@@ -506,8 +523,9 @@ class TestBaseAgentVendor(db_base.DbTestCase):
self.assertFalse(notify_mock.called)
@mock.patch.object(agent_base_vendor.BaseAgentVendor,
'_notify_conductor_resume_clean')
@mock.patch.object(agent_client.AgentClient, 'get_commands_status')
'_notify_conductor_resume_clean', autospec=True)
@mock.patch.object(agent_client.AgentClient, 'get_commands_status',
autospec=True)
def test_continue_cleaning_running(self, status_mock, notify_mock):
# Test that no action is taken while a clean step is executing
status_mock.return_value = [{
@@ -520,8 +538,10 @@ class TestBaseAgentVendor(db_base.DbTestCase):
self.passthru.continue_cleaning(task)
self.assertFalse(notify_mock.called)
@mock.patch('ironic.conductor.manager.cleaning_error_handler')
@mock.patch.object(agent_client.AgentClient, 'get_commands_status')
@mock.patch('ironic.conductor.manager.cleaning_error_handler',
autospec=True)
@mock.patch.object(agent_client.AgentClient, 'get_commands_status',
autospec=True)
def test_continue_cleaning_fail(self, status_mock, error_mock):
# Test the a failure puts the node in CLEANFAIL
status_mock.return_value = [{
@@ -534,10 +554,12 @@ class TestBaseAgentVendor(db_base.DbTestCase):
self.passthru.continue_cleaning(task)
error_mock.assert_called_once_with(task, mock.ANY)
@mock.patch('ironic.conductor.manager.set_node_cleaning_steps')
@mock.patch('ironic.conductor.manager.set_node_cleaning_steps',
autospec=True)
@mock.patch.object(agent_base_vendor.BaseAgentVendor,
'_notify_conductor_resume_clean')
@mock.patch.object(agent_client.AgentClient, 'get_commands_status')
'_notify_conductor_resume_clean', autospec=True)
@mock.patch.object(agent_client.AgentClient, 'get_commands_status',
autospec=True)
def test_continue_cleaning_clean_version_mismatch(
self, status_mock, notify_mock, steps_mock):
# Test that cleaning is restarted if there is a version mismatch
@@ -550,10 +572,12 @@ class TestBaseAgentVendor(db_base.DbTestCase):
shared=False) as task:
self.passthru.continue_cleaning(task)
steps_mock.assert_called_once_with(task)
notify_mock.assert_called_once_with(task)
notify_mock.assert_called_once_with(mock.ANY, task)
@mock.patch('ironic.conductor.manager.cleaning_error_handler')
@mock.patch.object(agent_client.AgentClient, 'get_commands_status')
@mock.patch('ironic.conductor.manager.cleaning_error_handler',
autospec=True)
@mock.patch.object(agent_client.AgentClient, 'get_commands_status',
autospec=True)
def test_continue_cleaning_unknown(self, status_mock, error_mock):
# Test that unknown commands are treated as failures
status_mock.return_value = [{
+14 -13
View File
@@ -55,7 +55,7 @@ class TestAgentClient(base.TestCase):
def setUp(self):
super(TestAgentClient, self).setUp()
self.client = agent_client.AgentClient()
self.client.session = mock.Mock(autospec=requests.Session)
self.client.session = mock.MagicMock(autospec=requests.Session)
self.node = MockNode()
def test_content_type_header(self):
@@ -116,15 +116,16 @@ class TestAgentClient(base.TestCase):
params={'wait': 'false'})
def test_get_commands_status(self):
with mock.patch.object(self.client.session, 'get') as mock_get:
res = mock.Mock()
with mock.patch.object(self.client.session, 'get',
autospec=True) as mock_get:
res = mock.MagicMock(spec_set=['json'])
res.json.return_value = {'commands': []}
mock_get.return_value = res
self.assertEqual([], self.client.get_commands_status(self.node))
@mock.patch('uuid.uuid4', mock.MagicMock(return_value='uuid'))
@mock.patch('uuid.uuid4', mock.MagicMock(spec_set=[], return_value='uuid'))
def test_prepare_image(self):
self.client._command = mock.Mock()
self.client._command = mock.MagicMock(spec_set=[])
image_info = {'image_id': 'image'}
params = {'image_info': image_info}
@@ -136,9 +137,9 @@ class TestAgentClient(base.TestCase):
params=params,
wait=False)
@mock.patch('uuid.uuid4', mock.MagicMock(return_value='uuid'))
@mock.patch('uuid.uuid4', mock.MagicMock(spec_set=[], return_value='uuid'))
def test_prepare_image_with_configdrive(self):
self.client._command = mock.Mock()
self.client._command = mock.MagicMock(spec_set=[])
configdrive_url = 'http://swift/configdrive'
self.node.instance_info['configdrive'] = configdrive_url
image_info = {'image_id': 'image'}
@@ -155,9 +156,9 @@ class TestAgentClient(base.TestCase):
params=params,
wait=False)
@mock.patch('uuid.uuid4', mock.MagicMock(return_value='uuid'))
@mock.patch('uuid.uuid4', mock.MagicMock(spec_set=[], return_value='uuid'))
def test_start_iscsi_target(self):
self.client._command = mock.Mock()
self.client._command = mock.MagicMock(spec_set=[])
iqn = 'fake-iqn'
params = {'iqn': iqn}
@@ -167,9 +168,9 @@ class TestAgentClient(base.TestCase):
params=params,
wait=True)
@mock.patch('uuid.uuid4', mock.MagicMock(return_value='uuid'))
@mock.patch('uuid.uuid4', mock.MagicMock(spec_set=[], return_value='uuid'))
def test_install_bootloader(self):
self.client._command = mock.Mock()
self.client._command = mock.MagicMock(spec_set=[])
root_uuid = 'fake-root-uuid'
efi_system_part_uuid = 'fake-efi-system-part-uuid'
params = {'root_uuid': root_uuid,
@@ -182,7 +183,7 @@ class TestAgentClient(base.TestCase):
wait=True)
def test_get_clean_steps(self):
self.client._command = mock.Mock()
self.client._command = mock.MagicMock(spec_set=[])
ports = []
expected_params = {
'node': self.node.as_dict(),
@@ -197,7 +198,7 @@ class TestAgentClient(base.TestCase):
wait=True)
def test_execute_clean_step(self):
self.client._command = mock.Mock()
self.client._command = mock.MagicMock(spec_set=[])
ports = []
step = {'priority': 10, 'step': 'erase_devices', 'interface': 'deploy'}
expected_params = {
+11 -10
View File
@@ -53,22 +53,23 @@ class PassthruDecoratorTestCase(base.TestCase):
def setUp(self):
super(PassthruDecoratorTestCase, self).setUp()
self.fvi = FakeVendorInterface()
driver_base.LOG = mock.Mock()
def test_passthru_noexception(self):
result = self.fvi.noexception()
self.assertEqual("Fake", result)
def test_passthru_ironicexception(self):
@mock.patch.object(driver_base, 'LOG', autospec=True)
def test_passthru_ironicexception(self, mock_log):
self.assertRaises(exception.IronicException,
self.fvi.ironicexception, mock.ANY)
driver_base.LOG.exception.assert_called_with(
mock_log.exception.assert_called_with(
mock.ANY, 'ironicexception')
def test_passthru_nonironicexception(self):
@mock.patch.object(driver_base, 'LOG', autospec=True)
def test_passthru_nonironicexception(self, mock_log):
self.assertRaises(exception.VendorPassthruException,
self.fvi.normalexception, mock.ANY)
driver_base.LOG.exception.assert_called_with(
mock_log.exception.assert_called_with(
mock.ANY, 'normalexception')
def test_passthru_check_func_references(self):
@@ -81,12 +82,12 @@ class PassthruDecoratorTestCase(base.TestCase):
inst2.driver_routes['driver_noexception']['func'])
@mock.patch.object(eventlet.greenthread, 'spawn_n',
@mock.patch.object(eventlet.greenthread, 'spawn_n', autospec=True,
side_effect=lambda func, *args, **kw: func(*args, **kw))
class DriverPeriodicTaskTestCase(base.TestCase):
def test(self, spawn_mock):
method_mock = mock.Mock()
function_mock = mock.Mock()
method_mock = mock.MagicMock(spec_set=[])
function_mock = mock.MagicMock(spec_set=[])
class TestClass(object):
@driver_base.driver_periodic_task(spacing=42)
@@ -118,8 +119,8 @@ class CleanStepTestCase(base.TestCase):
# Create a fake Driver class, create some clean steps, make sure
# they are listed correctly, and attempt to execute one of them
method_mock = mock.Mock()
task_mock = mock.Mock()
method_mock = mock.MagicMock(spec_set=[])
task_mock = mock.MagicMock(spec_set=[])
class TestClass(driver_base.BaseInterface):
interface_type = 'test'
+83 -61
View File
@@ -21,6 +21,7 @@ import shutil
import stat
import tempfile
import time
import types
import mock
from oslo_concurrency import processutils
@@ -225,12 +226,14 @@ image=chain.c32
class PhysicalWorkTestCase(tests_base.TestCase):
def _mock_calls(self, name_list):
patch_list = [mock.patch.object(utils, name) for name in name_list]
patch_list = [mock.patch.object(utils, name,
spec_set=types.FunctionType)
for name in name_list]
mock_list = [patcher.start() for patcher in patch_list]
for patcher in patch_list:
self.addCleanup(patcher.stop)
parent_mock = mock.MagicMock()
parent_mock = mock.MagicMock(spec=[])
for mocker, name in zip(mock_list, name_list):
parent_mock.attach_mock(mocker, name)
return parent_mock
@@ -338,7 +341,7 @@ class PhysicalWorkTestCase(tests_base.TestCase):
# We mock utils.block_uuid separately here because we can't predict
# the order in which it will be called.
@mock.patch.object(utils, 'block_uuid')
@mock.patch.object(utils, 'block_uuid', autospec=True)
def test_deploy_partition_image_localboot_uefi(self, block_uuid_mock):
"""Check loosely all functions are called with right args."""
address = '127.0.0.1'
@@ -602,7 +605,7 @@ class PhysicalWorkTestCase(tests_base.TestCase):
self.assertFalse(parent_mock.get_dev_block_size.called)
self.assertEqual(root_uuid, uuid_dict_returned['root uuid'])
@mock.patch.object(common_utils, 'unlink_without_raise')
@mock.patch.object(common_utils, 'unlink_without_raise', autospec=True)
def test_deploy_partition_image_with_configdrive(self, mock_unlink):
"""Check loosely all functions are called with right args."""
address = '127.0.0.1'
@@ -668,7 +671,7 @@ class PhysicalWorkTestCase(tests_base.TestCase):
self.assertEqual(root_uuid, uuid_dict_returned['root uuid'])
mock_unlink.assert_called_once_with('configdrive-path')
@mock.patch.object(utils, 'get_disk_identifier')
@mock.patch.object(utils, 'get_disk_identifier', autospec=True)
def test_deploy_whole_disk_image(self, mock_gdi):
"""Check loosely all functions are called with right args."""
address = '127.0.0.1'
@@ -700,7 +703,7 @@ class PhysicalWorkTestCase(tests_base.TestCase):
self.assertEqual(calls_expected, parent_mock.mock_calls)
self.assertEqual('0x12345678', uuid_dict_returned['disk identifier'])
@mock.patch.object(common_utils, 'execute')
@mock.patch.object(common_utils, 'execute', autospec=True)
def test_verify_iscsi_connection_raises(self, mock_exec):
iqn = 'iqn.xyz'
mock_exec.return_value = ['iqn.abc', '']
@@ -708,7 +711,7 @@ class PhysicalWorkTestCase(tests_base.TestCase):
utils.verify_iscsi_connection, iqn)
self.assertEqual(3, mock_exec.call_count)
@mock.patch.object(os.path, 'exists')
@mock.patch.object(os.path, 'exists', autospec=True)
def test_check_file_system_for_iscsi_device_raises(self, mock_os):
iqn = 'iqn.xyz'
ip = "127.0.0.1"
@@ -718,7 +721,7 @@ class PhysicalWorkTestCase(tests_base.TestCase):
utils.check_file_system_for_iscsi_device, ip, port, iqn)
self.assertEqual(3, mock_os.call_count)
@mock.patch.object(os.path, 'exists')
@mock.patch.object(os.path, 'exists', autospec=True)
def test_check_file_system_for_iscsi_device(self, mock_os):
iqn = 'iqn.xyz'
ip = "127.0.0.1"
@@ -731,7 +734,7 @@ class PhysicalWorkTestCase(tests_base.TestCase):
utils.check_file_system_for_iscsi_device(ip, port, iqn)
mock_os.assert_called_once_with(check_dir)
@mock.patch.object(common_utils, 'execute')
@mock.patch.object(common_utils, 'execute', autospec=True)
def test_verify_iscsi_connection(self, mock_exec):
iqn = 'iqn.xyz'
mock_exec.return_value = ['iqn.xyz', '']
@@ -742,7 +745,7 @@ class PhysicalWorkTestCase(tests_base.TestCase):
run_as_root=True,
check_exit_code=[0])
@mock.patch.object(common_utils, 'execute')
@mock.patch.object(common_utils, 'execute', autospec=True)
def test_force_iscsi_lun_update(self, mock_exec):
iqn = 'iqn.xyz'
utils.force_iscsi_lun_update(iqn)
@@ -753,10 +756,11 @@ class PhysicalWorkTestCase(tests_base.TestCase):
run_as_root=True,
check_exit_code=[0])
@mock.patch.object(common_utils, 'execute')
@mock.patch.object(utils, 'verify_iscsi_connection')
@mock.patch.object(utils, 'force_iscsi_lun_update')
@mock.patch.object(utils, 'check_file_system_for_iscsi_device')
@mock.patch.object(common_utils, 'execute', autospec=True)
@mock.patch.object(utils, 'verify_iscsi_connection', autospec=True)
@mock.patch.object(utils, 'force_iscsi_lun_update', autospec=True)
@mock.patch.object(utils, 'check_file_system_for_iscsi_device',
autospec=True)
def test_login_iscsi_calls_verify_and_update(self,
mock_check_dev,
mock_update,
@@ -809,12 +813,14 @@ class PhysicalWorkTestCase(tests_base.TestCase):
name_list = ['get_dev', 'get_image_mb', 'discovery', 'login_iscsi',
'logout_iscsi', 'delete_iscsi', 'work_on_disk']
patch_list = [mock.patch.object(utils, name) for name in name_list]
patch_list = [mock.patch.object(utils, name,
spec_set=types.FunctionType)
for name in name_list]
mock_list = [patcher.start() for patcher in patch_list]
for patcher in patch_list:
self.addCleanup(patcher.stop)
parent_mock = mock.MagicMock()
parent_mock = mock.MagicMock(spec=[])
for mocker, name in zip(mock_list, name_list):
parent_mock.attach_mock(mocker, name)
@@ -938,8 +944,8 @@ class OtherFunctionTestCase(db_base.DbTestCase):
actual = utils.get_dev('1.2.3.4', 5678, 'iqn.fake', 9)
self.assertEqual(expected, actual)
@mock.patch.object(os, 'stat')
@mock.patch.object(stat, 'S_ISBLK')
@mock.patch.object(os, 'stat', autospec=True)
@mock.patch.object(stat, 'S_ISBLK', autospec=True)
def test_is_block_device_works(self, mock_is_blk, mock_os):
device = '/dev/disk/by-path/ip-1.2.3.4:5678-iscsi-iqn.fake-lun-9'
mock_is_blk.return_value = True
@@ -947,7 +953,7 @@ class OtherFunctionTestCase(db_base.DbTestCase):
self.assertTrue(utils.is_block_device(device))
mock_is_blk.assert_called_once_with(mock_os().st_mode)
@mock.patch.object(os, 'stat')
@mock.patch.object(os, 'stat', autospec=True)
def test_is_block_device_raises(self, mock_os):
device = '/dev/disk/by-path/ip-1.2.3.4:5678-iscsi-iqn.fake-lun-9'
mock_os.side_effect = OSError
@@ -955,8 +961,8 @@ class OtherFunctionTestCase(db_base.DbTestCase):
utils.is_block_device, device)
mock_os.assert_has_calls([mock.call(device)] * 3)
@mock.patch.object(os.path, 'getsize')
@mock.patch.object(images, 'converted_size')
@mock.patch.object(os.path, 'getsize', autospec=True)
@mock.patch.object(images, 'converted_size', autospec=True)
def test_get_image_mb(self, mock_csize, mock_getsize):
mb = 1024 * 1024
@@ -1088,8 +1094,8 @@ class WorkOnDiskTestCase(tests_base.TestCase):
boot_option="netboot",
boot_mode="bios")
@mock.patch.object(common_utils, 'unlink_without_raise')
@mock.patch.object(utils, '_get_configdrive')
@mock.patch.object(common_utils, 'unlink_without_raise', autospec=True)
@mock.patch.object(utils, '_get_configdrive', autospec=True)
def test_no_configdrive_partition(self, mock_configdrive, mock_unlink):
mock_configdrive.return_value = (10, 'fake-path')
swap_part = '/dev/fake-part1'
@@ -1121,7 +1127,7 @@ class WorkOnDiskTestCase(tests_base.TestCase):
mock_unlink.assert_called_once_with('fake-path')
@mock.patch.object(common_utils, 'execute')
@mock.patch.object(common_utils, 'execute', autospec=True)
class MakePartitionsTestCase(tests_base.TestCase):
def setUp(self):
@@ -1172,8 +1178,8 @@ class MakePartitionsTestCase(tests_base.TestCase):
mock_exc.assert_has_calls([parted_call])
@mock.patch.object(utils, 'get_dev_block_size')
@mock.patch.object(common_utils, 'execute')
@mock.patch.object(utils, 'get_dev_block_size', autospec=True)
@mock.patch.object(common_utils, 'execute', autospec=True)
class DestroyMetaDataTestCase(tests_base.TestCase):
def setUp(self):
@@ -1220,7 +1226,7 @@ class DestroyMetaDataTestCase(tests_base.TestCase):
self.assertFalse(mock_gz.called)
@mock.patch.object(common_utils, 'execute')
@mock.patch.object(common_utils, 'execute', autospec=True)
class GetDeviceBlockSizeTestCase(tests_base.TestCase):
def setUp(self):
@@ -1236,9 +1242,9 @@ class GetDeviceBlockSizeTestCase(tests_base.TestCase):
mock_exec.assert_has_calls(expected_call)
@mock.patch.object(utils, 'dd')
@mock.patch.object(images, 'qemu_img_info')
@mock.patch.object(images, 'convert_image')
@mock.patch.object(utils, 'dd', autospec=True)
@mock.patch.object(images, 'qemu_img_info', autospec=True)
@mock.patch.object(images, 'convert_image', autospec=True)
class PopulateImageTestCase(tests_base.TestCase):
def setUp(self):
@@ -1334,10 +1340,11 @@ class RealFilePartitioningTestCase(tests_base.TestCase):
"unexpected partitioning %s" % part_table)
self.assertIn(sizes[2], (9, 10))
@mock.patch.object(image_cache, 'clean_up_caches')
@mock.patch.object(image_cache, 'clean_up_caches', autospec=True)
def test_fetch_images(self, mock_clean_up_caches):
mock_cache = mock.MagicMock(master_dir='master_dir')
mock_cache = mock.MagicMock(
spec_set=['fetch_image', 'master_dir'], master_dir='master_dir')
utils.fetch_images(None, mock_cache, [('uuid', 'path')])
mock_clean_up_caches.assert_called_once_with(None, 'master_dir',
[('uuid', 'path')])
@@ -1345,15 +1352,16 @@ class RealFilePartitioningTestCase(tests_base.TestCase):
ctx=None,
force_raw=True)
@mock.patch.object(image_cache, 'clean_up_caches')
@mock.patch.object(image_cache, 'clean_up_caches', autospec=True)
def test_fetch_images_fail(self, mock_clean_up_caches):
exc = exception.InsufficientDiskSpace(path='a',
required=2,
actual=1)
mock_cache = mock.MagicMock(master_dir='master_dir')
mock_clean_up_caches.side_effect = [exc]
mock_cache = mock.MagicMock(
spec_set=['master_dir'], master_dir='master_dir')
mock_clean_up_caches.side_effect = iter([exc])
self.assertRaises(exception.InstanceDeployFailure,
utils.fetch_images,
None,
@@ -1363,20 +1371,21 @@ class RealFilePartitioningTestCase(tests_base.TestCase):
[('uuid', 'path')])
@mock.patch.object(shutil, 'copyfileobj')
@mock.patch.object(requests, 'get')
@mock.patch.object(shutil, 'copyfileobj', autospec=True)
@mock.patch.object(requests, 'get', autospec=True)
class GetConfigdriveTestCase(tests_base.TestCase):
@mock.patch.object(gzip, 'GzipFile')
@mock.patch.object(gzip, 'GzipFile', autospec=True)
def test_get_configdrive(self, mock_gzip, mock_requests, mock_copy):
mock_requests.return_value = mock.MagicMock(content='Zm9vYmFy')
mock_requests.return_value = mock.MagicMock(
spec_set=['content'], content='Zm9vYmFy')
utils._get_configdrive('http://1.2.3.4/cd', 'fake-node-uuid')
mock_requests.assert_called_once_with('http://1.2.3.4/cd')
mock_gzip.assert_called_once_with('configdrive', 'rb',
fileobj=mock.ANY)
mock_copy.assert_called_once_with(mock.ANY, mock.ANY)
@mock.patch.object(gzip, 'GzipFile')
@mock.patch.object(gzip, 'GzipFile', autospec=True)
def test_get_configdrive_base64_string(self, mock_gzip, mock_requests,
mock_copy):
utils._get_configdrive('Zm9vYmFy', 'fake-node-uuid')
@@ -1392,7 +1401,7 @@ class GetConfigdriveTestCase(tests_base.TestCase):
'fake-node-uuid')
self.assertFalse(mock_copy.called)
@mock.patch.object(base64, 'b64decode')
@mock.patch.object(base64, 'b64decode', autospec=True)
def test_get_configdrive_base64_error(self, mock_b64, mock_requests,
mock_copy):
mock_b64.side_effect = TypeError
@@ -1402,10 +1411,11 @@ class GetConfigdriveTestCase(tests_base.TestCase):
mock_b64.assert_called_once_with('malformed')
self.assertFalse(mock_copy.called)
@mock.patch.object(gzip, 'GzipFile')
@mock.patch.object(gzip, 'GzipFile', autospec=True)
def test_get_configdrive_gzip_error(self, mock_gzip, mock_requests,
mock_copy):
mock_requests.return_value = mock.MagicMock(content='Zm9vYmFy')
mock_requests.return_value = mock.MagicMock(
spec_set=['content'], content='Zm9vYmFy')
mock_copy.side_effect = IOError
self.assertRaises(exception.InstanceDeployFailure,
utils._get_configdrive, 'http://1.2.3.4/cd',
@@ -1499,7 +1509,7 @@ class TrySetBootDeviceTestCase(db_base.DbTestCase):
mgr_utils.mock_the_extension_manager(driver="fake")
self.node = obj_utils.create_test_node(self.context, driver="fake")
@mock.patch.object(manager_utils, 'node_set_boot_device')
@mock.patch.object(manager_utils, 'node_set_boot_device', autospec=True)
def test_try_set_boot_device_okay(self, node_set_boot_device_mock):
with task_manager.acquire(self.context, self.node.uuid,
shared=False) as task:
@@ -1508,8 +1518,8 @@ class TrySetBootDeviceTestCase(db_base.DbTestCase):
node_set_boot_device_mock.assert_called_once_with(
task, boot_devices.DISK, persistent=True)
@mock.patch.object(utils, 'LOG')
@mock.patch.object(manager_utils, 'node_set_boot_device')
@mock.patch.object(utils, 'LOG', autospec=True)
@mock.patch.object(manager_utils, 'node_set_boot_device', autospec=True)
def test_try_set_boot_device_ipmifailure_uefi(self,
node_set_boot_device_mock, log_mock):
self.node.properties = {'capabilities': 'boot_mode:uefi'}
@@ -1523,7 +1533,7 @@ class TrySetBootDeviceTestCase(db_base.DbTestCase):
task, boot_devices.DISK, persistent=True)
log_mock.warning.assert_called_once_with(mock.ANY)
@mock.patch.object(manager_utils, 'node_set_boot_device')
@mock.patch.object(manager_utils, 'node_set_boot_device', autospec=True)
def test_try_set_boot_device_ipmifailure_bios(
self, node_set_boot_device_mock):
node_set_boot_device_mock.side_effect = exception.IPMIFailure(cmd='a')
@@ -1535,7 +1545,7 @@ class TrySetBootDeviceTestCase(db_base.DbTestCase):
node_set_boot_device_mock.assert_called_once_with(
task, boot_devices.DISK, persistent=True)
@mock.patch.object(manager_utils, 'node_set_boot_device')
@mock.patch.object(manager_utils, 'node_set_boot_device', autospec=True)
def test_try_set_boot_device_some_other_exception(
self, node_set_boot_device_mock):
exc = exception.IloOperationError(operation="qwe", error="error")
@@ -1579,8 +1589,10 @@ class AgentCleaningTestCase(db_base.DbTestCase):
}
}
@mock.patch('ironic.objects.Port.list_by_node_id')
@mock.patch.object(agent_client.AgentClient, 'get_clean_steps')
@mock.patch('ironic.objects.Port.list_by_node_id',
spec_set=types.FunctionType)
@mock.patch.object(agent_client.AgentClient, 'get_clean_steps',
autospec=True)
def test_get_clean_steps(self, client_mock, list_ports_mock):
client_mock.return_value = {
'command_result': self.clean_steps}
@@ -1589,7 +1601,8 @@ class AgentCleaningTestCase(db_base.DbTestCase):
with task_manager.acquire(
self.context, self.node['uuid'], shared=False) as task:
response = utils.agent_get_clean_steps(task)
client_mock.assert_called_once_with(task.node, self.ports)
client_mock.assert_called_once_with(mock.ANY, task.node,
self.ports)
self.assertEqual('1', task.node.driver_internal_info[
'hardware_manager_version'])
@@ -1601,8 +1614,10 @@ class AgentCleaningTestCase(db_base.DbTestCase):
self.assertIn(self.clean_steps['clean_steps'][
'SpecificHardwareManager'][0], response)
@mock.patch('ironic.objects.Port.list_by_node_id')
@mock.patch.object(agent_client.AgentClient, 'get_clean_steps')
@mock.patch('ironic.objects.Port.list_by_node_id',
spec_set=types.FunctionType)
@mock.patch.object(agent_client.AgentClient, 'get_clean_steps',
autospec=True)
def test_get_clean_steps_missing_steps(self, client_mock,
list_ports_mock):
del self.clean_steps['clean_steps']
@@ -1615,10 +1630,13 @@ class AgentCleaningTestCase(db_base.DbTestCase):
self.assertRaises(exception.NodeCleaningFailure,
utils.agent_get_clean_steps,
task)
client_mock.assert_called_once_with(task.node, self.ports)
client_mock.assert_called_once_with(mock.ANY, task.node,
self.ports)
@mock.patch('ironic.objects.Port.list_by_node_id')
@mock.patch.object(agent_client.AgentClient, 'execute_clean_step')
@mock.patch('ironic.objects.Port.list_by_node_id',
spec_set=types.FunctionType)
@mock.patch.object(agent_client.AgentClient, 'execute_clean_step',
autospec=True)
def test_execute_clean_step(self, client_mock, list_ports_mock):
client_mock.return_value = {
'command_status': 'SUCCEEDED'}
@@ -1631,8 +1649,10 @@ class AgentCleaningTestCase(db_base.DbTestCase):
self.clean_steps['clean_steps']['GenericHardwareManager'][0])
self.assertEqual(states.CLEANING, response)
@mock.patch('ironic.objects.Port.list_by_node_id')
@mock.patch.object(agent_client.AgentClient, 'execute_clean_step')
@mock.patch('ironic.objects.Port.list_by_node_id',
spec_set=types.FunctionType)
@mock.patch.object(agent_client.AgentClient, 'execute_clean_step',
autospec=True)
def test_execute_clean_step_running(self, client_mock, list_ports_mock):
client_mock.return_value = {
'command_status': 'RUNNING'}
@@ -1645,8 +1665,10 @@ class AgentCleaningTestCase(db_base.DbTestCase):
self.clean_steps['clean_steps']['GenericHardwareManager'][0])
self.assertEqual(states.CLEANING, response)
@mock.patch('ironic.objects.Port.list_by_node_id')
@mock.patch.object(agent_client.AgentClient, 'execute_clean_step')
@mock.patch('ironic.objects.Port.list_by_node_id',
spec_set=types.FunctionType)
@mock.patch.object(agent_client.AgentClient, 'execute_clean_step',
autospec=True)
def test_execute_clean_step_version_mismatch(self, client_mock,
list_ports_mock):
client_mock.return_value = {
@@ -1661,7 +1683,7 @@ class AgentCleaningTestCase(db_base.DbTestCase):
self.assertEqual(states.CLEANING, response)
@mock.patch.object(utils, 'is_block_device')
@mock.patch.object(utils, 'is_block_device', autospec=True)
@mock.patch.object(utils, 'login_iscsi', lambda *_: None)
@mock.patch.object(utils, 'discovery', lambda *_: None)
@mock.patch.object(utils, 'logout_iscsi', lambda *_: None)
+9 -9
View File
@@ -74,8 +74,8 @@ class BaseTestCase(db_base.DbTestCase):
mgr_utils.mock_the_extension_manager("fake_discoverd")
self.driver = driver_factory.get_driver("fake_discoverd")
self.node = obj_utils.get_test_node(self.context)
self.task = mock.Mock(spec=task_manager.TaskManager)
self.task.context = mock.Mock()
self.task = mock.MagicMock(spec=task_manager.TaskManager)
self.task.context = mock.MagicMock(spec_set=['auth_token'])
self.task.shared = False
self.task.node = self.node
self.task.driver = self.driver
@@ -93,7 +93,7 @@ class CommonFunctionsTestCase(BaseTestCase):
res = discoverd.DiscoverdInspect.create_if_enabled('driver')
self.assertIsInstance(res, discoverd.DiscoverdInspect)
@mock.patch.object(discoverd.LOG, 'info')
@mock.patch.object(discoverd.LOG, 'info', autospec=True)
def test_create_if_enabled_disabled(self, warn_mock):
self.config(enabled=False, group='discoverd')
res = discoverd.DiscoverdInspect.create_if_enabled('driver')
@@ -102,7 +102,7 @@ class CommonFunctionsTestCase(BaseTestCase):
@mock.patch.object(eventlet, 'spawn_n', lambda f, *a, **kw: f(*a, **kw))
@mock.patch.object(client, 'introspect')
@mock.patch.object(client, 'introspect', autospec=True)
class InspectHardwareTestCase(BaseTestCase):
def test_ok(self, mock_introspect):
self.assertEqual(states.INSPECTING,
@@ -120,7 +120,7 @@ class InspectHardwareTestCase(BaseTestCase):
auth_token=self.task.context.auth_token,
base_url='meow')
@mock.patch.object(task_manager, 'acquire')
@mock.patch.object(task_manager, 'acquire', autospec=True)
def test_error(self, mock_acquire, mock_introspect):
mock_introspect.side_effect = RuntimeError('boom')
self.driver.inspect.inspect_hardware(self.task)
@@ -133,7 +133,7 @@ class InspectHardwareTestCase(BaseTestCase):
@mock.patch.object(keystone, 'get_admin_auth_token', lambda: 'the token')
@mock.patch.object(client, 'get_status')
@mock.patch.object(client, 'get_status', autospec=True)
class CheckStatusTestCase(BaseTestCase):
def setUp(self):
super(CheckStatusTestCase, self).setUp()
@@ -195,11 +195,11 @@ class CheckStatusTestCase(BaseTestCase):
@mock.patch.object(discoverd, '_check_status', autospec=True)
class PeriodicTaskTestCase(BaseTestCase):
def test_ok(self, mock_check, mock_acquire):
mgr = mock.Mock(spec=['iter_nodes'])
mgr = mock.MagicMock(spec=['iter_nodes'])
mgr.iter_nodes.return_value = [('1', 'd1'), ('2', 'd2')]
tasks = [mock.sentinel.task1, mock.sentinel.task2]
mock_acquire.side_effect = (
mock.MagicMock(__enter__=mock.Mock(return_value=task))
mock.MagicMock(__enter__=mock.MagicMock(return_value=task))
for task in tasks
)
discoverd.DiscoverdInspect()._periodic_check_result(
@@ -209,7 +209,7 @@ class PeriodicTaskTestCase(BaseTestCase):
self.assertEqual(2, mock_acquire.call_count)
def test_node_locked(self, mock_check, mock_acquire):
mgr = mock.Mock(spec=['iter_nodes'])
mgr = mock.MagicMock(spec=['iter_nodes'])
mgr.iter_nodes.return_value = [('1', 'd1'), ('2', 'd2')]
mock_acquire.side_effect = exception.NodeLocked("boom")
discoverd.DiscoverdInspect()._periodic_check_result(
+1 -1
View File
@@ -37,7 +37,7 @@ class FakeDriverTestCase(db_base.DbTestCase):
mgr_utils.mock_the_extension_manager()
self.driver = driver_factory.get_driver("fake")
self.node = obj_utils.get_test_node(self.context)
self.task = mock.Mock(spec=task_manager.TaskManager)
self.task = mock.MagicMock(spec=task_manager.TaskManager)
self.task.shared = False
self.task.node = self.node
self.task.driver = self.driver
+29 -27
View File
@@ -17,6 +17,8 @@
"""Test class for iBoot PDU driver module."""
import types
import mock
from ironic.common import driver_factory
@@ -122,9 +124,9 @@ class IBootPrivateMethodTestCase(db_base.DbTestCase):
iboot._parse_driver_info,
node)
@mock.patch.object(iboot, '_get_connection')
@mock.patch.object(iboot, '_get_connection', autospec=True)
def test__power_status_on(self, mock_get_conn):
mock_connection = mock.Mock()
mock_connection = mock.MagicMock(spec_set=['get_relays'])
mock_connection.get_relays.return_value = [True]
mock_get_conn.return_value = mock_connection
node = obj_utils.create_test_node(
@@ -139,9 +141,9 @@ class IBootPrivateMethodTestCase(db_base.DbTestCase):
mock_get_conn.assert_called_once_with(info)
mock_connection.get_relays.assert_called_once_with()
@mock.patch.object(iboot, '_get_connection')
@mock.patch.object(iboot, '_get_connection', autospec=True)
def test__power_status_off(self, mock_get_conn):
mock_connection = mock.Mock()
mock_connection = mock.MagicMock(spec_set=['get_relays'])
mock_connection.get_relays.return_value = [False]
mock_get_conn.return_value = mock_connection
node = obj_utils.create_test_node(
@@ -156,9 +158,9 @@ class IBootPrivateMethodTestCase(db_base.DbTestCase):
mock_get_conn.assert_called_once_with(info)
mock_connection.get_relays.assert_called_once_with()
@mock.patch.object(iboot, '_get_connection')
@mock.patch.object(iboot, '_get_connection', autospec=True)
def test__power_status_exception(self, mock_get_conn):
mock_connection = mock.Mock()
mock_connection = mock.MagicMock(spec_set=['get_relays'])
mock_connection.get_relays.return_value = None
mock_get_conn.return_value = mock_connection
node = obj_utils.create_test_node(
@@ -174,9 +176,9 @@ class IBootPrivateMethodTestCase(db_base.DbTestCase):
mock_get_conn.assert_called_once_with(info)
mock_connection.get_relays.assert_called_once_with()
@mock.patch.object(iboot, '_get_connection')
@mock.patch.object(iboot, '_get_connection', autospec=True)
def test__power_status_exception_type_error(self, mock_get_conn):
mock_connection = mock.Mock()
mock_connection = mock.MagicMock(spec_set=['get_relays'])
side_effect = TypeError("Surprise!")
mock_connection.get_relays.side_effect = side_effect
@@ -194,9 +196,9 @@ class IBootPrivateMethodTestCase(db_base.DbTestCase):
mock_get_conn.assert_called_once_with(info)
mock_connection.get_relays.assert_called_once_with()
@mock.patch.object(iboot, '_get_connection')
@mock.patch.object(iboot, '_get_connection', autospec=True)
def test__power_status_exception_index_error(self, mock_get_conn):
mock_connection = mock.Mock()
mock_connection = mock.MagicMock(spec_set=['get_relays'])
side_effect = IndexError("Gotcha!")
mock_connection.get_relays.side_effect = side_effect
@@ -212,9 +214,9 @@ class IBootPrivateMethodTestCase(db_base.DbTestCase):
mock_get_conn.assert_called_once_with(info)
mock_connection.get_relays.assert_called_once_with()
@mock.patch.object(iboot, '_get_connection')
@mock.patch.object(iboot, '_get_connection', autospec=True)
def test__power_status_error(self, mock_get_conn):
mock_connection = mock.Mock()
mock_connection = mock.MagicMock(spec_set=['get_relays'])
mock_connection.get_relays.return_value = list()
mock_get_conn.return_value = mock_connection
node = obj_utils.create_test_node(
@@ -248,8 +250,8 @@ class IBootDriverTestCase(db_base.DbTestCase):
shared=True) as task:
self.assertEqual(expected, task.driver.get_properties())
@mock.patch.object(iboot, '_power_status')
@mock.patch.object(iboot, '_switch')
@mock.patch.object(iboot, '_power_status', autospec=True)
@mock.patch.object(iboot, '_switch', autospec=True)
def test_set_power_state_good(self, mock_switch, mock_power_status):
mock_power_status.return_value = states.POWER_ON
@@ -260,8 +262,8 @@ class IBootDriverTestCase(db_base.DbTestCase):
mock_switch.assert_called_once_with(self.info, True)
mock_power_status.assert_called_once_with(self.info)
@mock.patch.object(iboot, '_power_status')
@mock.patch.object(iboot, '_switch')
@mock.patch.object(iboot, '_power_status', autospec=True)
@mock.patch.object(iboot, '_switch', autospec=True)
def test_set_power_state_bad(self, mock_switch, mock_power_status):
mock_power_status.return_value = states.POWER_OFF
@@ -274,8 +276,8 @@ class IBootDriverTestCase(db_base.DbTestCase):
mock_switch.assert_called_once_with(self.info, True)
mock_power_status.assert_called_once_with(self.info)
@mock.patch.object(iboot, '_power_status')
@mock.patch.object(iboot, '_switch')
@mock.patch.object(iboot, '_power_status', autospec=True)
@mock.patch.object(iboot, '_switch', autospec=True)
def test_set_power_state_invalid_parameter(self, mock_switch,
mock_power_status):
mock_power_status.return_value = states.POWER_ON
@@ -285,10 +287,10 @@ class IBootDriverTestCase(db_base.DbTestCase):
task.driver.power.set_power_state,
task, states.NOSTATE)
@mock.patch.object(iboot, '_power_status')
@mock.patch.object(iboot, '_switch')
@mock.patch.object(iboot, '_power_status', autospec=True)
@mock.patch.object(iboot, '_switch', spec_set=types.FunctionType)
def test_reboot_good(self, mock_switch, mock_power_status):
manager = mock.MagicMock()
manager = mock.MagicMock(spec_set=['switch'])
mock_power_status.return_value = states.POWER_ON
manager.attach_mock(mock_switch, 'switch')
@@ -300,10 +302,10 @@ class IBootDriverTestCase(db_base.DbTestCase):
self.assertEqual(manager.mock_calls, expected)
@mock.patch.object(iboot, '_power_status')
@mock.patch.object(iboot, '_switch')
@mock.patch.object(iboot, '_power_status', autospec=True)
@mock.patch.object(iboot, '_switch', spec_set=types.FunctionType)
def test_reboot_bad(self, mock_switch, mock_power_status):
manager = mock.MagicMock()
manager = mock.MagicMock(spec_set=['switch'])
mock_power_status.return_value = states.POWER_OFF
manager.attach_mock(mock_switch, 'switch')
@@ -316,7 +318,7 @@ class IBootDriverTestCase(db_base.DbTestCase):
self.assertEqual(manager.mock_calls, expected)
@mock.patch.object(iboot, '_power_status')
@mock.patch.object(iboot, '_power_status', autospec=True)
def test_get_power_state(self, mock_power_status):
mock_power_status.return_value = states.POWER_ON
@@ -327,14 +329,14 @@ class IBootDriverTestCase(db_base.DbTestCase):
# ensure functions were called with the valid parameters
mock_power_status.assert_called_once_with(self.info)
@mock.patch.object(iboot, '_parse_driver_info')
@mock.patch.object(iboot, '_parse_driver_info', autospec=True)
def test_validate_good(self, parse_drv_info_mock):
with task_manager.acquire(self.context, self.node.uuid,
shared=True) as task:
task.driver.power.validate(task)
self.assertEqual(1, parse_drv_info_mock.call_count)
@mock.patch.object(iboot, '_parse_driver_info')
@mock.patch.object(iboot, '_parse_driver_info', autospec=True)
def test_validate_fails(self, parse_drv_info_mock):
side_effect = exception.InvalidParameterValue("Bad input")
parse_drv_info_mock.side_effect = side_effect
+94 -70
View File
@@ -37,7 +37,7 @@ def touch(filename):
open(filename, 'w').close()
@mock.patch.object(image_cache, '_fetch')
@mock.patch.object(image_cache, '_fetch', autospec=True)
class TestImageCacheFetch(base.TestCase):
def setUp(self):
@@ -49,8 +49,9 @@ class TestImageCacheFetch(base.TestCase):
self.uuid = uuidutils.generate_uuid()
self.master_path = os.path.join(self.master_dir, self.uuid)
@mock.patch.object(image_cache.ImageCache, 'clean_up')
@mock.patch.object(image_cache.ImageCache, '_download_image')
@mock.patch.object(image_cache.ImageCache, 'clean_up', autospec=True)
@mock.patch.object(image_cache.ImageCache, '_download_image',
autospec=True)
def test_fetch_image_no_master_dir(self, mock_download, mock_clean_up,
mock_fetch):
self.cache.master_dir = None
@@ -60,9 +61,10 @@ class TestImageCacheFetch(base.TestCase):
None, self.uuid, self.dest_path, None, True)
self.assertFalse(mock_clean_up.called)
@mock.patch.object(os, 'unlink')
@mock.patch.object(image_cache.ImageCache, 'clean_up')
@mock.patch.object(image_cache.ImageCache, '_download_image')
@mock.patch.object(os, 'unlink', autospec=True)
@mock.patch.object(image_cache.ImageCache, 'clean_up', autospec=True)
@mock.patch.object(image_cache.ImageCache, '_download_image',
autospec=True)
def test_fetch_image_dest_and_master_exist_uptodate(self, mock_download,
mock_clean_up, mock_unlink, mock_fetch):
touch(self.master_path)
@@ -73,8 +75,9 @@ class TestImageCacheFetch(base.TestCase):
self.assertFalse(mock_fetch.called)
self.assertFalse(mock_clean_up.called)
@mock.patch.object(image_cache.ImageCache, 'clean_up')
@mock.patch.object(image_cache.ImageCache, '_download_image')
@mock.patch.object(image_cache.ImageCache, 'clean_up', autospec=True)
@mock.patch.object(image_cache.ImageCache, '_download_image',
autospec=True)
def test_fetch_image_dest_and_master_exist_outdated(self, mock_download,
mock_clean_up, mock_fetch):
touch(self.master_path)
@@ -89,9 +92,10 @@ class TestImageCacheFetch(base.TestCase):
os.stat(self.master_path).st_ino)
self.assertFalse(mock_clean_up.called)
@mock.patch.object(os, 'unlink')
@mock.patch.object(image_cache.ImageCache, 'clean_up')
@mock.patch.object(image_cache.ImageCache, '_download_image')
@mock.patch.object(os, 'unlink', autospec=True)
@mock.patch.object(image_cache.ImageCache, 'clean_up', autospec=True)
@mock.patch.object(image_cache.ImageCache, '_download_image',
autospec=True)
def test_fetch_image_only_dest_exists(self, mock_download,
mock_clean_up, mock_unlink, mock_fetch):
touch(self.dest_path)
@@ -99,12 +103,13 @@ class TestImageCacheFetch(base.TestCase):
mock_unlink.assert_called_once_with(self.dest_path)
self.assertFalse(mock_fetch.called)
mock_download.assert_called_once_with(
self.uuid, self.master_path, self.dest_path,
self.cache, self.uuid, self.master_path, self.dest_path,
ctx=None, force_raw=True)
self.assertTrue(mock_clean_up.called)
@mock.patch.object(image_cache.ImageCache, 'clean_up')
@mock.patch.object(image_cache.ImageCache, '_download_image')
@mock.patch.object(image_cache.ImageCache, 'clean_up', autospec=True)
@mock.patch.object(image_cache.ImageCache, '_download_image',
autospec=True)
def test_fetch_image_master_exists(self, mock_download, mock_clean_up,
mock_fetch):
touch(self.master_path)
@@ -116,19 +121,21 @@ class TestImageCacheFetch(base.TestCase):
os.stat(self.master_path).st_ino)
self.assertFalse(mock_clean_up.called)
@mock.patch.object(image_cache.ImageCache, 'clean_up')
@mock.patch.object(image_cache.ImageCache, '_download_image')
@mock.patch.object(image_cache.ImageCache, 'clean_up', autospec=True)
@mock.patch.object(image_cache.ImageCache, '_download_image',
autospec=True)
def test_fetch_image(self, mock_download, mock_clean_up,
mock_fetch):
self.cache.fetch_image(self.uuid, self.dest_path)
self.assertFalse(mock_fetch.called)
mock_download.assert_called_once_with(
self.uuid, self.master_path, self.dest_path,
self.cache, self.uuid, self.master_path, self.dest_path,
ctx=None, force_raw=True)
self.assertTrue(mock_clean_up.called)
@mock.patch.object(image_cache.ImageCache, 'clean_up')
@mock.patch.object(image_cache.ImageCache, '_download_image')
@mock.patch.object(image_cache.ImageCache, 'clean_up', autospec=True)
@mock.patch.object(image_cache.ImageCache, '_download_image',
autospec=True)
def test_fetch_image_not_uuid(self, mock_download, mock_clean_up,
mock_fetch):
href = u'http://abc.com/ubuntu.qcow2'
@@ -138,7 +145,7 @@ class TestImageCacheFetch(base.TestCase):
self.cache.fetch_image(href, self.dest_path)
self.assertFalse(mock_fetch.called)
mock_download.assert_called_once_with(
href, master_path, self.dest_path,
self.cache, href, master_path, self.dest_path,
ctx=None, force_raw=True)
self.assertTrue(mock_clean_up.called)
@@ -169,7 +176,8 @@ class TestImageCacheCleanUp(base.TestCase):
cache_size=10,
cache_ttl=600)
@mock.patch.object(image_cache.ImageCache, '_clean_up_ensure_cache_size')
@mock.patch.object(image_cache.ImageCache, '_clean_up_ensure_cache_size',
autospec=True)
def test_clean_up_old_deleted(self, mock_clean_size):
mock_clean_size.return_value = None
files = [os.path.join(self.master_dir, str(i))
@@ -182,8 +190,8 @@ class TestImageCacheCleanUp(base.TestCase):
with mock.patch.object(time, 'time', lambda: new_current_time):
self.cache.clean_up()
mock_clean_size.assert_called_once_with(mock.ANY, None)
survived = mock_clean_size.call_args[0][0]
mock_clean_size.assert_called_once_with(self.cache, mock.ANY, None)
survived = mock_clean_size.call_args[0][1]
self.assertEqual(1, len(survived))
self.assertEqual(files[0], survived[0][0])
# NOTE(dtantsur): do not compare milliseconds
@@ -191,7 +199,8 @@ class TestImageCacheCleanUp(base.TestCase):
self.assertEqual(int(new_current_time - 100),
int(survived[0][2].st_mtime))
@mock.patch.object(image_cache.ImageCache, '_clean_up_ensure_cache_size')
@mock.patch.object(image_cache.ImageCache, '_clean_up_ensure_cache_size',
autospec=True)
def test_clean_up_old_with_amount(self, mock_clean_size):
files = [os.path.join(self.master_dir, str(i))
for i in range(2)]
@@ -206,7 +215,8 @@ class TestImageCacheCleanUp(base.TestCase):
self.assertTrue(any(os.path.exists(f) for f in files))
self.assertFalse(all(os.path.exists(f) for f in files))
@mock.patch.object(image_cache.ImageCache, '_clean_up_ensure_cache_size')
@mock.patch.object(image_cache.ImageCache, '_clean_up_ensure_cache_size',
autospec=True)
def test_clean_up_files_with_links_untouched(self, mock_clean_size):
mock_clean_size.return_value = None
files = [os.path.join(self.master_dir, str(i))
@@ -221,11 +231,12 @@ class TestImageCacheCleanUp(base.TestCase):
for filename in files:
self.assertTrue(os.path.exists(filename))
mock_clean_size.assert_called_once_with([], None)
mock_clean_size.assert_called_once_with(mock.ANY, [], None)
@mock.patch.object(image_cache.ImageCache, '_clean_up_too_old')
@mock.patch.object(image_cache.ImageCache, '_clean_up_too_old',
autospec=True)
def test_clean_up_ensure_cache_size(self, mock_clean_ttl):
mock_clean_ttl.side_effect = lambda *xx: xx
mock_clean_ttl.side_effect = lambda *xx: xx[1:]
# NOTE(dtantsur): Cache size in test is 10 bytes, we create 6 files
# with 3 bytes each and expect 3 to be deleted
files = [os.path.join(self.master_dir, str(i))
@@ -247,11 +258,12 @@ class TestImageCacheCleanUp(base.TestCase):
for filename in files[3:]:
self.assertFalse(os.path.exists(filename))
mock_clean_ttl.assert_called_once_with(mock.ANY, None)
mock_clean_ttl.assert_called_once_with(mock.ANY, mock.ANY, None)
@mock.patch.object(image_cache.ImageCache, '_clean_up_too_old')
@mock.patch.object(image_cache.ImageCache, '_clean_up_too_old',
autospec=True)
def test_clean_up_ensure_cache_size_with_amount(self, mock_clean_ttl):
mock_clean_ttl.side_effect = lambda *xx: xx
mock_clean_ttl.side_effect = lambda *xx: xx[1:]
# NOTE(dtantsur): Cache size in test is 10 bytes, we create 6 files
# with 3 bytes each and set amount to be 15, 5 files are to be deleted
files = [os.path.join(self.master_dir, str(i))
@@ -271,12 +283,13 @@ class TestImageCacheCleanUp(base.TestCase):
for filename in files[5:]:
self.assertFalse(os.path.exists(filename))
mock_clean_ttl.assert_called_once_with(mock.ANY, 15)
mock_clean_ttl.assert_called_once_with(mock.ANY, mock.ANY, 15)
@mock.patch.object(image_cache.LOG, 'info')
@mock.patch.object(image_cache.ImageCache, '_clean_up_too_old')
@mock.patch.object(image_cache.LOG, 'info', autospec=True)
@mock.patch.object(image_cache.ImageCache, '_clean_up_too_old',
autospec=True)
def test_clean_up_cache_still_large(self, mock_clean_ttl, mock_log):
mock_clean_ttl.side_effect = lambda *xx: xx
mock_clean_ttl.side_effect = lambda *xx: xx[1:]
# NOTE(dtantsur): Cache size in test is 10 bytes, we create 2 files
# than cannot be deleted and expected this to be logged
files = [os.path.join(self.master_dir, str(i))
@@ -291,10 +304,10 @@ class TestImageCacheCleanUp(base.TestCase):
for filename in files:
self.assertTrue(os.path.exists(filename))
self.assertTrue(mock_log.called)
mock_clean_ttl.assert_called_once_with(mock.ANY, None)
mock_clean_ttl.assert_called_once_with(mock.ANY, mock.ANY, None)
@mock.patch.object(utils, 'rmtree_without_raise')
@mock.patch.object(image_cache, '_fetch')
@mock.patch.object(utils, 'rmtree_without_raise', autospec=True)
@mock.patch.object(image_cache, '_fetch', autospec=True)
def test_temp_images_not_cleaned(self, mock_fetch, mock_rmtree):
def _fake_fetch(ctx, uuid, tmp_path, *args):
with open(tmp_path, 'w') as fp:
@@ -310,8 +323,8 @@ class TestImageCacheCleanUp(base.TestCase):
self.cache._download_image('uuid', master_path, dest_path)
self.assertTrue(mock_rmtree.called)
@mock.patch.object(utils, 'rmtree_without_raise')
@mock.patch.object(image_cache, '_fetch')
@mock.patch.object(utils, 'rmtree_without_raise', autospec=True)
@mock.patch.object(image_cache, '_fetch', autospec=True)
def test_temp_dir_exception(self, mock_fetch, mock_rmtree):
mock_fetch.side_effect = exception.IronicException
self.assertRaises(exception.IronicException,
@@ -319,13 +332,15 @@ class TestImageCacheCleanUp(base.TestCase):
'uuid', 'fake', 'fake')
self.assertTrue(mock_rmtree.called)
@mock.patch.object(image_cache.LOG, 'warn')
@mock.patch.object(image_cache.ImageCache, '_clean_up_too_old')
@mock.patch.object(image_cache.ImageCache, '_clean_up_ensure_cache_size')
@mock.patch.object(image_cache.LOG, 'warn', autospec=True)
@mock.patch.object(image_cache.ImageCache, '_clean_up_too_old',
autospec=True)
@mock.patch.object(image_cache.ImageCache, '_clean_up_ensure_cache_size',
autospec=True)
def test_clean_up_amount_not_satisfied(self, mock_clean_size,
mock_clean_ttl, mock_log):
mock_clean_ttl.side_effect = lambda *xx: xx
mock_clean_size.side_effect = lambda listing, amount: amount
mock_clean_ttl.side_effect = lambda *xx: xx[1:]
mock_clean_size.side_effect = lambda self, listing, amount: amount
self.cache.clean_up(amount=15)
self.assertTrue(mock_log.called)
@@ -358,15 +373,15 @@ class TestImageCacheCleanUp(base.TestCase):
self.assertEqual(item_possibilities[0], third_item_actual)
@mock.patch.object(image_cache, '_cache_cleanup_list')
@mock.patch.object(os, 'statvfs')
@mock.patch.object(image_service, 'get_image_service')
@mock.patch.object(image_cache, '_cache_cleanup_list', autospec=True)
@mock.patch.object(os, 'statvfs', autospec=True)
@mock.patch.object(image_service, 'get_image_service', autospec=True)
class CleanupImageCacheTestCase(base.TestCase):
def setUp(self):
super(CleanupImageCacheTestCase, self).setUp()
self.mock_first_cache = mock.MagicMock()
self.mock_second_cache = mock.MagicMock()
self.mock_first_cache = mock.MagicMock(spec_set=[])
self.mock_second_cache = mock.MagicMock(spec_set=[])
self.cache_cleanup_list = [(50, self.mock_first_cache),
(20, self.mock_second_cache)]
self.mock_first_cache.return_value.master_dir = 'first_cache_dir'
@@ -377,7 +392,8 @@ class CleanupImageCacheTestCase(base.TestCase):
# Enough space found - no clean up
mock_show = mock_image_service.return_value.show
mock_show.return_value = dict(size=42)
mock_statvfs.return_value = mock.Mock(f_frsize=1, f_bavail=1024)
mock_statvfs.return_value = mock.MagicMock(
spec_set=['f_frsize', 'f_bavail'], f_frsize=1, f_bavail=1024)
cache_cleanup_list_mock.__iter__.return_value = self.cache_cleanup_list
@@ -390,7 +406,7 @@ class CleanupImageCacheTestCase(base.TestCase):
mock_statvfs.assert_called_once_with('master_dir')
@mock.patch.object(os, 'stat')
@mock.patch.object(os, 'stat', autospec=True)
def test_one_clean_up(self, mock_stat, mock_image_service, mock_statvfs,
cache_cleanup_list_mock):
# Not enough space, first cache clean up is enough
@@ -398,8 +414,10 @@ class CleanupImageCacheTestCase(base.TestCase):
mock_show = mock_image_service.return_value.show
mock_show.return_value = dict(size=42)
mock_statvfs.side_effect = [
mock.Mock(f_frsize=1, f_bavail=1),
mock.Mock(f_frsize=1, f_bavail=1024)
mock.MagicMock(f_frsize=1, f_bavail=1,
spec_set=['f_frsize', 'f_bavail']),
mock.MagicMock(f_frsize=1, f_bavail=1024,
spec_set=['f_frsize', 'f_bavail'])
]
cache_cleanup_list_mock.__iter__.return_value = self.cache_cleanup_list
image_cache.clean_up_caches(None, 'master_dir', [('uuid', 'path')])
@@ -421,18 +439,20 @@ class CleanupImageCacheTestCase(base.TestCase):
self.assertEqual(mock_stat_calls_expected, mock_stat.mock_calls)
self.assertEqual(mock_statvfs_calls_expected, mock_statvfs.mock_calls)
@mock.patch.object(os, 'stat')
@mock.patch.object(os, 'stat', autospec=True)
def test_clean_up_another_fs(self, mock_stat, mock_image_service,
mock_statvfs, cache_cleanup_list_mock):
# Not enough space, need to cleanup second cache
mock_stat.side_effect = [mock.Mock(st_dev=1),
mock.Mock(st_dev=2),
mock.Mock(st_dev=1)]
mock_stat.side_effect = [mock.MagicMock(st_dev=1, spec_set=['st_dev']),
mock.MagicMock(st_dev=2, spec_set=['st_dev']),
mock.MagicMock(st_dev=1, spec_set=['st_dev'])]
mock_show = mock_image_service.return_value.show
mock_show.return_value = dict(size=42)
mock_statvfs.side_effect = [
mock.Mock(f_frsize=1, f_bavail=1),
mock.Mock(f_frsize=1, f_bavail=1024)
mock.MagicMock(f_frsize=1, f_bavail=1,
spec_set=['f_frsize', 'f_bavail']),
mock.MagicMock(f_frsize=1, f_bavail=1024,
spec_set=['f_frsize', 'f_bavail'])
]
cache_cleanup_list_mock.__iter__.return_value = self.cache_cleanup_list
@@ -455,7 +475,7 @@ class CleanupImageCacheTestCase(base.TestCase):
self.assertEqual(mock_stat_calls_expected, mock_stat.mock_calls)
self.assertEqual(mock_statvfs_calls_expected, mock_statvfs.mock_calls)
@mock.patch.object(os, 'stat')
@mock.patch.object(os, 'stat', autospec=True)
def test_both_clean_up(self, mock_stat, mock_image_service, mock_statvfs,
cache_cleanup_list_mock):
# Not enough space, clean up of both caches required
@@ -463,9 +483,12 @@ class CleanupImageCacheTestCase(base.TestCase):
mock_show = mock_image_service.return_value.show
mock_show.return_value = dict(size=42)
mock_statvfs.side_effect = [
mock.Mock(f_frsize=1, f_bavail=1),
mock.Mock(f_frsize=1, f_bavail=2),
mock.Mock(f_frsize=1, f_bavail=1024)
mock.MagicMock(f_frsize=1, f_bavail=1,
spec_set=['f_frsize', 'f_bavail']),
mock.MagicMock(f_frsize=1, f_bavail=2,
spec_set=['f_frsize', 'f_bavail']),
mock.MagicMock(f_frsize=1, f_bavail=1024,
spec_set=['f_frsize', 'f_bavail'])
]
cache_cleanup_list_mock.__iter__.return_value = self.cache_cleanup_list
@@ -488,14 +511,15 @@ class CleanupImageCacheTestCase(base.TestCase):
self.assertEqual(mock_stat_calls_expected, mock_stat.mock_calls)
self.assertEqual(mock_statvfs_calls_expected, mock_statvfs.mock_calls)
@mock.patch.object(os, 'stat')
@mock.patch.object(os, 'stat', autospec=True)
def test_clean_up_fail(self, mock_stat, mock_image_service, mock_statvfs,
cache_cleanup_list_mock):
# Not enough space even after cleaning both caches - failure
mock_stat.return_value.st_dev = 1
mock_show = mock_image_service.return_value.show
mock_show.return_value = dict(size=42)
mock_statvfs.return_value = mock.Mock(f_frsize=1, f_bavail=1)
mock_statvfs.return_value = mock.MagicMock(
f_frsize=1, f_bavail=1, spec_set=['f_frsize', 'f_bavail'])
cache_cleanup_list_mock.__iter__.return_value = self.cache_cleanup_list
self.assertRaises(exception.InsufficientDiskSpace,
@@ -522,10 +546,10 @@ class CleanupImageCacheTestCase(base.TestCase):
class TestFetchCleanup(base.TestCase):
@mock.patch.object(images, 'converted_size')
@mock.patch.object(images, 'fetch')
@mock.patch.object(images, 'image_to_raw')
@mock.patch.object(image_cache, '_clean_up_caches')
@mock.patch.object(images, 'converted_size', autospec=True)
@mock.patch.object(images, 'fetch', autospec=True)
@mock.patch.object(images, 'image_to_raw', autospec=True)
@mock.patch.object(image_cache, '_clean_up_caches', autospec=True)
def test__fetch(self, mock_clean, mock_raw, mock_fetch, mock_size):
mock_size.return_value = 100
image_cache._fetch('fake', 'fake-uuid', '/foo/bar', force_raw=True)
+21 -21
View File
@@ -67,7 +67,7 @@ class IPMINativePrivateMethodTestCase(db_base.DbTestCase):
ipminative._parse_driver_info,
node)
@mock.patch('pyghmi.ipmi.command.Command')
@mock.patch('pyghmi.ipmi.command.Command', autospec=True)
def test__power_status_on(self, ipmi_mock):
ipmicmd = ipmi_mock.return_value
ipmicmd.get_power.return_value = {'powerstate': 'on'}
@@ -76,7 +76,7 @@ class IPMINativePrivateMethodTestCase(db_base.DbTestCase):
ipmicmd.get_power.assert_called_once_with()
self.assertEqual(states.POWER_ON, state)
@mock.patch('pyghmi.ipmi.command.Command')
@mock.patch('pyghmi.ipmi.command.Command', autospec=True)
def test__power_status_off(self, ipmi_mock):
ipmicmd = ipmi_mock.return_value
ipmicmd.get_power.return_value = {'powerstate': 'off'}
@@ -85,7 +85,7 @@ class IPMINativePrivateMethodTestCase(db_base.DbTestCase):
ipmicmd.get_power.assert_called_once_with()
self.assertEqual(states.POWER_OFF, state)
@mock.patch('pyghmi.ipmi.command.Command')
@mock.patch('pyghmi.ipmi.command.Command', autospec=True)
def test__power_status_error(self, ipmi_mock):
ipmicmd = ipmi_mock.return_value
ipmicmd.get_power.return_value = {'powerstate': 'Error'}
@@ -94,7 +94,7 @@ class IPMINativePrivateMethodTestCase(db_base.DbTestCase):
ipmicmd.get_power.assert_called_once_with()
self.assertEqual(states.ERROR, state)
@mock.patch('pyghmi.ipmi.command.Command')
@mock.patch('pyghmi.ipmi.command.Command', autospec=True)
def test__power_on(self, ipmi_mock):
ipmicmd = ipmi_mock.return_value
ipmicmd.set_power.return_value = {'powerstate': 'on'}
@@ -104,7 +104,7 @@ class IPMINativePrivateMethodTestCase(db_base.DbTestCase):
ipmicmd.set_power.assert_called_once_with('on', 400)
self.assertEqual(states.POWER_ON, state)
@mock.patch('pyghmi.ipmi.command.Command')
@mock.patch('pyghmi.ipmi.command.Command', autospec=True)
def test__power_off(self, ipmi_mock):
ipmicmd = ipmi_mock.return_value
ipmicmd.set_power.return_value = {'powerstate': 'off'}
@@ -114,7 +114,7 @@ class IPMINativePrivateMethodTestCase(db_base.DbTestCase):
ipmicmd.set_power.assert_called_once_with('off', 500)
self.assertEqual(states.POWER_OFF, state)
@mock.patch('pyghmi.ipmi.command.Command')
@mock.patch('pyghmi.ipmi.command.Command', autospec=True)
def test__reboot(self, ipmi_mock):
ipmicmd = ipmi_mock.return_value
ipmicmd.set_power.return_value = {'powerstate': 'on'}
@@ -132,7 +132,7 @@ class IPMINativePrivateMethodTestCase(db_base.DbTestCase):
'name': name, 'states': states,
'units': units, 'health': health})()
@mock.patch('pyghmi.ipmi.command.Command')
@mock.patch('pyghmi.ipmi.command.Command', autospec=True)
def test__get_sensors_data(self, ipmi_mock):
reading_1 = self._create_sensor_object('fake_value1',
'fake_type_A',
@@ -175,7 +175,7 @@ class IPMINativePrivateMethodTestCase(db_base.DbTestCase):
ret = ipminative._get_sensors_data(self.info)
self.assertEqual(expected, ret)
@mock.patch('pyghmi.ipmi.command.Command')
@mock.patch('pyghmi.ipmi.command.Command', autospec=True)
def test__get_sensors_data_missing_values(self, ipmi_mock):
reading_1 = self._create_sensor_object('fake_value1',
'fake_type_A',
@@ -230,7 +230,7 @@ class IPMINativeDriverTestCase(db_base.DbTestCase):
self.assertEqual(sorted(expected),
sorted(self.driver.get_properties().keys()))
@mock.patch('pyghmi.ipmi.command.Command')
@mock.patch('pyghmi.ipmi.command.Command', autospec=True)
def test_get_power_state(self, ipmi_mock):
# Getting the mocked command.
cmd_mock = ipmi_mock.return_value
@@ -256,7 +256,7 @@ class IPMINativeDriverTestCase(db_base.DbTestCase):
"pyghmi.ipmi.command.Command.get_power was not"
" called 3 times.")
@mock.patch.object(ipminative, '_power_on')
@mock.patch.object(ipminative, '_power_on', autospec=True)
def test_set_power_on_ok(self, power_on_mock):
power_on_mock.return_value = states.POWER_ON
@@ -266,7 +266,7 @@ class IPMINativeDriverTestCase(db_base.DbTestCase):
task, states.POWER_ON)
power_on_mock.assert_called_once_with(self.info)
@mock.patch.object(ipminative, '_power_off')
@mock.patch.object(ipminative, '_power_off', autospec=True)
def test_set_power_off_ok(self, power_off_mock):
power_off_mock.return_value = states.POWER_OFF
@@ -276,7 +276,7 @@ class IPMINativeDriverTestCase(db_base.DbTestCase):
task, states.POWER_OFF)
power_off_mock.assert_called_once_with(self.info)
@mock.patch('pyghmi.ipmi.command.Command')
@mock.patch('pyghmi.ipmi.command.Command', autospec=True)
def test_set_power_on_fail(self, ipmi_mock):
ipmicmd = ipmi_mock.return_value
ipmicmd.set_power.return_value = {'powerstate': 'error'}
@@ -290,7 +290,7 @@ class IPMINativeDriverTestCase(db_base.DbTestCase):
states.POWER_ON)
ipmicmd.set_power.assert_called_once_with('on', 500)
@mock.patch('pyghmi.ipmi.command.Command')
@mock.patch('pyghmi.ipmi.command.Command', autospec=True)
def test_set_boot_device_ok(self, ipmi_mock):
ipmicmd = ipmi_mock.return_value
ipmicmd.set_bootdev.return_value = None
@@ -308,7 +308,7 @@ class IPMINativeDriverTestCase(db_base.DbTestCase):
task,
'fake-device')
@mock.patch.object(ipminative, '_reboot')
@mock.patch.object(ipminative, '_reboot', autospec=True)
def test_reboot_ok(self, reboot_mock):
reboot_mock.return_value = None
@@ -317,7 +317,7 @@ class IPMINativeDriverTestCase(db_base.DbTestCase):
self.driver.power.reboot(task)
reboot_mock.assert_called_once_with(self.info)
@mock.patch('pyghmi.ipmi.command.Command')
@mock.patch('pyghmi.ipmi.command.Command', autospec=True)
def test_reboot_fail(self, ipmi_mock):
ipmicmd = ipmi_mock.return_value
ipmicmd.set_power.return_value = {'powerstate': 'error'}
@@ -337,7 +337,7 @@ class IPMINativeDriverTestCase(db_base.DbTestCase):
self.assertEqual(sorted(expected), sorted(task.driver.management.
get_supported_boot_devices()))
@mock.patch('pyghmi.ipmi.command.Command')
@mock.patch('pyghmi.ipmi.command.Command', autospec=True)
def test_management_interface_get_boot_device_good(self, ipmi_mock):
ipmicmd = ipmi_mock.return_value
ipmicmd.get_bootdev.return_value = {'bootdev': 'hd'}
@@ -346,7 +346,7 @@ class IPMINativeDriverTestCase(db_base.DbTestCase):
self.assertEqual(boot_devices.DISK, bootdev['boot_device'])
self.assertIsNone(bootdev['persistent'])
@mock.patch('pyghmi.ipmi.command.Command')
@mock.patch('pyghmi.ipmi.command.Command', autospec=True)
def test_management_interface_get_boot_device_persistent(self, ipmi_mock):
ipmicmd = ipmi_mock.return_value
ipmicmd.get_bootdev.return_value = {'bootdev': 'hd',
@@ -356,7 +356,7 @@ class IPMINativeDriverTestCase(db_base.DbTestCase):
self.assertEqual(boot_devices.DISK, bootdev['boot_device'])
self.assertTrue(bootdev['persistent'])
@mock.patch('pyghmi.ipmi.command.Command')
@mock.patch('pyghmi.ipmi.command.Command', autospec=True)
def test_management_interface_get_boot_device_fail(self, ipmi_mock):
ipmicmd = ipmi_mock.return_value
ipmicmd.get_bootdev.side_effect = pyghmi_exception.IpmiException
@@ -364,7 +364,7 @@ class IPMINativeDriverTestCase(db_base.DbTestCase):
self.assertRaises(exception.IPMIFailure,
self.driver.management.get_boot_device, task)
@mock.patch('pyghmi.ipmi.command.Command')
@mock.patch('pyghmi.ipmi.command.Command', autospec=True)
def test_management_interface_get_boot_device_fail_dict(self, ipmi_mock):
ipmicmd = ipmi_mock.return_value
ipmicmd.get_bootdev.return_value = {'error': 'boooom'}
@@ -372,7 +372,7 @@ class IPMINativeDriverTestCase(db_base.DbTestCase):
self.assertRaises(exception.IPMIFailure,
self.driver.management.get_boot_device, task)
@mock.patch('pyghmi.ipmi.command.Command')
@mock.patch('pyghmi.ipmi.command.Command', autospec=True)
def test_management_interface_get_boot_device_unknown(self, ipmi_mock):
ipmicmd = ipmi_mock.return_value
ipmicmd.get_bootdev.return_value = {'bootdev': 'unknown'}
@@ -394,7 +394,7 @@ class IPMINativeDriverTestCase(db_base.DbTestCase):
self.assertRaises(exception.MissingParameterValue,
task.driver.management.validate, task)
@mock.patch('pyghmi.ipmi.command.Command')
@mock.patch('pyghmi.ipmi.command.Command', autospec=True)
def test_get_sensors_data(self, ipmi_mock):
ipmicmd = ipmi_mock.return_value
ipmicmd.get_sensor_data.return_value = None
+61 -57
View File
@@ -24,6 +24,7 @@ import os
import stat
import tempfile
import time
import types
import mock
from oslo_concurrency import processutils
@@ -170,8 +171,8 @@ class IPMIToolCheckInitTestCase(base.TestCase):
class IPMIToolCheckOptionSupportedTestCase(base.TestCase):
@mock.patch.object(ipmi, '_is_option_supported')
@mock.patch.object(utils, 'execute')
@mock.patch.object(ipmi, '_is_option_supported', autospec=True)
@mock.patch.object(utils, 'execute', autospec=True)
def test_check_timing_pass(self, mock_exc, mock_support):
mock_exc.return_value = (None, None)
mock_support.return_value = None
@@ -182,8 +183,8 @@ class IPMIToolCheckOptionSupportedTestCase(base.TestCase):
self.assertTrue(mock_exc.called)
self.assertEqual(expected, mock_support.call_args_list)
@mock.patch.object(ipmi, '_is_option_supported')
@mock.patch.object(utils, 'execute')
@mock.patch.object(ipmi, '_is_option_supported', autospec=True)
@mock.patch.object(utils, 'execute', autospec=True)
def test_check_timing_fail(self, mock_exc, mock_support):
mock_exc.side_effect = processutils.ProcessExecutionError()
mock_support.return_value = None
@@ -194,8 +195,8 @@ class IPMIToolCheckOptionSupportedTestCase(base.TestCase):
self.assertTrue(mock_exc.called)
self.assertEqual(expected, mock_support.call_args_list)
@mock.patch.object(ipmi, '_is_option_supported')
@mock.patch.object(utils, 'execute')
@mock.patch.object(ipmi, '_is_option_supported', autospec=True)
@mock.patch.object(utils, 'execute', autospec=True)
def test_check_timing_no_ipmitool(self, mock_exc, mock_support):
mock_exc.side_effect = OSError()
mock_support.return_value = None
@@ -205,8 +206,8 @@ class IPMIToolCheckOptionSupportedTestCase(base.TestCase):
self.assertTrue(mock_exc.called)
self.assertEqual(expected, mock_support.call_args_list)
@mock.patch.object(ipmi, '_is_option_supported')
@mock.patch.object(utils, 'execute')
@mock.patch.object(ipmi, '_is_option_supported', autospec=True)
@mock.patch.object(utils, 'execute', autospec=True)
def test_check_single_bridge_pass(self, mock_exc, mock_support):
mock_exc.return_value = (None, None)
mock_support.return_value = None
@@ -217,8 +218,8 @@ class IPMIToolCheckOptionSupportedTestCase(base.TestCase):
self.assertTrue(mock_exc.called)
self.assertEqual(expected, mock_support.call_args_list)
@mock.patch.object(ipmi, '_is_option_supported')
@mock.patch.object(utils, 'execute')
@mock.patch.object(ipmi, '_is_option_supported', autospec=True)
@mock.patch.object(utils, 'execute', autospec=True)
def test_check_single_bridge_fail(self, mock_exc, mock_support):
mock_exc.side_effect = processutils.ProcessExecutionError()
mock_support.return_value = None
@@ -229,8 +230,8 @@ class IPMIToolCheckOptionSupportedTestCase(base.TestCase):
self.assertTrue(mock_exc.called)
self.assertEqual(expected, mock_support.call_args_list)
@mock.patch.object(ipmi, '_is_option_supported')
@mock.patch.object(utils, 'execute')
@mock.patch.object(ipmi, '_is_option_supported', autospec=True)
@mock.patch.object(utils, 'execute', autospec=True)
def test_check_single_bridge_no_ipmitool(self, mock_exc,
mock_support):
mock_exc.side_effect = OSError()
@@ -242,8 +243,8 @@ class IPMIToolCheckOptionSupportedTestCase(base.TestCase):
self.assertTrue(mock_exc.called)
self.assertEqual(expected, mock_support.call_args_list)
@mock.patch.object(ipmi, '_is_option_supported')
@mock.patch.object(utils, 'execute')
@mock.patch.object(ipmi, '_is_option_supported', autospec=True)
@mock.patch.object(utils, 'execute', autospec=True)
def test_check_dual_bridge_pass(self, mock_exc, mock_support):
mock_exc.return_value = (None, None)
mock_support.return_value = None
@@ -254,8 +255,8 @@ class IPMIToolCheckOptionSupportedTestCase(base.TestCase):
self.assertTrue(mock_exc.called)
self.assertEqual(expected, mock_support.call_args_list)
@mock.patch.object(ipmi, '_is_option_supported')
@mock.patch.object(utils, 'execute')
@mock.patch.object(ipmi, '_is_option_supported', autospec=True)
@mock.patch.object(utils, 'execute', autospec=True)
def test_check_dual_bridge_fail(self, mock_exc, mock_support):
mock_exc.side_effect = processutils.ProcessExecutionError()
mock_support.return_value = None
@@ -266,8 +267,8 @@ class IPMIToolCheckOptionSupportedTestCase(base.TestCase):
self.assertTrue(mock_exc.called)
self.assertEqual(expected, mock_support.call_args_list)
@mock.patch.object(ipmi, '_is_option_supported')
@mock.patch.object(utils, 'execute')
@mock.patch.object(ipmi, '_is_option_supported', autospec=True)
@mock.patch.object(utils, 'execute', autospec=True)
def test_check_dual_bridge_no_ipmitool(self, mock_exc, mock_support):
mock_exc.side_effect = OSError()
mock_support.return_value = None
@@ -278,8 +279,8 @@ class IPMIToolCheckOptionSupportedTestCase(base.TestCase):
self.assertTrue(mock_exc.called)
self.assertEqual(expected, mock_support.call_args_list)
@mock.patch.object(ipmi, '_is_option_supported')
@mock.patch.object(utils, 'execute')
@mock.patch.object(ipmi, '_is_option_supported', autospec=True)
@mock.patch.object(utils, 'execute', autospec=True)
def test_check_all_options_pass(self, mock_exc, mock_support):
mock_exc.return_value = (None, None)
mock_support.return_value = None
@@ -293,8 +294,8 @@ class IPMIToolCheckOptionSupportedTestCase(base.TestCase):
self.assertTrue(mock_exc.called)
self.assertEqual(expected, mock_support.call_args_list)
@mock.patch.object(ipmi, '_is_option_supported')
@mock.patch.object(utils, 'execute')
@mock.patch.object(ipmi, '_is_option_supported', autospec=True)
@mock.patch.object(utils, 'execute', autospec=True)
def test_check_all_options_fail(self, mock_exc, mock_support):
mock_exc.side_effect = processutils.ProcessExecutionError()
mock_support.return_value = None
@@ -309,8 +310,8 @@ class IPMIToolCheckOptionSupportedTestCase(base.TestCase):
self.assertTrue(mock_exc.called)
self.assertEqual(expected, mock_support.call_args_list)
@mock.patch.object(ipmi, '_is_option_supported')
@mock.patch.object(utils, 'execute')
@mock.patch.object(ipmi, '_is_option_supported', autospec=True)
@mock.patch.object(utils, 'execute', autospec=True)
def test_check_all_options_no_ipmitool(self, mock_exc, mock_support):
mock_exc.side_effect = OSError()
mock_support.return_value = None
@@ -323,7 +324,7 @@ class IPMIToolCheckOptionSupportedTestCase(base.TestCase):
self.assertEqual(expected, mock_support.call_args_list)
@mock.patch.object(time, 'sleep')
@mock.patch.object(time, 'sleep', autospec=True)
class IPMIToolPrivateMethodTestCase(db_base.DbTestCase):
def setUp(self):
@@ -431,7 +432,7 @@ class IPMIToolPrivateMethodTestCase(db_base.DbTestCase):
ipmi._parse_driver_info,
node)
@mock.patch.object(ipmi, '_is_option_supported')
@mock.patch.object(ipmi, '_is_option_supported', autospec=True)
def test__parse_driver_info_with_invalid_bridging_type(self,
mock_support, mock_sleep):
info = BRIDGE_INFO_DICT.copy()
@@ -443,7 +444,7 @@ class IPMIToolPrivateMethodTestCase(db_base.DbTestCase):
node)
self.assertFalse(mock_support.called)
@mock.patch.object(ipmi, '_is_option_supported')
@mock.patch.object(ipmi, '_is_option_supported', autospec=True)
def test__parse_driver_info_with_no_bridging(self,
mock_support, mock_sleep):
_OPTIONS = ['address', 'username', 'password', 'uuid']
@@ -468,7 +469,7 @@ class IPMIToolPrivateMethodTestCase(db_base.DbTestCase):
for option in _BRIDGING_OPTIONS:
self.assertIsNone(ret[option])
@mock.patch.object(ipmi, '_is_option_supported')
@mock.patch.object(ipmi, '_is_option_supported', autospec=True)
def test__parse_driver_info_with_dual_bridging_pass(self,
mock_support, mock_sleep):
_OPTIONS = ['address', 'username', 'password', 'uuid',
@@ -497,7 +498,7 @@ class IPMIToolPrivateMethodTestCase(db_base.DbTestCase):
ipmi._parse_driver_info(node)
self.assertEqual(mock.call('dual_bridge'), mock_support.call_args)
@mock.patch.object(ipmi, '_is_option_supported')
@mock.patch.object(ipmi, '_is_option_supported', autospec=True)
def test__parse_driver_info_with_dual_bridging_not_supported(self,
mock_support, mock_sleep):
node = obj_utils.get_test_node(self.context, driver='fake_ipmitool',
@@ -508,7 +509,7 @@ class IPMIToolPrivateMethodTestCase(db_base.DbTestCase):
ipmi._parse_driver_info, node)
mock_support.assert_called_once_with('dual_bridge')
@mock.patch.object(ipmi, '_is_option_supported')
@mock.patch.object(ipmi, '_is_option_supported', autospec=True)
def test__parse_driver_info_with_dual_bridging_missing_parameters(self,
mock_support, mock_sleep):
info = BRIDGE_INFO_DICT.copy()
@@ -524,7 +525,7 @@ class IPMIToolPrivateMethodTestCase(db_base.DbTestCase):
self.assertEqual(mock.call('dual_bridge'),
mock_support.call_args)
@mock.patch.object(ipmi, '_is_option_supported')
@mock.patch.object(ipmi, '_is_option_supported', autospec=True)
def test__parse_driver_info_with_single_bridging_pass(self,
mock_support, mock_sleep):
_OPTIONS = ['address', 'username', 'password', 'uuid',
@@ -559,7 +560,7 @@ class IPMIToolPrivateMethodTestCase(db_base.DbTestCase):
self.assertEqual(mock.call('single_bridge'),
mock_support.call_args)
@mock.patch.object(ipmi, '_is_option_supported')
@mock.patch.object(ipmi, '_is_option_supported', autospec=True)
def test__parse_driver_info_with_single_bridging_not_supported(self,
mock_support, mock_sleep):
info = BRIDGE_INFO_DICT.copy()
@@ -573,7 +574,7 @@ class IPMIToolPrivateMethodTestCase(db_base.DbTestCase):
ipmi._parse_driver_info, node)
mock_support.assert_called_once_with('single_bridge')
@mock.patch.object(ipmi, '_is_option_supported')
@mock.patch.object(ipmi, '_is_option_supported', autospec=True)
def test__parse_driver_info_with_single_bridging_missing_parameters(
self, mock_support, mock_sleep):
info = dict(BRIDGE_INFO_DICT)
@@ -590,7 +591,7 @@ class IPMIToolPrivateMethodTestCase(db_base.DbTestCase):
self.assertEqual(mock.call('single_bridge'),
mock_support.call_args)
@mock.patch.object(ipmi, '_is_option_supported')
@mock.patch.object(ipmi, '_is_option_supported', autospec=True)
@mock.patch.object(ipmi, '_make_password_file', autospec=True)
@mock.patch.object(utils, 'execute', autospec=True)
def test__exec_ipmitool_first_call_to_address(self, mock_exec, mock_pwf,
@@ -620,7 +621,7 @@ class IPMIToolPrivateMethodTestCase(db_base.DbTestCase):
mock_exec.assert_called_once_with(*args)
self.assertFalse(mock_sleep.called)
@mock.patch.object(ipmi, '_is_option_supported')
@mock.patch.object(ipmi, '_is_option_supported', autospec=True)
@mock.patch.object(ipmi, '_make_password_file', autospec=True)
@mock.patch.object(utils, 'execute', autospec=True)
def test__exec_ipmitool_second_call_to_address_sleep(self, mock_exec,
@@ -664,7 +665,7 @@ class IPMIToolPrivateMethodTestCase(db_base.DbTestCase):
self.assertEqual(expected, mock_support.call_args_list)
mock_exec.assert_called_with(*args[1])
@mock.patch.object(ipmi, '_is_option_supported')
@mock.patch.object(ipmi, '_is_option_supported', autospec=True)
@mock.patch.object(ipmi, '_make_password_file', autospec=True)
@mock.patch.object(utils, 'execute', autospec=True)
def test__exec_ipmitool_second_call_to_address_no_sleep(self, mock_exec,
@@ -710,7 +711,7 @@ class IPMIToolPrivateMethodTestCase(db_base.DbTestCase):
self.assertEqual(expected, mock_support.call_args_list)
mock_exec.assert_called_with(*args[1])
@mock.patch.object(ipmi, '_is_option_supported')
@mock.patch.object(ipmi, '_is_option_supported', autospec=True)
@mock.patch.object(ipmi, '_make_password_file', autospec=True)
@mock.patch.object(utils, 'execute', autospec=True)
def test__exec_ipmitool_two_calls_to_diff_address(self, mock_exec,
@@ -754,7 +755,7 @@ class IPMIToolPrivateMethodTestCase(db_base.DbTestCase):
self.assertEqual(expected, mock_support.call_args_list)
mock_exec.assert_called_with(*args[1])
@mock.patch.object(ipmi, '_is_option_supported')
@mock.patch.object(ipmi, '_is_option_supported', autospec=True)
@mock.patch.object(ipmi, '_make_password_file', autospec=True)
@mock.patch.object(utils, 'execute', autospec=True)
def test__exec_ipmitool_without_timing(self, mock_exec, mock_pwf,
@@ -783,7 +784,7 @@ class IPMIToolPrivateMethodTestCase(db_base.DbTestCase):
mock_pwf.assert_called_once_with(self.info['password'])
mock_exec.assert_called_once_with(*args)
@mock.patch.object(ipmi, '_is_option_supported')
@mock.patch.object(ipmi, '_is_option_supported', autospec=True)
@mock.patch.object(ipmi, '_make_password_file', autospec=True)
@mock.patch.object(utils, 'execute', autospec=True)
def test__exec_ipmitool_with_timing(self, mock_exec, mock_pwf,
@@ -813,7 +814,7 @@ class IPMIToolPrivateMethodTestCase(db_base.DbTestCase):
mock_pwf.assert_called_once_with(self.info['password'])
mock_exec.assert_called_once_with(*args)
@mock.patch.object(ipmi, '_is_option_supported')
@mock.patch.object(ipmi, '_is_option_supported', autospec=True)
@mock.patch.object(ipmi, '_make_password_file', autospec=True)
@mock.patch.object(utils, 'execute', autospec=True)
def test__exec_ipmitool_without_username(self, mock_exec, mock_pwf,
@@ -839,7 +840,7 @@ class IPMIToolPrivateMethodTestCase(db_base.DbTestCase):
self.assertTrue(mock_pwf.called)
mock_exec.assert_called_once_with(*args)
@mock.patch.object(ipmi, '_is_option_supported')
@mock.patch.object(ipmi, '_is_option_supported', autospec=True)
@mock.patch.object(ipmi, '_make_password_file', autospec=True)
@mock.patch.object(utils, 'execute', autospec=True)
def test__exec_ipmitool_with_dual_bridging(self,
@@ -881,7 +882,7 @@ class IPMIToolPrivateMethodTestCase(db_base.DbTestCase):
self.assertTrue(mock_pwf.called)
mock_exec.assert_called_once_with(*args)
@mock.patch.object(ipmi, '_is_option_supported')
@mock.patch.object(ipmi, '_is_option_supported', autospec=True)
@mock.patch.object(ipmi, '_make_password_file', autospec=True)
@mock.patch.object(utils, 'execute', autospec=True)
def test__exec_ipmitool_with_single_bridging(self,
@@ -924,7 +925,7 @@ class IPMIToolPrivateMethodTestCase(db_base.DbTestCase):
self.assertTrue(mock_pwf.called)
mock_exec.assert_called_once_with(*args)
@mock.patch.object(ipmi, '_is_option_supported')
@mock.patch.object(ipmi, '_is_option_supported', autospec=True)
@mock.patch.object(ipmi, '_make_password_file', autospec=True)
@mock.patch.object(utils, 'execute', autospec=True)
def test__exec_ipmitool_exception(self, mock_exec, mock_pwf,
@@ -1068,7 +1069,7 @@ class IPMIToolPrivateMethodTestCase(db_base.DbTestCase):
mock_exec.assert_called_once_with(self.info, "power status")
@mock.patch.object(ipmi, '_exec_ipmitool', autospec=True)
@mock.patch('eventlet.greenthread.sleep')
@mock.patch('eventlet.greenthread.sleep', autospec=True)
def test__power_on_max_retries(self, sleep_mock, mock_exec, mock_sleep):
self.config(retry_timeout=2, group='ipmi')
@@ -1257,8 +1258,8 @@ class IPMIToolDriverTestCase(db_base.DbTestCase):
self.driver.vendor.bmc_reset,
task, 'POST')
@mock.patch.object(ipmi, '_power_off', autospec=False)
@mock.patch.object(ipmi, '_power_on', autospec=False)
@mock.patch.object(ipmi, '_power_off', spec_set=types.FunctionType)
@mock.patch.object(ipmi, '_power_on', spec_set=types.FunctionType)
def test_reboot_ok(self, mock_on, mock_off):
manager = mock.MagicMock()
# NOTE(rloo): if autospec is True, then manager.mock_calls is empty
@@ -1274,8 +1275,8 @@ class IPMIToolDriverTestCase(db_base.DbTestCase):
self.assertEqual(manager.mock_calls, expected)
@mock.patch.object(ipmi, '_power_off', autospec=False)
@mock.patch.object(ipmi, '_power_on', autospec=False)
@mock.patch.object(ipmi, '_power_off', spec_set=types.FunctionType)
@mock.patch.object(ipmi, '_power_on', spec_set=types.FunctionType)
def test_reboot_fail(self, mock_on, mock_off):
manager = mock.MagicMock()
# NOTE(rloo): if autospec is True, then manager.mock_calls is empty
@@ -1293,7 +1294,7 @@ class IPMIToolDriverTestCase(db_base.DbTestCase):
self.assertEqual(manager.mock_calls, expected)
@mock.patch.object(ipmi, '_parse_driver_info')
@mock.patch.object(ipmi, '_parse_driver_info', autospec=True)
def test_vendor_passthru_validate__parse_driver_info_fail(self, info_mock):
info_mock.side_effect = exception.InvalidParameterValue("bad")
with task_manager.acquire(self.context, self.node['uuid']) as task:
@@ -1315,14 +1316,15 @@ class IPMIToolDriverTestCase(db_base.DbTestCase):
self.driver.vendor.validate,
task, method='send_raw')
@mock.patch.object(ipmi.VendorPassthru, 'send_raw')
@mock.patch.object(ipmi.VendorPassthru, 'send_raw', autospec=True)
def test_vendor_passthru_call_send_raw_bytes(self, raw_bytes_mock):
with task_manager.acquire(self.context, self.node['uuid'],
shared=False) as task:
self.driver.vendor.send_raw(task, http_method='POST',
raw_bytes='0x00 0x01')
raw_bytes_mock.assert_called_once_with(task, http_method='POST',
raw_bytes='0x00 0x01')
raw_bytes_mock.assert_called_once_with(
self.driver.vendor, task, http_method='POST',
raw_bytes='0x00 0x01')
def test_vendor_passthru_validate__bmc_reset_good(self):
with task_manager.acquire(self.context, self.node['uuid']) as task:
@@ -1341,19 +1343,21 @@ class IPMIToolDriverTestCase(db_base.DbTestCase):
method='bmc_reset',
warm=False)
@mock.patch.object(ipmi.VendorPassthru, 'bmc_reset')
@mock.patch.object(ipmi.VendorPassthru, 'bmc_reset', autospec=True)
def test_vendor_passthru_call_bmc_reset_warm(self, bmc_mock):
with task_manager.acquire(self.context, self.node['uuid'],
shared=False) as task:
self.driver.vendor.bmc_reset(task, 'POST', warm=True)
bmc_mock.assert_called_once_with(task, 'POST', warm=True)
bmc_mock.assert_called_once_with(
self.driver.vendor, task, 'POST', warm=True)
@mock.patch.object(ipmi.VendorPassthru, 'bmc_reset')
@mock.patch.object(ipmi.VendorPassthru, 'bmc_reset', autospec=True)
def test_vendor_passthru_call_bmc_reset_cold(self, bmc_mock):
with task_manager.acquire(self.context, self.node['uuid'],
shared=False) as task:
self.driver.vendor.bmc_reset(task, 'POST', warm=False)
bmc_mock.assert_called_once_with(task, 'POST', warm=False)
bmc_mock.assert_called_once_with(
self.driver.vendor, task, 'POST', warm=False)
def test_vendor_passthru_vendor_routes(self):
expected = ['send_raw', 'bmc_reset']
@@ -1434,7 +1438,7 @@ class IPMIToolDriverTestCase(db_base.DbTestCase):
mock_stop.assert_called_once_with(self.node.uuid)
@mock.patch.object(console_utils, 'get_shellinabox_console_url',
utospec=True)
autospec=True)
def test_get_console(self, mock_exec):
url = 'http://localhost:4201'
mock_exec.return_value = url
+50 -48
View File
@@ -29,6 +29,7 @@ from ironic.common import states
from ironic.common import utils
from ironic.conductor import task_manager
from ironic.conductor import utils as manager_utils
from ironic.drivers.modules import agent_client
from ironic.drivers.modules import deploy_utils
from ironic.drivers.modules import iscsi_deploy
from ironic.drivers.modules import pxe
@@ -207,7 +208,7 @@ class IscsiDeployValidateParametersTestCase(db_base.DbTestCase):
self.assertRaises(exception.MissingParameterValue,
iscsi_deploy.parse_instance_info, node)
@mock.patch.object(image_service, 'get_image_service')
@mock.patch.object(image_service, 'get_image_service', autospec=True)
def test_validate_image_properties_glance_image(self, image_service_mock):
node = obj_utils.create_test_node(
self.context, driver='fake_pxe',
@@ -226,7 +227,7 @@ class IscsiDeployValidateParametersTestCase(db_base.DbTestCase):
node.instance_info['image_source'], context=self.context
)
@mock.patch.object(image_service, 'get_image_service')
@mock.patch.object(image_service, 'get_image_service', autospec=True)
def test_validate_image_properties_glance_image_missing_prop(self,
image_service_mock):
node = obj_utils.create_test_node(
@@ -247,7 +248,7 @@ class IscsiDeployValidateParametersTestCase(db_base.DbTestCase):
node.instance_info['image_source'], context=self.context
)
@mock.patch.object(image_service, 'get_image_service')
@mock.patch.object(image_service, 'get_image_service', autospec=True)
def test_validate_image_properties_glance_image_not_authorized(self,
image_service_mock):
d_info = {'image_source': 'uuid'}
@@ -257,7 +258,7 @@ class IscsiDeployValidateParametersTestCase(db_base.DbTestCase):
iscsi_deploy.validate_image_properties, self.context,
d_info, [])
@mock.patch.object(image_service, 'get_image_service')
@mock.patch.object(image_service, 'get_image_service', autospec=True)
def test_validate_image_properties_glance_image_not_found(self,
image_service_mock):
d_info = {'image_source': 'uuid'}
@@ -273,7 +274,7 @@ class IscsiDeployValidateParametersTestCase(db_base.DbTestCase):
iscsi_deploy.validate_image_properties, self.context,
d_info, [])
@mock.patch.object(image_service.HttpImageService, 'show')
@mock.patch.object(image_service.HttpImageService, 'show', autospec=True)
def test_validate_image_properties_nonglance_image(self,
image_service_show_mock):
instance_info = {
@@ -293,9 +294,9 @@ class IscsiDeployValidateParametersTestCase(db_base.DbTestCase):
iscsi_deploy.validate_image_properties(self.context, d_info,
['kernel', 'ramdisk'])
image_service_show_mock.assert_called_once_with(
instance_info['image_source'])
mock.ANY, instance_info['image_source'])
@mock.patch.object(image_service.HttpImageService, 'show')
@mock.patch.object(image_service.HttpImageService, 'show', autospec=True)
def test_validate_image_properties_nonglance_image_validation_fail(self,
img_service_show_mock):
instance_info = {
@@ -379,7 +380,7 @@ class IscsiDeployMethodsTestCase(db_base.DbTestCase):
mgr_utils.mock_the_extension_manager(driver="fake_pxe")
self.node = obj_utils.create_test_node(self.context, **n)
@mock.patch.object(deploy_utils, 'fetch_images')
@mock.patch.object(deploy_utils, 'fetch_images', autospec=True)
def test_cache_instance_images_master_path(self, mock_fetch_image):
temp_dir = tempfile.mkdtemp()
self.config(images_path=temp_dir, group='pxe')
@@ -398,9 +399,9 @@ class IscsiDeployMethodsTestCase(db_base.DbTestCase):
'disk'),
image_path)
@mock.patch.object(utils, 'unlink_without_raise')
@mock.patch.object(utils, 'rmtree_without_raise')
@mock.patch.object(iscsi_deploy, 'InstanceImageCache')
@mock.patch.object(utils, 'unlink_without_raise', autospec=True)
@mock.patch.object(utils, 'rmtree_without_raise', autospec=True)
@mock.patch.object(iscsi_deploy, 'InstanceImageCache', autospec=True)
def test_destroy_images(self, mock_cache, mock_rmtree, mock_unlink):
self.config(images_path='/path', group='pxe')
@@ -442,8 +443,8 @@ class IscsiDeployMethodsTestCase(db_base.DbTestCase):
# assert deploy_key was injected in the node
self.assertIn('deploy_key', self.node.instance_info)
@mock.patch.object(keystone, 'get_service_url')
@mock.patch.object(utils, 'random_alnum')
@mock.patch.object(keystone, 'get_service_url', autospec=True)
@mock.patch.object(utils, 'random_alnum', autospec=True)
def test_build_deploy_ramdisk_options(self, mock_alnum, mock_get_url):
fake_api_url = 'http://127.0.0.1:6385'
self.config(api_url=fake_api_url, group='conductor')
@@ -453,8 +454,8 @@ class IscsiDeployMethodsTestCase(db_base.DbTestCase):
# assert keystone wasn't called
self.assertFalse(mock_get_url.called)
@mock.patch.object(keystone, 'get_service_url')
@mock.patch.object(utils, 'random_alnum')
@mock.patch.object(keystone, 'get_service_url', autospec=True)
@mock.patch.object(utils, 'random_alnum', autospec=True)
def test_build_deploy_ramdisk_options_keystone(self, mock_alnum,
mock_get_url):
fake_api_url = 'http://127.0.0.1:6385'
@@ -465,8 +466,8 @@ class IscsiDeployMethodsTestCase(db_base.DbTestCase):
# assert we are getting it from keystone
mock_get_url.assert_called_once_with()
@mock.patch.object(keystone, 'get_service_url')
@mock.patch.object(utils, 'random_alnum')
@mock.patch.object(keystone, 'get_service_url', autospec=True)
@mock.patch.object(utils, 'random_alnum', autospec=True)
def test_build_deploy_ramdisk_options_root_device(self, mock_alnum,
mock_get_url):
self.node.properties['root_device'] = {'wwn': 123456}
@@ -476,8 +477,8 @@ class IscsiDeployMethodsTestCase(db_base.DbTestCase):
self._test_build_deploy_ramdisk_options(mock_alnum, fake_api_url,
expected_root_device=expected)
@mock.patch.object(keystone, 'get_service_url')
@mock.patch.object(utils, 'random_alnum')
@mock.patch.object(keystone, 'get_service_url', autospec=True)
@mock.patch.object(utils, 'random_alnum', autospec=True)
def test_build_deploy_ramdisk_options_boot_option(self, mock_alnum,
mock_get_url):
self.node.instance_info = {'capabilities': '{"boot_option": "local"}'}
@@ -516,9 +517,9 @@ class IscsiDeployMethodsTestCase(db_base.DbTestCase):
result = iscsi_deploy.get_boot_option(self.node)
self.assertEqual("netboot", result)
@mock.patch.object(iscsi_deploy, 'InstanceImageCache')
@mock.patch.object(manager_utils, 'node_power_action')
@mock.patch.object(deploy_utils, 'deploy_partition_image')
@mock.patch.object(iscsi_deploy, 'InstanceImageCache', autospec=True)
@mock.patch.object(manager_utils, 'node_power_action', autospec=True)
@mock.patch.object(deploy_utils, 'deploy_partition_image', autospec=True)
def test_continue_deploy_fail(self, deploy_mock, power_mock,
mock_image_cache):
kwargs = {'address': '123456', 'iqn': 'aaa-bbb', 'key': 'fake-56789'}
@@ -542,9 +543,9 @@ class IscsiDeployMethodsTestCase(db_base.DbTestCase):
mock_image_cache.assert_called_once_with()
mock_image_cache.return_value.clean_up.assert_called_once_with()
@mock.patch.object(iscsi_deploy, 'InstanceImageCache')
@mock.patch.object(manager_utils, 'node_power_action')
@mock.patch.object(deploy_utils, 'deploy_partition_image')
@mock.patch.object(iscsi_deploy, 'InstanceImageCache', autospec=True)
@mock.patch.object(manager_utils, 'node_power_action', autospec=True)
@mock.patch.object(deploy_utils, 'deploy_partition_image', autospec=True)
def test_continue_deploy_ramdisk_fails(self, deploy_mock, power_mock,
mock_image_cache):
kwargs = {'address': '123456', 'iqn': 'aaa-bbb', 'key': 'fake-56789',
@@ -566,9 +567,9 @@ class IscsiDeployMethodsTestCase(db_base.DbTestCase):
mock_image_cache.return_value.clean_up.assert_called_once_with()
self.assertFalse(deploy_mock.called)
@mock.patch.object(iscsi_deploy, 'InstanceImageCache')
@mock.patch.object(manager_utils, 'node_power_action')
@mock.patch.object(deploy_utils, 'deploy_partition_image')
@mock.patch.object(iscsi_deploy, 'InstanceImageCache', autospec=True)
@mock.patch.object(manager_utils, 'node_power_action', autospec=True)
@mock.patch.object(deploy_utils, 'deploy_partition_image', autospec=True)
def test_continue_deploy_fail_no_root_uuid_or_disk_id(
self, deploy_mock, power_mock, mock_image_cache):
kwargs = {'address': '123456', 'iqn': 'aaa-bbb', 'key': 'fake-56789'}
@@ -591,9 +592,9 @@ class IscsiDeployMethodsTestCase(db_base.DbTestCase):
mock_image_cache.assert_called_once_with()
mock_image_cache.return_value.clean_up.assert_called_once_with()
@mock.patch.object(iscsi_deploy, 'InstanceImageCache')
@mock.patch.object(manager_utils, 'node_power_action')
@mock.patch.object(deploy_utils, 'deploy_partition_image')
@mock.patch.object(iscsi_deploy, 'InstanceImageCache', autospec=True)
@mock.patch.object(manager_utils, 'node_power_action', autospec=True)
@mock.patch.object(deploy_utils, 'deploy_partition_image', autospec=True)
def test_continue_deploy_fail_empty_root_uuid(
self, deploy_mock, power_mock, mock_image_cache):
kwargs = {'address': '123456', 'iqn': 'aaa-bbb', 'key': 'fake-56789'}
@@ -616,11 +617,11 @@ class IscsiDeployMethodsTestCase(db_base.DbTestCase):
mock_image_cache.assert_called_once_with()
mock_image_cache.return_value.clean_up.assert_called_once_with()
@mock.patch.object(iscsi_deploy, 'LOG')
@mock.patch.object(iscsi_deploy, 'get_deploy_info')
@mock.patch.object(iscsi_deploy, 'InstanceImageCache')
@mock.patch.object(manager_utils, 'node_power_action')
@mock.patch.object(deploy_utils, 'deploy_partition_image')
@mock.patch.object(iscsi_deploy, 'LOG', autospec=True)
@mock.patch.object(iscsi_deploy, 'get_deploy_info', autospec=True)
@mock.patch.object(iscsi_deploy, 'InstanceImageCache', autospec=True)
@mock.patch.object(manager_utils, 'node_power_action', autospec=True)
@mock.patch.object(deploy_utils, 'deploy_partition_image', autospec=True)
def test_continue_deploy(self, deploy_mock, power_mock, mock_image_cache,
mock_deploy_info, mock_log):
kwargs = {'address': '123456', 'iqn': 'aaa-bbb', 'key': 'fake-56789'}
@@ -667,11 +668,11 @@ class IscsiDeployMethodsTestCase(db_base.DbTestCase):
mock_image_cache.return_value.clean_up.assert_called_once_with()
self.assertEqual(uuid_dict_returned, retval)
@mock.patch.object(iscsi_deploy, 'LOG')
@mock.patch.object(iscsi_deploy, 'get_deploy_info')
@mock.patch.object(iscsi_deploy, 'InstanceImageCache')
@mock.patch.object(manager_utils, 'node_power_action')
@mock.patch.object(deploy_utils, 'deploy_disk_image')
@mock.patch.object(iscsi_deploy, 'LOG', autospec=True)
@mock.patch.object(iscsi_deploy, 'get_deploy_info', autospec=True)
@mock.patch.object(iscsi_deploy, 'InstanceImageCache', autospec=True)
@mock.patch.object(manager_utils, 'node_power_action', autospec=True)
@mock.patch.object(deploy_utils, 'deploy_disk_image', autospec=True)
def test_continue_deploy_whole_disk_image(
self, deploy_mock, power_mock, mock_image_cache, mock_deploy_info,
mock_log):
@@ -688,7 +689,6 @@ class IscsiDeployMethodsTestCase(db_base.DbTestCase):
'lun': '1',
'node_uuid': u'1be26c0b-03f2-4d2e-ae87-c02d7f33c123',
'port': '3260',
'root_mb': 102400,
}
log_params = mock_deploy_info.return_value.copy()
expected_dict = {
@@ -743,13 +743,14 @@ class IscsiDeployMethodsTestCase(db_base.DbTestCase):
self.assertEqual('target-iqn', ret_val['iqn'])
self.assertEqual('local', ret_val['boot_option'])
@mock.patch.object(iscsi_deploy, 'continue_deploy')
@mock.patch.object(iscsi_deploy, 'build_deploy_ramdisk_options')
@mock.patch.object(iscsi_deploy, 'continue_deploy', autospec=True)
@mock.patch.object(iscsi_deploy, 'build_deploy_ramdisk_options',
autospec=True)
def test_do_agent_iscsi_deploy_okay(self, build_options_mock,
continue_deploy_mock):
build_options_mock.return_value = {'deployment_key': 'abcdef',
'iscsi_target_iqn': 'iqn-qweqwe'}
agent_client_mock = mock.MagicMock()
agent_client_mock = mock.MagicMock(spec_set=agent_client.AgentClient)
agent_client_mock.start_iscsi_target.return_value = {
'command_status': 'SUCCESS', 'command_error': None}
driver_internal_info = {'agent_url': 'http://1.2.3.4:1234'}
@@ -773,12 +774,13 @@ class IscsiDeployMethodsTestCase(db_base.DbTestCase):
task.node.driver_internal_info['root_uuid_or_disk_id'])
self.assertEqual(ret_val, uuid_dict_returned)
@mock.patch.object(iscsi_deploy, 'build_deploy_ramdisk_options')
@mock.patch.object(iscsi_deploy, 'build_deploy_ramdisk_options',
autospec=True)
def test_do_agent_iscsi_deploy_start_iscsi_failure(self,
build_options_mock):
build_options_mock.return_value = {'deployment_key': 'abcdef',
'iscsi_target_iqn': 'iqn-qweqwe'}
agent_client_mock = mock.MagicMock()
agent_client_mock = mock.MagicMock(spec_set=agent_client.AgentClient)
agent_client_mock.start_iscsi_target.return_value = {
'command_status': 'FAILED', 'command_error': 'booom'}
self.node.provision_state = states.DEPLOYING
@@ -888,7 +890,7 @@ class IscsiDeployMethodsTestCase(db_base.DbTestCase):
iscsi_deploy.finish_deploy, task, '1.2.3.4')
set_fail_state_mock.assert_called_once_with(task, mock.ANY)
@mock.patch.object(manager_utils, 'node_power_action')
@mock.patch.object(manager_utils, 'node_power_action', autospec=True)
@mock.patch.object(deploy_utils, 'notify_ramdisk_to_proceed',
autospec=True)
def test_finish_deploy_ssh_with_local_boot(self, notify_mock,
+134 -113
View File
@@ -124,7 +124,8 @@ class PXEPrivateMethodsTestCase(db_base.DbTestCase):
mgr_utils.mock_the_extension_manager(driver="fake_pxe")
self.node = obj_utils.create_test_node(self.context, **n)
@mock.patch.object(base_image_service.BaseImageService, '_show')
@mock.patch.object(base_image_service.BaseImageService, '_show',
autospec=True)
def _test__get_image_info(self, show_mock):
properties = {'properties': {u'kernel_id': u'instance_kernel_uuid',
u'ramdisk_id': u'instance_ramdisk_uuid'}}
@@ -151,7 +152,7 @@ class PXEPrivateMethodsTestCase(db_base.DbTestCase):
'deploy_kernel'))}
show_mock.return_value = properties
image_info = pxe._get_image_info(self.node, self.context)
show_mock.assert_called_once_with('glance://image_uuid',
show_mock.assert_called_once_with(mock.ANY, 'glance://image_uuid',
method='get')
self.assertEqual(expected_info, image_info)
@@ -176,7 +177,8 @@ class PXEPrivateMethodsTestCase(db_base.DbTestCase):
self.node.save()
self._test__get_image_info()
@mock.patch.object(base_image_service.BaseImageService, '_show')
@mock.patch.object(base_image_service.BaseImageService, '_show',
autospec=True)
def test__get_image_info_whole_disk_image(self, show_mock):
properties = {'properties': None}
@@ -195,8 +197,9 @@ class PXEPrivateMethodsTestCase(db_base.DbTestCase):
image_info = pxe._get_image_info(self.node, self.context)
self.assertEqual(expected_info, image_info)
@mock.patch.object(iscsi_deploy, 'build_deploy_ramdisk_options')
@mock.patch.object(pxe_utils, '_build_pxe_config')
@mock.patch.object(iscsi_deploy, 'build_deploy_ramdisk_options',
autospec=True)
@mock.patch.object(pxe_utils, '_build_pxe_config', autospec=True)
def _test_build_pxe_config_options(self, build_pxe_mock, deploy_opts_mock,
whle_dsk_img=False,
ipxe_enabled=False):
@@ -298,8 +301,9 @@ class PXEPrivateMethodsTestCase(db_base.DbTestCase):
self._test_build_pxe_config_options(whle_dsk_img=False,
ipxe_enabled=False)
@mock.patch.object(iscsi_deploy, 'build_deploy_ramdisk_options')
@mock.patch.object(pxe_utils, '_build_pxe_config')
@mock.patch.object(iscsi_deploy, 'build_deploy_ramdisk_options',
autospec=True)
@mock.patch.object(pxe_utils, '_build_pxe_config', autospec=True)
def test__build_pxe_config_options_whole_disk_image(self,
build_pxe_mock,
deploy_opts_mock,
@@ -370,7 +374,7 @@ class PXEPrivateMethodsTestCase(db_base.DbTestCase):
self.assertEqual('/tftpboot/token-' + node_uuid,
pxe._get_token_file_path(node_uuid))
@mock.patch.object(deploy_utils, 'fetch_images')
@mock.patch.object(deploy_utils, 'fetch_images', autospec=True)
def test__cache_tftp_images_master_path(self, mock_fetch_image):
temp_dir = tempfile.mkdtemp()
self.config(tftp_root=temp_dir, group='pxe')
@@ -391,8 +395,8 @@ class PXEPrivateMethodsTestCase(db_base.DbTestCase):
True)
@mock.patch.object(pxe, 'TFTPImageCache', lambda: None)
@mock.patch.object(fileutils, 'ensure_tree')
@mock.patch.object(deploy_utils, 'fetch_images')
@mock.patch.object(fileutils, 'ensure_tree', autospec=True)
@mock.patch.object(deploy_utils, 'fetch_images', autospec=True)
def test__cache_ramdisk_kernel(self, mock_fetch_image, mock_ensure_tree):
self.config(ipxe_enabled=False, group='pxe')
fake_pxe_info = {'foo': 'bar'}
@@ -404,8 +408,8 @@ class PXEPrivateMethodsTestCase(db_base.DbTestCase):
self.context, mock.ANY, list(fake_pxe_info.values()), True)
@mock.patch.object(pxe, 'TFTPImageCache', lambda: None)
@mock.patch.object(fileutils, 'ensure_tree')
@mock.patch.object(deploy_utils, 'fetch_images')
@mock.patch.object(fileutils, 'ensure_tree', autospec=True)
@mock.patch.object(deploy_utils, 'fetch_images', autospec=True)
def test__cache_ramdisk_kernel_ipxe(self, mock_fetch_image,
mock_ensure_tree):
self.config(ipxe_enabled=True, group='pxe')
@@ -418,7 +422,7 @@ class PXEPrivateMethodsTestCase(db_base.DbTestCase):
list(fake_pxe_info.values()),
True)
@mock.patch.object(pxe.LOG, 'error')
@mock.patch.object(pxe.LOG, 'error', autospec=True)
def test_validate_boot_option_for_uefi_exc(self, mock_log):
properties = {'capabilities': 'boot_mode:uefi'}
instance_info = {"boot_option": "netboot"}
@@ -430,7 +434,7 @@ class PXEPrivateMethodsTestCase(db_base.DbTestCase):
self.node)
self.assertTrue(mock_log.called)
@mock.patch.object(pxe.LOG, 'error')
@mock.patch.object(pxe.LOG, 'error', autospec=True)
def test_validate_boot_option_for_uefi_noexc_one(self, mock_log):
properties = {'capabilities': 'boot_mode:uefi'}
instance_info = {"boot_option": "local"}
@@ -440,7 +444,7 @@ class PXEPrivateMethodsTestCase(db_base.DbTestCase):
pxe.validate_boot_option_for_uefi(self.node)
self.assertFalse(mock_log.called)
@mock.patch.object(pxe.LOG, 'error')
@mock.patch.object(pxe.LOG, 'error', autospec=True)
def test_validate_boot_option_for_uefi_noexc_two(self, mock_log):
properties = {'capabilities': 'boot_mode:bios'}
instance_info = {"boot_option": "local"}
@@ -450,7 +454,7 @@ class PXEPrivateMethodsTestCase(db_base.DbTestCase):
pxe.validate_boot_option_for_uefi(self.node)
self.assertFalse(mock_log.called)
@mock.patch.object(pxe.LOG, 'error')
@mock.patch.object(pxe.LOG, 'error', autospec=True)
def test_validate_boot_option_for_uefi_noexc_three(self, mock_log):
properties = {'capabilities': 'boot_mode:uefi'}
instance_info = {"boot_option": "local"}
@@ -494,7 +498,8 @@ class PXEDriverTestCase(db_base.DbTestCase):
shared=True) as task:
self.assertEqual(expected, task.driver.get_properties())
@mock.patch.object(base_image_service.BaseImageService, '_show')
@mock.patch.object(base_image_service.BaseImageService, '_show',
autospec=True)
def test_validate_good(self, mock_glance):
mock_glance.return_value = {'properties': {'kernel_id': 'fake-kernel',
'ramdisk_id': 'fake-initr'}}
@@ -502,7 +507,8 @@ class PXEDriverTestCase(db_base.DbTestCase):
shared=True) as task:
task.driver.deploy.validate(task)
@mock.patch.object(base_image_service.BaseImageService, '_show')
@mock.patch.object(base_image_service.BaseImageService, '_show',
autospec=True)
def test_validate_good_whole_disk_image(self, mock_glance):
with task_manager.acquire(self.context, self.node.uuid,
shared=True) as task:
@@ -519,7 +525,8 @@ class PXEDriverTestCase(db_base.DbTestCase):
self.assertRaises(exception.MissingParameterValue,
task.driver.deploy.validate, task)
@mock.patch.object(base_image_service.BaseImageService, '_show')
@mock.patch.object(base_image_service.BaseImageService, '_show',
autospec=True)
def test_validate_fail_invalid_boot_mode(self, mock_glance):
properties = {'capabilities': 'boot_mode:foo,cap2:value2'}
mock_glance.return_value = {'properties': {'kernel_id': 'fake-kernel',
@@ -530,7 +537,8 @@ class PXEDriverTestCase(db_base.DbTestCase):
self.assertRaises(exception.InvalidParameterValue,
task.driver.deploy.validate, task)
@mock.patch.object(base_image_service.BaseImageService, '_show')
@mock.patch.object(base_image_service.BaseImageService, '_show',
autospec=True)
def test_validate_fail_invalid_config_uefi_ipxe(self, mock_glance):
properties = {'capabilities': 'boot_mode:uefi,cap2:value2'}
mock_glance.return_value = {'properties': {'kernel_id': 'fake-kernel',
@@ -554,7 +562,8 @@ class PXEDriverTestCase(db_base.DbTestCase):
self.assertRaises(exception.InvalidParameterValue,
task.driver.deploy.validate, task)
@mock.patch.object(base_image_service.BaseImageService, '_show')
@mock.patch.object(base_image_service.BaseImageService, '_show',
autospec=True)
def test_validate_fail_invalid_boot_option(self, mock_glance):
properties = {'capabilities': 'boot_option:foo,dog:wuff'}
mock_glance.return_value = {'properties': {'kernel_id': 'fake-kernel',
@@ -576,8 +585,9 @@ class PXEDriverTestCase(db_base.DbTestCase):
self.assertRaises(exception.MissingParameterValue,
task.driver.deploy.validate, task)
@mock.patch.object(base_image_service.BaseImageService, '_show')
@mock.patch.object(keystone, 'get_service_url')
@mock.patch.object(base_image_service.BaseImageService, '_show',
autospec=True)
@mock.patch.object(keystone, 'get_service_url', autospec=True)
def test_validate_good_api_url_from_config_file(self, mock_ks,
mock_glance):
mock_glance.return_value = {'properties': {'kernel_id': 'fake-kernel',
@@ -590,8 +600,9 @@ class PXEDriverTestCase(db_base.DbTestCase):
task.driver.deploy.validate(task)
self.assertFalse(mock_ks.called)
@mock.patch.object(base_image_service.BaseImageService, '_show')
@mock.patch.object(keystone, 'get_service_url')
@mock.patch.object(base_image_service.BaseImageService, '_show',
autospec=True)
@mock.patch.object(keystone, 'get_service_url', autospec=True)
def test_validate_good_api_url_from_keystone(self, mock_ks, mock_glance):
mock_glance.return_value = {'properties': {'kernel_id': 'fake-kernel',
'ramdisk_id': 'fake-initr'}}
@@ -605,7 +616,7 @@ class PXEDriverTestCase(db_base.DbTestCase):
task.driver.deploy.validate(task)
mock_ks.assert_called_once_with()
@mock.patch.object(keystone, 'get_service_url')
@mock.patch.object(keystone, 'get_service_url', autospec=True)
def test_validate_fail_no_api_url(self, mock_ks):
# not present in the keystone catalog
mock_ks.side_effect = exception.KeystoneFailure
@@ -618,7 +629,8 @@ class PXEDriverTestCase(db_base.DbTestCase):
task.driver.deploy.validate, task)
mock_ks.assert_called_once_with()
@mock.patch.object(base_image_service.BaseImageService, '_show')
@mock.patch.object(base_image_service.BaseImageService, '_show',
autospec=True)
def test_validate_fail_no_image_kernel_ramdisk_props(self, mock_glance):
mock_glance.return_value = {'properties': {}}
with task_manager.acquire(self.context, self.node.uuid,
@@ -627,7 +639,8 @@ class PXEDriverTestCase(db_base.DbTestCase):
task.driver.deploy.validate,
task)
@mock.patch.object(base_image_service.BaseImageService, '_show')
@mock.patch.object(base_image_service.BaseImageService, '_show',
autospec=True)
def test_validate_fail_glance_image_doesnt_exists(self, mock_glance):
mock_glance.side_effect = exception.ImageNotFound('not found')
with task_manager.acquire(self.context, self.node.uuid,
@@ -635,19 +648,21 @@ class PXEDriverTestCase(db_base.DbTestCase):
self.assertRaises(exception.InvalidParameterValue,
task.driver.deploy.validate, task)
@mock.patch.object(base_image_service.BaseImageService, '_show')
@mock.patch.object(base_image_service.BaseImageService, '_show',
autospec=True)
def test_validate_fail_glance_conn_problem(self, mock_glance):
exceptions = (exception.GlanceConnectionFailed('connection fail'),
exception.ImageNotAuthorized('not authorized'),
exception.Invalid('invalid'))
mock_glance.side_effect = exceptions
mock_glance.side_effect = iter(exceptions)
for exc in exceptions:
with task_manager.acquire(self.context, self.node.uuid,
shared=True) as task:
self.assertRaises(exception.InvalidParameterValue,
task.driver.deploy.validate, task)
@mock.patch.object(base_image_service.BaseImageService, '_show')
@mock.patch.object(base_image_service.BaseImageService, '_show',
autospec=True)
def test_validate_invalid_root_device_hints(self, mock_glance):
mock_glance.return_value = {'properties': {'kernel_id': 'fake-kernel',
'ramdisk_id': 'fake-initr'}}
@@ -708,10 +723,10 @@ class PXEDriverTestCase(db_base.DbTestCase):
finish_deploy_mock.assert_called_once_with(task, '123456')
validate_input_mock.assert_called_once_with(task, kwargs)
@mock.patch.object(pxe, '_get_image_info')
@mock.patch.object(pxe, '_cache_ramdisk_kernel')
@mock.patch.object(pxe, '_build_pxe_config_options')
@mock.patch.object(pxe_utils, 'create_pxe_config')
@mock.patch.object(pxe, '_get_image_info', autospec=True)
@mock.patch.object(pxe, '_cache_ramdisk_kernel', autospec=True)
@mock.patch.object(pxe, '_build_pxe_config_options', autospec=True)
@mock.patch.object(pxe_utils, 'create_pxe_config', autospec=True)
def test_prepare(self, mock_pxe_config,
mock_build_pxe, mock_cache_r_k,
mock_img_info):
@@ -728,12 +743,12 @@ class PXEDriverTestCase(db_base.DbTestCase):
mock_cache_r_k.assert_called_once_with(self.context,
task.node, None)
@mock.patch.object(pxe, '_get_image_info')
@mock.patch.object(pxe, '_cache_ramdisk_kernel')
@mock.patch.object(pxe, '_build_pxe_config_options')
@mock.patch.object(pxe_utils, 'create_pxe_config')
@mock.patch.object(pxe_utils, 'get_pxe_config_file_path')
@mock.patch.object(deploy_utils, 'switch_pxe_config')
@mock.patch.object(pxe, '_get_image_info', autospec=True)
@mock.patch.object(pxe, '_cache_ramdisk_kernel', autospec=True)
@mock.patch.object(pxe, '_build_pxe_config_options', autospec=True)
@mock.patch.object(pxe_utils, 'create_pxe_config', autospec=True)
@mock.patch.object(pxe_utils, 'get_pxe_config_file_path', autospec=True)
@mock.patch.object(deploy_utils, 'switch_pxe_config', autospec=True)
def test_prepare_node_active_missing_root_uuid(self,
mock_switch,
mock_pxe_get_cfg,
@@ -757,13 +772,13 @@ class PXEDriverTestCase(db_base.DbTestCase):
self.assertFalse(mock_pxe_get_cfg.called)
self.assertFalse(mock_switch.called)
@mock.patch.object(pxe, '_get_image_info')
@mock.patch.object(pxe, '_cache_ramdisk_kernel')
@mock.patch.object(pxe, '_build_pxe_config_options')
@mock.patch.object(pxe_utils, 'create_pxe_config')
@mock.patch.object(pxe_utils, 'get_pxe_config_file_path')
@mock.patch.object(deploy_utils, 'switch_pxe_config')
@mock.patch.object(driver_utils, 'get_node_capability')
@mock.patch.object(pxe, '_get_image_info', autospec=True)
@mock.patch.object(pxe, '_cache_ramdisk_kernel', autospec=True)
@mock.patch.object(pxe, '_build_pxe_config_options', autospec=True)
@mock.patch.object(pxe_utils, 'create_pxe_config', autospec=True)
@mock.patch.object(pxe_utils, 'get_pxe_config_file_path', autospec=True)
@mock.patch.object(deploy_utils, 'switch_pxe_config', autospec=True)
@mock.patch.object(driver_utils, 'get_node_capability', autospec=True)
def _test_prepare_node_active(self,
mock_get_cap,
mock_switch,
@@ -804,13 +819,13 @@ class PXEDriverTestCase(db_base.DbTestCase):
self.node.save()
self._test_prepare_node_active()
@mock.patch.object(keystone, 'token_expires_soon')
@mock.patch.object(deploy_utils, 'get_image_mb')
@mock.patch.object(iscsi_deploy, '_get_image_file_path')
@mock.patch.object(iscsi_deploy, 'cache_instance_image')
@mock.patch.object(dhcp_factory.DHCPFactory, 'update_dhcp')
@mock.patch.object(manager_utils, 'node_power_action')
@mock.patch.object(manager_utils, 'node_set_boot_device')
@mock.patch.object(keystone, 'token_expires_soon', autospec=True)
@mock.patch.object(deploy_utils, 'get_image_mb', autospec=True)
@mock.patch.object(iscsi_deploy, '_get_image_file_path', autospec=True)
@mock.patch.object(iscsi_deploy, 'cache_instance_image', autospec=True)
@mock.patch.object(dhcp_factory.DHCPFactory, 'update_dhcp', autospec=True)
@mock.patch.object(manager_utils, 'node_power_action', autospec=True)
@mock.patch.object(manager_utils, 'node_set_boot_device', autospec=True)
def test_deploy(self, mock_node_set_boot, mock_node_power_action,
mock_update_dhcp, mock_cache_instance_image,
mock_get_image_file_path, mock_get_image_mb, mock_expire):
@@ -829,7 +844,7 @@ class PXEDriverTestCase(db_base.DbTestCase):
self.context, task.node)
mock_get_image_file_path.assert_called_once_with(task.node.uuid)
mock_get_image_mb.assert_called_once_with(fake_img_path)
mock_update_dhcp.assert_called_once_with(task, dhcp_opts)
mock_update_dhcp.assert_called_once_with(mock.ANY, task, dhcp_opts)
mock_expire.assert_called_once_with(self.context.auth_token, 600)
mock_node_set_boot.assert_called_once_with(task, 'pxe',
persistent=True)
@@ -840,14 +855,14 @@ class PXEDriverTestCase(db_base.DbTestCase):
token = open(t_path, 'r').read()
self.assertEqual(self.context.auth_token, token)
@mock.patch.object(keystone, 'get_admin_auth_token')
@mock.patch.object(keystone, 'token_expires_soon')
@mock.patch.object(deploy_utils, 'get_image_mb')
@mock.patch.object(iscsi_deploy, '_get_image_file_path')
@mock.patch.object(iscsi_deploy, 'cache_instance_image')
@mock.patch.object(dhcp_factory.DHCPFactory, 'update_dhcp')
@mock.patch.object(manager_utils, 'node_power_action')
@mock.patch.object(manager_utils, 'node_set_boot_device')
@mock.patch.object(keystone, 'get_admin_auth_token', autospec=True)
@mock.patch.object(keystone, 'token_expires_soon', autospec=True)
@mock.patch.object(deploy_utils, 'get_image_mb', autospec=True)
@mock.patch.object(iscsi_deploy, '_get_image_file_path', autospec=True)
@mock.patch.object(iscsi_deploy, 'cache_instance_image', autospec=True)
@mock.patch.object(dhcp_factory.DHCPFactory, 'update_dhcp', autospec=True)
@mock.patch.object(manager_utils, 'node_power_action', autospec=True)
@mock.patch.object(manager_utils, 'node_set_boot_device', autospec=True)
def test_deploy_token_near_expiration(self, mock_node_set_boot,
mock_node_power_action, mock_update_dhcp,
mock_cache_instance_image, mock_get_image_file_path,
@@ -869,9 +884,9 @@ class PXEDriverTestCase(db_base.DbTestCase):
token = open(t_path, 'r').read()
self.assertEqual(new_token, token)
@mock.patch.object(deploy_utils, 'get_image_mb')
@mock.patch.object(iscsi_deploy, '_get_image_file_path')
@mock.patch.object(iscsi_deploy, 'cache_instance_image')
@mock.patch.object(deploy_utils, 'get_image_mb', autospec=True)
@mock.patch.object(iscsi_deploy, '_get_image_file_path', autospec=True)
@mock.patch.object(iscsi_deploy, 'cache_instance_image', autospec=True)
def test_deploy_image_too_large(self, mock_cache_instance_image,
mock_get_image_file_path,
mock_get_image_mb):
@@ -888,7 +903,7 @@ class PXEDriverTestCase(db_base.DbTestCase):
mock_get_image_file_path.assert_called_once_with(task.node.uuid)
mock_get_image_mb.assert_called_once_with(fake_img_path)
@mock.patch.object(manager_utils, 'node_power_action')
@mock.patch.object(manager_utils, 'node_power_action', autospec=True)
def test_tear_down(self, node_power_mock):
with task_manager.acquire(self.context,
self.node.uuid) as task:
@@ -896,8 +911,8 @@ class PXEDriverTestCase(db_base.DbTestCase):
self.assertEqual(states.DELETED, state)
node_power_mock.assert_called_once_with(task, states.POWER_OFF)
@mock.patch.object(pxe_utils, 'clean_up_pxe_config')
@mock.patch.object(dhcp_factory.DHCPFactory, 'update_dhcp')
@mock.patch.object(pxe_utils, 'clean_up_pxe_config', autospec=True)
@mock.patch.object(dhcp_factory.DHCPFactory, 'update_dhcp', autospec=True)
def test_take_over(self, update_dhcp_mock, clean_pxe_mock):
with task_manager.acquire(
self.context, self.node.uuid, shared=True) as task:
@@ -905,14 +920,14 @@ class PXEDriverTestCase(db_base.DbTestCase):
task.driver.deploy.take_over(task)
# Assert we update the DHCP server
update_dhcp_mock.assert_called_once_with(task, dhcp_opts)
update_dhcp_mock.assert_called_once_with(mock.ANY, task, dhcp_opts)
# Assert we don't clean the PXE config files in
# case it's not local boot
self.assertFalse(clean_pxe_mock.called)
@mock.patch.object(pxe_utils, 'clean_up_pxe_config')
@mock.patch.object(dhcp_factory.DHCPFactory, 'update_dhcp')
@mock.patch.object(pxe_utils, 'clean_up_pxe_config', autospec=True)
@mock.patch.object(dhcp_factory.DHCPFactory, 'update_dhcp', autospec=True)
def test_take_over_localboot(self, update_dhcp_mock, clean_pxe_mock):
with task_manager.acquire(
self.context, self.node.uuid, shared=True) as task:
@@ -926,12 +941,13 @@ class PXEDriverTestCase(db_base.DbTestCase):
# Assert we are cleaning the PXE config files
clean_pxe_mock.assert_called_once_with(task)
@mock.patch.object(pxe_utils, 'clean_up_pxe_config')
@mock.patch.object(manager_utils, 'node_set_boot_device')
@mock.patch.object(deploy_utils, 'notify_ramdisk_to_proceed')
@mock.patch.object(deploy_utils, 'switch_pxe_config')
@mock.patch.object(iscsi_deploy, 'InstanceImageCache')
@mock.patch.object(deploy_utils, 'deploy_partition_image')
@mock.patch.object(pxe_utils, 'clean_up_pxe_config', autospec=True)
@mock.patch.object(manager_utils, 'node_set_boot_device', autospec=True)
@mock.patch.object(deploy_utils, 'notify_ramdisk_to_proceed',
autospec=True)
@mock.patch.object(deploy_utils, 'switch_pxe_config', autospec=True)
@mock.patch.object(iscsi_deploy, 'InstanceImageCache', autospec=True)
@mock.patch.object(deploy_utils, 'deploy_partition_image', autospec=True)
def _test_pass_deploy_info_deploy(self, is_localboot, mock_deploy,
mock_image_cache, mock_switch_config,
notify_mock, mock_node_boot_dev,
@@ -980,12 +996,13 @@ class PXEDriverTestCase(db_base.DbTestCase):
self.assertFalse(mock_node_boot_dev.called)
self.assertFalse(mock_clean_pxe.called)
@mock.patch.object(pxe_utils, 'clean_up_pxe_config')
@mock.patch.object(manager_utils, 'node_set_boot_device')
@mock.patch.object(deploy_utils, 'notify_ramdisk_to_proceed')
@mock.patch.object(deploy_utils, 'switch_pxe_config')
@mock.patch.object(iscsi_deploy, 'InstanceImageCache')
@mock.patch.object(deploy_utils, 'deploy_disk_image')
@mock.patch.object(pxe_utils, 'clean_up_pxe_config', autospec=True)
@mock.patch.object(manager_utils, 'node_set_boot_device', autospec=True)
@mock.patch.object(deploy_utils, 'notify_ramdisk_to_proceed',
autospec=True)
@mock.patch.object(deploy_utils, 'switch_pxe_config', autospec=True)
@mock.patch.object(iscsi_deploy, 'InstanceImageCache', autospec=True)
@mock.patch.object(deploy_utils, 'deploy_disk_image', autospec=True)
def _test_pass_deploy_info_whole_disk_image(self, is_localboot,
mock_deploy,
mock_image_cache,
@@ -1077,8 +1094,8 @@ class PXEDriverTestCase(db_base.DbTestCase):
def test_lock_elevated(self):
with task_manager.acquire(self.context, self.node.uuid) as task:
with mock.patch.object(task.driver.vendor,
'pass_deploy_info') as _cont_deploy_mock:
with mock.patch.object(task.driver.vendor, 'pass_deploy_info',
autospec=True) as _cont_deploy_mock:
task.driver.vendor.pass_deploy_info(
task, address='123456', iqn='aaa-bbb', key='fake-56789')
@@ -1104,11 +1121,11 @@ class PXEDriverTestCase(db_base.DbTestCase):
self.assertEqual(sorted(expected), sorted(list(driver_routes)))
@mock.patch.object(utils, 'unlink_without_raise')
@mock.patch.object(iscsi_deploy, 'destroy_images')
@mock.patch.object(pxe_utils, 'clean_up_pxe_config')
@mock.patch.object(pxe, 'TFTPImageCache')
@mock.patch.object(pxe, '_get_image_info')
@mock.patch.object(utils, 'unlink_without_raise', autospec=True)
@mock.patch.object(iscsi_deploy, 'destroy_images', autospec=True)
@mock.patch.object(pxe_utils, 'clean_up_pxe_config', autospec=True)
@mock.patch.object(pxe, 'TFTPImageCache', autospec=True)
@mock.patch.object(pxe, '_get_image_info', autospec=True)
class CleanUpTestCase(db_base.DbTestCase):
def setUp(self):
super(CleanUpTestCase, self).setUp()
@@ -1219,7 +1236,7 @@ class CleanUpFullFlowTestCase(db_base.DbTestCase):
os.link(self.master_kernel_path, self.kernel_path)
os.link(self.master_instance_path, self.image_path)
@mock.patch.object(pxe, '_get_image_info')
@mock.patch.object(pxe, '_get_image_info', autospec=True)
def test_clean_up_with_master(self, mock_get_image_info):
image_info = {'kernel': ('kernel_uuid',
self.kernel_path)}
@@ -1250,17 +1267,17 @@ class TestAgentVendorPassthru(db_base.DbTestCase):
driver_internal_info=DRV_INTERNAL_INFO_DICT,
)
self.node.driver_internal_info['agent_url'] = 'http://1.2.3.4:1234'
self.task = mock.Mock(spec=task_manager.TaskManager)
self.task = mock.MagicMock(spec=task_manager.TaskManager)
self.task.shared = False
self.task.node = self.node
self.task.driver = self.driver
self.task.context = self.context
@mock.patch.object(agent_base_vendor.BaseAgentVendor,
'reboot_and_finish_deploy')
@mock.patch.object(deploy_utils, 'switch_pxe_config')
@mock.patch.object(iscsi_deploy, 'do_agent_iscsi_deploy')
@mock.patch.object(pxe, '_destroy_token_file')
'reboot_and_finish_deploy', autospec=True)
@mock.patch.object(deploy_utils, 'switch_pxe_config', autospec=True)
@mock.patch.object(iscsi_deploy, 'do_agent_iscsi_deploy', autospec=True)
@mock.patch.object(pxe, '_destroy_token_file', autospec=True)
def test_continue_deploy_netboot(self, destroy_token_file_mock,
do_agent_iscsi_deploy_mock,
switch_pxe_config_mock,
@@ -1276,15 +1293,16 @@ class TestAgentVendorPassthru(db_base.DbTestCase):
switch_pxe_config_mock.assert_called_once_with(tftp_config,
'some-root-uuid',
None, False)
reboot_and_finish_deploy_mock.assert_called_once_with(self.task)
reboot_and_finish_deploy_mock.assert_called_once_with(
mock.ANY, self.task)
@mock.patch.object(agent_base_vendor.BaseAgentVendor,
'reboot_and_finish_deploy')
@mock.patch.object(pxe_utils, 'clean_up_pxe_config')
'reboot_and_finish_deploy', autospec=True)
@mock.patch.object(pxe_utils, 'clean_up_pxe_config', autospec=True)
@mock.patch.object(agent_base_vendor.BaseAgentVendor,
'configure_local_boot')
@mock.patch.object(iscsi_deploy, 'do_agent_iscsi_deploy')
@mock.patch.object(pxe, '_destroy_token_file')
'configure_local_boot', autospec=True)
@mock.patch.object(iscsi_deploy, 'do_agent_iscsi_deploy', autospec=True)
@mock.patch.object(pxe, '_destroy_token_file', autospec=True)
def test_continue_deploy_localboot(self, destroy_token_file_mock,
do_agent_iscsi_deploy_mock,
configure_local_boot_mock,
@@ -1302,17 +1320,19 @@ class TestAgentVendorPassthru(db_base.DbTestCase):
do_agent_iscsi_deploy_mock.assert_called_once_with(
self.task, self.driver.vendor._client)
configure_local_boot_mock.assert_called_once_with(
self.task, root_uuid='some-root-uuid', efi_system_part_uuid=None)
self.task.driver.vendor, self.task, root_uuid='some-root-uuid',
efi_system_part_uuid=None)
clean_up_pxe_config_mock.assert_called_once_with(self.task)
reboot_and_finish_deploy_mock.assert_called_once_with(self.task)
reboot_and_finish_deploy_mock.assert_called_once_with(
self.task.driver.vendor, self.task)
@mock.patch.object(agent_base_vendor.BaseAgentVendor,
'reboot_and_finish_deploy')
@mock.patch.object(pxe_utils, 'clean_up_pxe_config')
'reboot_and_finish_deploy', autospec=True)
@mock.patch.object(pxe_utils, 'clean_up_pxe_config', autospec=True)
@mock.patch.object(agent_base_vendor.BaseAgentVendor,
'configure_local_boot')
@mock.patch.object(iscsi_deploy, 'do_agent_iscsi_deploy')
@mock.patch.object(pxe, '_destroy_token_file')
'configure_local_boot', autospec=True)
@mock.patch.object(iscsi_deploy, 'do_agent_iscsi_deploy', autospec=True)
@mock.patch.object(pxe, '_destroy_token_file', autospec=True)
def test_continue_deploy_localboot_uefi(self, destroy_token_file_mock,
do_agent_iscsi_deploy_mock,
configure_local_boot_mock,
@@ -1331,7 +1351,8 @@ class TestAgentVendorPassthru(db_base.DbTestCase):
do_agent_iscsi_deploy_mock.assert_called_once_with(
self.task, self.driver.vendor._client)
configure_local_boot_mock.assert_called_once_with(
self.task, root_uuid='some-root-uuid',
self.task.driver.vendor, self.task, root_uuid='some-root-uuid',
efi_system_part_uuid='efi-part-uuid')
clean_up_pxe_config_mock.assert_called_once_with(self.task)
reboot_and_finish_deploy_mock.assert_called_once_with(self.task)
reboot_and_finish_deploy_mock.assert_called_once_with(
self.task.driver.vendor, self.task)
+58 -50
View File
@@ -147,7 +147,7 @@ class SeaMicroPrivateMethodsTestCase(db_base.DbTestCase):
self.info = seamicro._parse_driver_info(self.node)
@mock.patch.object(seamicro_client, "Client")
@mock.patch.object(seamicro_client, "Client", autospec=True)
def test__get_client(self, mock_client):
args = {'username': self.info['username'],
'password': self.info['password'],
@@ -155,7 +155,7 @@ class SeaMicroPrivateMethodsTestCase(db_base.DbTestCase):
seamicro._get_client(**self.info)
mock_client.assert_called_once_with(self.info['api_version'], **args)
@mock.patch.object(seamicro_client, "Client")
@mock.patch.object(seamicro_client, "Client", autospec=True)
def test__get_client_fail(self, mock_client):
args = {'username': self.info['username'],
'password': self.info['password'],
@@ -166,31 +166,31 @@ class SeaMicroPrivateMethodsTestCase(db_base.DbTestCase):
**self.info)
mock_client.assert_called_once_with(self.info['api_version'], **args)
@mock.patch.object(seamicro, "_get_server")
@mock.patch.object(seamicro, "_get_server", autospec=True)
def test__get_power_status_on(self, mock_get_server):
mock_get_server.return_value = self.Server(active=True)
pstate = seamicro._get_power_status(self.node)
self.assertEqual(states.POWER_ON, pstate)
@mock.patch.object(seamicro, "_get_server")
@mock.patch.object(seamicro, "_get_server", autospec=True)
def test__get_power_status_off(self, mock_get_server):
mock_get_server.return_value = self.Server(active=False)
pstate = seamicro._get_power_status(self.node)
self.assertEqual(states.POWER_OFF, pstate)
@mock.patch.object(seamicro, "_get_server")
@mock.patch.object(seamicro, "_get_server", autospec=True)
def test__get_power_status_error(self, mock_get_server):
mock_get_server.return_value = self.Server(active=None)
pstate = seamicro._get_power_status(self.node)
self.assertEqual(states.ERROR, pstate)
@mock.patch.object(seamicro, "_get_server")
@mock.patch.object(seamicro, "_get_server", autospec=True)
def test__power_on_good(self, mock_get_server):
mock_get_server.return_value = self.Server(active=False)
pstate = seamicro._power_on(self.node)
self.assertEqual(states.POWER_ON, pstate)
@mock.patch.object(seamicro, "_get_server")
@mock.patch.object(seamicro, "_get_server", autospec=True)
def test__power_on_fail(self, mock_get_server):
def fake_power_on():
return
@@ -201,13 +201,13 @@ class SeaMicroPrivateMethodsTestCase(db_base.DbTestCase):
pstate = seamicro._power_on(self.node)
self.assertEqual(states.ERROR, pstate)
@mock.patch.object(seamicro, "_get_server")
@mock.patch.object(seamicro, "_get_server", autospec=True)
def test__power_off_good(self, mock_get_server):
mock_get_server.return_value = self.Server(active=True)
pstate = seamicro._power_off(self.node)
self.assertEqual(states.POWER_OFF, pstate)
@mock.patch.object(seamicro, "_get_server")
@mock.patch.object(seamicro, "_get_server", autospec=True)
def test__power_off_fail(self, mock_get_server):
def fake_power_off():
return
@@ -217,13 +217,13 @@ class SeaMicroPrivateMethodsTestCase(db_base.DbTestCase):
pstate = seamicro._power_off(self.node)
self.assertEqual(states.ERROR, pstate)
@mock.patch.object(seamicro, "_get_server")
@mock.patch.object(seamicro, "_get_server", autospec=True)
def test__reboot_good(self, mock_get_server):
mock_get_server.return_value = self.Server(active=True)
pstate = seamicro._reboot(self.node)
self.assertEqual(states.POWER_ON, pstate)
@mock.patch.object(seamicro, "_get_server")
@mock.patch.object(seamicro, "_get_server", autospec=True)
def test__reboot_fail(self, mock_get_server):
def fake_reboot():
return
@@ -233,7 +233,7 @@ class SeaMicroPrivateMethodsTestCase(db_base.DbTestCase):
pstate = seamicro._reboot(self.node)
self.assertEqual(states.ERROR, pstate)
@mock.patch.object(seamicro, "_get_volume")
@mock.patch.object(seamicro, "_get_volume", autospec=True)
def test__validate_fail(self, mock_get_volume):
volume_id = "0/p6-6/vol1"
volume = self.Volume()
@@ -242,29 +242,29 @@ class SeaMicroPrivateMethodsTestCase(db_base.DbTestCase):
self.assertRaises(exception.InvalidParameterValue,
seamicro._validate_volume, self.info, volume_id)
@mock.patch.object(seamicro, "_get_volume")
@mock.patch.object(seamicro, "_get_volume", autospec=True)
def test__validate_good(self, mock_get_volume):
volume = self.Volume()
mock_get_volume.return_value = volume
valid = seamicro._validate_volume(self.info, volume.id)
self.assertEqual(valid, True)
@mock.patch.object(seamicro, "_get_pools")
@mock.patch.object(seamicro, "_get_pools", autospec=True)
def test__create_volume_fail(self, mock_get_pools):
mock_get_pools.return_value = None
self.assertRaises(exception.IronicException,
seamicro._create_volume,
self.info, 2)
@mock.patch.object(seamicro, "_get_pools")
@mock.patch.object(seamicro, "_get_client")
@mock.patch.object(seamicro, "_get_pools", autospec=True)
@mock.patch.object(seamicro, "_get_client", autospec=True)
def test__create_volume_good(self, mock_get_client, mock_get_pools):
pools = [self.Pool(1), self.Pool(6), self.Pool(5)]
get_pools_patcher = mock.patch.object(mock_get_client, "volume.create")
get_pools_patcher.start()
mock_seamicro_volumes = mock.MagicMock(spec_set=['create'])
mock_get_client.return_value = mock.MagicMock(
volumes=mock_seamicro_volumes, spec_set=['volumes'])
mock_get_pools.return_value = pools
seamicro._create_volume(self.info, 2)
get_pools_patcher.stop()
class SeaMicroPowerDriverTestCase(db_base.DbTestCase):
@@ -276,7 +276,8 @@ class SeaMicroPowerDriverTestCase(db_base.DbTestCase):
self.node = obj_utils.create_test_node(self.context,
driver='fake_seamicro',
driver_info=INFO_DICT)
self.get_server_patcher = mock.patch.object(seamicro, '_get_server')
self.get_server_patcher = mock.patch.object(seamicro, '_get_server',
autospec=True)
self.get_server_mock = None
self.Server = Fake_Server
@@ -311,14 +312,14 @@ class SeaMicroPowerDriverTestCase(db_base.DbTestCase):
self.assertIsInstance(driver_routes, dict)
self.assertEqual({}, driver_routes)
@mock.patch.object(seamicro, '_parse_driver_info')
@mock.patch.object(seamicro, '_parse_driver_info', autospec=True)
def test_power_interface_validate_good(self, parse_drv_info_mock):
with task_manager.acquire(self.context, self.node['uuid'],
shared=True) as task:
task.driver.power.validate(task)
self.assertEqual(1, parse_drv_info_mock.call_count)
@mock.patch.object(seamicro, '_parse_driver_info')
@mock.patch.object(seamicro, '_parse_driver_info', autospec=True)
def test_power_interface_validate_fails(self, parse_drv_info_mock):
side_effect = exception.InvalidParameterValue("Bad input")
parse_drv_info_mock.side_effect = side_effect
@@ -328,7 +329,7 @@ class SeaMicroPowerDriverTestCase(db_base.DbTestCase):
task.driver.power.validate, task)
self.assertEqual(1, parse_drv_info_mock.call_count)
@mock.patch.object(seamicro, '_reboot')
@mock.patch.object(seamicro, '_reboot', autospec=True)
def test_reboot(self, mock_reboot):
mock_reboot.return_value = states.POWER_ON
@@ -349,7 +350,7 @@ class SeaMicroPowerDriverTestCase(db_base.DbTestCase):
task, "BAD_PSTATE")
self.get_server_patcher.stop()
@mock.patch.object(seamicro, '_power_on')
@mock.patch.object(seamicro, '_power_on', autospec=True)
def test_set_power_state_on_good(self, mock_power_on):
mock_power_on.return_value = states.POWER_ON
@@ -359,7 +360,7 @@ class SeaMicroPowerDriverTestCase(db_base.DbTestCase):
mock_power_on.assert_called_once_with(task.node)
@mock.patch.object(seamicro, '_power_on')
@mock.patch.object(seamicro, '_power_on', autospec=True)
def test_set_power_state_on_fail(self, mock_power_on):
mock_power_on.return_value = states.POWER_OFF
@@ -371,7 +372,7 @@ class SeaMicroPowerDriverTestCase(db_base.DbTestCase):
mock_power_on.assert_called_once_with(task.node)
@mock.patch.object(seamicro, '_power_off')
@mock.patch.object(seamicro, '_power_off', autospec=True)
def test_set_power_state_off_good(self, mock_power_off):
mock_power_off.return_value = states.POWER_OFF
@@ -381,7 +382,7 @@ class SeaMicroPowerDriverTestCase(db_base.DbTestCase):
mock_power_off.assert_called_once_with(task.node)
@mock.patch.object(seamicro, '_power_off')
@mock.patch.object(seamicro, '_power_off', autospec=True)
def test_set_power_state_off_fail(self, mock_power_off):
mock_power_off.return_value = states.POWER_ON
@@ -393,7 +394,7 @@ class SeaMicroPowerDriverTestCase(db_base.DbTestCase):
mock_power_off.assert_called_once_with(task.node)
@mock.patch.object(seamicro, '_parse_driver_info')
@mock.patch.object(seamicro, '_parse_driver_info', autospec=True)
def test_vendor_passthru_validate_good(self, mock_info):
with task_manager.acquire(self.context, self.node['uuid'],
shared=True) as task:
@@ -402,7 +403,7 @@ class SeaMicroPowerDriverTestCase(db_base.DbTestCase):
self.assertEqual(len(task.driver.vendor.vendor_routes),
mock_info.call_count)
@mock.patch.object(seamicro, '_parse_driver_info')
@mock.patch.object(seamicro, '_parse_driver_info', autospec=True)
def test_vendor_passthru_validate_parse_driver_info_fail(self, mock_info):
mock_info.side_effect = exception.InvalidParameterValue("bad")
with task_manager.acquire(self.context, self.node['uuid'],
@@ -413,7 +414,7 @@ class SeaMicroPowerDriverTestCase(db_base.DbTestCase):
task, **{'method': method})
mock_info.assert_called_once_with(task.node)
@mock.patch.object(seamicro, '_get_server')
@mock.patch.object(seamicro, '_get_server', autospec=True)
def test_set_node_vlan_id_good(self, mock_get_server):
vlan_id = "12"
mock_get_server.return_value = self.Server(active="true")
@@ -430,7 +431,7 @@ class SeaMicroPowerDriverTestCase(db_base.DbTestCase):
task.driver.vendor.set_node_vlan_id,
task, **{})
@mock.patch.object(seamicro, '_get_server')
@mock.patch.object(seamicro, '_get_server', autospec=True)
def test_set_node_vlan_id_fail(self, mock_get_server):
def fake_set_untagged_vlan(self, **kwargs):
raise seamicro_client_exception.ClientException(500)
@@ -448,8 +449,8 @@ class SeaMicroPowerDriverTestCase(db_base.DbTestCase):
mock_get_server.assert_called_once_with(self.info)
@mock.patch.object(seamicro, '_get_server')
@mock.patch.object(seamicro, '_validate_volume')
@mock.patch.object(seamicro, '_get_server', autospec=True)
@mock.patch.object(seamicro, '_validate_volume', autospec=True)
def test_attach_volume_with_volume_id_good(self, mock_validate_volume,
mock_get_server):
volume_id = '0/ironic-p6-1/vol1'
@@ -461,8 +462,8 @@ class SeaMicroPowerDriverTestCase(db_base.DbTestCase):
task.driver.vendor.attach_volume(task, **kwargs)
mock_get_server.assert_called_once_with(self.info)
@mock.patch.object(seamicro, '_get_server')
@mock.patch.object(seamicro, '_get_volume')
@mock.patch.object(seamicro, '_get_server', autospec=True)
@mock.patch.object(seamicro, '_get_volume', autospec=True)
def test_attach_volume_with_invalid_volume_id_fail(self,
mock_get_volume,
mock_get_server):
@@ -476,8 +477,8 @@ class SeaMicroPowerDriverTestCase(db_base.DbTestCase):
task.driver.vendor.attach_volume,
task, **kwargs)
@mock.patch.object(seamicro, '_get_server')
@mock.patch.object(seamicro, '_validate_volume')
@mock.patch.object(seamicro, '_get_server', autospec=True)
@mock.patch.object(seamicro, '_validate_volume', autospec=True)
def test_attach_volume_fail(self, mock_validate_volume,
mock_get_server):
def fake_attach_volume(self, **kwargs):
@@ -497,9 +498,9 @@ class SeaMicroPowerDriverTestCase(db_base.DbTestCase):
mock_get_server.assert_called_once_with(self.info)
@mock.patch.object(seamicro, '_get_server')
@mock.patch.object(seamicro, '_validate_volume')
@mock.patch.object(seamicro, '_create_volume')
@mock.patch.object(seamicro, '_get_server', autospec=True)
@mock.patch.object(seamicro, '_validate_volume', autospec=True)
@mock.patch.object(seamicro, '_create_volume', autospec=True)
def test_attach_volume_with_volume_size_good(self, mock_create_volume,
mock_validate_volume,
mock_get_server):
@@ -522,7 +523,7 @@ class SeaMicroPowerDriverTestCase(db_base.DbTestCase):
task.driver.vendor.attach_volume, task,
**{})
@mock.patch.object(seamicro, '_get_server')
@mock.patch.object(seamicro, '_get_server', autospec=True)
def test_set_boot_device_good(self, mock_get_server):
boot_device = "disk"
mock_get_server.return_value = self.Server(active="true")
@@ -531,7 +532,7 @@ class SeaMicroPowerDriverTestCase(db_base.DbTestCase):
task.driver.management.set_boot_device(task, boot_device)
mock_get_server.assert_called_once_with(self.info)
@mock.patch.object(seamicro, '_get_server')
@mock.patch.object(seamicro, '_get_server', autospec=True)
def test_set_boot_device_invalid_device_fail(self, mock_get_server):
boot_device = "invalid_device"
mock_get_server.return_value = self.Server(active="true")
@@ -541,7 +542,7 @@ class SeaMicroPowerDriverTestCase(db_base.DbTestCase):
task.driver.management.set_boot_device,
task, boot_device)
@mock.patch.object(seamicro, '_get_server')
@mock.patch.object(seamicro, '_get_server', autospec=True)
def test_set_boot_device_fail(self, mock_get_server):
def fake_set_boot_order(self, **kwargs):
raise seamicro_client_exception.ClientException(500)
@@ -593,14 +594,16 @@ class SeaMicroDriverTestCase(db_base.DbTestCase):
self.node = obj_utils.create_test_node(self.context,
driver='fake_seamicro',
driver_info=INFO_DICT)
self.get_server_patcher = mock.patch.object(seamicro, '_get_server')
self.get_server_patcher = mock.patch.object(seamicro, '_get_server',
autospec=True)
self.get_server_mock = None
self.Server = Fake_Server
self.Volume = Fake_Volume
self.info = seamicro._parse_driver_info(self.node)
@mock.patch.object(console_utils, 'start_shellinabox_console')
@mock.patch.object(console_utils, 'start_shellinabox_console',
autospec=True)
def test_start_console(self, mock_exec):
mock_exec.return_value = None
with task_manager.acquire(self.context,
@@ -611,7 +614,8 @@ class SeaMicroDriverTestCase(db_base.DbTestCase):
self.info['port'],
mock.ANY)
@mock.patch.object(console_utils, 'start_shellinabox_console')
@mock.patch.object(console_utils, 'start_shellinabox_console',
autospec=True)
def test_start_console_fail(self, mock_exec):
mock_exec.side_effect = exception.ConsoleSubprocessFailed(
error='error')
@@ -622,7 +626,8 @@ class SeaMicroDriverTestCase(db_base.DbTestCase):
self.driver.console.start_console,
task)
@mock.patch.object(console_utils, 'stop_shellinabox_console')
@mock.patch.object(console_utils, 'stop_shellinabox_console',
autospec=True)
def test_stop_console(self, mock_exec):
mock_exec.return_value = None
with task_manager.acquire(self.context,
@@ -631,7 +636,8 @@ class SeaMicroDriverTestCase(db_base.DbTestCase):
mock_exec.assert_called_once_with(self.info['uuid'])
@mock.patch.object(console_utils, 'stop_shellinabox_console')
@mock.patch.object(console_utils, 'stop_shellinabox_console',
autospec=True)
def test_stop_console_fail(self, mock_stop):
mock_stop.side_effect = exception.ConsoleError()
@@ -643,7 +649,8 @@ class SeaMicroDriverTestCase(db_base.DbTestCase):
mock_stop.assert_called_once_with(self.node.uuid)
@mock.patch.object(console_utils, 'start_shellinabox_console')
@mock.patch.object(console_utils, 'start_shellinabox_console',
autospec=True)
def test_start_console_fail_nodir(self, mock_exec):
mock_exec.side_effect = exception.ConsoleError()
@@ -654,7 +661,8 @@ class SeaMicroDriverTestCase(db_base.DbTestCase):
task)
mock_exec.assert_called_once_with(self.node.uuid, mock.ANY, mock.ANY)
@mock.patch.object(console_utils, 'get_shellinabox_console_url')
@mock.patch.object(console_utils, 'get_shellinabox_console_url',
autospec=True)
def test_get_console(self, mock_exec):
url = 'http://localhost:4201'
mock_exec.return_value = url
+32 -32
View File
@@ -39,7 +39,7 @@ CONF = cfg.CONF
INFO_DICT = db_utils.get_test_snmp_info()
@mock.patch.object(cmdgen, 'CommandGenerator')
@mock.patch.object(cmdgen, 'CommandGenerator', autospec=True)
class SNMPClientTestCase(base.TestCase):
def setUp(self):
super(SNMPClientTestCase, self).setUp()
@@ -58,28 +58,28 @@ class SNMPClientTestCase(base.TestCase):
self.assertFalse('security' in client.__dict__)
self.assertEqual(mock_cmdgen.return_value, client.cmd_gen)
@mock.patch.object(cmdgen, 'CommunityData')
@mock.patch.object(cmdgen, 'CommunityData', autospec=True)
def test__get_auth_v1(self, mock_community, mock_cmdgen):
client = snmp.SNMPClient(self.address, self.port, snmp.SNMP_V1)
client._get_auth()
mock_cmdgen.assert_called_once_with()
mock_community.assert_called_once_with(client.community, mpModel=0)
@mock.patch.object(cmdgen, 'UsmUserData')
@mock.patch.object(cmdgen, 'UsmUserData', autospec=True)
def test__get_auth_v3(self, mock_user, mock_cmdgen):
client = snmp.SNMPClient(self.address, self.port, snmp.SNMP_V3)
client._get_auth()
mock_cmdgen.assert_called_once_with()
mock_user.assert_called_once_with(client.security)
@mock.patch.object(cmdgen, 'UdpTransportTarget')
@mock.patch.object(cmdgen, 'UdpTransportTarget', autospec=True)
def test__get_transport(self, mock_transport, mock_cmdgen):
client = snmp.SNMPClient(self.address, self.port, snmp.SNMP_V3)
client._get_transport()
mock_cmdgen.assert_called_once_with()
mock_transport.assert_called_once_with((client.address, client.port))
@mock.patch.object(cmdgen, 'UdpTransportTarget')
@mock.patch.object(cmdgen, 'UdpTransportTarget', autospec=True)
def test__get_transport_err(self, mock_transport, mock_cmdgen):
mock_transport.side_effect = snmp_error.PySnmpError
client = snmp.SNMPClient(self.address, self.port, snmp.SNMP_V3)
@@ -87,8 +87,8 @@ class SNMPClientTestCase(base.TestCase):
mock_cmdgen.assert_called_once_with()
mock_transport.assert_called_once_with((client.address, client.port))
@mock.patch.object(snmp.SNMPClient, '_get_transport')
@mock.patch.object(snmp.SNMPClient, '_get_auth')
@mock.patch.object(snmp.SNMPClient, '_get_transport', autospec=True)
@mock.patch.object(snmp.SNMPClient, '_get_auth', autospec=True)
def test_get(self, mock_auth, mock_transport, mock_cmdgen):
var_bind = (self.oid, self.value)
mock_cmdgenerator = mock_cmdgen.return_value
@@ -99,8 +99,8 @@ class SNMPClientTestCase(base.TestCase):
mock_cmdgenerator.getCmd.assert_called_once_with(mock.ANY, mock.ANY,
self.oid)
@mock.patch.object(snmp.SNMPClient, '_get_transport')
@mock.patch.object(snmp.SNMPClient, '_get_auth')
@mock.patch.object(snmp.SNMPClient, '_get_transport', autospec=True)
@mock.patch.object(snmp.SNMPClient, '_get_auth', autospec=True)
def test_get_err_transport(self, mock_auth, mock_transport, mock_cmdgen):
mock_transport.side_effect = snmp_error.PySnmpError
var_bind = (self.oid, self.value)
@@ -111,8 +111,8 @@ class SNMPClientTestCase(base.TestCase):
self.assertRaises(exception.SNMPFailure, client.get, self.oid)
self.assertFalse(mock_cmdgenerator.getCmd.called)
@mock.patch.object(snmp.SNMPClient, '_get_transport')
@mock.patch.object(snmp.SNMPClient, '_get_auth')
@mock.patch.object(snmp.SNMPClient, '_get_transport', autospec=True)
@mock.patch.object(snmp.SNMPClient, '_get_auth', autospec=True)
def test_get_err_engine(self, mock_auth, mock_transport, mock_cmdgen):
var_bind = (self.oid, self.value)
mock_cmdgenerator = mock_cmdgen.return_value
@@ -123,8 +123,8 @@ class SNMPClientTestCase(base.TestCase):
mock_cmdgenerator.getCmd.assert_called_once_with(mock.ANY, mock.ANY,
self.oid)
@mock.patch.object(snmp.SNMPClient, '_get_transport')
@mock.patch.object(snmp.SNMPClient, '_get_auth')
@mock.patch.object(snmp.SNMPClient, '_get_transport', autospec=True)
@mock.patch.object(snmp.SNMPClient, '_get_auth', autospec=True)
def test_set(self, mock_auth, mock_transport, mock_cmdgen):
var_bind = (self.oid, self.value)
mock_cmdgenerator = mock_cmdgen.return_value
@@ -134,8 +134,8 @@ class SNMPClientTestCase(base.TestCase):
mock_cmdgenerator.setCmd.assert_called_once_with(mock.ANY, mock.ANY,
var_bind)
@mock.patch.object(snmp.SNMPClient, '_get_transport')
@mock.patch.object(snmp.SNMPClient, '_get_auth')
@mock.patch.object(snmp.SNMPClient, '_get_transport', autospec=True)
@mock.patch.object(snmp.SNMPClient, '_get_auth', autospec=True)
def test_set_err_transport(self, mock_auth, mock_transport, mock_cmdgen):
mock_transport.side_effect = snmp_error.PySnmpError
var_bind = (self.oid, self.value)
@@ -147,8 +147,8 @@ class SNMPClientTestCase(base.TestCase):
client.set, self.oid, self.value)
self.assertFalse(mock_cmdgenerator.setCmd.called)
@mock.patch.object(snmp.SNMPClient, '_get_transport')
@mock.patch.object(snmp.SNMPClient, '_get_auth')
@mock.patch.object(snmp.SNMPClient, '_get_transport', autospec=True)
@mock.patch.object(snmp.SNMPClient, '_get_auth', autospec=True)
def test_set_err_engine(self, mock_auth, mock_transport, mock_cmdgen):
var_bind = (self.oid, self.value)
mock_cmdgenerator = mock_cmdgen.return_value
@@ -351,7 +351,7 @@ class SNMPValidateParametersTestCase(db_base.DbTestCase):
node)
@mock.patch.object(snmp, '_get_client')
@mock.patch.object(snmp, '_get_client', autospec=True)
class SNMPDeviceDriverTestCase(db_base.DbTestCase):
"""Tests for the SNMP device-specific driver classes.
@@ -433,7 +433,7 @@ class SNMPDeviceDriverTestCase(db_base.DbTestCase):
mock_client.get.assert_called_once_with(driver._snmp_oid())
self.assertEqual(states.POWER_OFF, pstate)
@mock.patch("eventlet.greenthread.sleep")
@mock.patch("eventlet.greenthread.sleep", autospec=True)
def test_power_on_delay(self, mock_sleep, mock_get_client):
# Ensure driver waits for the state to change following a power on
mock_client = mock_get_client.return_value
@@ -447,7 +447,7 @@ class SNMPDeviceDriverTestCase(db_base.DbTestCase):
mock_client.get.assert_has_calls(calls)
self.assertEqual(states.POWER_ON, pstate)
@mock.patch("eventlet.greenthread.sleep")
@mock.patch("eventlet.greenthread.sleep", autospec=True)
def test_power_off_delay(self, mock_sleep, mock_get_client):
# Ensure driver waits for the state to change following a power off
mock_client = mock_get_client.return_value
@@ -461,7 +461,7 @@ class SNMPDeviceDriverTestCase(db_base.DbTestCase):
mock_client.get.assert_has_calls(calls)
self.assertEqual(states.POWER_OFF, pstate)
@mock.patch("eventlet.greenthread.sleep")
@mock.patch("eventlet.greenthread.sleep", autospec=True)
def test_power_on_invalid_state(self, mock_sleep, mock_get_client):
# Ensure driver retries when querying unexpected states following a
# power on
@@ -476,7 +476,7 @@ class SNMPDeviceDriverTestCase(db_base.DbTestCase):
mock_client.get.assert_has_calls(calls)
self.assertEqual(states.ERROR, pstate)
@mock.patch("eventlet.greenthread.sleep")
@mock.patch("eventlet.greenthread.sleep", autospec=True)
def test_power_off_invalid_state(self, mock_sleep, mock_get_client):
# Ensure driver retries when querying unexpected states following a
# power off
@@ -537,7 +537,7 @@ class SNMPDeviceDriverTestCase(db_base.DbTestCase):
driver.value_power_off)
mock_client.get.assert_called_once_with(driver._snmp_oid())
@mock.patch("eventlet.greenthread.sleep")
@mock.patch("eventlet.greenthread.sleep", autospec=True)
def test_power_on_timeout(self, mock_sleep, mock_get_client):
# Ensure that a power on consistency poll timeout causes an error
mock_client = mock_get_client.return_value
@@ -551,7 +551,7 @@ class SNMPDeviceDriverTestCase(db_base.DbTestCase):
mock_client.get.assert_has_calls(calls)
self.assertEqual(states.ERROR, pstate)
@mock.patch("eventlet.greenthread.sleep")
@mock.patch("eventlet.greenthread.sleep", autospec=True)
def test_power_off_timeout(self, mock_sleep, mock_get_client):
# Ensure that a power off consistency poll timeout causes an error
mock_client = mock_get_client.return_value
@@ -580,7 +580,7 @@ class SNMPDeviceDriverTestCase(db_base.DbTestCase):
mock_client.get.assert_has_calls(calls)
self.assertEqual(states.POWER_ON, pstate)
@mock.patch("eventlet.greenthread.sleep")
@mock.patch("eventlet.greenthread.sleep", autospec=True)
def test_power_reset_off_delay(self, mock_sleep, mock_get_client):
# Ensure driver waits for the power off state change following a power
# reset
@@ -597,7 +597,7 @@ class SNMPDeviceDriverTestCase(db_base.DbTestCase):
mock_client.get.assert_has_calls(calls)
self.assertEqual(states.POWER_ON, pstate)
@mock.patch("eventlet.greenthread.sleep")
@mock.patch("eventlet.greenthread.sleep", autospec=True)
def test_power_reset_on_delay(self, mock_sleep, mock_get_client):
# Ensure driver waits for the power on state change following a power
# reset
@@ -614,7 +614,7 @@ class SNMPDeviceDriverTestCase(db_base.DbTestCase):
mock_client.get.assert_has_calls(calls)
self.assertEqual(states.POWER_ON, pstate)
@mock.patch("eventlet.greenthread.sleep")
@mock.patch("eventlet.greenthread.sleep", autospec=True)
def test_power_reset_off_delay_on_delay(self, mock_sleep, mock_get_client):
# Ensure driver waits for both state changes following a power reset
mock_client = mock_get_client.return_value
@@ -631,7 +631,7 @@ class SNMPDeviceDriverTestCase(db_base.DbTestCase):
mock_client.get.assert_has_calls(calls)
self.assertEqual(states.POWER_ON, pstate)
@mock.patch("eventlet.greenthread.sleep")
@mock.patch("eventlet.greenthread.sleep", autospec=True)
def test_power_reset_off_invalid_state(self, mock_sleep, mock_get_client):
# Ensure driver retries when querying unexpected states following a
# power off during a reset
@@ -646,7 +646,7 @@ class SNMPDeviceDriverTestCase(db_base.DbTestCase):
mock_client.get.assert_has_calls(calls)
self.assertEqual(states.ERROR, pstate)
@mock.patch("eventlet.greenthread.sleep")
@mock.patch("eventlet.greenthread.sleep", autospec=True)
def test_power_reset_on_invalid_state(self, mock_sleep, mock_get_client):
# Ensure driver retries when querying unexpected states following a
# power on during a reset
@@ -663,7 +663,7 @@ class SNMPDeviceDriverTestCase(db_base.DbTestCase):
mock_client.get.assert_has_calls(calls)
self.assertEqual(states.ERROR, pstate)
@mock.patch("eventlet.greenthread.sleep")
@mock.patch("eventlet.greenthread.sleep", autospec=True)
def test_power_reset_off_timeout(self, mock_sleep, mock_get_client):
# Ensure that a power off consistency poll timeout during a reset
# causes an error
@@ -678,7 +678,7 @@ class SNMPDeviceDriverTestCase(db_base.DbTestCase):
mock_client.get.assert_has_calls(calls)
self.assertEqual(states.ERROR, pstate)
@mock.patch("eventlet.greenthread.sleep")
@mock.patch("eventlet.greenthread.sleep", autospec=True)
def test_power_reset_on_timeout(self, mock_sleep, mock_get_client):
# Ensure that a power on consistency poll timeout during a reset
# causes an error
@@ -1016,7 +1016,7 @@ class SNMPDeviceDriverTestCase(db_base.DbTestCase):
self.assertEqual(states.POWER_ON, pstate)
@mock.patch.object(snmp, '_get_driver')
@mock.patch.object(snmp, '_get_driver', autospec=True)
class SNMPDriverTestCase(db_base.DbTestCase):
"""SNMP power driver interface tests.
+116 -116
View File
@@ -201,7 +201,7 @@ class SSHPrivateMethodsTestCase(db_base.DbTestCase):
driver_info=db_utils.get_test_ssh_info())
self.sshclient = paramiko.SSHClient()
@mock.patch.object(utils, 'ssh_connect')
@mock.patch.object(utils, 'ssh_connect', autospec=True)
def test__get_connection_client(self, ssh_connect_mock):
ssh_connect_mock.return_value = self.sshclient
client = ssh._get_connection(self.node)
@@ -209,7 +209,7 @@ class SSHPrivateMethodsTestCase(db_base.DbTestCase):
driver_info = ssh._parse_driver_info(self.node)
ssh_connect_mock.assert_called_once_with(driver_info)
@mock.patch.object(utils, 'ssh_connect')
@mock.patch.object(utils, 'ssh_connect', autospec=True)
def test__get_connection_exception(self, ssh_connect_mock):
ssh_connect_mock.side_effect = exception.SSHConnectFailed(host='fake')
self.assertRaises(exception.SSHConnectFailed,
@@ -218,7 +218,7 @@ class SSHPrivateMethodsTestCase(db_base.DbTestCase):
driver_info = ssh._parse_driver_info(self.node)
ssh_connect_mock.assert_called_once_with(driver_info)
@mock.patch.object(processutils, 'ssh_execute')
@mock.patch.object(processutils, 'ssh_execute', autospec=True)
def test__ssh_execute(self, exec_ssh_mock):
ssh_cmd = "somecmd"
expected = ['a', 'b', 'c']
@@ -227,7 +227,7 @@ class SSHPrivateMethodsTestCase(db_base.DbTestCase):
exec_ssh_mock.assert_called_once_with(self.sshclient, ssh_cmd)
self.assertEqual(expected, lst)
@mock.patch.object(processutils, 'ssh_execute')
@mock.patch.object(processutils, 'ssh_execute', autospec=True)
def test__ssh_execute_exception(self, exec_ssh_mock):
ssh_cmd = "somecmd"
exec_ssh_mock.side_effect = processutils.ProcessExecutionError
@@ -237,8 +237,8 @@ class SSHPrivateMethodsTestCase(db_base.DbTestCase):
ssh_cmd)
exec_ssh_mock.assert_called_once_with(self.sshclient, ssh_cmd)
@mock.patch.object(processutils, 'ssh_execute')
@mock.patch.object(ssh, '_get_hosts_name_for_node')
@mock.patch.object(processutils, 'ssh_execute', autospec=True)
@mock.patch.object(ssh, '_get_hosts_name_for_node', autospec=True)
def test__get_power_status_on(self, get_hosts_name_mock, exec_ssh_mock):
info = ssh._parse_driver_info(self.node)
exec_ssh_mock.return_value = (
@@ -253,8 +253,8 @@ class SSHPrivateMethodsTestCase(db_base.DbTestCase):
exec_ssh_mock.assert_called_once_with(self.sshclient, ssh_cmd)
get_hosts_name_mock.assert_called_once_with(self.sshclient, info)
@mock.patch.object(processutils, 'ssh_execute')
@mock.patch.object(ssh, '_get_hosts_name_for_node')
@mock.patch.object(processutils, 'ssh_execute', autospec=True)
@mock.patch.object(ssh, '_get_hosts_name_for_node', autospec=True)
def test__get_power_status_off(self, get_hosts_name_mock, exec_ssh_mock):
info = ssh._parse_driver_info(self.node)
exec_ssh_mock.return_value = (
@@ -269,8 +269,8 @@ class SSHPrivateMethodsTestCase(db_base.DbTestCase):
exec_ssh_mock.assert_called_once_with(self.sshclient, ssh_cmd)
get_hosts_name_mock.assert_called_once_with(self.sshclient, info)
@mock.patch.object(processutils, 'ssh_execute')
@mock.patch.object(ssh, '_get_hosts_name_for_node')
@mock.patch.object(processutils, 'ssh_execute', autospec=True)
@mock.patch.object(ssh, '_get_hosts_name_for_node', autospec=True)
def test__get_power_status_error(self, get_hosts_name_mock, exec_ssh_mock):
info = ssh._parse_driver_info(self.node)
@@ -285,7 +285,7 @@ class SSHPrivateMethodsTestCase(db_base.DbTestCase):
get_hosts_name_mock.assert_called_once_with(self.sshclient, info)
self.assertFalse(exec_ssh_mock.called)
@mock.patch.object(processutils, 'ssh_execute')
@mock.patch.object(processutils, 'ssh_execute', autospec=True)
def test__get_power_status_exception(self, exec_ssh_mock):
info = ssh._parse_driver_info(self.node)
exec_ssh_mock.side_effect = processutils.ProcessExecutionError
@@ -299,8 +299,8 @@ class SSHPrivateMethodsTestCase(db_base.DbTestCase):
exec_ssh_mock.assert_called_once_with(
self.sshclient, ssh_cmd)
@mock.patch.object(processutils, 'ssh_execute')
@mock.patch.object(ssh, '_get_hosts_name_for_node')
@mock.patch.object(processutils, 'ssh_execute', autospec=True)
@mock.patch.object(ssh, '_get_hosts_name_for_node', autospec=True)
def test__get_power_status_correct_node(self, get_hosts_name_mock,
exec_ssh_mock):
# Bug: #1397834 test that get_power_status return status of
@@ -312,7 +312,7 @@ class SSHPrivateMethodsTestCase(db_base.DbTestCase):
pstate = ssh._get_power_status(self.sshclient, info)
self.assertEqual(states.POWER_OFF, pstate)
@mock.patch.object(processutils, 'ssh_execute')
@mock.patch.object(processutils, 'ssh_execute', autospec=True)
def test__get_hosts_name_for_node_match(self, exec_ssh_mock):
info = ssh._parse_driver_info(self.node)
info['macs'] = ["11:11:11:11:11:11", "52:54:00:cf:2d:31"]
@@ -322,8 +322,8 @@ class SSHPrivateMethodsTestCase(db_base.DbTestCase):
cmd_to_exec = "%s %s" % (info['cmd_set']['base_cmd'],
info['cmd_set']['get_node_macs'])
cmd_to_exec = cmd_to_exec.replace('{_NodeName_}', 'NodeName')
exec_ssh_mock.side_effect = [('NodeName', ''),
('52:54:00:cf:2d:31', '')]
exec_ssh_mock.side_effect = iter([('NodeName', ''),
('52:54:00:cf:2d:31', '')])
expected = [mock.call(self.sshclient, ssh_cmd),
mock.call(self.sshclient, cmd_to_exec)]
@@ -332,12 +332,12 @@ class SSHPrivateMethodsTestCase(db_base.DbTestCase):
self.assertEqual('NodeName', found_name)
self.assertEqual(expected, exec_ssh_mock.call_args_list)
@mock.patch.object(processutils, 'ssh_execute')
@mock.patch.object(processutils, 'ssh_execute', autospec=True)
def test__get_hosts_name_for_node_no_match(self, exec_ssh_mock):
info = ssh._parse_driver_info(self.node)
info['macs'] = ["11:11:11:11:11:11", "22:22:22:22:22:22"]
exec_ssh_mock.side_effect = [('NodeName', ''),
('52:54:00:cf:2d:31', '')]
exec_ssh_mock.side_effect = iter([('NodeName', ''),
('52:54:00:cf:2d:31', '')])
ssh_cmd = "%s %s" % (info['cmd_set']['base_cmd'],
info['cmd_set']['list_all'])
@@ -354,7 +354,7 @@ class SSHPrivateMethodsTestCase(db_base.DbTestCase):
self.assertIsNone(found_name)
self.assertEqual(expected, exec_ssh_mock.call_args_list)
@mock.patch.object(processutils, 'ssh_execute')
@mock.patch.object(processutils, 'ssh_execute', autospec=True)
def test__get_hosts_name_for_node_exception(self, exec_ssh_mock):
info = ssh._parse_driver_info(self.node)
info['macs'] = ["11:11:11:11:11:11", "52:54:00:cf:2d:31"]
@@ -365,8 +365,8 @@ class SSHPrivateMethodsTestCase(db_base.DbTestCase):
info['cmd_set']['get_node_macs'])
cmd_to_exec = cmd_to_exec.replace('{_NodeName_}', 'NodeName')
exec_ssh_mock.side_effect = [('NodeName', ''),
processutils.ProcessExecutionError]
exec_ssh_mock.side_effect = iter([('NodeName', ''),
processutils.ProcessExecutionError])
expected = [mock.call(self.sshclient, ssh_cmd),
mock.call(self.sshclient, cmd_to_exec)]
@@ -376,16 +376,16 @@ class SSHPrivateMethodsTestCase(db_base.DbTestCase):
info)
self.assertEqual(expected, exec_ssh_mock.call_args_list)
@mock.patch.object(processutils, 'ssh_execute')
@mock.patch.object(ssh, '_get_power_status')
@mock.patch.object(ssh, '_get_hosts_name_for_node')
@mock.patch.object(processutils, 'ssh_execute', autospec=True)
@mock.patch.object(ssh, '_get_power_status', autospec=True)
@mock.patch.object(ssh, '_get_hosts_name_for_node', autospec=True)
def test__power_on_good(self, get_hosts_name_mock, get_power_status_mock,
exec_ssh_mock):
info = ssh._parse_driver_info(self.node)
info['macs'] = ["11:11:11:11:11:11", "52:54:00:cf:2d:31"]
get_power_status_mock.side_effect = [states.POWER_OFF,
states.POWER_ON]
get_power_status_mock.side_effect = iter([states.POWER_OFF,
states.POWER_ON])
get_hosts_name_mock.return_value = "NodeName"
expected = [mock.call(self.sshclient, info),
mock.call(self.sshclient, info)]
@@ -400,15 +400,15 @@ class SSHPrivateMethodsTestCase(db_base.DbTestCase):
get_hosts_name_mock.assert_called_once_with(self.sshclient, info)
exec_ssh_mock.assert_called_once_with(self.sshclient, cmd_to_exec)
@mock.patch.object(processutils, 'ssh_execute')
@mock.patch.object(ssh, '_get_power_status')
@mock.patch.object(ssh, '_get_hosts_name_for_node')
@mock.patch.object(processutils, 'ssh_execute', autospec=True)
@mock.patch.object(ssh, '_get_power_status', autospec=True)
@mock.patch.object(ssh, '_get_hosts_name_for_node', autospec=True)
def test__power_on_fail(self, get_hosts_name_mock, get_power_status_mock,
exec_ssh_mock):
info = ssh._parse_driver_info(self.node)
info['macs'] = ["11:11:11:11:11:11", "52:54:00:cf:2d:31"]
get_power_status_mock.side_effect = [states.POWER_OFF,
states.POWER_OFF]
get_power_status_mock.side_effect = iter([states.POWER_OFF,
states.POWER_OFF])
get_hosts_name_mock.return_value = "NodeName"
expected = [mock.call(self.sshclient, info),
mock.call(self.sshclient, info)]
@@ -423,17 +423,17 @@ class SSHPrivateMethodsTestCase(db_base.DbTestCase):
get_hosts_name_mock.assert_called_once_with(self.sshclient, info)
exec_ssh_mock.assert_called_once_with(self.sshclient, cmd_to_exec)
@mock.patch.object(processutils, 'ssh_execute')
@mock.patch.object(ssh, '_get_power_status')
@mock.patch.object(ssh, '_get_hosts_name_for_node')
@mock.patch.object(processutils, 'ssh_execute', autospec=True)
@mock.patch.object(ssh, '_get_power_status', autospec=True)
@mock.patch.object(ssh, '_get_hosts_name_for_node', autospec=True)
def test__power_on_exception(self, get_hosts_name_mock,
get_power_status_mock, exec_ssh_mock):
info = ssh._parse_driver_info(self.node)
info['macs'] = ["11:11:11:11:11:11", "52:54:00:cf:2d:31"]
exec_ssh_mock.side_effect = processutils.ProcessExecutionError
get_power_status_mock.side_effect = [states.POWER_OFF,
states.POWER_ON]
get_power_status_mock.side_effect = iter([states.POWER_OFF,
states.POWER_ON])
get_hosts_name_mock.return_value = "NodeName"
cmd_to_exec = "%s %s" % (info['cmd_set']['base_cmd'],
@@ -448,15 +448,15 @@ class SSHPrivateMethodsTestCase(db_base.DbTestCase):
get_hosts_name_mock.assert_called_once_with(self.sshclient, info)
exec_ssh_mock.assert_called_once_with(self.sshclient, cmd_to_exec)
@mock.patch.object(processutils, 'ssh_execute')
@mock.patch.object(ssh, '_get_power_status')
@mock.patch.object(ssh, '_get_hosts_name_for_node')
@mock.patch.object(processutils, 'ssh_execute', autospec=True)
@mock.patch.object(ssh, '_get_power_status', autospec=True)
@mock.patch.object(ssh, '_get_hosts_name_for_node', autospec=True)
def test__power_off_good(self, get_hosts_name_mock,
get_power_status_mock, exec_ssh_mock):
info = ssh._parse_driver_info(self.node)
info['macs'] = ["11:11:11:11:11:11", "52:54:00:cf:2d:31"]
get_power_status_mock.side_effect = [states.POWER_ON,
states.POWER_OFF]
get_power_status_mock.side_effect = iter([states.POWER_ON,
states.POWER_OFF])
get_hosts_name_mock.return_value = "NodeName"
expected = [mock.call(self.sshclient, info),
mock.call(self.sshclient, info)]
@@ -471,15 +471,15 @@ class SSHPrivateMethodsTestCase(db_base.DbTestCase):
get_hosts_name_mock.assert_called_once_with(self.sshclient, info)
exec_ssh_mock.assert_called_once_with(self.sshclient, cmd_to_exec)
@mock.patch.object(processutils, 'ssh_execute')
@mock.patch.object(ssh, '_get_power_status')
@mock.patch.object(ssh, '_get_hosts_name_for_node')
@mock.patch.object(processutils, 'ssh_execute', autospec=True)
@mock.patch.object(ssh, '_get_power_status', autospec=True)
@mock.patch.object(ssh, '_get_hosts_name_for_node', autospec=True)
def test__power_off_fail(self, get_hosts_name_mock,
get_power_status_mock, exec_ssh_mock):
info = ssh._parse_driver_info(self.node)
info['macs'] = ["11:11:11:11:11:11", "52:54:00:cf:2d:31"]
get_power_status_mock.side_effect = [states.POWER_ON,
states.POWER_ON]
get_power_status_mock.side_effect = iter([states.POWER_ON,
states.POWER_ON])
get_hosts_name_mock.return_value = "NodeName"
expected = [mock.call(self.sshclient, info),
mock.call(self.sshclient, info)]
@@ -494,16 +494,16 @@ class SSHPrivateMethodsTestCase(db_base.DbTestCase):
get_hosts_name_mock.assert_called_once_with(self.sshclient, info)
exec_ssh_mock.assert_called_once_with(self.sshclient, cmd_to_exec)
@mock.patch.object(processutils, 'ssh_execute')
@mock.patch.object(ssh, '_get_power_status')
@mock.patch.object(ssh, '_get_hosts_name_for_node')
@mock.patch.object(processutils, 'ssh_execute', autospec=True)
@mock.patch.object(ssh, '_get_power_status', autospec=True)
@mock.patch.object(ssh, '_get_hosts_name_for_node', autospec=True)
def test__power_off_exception(self, get_hosts_name_mock,
get_power_status_mock, exec_ssh_mock):
info = ssh._parse_driver_info(self.node)
info['macs'] = ["11:11:11:11:11:11", "52:54:00:cf:2d:31"]
exec_ssh_mock.side_effect = processutils.ProcessExecutionError
get_power_status_mock.side_effect = [states.POWER_ON,
states.POWER_OFF]
get_power_status_mock.side_effect = iter([states.POWER_ON,
states.POWER_OFF])
get_hosts_name_mock.return_value = "NodeName"
cmd_to_exec = "%s %s" % (info['cmd_set']['base_cmd'],
@@ -532,8 +532,8 @@ class SSHPrivateMethodsTestCase(db_base.DbTestCase):
def close(self):
pass
with mock.patch.object(self.sshclient,
'exec_command') as exec_command_mock:
with mock.patch.object(self.sshclient, 'exec_command',
autospec=True) as exec_command_mock:
exec_command_mock.return_value = (Stream(),
Stream('hello'),
Stream())
@@ -559,8 +559,8 @@ class SSHPrivateMethodsTestCase(db_base.DbTestCase):
def close(self):
pass
with mock.patch.object(self.sshclient,
'exec_command') as exec_command_mock:
with mock.patch.object(self.sshclient, 'exec_command',
autospec=True) as exec_command_mock:
exec_command_mock.return_value = (Stream(),
Stream('hello'),
Stream())
@@ -584,7 +584,7 @@ class SSHDriverTestCase(db_base.DbTestCase):
node_id=self.node.id)
self.sshclient = paramiko.SSHClient()
@mock.patch.object(utils, 'ssh_connect')
@mock.patch.object(utils, 'ssh_connect', autospec=True)
def test__validate_info_ssh_connect_failed(self, ssh_connect_mock):
info = ssh._parse_driver_info(self.node)
@@ -616,9 +616,9 @@ class SSHDriverTestCase(db_base.DbTestCase):
task.driver.power.validate,
task)
@mock.patch.object(driver_utils, 'get_node_mac_addresses')
@mock.patch.object(ssh, '_get_connection')
@mock.patch.object(ssh, '_power_on')
@mock.patch.object(driver_utils, 'get_node_mac_addresses', autospec=True)
@mock.patch.object(ssh, '_get_connection', autospec=True)
@mock.patch.object(ssh, '_power_on', autospec=True)
def test_reboot_good(self, power_on_mock, get_conn_mock,
get_mac_addr_mock):
info = ssh._parse_driver_info(self.node)
@@ -626,8 +626,8 @@ class SSHDriverTestCase(db_base.DbTestCase):
get_mac_addr_mock.return_value = info['macs']
get_conn_mock.return_value = self.sshclient
power_on_mock.return_value = states.POWER_ON
with mock.patch.object(ssh,
'_parse_driver_info') as parse_drv_info_mock:
with mock.patch.object(ssh, '_parse_driver_info',
autospec=True) as parse_drv_info_mock:
parse_drv_info_mock.return_value = info
with task_manager.acquire(self.context, info['uuid'],
shared=False) as task:
@@ -638,9 +638,9 @@ class SSHDriverTestCase(db_base.DbTestCase):
get_conn_mock.assert_called_once_with(task.node)
power_on_mock.assert_called_once_with(self.sshclient, info)
@mock.patch.object(driver_utils, 'get_node_mac_addresses')
@mock.patch.object(ssh, '_get_connection')
@mock.patch.object(ssh, '_power_on')
@mock.patch.object(driver_utils, 'get_node_mac_addresses', autospec=True)
@mock.patch.object(ssh, '_get_connection', autospec=True)
@mock.patch.object(ssh, '_power_on', autospec=True)
def test_reboot_fail(self, power_on_mock, get_conn_mock,
get_mac_addr_mock):
info = ssh._parse_driver_info(self.node)
@@ -648,8 +648,8 @@ class SSHDriverTestCase(db_base.DbTestCase):
get_mac_addr_mock.return_value = info['macs']
get_conn_mock.return_value = self.sshclient
power_on_mock.return_value = states.POWER_OFF
with mock.patch.object(ssh,
'_parse_driver_info') as parse_drv_info_mock:
with mock.patch.object(ssh, '_parse_driver_info',
autospec=True) as parse_drv_info_mock:
parse_drv_info_mock.return_value = info
with task_manager.acquire(self.context, info['uuid'],
shared=False) as task:
@@ -660,16 +660,16 @@ class SSHDriverTestCase(db_base.DbTestCase):
get_conn_mock.assert_called_once_with(task.node)
power_on_mock.assert_called_once_with(self.sshclient, info)
@mock.patch.object(driver_utils, 'get_node_mac_addresses')
@mock.patch.object(ssh, '_get_connection')
@mock.patch.object(driver_utils, 'get_node_mac_addresses', autospec=True)
@mock.patch.object(ssh, '_get_connection', autospec=True)
def test_set_power_state_bad_state(self, get_conn_mock,
get_mac_addr_mock):
info = ssh._parse_driver_info(self.node)
info['macs'] = ["11:11:11:11:11:11", "52:54:00:cf:2d:31"]
get_mac_addr_mock.return_value = info['macs']
get_conn_mock.return_value = self.sshclient
with mock.patch.object(ssh,
'_parse_driver_info') as parse_drv_info_mock:
with mock.patch.object(ssh, '_parse_driver_info',
autospec=True) as parse_drv_info_mock:
parse_drv_info_mock.return_value = info
with task_manager.acquire(self.context, info['uuid'],
shared=False) as task:
@@ -683,9 +683,9 @@ class SSHDriverTestCase(db_base.DbTestCase):
get_mac_addr_mock.assert_called_once_with(mock.ANY)
get_conn_mock.assert_called_once_with(task.node)
@mock.patch.object(driver_utils, 'get_node_mac_addresses')
@mock.patch.object(ssh, '_get_connection')
@mock.patch.object(ssh, '_power_on')
@mock.patch.object(driver_utils, 'get_node_mac_addresses', autospec=True)
@mock.patch.object(ssh, '_get_connection', autospec=True)
@mock.patch.object(ssh, '_power_on', autospec=True)
def test_set_power_state_on_good(self, power_on_mock, get_conn_mock,
get_mac_addr_mock):
info = ssh._parse_driver_info(self.node)
@@ -693,8 +693,8 @@ class SSHDriverTestCase(db_base.DbTestCase):
get_mac_addr_mock.return_value = info['macs']
get_conn_mock.return_value = self.sshclient
power_on_mock.return_value = states.POWER_ON
with mock.patch.object(ssh,
'_parse_driver_info') as parse_drv_info_mock:
with mock.patch.object(ssh, '_parse_driver_info',
autospec=True) as parse_drv_info_mock:
parse_drv_info_mock.return_value = info
with task_manager.acquire(self.context, info['uuid'],
shared=False) as task:
@@ -705,9 +705,9 @@ class SSHDriverTestCase(db_base.DbTestCase):
get_conn_mock.assert_called_once_with(task.node)
power_on_mock.assert_called_once_with(self.sshclient, info)
@mock.patch.object(driver_utils, 'get_node_mac_addresses')
@mock.patch.object(ssh, '_get_connection')
@mock.patch.object(ssh, '_power_on')
@mock.patch.object(driver_utils, 'get_node_mac_addresses', autospec=True)
@mock.patch.object(ssh, '_get_connection', autospec=True)
@mock.patch.object(ssh, '_power_on', autospec=True)
def test_set_power_state_on_fail(self, power_on_mock, get_conn_mock,
get_mac_addr_mock):
info = ssh._parse_driver_info(self.node)
@@ -715,8 +715,8 @@ class SSHDriverTestCase(db_base.DbTestCase):
get_mac_addr_mock.return_value = info['macs']
get_conn_mock.return_value = self.sshclient
power_on_mock.return_value = states.POWER_OFF
with mock.patch.object(ssh,
'_parse_driver_info') as parse_drv_info_mock:
with mock.patch.object(ssh, '_parse_driver_info',
autospec=True) as parse_drv_info_mock:
parse_drv_info_mock.return_value = info
with task_manager.acquire(self.context, info['uuid'],
shared=False) as task:
@@ -731,9 +731,9 @@ class SSHDriverTestCase(db_base.DbTestCase):
get_conn_mock.assert_called_once_with(task.node)
power_on_mock.assert_called_once_with(self.sshclient, info)
@mock.patch.object(driver_utils, 'get_node_mac_addresses')
@mock.patch.object(ssh, '_get_connection')
@mock.patch.object(ssh, '_power_off')
@mock.patch.object(driver_utils, 'get_node_mac_addresses', autospec=True)
@mock.patch.object(ssh, '_get_connection', autospec=True)
@mock.patch.object(ssh, '_power_off', autospec=True)
def test_set_power_state_off_good(self, power_off_mock, get_conn_mock,
get_mac_addr_mock):
info = ssh._parse_driver_info(self.node)
@@ -741,8 +741,8 @@ class SSHDriverTestCase(db_base.DbTestCase):
get_mac_addr_mock.return_value = info['macs']
get_conn_mock.return_value = self.sshclient
power_off_mock.return_value = states.POWER_OFF
with mock.patch.object(ssh,
'_parse_driver_info') as parse_drv_info_mock:
with mock.patch.object(ssh, '_parse_driver_info',
autospec=True) as parse_drv_info_mock:
parse_drv_info_mock.return_value = info
with task_manager.acquire(self.context, info['uuid'],
shared=False) as task:
@@ -753,9 +753,9 @@ class SSHDriverTestCase(db_base.DbTestCase):
get_conn_mock.assert_called_once_with(task.node)
power_off_mock.assert_called_once_with(self.sshclient, info)
@mock.patch.object(driver_utils, 'get_node_mac_addresses')
@mock.patch.object(ssh, '_get_connection')
@mock.patch.object(ssh, '_power_off')
@mock.patch.object(driver_utils, 'get_node_mac_addresses', autospec=True)
@mock.patch.object(ssh, '_get_connection', autospec=True)
@mock.patch.object(ssh, '_power_off', autospec=True)
def test_set_power_state_off_fail(self, power_off_mock, get_conn_mock,
get_mac_addr_mock):
info = ssh._parse_driver_info(self.node)
@@ -763,8 +763,8 @@ class SSHDriverTestCase(db_base.DbTestCase):
get_mac_addr_mock.return_value = info['macs']
get_conn_mock.return_value = self.sshclient
power_off_mock.return_value = states.POWER_ON
with mock.patch.object(ssh,
'_parse_driver_info') as parse_drv_info_mock:
with mock.patch.object(ssh, '_parse_driver_info',
autospec=True) as parse_drv_info_mock:
parse_drv_info_mock.return_value = info
with task_manager.acquire(self.context, info['uuid'],
shared=False) as task:
@@ -779,9 +779,9 @@ class SSHDriverTestCase(db_base.DbTestCase):
get_conn_mock.assert_called_once_with(task.node)
power_off_mock.assert_called_once_with(self.sshclient, info)
@mock.patch.object(ssh, '_get_connection')
@mock.patch.object(ssh, '_get_hosts_name_for_node')
@mock.patch.object(ssh, '_ssh_execute')
@mock.patch.object(ssh, '_get_connection', autospec=True)
@mock.patch.object(ssh, '_get_hosts_name_for_node', autospec=True)
@mock.patch.object(ssh, '_ssh_execute', autospec=True)
def test_management_interface_set_boot_device_vbox_ok(self, mock_exc,
mock_h,
mock_get_conn):
@@ -795,9 +795,9 @@ class SSHDriverTestCase(db_base.DbTestCase):
'--boot1 net') % fake_name
mock_exc.assert_called_once_with(mock.ANY, expected_cmd)
@mock.patch.object(ssh, '_get_connection')
@mock.patch.object(ssh, '_get_hosts_name_for_node')
@mock.patch.object(ssh, '_ssh_execute')
@mock.patch.object(ssh, '_get_connection', autospec=True)
@mock.patch.object(ssh, '_get_hosts_name_for_node', autospec=True)
@mock.patch.object(ssh, '_ssh_execute', autospec=True)
def test_management_interface_set_boot_device_parallels_ok(self, mock_exc,
mock_h,
mock_get_conn):
@@ -811,9 +811,9 @@ class SSHDriverTestCase(db_base.DbTestCase):
'--device-bootorder "net0"') % fake_name
mock_exc.assert_called_once_with(mock.ANY, expected_cmd)
@mock.patch.object(ssh, '_get_connection')
@mock.patch.object(ssh, '_get_hosts_name_for_node')
@mock.patch.object(ssh, '_ssh_execute')
@mock.patch.object(ssh, '_get_connection', autospec=True)
@mock.patch.object(ssh, '_get_hosts_name_for_node', autospec=True)
@mock.patch.object(ssh, '_ssh_execute', autospec=True)
def test_management_interface_set_boot_device_virsh_ok(self, mock_exc,
mock_h,
mock_get_conn):
@@ -835,8 +835,8 @@ class SSHDriverTestCase(db_base.DbTestCase):
self.driver.management.set_boot_device,
task, 'invalid-device')
@mock.patch.object(ssh, '_get_connection')
@mock.patch.object(ssh, '_get_hosts_name_for_node')
@mock.patch.object(ssh, '_get_connection', autospec=True)
@mock.patch.object(ssh, '_get_hosts_name_for_node', autospec=True)
def test_set_boot_device_not_supported(self, mock_h, mock_get_conn):
mock_h.return_value = 'NodeName'
mock_get_conn.return_value = self.sshclient
@@ -854,9 +854,9 @@ class SSHDriverTestCase(db_base.DbTestCase):
self.assertEqual(sorted(expected), sorted(task.driver.management.
get_supported_boot_devices()))
@mock.patch.object(ssh, '_get_connection')
@mock.patch.object(ssh, '_get_hosts_name_for_node')
@mock.patch.object(ssh, '_ssh_execute')
@mock.patch.object(ssh, '_get_connection', autospec=True)
@mock.patch.object(ssh, '_get_hosts_name_for_node', autospec=True)
@mock.patch.object(ssh, '_ssh_execute', autospec=True)
def test_management_interface_get_boot_device_vbox(self, mock_exc,
mock_h,
mock_get_conn):
@@ -873,9 +873,9 @@ class SSHDriverTestCase(db_base.DbTestCase):
'| awk -F \'"\' \'/boot1/{print $2}\'') % fake_name
mock_exc.assert_called_once_with(mock.ANY, expected_cmd)
@mock.patch.object(ssh, '_get_connection')
@mock.patch.object(ssh, '_get_hosts_name_for_node')
@mock.patch.object(ssh, '_ssh_execute')
@mock.patch.object(ssh, '_get_connection', autospec=True)
@mock.patch.object(ssh, '_get_hosts_name_for_node', autospec=True)
@mock.patch.object(ssh, '_ssh_execute', autospec=True)
def test_management_interface_get_boot_device_parallels(self, mock_exc,
mock_h,
mock_get_conn):
@@ -891,9 +891,9 @@ class SSHDriverTestCase(db_base.DbTestCase):
'| awk \'/^Boot order:/ {print $3}\'') % fake_name
mock_exc.assert_called_once_with(mock.ANY, expected_cmd)
@mock.patch.object(ssh, '_get_connection')
@mock.patch.object(ssh, '_get_hosts_name_for_node')
@mock.patch.object(ssh, '_ssh_execute')
@mock.patch.object(ssh, '_get_connection', autospec=True)
@mock.patch.object(ssh, '_get_hosts_name_for_node', autospec=True)
@mock.patch.object(ssh, '_ssh_execute', autospec=True)
def test_management_interface_get_boot_device_virsh(self, mock_exc,
mock_h,
mock_get_conn):
@@ -911,8 +911,8 @@ class SSHDriverTestCase(db_base.DbTestCase):
'print; }\' Q="\'" RS="[<>]" | head -1') % fake_name
mock_exc.assert_called_once_with(mock.ANY, expected_cmd)
@mock.patch.object(ssh, '_get_connection')
@mock.patch.object(ssh, '_get_hosts_name_for_node')
@mock.patch.object(ssh, '_get_connection', autospec=True)
@mock.patch.object(ssh, '_get_hosts_name_for_node', autospec=True)
def test_get_boot_device_not_supported(self, mock_h, mock_get_conn):
mock_h.return_value = 'NodeName'
mock_get_conn.return_value = self.sshclient
@@ -923,9 +923,9 @@ class SSHDriverTestCase(db_base.DbTestCase):
self.assertEqual(expected,
self.driver.management.get_boot_device(task))
@mock.patch.object(ssh, '_get_connection')
@mock.patch.object(ssh, '_get_hosts_name_for_node')
@mock.patch.object(ssh, '_ssh_execute')
@mock.patch.object(ssh, '_get_connection', autospec=True)
@mock.patch.object(ssh, '_get_hosts_name_for_node', autospec=True)
@mock.patch.object(ssh, '_ssh_execute', autospec=True)
def test_get_power_state_vmware(self, mock_exc, mock_h, mock_get_conn):
# To see replacing {_NodeName_} in vmware's list_running
nodename = 'fakevm'
+4 -3
View File
@@ -41,13 +41,14 @@ class UtilsTestCase(db_base.DbTestCase):
props = self.driver.vendor.get_properties()
self.assertEqual(expected, props)
@mock.patch.object(fake.FakeVendorA, 'validate')
@mock.patch.object(fake.FakeVendorA, 'validate', autospec=True)
def test_vendor_interface_validate_valid_methods(self,
mock_fakea_validate):
with task_manager.acquire(self.context, self.node.uuid) as task:
self.driver.vendor.validate(task, method='first_method')
mock_fakea_validate.assert_called_once_with(task,
method='first_method')
mock_fakea_validate.assert_called_once_with(
self.driver.vendor.mapping['first_method'],
task, method='first_method')
def test_vendor_interface_validate_bad_method(self):
with task_manager.acquire(self.context, self.node.uuid) as task:
+31 -31
View File
@@ -75,11 +75,11 @@ class VirtualBoxMethodsTestCase(db_base.DbTestCase):
info = virtualbox._parse_driver_info(self.node)
self.assertEqual(18083, info['port'])
@mock.patch.object(pyremotevbox_vbox, 'VirtualBoxHost')
@mock.patch.object(pyremotevbox_vbox, 'VirtualBoxHost', autospec=True)
def test__run_virtualbox_method(self, host_mock):
host_object_mock = mock.MagicMock()
func_mock = mock.MagicMock()
vm_object_mock = mock.MagicMock(foo=func_mock)
host_object_mock = mock.MagicMock(spec_set=['find_vm'])
func_mock = mock.MagicMock(spec_set=[])
vm_object_mock = mock.MagicMock(spec_set=['foo'], foo=func_mock)
host_mock.return_value = host_object_mock
host_object_mock.find_vm.return_value = vm_object_mock
func_mock.return_value = 'return-value'
@@ -96,7 +96,7 @@ class VirtualBoxMethodsTestCase(db_base.DbTestCase):
func_mock.assert_called_once_with('args', kwarg='kwarg')
self.assertEqual('return-value', return_value)
@mock.patch.object(pyremotevbox_vbox, 'VirtualBoxHost')
@mock.patch.object(pyremotevbox_vbox, 'VirtualBoxHost', autospec=True)
def test__run_virtualbox_method_get_host_fails(self, host_mock):
host_mock.side_effect = pyremotevbox_exc.PyRemoteVBoxException
@@ -105,9 +105,9 @@ class VirtualBoxMethodsTestCase(db_base.DbTestCase):
self.node, 'some-ironic-method', 'foo',
'args', kwarg='kwarg')
@mock.patch.object(pyremotevbox_vbox, 'VirtualBoxHost')
@mock.patch.object(pyremotevbox_vbox, 'VirtualBoxHost', autospec=True)
def test__run_virtualbox_method_find_vm_fails(self, host_mock):
host_object_mock = mock.MagicMock()
host_object_mock = mock.MagicMock(spec_set=['find_vm'])
host_mock.return_value = host_object_mock
exc = pyremotevbox_exc.PyRemoteVBoxException
host_object_mock.find_vm.side_effect = exc
@@ -123,12 +123,12 @@ class VirtualBoxMethodsTestCase(db_base.DbTestCase):
port=12345)
host_object_mock.find_vm.assert_called_once_with('baremetal1')
@mock.patch.object(pyremotevbox_vbox, 'VirtualBoxHost')
@mock.patch.object(pyremotevbox_vbox, 'VirtualBoxHost', autospec=True)
def test__run_virtualbox_method_func_fails(self, host_mock):
host_object_mock = mock.MagicMock()
host_object_mock = mock.MagicMock(spec_set=['find_vm'])
host_mock.return_value = host_object_mock
func_mock = mock.MagicMock()
vm_object_mock = mock.MagicMock(foo=func_mock)
vm_object_mock = mock.MagicMock(spec_set=['foo'], foo=func_mock)
host_object_mock.find_vm.return_value = vm_object_mock
func_mock.side_effect = pyremotevbox_exc.PyRemoteVBoxException
@@ -144,11 +144,11 @@ class VirtualBoxMethodsTestCase(db_base.DbTestCase):
host_object_mock.find_vm.assert_called_once_with('baremetal1')
func_mock.assert_called_once_with('args', kwarg='kwarg')
@mock.patch.object(pyremotevbox_vbox, 'VirtualBoxHost')
@mock.patch.object(pyremotevbox_vbox, 'VirtualBoxHost', autospec=True)
def test__run_virtualbox_method_invalid_method(self, host_mock):
host_object_mock = mock.MagicMock()
host_object_mock = mock.MagicMock(spec_set=['find_vm'])
host_mock.return_value = host_object_mock
vm_object_mock = mock.MagicMock()
vm_object_mock = mock.MagicMock(spec_set=[])
host_object_mock.find_vm.return_value = vm_object_mock
del vm_object_mock.foo
@@ -163,12 +163,12 @@ class VirtualBoxMethodsTestCase(db_base.DbTestCase):
port=12345)
host_object_mock.find_vm.assert_called_once_with('baremetal1')
@mock.patch.object(pyremotevbox_vbox, 'VirtualBoxHost')
@mock.patch.object(pyremotevbox_vbox, 'VirtualBoxHost', autospec=True)
def test__run_virtualbox_method_vm_wrong_power_state(self, host_mock):
host_object_mock = mock.MagicMock()
host_object_mock = mock.MagicMock(spec_set=['find_vm'])
host_mock.return_value = host_object_mock
func_mock = mock.MagicMock()
vm_object_mock = mock.MagicMock(foo=func_mock)
func_mock = mock.MagicMock(spec_set=[])
vm_object_mock = mock.MagicMock(spec_set=['foo'], foo=func_mock)
host_object_mock.find_vm.return_value = vm_object_mock
func_mock.side_effect = pyremotevbox_exc.VmInWrongPowerState
@@ -205,14 +205,14 @@ class VirtualBoxPowerTestCase(db_base.DbTestCase):
self.assertIn('virtualbox_vmname', properties)
self.assertIn('virtualbox_host', properties)
@mock.patch.object(virtualbox, '_parse_driver_info')
@mock.patch.object(virtualbox, '_parse_driver_info', autospec=True)
def test_validate(self, parse_info_mock):
with task_manager.acquire(self.context, self.node.uuid,
shared=False) as task:
task.driver.power.validate(task)
parse_info_mock.assert_called_once_with(task.node)
@mock.patch.object(virtualbox, '_run_virtualbox_method')
@mock.patch.object(virtualbox, '_run_virtualbox_method', autospec=True)
def test_get_power_state(self, run_method_mock):
run_method_mock.return_value = 'PoweredOff'
with task_manager.acquire(self.context, self.node.uuid,
@@ -223,7 +223,7 @@ class VirtualBoxPowerTestCase(db_base.DbTestCase):
'get_power_status')
self.assertEqual(states.POWER_OFF, power_state)
@mock.patch.object(virtualbox, '_run_virtualbox_method')
@mock.patch.object(virtualbox, '_run_virtualbox_method', autospec=True)
def test_get_power_state_invalid_state(self, run_method_mock):
run_method_mock.return_value = 'invalid-state'
with task_manager.acquire(self.context, self.node.uuid,
@@ -234,7 +234,7 @@ class VirtualBoxPowerTestCase(db_base.DbTestCase):
'get_power_status')
self.assertEqual(states.ERROR, power_state)
@mock.patch.object(virtualbox, '_run_virtualbox_method')
@mock.patch.object(virtualbox, '_run_virtualbox_method', autospec=True)
def test_set_power_state_off(self, run_method_mock):
with task_manager.acquire(self.context, self.node.uuid,
shared=False) as task:
@@ -243,7 +243,7 @@ class VirtualBoxPowerTestCase(db_base.DbTestCase):
'set_power_state',
'stop')
@mock.patch.object(virtualbox, '_run_virtualbox_method')
@mock.patch.object(virtualbox, '_run_virtualbox_method', autospec=True)
def test_set_power_state_on(self, run_method_mock):
with task_manager.acquire(self.context, self.node.uuid,
shared=False) as task:
@@ -252,7 +252,7 @@ class VirtualBoxPowerTestCase(db_base.DbTestCase):
'set_power_state',
'start')
@mock.patch.object(virtualbox, '_run_virtualbox_method')
@mock.patch.object(virtualbox, '_run_virtualbox_method', autospec=True)
def test_set_power_state_reboot(self, run_method_mock):
with task_manager.acquire(self.context, self.node.uuid,
shared=False) as task:
@@ -271,7 +271,7 @@ class VirtualBoxPowerTestCase(db_base.DbTestCase):
task.driver.power.set_power_state,
task, 'invalid-state')
@mock.patch.object(virtualbox, '_run_virtualbox_method')
@mock.patch.object(virtualbox, '_run_virtualbox_method', autospec=True)
def test_reboot(self, run_method_mock):
with task_manager.acquire(self.context, self.node.uuid,
shared=False) as task:
@@ -302,7 +302,7 @@ class VirtualBoxManagementTestCase(db_base.DbTestCase):
self.assertIn('virtualbox_vmname', properties)
self.assertIn('virtualbox_host', properties)
@mock.patch.object(virtualbox, '_parse_driver_info')
@mock.patch.object(virtualbox, '_parse_driver_info', autospec=True)
def test_validate(self, parse_info_mock):
with task_manager.acquire(self.context, self.node.uuid,
shared=False) as task:
@@ -317,7 +317,7 @@ class VirtualBoxManagementTestCase(db_base.DbTestCase):
self.assertIn(boot_devices.DISK, devices)
self.assertIn(boot_devices.CDROM, devices)
@mock.patch.object(virtualbox, '_run_virtualbox_method')
@mock.patch.object(virtualbox, '_run_virtualbox_method', autospec=True)
def test_get_boot_device_ok(self, run_method_mock):
run_method_mock.return_value = 'Network'
with task_manager.acquire(self.context, self.node.uuid,
@@ -329,7 +329,7 @@ class VirtualBoxManagementTestCase(db_base.DbTestCase):
self.assertEqual(boot_devices.PXE, ret_val['boot_device'])
self.assertTrue(ret_val['persistent'])
@mock.patch.object(virtualbox, '_run_virtualbox_method')
@mock.patch.object(virtualbox, '_run_virtualbox_method', autospec=True)
def test_get_boot_device_invalid(self, run_method_mock):
run_method_mock.return_value = 'invalid-boot-device'
with task_manager.acquire(self.context, self.node.uuid,
@@ -338,7 +338,7 @@ class VirtualBoxManagementTestCase(db_base.DbTestCase):
self.assertIsNone(ret_val['boot_device'])
self.assertIsNone(ret_val['persistent'])
@mock.patch.object(virtualbox, '_run_virtualbox_method')
@mock.patch.object(virtualbox, '_run_virtualbox_method', autospec=True)
def test_set_boot_device_ok(self, run_method_mock):
with task_manager.acquire(self.context, self.node.uuid,
shared=False) as task:
@@ -348,8 +348,8 @@ class VirtualBoxManagementTestCase(db_base.DbTestCase):
'set_boot_device',
'Network')
@mock.patch.object(virtualbox, 'LOG')
@mock.patch.object(virtualbox, '_run_virtualbox_method')
@mock.patch.object(virtualbox, 'LOG', autospec=True)
@mock.patch.object(virtualbox, '_run_virtualbox_method', autospec=True)
def test_set_boot_device_wrong_power_state(self, run_method_mock,
log_mock):
run_method_mock.side_effect = pyremotevbox_exc.VmInWrongPowerState
@@ -358,7 +358,7 @@ class VirtualBoxManagementTestCase(db_base.DbTestCase):
task.driver.management.set_boot_device(task, boot_devices.PXE)
log_mock.error.assert_called_once_with(mock.ANY, mock.ANY)
@mock.patch.object(virtualbox, '_run_virtualbox_method')
@mock.patch.object(virtualbox, '_run_virtualbox_method', autospec=True)
def test_set_boot_device_invalid(self, run_method_mock):
with task_manager.acquire(self.context, self.node.uuid,
shared=False) as task:
@@ -16,6 +16,53 @@
"""This module provides mock 'specs' for third party modules that can be used
when needing to mock those third party modules"""
# iboot
IBOOT_SPEC = (
'iBootInterface',
)
# ironic_discoverd
IRONIC_DISCOVERD_SPEC = (
'__version__',
'__version_info__',
'client',
)
# proliantutils
PROLIANTUTILS_SPEC = (
'exception',
'ilo',
)
# pyghmi
PYGHMI_SPEC = (
'exceptions',
'ipmi',
)
PYGHMI_EXC_SPEC = (
'IpmiException',
)
PYGHMI_IPMI_SPEC = (
'command',
)
PYGHMI_IPMICMD_SPEC = (
'boot_devices',
'Command',
)
# pyremotevbox
PYREMOTEVBOX_SPEC = (
'exception',
'vbox',
)
PYREMOTEVBOX_EXC_SPEC = (
'PyRemoteVBoxException',
'VmInWrongPowerState',
)
PYREMOTEVBOX_VBOX_SPEC = (
'VirtualBoxHost',
)
# pywsman
PYWSMAN_SPEC = (
'Client',
@@ -28,11 +75,17 @@ PYWSMAN_SPEC = (
'wsman_transport_set_verify_peer',
)
# pywsnmp
PYWSNMP_SPEC = (
'entity',
'error',
'proto',
)
# scciclient
SCCICLIENT_SPEC = (
'irmc',
)
SCCICLIENT_IRMC_SCCI_SPEC = (
'POWER_OFF',
'POWER_ON',
@@ -42,3 +95,17 @@ SCCICLIENT_IRMC_SCCI_SPEC = (
'get_report',
'get_sensor_data',
)
# seamicro
SEAMICRO_SPEC = (
'client',
'exceptions',
)
# seamicro.client module
SEAMICRO_CLIENT_MOD_SPEC = (
'Client',
)
SEAMICRO_EXC_SPEC = (
'ClientException',
'UnsupportedVersion',
)
@@ -43,9 +43,9 @@ from ironic.tests.drivers import third_party_driver_mock_specs as mock_specs
# required by the optional drivers.modules.seamicro module
seamicroclient = importutils.try_import("seamicroclient")
if not seamicroclient:
smc = mock.Mock()
smc.client = mock.Mock()
smc.exceptions = mock.Mock()
smc = mock.MagicMock(spec_set=mock_specs.SEAMICRO_SPEC)
smc.client = mock.MagicMock(spec_set=mock_specs.SEAMICRO_CLIENT_MOD_SPEC)
smc.exceptions = mock.MagicMock(spec_set=mock_specs.SEAMICRO_EXC_SPEC)
smc.exceptions.ClientException = Exception
smc.exceptions.UnsupportedVersion = Exception
sys.modules['seamicroclient'] = smc
@@ -66,12 +66,12 @@ ipmitool.SINGLE_BRIDGE_SUPPORT = False
pyghmi = importutils.try_import("pyghmi")
if not pyghmi:
p = mock.Mock()
p.exceptions = mock.Mock()
p = mock.MagicMock(spec_set=mock_specs.PYGHMI_SPEC)
p.exceptions = mock.MagicMock(spec_set=mock_specs.PYGHMI_EXC_SPEC)
p.exceptions.IpmiException = Exception
p.ipmi = mock.Mock()
p.ipmi.command = mock.Mock()
p.ipmi.command.Command = mock.Mock()
p.ipmi = mock.MagicMock(spec_set=mock_specs.PYGHMI_IPMI_SPEC)
p.ipmi.command = mock.MagicMock(spec_set=mock_specs.PYGHMI_IPMICMD_SPEC)
p.ipmi.command.Command = mock.MagicMock(spec_set=[])
sys.modules['pyghmi'] = p
sys.modules['pyghmi.exceptions'] = p.exceptions
sys.modules['pyghmi.ipmi'] = p.ipmi
@@ -86,7 +86,7 @@ if 'ironic.drivers.modules.ipminative' in sys.modules:
proliantutils = importutils.try_import('proliantutils')
if not proliantutils:
proliantutils = mock.MagicMock()
proliantutils = mock.MagicMock(spec_set=mock_specs.PROLIANTUTILS_SPEC)
sys.modules['proliantutils'] = proliantutils
sys.modules['proliantutils.ilo'] = proliantutils.ilo
sys.modules['proliantutils.ilo.client'] = proliantutils.ilo.client
@@ -102,7 +102,7 @@ if not proliantutils:
# the optional drivers.modules.drac and drivers.modules.amt module
pywsman = importutils.try_import('pywsman')
if not pywsman:
pywsman = mock.Mock(spec=mock_specs.PYWSMAN_SPEC)
pywsman = mock.MagicMock(spec_set=mock_specs.PYWSMAN_SPEC)
sys.modules['pywsman'] = pywsman
# Now that the external library has been mocked, if anything had already
# loaded any of the drivers, reload them.
@@ -116,8 +116,8 @@ if not pywsman:
# the optional drivers.modules.iboot module
iboot = importutils.try_import("iboot")
if not iboot:
ib = mock.Mock()
ib.iBootInterface = mock.Mock()
ib = mock.MagicMock(spec_set=mock_specs.IBOOT_SPEC)
ib.iBootInterface = mock.MagicMock(spec_set=[])
sys.modules['iboot'] = ib
# if anything has loaded the iboot driver yet, reload it now that the
@@ -130,7 +130,7 @@ if 'ironic.drivers.modules.iboot' in sys.modules:
# the optional drivers.modules.snmp module
pysnmp = importutils.try_import("pysnmp")
if not pysnmp:
pysnmp = mock.Mock()
pysnmp = mock.MagicMock(spec_set=mock_specs.PYWSNMP_SPEC)
sys.modules["pysnmp"] = pysnmp
sys.modules["pysnmp.entity"] = pysnmp.entity
sys.modules["pysnmp.entity.rfc3413"] = pysnmp.entity.rfc3413
@@ -173,10 +173,13 @@ if 'ironic.drivers.modules.irmc' in sys.modules:
pyremotevbox = importutils.try_import('pyremotevbox')
if not pyremotevbox:
pyremotevbox = mock.MagicMock()
pyremotevbox.exception = mock.MagicMock()
pyremotevbox = mock.MagicMock(spec_set=mock_specs.PYREMOTEVBOX_SPEC)
pyremotevbox.exception = mock.MagicMock(
spec_set=mock_specs.PYREMOTEVBOX_EXC_SPEC)
pyremotevbox.exception.PyRemoteVBoxException = Exception
pyremotevbox.exception.VmInWrongPowerState = Exception
pyremotevbox.vbox = mock.MagicMock(
spec_set=mock_specs.PYREMOTEVBOX_VBOX_SPEC)
sys.modules['pyremotevbox'] = pyremotevbox
if 'ironic.drivers.modules.virtualbox' in sys.modules:
six.moves.reload_module(
@@ -185,7 +188,8 @@ if not pyremotevbox:
ironic_discoverd = importutils.try_import('ironic_discoverd')
if not ironic_discoverd:
ironic_discoverd = mock.MagicMock()
ironic_discoverd = mock.MagicMock(
spec_set=mock_specs.IRONIC_DISCOVERD_SPEC)
ironic_discoverd.__version_info__ = (1, 0, 0)
ironic_discoverd.__version__ = "1.0.0"
sys.modules['ironic_discoverd'] = ironic_discoverd