Пример #1
0
    def test_remove_node_raise(self):
        model = model_root.ModelRoot()
        uuid_ = "{0}".format(uuidutils.generate_uuid())
        node = element.ComputeNode(id=1)
        node.uuid = uuid_
        model.add_node(node)

        uuid2 = "{0}".format(uuidutils.generate_uuid())
        node2 = element.ComputeNode(id=2)
        node2.uuid = uuid2

        self.assertRaises(exception.ComputeNodeNotFound, model.remove_node,
                          node2)
Пример #2
0
 def test_add_node(self):
     model = model_root.ModelRoot()
     uuid_ = "{0}".format(uuidutils.generate_uuid())
     node = element.ComputeNode(id=1)
     node.uuid = uuid_
     model.add_node(node)
     self.assertEqual(node, model.get_node_by_uuid(uuid_))
Пример #3
0
    def create_compute_node(self, node_hostname):
        """Update the compute node by querying the Nova API."""
        try:
            _node = self.nova.get_compute_node_by_hostname(node_hostname)
            node = element.ComputeNode(_node.id)
            node.uuid = node_hostname
            node.hostname = _node.hypervisor_hostname
            node.state = _node.state
            node.status = _node.status

            self.update_capacity(element.ResourceType.memory, node,
                                 _node.memory_mb)
            self.update_capacity(element.ResourceType.cpu_cores, node,
                                 _node.vcpus)
            self.update_capacity(element.ResourceType.disk, node,
                                 _node.free_disk_gb)
            self.update_capacity(element.ResourceType.disk_capacity, node,
                                 _node.local_gb)
            return node
        except Exception as exc:
            LOG.exception(exc)
            LOG.debug("Could not refresh the node %s.", node_hostname)
            raise exception.ComputeNodeNotFound(name=node_hostname)

        return False
Пример #4
0
    def build_compute_node(self, node):
        """Build a compute node from a Nova compute node

        :param node: A node hypervisor instance
        :type node: :py:class:`~novaclient.v2.hypervisors.Hypervisor`
        """
        # build up the compute node.
        compute_service = self.nova_helper.get_service(node.service["id"])
        node_attributes = {
            "id": node.id,
            "uuid": compute_service.host,
            "hostname": node.hypervisor_hostname,
            "memory": node.memory_mb,
            "disk": node.free_disk_gb,
            "disk_capacity": node.local_gb,
            "vcpus": node.vcpus,
            "state": node.state,
            "status": node.status,
            "disabled_reason": compute_service.disabled_reason
        }

        compute_node = element.ComputeNode(**node_attributes)
        # compute_node = self._build_node("physical", "compute", "hypervisor",
        #                                 node_attributes)
        return compute_node
Пример #5
0
    def build_compute_node(self, node):
        """Build a compute node from a Nova compute node

        :param node: A node hypervisor instance
        :type node: :py:class:`~novaclient.v2.hypervisors.Hypervisor`
        """
        inventories = self.placement_helper.get_inventories(node.id)
        if inventories and orc.VCPU in inventories:
            vcpus = inventories[orc.VCPU]['total']
            vcpu_reserved = inventories[orc.VCPU]['reserved']
            vcpu_ratio = inventories[orc.VCPU]['allocation_ratio']
        else:
            vcpus = node.vcpus
            vcpu_reserved = 0
            vcpu_ratio = 1.0

        if inventories and orc.MEMORY_MB in inventories:
            memory_mb = inventories[orc.MEMORY_MB]['total']
            memory_mb_reserved = inventories[orc.MEMORY_MB]['reserved']
            memory_ratio = inventories[orc.MEMORY_MB]['allocation_ratio']
        else:
            memory_mb = node.memory_mb
            memory_mb_reserved = 0
            memory_ratio = 1.0

        # NOTE(licanwei): A nova BP support-shared-storage-resource-provider
        # will move DISK_GB from compute node to shared storage RP.
        # Here may need to be updated when the nova BP released.
        if inventories and orc.DISK_GB in inventories:
            disk_capacity = inventories[orc.DISK_GB]['total']
            disk_gb_reserved = inventories[orc.DISK_GB]['reserved']
            disk_ratio = inventories[orc.DISK_GB]['allocation_ratio']
        else:
            disk_capacity = node.local_gb
            disk_gb_reserved = 0
            disk_ratio = 1.0

        # build up the compute node.
        node_attributes = {
            # The id of the hypervisor as a UUID from version 2.53.
            "uuid": node.id,
            "hostname": node.service["host"],
            "memory": memory_mb,
            "memory_ratio": memory_ratio,
            "memory_mb_reserved": memory_mb_reserved,
            "disk": disk_capacity,
            "disk_gb_reserved": disk_gb_reserved,
            "disk_ratio": disk_ratio,
            "vcpus": vcpus,
            "vcpu_reserved": vcpu_reserved,
            "vcpu_ratio": vcpu_ratio,
            "state": node.state,
            "status": node.status,
            "disabled_reason": node.service["disabled_reason"]}

        compute_node = element.ComputeNode(**node_attributes)
        # compute_node = self._build_node("physical", "compute", "hypervisor",
        #                                 node_attributes)
        return compute_node
