summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRomanos Skiadas <rski@intracom-telecom.com>2016-11-07 11:45:33 +0200
committerRomanos Skiadas <rski@intracom-telecom.com>2016-11-07 12:08:57 +0200
commit4db8c4108dcedae322ba6a3fde812e63f746d0f9 (patch)
tree7b836c092ae29b10ed59d44bf36d86569d92e1d5
parentb9eb7024b014cba0d299b1cf3b01e179c7d0482e (diff)
Refactor common code across tests
- Move collecting test results in a method in Results class - Create a util function for asserting the environment has enough compute nodes Change-Id: Ib7b9dfab7d2e9f50d5f352d3eadba4d4717ee750 Signed-off-by: Romanos Skiadas <rski@intracom-telecom.com>
-rw-r--r--test/functest/results.py19
-rw-r--r--test/functest/testcase_1.py27
-rw-r--r--test/functest/testcase_2.py26
-rw-r--r--test/functest/testcase_4.py24
-rw-r--r--test/functest/utils.py17
5 files changed, 42 insertions, 71 deletions
diff --git a/test/functest/results.py b/test/functest/results.py
index baa6af7..7c73556 100644
--- a/test/functest/results.py
+++ b/test/functest/results.py
@@ -145,3 +145,22 @@ class Results(object):
% vm_source.name)
self.add_to_summary(2, "FAIL", test_case_name)
break
+
+ def compile_summary(self, SUCCESS_CRITERIA):
+ success_message = "All the subtests have passed."
+ failure_message = "One or more subtests have failed."
+
+ self.add_to_summary(0, "=")
+ logger.info("\n%s" % self.summary)
+ if self.test_result == "PASS":
+ logger.info(success_message)
+ else:
+ logger.info(failure_message)
+
+ status = "PASS"
+ success = 100 - \
+ (100 * int(self.num_tests_failed) / int(self.num_tests))
+ if success < int(SUCCESS_CRITERIA):
+ status = "FAILED"
+
+ return {"status": status, "details": self.details}
diff --git a/test/functest/testcase_1.py b/test/functest/testcase_1.py
index 4ad29b6..ad1e121 100644
--- a/test/functest/testcase_1.py
+++ b/test/functest/testcase_1.py
@@ -11,7 +11,6 @@
import argparse
import os
from random import randint
-import sys
import time
import functest.utils.functest_logger as ft_logger
@@ -128,16 +127,8 @@ def main():
sg_id = os_utils.create_security_group_full(neutron_client,
SECGROUP_NAME, SECGROUP_DESCR)
- # Get hypervisors zones
- compute_nodes = os_utils.get_hypervisors(nova_client)
- num_compute_nodes = len(compute_nodes)
- if num_compute_nodes < 2:
- logger.error("There are %s compute nodes in the deployment. "
- "Minimum number of nodes to complete the test is 2."
- % num_compute_nodes)
- sys.exit(-1)
+ compute_nodes = test_utils.assert_and_get_compute_nodes(nova_client)
- logger.debug("Compute nodes: %s" % compute_nodes)
av_zone_1 = "nova:" + compute_nodes[0]
av_zone_2 = "nova:" + compute_nodes[1]
@@ -292,21 +283,7 @@ def main():
results.get_ping_status(vm_1, vm_1_ip, vm_5, vm_5_ip,
expected="PASS", timeout=30)
- results.add_to_summary(0, "=")
- logger.info("\n%s" % results.summary)
-
- if results.test_result == "PASS":
- logger.info("All the ping tests have passed as expected.")
- else:
- logger.info("One or more ping tests have failed.")
-
- status = "PASS"
- success = 100 - \
- (100 * int(results.num_tests_failed) / int(results.num_tests))
- if success < int(SUCCESS_CRITERIA):
- status = "FAILED"
-
- return {"status": status, "details": results.details}
+ return results.compile_summary(SUCCESS_CRITERIA)
if __name__ == '__main__':
diff --git a/test/functest/testcase_2.py b/test/functest/testcase_2.py
index ed86b02..f6296be 100644
--- a/test/functest/testcase_2.py
+++ b/test/functest/testcase_2.py
@@ -148,16 +148,8 @@ def main():
sg_id = os_utils.create_security_group_full(neutron_client,
SECGROUP_NAME, SECGROUP_DESCR)
- # Get hypervisors zones
- compute_nodes = os_utils.get_hypervisors(nova_client)
- num_compute_nodes = len(compute_nodes)
- if num_compute_nodes < 2:
- logger.error("There are %s compute nodes in the deployment. "
- "Minimum number of nodes to complete the test is 2."
- % num_compute_nodes)
- sys.exit(-1)
+ compute_nodes = test_utils.assert_and_get_compute_nodes(nova_client)
- logger.debug("Compute nodes: %s" % compute_nodes)
av_zone_1 = "nova:" + compute_nodes[0]
av_zone_2 = "nova:" + compute_nodes[1]
@@ -313,21 +305,7 @@ def main():
results.check_ssh_output(
vm_4, vm_4_ip, vm_1, vm_1_ip, expected="not reachable", timeout=30)
- results.add_to_summary(0, "=")
- logger.info("\n%s" % results.summary)
-
- if results.test_result == "PASS":
- logger.info("All the sub tests have passed as expected.")
- else:
- logger.info("One or more sub tests have failed.")
-
- status = "PASS"
- success = 100 - \
- (100 * int(results.num_tests_failed) / int(results.num_tests))
- if success < int(SUCCESS_CRITERIA):
- status = "FAILED"
-
- return {"status": status, "details": results.details}
+ return results.compile_summary(SUCCESS_CRITERIA)
if __name__ == '__main__':
diff --git a/test/functest/testcase_4.py b/test/functest/testcase_4.py
index 13f531f..3811141 100644
--- a/test/functest/testcase_4.py
+++ b/test/functest/testcase_4.py
@@ -11,7 +11,6 @@
import argparse
import os
from random import randint
-import sys
import time
import functest.utils.functest_logger as ft_logger
@@ -121,16 +120,8 @@ def main():
sg_id = os_utils.create_security_group_full(neutron_client,
SECGROUP_NAME, SECGROUP_DESCR)
- # Get hypervisors zones
- compute_nodes = os_utils.get_hypervisors(nova_client)
- num_compute_nodes = len(compute_nodes)
- if num_compute_nodes < 2:
- logger.error("There are %s compute nodes in the deployment. "
- "Minimum number of nodes to complete the test is 2."
- % num_compute_nodes)
- sys.exit(-1)
+ compute_nodes = test_utils.assert_and_get_compute_nodes(nova_client)
- logger.debug("Compute nodes: %s" % compute_nodes)
av_zone_1 = "nova:" + compute_nodes[0]
av_zone_2 = "nova:" + compute_nodes[1]
@@ -288,18 +279,7 @@ def main():
results.add_to_summary(0, "=")
logger.info("\n%s" % results.summary)
- if results.test_result == "PASS":
- logger.info("All the ping tests have passed as expected.")
- else:
- logger.info("One or more ping tests have failed.")
-
- status = "PASS"
- success = 100 - \
- (100 * int(results.num_tests_failed) / int(results.num_tests_failed))
- if success < int(SUCCESS_CRITERIA):
- status = "FAILED"
-
- return {"status": status, "details": results.details}
+ return results.compile_summary(SUCCESS_CRITERIA)
if __name__ == '__main__':
diff --git a/test/functest/utils.py b/test/functest/utils.py
index be08572..d416765 100644
--- a/test/functest/utils.py
+++ b/test/functest/utils.py
@@ -269,3 +269,20 @@ def wait_for_bgp_router_assocs(neutron_client, bgpvpn_id, *args):
for id in args]
# Return True if all associations succeeded
return all(check)
+
+
+def assert_and_get_compute_nodes(nova_client, required_node_number=2):
+ """Get the compute nodes in the deployment
+
+ Exit if the deployment doesn't have enough compute nodes"""
+ compute_nodes = os_utils.get_hypervisors(nova_client)
+
+ num_compute_nodes = len(compute_nodes)
+ if num_compute_nodes < 2:
+ logger.error("There are %s compute nodes in the deployment. "
+ "Minimum number of nodes to complete the test is 2."
+ % num_compute_nodes)
+ sys.exit(-1)
+
+ logger.debug("Compute nodes: %s" % compute_nodes)
+ return compute_nodes