Exemplo n.º 1
0
def test_convert_metrics_to_table_store_multiple_buckets(caplog, metric_name):
    results = metrics.MetricResults(
        status=metrics.MetricsStatus["OK"],
        snap_id="test-snap-id",
        metric_name=metric_name,
        buckets=["2021-01-01", "2021-01-02", "2021-01-03"],
        series=[
            metrics.Series(name="blah",
                           values=[1, 2, 3],
                           currently_released=None),
            metrics.Series(name="blahh",
                           values=[4, 5, 6],
                           currently_released=None),
            metrics.Series(name="blahhh",
                           values=[7, 8, 9],
                           currently_released=None),
        ],
    )

    assert convert_metrics_to_table(results) == [
        (
            get_series_label_from_metric_name(metric_name),
            "2021-01-01",
            "2021-01-02",
            "2021-01-03",
        ),
        ("Blah", 1, 2, 3),
        ("Blahh", 4, 5, 6),
        ("Blahhh", 7, 8, 9),
    ]
    assert [rec.message for rec in caplog.records] == []
Exemplo n.º 2
0
def test_convert_metrics_to_table_no_data(caplog, metric_name):
    results = metrics.MetricResults(
        status=metrics.MetricsStatus["NO DATA"],
        snap_id="foo",
        metric_name=metric_name,
        buckets=[],
        series=[],
    )

    assert convert_metrics_to_table(results) == []
    assert [rec.message for rec in caplog.records] == []
Exemplo n.º 3
0
def test_convert_metrics_to_table_store_failure_no_data(caplog, metric_name):
    results = metrics.MetricResults(
        status=metrics.MetricsStatus["FAIL"],
        snap_id="foo",
        metric_name=metric_name,
        buckets=[],
        series=[],
    )

    assert convert_metrics_to_table(results) == []
    assert [rec.message for rec in caplog.records
            ] == ["No data available due to Snap Store internal failure."]
Exemplo n.º 4
0
def test_convert_metrics_to_table_store_one_bucket(caplog, metric_name):
    results = metrics.MetricResults(
        status=metrics.MetricsStatus["OK"],
        snap_id="test-snap-id",
        metric_name=metric_name,
        buckets=["2021-01-01"],
        series=[
            metrics.Series(name="blah", values=[1], currently_released=None)
        ],
    )

    assert convert_metrics_to_table(results) == [
        (get_series_label_from_metric_name(metric_name), "2021-01-01"),
        ("Blah", 1),
    ]
    assert [rec.message for rec in caplog.records] == []