Пример #6
0
 def test_assert_node_raise(self):
     model = model_root.ModelRoot()
     uuid_ = "{0}".format(uuidutils.generate_uuid())
     node = element.ComputeNode(id=1)
     node.uuid = uuid_
     model.add_node(node)
     self.assertRaises(exception.IllegalArgumentException,
                       model.assert_node, "objet_qcq")
Пример #7
0
    def build_scenario_1(self):
        instances = []

        model = modelroot.ModelRoot()
        # number of nodes
        node_count = 5
        # number max of instance per node
        node_instance_count = 7
        # total number of virtual machine
        instance_count = (node_count * node_instance_count)

        for id_ in range(0, node_count):
            node_uuid = "Node_{0}".format(id_)
            hostname = "hostname_{0}".format(id_)
            node_attributes = {
                "id": id_,
                "uuid": node_uuid,
                "hostname": hostname,
                "memory": 132,
                "disk": 250,
                "disk_capacity": 250,
                "vcpus": 40,
            }
            node = element.ComputeNode(**node_attributes)
            model.add_node(node)

        for i in range(0, instance_count):
            instance_uuid = "INSTANCE_{0}".format(i)
            instance_attributes = {
                "uuid": instance_uuid,
                "memory": 2,
                "disk": 20,
                "disk_capacity": 20,
                "vcpus": 10,
            }

            instance = element.Instance(**instance_attributes)
            instances.append(instance)
            model.add_instance(instance)

        mappings = [
            ("INSTANCE_0", "Node_0"),
            ("INSTANCE_1", "Node_0"),
            ("INSTANCE_2", "Node_1"),
            ("INSTANCE_3", "Node_2"),
            ("INSTANCE_4", "Node_2"),
            ("INSTANCE_5", "Node_2"),
            ("INSTANCE_6", "Node_3"),
            ("INSTANCE_7", "Node_4"),
        ]
        for instance_uuid, node_uuid in mappings:
            model.map_instance(
                model.get_instance_by_uuid(instance_uuid),
                model.get_node_by_uuid(node_uuid),
            )

        return model
Пример #8
0
    def test_get_node_used_resources(self):
        fake_cluster = faker_cluster_state.FakerModelCollector()
        model = fake_cluster.generate_scenario_1()
        node = element.ComputeNode(uuid="Node_0")
        resources_used = model.get_node_used_resources(node)

        self.assertEqual(20, resources_used.get('vcpu'))
        self.assertEqual(4, resources_used.get('memory'))
        self.assertEqual(40, resources_used.get('disk'))
Пример #9
0
 def test_delete_node(self):
     model = model_root.ModelRoot()
     uuid_ = "{0}".format(uuidutils.generate_uuid())
     node = element.ComputeNode(id=1)
     node.uuid = uuid_
     model.add_node(node)
     self.assertEqual(node, model.get_node_by_uuid(uuid_))
     model.remove_node(node)
     self.assertRaises(exception.ComputeNodeNotFound,
                       model.get_node_by_uuid, uuid_)
