Exemple #1
0
    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)
Exemple #2
0
    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()
Exemple #3
0
 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 = []
Exemple #4
0
    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()
Exemple #5
0
    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)
Exemple #6
0
 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()
Exemple #7
0
 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()