Exemplo n.º 1
0
 def test__add_driver_fields_fail(self, mock_update):
     mock_update.side_effect = ironic_exception.BadRequest()
     node = ironic_utils.get_test_node(driver='fake')
     instance = fake_instance.fake_instance_obj(self.ctx, node=node.uuid)
     self.assertRaises(exception.InstanceDeployFailure,
                       self.driver._add_driver_fields, node, instance, None,
                       None)
Exemplo n.º 2
0
 def test__cleanup_deploy_fail(self, mock_update, mock_flavor):
     mock_flavor.return_value = ironic_utils.get_test_flavor(extra_specs={})
     mock_update.side_effect = ironic_exception.BadRequest()
     node = ironic_utils.get_test_node(driver='fake',
                                       instance_uuid='fake-id')
     instance = fake_instance.fake_instance_obj(self.ctx, node=node.uuid)
     self.assertRaises(exception.InstanceTerminationFailure,
                       self.driver._cleanup_deploy, node, instance, None)
Exemplo n.º 3
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)
Exemplo n.º 4
0
    def spawn(self, context, server, configdrive_value):
        """Deploy a server.

        :param context: The security context.
        :param server: The server object.
        :param configdrive_value: The configdrive value to be injected.
        """
        LOG.debug('Spawn called for server', server=server)

        # The engine manager is meant to know the node uuid, so missing uuid
        # is a significant issue. It may mean we've been passed the wrong data.
        node_uuid = server.node_uuid
        if not node_uuid:
            raise ironic_exc.BadRequest(
                _("Ironic node uuid not supplied to "
                  "driver for server %s.") % server.uuid)

        # add server info to node
        node = self._get_node(node_uuid)
        self._add_server_info_to_node(node, server)

        # validate we are ready to do the deploy
        validate_chk = self.ironicclient.call("node.validate", node_uuid)
        if (not validate_chk.deploy.get('result')
                or not validate_chk.power.get('result')):
            # something is wrong. undo what we have done
            self._cleanup_deploy(context, node, server)
            raise exception.ValidationError(
                _("Ironic node: %(id)s failed to validate."
                  " (deploy: %(deploy)s, power: %(power)s)") % {
                      'id': server.node_uuid,
                      'deploy': validate_chk.deploy,
                      'power': validate_chk.power
                  })

        # trigger the node deploy
        try:
            self.ironicclient.call("node.set_provision_state",
                                   node_uuid,
                                   ironic_states.ACTIVE,
                                   configdrive=configdrive_value)
        except Exception as e:
            with excutils.save_and_reraise_exception():
                msg = ("Failed to request Ironic to provision server "
                       "%(server)s: %(reason)s", {
                           'server': server.uuid,
                           'reason': six.text_type(e)
                       })
                LOG.error(msg)

        timer = loopingcall.FixedIntervalLoopingCall(self._wait_for_active,
                                                     server)
        try:
            timer.start(interval=CONF.ironic.api_retry_interval).wait()
            LOG.info('Successfully provisioned Ironic node %s',
                     node.uuid,
                     server=server)
        except Exception:
            with excutils.save_and_reraise_exception():
                LOG.error(
                    "Error deploying server %(server)s on "
                    "baremetal node %(node)s.", {
                        'server': server.uuid,
                        'node': node_uuid
                    })