Пример #10
0
    def test_node_from_uuid_raise(self):
        model = model_root.ModelRoot()
        uuid_ = "{0}".format(uuidutils.generate_uuid())
        node = element.ComputeNode(id=1)
        node.uuid = uuid_
        model.add_node(node)

        uuid2 = "{0}".format(uuidutils.generate_uuid())
        self.assertRaises(exception.ComputeNodeNotFound,
                          model.get_node_by_uuid, uuid2)
Пример #11
0
    def test_unmap_by_uuid_log_warning(self):
        model = self.fake_cluster.generate_scenario_3_with_2_nodes()
        instances = model.get_all_instances()
        keys = list(instances.keys())
        instance0 = instances[keys[0]]
        uuid_ = "{0}".format(uuid.uuid4())
        node = element.ComputeNode(id=1)
        node.uuid = uuid_

        model.mapping.unmap_by_uuid(node.uuid, instance0.uuid)
Пример #12
0
 def test_get_all_compute_nodes(self):
     model = model_root.ModelRoot()
     for id_ in range(10):
         uuid_ = "{0}".format(uuidutils.generate_uuid())
         node = element.ComputeNode(id_)
         node.uuid = uuid_
         model.add_node(node)
     all_nodes = model.get_all_compute_nodes()
     for uuid_ in all_nodes:
         node = model.get_node_by_uuid(uuid_)
         model.assert_node(node)
Пример #13
0
    def test_get_node_instances(self):
        fake_cluster = faker_cluster_state.FakerModelCollector()
        model = fake_cluster.generate_scenario_1()
        node = element.ComputeNode(uuid="Node_0")
        instance0 = model.get_instance_by_uuid("INSTANCE_0")
        instance1 = model.get_instance_by_uuid("INSTANCE_1")
        instances = model.get_node_instances(node)

        self.assertEqual(2, len(instances))
        self.assertIn(instance0, instances)
        self.assertIn(instance1, instances)
Пример #14
0
 def test_get_node_by_name(self):
     model = model_root.ModelRoot()
     uuid_ = "{0}".format(uuidutils.generate_uuid())
     name = 'test_node'
     node = element.ComputeNode()
     node.uuid = uuid_
     node.hostname = name
     model.add_node(node)
     compute_node = model.get_node_by_name(name)
     model.assert_node(compute_node)
     self.assertEqual(name, compute_node['hostname'])
     self.assertEqual(uuid_, compute_node['uuid'])
Пример #15
0
    def test_node_from_name_raise(self):
        model = model_root.ModelRoot()
        uuid_ = "{0}".format(uuidutils.generate_uuid())
        name = 'test_node'
        node = element.ComputeNode()
        node.uuid = uuid_
        node.hostname = name
        model.add_node(node)

        fake_name = 'fake_node'
        self.assertRaises(exception.ComputeNodeNotFound,
                          model.get_node_by_name, fake_name)
Пример #16
0
    def test_set_get_state_nodes(self):
        model = model_root.ModelRoot()
        uuid_ = "{0}".format(uuidutils.generate_uuid())
        node = element.ComputeNode(id=1)
        node.uuid = uuid_
        model.add_node(node)

        self.assertIn(node.state, [el.value for el in element.ServiceState])

        node = model.get_node_by_uuid(uuid_)
        node.state = element.ServiceState.OFFLINE.value
        self.assertIn(node.state, [el.value for el in element.ServiceState])
Пример #17
0
 def test_get_node_by_instance_uuid(self):
     model = model_root.ModelRoot()
     uuid_ = "{0}".format(uuidutils.generate_uuid())
     node = element.ComputeNode(id=1)
     node.uuid = uuid_
     model.add_node(node)
     self.assertEqual(node, model.get_node_by_uuid(uuid_))
     uuid_ = "{0}".format(uuidutils.generate_uuid())
     instance = element.Instance(id=1)
     instance.uuid = uuid_
     model.add_instance(instance)
     self.assertEqual(instance, model.get_instance_by_uuid(uuid_))
     model.map_instance(instance, node)
     self.assertEqual(node, model.get_node_by_instance_uuid(instance.uuid))
