Introduce parametrized fixture for collecting groups
diff --git a/cvp_checks/fixtures/base.py b/cvp_checks/fixtures/base.py
index f1893fa..85313d0 100644
--- a/cvp_checks/fixtures/base.py
+++ b/cvp_checks/fixtures/base.py
@@ -2,6 +2,12 @@
import cvp_checks.utils as utils
-@pytest.fixture
+@pytest.fixture(scope='session')
def local_salt_client():
return utils.init_salt_client()
+
+nodes = utils.calculate_groups()
+
+@pytest.fixture(scope='session', params=nodes.values(), ids=nodes.keys())
+def nodes_in_group(request):
+ return request.param
diff --git a/cvp_checks/tests/test_default_gateway.py b/cvp_checks/tests/test_default_gateway.py
index cac5328..69fd116 100644
--- a/cvp_checks/tests/test_default_gateway.py
+++ b/cvp_checks/tests/test_default_gateway.py
@@ -4,13 +4,9 @@
from cvp_checks import utils
-@pytest.mark.parametrize(
- "group",
- utils.node_groups.keys()
-)
-def test_check_default_gateways(local_salt_client, group):
+def test_check_default_gateways(local_salt_client, nodes_in_group):
netstat_info = local_salt_client.cmd(
- "L@"+','.join(utils.node_groups[group]), 'cmd.run', ['ip r | sed -n 1p'], expr_form='compound')
+ "L@"+','.join(nodes_in_group), 'cmd.run', ['ip r | sed -n 1p'], expr_form='compound')
gateways = {}
nodes = netstat_info.keys()
@@ -22,7 +18,6 @@
gateways[netstat_info[node]].append(node)
assert len(gateways.keys()) == 1, \
- "There were found few gateways within group {group}: {gw}".format(
- group=group,
+ "There were found few gateways: {gw}".format(
gw=json.dumps(gateways, indent=4)
)
diff --git a/cvp_checks/tests/test_mtu.py b/cvp_checks/tests/test_mtu.py
index 53d9dba..735091f 100644
--- a/cvp_checks/tests/test_mtu.py
+++ b/cvp_checks/tests/test_mtu.py
@@ -4,18 +4,14 @@
import os
-@pytest.mark.parametrize(
- "group",
- utils.node_groups.keys()
-)
-def test_mtu(local_salt_client, group):
+def test_mtu(local_salt_client, nodes_in_group):
testname = os.path.basename(__file__).split('.')[0]
config = utils.get_configuration()
skipped_ifaces = config.get(testname)["skipped_ifaces"] or \
["bonding_masters", "lo", "veth", "tap", "cali"]
total = {}
network_info = local_salt_client.cmd(
- "L@"+','.join(utils.node_groups[group]), 'cmd.run', ['ls /sys/class/net/'], expr_form='compound')
+ "L@"+','.join(nodes_in_group), 'cmd.run', ['ls /sys/class/net/'], expr_form='compound')
kvm_nodes = local_salt_client.cmd(
'salt:control', 'test.ping', expr_form='pillar').keys()
@@ -66,5 +62,5 @@
row.insert(0, interf)
mtu_data.append(row)
assert len(mtu_data) == 0, \
- "Several problems found for {0} group: {1}".format(
- group, json.dumps(mtu_data, indent=4))
+ "Several problems found: {1}".format(
+ json.dumps(mtu_data, indent=4))
diff --git a/cvp_checks/tests/test_packet_checker.py b/cvp_checks/tests/test_packet_checker.py
index d85e87e..724cc00 100644
--- a/cvp_checks/tests/test_packet_checker.py
+++ b/cvp_checks/tests/test_packet_checker.py
@@ -4,12 +4,8 @@
from cvp_checks import utils
-@pytest.mark.parametrize(
- "group",
- utils.node_groups.keys()
-)
-def test_check_package_versions(local_salt_client, group):
- output = local_salt_client.cmd("L@"+','.join(utils.node_groups[group]), 'lowpkg.list_pkgs', expr_form='compound')
+def test_check_package_versions(local_salt_client, nodes_in_group):
+ output = local_salt_client.cmd("L@"+','.join(nodes_in_group), 'lowpkg.list_pkgs', expr_form='compound')
if len(output.keys()) < 2:
pytest.skip("Nothing to compare - only 1 node")
@@ -36,22 +32,18 @@
row.insert(0, deb)
pkts_data.append(row)
assert len(pkts_data) <= 1, \
- "Several problems found for {0} group: {1}".format(
- group, json.dumps(pkts_data, indent=4))
+ "Several problems found: {1}".format(
+ json.dumps(pkts_data, indent=4))
-@pytest.mark.parametrize(
- "group",
- utils.node_groups.keys()
-)
-def test_check_module_versions(local_salt_client, group):
+def test_check_module_versions(local_salt_client, nodes_in_group):
pre_check = local_salt_client.cmd(
- "L@"+','.join(utils.node_groups[group]), 'cmd.run', ['dpkg -l | grep "python-pip "'], expr_form='compound')
+ "L@"+','.join(nodes_in_group), 'cmd.run', ['dpkg -l | grep "python-pip "'], expr_form='compound')
if pre_check.values().count('') > 0:
pytest.skip("pip is not installed on one or more nodes")
if len(pre_check.keys()) < 2:
pytest.skip("Nothing to compare - only 1 node")
- output = local_salt_client.cmd("L@"+','.join(utils.node_groups[group]), 'pip.freeze', expr_form='compound')
+ output = local_salt_client.cmd("L@"+','.join(nodes_in_group), 'pip.freeze', expr_form='compound')
nodes = []
pkts_data = []
@@ -76,5 +68,5 @@
row.insert(0, deb)
pkts_data.append(row)
assert len(pkts_data) <= 1, \
- "Several problems found for {0} group: {1}".format(
- group, json.dumps(pkts_data, indent=4))
+ "Several problems found: {1}".format(
+ json.dumps(pkts_data, indent=4))
diff --git a/cvp_checks/tests/test_repo_list.py b/cvp_checks/tests/test_repo_list.py
index cef0f04..3e440a5 100644
--- a/cvp_checks/tests/test_repo_list.py
+++ b/cvp_checks/tests/test_repo_list.py
@@ -2,13 +2,9 @@
from cvp_checks import utils
-@pytest.mark.parametrize(
- "group",
- utils.node_groups.keys()
-)
-def test_list_of_repo_on_nodes(local_salt_client, group):
+def test_list_of_repo_on_nodes(local_salt_client, nodes_in_group):
info_salt = local_salt_client.cmd('L@' + ','.join(
- utils.node_groups[group]),
+ nodes_in_group),
'pillar.data', ['linux:system:repo'],
expr_form='compound')
@@ -22,11 +18,12 @@
repos.pop(repo)
raw_actual_info = local_salt_client.cmd(
- group,
+ 'L@' + ','.join(
+ nodes_in_group),
'cmd.run',
['cat /etc/apt/sources.list.d/*;'
'cat /etc/apt/sources.list|grep deb|grep -v "#"'],
- expr_form='pcre')
+ expr_form='compound')
actual_repo_list = [item.replace('/ ', ' ').replace('[arch=amd64] ', '')
for item in raw_actual_info.values()[0].split('\n')]
if info_salt.values()[0]['linux:system:repo'] == '':
@@ -56,7 +53,7 @@
rows.append("{}: No repo".format('pillars'))
diff[repo] = rows
assert fail_counter == 0, \
- "Several problems found for {0} group: {1}".format(
- group, json.dumps(diff, indent=4))
+ "Several problems found: {1}".format(
+ json.dumps(diff, indent=4))
if fail_counter == 0 and len(diff) > 0:
print "\nWarning: nodes contain more repos than reclass"
diff --git a/cvp_checks/tests/test_services.py b/cvp_checks/tests/test_services.py
index be0bc16..284956d 100644
--- a/cvp_checks/tests/test_services.py
+++ b/cvp_checks/tests/test_services.py
@@ -4,12 +4,8 @@
from cvp_checks import utils
-@pytest.mark.parametrize(
- "group",
- utils.node_groups.keys()
-)
-def test_check_services(local_salt_client, group):
- output = local_salt_client.cmd("L@"+','.join(utils.node_groups[group]), 'service.get_all', expr_form='compound')
+def test_check_services(local_salt_client, nodes_in_group):
+ output = local_salt_client.cmd("L@"+','.join(nodes_in_group), 'service.get_all', expr_form='compound')
if len(output.keys()) < 2:
pytest.skip("Nothing to compare - only 1 node")
@@ -36,5 +32,5 @@
row.insert(0, srv)
pkts_data.append(row)
assert len(pkts_data) <= 1, \
- "Several problems found for {0} group: {1}".format(
- group, json.dumps(pkts_data, indent=4))
+ "Several problems found: {1}".format(
+ json.dumps(pkts_data, indent=4))
diff --git a/cvp_checks/tests/test_single_vip.py b/cvp_checks/tests/test_single_vip.py
index d829a1a..fe6cb5f 100644
--- a/cvp_checks/tests/test_single_vip.py
+++ b/cvp_checks/tests/test_single_vip.py
@@ -4,14 +4,10 @@
from collections import Counter
-@pytest.mark.parametrize(
- "group",
- utils.node_groups.keys()
-)
-def test_single_vip(local_salt_client, group):
- local_salt_client.cmd("L@"+','.join(utils.node_groups[group]), 'saltutil.sync_all', expr_form='compound')
+def test_single_vip(local_salt_client, nodes_in_group):
+ local_salt_client.cmd("L@"+','.join(nodes_in_group), 'saltutil.sync_all', expr_form='compound')
nodes_list = local_salt_client.cmd(
- group, 'grains.item', ['ipv4'], expr_form='pcre')
+ "L@"+','.join(nodes_in_group), 'grains.item', ['ipv4'], expr_form='compound')
ipv4_list = []
@@ -25,4 +21,4 @@
continue
elif cnt[ip] > 1:
assert "VIP IP duplicate found " \
- "in group {}\n{}".format(group, ipv4_list)
+ "\n{}".format(ipv4_list)
diff --git a/cvp_checks/utils/__init__.py b/cvp_checks/utils/__init__.py
index 83b867d..7b1a2ab 100644
--- a/cvp_checks/utils/__init__.py
+++ b/cvp_checks/utils/__init__.py
@@ -28,9 +28,6 @@
raise EnvironmentError("401 Not authorized.")
-node_groups = {}
-
-
def init_salt_client():
local = salt_remote()
return local
@@ -104,6 +101,7 @@
'test.ping',
expr_form=expr_form)
node_groups[node_name]=[x for x in nodes if x not in config['skipped_nodes']]
+ return node_groups
def get_configuration():
@@ -123,6 +121,3 @@
global_config[param] = os.environ[param]
return global_config
-
-
-calculate_groups()