Beispiel #1
0
    def test_update_storage_data(self):
        """Test that _update_storage_data updates storage data."""
        kwargs = {
            "volume_claim_usage_gig":
            self._usage_dict(),
            "vc_capacity":
            self.fake.pyint(1, 100),
            "namespace":
            self.fake.word(),
            "pod":
            self.fake.word(),
            "volume_claim":
            self.fake.uuid4(),
            "volume_name":
            self.fake.word(),
            "storage_class":
            self.fake.word(),
            "volume_request":
            self.fake.pyint(1, 100),
            "volume_labels": (
                f"label_{self.fake.word()}:{self.fake.word()}",
                f"|label_{self.fake.word()}:{self.fake.word()}",
            ),
            "volume_claim_labels": (
                f"label_{self.fake.word()}:{self.fake.word()}",
                f"|label_{self.fake.word()}:{self.fake.word()}",
            ),
        }
        changed = {
            "namespace",
            "pod",
            "persistentvolumeclaim",
            "persistentvolume",
            "storageclass",
            "persistentvolumeclaim_capacity_bytes",
            "persistentvolumeclaim_capacity_byte_seconds",
            "volume_request_storage_byte_seconds",
            "persistentvolume_labels",
            "persistentvolumeclaim_labels",
            "persistentvolumeclaim_usage_byte_seconds",
        }

        generator = OCPGenerator(self.two_hours_ago, self.now)
        in_row = generator._init_data_row(self.two_hours_ago,
                                          self.now,
                                          report_type=OCP_STORAGE_USAGE)
        out_row = generator._update_storage_data(copy(in_row),
                                                 self.two_hours_ago, self.now,
                                                 **kwargs)

        for key in changed:
            with self.subTest(key=key):
                if key in kwargs:
                    self.assertEqual(out_row.get(key), kwargs.get(key))
                self.assertNotEqual(out_row.get(key), in_row.get(key))

        for key in list(set(out_row.keys()) - changed):
            with self.subTest(key=key):
                self.assertIsNotNone(out_row.get(key))
Beispiel #2
0
    def test_update_storage_data_usage_lt_request(self):
        """Test that _update_storge_data keeps usage <= capacity <= request."""
        kwargs = {
            "volume_claim_usage_gig":
            self._usage_dict(),
            "vc_capacity":
            self.fake.pyint(1, 100),
            "namespace":
            self.fake.word(),
            "pod":
            self.fake.word(),
            "volume_claim":
            self.fake.uuid4(),
            "volume_name":
            self.fake.word(),
            "storage_class":
            self.fake.word(),
            "volume_request":
            self.fake.pyint(1, 100),
            "volume_labels": (
                f"label_{self.fake.word()}:{self.fake.word()}",
                f"|label_{self.fake.word()}:{self.fake.word()}",
            ),
            "volume_claim_labels": (
                f"label_{self.fake.word()}:{self.fake.word()}",
                f"|label_{self.fake.word()}:{self.fake.word()}",
            ),
        }

        generator = OCPGenerator(self.two_hours_ago, self.now)
        in_row = generator._init_data_row(self.two_hours_ago,
                                          self.now,
                                          report_type=OCP_STORAGE_USAGE)
        out_row = generator._update_storage_data(copy(in_row),
                                                 self.two_hours_ago, self.now,
                                                 **kwargs)

        self.assertLessEqual(
            out_row.get("persistentvolumeclaim_usage_byte_seconds"),
            out_row.get("persistentvolumeclaim_capacity_byte_seconds") *
            GIGABYTE,
        )
        self.assertLessEqual(
            out_row.get("persistentvolumeclaim_capacity_byte_seconds"),
            out_row.get("volume_request_storage_byte_seconds"),
        )