Beispiel #1
0
    def test_spawn_prepared(self):
        node = self._create_node()

        def update_2prepared(context, node, instance, state):
            row = db.bm_node_get(context, node['id'])
            self.assertEqual(row['task_state'], baremetal_states.BUILDING)
            db.bm_node_update(context, node['id'],
                              {'task_state': baremetal_states.PREPARED})

        self.mox.StubOutWithMock(fake.FakeDriver, 'activate_node')
        self.mox.StubOutWithMock(bm_driver, '_update_state')

        bm_driver._update_state(
            self.context, mox.IsA(node['node']), node['instance'],
            baremetal_states.PREPARED).WithSideEffects(update_2prepared)
        fake.FakeDriver.activate_node(self.context, mox.IsA(
            node['node']), node['instance']).AndRaise(test.TestingException)
        bm_driver._update_state(
            self.context, mox.IsA(node['node']), node['instance'],
            baremetal_states.ERROR).AndRaise(test.TestingException)
        self.mox.ReplayAll()

        self.assertRaises(test.TestingException, self.driver.spawn,
                          **node['spawn_params'])

        row = db.bm_node_get(self.context, node['node']['id'])
        self.assertEqual(row['task_state'], baremetal_states.PREPARED)
Beispiel #2
0
    def reboot(self, context, instance, network_info, reboot_type, block_device_info=None, bad_volumes_callback=None):
        """Reboot the specified instance.

        After this is called successfully, the instance's state
        goes back to power_state.RUNNING. The virtualization
        platform should ensure that the reboot action has completed
        successfully even in cases in which the underlying domain/vm
        is paused or halted/stopped.

        :param instance: Instance object as returned by DB layer.
        :param network_info:
           :py:meth:`~nova.network.manager.NetworkManager.get_instance_nw_info`
        :param reboot_type: Either a HARD or SOFT reboot
        :param block_device_info: Info pertaining to attached volumes
        :param bad_volumes_callback: Function to handle any bad volumes
            encountered
        """
        try:
            node = bm_driver._get_baremetal_node_by_instance_uuid(instance["uuid"])
            macs = self.macs_for_instance(instance)
            nodename = self.xcat.get_xcat_node_name(macs)
            self.xcat.reboot_node(nodename)
            bm_driver._update_state(context, node, instance, baremetal_states.RUNNING)
        except xcat_exception.xCATCommandError as e:
            with excutils.save_and_reraise_exception():
                LOG.error(
                    _("Error occured while rebooting instance %(instance)s " "on baremetal node %(node)s: %(error)s")
                    % {"instance": instance["uuid"], "node": node["uuid"], "error": str(e)}
                )
                bm_driver._update_state(context, node, instance, baremetal_states.ERROR)
Beispiel #3
0
    def test_spawn_prepared(self):
        node = self._create_node()

        def update_2prepared(context, node, instance, state):
            row = db.bm_node_get(context, node['id'])
            self.assertEqual(row['task_state'], baremetal_states.BUILDING)
            db.bm_node_update(
                context, node['id'],
                {'task_state': baremetal_states.PREPARED})

        self.mox.StubOutWithMock(fake.FakeDriver, 'activate_node')
        self.mox.StubOutWithMock(bm_driver, '_update_state')

        bm_driver._update_state(
            self.context,
            mox.IsA(node['node']),
            node['instance'],
            baremetal_states.PREPARED).WithSideEffects(update_2prepared)
        fake.FakeDriver.activate_node(
            self.context,
            mox.IsA(node['node']),
            node['instance']).AndRaise(test.TestingException)
        bm_driver._update_state(
            self.context,
            mox.IsA(node['node']),
            node['instance'],
            baremetal_states.ERROR).AndRaise(test.TestingException)
        self.mox.ReplayAll()

        self.assertRaises(test.TestingException,
                          self.driver.spawn, **node['spawn_params'])

        row = db.bm_node_get(self.context, node['node']['id'])
        self.assertEqual(row['task_state'], baremetal_states.PREPARED)
