From 5cc39c4b3a2de6d670f357ed3329a4d6587c7fc7 Mon Sep 17 00:00:00 2001 From: asteroide Date: Thu, 6 Jul 2017 15:37:03 +0200 Subject: Update test and visualization scripts Change-Id: I62d50d8d3e839a1d6c8ff948cc84ecc45bb0e92f --- moonv4/moon_interface/tests/apitests/utils/models.py | 8 +++++++- moonv4/moon_interface/tests/apitests/utils/policies.py | 13 +++++++++++-- 2 files changed, 18 insertions(+), 3 deletions(-) (limited to 'moonv4/moon_interface/tests/apitests/utils') diff --git a/moonv4/moon_interface/tests/apitests/utils/models.py b/moonv4/moon_interface/tests/apitests/utils/models.py index 8343f77e..5039d185 100644 --- a/moonv4/moon_interface/tests/apitests/utils/models.py +++ b/moonv4/moon_interface/tests/apitests/utils/models.py @@ -1,7 +1,13 @@ import requests import copy +import configparser -URL = "http://172.18.0.11:38001{}" +config = configparser.ConfigParser() +if not config.read("moon.conf"): + config.read("/etc/moon/moon.conf") + +URL = "http://{}:{}".format(config['interface']['host'], config['interface']['port']) +URL = URL + "{}" HEADERS = {"content-type": "application/json"} model_template = { diff --git a/moonv4/moon_interface/tests/apitests/utils/policies.py b/moonv4/moon_interface/tests/apitests/utils/policies.py index e6df7f71..444f34d7 100644 --- a/moonv4/moon_interface/tests/apitests/utils/policies.py +++ b/moonv4/moon_interface/tests/apitests/utils/policies.py @@ -1,6 +1,12 @@ import requests +import configparser -URL = "http://172.18.0.11:38001{}" +config = configparser.ConfigParser() +if not config.read("moon.conf"): + config.read("/etc/moon/moon.conf") + +URL = "http://{}:{}".format(config['interface']['host'], config['interface']['port']) +URL = URL + "{}" HEADERS = {"content-type": "application/json"} FILE = open("/tmp/test.log", "w") @@ -580,7 +586,10 @@ def add_rule(policy_id, meta_rule_id, rule, instructions={"chain": [{"security_p assert req.status_code == 200 result = req.json() assert "rules" in result - rule_id = list(result["rules"].keys())[0] + try: + rule_id = list(result["rules"].keys())[0] + except Exception as e: + return False assert "policy_id" in result["rules"][rule_id] assert policy_id == result["rules"][rule_id]["policy_id"] assert "meta_rule_id" in result["rules"][rule_id] -- cgit 1.2.3-korg