Ejemplo n.º 1
0
 def test_get_info_ok(self):
     node = self._create_node()
     db.bm_node_associate_and_update(self.context, node['node']['uuid'],
             {'instance_uuid': node['instance']['uuid'],
              'instance_name': node['instance']['hostname'],
              'task_state': baremetal_states.ACTIVE})
     res = self.driver.get_info(node['instance'])
     self.assertEqual(res['state'], power_state.RUNNING)
Ejemplo n.º 2
0
 def test_get_info_ok(self):
     node = self._create_node()
     db.bm_node_associate_and_update(self.context, node['node']['uuid'],
             {'instance_uuid': node['instance']['uuid'],
              'instance_name': node['instance']['hostname'],
              'task_state': baremetal_states.ACTIVE})
     res = self.driver.get_info(node['instance'])
     self.assertEqual(res['state'], power_state.RUNNING)
Ejemplo n.º 3
0
 def test_get_info_ok(self):
     node = self._create_node()
     db.bm_node_associate_and_update(
         self.context,
         node["node"]["uuid"],
         {
             "instance_uuid": node["instance"]["uuid"],
             "instance_name": node["instance"]["hostname"],
             "task_state": baremetal_states.ACTIVE,
         },
     )
     res = self.driver.get_info(node["instance"])
     self.assertEqual(res["state"], power_state.RUNNING)
Ejemplo n.º 4
0
    def spawn(self,
              context,
              instance,
              image_meta,
              injected_files,
              admin_password,
              network_info=None,
              block_device_info=None):
        node_uuid = self._require_node(instance)
        self._set_default_ephemeral_device(instance)

        # NOTE(deva): this db method will raise an exception if the node is
        #             already in use. We call it here to ensure no one else
        #             allocates this node before we begin provisioning it.
        node = db.bm_node_associate_and_update(
            context, node_uuid, {
                'instance_uuid': instance['uuid'],
                'instance_name': instance['hostname'],
                'task_state': baremetal_states.BUILDING,
                'preserve_ephemeral': False
            })
        self._spawn(node,
                    context,
                    instance,
                    image_meta,
                    injected_files,
                    admin_password,
                    network_info=network_info,
                    block_device_info=block_device_info)
Ejemplo n.º 5
0
    def test_get_info_with_defunct_pm(self):
        # test fix for bug 1178378
        node = self._create_node()
        db.bm_node_associate_and_update(self.context, node['node']['uuid'],
                {'instance_uuid': node['instance']['uuid'],
                 'instance_name': node['instance']['hostname'],
                 'task_state': baremetal_states.ACTIVE})

        # fake the power manager and don't get a power state
        self.mox.StubOutWithMock(fake.FakePowerManager, 'is_power_on')
        fake.FakePowerManager.is_power_on().AndReturn(None)
        self.mox.ReplayAll()

        res = self.driver.get_info(node['instance'])
        # prior to the fix, returned power_state was SHUTDOWN
        self.assertEqual(res['state'], power_state.NOSTATE)
        self.mox.VerifyAll()
Ejemplo n.º 6
0
    def test_get_info_with_defunct_pm(self):
        # test fix for bug 1178378
        node = self._create_node()
        db.bm_node_associate_and_update(self.context, node['node']['uuid'],
                {'instance_uuid': node['instance']['uuid'],
                 'instance_name': node['instance']['hostname'],
                 'task_state': baremetal_states.ACTIVE})

        # fake the power manager and don't get a power state
        self.mox.StubOutWithMock(fake.FakePowerManager, 'is_power_on')
        fake.FakePowerManager.is_power_on().AndReturn(None)
        self.mox.ReplayAll()

        res = self.driver.get_info(node['instance'])
        # prior to the fix, returned power_state was SHUTDOWN
        self.assertEqual(res['state'], power_state.NOSTATE)
        self.mox.VerifyAll()
Ejemplo n.º 7
0
    def spawn(
        self, context, instance, image_meta, injected_files, admin_password, network_info=None, block_device_info=None
    ):
        node_uuid = self._require_node(instance)

        # NOTE(deva): this db method will raise an exception if the node is
        #             already in use. We call it here to ensure no one else
        #             allocates this node before we begin provisioning it.
        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)

            self.driver.cache_images(
                context,
                node,
                instance,
                admin_password=admin_password,
                image_meta=image_meta,
                injected_files=injected_files,
                network_info=network_info,
            )
            self.driver.activate_bootloader(context, node, instance)
            self.power_on(instance, node)
            self.driver.activate_node(context, node, instance)
            _update_state(context, node, instance, baremetal_states.ACTIVE)
        except Exception:
            with excutils.save_and_reraise_exception():
                LOG.error(
                    _("Error deploying instance %(instance)s " "on baremetal node %(node)s.")
                    % {"instance": instance["uuid"], "node": node["uuid"]}
                )

                # Do not set instance=None yet. This prevents another
                # spawn() while we are cleaning up.
                _update_state(context, node, instance, baremetal_states.ERROR)

                self.driver.deactivate_node(context, node, instance)
                self.power_off(instance, node)
                self.driver.deactivate_bootloader(context, node, instance)
                self.driver.destroy_images(context, node, instance)

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

                _update_state(context, node, None, baremetal_states.DELETED)
