Big change in config and skip mechanism
diff --git a/cvp_checks/global_config.yaml b/cvp_checks/global_config.yaml
index 9edfc0d..5b8e6c2 100644
--- a/cvp_checks/global_config.yaml
+++ b/cvp_checks/global_config.yaml
@@ -1,14 +1,25 @@
---
# MANDATORY: Credentials for Salt master
-#SALT_URL: <salt_url>
-#SALT_USERNAME: <salt_usr>
-#SALT_PASSWORD: <salt_pwd>
+SALT_URL: <salt_url>
+SALT_USERNAME: <salt_usr>
+SALT_PASSWORD: <salt_pwd>
-# List of nodes to skip in tests
-skipped_nodes: []
+# List of nodes (full fqdn) to skip in all tests
+# TEMPORARY: please do not comment this setting.
+skipped_nodes: [""]
+
+# List of groups (short name, e.g. dbs) to skip in group tests
+# TEMPORARY: please do not comment this setting.
+skipped_groups: [""]
+
+# Some tests may skip groups
+#test_mtu: {"skipped_groups": ["dbs"]}
# ntp test setting
-time_deviation: 30
+# this test may skip specific node (use fqdn)
+test_ntp_sync:
+ { #"skipped_nodes": [""],
+ "time_deviation": 30}
# mtu test setting
# mask for interfaces to skip
diff --git a/cvp_checks/tests/test_default_gateway.py b/cvp_checks/tests/test_default_gateway.py
index 57a6d7b..b6c74c2 100644
--- a/cvp_checks/tests/test_default_gateway.py
+++ b/cvp_checks/tests/test_default_gateway.py
@@ -1,15 +1,16 @@
import json
import pytest
-
+import os
from cvp_checks import utils
@pytest.mark.parametrize(
"group",
- utils.get_groups(utils.get_configuration(__file__))
+ utils.get_groups(os.path.basename(__file__))
)
def test_check_default_gateways(local_salt_client, group):
- config = utils.get_configuration(__file__)
+ if "skipped" in group:
+ pytest.skip("skipped in config")
netstat_info = local_salt_client.cmd(
group, 'cmd.run', ['ip r | sed -n 1p'], expr_form='pcre')
diff --git a/cvp_checks/tests/test_mtu.py b/cvp_checks/tests/test_mtu.py
index f3c3511..be17237 100644
--- a/cvp_checks/tests/test_mtu.py
+++ b/cvp_checks/tests/test_mtu.py
@@ -1,14 +1,17 @@
import pytest
import json
from cvp_checks import utils
+import os
@pytest.mark.parametrize(
"group",
- utils.get_groups(utils.get_configuration(__file__))
+ utils.get_groups(os.path.basename(__file__))
)
def test_mtu(local_salt_client, group):
- config = utils.get_configuration(__file__)
+ if "skipped" in group:
+ pytest.skip("skipped in config")
+ config = utils.get_configuration()
skipped_ifaces = config["skipped_ifaces"]
total = {}
network_info = local_salt_client.cmd(
diff --git a/cvp_checks/tests/test_ntp_sync.py b/cvp_checks/tests/test_ntp_sync.py
index 10eb130..b900e12 100644
--- a/cvp_checks/tests/test_ntp_sync.py
+++ b/cvp_checks/tests/test_ntp_sync.py
@@ -1,21 +1,25 @@
from cvp_checks import utils
+import os
def test_ntp_sync(local_salt_client):
- config = utils.get_configuration(__file__)
+ testname = os.path.basename(__file__).split('.')[0]
+ active_nodes = utils.get_active_nodes(os.path.basename(__file__))
+ config = utils.get_configuration()
fail = {}
saltmaster_time = int(local_salt_client.cmd(
'salt:master',
'cmd.run',
['date +%s'],
expr_form='pillar').values()[0])
-
nodes_time = local_salt_client.cmd(
- '*', 'cmd.run', ['date +%s'])
-
+ utils.list_to_target_string(active_nodes, 'or'),
+ 'cmd.run',
+ ['date +%s'],
+ expr_form='compound')
for node, time in nodes_time.iteritems():
- if (int(time) - saltmaster_time) > config["time_deviation"] or \
- (int(time) - saltmaster_time) < -config["time_deviation"]:
+ if (int(time) - saltmaster_time) > config.get(testname)["time_deviation"] or \
+ (int(time) - saltmaster_time) < -config.get(testname)["time_deviation"]:
fail[node] = time
assert not fail, 'SaltMaster time: {}\n' \
diff --git a/cvp_checks/tests/test_packet_checker.py b/cvp_checks/tests/test_packet_checker.py
index 79915ec..2556bcf 100644
--- a/cvp_checks/tests/test_packet_checker.py
+++ b/cvp_checks/tests/test_packet_checker.py
@@ -1,15 +1,16 @@
import pytest
import json
+import os
from cvp_checks import utils
@pytest.mark.parametrize(
"group",
- utils.get_groups(utils.get_configuration(__file__))
+ utils.get_groups(os.path.basename(__file__))
)
def test_check_package_versions(local_salt_client, group):
- config = utils.get_configuration(__file__)
-
+ if "skipped" in group:
+ pytest.skip("skipped in config")
output = local_salt_client.cmd(group, 'lowpkg.list_pkgs', expr_form='pcre')
if len(output.keys()) < 2:
@@ -43,11 +44,11 @@
@pytest.mark.parametrize(
"group",
- utils.get_groups(utils.get_configuration(__file__))
+ utils.get_groups(os.path.basename(__file__))
)
def test_check_module_versions(local_salt_client, group):
- config = utils.get_configuration(__file__)
-
+ if "skipped" in group:
+ pytest.skip("skipped in config")
pre_check = local_salt_client.cmd(
group, 'cmd.run', ['dpkg -l | grep "python-pip "'], expr_form='pcre')
if pre_check.values().count('') > 0:
diff --git a/cvp_checks/tests/test_repo_list.py b/cvp_checks/tests/test_repo_list.py
index 0970fdc..bd3214c 100644
--- a/cvp_checks/tests/test_repo_list.py
+++ b/cvp_checks/tests/test_repo_list.py
@@ -1,12 +1,15 @@
import pytest
+import os
from cvp_checks import utils
@pytest.mark.parametrize(
"group",
- utils.get_groups(utils.get_configuration(__file__))
+ utils.get_groups(os.path.basename(__file__))
)
def test_list_of_repo_on_nodes(local_salt_client, group):
+ if "skipped" in group:
+ pytest.skip("skipped in config")
info_salt = local_salt_client.cmd(
group, 'pillar.data', ['linux:system:repo'], expr_form='pcre')
diff --git a/cvp_checks/tests/test_services.py b/cvp_checks/tests/test_services.py
index 3d90218..7f04578 100644
--- a/cvp_checks/tests/test_services.py
+++ b/cvp_checks/tests/test_services.py
@@ -1,15 +1,16 @@
import pytest
import json
+import os
from cvp_checks import utils
@pytest.mark.parametrize(
"group",
- utils.get_groups(utils.get_configuration(__file__))
+ utils.get_groups(os.path.basename(__file__))
)
def test_check_services(local_salt_client, group):
- config = utils.get_configuration(__file__)
-
+ if "skipped" in group:
+ pytest.skip("skipped in config")
output = local_salt_client.cmd(group, 'service.get_all', expr_form='pcre')
if len(output.keys()) < 2:
diff --git a/cvp_checks/tests/test_single_vip.py b/cvp_checks/tests/test_single_vip.py
index 9e0f16e..60d1894 100644
--- a/cvp_checks/tests/test_single_vip.py
+++ b/cvp_checks/tests/test_single_vip.py
@@ -1,13 +1,16 @@
import pytest
from cvp_checks import utils
+import os
from collections import Counter
@pytest.mark.parametrize(
"group",
- utils.get_groups(utils.get_configuration(__file__))
+ utils.get_groups(os.path.basename(__file__))
)
def test_single_vip(local_salt_client, group):
+ if "skipped" in group:
+ pytest.skip("skipped in config")
local_salt_client.cmd(group, 'saltutil.sync_all', expr_form='pcre')
nodes_list = local_salt_client.cmd(
group, 'grains.item', ['ipv4'], expr_form='pcre')
diff --git a/cvp_checks/utils/__init__.py b/cvp_checks/utils/__init__.py
index e58ed40..85f5a61 100644
--- a/cvp_checks/utils/__init__.py
+++ b/cvp_checks/utils/__init__.py
@@ -2,14 +2,11 @@
import yaml
import requests
import re
-
+import pytest
class salt_remote:
def cmd(self, tgt, fun, param=None,expr_form=None,tgt_type=None):
- config = get_configuration(__file__)
- for salt_cred in ['SALT_USERNAME', 'SALT_PASSWORD', 'SALT_URL']:
- if os.environ.get(salt_cred):
- config[salt_cred] = os.environ[salt_cred]
+ config = get_configuration()
headers = {'Accept':'application/json'}
login_payload = {'username':config['SALT_USERNAME'],'password':config['SALT_PASSWORD'],'eauth':'pam'}
accept_key_payload = {'fun': fun,'tgt':tgt,'client':'local','expr_form':expr_form,'tgt_type':tgt_type}
@@ -26,25 +23,47 @@
return local
-def get_active_nodes(config):
+def list_to_target_string(node_list, separator):
+ result = ''
+ for node in node_list:
+ result += node + ' ' + separator + ' '
+ return result.strip(' ' + separator + ' ')
+
+
+def get_active_nodes(test=None):
+ config = get_configuration()
local_salt_client = init_salt_client()
skipped_nodes = config.get('skipped_nodes') or []
- # TODO add skipped nodes to cmd command instead of filtering
- nodes = local_salt_client.cmd('*', 'test.ping')
- active_nodes = [
- node_name for node_name in nodes
- if nodes[node_name] and node_name not in skipped_nodes
- ]
- return active_nodes
+ if test:
+ testname = test.split('.')[0]
+ if 'skipped_nodes' in config.get(testname).keys():
+ skipped_nodes += config.get(testname)['skipped_nodes'] or []
+
+ if skipped_nodes:
+ print "\nNotice: {0} nodes will be skipped".format(skipped_nodes)
+ nodes = local_salt_client.cmd(
+ '* and not '+list_to_target_string(skipped_nodes, 'and not'),
+ 'test.ping',
+ expr_form='compound')
+ else:
+ nodes = local_salt_client.cmd('*', 'test.ping')
+ return nodes
-def get_groups(config):
+def get_groups(test):
+ config = get_configuration()
+ testname = test.split('.')[0]
# assume that node name is like <name>.domain
# last 1-3 digits of name are index, e.g. 001 in cpu001
# name doesn't contain dots
- active_nodes = get_active_nodes(config)
- skipped_group = config.get('skipped_group') or []
+ active_nodes = get_active_nodes()
+
+ skipped_groups = config.get('skipped_groups') or []
+ if config.get(testname):
+ if 'skipped_groups' in config.get(testname).keys():
+ skipped_groups += config.get(testname)['skipped_groups'] or []
+
groups = []
for node in active_nodes:
@@ -53,44 +72,30 @@
group_name = node.split('.')[0][:-len(index.group(0))]
else:
group_name = node
- if group_name not in skipped_group and group_name not in groups:
- groups.append(group_name)
- test_groups = []
- groups_from_config = config.get('groups')
- # check if config.yaml contains `groups` key
- if groups_from_config is not None:
- invalid_groups = []
- for group in groups_from_config:
- # check if group name from config
- # is substring of one of the groups
- grp = [x for x in groups if group in x]
- if grp:
- test_groups.append(grp[0])
+ if group_name not in groups:
+ if group_name not in skipped_groups:
+ groups.append(group_name)
else:
- invalid_groups.append(group)
- if invalid_groups:
- raise ValueError('Config file contains'
- ' invalid groups name: {}'.format(invalid_groups))
-
- groups = test_groups if test_groups else groups
+ if group_name+" - skipped" not in groups:
+ groups.append(group_name+" - skipped")
return groups
-def get_configuration(path_to_test):
+def get_configuration():
"""function returns configuration for environment
-
and for test if it's specified"""
global_config_file = os.path.join(
os.path.dirname(os.path.abspath(__file__)), "../global_config.yaml")
with open(global_config_file, 'r') as file:
global_config = yaml.load(file)
-
- config_file = os.path.join(
- os.path.dirname(os.path.abspath(path_to_test)), "config.yaml")
-
- if os.path.exists(config_file):
- with open(config_file, 'r') as file:
- global_config.update(yaml.load(file))
+ for param in global_config.keys():
+ if param in os.environ.keys():
+ if ',' in os.environ[param]:
+ global_config[param]=[]
+ for item in os.environ[param].split(','):
+ global_config[param].append(item)
+ else:
+ global_config[param]=os.environ[param]
return global_config