Пример #18
0
    def execute(self):
        """Build the compute cluster data model"""
        LOG.debug("Building latest Nova cluster data model")

        model = model_root.ModelRoot()
        mem = element.Resource(element.ResourceType.memory)
        num_cores = element.Resource(element.ResourceType.cpu_cores)
        disk = element.Resource(element.ResourceType.disk)
        disk_capacity = element.Resource(element.ResourceType.disk_capacity)
        model.create_resource(mem)
        model.create_resource(num_cores)
        model.create_resource(disk)
        model.create_resource(disk_capacity)

        flavor_cache = {}
        nodes = self.wrapper.get_compute_node_list()
        for n in nodes:
            service = self.wrapper.nova.services.find(id=n.service['id'])
            # create node in cluster_model_collector
            node = element.ComputeNode(n.id)
            node.uuid = service.host
            node.hostname = n.hypervisor_hostname
            # set capacity
            mem.set_capacity(node, n.memory_mb)
            disk.set_capacity(node, n.free_disk_gb)
            disk_capacity.set_capacity(node, n.local_gb)
            num_cores.set_capacity(node, n.vcpus)
            node.state = n.state
            node.status = n.status
            model.add_node(node)
            instances = self.wrapper.get_instances_by_node(str(service.host))
            for v in instances:
                # create VM in cluster_model_collector
                instance = element.Instance()
                instance.uuid = v.id
                # nova/nova/compute/instance_states.py
                instance.state = getattr(v, 'OS-EXT-STS:vm_state')

                # set capacity
                self.wrapper.get_flavor_instance(v, flavor_cache)
                mem.set_capacity(instance, v.flavor['ram'])
                # FIXME: update all strategies to use disk_capacity
                # for instances instead of disk
                disk.set_capacity(instance, v.flavor['disk'])
                disk_capacity.set_capacity(instance, v.flavor['disk'])
                num_cores.set_capacity(instance, v.flavor['vcpus'])

                model.map_instance(instance, node)

        return model
Пример #19
0
    def from_xml(cls, data):
        model = cls()
        root = etree.fromstring(data)

        mem = element.Resource(element.ResourceType.memory)
        num_cores = element.Resource(element.ResourceType.cpu_cores)
        disk = element.Resource(element.ResourceType.disk)
        disk_capacity = element.Resource(element.ResourceType.disk_capacity)
        model.create_resource(mem)
        model.create_resource(num_cores)
        model.create_resource(disk)
        model.create_resource(disk_capacity)

        for cn in root.findall('.//ComputeNode'):
            node = element.ComputeNode(cn.get('id'))
            node.uuid = cn.get('uuid')
            node.hostname = cn.get('hostname')
            # set capacity
            mem.set_capacity(node, int(cn.get(str(mem.name))))
            disk.set_capacity(node, int(cn.get(str(disk.name))))
            disk_capacity.set_capacity(node,
                                       int(cn.get(str(disk_capacity.name))))
            num_cores.set_capacity(node, int(cn.get(str(num_cores.name))))
            node.state = cn.get('state')
            node.status = cn.get('status')

            model.add_node(node)

        for inst in root.findall('.//Instance'):
            instance = element.Instance()
            instance.uuid = inst.get('uuid')
            instance.state = inst.get('state')

            mem.set_capacity(instance, int(inst.get(str(mem.name))))
            disk.set_capacity(instance, int(inst.get(str(disk.name))))
            disk_capacity.set_capacity(instance,
                                       int(inst.get(str(disk_capacity.name))))
            num_cores.set_capacity(instance,
                                   int(inst.get(str(num_cores.name))))

            parent = inst.getparent()
            if parent.tag == 'ComputeNode':
                node = model.get_node_by_uuid(parent.get('uuid'))
                model.map_instance(instance, node)
            else:
                model.add_instance(instance)

        return model
