def test_rebuild_failures(self, mock_save, mock_get, mock_driver_fields, mock_fg_bid, mock_set_pstate): node_uuid = uuidutils.generate_uuid() instance_uuid = uuidutils.generate_uuid() node = ironic_utils.get_test_node(uuid=node_uuid, instance_uuid=instance_uuid, instance_type_id=5) mock_get.return_value = node image_meta = ironic_utils.get_test_image_meta() flavor_id = 5 flavor = {'id': flavor_id, 'name': 'baremetal'} mock_fg_bid.return_value = flavor instance = fake_instance.fake_instance_obj(self.ctx, uuid=instance_uuid, node=node_uuid, instance_type_id=flavor_id) exceptions = [ exception.NovaException(), ironic_exception.BadRequest(), ironic_exception.InternalServerError(), ] for e in exceptions: mock_set_pstate.side_effect = e self.assertRaises(exception.InstanceDeployFailure, self.driver.rebuild, context=self.ctx, instance=instance, image_meta=image_meta, injected_files=None, admin_password=None, bdms=None, detach_block_devices=None, attach_block_devices=None)
def setUp(self): super(IronicDriverFieldsTestCase, self).setUp() self.image_meta = ironic_utils.get_test_image_meta() self.flavor = ironic_utils.get_test_flavor() self.ctx = nova_context.get_admin_context() self.instance = fake_instance.fake_instance_obj(self.ctx) # Generic expected patches self._expected_deploy_patch = [{'path': '/instance_info/image_source', 'value': self.image_meta['id'], 'op': 'add'}, {'path': '/instance_info/root_gb', 'value': str(self.instance['root_gb']), 'op': 'add'}, {'path': '/instance_info/swap_mb', 'value': str(self.flavor['swap']), 'op': 'add'}] self._expected_cleanup_patch = []
def setUp(self): super(IronicDriverFieldsTestCase, self).setUp() self.image_meta = ironic_utils.get_test_image_meta() self.flavor = ironic_utils.get_test_flavor() self.ctx = nova_context.get_admin_context() self.instance = fake_instance.fake_instance_obj(self.ctx) # Generic expected patches self._expected_deploy_patch = [{'path': '/instance_info/image_source', 'value': self.image_meta['id'], 'op': 'add'}, {'path': '/instance_info/root_gb', 'value': str(self.instance['root_gb']), 'op': 'add'}, {'path': '/instance_info/swap_mb', 'value': str(self.flavor['swap']), 'op': 'add'}] self._expected_cleanup_patch = []
def _test_rebuild(self, mock_save, mock_get, mock_driver_fields, mock_fg_bid, mock_set_pstate, mock_looping, mock_wait_active, preserve=False): node_uuid = uuidutils.generate_uuid() instance_uuid = uuidutils.generate_uuid() node = ironic_utils.get_test_node(uuid=node_uuid, instance_uuid=instance_uuid, instance_type_id=5) mock_get.return_value = node image_meta = ironic_utils.get_test_image_meta() flavor_id = 5 flavor = {'id': flavor_id, 'name': 'baremetal'} mock_fg_bid.return_value = flavor instance = fake_instance.fake_instance_obj(self.ctx, uuid=instance_uuid, node=node_uuid, instance_type_id=flavor_id) fake_looping_call = FakeLoopingCall() mock_looping.return_value = fake_looping_call self.driver.rebuild( context=self.ctx, instance=instance, image_meta=image_meta, injected_files=None, admin_password=None, bdms=None, detach_block_devices=None, attach_block_devices=None, preserve_ephemeral=preserve) mock_save.assert_called_once_with( expected_task_state=[task_states.REBUILDING]) mock_driver_fields.assert_called_once_with(node, instance, image_meta, flavor, preserve) mock_set_pstate.assert_called_once_with(node_uuid, ironic_states.REBUILD) mock_looping.assert_called_once_with(mock_wait_active, FAKE_CLIENT_WRAPPER, instance) fake_looping_call.start.assert_called_once_with( interval=CONF.ironic.api_retry_interval) fake_looping_call.wait.assert_called_once()
def setUp(self): super(IronicDriverFieldsTestCase, self).setUp() self.image_meta = ironic_utils.get_test_image_meta() self.flavor = ironic_utils.get_test_flavor() self.ctx = nova_context.get_admin_context()