Ejemplo n.º 8
0
    def spawn(self, context, instance, image_meta, injected_files,
              admin_password, network_info=None, block_device_info=None):
        node_uuid = self._require_node(instance)
        self._set_default_ephemeral_device(instance)

        # NOTE(deva): this db method will raise an exception if the node is
        #             already in use. We call it here to ensure no one else
        #             allocates this node before we begin provisioning it.
        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)

            self.driver.cache_images(
                            context, node, instance,
                            admin_password=admin_password,
                            image_meta=image_meta,
                            injected_files=injected_files,
                            network_info=network_info,
                        )
            self.driver.activate_bootloader(context, node, instance,
                                            network_info=network_info)
            # NOTE(deva): ensure node is really off before we turn it on
            #             fixes bug https://code.launchpad.net/bugs/1178919
            self.power_off(instance, node)
            self.power_on(context, instance, network_info, block_device_info,
                          node)
            _update_state(context, node, instance, baremetal_states.PREPARED)

            self.driver.activate_node(context, node, instance)
            _update_state(context, node, instance, baremetal_states.ACTIVE)
        except Exception:
            with excutils.save_and_reraise_exception():
                LOG.error(_("Error deploying instance %(instance)s "
                            "on baremetal node %(node)s.") %
                            {'instance': instance['uuid'],
                             'node': node['uuid']})

                # Do not set instance=None yet. This prevents another
                # spawn() while we are cleaning up.
                _update_state(context, node, instance, baremetal_states.ERROR)

                self.driver.deactivate_node(context, node, instance)
                self.power_off(instance, node)
                self.driver.deactivate_bootloader(context, node, instance)
                self.driver.destroy_images(context, node, instance)

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

                _update_state(context, node, None, baremetal_states.DELETED)
Ejemplo n.º 9
0
    def spawn(self, context, instance, image_meta, injected_files,
              admin_password, network_info=None, block_device_info=None):
        node_uuid = self._require_node(instance)
        self._set_default_ephemeral_device(instance)

        # NOTE(deva): this db method will raise an exception if the node is
        #             already in use. We call it here to ensure no one else
        #             allocates this node before we begin provisioning it.
        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)

            self.driver.cache_images(
                            context, node, instance,
                            admin_password=admin_password,
                            image_meta=image_meta,
                            injected_files=injected_files,
                            network_info=network_info,
                        )
            self.driver.activate_bootloader(context, node, instance,
                                            network_info=network_info)
            # NOTE(deva): ensure node is really off before we turn it on
            #             fixes bug https://code.launchpad.net/bugs/1178919
            self.power_off(instance, node)
            self.power_on(context, instance, network_info, block_device_info,
                          node)
            self.driver.activate_node(context, node, instance)
            _update_state(context, node, instance, baremetal_states.ACTIVE)
        except Exception:
            with excutils.save_and_reraise_exception():
                LOG.error(_("Error deploying instance %(instance)s "
                            "on baremetal node %(node)s.") %
                            {'instance': instance['uuid'],
                             'node': node['uuid']})

                # Do not set instance=None yet. This prevents another
                # spawn() while we are cleaning up.
                _update_state(context, node, instance, baremetal_states.ERROR)

                self.driver.deactivate_node(context, node, instance)
                self.power_off(instance, node)
                self.driver.deactivate_bootloader(context, node, instance)
                self.driver.destroy_images(context, node, instance)

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

                _update_state(context, node, None, baremetal_states.DELETED)
Ejemplo n.º 10
0
    def spawn(self, context, instance, image_meta, injected_files,
              admin_password, network_info=None, block_device_info=None):
        node_uuid = self._require_node(instance)
        self._set_default_ephemeral_device(instance)

        # NOTE(deva): this db method will raise an exception if the node is
        #             already in use. We call it here to ensure no one else
        #             allocates this node before we begin provisioning it.
        node = db.bm_node_associate_and_update(context, node_uuid,
                    {'instance_uuid': instance['uuid'],
                     'instance_name': instance['hostname'],
                     'task_state': baremetal_states.BUILDING,
                     'preserve_ephemeral': False})
        self._spawn(node, context, instance, image_meta, injected_files,
            admin_password, network_info=network_info,
            block_device_info=block_device_info)
Ejemplo n.º 11
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)
Ejemplo n.º 12
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)