Beispiel #4
0
    def destroy(self, instance, network_info, block_device_info=None,
                context=None):
        """Destroy (shutdown and delete) the specified instance.

        If the instance is not found (for example if networking failed), this
        function should still succeed.  It's probably a good idea to log a
        warning in that case.

        :param context: security context
        :param instance: Instance object as returned by DB layer.
        :param network_info:
           :py:meth:`~nova.network.manager.NetworkManager.get_instance_nw_info`
        :param block_device_info: Information about block devices that should
                                  be detached from the instance.
        :param destroy_disks: Indicates if disks should be destroyed
        """
 	    #import pdb
	    #pdb.set_trace()
        context = nova_context.get_admin_context()
        try:
            node = bm_driver._get_baremetal_node_by_instance_uuid(instance['uuid'])

        except exception.InstanceNotFound:
            LOG.warning(_("Destroy function called on a non-existing instance %s")
                        % instance['uuid'])
            return

        try:
            macs = self.macs_for_instance(instance)
            nodename = self.xcat.get_xcat_node_name(macs)
            interfaces = bm_utils.map_network_interfaces(network_info, CONF.use_ipv6)
            fixed_ip=None
            if interfaces and interfaces[0]:
                if CONF.use_ipv6:
                    fixed_ip = interfaces[0].get('address_v6')
                else:
                    fixed_ip = interfaces[0].get('address')
            if fixed_ip:
                self.xcat.cleanup_node(nodename, fixed_ip)
            else:
                self.xcat.cleanup_node(nodename)
        except Exception as e:
            #just log it and move on
            LOG.warning(_("Destroy called with xCAT error:" + str(e)))

        try:
            self._detach_block_devices(instance, block_device_info)
            self._stop_firewall(instance, network_info)
            self._unplug_vifs(instance, network_info)

            bm_driver._update_state(context, node, None, baremetal_states.DELETED)
        except Exception as e:
            with excutils.save_and_reraise_exception():
                LOG.error(_("Error occurred while destroying instance %s: %s")
                          % (instance['uuid'], str(e)))
                bm_driver._update_state(context, node, instance,
                                        baremetal_states.ERROR)
Beispiel #5
0
    def reboot(self,
               context,
               instance,
               network_info,
               reboot_type,
               block_device_info=None,
               bad_volumes_callback=None):
        """Reboot the specified instance.

        After this is called successfully, the instance's state
        goes back to power_state.RUNNING. The virtualization
        platform should ensure that the reboot action has completed
        successfully even in cases in which the underlying domain/vm
        is paused or halted/stopped.

        :param instance: Instance object as returned by DB layer.
        :param network_info:
           :py:meth:`~nova.network.manager.NetworkManager.get_instance_nw_info`
        :param reboot_type: Either a HARD or SOFT reboot
        :param block_device_info: Info pertaining to attached volumes
        :param bad_volumes_callback: Function to handle any bad volumes
            encountered
        """
        try:
            node = bm_driver._get_baremetal_node_by_instance_uuid(
                instance['uuid'])
            macs = self.macs_for_instance(instance)
            nodename = self.xcat.get_xcat_node_name(macs)
            self.xcat.reboot_node(nodename)
            bm_driver._update_state(context, node, instance,
                                    baremetal_states.RUNNING)
        except xcat_exception.xCATCommandError as e:
            with excutils.save_and_reraise_exception():
                LOG.error(
                    _("Error occured while rebooting instance %(instance)s "
                      "on baremetal node %(node)s: %(error)s") % {
                          'instance': instance['uuid'],
                          'node': node['uuid'],
                          'error': str(e)
                      })
                bm_driver._update_state(context, node, instance,
                                        baremetal_states.ERROR)