Пример #20
0
    def build_compute_node(self, node):
        """Build a compute node from a Nova compute node

        :param node: A node hypervisor instance
        :type node: :py:class:`~novaclient.v2.hypervisors.Hypervisor`
        """
        # build up the compute node.
        compute_service = self.nova_helper.get_service(node.service["id"])
        node_attributes = {
            "id": node.id,
            "uuid": compute_service.host,
            "hostname": node.hypervisor_hostname,
            "memory": node.memory_mb,
            "disk": node.free_disk_gb,
            "disk_capacity": node.local_gb,
            "vcpus": node.vcpus,
            "state": node.state,
            "status": node.status}

        if compute_service.status == 'enabled':
            service_status = element.ServiceState.ENABLED.value
        elif compute_service.disabled_reason == 'watcher_disabled':
            service_status = element.ServiceState.DISABLED.value
        elif compute_service.disabled_reason == 'watcher_maintaining':
            service_status = element.ServiceState.MAINTAINING.value
        # If compute node power off, set it in 'poweroff' status.
        # If compute node power on, but not up, set it in 'poweron' status.
        # If compute node power on, and up, set it in 'disabled' status,
        # for further optimize.
        elif compute_service.disabled_reason == 'watcher_poweroff':
            service_status = element.ServiceState.POWEROFF.value
        elif compute_service.disabled_reason == 'watcher_poweron' and
            node.state == 'down':
            service_status = element.ServiceState.POWERON.value
        elif compute_service.disabled_reason == 'watcher_poweron' and
            node.state == 'up':
            service_status = element.ServiceState.DISABLED.value
        else:
            service_status = element.ServiceState.UNKNOWN.value

        node_attributes["status"] = service_status
        compute_node = element.ComputeNode(**node_attributes)
        # compute_node = self._build_node("physical", "compute", "hypervisor",
        #                                 node_attributes)
        return compute_node
Пример #21
0
    def from_xml(cls, data):
        model = cls()

        root = etree.fromstring(data)
        for cn in root.findall('.//ComputeNode'):
            node = element.ComputeNode(**cn.attrib)
            model.add_node(node)

        for inst in root.findall('.//Instance'):
            instance = element.Instance(**inst.attrib)
            model.add_instance(instance)

            parent = inst.getparent()
            if parent.tag == 'ComputeNode':
                node = model.get_node_by_uuid(parent.get('uuid'))
                model.map_instance(instance, node)
            else:
                model.add_instance(instance)

        return model
Пример #22
0
    def create_compute_node(self, node_hostname):
        """Update the compute node by querying the Nova API."""
        try:
            _node = self.nova.get_compute_node_by_hostname(node_hostname)
            node = element.ComputeNode(
                id=_node.id,
                uuid=node_hostname,
                hostname=_node.hypervisor_hostname,
                state=_node.state,
                status=_node.status,
                memory=_node.memory_mb,
                vcpus=_node.vcpus,
                disk=_node.free_disk_gb,
                disk_capacity=_node.local_gb,
            )
            return node
        except Exception as exc:
            LOG.exception(exc)
            LOG.debug("Could not refresh the node %s.", node_hostname)
            raise exception.ComputeNodeNotFound(name=node_hostname)

        return False
