Exemplo n.º 1
0
 def test_link_vm(self):
     num = 3
     vms = [mock.Mock(id=i) for i in range(3)]
     n = node.Node(*range(7))
     initial_length = len(n.vms)
     map(n.link_vm, vms)
     self.assertEqual(initial_length + num, len(n.vms))
Exemplo n.º 2
0
    def from_dicts(cls, name, nodes, flavors, vms, groups):
        """
        This method creates cloud structure from dicts parsed from files
        We create objects in following order:
            1 - create flavor objects
            2 - find http://en.wikipedia.org/wiki/Greatest_common_divisor on
                all flavor properties
            3 - call reduce_resources method on all flavors objects
            4 - create all nodes objects
            5 - create vm objects assigned linked with node objects and
                flavor objects
            6 - create group objects linked to vms
        """
        nodes_dict, flavors_dict, vms_dict = {}, {}, {}

        # create Flavor Objects
        for flavor_id, flavor_params in flavors.items():
            flavors_dict.update(
                {flavor_id: flavor.Flavor(**flavor_params)})
        flavors_dict[flavor.default] = flavor.default

        # count gcd on Flavors for ram and cores
        ram_factor = reduce(
            fractions.gcd, [i.ram for i in flavors_dict.values()])
        core_factor = reduce(
            fractions.gcd, [i.core for i in flavors_dict.values()])

        # reduce flavors with core_factor and ram_factor
        for flavor_obj in flavors_dict.values():
            flavor_obj.reduce_resources(ram_factor, core_factor)

        # create Node Objects
        for node_name, node_params in nodes.items():
            # replace fqdn with just node name
            node_name = node_name.split(".")[0]
            nodes_dict.update(
                {node_name: node.Node(
                    name=node_name,
                    ram_factor=ram_factor,
                    core_factor=core_factor,
                    **node_params)})

        # create Vm objects linked to Nodes and Flavors
        for vm_params in vms.values():
            node_obj = nodes_dict.get(vm_params.get("host"))
            if node_obj is None:
                # VM is running on a host which is down
                LOG.info("VM '%s' is running on a down host. Skipping.",
                         vm_params['id'])
                continue
            flavor_obj = flavors_dict.get(vm_params.get("flavor"))
            vms_dict.update({vm_params.get("id"): vm.Vm(
                node=node_obj,
                vm_id=vm_params.get("id"),
                flavor=flavor_obj)})

        # create Groups objects
        groups = group.Group.from_dict(groups, vms_dict)
        return cls(name, nodes_dict, groups)
Exemplo n.º 3
0
 def test_calculate_flavors_required(self):
     n = node.Node(*range(1, 8))
     self.assertEqual(dict, type(n.calculate_flavors_required({})))
Exemplo n.º 4
0
 def test_potential_utilization(self):
     n = node.Node(*range(1, 8))
     self.assertEqual(tuple, type(n.potential_utilization({})))
Exemplo n.º 5
0
 def test_utilization(self):
     n = node.Node(*range(1, 8))
     self.assertEqual(tuple, type(n.utilization))
Exemplo n.º 6
0
 def test_free_resources(self):
     n = node.Node(*range(1, 8))
     self.assertEqual(tuple, type(n.free_resources))
Exemplo n.º 7
0
 def test_is_full(self):
     n = node.Node(*range(1, 8))
     self.assertEqual(bool, type(n.is_full))