Beispiel #6
0
    def spawn(
        self, context, instance, image_meta, injected_files, admin_password, network_info=None, block_device_info=None
    ):
        """
        Create a new instance/VM/domain on the virtualization platform.

        Once this successfully completes, the instance should be
        running (power_state.RUNNING).

        If this fails, any partial instance should be completely
        cleaned up, and the virtualization platform should be in the state
        that it was before this call began.

        :param context: security context
        :param instance: Instance object as returned by DB layer.
                         This function should use the data there to guide
                         the creation of the new instance.
        :param image_meta: image object returned by nova.image.glance that
                           defines the image from which to boot this instance
        :param injected_files: User files to inject into instance.
        :param admin_password: Administrator password to set in instance.
        :param network_info:
           :py:meth:`~nova.network.manager.NetworkManager.get_instance_nw_info`
        :param block_device_info: Information about block devices to be
                                  attached to the instance.
        """
        # import pdb
        # pdb.set_trace()
        node_uuid = self._require_node(instance)
        node = db.bm_node_associate_and_update(
            context,
            node_uuid,
            {
                "instance_uuid": instance["uuid"],
                "instance_name": instance["hostname"],
                "task_state": baremetal_states.BUILDING,
            },
        )

        try:
            self._plug_vifs(instance, network_info, context=context)
            self._attach_block_devices(instance, block_device_info)
            self._start_firewall(instance, network_info)

            macs = self.macs_for_instance(instance)
            nodename = self.xcat.get_xcat_node_name(macs)
            imagename = self._get_xCAT_image_name(image_meta)
            hostname = instance.get("hostname")

            # get the network information for the new node
            interfaces = bm_utils.map_network_interfaces(network_info, CONF.use_ipv6)
            if CONF.use_ipv6:
                fixed_ip = interfaces[0].get("address_v6")
                netmask = interfaces[0].get("netmask_v6")
                gateway = interfaces[0].get("gateway_v6")
            else:
                fixed_ip = interfaces[0].get("address")
                netmask = interfaces[0].get("netmask")
                gateway = interfaces[0].get("gateway")
            # convert netmask from IPAddress to unicode string
            if netmask:
                netmask = unicode(netmask)

            # let xCAT install it
            bm_driver._update_state(context, node, instance, baremetal_states.DEPLOYING)
            self.xcat.deploy_node(nodename, imagename, hostname, fixed_ip, netmask, gateway)
            bm_driver._update_state(context, node, instance, baremetal_states.ACTIVE)
        except Exception as e:
            with excutils.save_and_reraise_exception():
                LOG.error(
                    _("Error occured while deploying instance %(instance)s " "on baremetal node %(node)s: %(error)s")
                    % {"instance": instance["uuid"], "node": node["uuid"], "error": str(e)}
                )
                bm_driver._update_state(context, node, instance, baremetal_states.ERROR)
