Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Host status test #216

Merged
merged 16 commits into from
Mar 11, 2019
4 changes: 3 additions & 1 deletion usmqe/api/grafanaapi/grafanaapi.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,9 @@ def get_panel(self, panel_title, row_title, dashboard):
found_panels = [
panel for panel in panels
if "title" in panel and
panel["title"] == panel_title]
panel["title"] == panel_title
or "displayName" in panel and
panel["displayName"] == panel_title]
assert len(found_panels) == 1
return found_panels[0]

Expand Down
5 changes: 2 additions & 3 deletions usmqe/api/graphiteapi/graphiteapi.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,9 +97,8 @@ def compare_data_mean(
msg = "Data mean should be {}, data mean in Graphite is: {}, ".format(
expected_result,
graphite_data_mean_sum)
print(type(msg))
msg += "applicable divergence is {}".format(divergence)
pytest.check(
minimal_expected_result <
graphite_data_mean_sum < maximal_expected_result,
minimal_expected_result <=
graphite_data_mean_sum <= maximal_expected_result,
msg)
66 changes: 66 additions & 0 deletions usmqe_tests/api/grafana/test_cluster_dashboard.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
"""

import pytest
import time
from usmqe.api.grafanaapi import grafanaapi
from usmqe.api.graphiteapi import graphiteapi
from usmqe.gluster.gluster import GlusterCommon
Expand Down Expand Up @@ -209,3 +210,68 @@ def test_hosts_panel_status(cluster_reuse):
g_down == len(real_down),
"Number of hosts that are down in graphite ({}) should be {}".format(
g_down, len(real_down)))


@pytest.mark.ansible_playbook_setup("test_setup.tendrl_services_stopped_on_nodes.yml")
@pytest.mark.ansible_playbook_teardown("test_teardown.tendrl_services_stopped_on_nodes.yml")
@pytest.mark.author("[email protected]")
def test_hosts(ansible_playbook, workload_stop_nodes, cluster_reuse):
"""
Check that Grafana panel *Hosts* is showing correct values.
"""
if cluster_reuse["short_name"]:
cluster_identifier = cluster_reuse["short_name"]
else:
cluster_identifier = cluster_reuse["integration_id"]

grafana = grafanaapi.GrafanaApi()
graphite = graphiteapi.GraphiteApi()

hosts_panel = grafana.get_panel(
"Hosts",
row_title="At-a-glance",
dashboard="cluster-dashboard")

"""
:step:
Send **GET** request to ``GRAPHITE/render?target=[target]&format=json``
where [target] is part of uri obtained from previous GRAFANA call.
There should be target for statuses of a hosts.
Compare number of hosts from Graphite with value retrieved from
``workload_stop_nodes`` fixture.
:result:
JSON structure containing data related to hosts status is similar
to values set by ``workload_stop_nodes`` fixture in given time.
"""
# get graphite target pointing at data containing numbers of hosts
targets = grafana.get_panel_chart_targets(hosts_panel, cluster_identifier)
targets_used = (targets[0][0], targets[1][0], targets[2][0])
targets_expected = ('nodes_count.total', 'nodes_count.up', 'nodes_count.down')
for idx, target in enumerate(targets_used):
pytest.check(
target.endswith(targets_expected[idx]),
"There is used target that ends with `{}`".format(
targets_expected[idx]))
# make sure that all data in graphite are saved
time.sleep(3)
# check value *Total* of hosts
graphite.compare_data_mean(
workload_stop_nodes["result"],
(targets_used[0],),
workload_stop_nodes["start"],
workload_stop_nodes["end"],
divergence=0)
# check value *Up* of hosts
graphite.compare_data_mean(
0.0,
(targets_used[1],),
workload_stop_nodes["start"],
workload_stop_nodes["end"],
divergence=0)
# check value *Down* of hosts
graphite.compare_data_mean(
workload_stop_nodes["result"],
(targets_used[2],),
workload_stop_nodes["start"],
workload_stop_nodes["end"],
divergence=0)
23 changes: 23 additions & 0 deletions usmqe_tests/conftest.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import configparser
import pytest
import datetime
import time
import usmqe.usmssh as usmssh
from usmqe.usmqeconfig import UsmConfig

Expand Down Expand Up @@ -388,3 +389,25 @@ def fill_memory():
SSH[host].run(teardown_cmd)
return request.param
return measure_operation(fill_memory)


@pytest.fixture
def workload_stop_nodes():
"""
Test ran with this fixture have to have use fixture `ansible_playbook`
and markers before this fixture is called:

@pytest.mark.ansible_playbook_setup("test_setup.stop_tendrl_nodes.yml")
@pytest.mark.ansible_playbook_teardown("test_teardown.stop_tendrl_nodes.yml")

Returns:
dict: contains information about `start` and `stop` time of wait
procedure and as `result` is used number of nodes.
"""
# wait for tendrl to notice that nodes are down
time.sleep(240)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's add a log line, which states what you stated in the comment: wait for tendrl to notice that nodes are down. It would make it more clear what's going on when one checks logs while the test is running.


def wait():
time.sleep(120)
return len(CONF.inventory.get_groups_dict()["gluster_servers"])
return measure_operation(wait)