Exemple #1
0
 def test_gen_pods_usage_lt_capacity(self):
     """Test that gen_pods generates requests and usage values which don't exceed limit."""
     for attributes in [self.attributes, {}]:
         with self.subTest(attributes=attributes):
             generator = OCPGenerator(self.two_hours_ago, self.now,
                                      attributes)
             # gen_pods depends on the output of gen_namespaces.
             out_pods, _ = generator._gen_pods(generator.namespaces)
             for pod in out_pods.values():
                 with self.subTest(pod=pod):
                     self.assertLessEqual(
                         pod.get("cpu_limit"),
                         pod.get("node_capacity_cpu_cores"))
                     self.assertLessEqual(
                         pod.get("cpu_request"),
                         pod.get("node_capacity_cpu_cores"))
                     self.assertLessEqual(
                         pod.get("mem_limit_gig"),
                         pod.get("node_capacity_memory_bytes"))
                     self.assertLessEqual(
                         pod.get("mem_request_gig"),
                         pod.get("node_capacity_memory_bytes"))
                     if attributes:
                         for value in pod.get("cpu_usage").values():
                             self.assertLessEqual(
                                 value, pod.get("node_capacity_cpu_cores"))
                         for value in pod.get("mem_usage_gig").values():
                             self.assertLessEqual(
                                 value,
                                 pod.get("node_capacity_memory_bytes"))
Exemple #2
0
    def test_gen_pods_without_namespaces(self):
        """Test that gen_pods arranges the output dict in the expected way.

            If no namespaces are specified, pods are generated.
        """
        generator = OCPGenerator(self.two_hours_ago, self.now, {})
        out_pods, _ = generator._gen_pods(generator.namespaces)

        # these magic numbers are the random ranges defined in the OCP generator.
        self.assertGreaterEqual(len(out_pods), 2 * 2 * 2)
        self.assertLessEqual(len(out_pods), 6 * 12 * 20)

        # This list isn't quite the same as (OCP_POD_USAGE_COLUMNS + OCP_NODE_LABEL_COLUMNS + OCP_STORAGE_COLUMNS)
        # This might be a bug.
        expected = (
            "cpu_limit",
            "cpu_request",
            "cpu_usage",
            "interval_start",
            "interval_end",
            "mem_limit_gig",
            "mem_request_gig",
            "mem_usage_gig",
            "namespace",
            "node",
            "node_capacity_cpu_cores",
            "node_capacity_cpu_core_seconds",
            "node_capacity_memory_bytes",
            "node_capacity_memory_byte_seconds",
            "node_labels",
            "pod",
            "pod_labels",
            "pod_limit_cpu_core_seconds",
            "pod_limit_memory_byte_seconds",
            "pod_request_cpu_core_seconds",
            "pod_request_memory_byte_seconds",
            "pod_seconds",
            "pod_usage_cpu_core_seconds",
            "pod_usage_memory_byte_seconds",
            "report_period_start",
            "report_period_end",
            "resource_id",
        )
        for pod in out_pods.values():
            with self.subTest(podkeys=pod.keys()):
                for key in pod.keys():
                    with self.subTest(key=key):
                        self.assertIn(key, expected)
Exemple #3
0
    def test_gen_pods_with_namespaces(self):
        """Test that gen_pods arranges the output dict in the expected way.

            If namespaces with pods are specified, defined pods are used.
        """
        generator = OCPGenerator(self.two_hours_ago, self.now, self.attributes)
        out_pods, _ = generator._gen_pods(
            generator.namespaces
        )  # gen_pods depends on the output of gen_namespaces.
        self.assertEqual(len(out_pods), 2)

        expected = (
            "cpu_limit",
            "cpu_request",
            "cpu_usage",
            "interval_start",
            "interval_end",
            "mem_limit_gig",
            "mem_request_gig",
            "mem_usage_gig",
            "namespace",
            "node",
            "node_capacity_cpu_cores",
            "node_capacity_cpu_core_seconds",
            "node_capacity_memory_bytes",
            "node_capacity_memory_byte_seconds",
            "node_labels",
            "pod",
            "pod_labels",
            "pod_limit_cpu_core_seconds",
            "pod_limit_memory_byte_seconds",
            "pod_request_cpu_core_seconds",
            "pod_request_memory_byte_seconds",
            "pod_seconds",
            "pod_usage_cpu_core_seconds",
            "pod_usage_memory_byte_seconds",
            "report_period_start",
            "report_period_end",
            "resource_id",
        )
        for pod in out_pods.values():
            with self.subTest(podkeys=pod.keys()):
                for key in pod.keys():
                    with self.subTest(key=key):
                        self.assertIn(key, expected)
Exemple #4
0
    def test_gen_pods_with_namespaces(self):
        """Test that gen_pods arranges the output dict in the expected way.

            If namespaces with pods are specified, defined pods are used.
        """
        generator = OCPGenerator(self.two_hours_ago, self.now)
        in_node = self.attributes.get("nodes")[0]
        in_namespace = self.attributes.get("nodes")[0].get(
            "namespaces")[0].get("namespace_name")
        out_pods = generator._gen_pods(in_node, in_namespace)
        self.assertGreaterEqual(len(out_pods), 1)

        expected = (
            "namespace",
            "node",
            "resource_id",
            "pod_name",
            "node_capacity_cpu_cores",
            "node_capacity_cpu_core_seconds",
            "node_capacity_memory_bytes",
            "node_capacity_memory_byte_seconds",
            "cpu_request",
            "cpu_limit",
            "mem_request_gig",
            "mem_limit_gig",
            "labels",
            "cpu_usage",
            "mem_usage_gig",
            "pod_seconds",
        )
        for pod in out_pods:
            with self.subTest(podkeys=pod.keys()):
                for key in pod.keys():
                    with self.subTest(key=key):
                        self.assertIn(key, expected)
            self.assertEqual(pod.get("node"), in_node.get("node_name"))
            self.assertEqual(pod.get("namespace"), in_namespace)