Beispiel #7
0
    def spawn(self,
              context,
              instance,
              image_meta,
              injected_files,
              admin_password,
              network_info=None,
              block_device_info=None):
        """
        Create a new instance/VM/domain on the virtualization platform.

        Once this successfully completes, the instance should be
        running (power_state.RUNNING).

        If this fails, any partial instance should be completely
        cleaned up, and the virtualization platform should be in the state
        that it was before this call began.

        :param context: security context
        :param instance: Instance object as returned by DB layer.
                         This function should use the data there to guide
                         the creation of the new instance.
        :param image_meta: image object returned by nova.image.glance that
                           defines the image from which to boot this instance
        :param injected_files: User files to inject into instance.
        :param admin_password: Administrator password to set in instance.
        :param network_info:
           :py:meth:`~nova.network.manager.NetworkManager.get_instance_nw_info`
        :param block_device_info: Information about block devices to be
                                  attached to the instance.
        """
        #import pdb
        #pdb.set_trace()
        node_uuid = self._require_node(instance)
        node = db.bm_node_associate_and_update(
            context, node_uuid, {
                'instance_uuid': instance['uuid'],
                'instance_name': instance['hostname'],
                'task_state': baremetal_states.BUILDING
            })

        try:
            self._plug_vifs(instance, network_info, context=context)
            self._attach_block_devices(instance, block_device_info)
            self._start_firewall(instance, network_info)

            macs = self.macs_for_instance(instance)
            nodename = self.xcat.get_xcat_node_name(macs)
            imagename = self._get_xCAT_image_name(image_meta)
            hostname = instance.get('hostname')

            #get the network information for the new node
            interfaces = bm_utils.map_network_interfaces(
                network_info, CONF.use_ipv6)
            if CONF.use_ipv6:
                fixed_ip = interfaces[0].get('address_v6')
                netmask = interfaces[0].get('netmask_v6')
                gateway = interfaces[0].get('gateway_v6')
            else:
                fixed_ip = interfaces[0].get('address')
                netmask = interfaces[0].get('netmask')
                gateway = interfaces[0].get('gateway')
            #convert netmask from IPAddress to unicode string
            if netmask:
                netmask = unicode(netmask)

            #let xCAT install it
            bm_driver._update_state(context, node, instance,
                                    baremetal_states.DEPLOYING)
            self.xcat.deploy_node(nodename, imagename, hostname, fixed_ip,
                                  netmask, gateway)
            bm_driver._update_state(context, node, instance,
                                    baremetal_states.ACTIVE)
        except Exception as e:
            with excutils.save_and_reraise_exception():
                LOG.error(
                    _("Error occured while deploying instance %(instance)s "
                      "on baremetal node %(node)s: %(error)s") % {
                          'instance': instance['uuid'],
                          'node': node['uuid'],
                          'error': str(e)
                      })
                bm_driver._update_state(context, node, instance,
                                        baremetal_states.ERROR)
Beispiel #8
0
    def destroy(self,
                instance,
                network_info,
                block_device_info=None,
                context=None):
        """Destroy (shutdown and delete) the specified instance.

        If the instance is not found (for example if networking failed), this
        function should still succeed.  It's probably a good idea to log a
        warning in that case.

        :param context: security context
        :param instance: Instance object as returned by DB layer.
        :param network_info:
           :py:meth:`~nova.network.manager.NetworkManager.get_instance_nw_info`
        :param block_device_info: Information about block devices that should
                                  be detached from the instance.
        :param destroy_disks: Indicates if disks should be destroyed
        """
        #import pdb
        #pdb.set_trace()
        context = nova_context.get_admin_context()
        try:
            node = bm_driver._get_baremetal_node_by_instance_uuid(
                instance['uuid'])

        except exception.InstanceNotFound:
            LOG.warning(
                _("Destroy function called on a non-existing instance %s") %
                instance['uuid'])
            return

        try:
            macs = self.macs_for_instance(instance)
            nodename = self.xcat.get_xcat_node_name(macs)
            interfaces = bm_utils.map_network_interfaces(
                network_info, CONF.use_ipv6)
            fixed_ip = None
            if interfaces and interfaces[0]:
                if CONF.use_ipv6:
                    fixed_ip = interfaces[0].get('address_v6')
                else:
                    fixed_ip = interfaces[0].get('address')
            if fixed_ip:
                self.xcat.cleanup_node(nodename, fixed_ip)
            else:
                self.xcat.cleanup_node(nodename)
        except Exception as e:
            #just log it and move on
            LOG.warning(_("Destroy called with xCAT error:" + str(e)))

        try:
            self._detach_block_devices(instance, block_device_info)
            self._stop_firewall(instance, network_info)
            self._unplug_vifs(instance, network_info)

            bm_driver._update_state(context, node, None,
                                    baremetal_states.DELETED)
        except Exception as e:
            with excutils.save_and_reraise_exception():
                LOG.error(
                    _("Error occurred while destroying instance %s: %s") %
                    (instance['uuid'], str(e)))
                bm_driver._update_state(context, node, instance,
                                        baremetal_states.ERROR)