Exemplo n.º 5
0
    def setUp(self):
        super().setUp()

        # Our experimental environment variable is sticky
        self.useFixture(
            fixtures.EnvironmentVariable(
                "SNAPCRAFT_EXPERIMENTAL_PROGRESSIVE_RELEASES", None))

        self.fake_store_login = fixtures.MockPatchObject(
            storeapi.StoreClient, "login")
        self.useFixture(self.fake_store_login)

        self.fake_store_logout = fixtures.MockPatchObject(
            storeapi.StoreClient, "logout")
        self.useFixture(self.fake_store_logout)

        self.fake_store_register = fixtures.MockPatchObject(
            storeapi._dashboard_api.DashboardAPI, "register")
        self.useFixture(self.fake_store_register)

        self.fake_store_account_info_data = {
            "account_id": "abcd",
            "account_keys": list(),
            "snaps": {
                "16": {
                    "snap-test": {
                        "snap-id": "snap-test-snap-id",
                        "status": "Approved",
                        "private": False,
                        "since": "2016-12-12T01:01Z",
                        "price": "0",
                    },
                    "basic": {
                        "snap-id": "basic-snap-id",
                        "status": "Approved",
                        "private": False,
                        "since": "2016-12-12T01:01Z",
                        "price": "0",
                    },
                }
            },
        }

        self.fake_store_account_info = fixtures.MockPatchObject(
            storeapi._dashboard_api.DashboardAPI,
            "get_account_information",
            return_value=self.fake_store_account_info_data,
        )
        self.useFixture(self.fake_store_account_info)

        self.fake_store_status = fixtures.MockPatchObject(
            storeapi._dashboard_api.DashboardAPI,
            "snap_status",
            return_value=dict())
        self.useFixture(self.fake_store_status)

        self.fake_store_release = fixtures.MockPatchObject(
            storeapi.StoreClient, "release")
        self.useFixture(self.fake_store_release)

        self.fake_store_register_key = fixtures.MockPatchObject(
            storeapi._dashboard_api.DashboardAPI, "register_key")
        self.useFixture(self.fake_store_register_key)

        self.metrics = metrics.MetricsResults(metrics=[
            metrics.MetricResults(
                status=metrics.MetricsStatus["OK"],
                snap_id="test-snap-id",
                metric_name="daily_device_change",
                buckets=["2021-01-01", "2021-01-02", "2021-01-03"],
                series=[
                    metrics.Series(
                        name="continued",
                        values=[10, 11, 12],
                        currently_released=None,
                    ),
                    metrics.Series(name="lost",
                                   values=[1, 2, 3],
                                   currently_released=None),
                    metrics.Series(
                        name="new", values=[2, 3, 4], currently_released=None),
                ],
            )
        ])
        self.fake_store_get_metrics = fixtures.MockPatchObject(
            storeapi.StoreClient, "get_metrics", return_value=self.metrics)
        self.useFixture(self.fake_store_get_metrics)

        self.releases = Releases.unmarshal({
            "revisions": [
                {
                    "architectures": ["i386"],
                    "base": "core20",
                    "build_url": None,
                    "confinement": "strict",
                    "created_at": " 2016-09-27T19:23:40Z",
                    "grade": "stable",
                    "revision": 2,
                    "sha3-384":
                    "a9060ef4872ccacbfa440617a76fcd84967896b28d0d1eb7571f00a1098d766e7e93353b084ba6ad841d7b14b95ede48",
                    "size": 20,
                    "status": "Published",
                    "version": "2.0.1",
                },
                {
                    "architectures": ["amd64"],
                    "base": "core20",
                    "build_url": None,
                    "confinement": "strict",
                    "created_at": "2016-09-27T18:38:43Z",
                    "grade": "stable",
                    "revision": 1,
                    "sha3-384":
                    "a9060ef4872ccacbfa440617a76fcd84967896b28d0d1eb7571f00a1098d766e7e93353b084ba6ad841d7b14b95ede48",
                    "size": 20,
                    "status": "Published",
                    "version": "2.0.2",
                },
            ],
            "releases": [
                {
                    "architecture": "amd64",
                    "branch": None,
                    "channel": "latest/stable",
                    "expiration-date": None,
                    "revision": 1,
                    "risk": "stable",
                    "track": "latest",
                    "when": "2020-02-12T17:51:40.891996Z",
                },
                {
                    "architecture": "i386",
                    "branch": None,
                    "channel": "latest/stable",
                    "expiration-date": None,
                    "revision": None,
                    "risk": "stable",
                    "track": "latest",
                    "when": "2020-02-11T17:51:40.891996Z",
                },
                {
                    "architecture": "amd64",
                    "branch": None,
                    "channel": "latest/edge",
                    "expiration-date": None,
                    "revision": 1,
                    "risk": "stable",
                    "track": "latest",
                    "when": "2020-01-12T17:51:40.891996Z",
                },
            ],
        })
        self.fake_store_get_releases = fixtures.MockPatchObject(
            storeapi.StoreClient,
            "get_snap_releases",
            return_value=self.releases)
        self.useFixture(self.fake_store_get_releases)

        # Mock the snap command, pass through a select few.
        self.fake_check_output = fixtures.MockPatch(
            "subprocess.check_output", side_effect=mock_check_output)
        self.useFixture(self.fake_check_output)

        # Pretend that the snap command is available
        self.fake_package_installed = fixtures.MockPatch(
            "snapcraft_legacy.internal.repo.Repo.is_package_installed",
            return_value=True,
        )
        self.useFixture(self.fake_package_installed)