Пример #1
0
    def test_get_maas_stats(self):
        # Make one component of everything
        factory.make_RegionRackController()
        factory.make_RegionController()
        factory.make_RackController()
        factory.make_Machine(cpu_count=2, memory=200, status=NODE_STATUS.READY)
        factory.make_Machine(status=NODE_STATUS.READY)
        factory.make_Machine(status=NODE_STATUS.NEW)
        for _ in range(4):
            factory.make_Machine(status=NODE_STATUS.ALLOCATED)
        factory.make_Machine(
            cpu_count=3, memory=100, status=NODE_STATUS.FAILED_DEPLOYMENT
        )
        for _ in range(2):
            factory.make_Machine(status=NODE_STATUS.DEPLOYED)
        factory.make_Device()
        factory.make_Device()

        subnets = Subnet.objects.all()
        v4 = [net for net in subnets if net.get_ip_version() == 4]
        v6 = [net for net in subnets if net.get_ip_version() == 6]

        stats = get_maas_stats()
        machine_stats = get_machine_stats()

        # Due to floating point calculation subtleties, sometimes the value the
        # database returns is off by one compared to the value Python
        # calculates, so just get it directly from the database for the test.
        total_storage = machine_stats["total_storage"]

        expected = {
            "controllers": {"regionracks": 1, "regions": 1, "racks": 1},
            "nodes": {"machines": 10, "devices": 2},
            "machine_stats": {
                "total_cpu": 5,
                "total_mem": 300,
                "total_storage": total_storage,
            },
            "machine_status": {
                "new": 1,
                "ready": 2,
                "allocated": 4,
                "deployed": 2,
                "commissioning": 0,
                "testing": 0,
                "deploying": 0,
                "failed_deployment": 1,
                "failed_commissioning": 0,
                "failed_testing": 0,
                "broken": 0,
            },
            "network_stats": {
                "spaces": Space.objects.count(),
                "fabrics": Fabric.objects.count(),
                "vlans": VLAN.objects.count(),
                "subnets_v4": len(v4),
                "subnets_v6": len(v6),
            },
        }
        self.assertEqual(json.loads(stats), expected)
Пример #2
0
    def test_get_maas_stats(self):
        # Make one component of everything
        factory.make_RegionRackController()
        factory.make_RegionController()
        factory.make_RackController()
        factory.make_Machine(cpu_count=2, memory=200)
        factory.make_Machine(cpu_count=3, memory=100)
        factory.make_Device()

        stats = get_maas_stats()
        machine_stats = get_machine_stats()

        # Due to floating point calculation subtleties, sometimes the value the
        # database returns is off by one compared to the value Python
        # calculates, so just get it directly from the database for the test.
        total_storage = machine_stats['total_storage']

        compare = {
            "controllers": {
                "regionracks": 1,
                "regions": 1,
                "racks": 1,
            },
            "nodes": {
                "machines": 2,
                "devices": 1,
            },
            "machine_stats": {
                "total_cpu": 5,
                "total_mem": 300,
                "total_storage": total_storage,
            },
        }
        self.assertEquals(stats, json.dumps(compare))
Пример #3
0
    def test_get_maas_stats(self):
        # Make one component of everything
        factory.make_RegionRackController()
        factory.make_RegionController()
        factory.make_RackController()
        factory.make_Machine(cpu_count=2, memory=200, status=4)
        factory.make_Machine(cpu_count=3, memory=100, status=11)
        factory.make_Device()

        subnets = Subnet.objects.all()
        v4 = [net for net in subnets if net.get_ip_version() == 4]
        v6 = [net for net in subnets if net.get_ip_version() == 6]

        stats = get_maas_stats()
        machine_stats = get_machine_stats()

        # Due to floating point calculation subtleties, sometimes the value the
        # database returns is off by one compared to the value Python
        # calculates, so just get it directly from the database for the test.
        total_storage = machine_stats['total_storage']

        node_status = Node.objects.values_list('status', flat=True)
        node_status = Counter(node_status)

        compare = {
            "controllers": {
                "regionracks": 1,
                "regions": 1,
                "racks": 1,
            },
            "nodes": {
                "machines": 2,
                "devices": 1,
            },
            "machine_stats": {
                "total_cpu": 5,
                "total_mem": 300,
                "total_storage": total_storage,
            },
            "machine_status": {
                "new":
                node_status.get(NODE_STATUS.NEW, 0),
                "ready":
                node_status.get(NODE_STATUS.READY, 0),
                "allocated":
                node_status.get(NODE_STATUS.ALLOCATED, 0),
                "deployed":
                node_status.get(NODE_STATUS.DEPLOYED, 0),
                "commissioning":
                node_status.get(NODE_STATUS.COMMISSIONING, 0),
                "testing":
                node_status.get(NODE_STATUS.TESTING, 0),
                "deploying":
                node_status.get(NODE_STATUS.DEPLOYING, 0),
                "failed_deployment":
                node_status.get(NODE_STATUS.FAILED_DEPLOYMENT, 0),
                "failed_commissioning":
                node_status.get(NODE_STATUS.COMMISSIONING, 0),
                "failed_testing":
                node_status.get(NODE_STATUS.FAILED_TESTING, 0),
                "broken":
                node_status.get(NODE_STATUS.BROKEN, 0),
            },
            "network_stats": {
                "spaces": Space.objects.count(),
                "fabrics": Fabric.objects.count(),
                "vlans": VLAN.objects.count(),
                "subnets_v4": len(v4),
                "subnets_v6": len(v6),
            },
        }
        self.assertEquals(stats, json.dumps(compare))
