|
1 | 1 | import warnings
|
2 | 2 |
|
| 3 | +import grafana_client |
| 4 | +from grafana_client.elements.plugin import filter_plugin_by_id |
3 | 5 | from munch import munchify
|
4 | 6 | from packaging import version
|
5 | 7 |
|
@@ -555,3 +557,90 @@ def test_info(docker_grafana, capsys, caplog):
|
555 | 557 | assert "dashboard_panels" in data["summary"]
|
556 | 558 | assert "dashboard_annotations" in data["summary"]
|
557 | 559 | assert "dashboard_templating" in data["summary"]
|
| 560 | + |
| 561 | + |
| 562 | +def test_plugins_list(docker_grafana, capsys, caplog): |
| 563 | + """ |
| 564 | + Verify the plugin inquiry API works. |
| 565 | + """ |
| 566 | + # Which subcommand to test? |
| 567 | + set_command("plugins list", "--format=yaml") |
| 568 | + |
| 569 | + # Run command and capture YAML output. |
| 570 | + with caplog.at_level(logging.DEBUG): |
| 571 | + grafana_wtf.commands.run() |
| 572 | + captured = capsys.readouterr() |
| 573 | + data = yaml.safe_load(captured.out) |
| 574 | + |
| 575 | + # Grafana 6 has 28 plugins preinstalled. |
| 576 | + assert len(data) >= 28 |
| 577 | + |
| 578 | + # Proof the output is correct. |
| 579 | + plugin = munchify(filter_plugin_by_id(plugin_list=data, plugin_id="alertlist")) |
| 580 | + assert plugin.name.title() == "Alert List" |
| 581 | + assert plugin.type == "panel" |
| 582 | + assert plugin.id == "alertlist" |
| 583 | + assert plugin.category == "" |
| 584 | + assert plugin.enabled is True |
| 585 | + assert plugin.info.author.name in ["Grafana Project", "Grafana Labs"] |
| 586 | + assert plugin.info.version == "" |
| 587 | + |
| 588 | + assert "metrics" not in plugin |
| 589 | + assert "health" not in plugin |
| 590 | + |
| 591 | + |
| 592 | +def test_plugins_status_datasource(grafana_version, docker_grafana, capsys, caplog): |
| 593 | + """ |
| 594 | + Verify the plugin status (metrics endpoint) on a 3rd-party "datasource" plugin. |
| 595 | + """ |
| 596 | + if version.parse(grafana_version) < version.parse("8"): |
| 597 | + raise pytest.skip(f"Plugin status inquiry only works on Grafana 8 and newer") |
| 598 | + |
| 599 | + # Before conducting a plugin status test, install a non-internal one. |
| 600 | + grafana = grafana_client.GrafanaApi.from_url(url=docker_grafana, timeout=15) |
| 601 | + grafana.plugin.install_plugin("yesoreyeram-infinity-datasource") |
| 602 | + |
| 603 | + # Which subcommand to test? |
| 604 | + set_command("plugins status", "--format=yaml") |
| 605 | + |
| 606 | + # Run command and capture YAML output. |
| 607 | + with caplog.at_level(logging.DEBUG): |
| 608 | + grafana_wtf.commands.run() |
| 609 | + captured = capsys.readouterr() |
| 610 | + data = yaml.safe_load(captured.out) |
| 611 | + |
| 612 | + # Grafana 6 has 28 plugins preinstalled. |
| 613 | + assert len(data) >= 28 |
| 614 | + |
| 615 | + # Proof the output is correct. |
| 616 | + plugin = munchify(filter_plugin_by_id(plugin_list=data, plugin_id="yesoreyeram-infinity-datasource")) |
| 617 | + assert "go_gc_duration_seconds" in plugin.metrics |
| 618 | + |
| 619 | + |
| 620 | +def test_plugins_status_app(grafana_version, docker_grafana, capsys, caplog): |
| 621 | + """ |
| 622 | + Verify the plugin status (metrics endpoint and health check) on a 3rd-party "app" plugin. |
| 623 | + """ |
| 624 | + if version.parse(grafana_version) < version.parse("8"): |
| 625 | + raise pytest.skip(f"Plugin status inquiry only works on Grafana 8 and newer") |
| 626 | + |
| 627 | + # Before conducting a plugin status test, install a non-internal one. |
| 628 | + grafana = grafana_client.GrafanaApi.from_url(url=docker_grafana, timeout=15) |
| 629 | + grafana.plugin.install_plugin("aws-datasource-provisioner-app") |
| 630 | + |
| 631 | + # Which subcommand to test? |
| 632 | + set_command("plugins status", "--format=yaml") |
| 633 | + |
| 634 | + # Run command and capture YAML output. |
| 635 | + with caplog.at_level(logging.DEBUG): |
| 636 | + grafana_wtf.commands.run() |
| 637 | + captured = capsys.readouterr() |
| 638 | + data = yaml.safe_load(captured.out) |
| 639 | + |
| 640 | + # Grafana 6 has 28 plugins preinstalled. |
| 641 | + assert len(data) >= 28 |
| 642 | + |
| 643 | + # Proof the output is correct. |
| 644 | + plugin = munchify(filter_plugin_by_id(plugin_list=data, plugin_id="aws-datasource-provisioner-app")) |
| 645 | + assert "process_virtual_memory_max_bytes" in plugin.metrics |
| 646 | + assert plugin.health == {"message": "", "status": "OK"} |
0 commit comments