Пример #23
0
    def build_scenario_1(self):
        instances = []

        current_state_cluster = modelroot.ModelRoot()
        # number of nodes
        node_count = 5
        # number max of instance per node
        node_instance_count = 7
        # total number of virtual machine
        instance_count = (node_count * node_instance_count)

        # define ressouce ( CPU, MEM disk, ... )
        mem = element.Resource(element.ResourceType.memory)
        # 2199.954 Mhz
        num_cores = element.Resource(element.ResourceType.cpu_cores)
        disk = element.Resource(element.ResourceType.disk)
        disk_capacity = element.Resource(element.ResourceType.disk_capacity)

        current_state_cluster.create_resource(mem)
        current_state_cluster.create_resource(num_cores)
        current_state_cluster.create_resource(disk)
        current_state_cluster.create_resource(disk_capacity)

        for id_ in range(0, node_count):
            node_uuid = "Node_{0}".format(id_)
            node = element.ComputeNode(id_)
            node.uuid = node_uuid
            node.hostname = "hostname_{0}".format(id_)

            mem.set_capacity(node, 132)
            disk.set_capacity(node, 250)
            disk_capacity.set_capacity(node, 250)
            num_cores.set_capacity(node, 40)
            current_state_cluster.add_node(node)

        for i in range(0, instance_count):
            instance_uuid = "INSTANCE_{0}".format(i)
            instance = element.Instance()
            instance.uuid = instance_uuid
            mem.set_capacity(instance, 2)
            disk.set_capacity(instance, 20)
            disk_capacity.set_capacity(instance, 20)
            num_cores.set_capacity(instance, 10)
            instances.append(instance)
            current_state_cluster.add_instance(instance)

        current_state_cluster.mapping.map(
            current_state_cluster.get_node_by_uuid("Node_0"),
            current_state_cluster.get_instance_by_uuid("INSTANCE_0"))

        current_state_cluster.mapping.map(
            current_state_cluster.get_node_by_uuid("Node_0"),
            current_state_cluster.get_instance_by_uuid("INSTANCE_1"))

        current_state_cluster.mapping.map(
            current_state_cluster.get_node_by_uuid("Node_1"),
            current_state_cluster.get_instance_by_uuid("INSTANCE_2"))

        current_state_cluster.mapping.map(
            current_state_cluster.get_node_by_uuid("Node_2"),
            current_state_cluster.get_instance_by_uuid("INSTANCE_3"))

        current_state_cluster.mapping.map(
            current_state_cluster.get_node_by_uuid("Node_2"),
            current_state_cluster.get_instance_by_uuid("INSTANCE_4"))

        current_state_cluster.mapping.map(
            current_state_cluster.get_node_by_uuid("Node_2"),
            current_state_cluster.get_instance_by_uuid("INSTANCE_5"))

        current_state_cluster.mapping.map(
            current_state_cluster.get_node_by_uuid("Node_3"),
            current_state_cluster.get_instance_by_uuid("INSTANCE_6"))

        current_state_cluster.mapping.map(
            current_state_cluster.get_node_by_uuid("Node_4"),
            current_state_cluster.get_instance_by_uuid("INSTANCE_7"))

        return current_state_cluster
Пример #24
0
    def build_scenario_1(self):
        instances = []

        model = modelroot.ModelRoot()
        # number of nodes
        node_count = 5
        # number max of instance per node
        node_instance_count = 7
        # total number of virtual machine
        instance_count = (node_count * node_instance_count)

        for id_ in range(0, node_count):
            node_uuid = "Node_{0}".format(id_)
            hostname = "hostname_{0}".format(id_)
            node_attributes = {
                "id": id_,
                "uuid": node_uuid,
                "hostname": hostname,
                "memory": 132,
                "disk": 250,
                "disk_capacity": 250,
                "vcpus": 40,
            }
            node = element.ComputeNode(**node_attributes)
            model.add_node(node)

        for i in range(0, instance_count):
            instance_uuid = "INSTANCE_{0}".format(i)
            if instance_uuid == "INSTANCE_1":
                project_id = "26F03131-32CB-4697-9D61-9123F87A8147"
            elif instance_uuid == "INSTANCE_2":
                project_id = "109F7909-0607-4712-B32C-5CC6D49D2F15"
            else:
                project_id = "91FFFE30-78A0-4152-ACD2-8310FF274DC9"
            instance_attributes = {
                "uuid": instance_uuid,
                "memory": 2,
                "disk": 20,
                "disk_capacity": 20,
                "vcpus": 10,
                "metadata":
                '{"optimize": true,"top": "floor","nested": {"x": "y"}}',
                "project_id": project_id
            }

            instance = element.Instance(**instance_attributes)
            instances.append(instance)
            model.add_instance(instance)

        mappings = [
            ("INSTANCE_0", "Node_0"),
            ("INSTANCE_1", "Node_0"),
            ("INSTANCE_2", "Node_1"),
            ("INSTANCE_3", "Node_2"),
            ("INSTANCE_4", "Node_2"),
            ("INSTANCE_5", "Node_2"),
            ("INSTANCE_6", "Node_3"),
            ("INSTANCE_7", "Node_4"),
        ]
        for instance_uuid, node_uuid in mappings:
            model.map_instance(
                model.get_instance_by_uuid(instance_uuid),
                model.get_node_by_uuid(node_uuid),
            )

        return model