Пример #4
0
    def test_get_maas_stats(self):
        # Make one component of everything
        factory.make_RegionRackController()
        factory.make_RegionController()
        factory.make_RackController()
        factory.make_Machine(cpu_count=2, memory=200, status=NODE_STATUS.READY)
        factory.make_Machine(status=NODE_STATUS.READY)
        factory.make_Machine(status=NODE_STATUS.NEW)
        for _ in range(4):
            factory.make_Machine(status=NODE_STATUS.ALLOCATED)
        factory.make_Machine(cpu_count=3,
                             memory=100,
                             status=NODE_STATUS.FAILED_DEPLOYMENT)
        factory.make_Machine(status=NODE_STATUS.DEPLOYED)
        deployed_machine = factory.make_Machine(status=NODE_STATUS.DEPLOYED)
        OwnerData.objects.set_owner_data(deployed_machine, {"foo": "bar"})
        factory.make_Device()
        factory.make_Device()
        self.make_pod(cpu=10, mem=100, pod_type="lxd")
        self.make_pod(cpu=20, mem=200, pod_type="virsh")

        subnets = Subnet.objects.all()
        v4 = [net for net in subnets if net.get_ip_version() == 4]
        v6 = [net for net in subnets if net.get_ip_version() == 6]

        stats = get_maas_stats()
        machine_stats = get_machine_stats()

        # Due to floating point calculation subtleties, sometimes the value the
        # database returns is off by one compared to the value Python
        # calculates, so just get it directly from the database for the test.
        total_storage = machine_stats["total_storage"]

        expected = {
            "controllers": {
                "regionracks": 1,
                "regions": 1,
                "racks": 1
            },
            "nodes": {
                "machines": 10,
                "devices": 2
            },
            "machine_stats": {
                "total_cpu": 5,
                "total_mem": 300,
                "total_storage": total_storage,
            },
            "machine_status": {
                "new": 1,
                "ready": 2,
                "allocated": 4,
                "deployed": 2,
                "commissioning": 0,
                "testing": 0,
                "deploying": 0,
                "failed_deployment": 1,
                "failed_commissioning": 0,
                "failed_testing": 0,
                "broken": 0,
            },
            "network_stats": {
                "spaces": Space.objects.count(),
                "fabrics": Fabric.objects.count(),
                "vlans": VLAN.objects.count(),
                "subnets_v4": len(v4),
                "subnets_v6": len(v6),
            },
            "vm_hosts": {
                "lxd": {
                    "vm_hosts": 1,
                    "vms": 0,
                    "available_resources": {
                        "cores": 10,
                        "memory": 100,
                        "over_cores": 10.0,
                        "over_memory": 100.0,
                        "storage": 0,
                    },
                    "utilized_resources": {
                        "cores": 0,
                        "memory": 0,
                        "storage": 0,
                    },
                },
                "virsh": {
                    "vm_hosts": 1,
                    "vms": 0,
                    "available_resources": {
                        "cores": 20,
                        "memory": 200,
                        "over_cores": 20.0,
                        "over_memory": 200.0,
                        "storage": 0,
                    },
                    "utilized_resources": {
                        "cores": 0,
                        "memory": 0,
                        "storage": 0,
                    },
                },
            },
            "workload_annotations": {
                "annotated_machines": 1,
                "total_annotations": 1,
                "unique_keys": 1,
                "unique_values": 1,
            },
        }
        self.assertEqual(stats, expected)