aboutsummaryrefslogtreecommitdiffstats
path: root/functest
diff options
context:
space:
mode:
Diffstat (limited to 'functest')
-rw-r--r--functest/ci/check_deployment.py32
-rw-r--r--functest/ci/testcases.yaml1
-rw-r--r--functest/cli/commands/cli_os.py5
-rw-r--r--functest/opnfv_tests/openstack/rally/rally.py44
-rw-r--r--functest/opnfv_tests/openstack/snaps/snaps_utils.py10
-rw-r--r--functest/tests/unit/ci/test_check_deployment.py17
-rw-r--r--functest/tests/unit/openstack/rally/test_rally.py5
7 files changed, 73 insertions, 41 deletions
diff --git a/functest/ci/check_deployment.py b/functest/ci/check_deployment.py
index e593e17b..db94fd74 100644
--- a/functest/ci/check_deployment.py
+++ b/functest/ci/check_deployment.py
@@ -22,6 +22,8 @@ import pkg_resources
import socket
from urlparse import urlparse
+from functest.opnfv_tests.openstack.snaps import snaps_utils
+
from snaps.openstack.utils import glance_utils
from snaps.openstack.utils import keystone_utils
from snaps.openstack.utils import neutron_utils
@@ -33,16 +35,20 @@ __author__ = "Jose Lausuch <jose.lausuch@ericsson.com>"
LOGGER = logging.getLogger(__name__)
-def verify_connectivity(adress, port):
+def verify_connectivity(endpoint):
""" Returns true if an ip/port is reachable"""
connection = socket.socket()
connection.settimeout(10)
+ ip = urlparse(endpoint).hostname
+ port = urlparse(endpoint).port
+ if not port:
+ port = 443 if urlparse(endpoint).scheme == "https" else 80
try:
- connection.connect((adress, port))
- LOGGER.debug('%s:%s is reachable!', adress, port)
+ connection.connect((ip, port))
+ LOGGER.debug('%s:%s is reachable!', ip, port)
return True
except socket.error:
- LOGGER.error('%s:%s is not reachable.', adress, port)
+ LOGGER.exception('%s:%s is not reachable.', ip, port)
return False
@@ -65,8 +71,7 @@ class CheckDeployment(object):
def check_auth_endpoint(self):
""" Verifies connectivity to the OS_AUTH_URL given in the RC file """
rc_endpoint = self.os_creds.auth_url
- if not (verify_connectivity(urlparse(rc_endpoint).hostname,
- urlparse(rc_endpoint).port)):
+ if not (verify_connectivity(rc_endpoint)):
raise Exception("OS_AUTH_URL {} is not reachable.".
format(rc_endpoint))
LOGGER.info("Connectivity to OS_AUTH_URL %s ...OK", rc_endpoint)
@@ -76,8 +81,7 @@ class CheckDeployment(object):
public_endpoint = keystone_utils.get_endpoint(self.os_creds,
'identity',
interface='public')
- if not (verify_connectivity(urlparse(public_endpoint).hostname,
- urlparse(public_endpoint).port)):
+ if not (verify_connectivity(public_endpoint)):
raise Exception("Public endpoint {} is not reachable.".
format(public_endpoint))
LOGGER.info("Connectivity to the public endpoint %s ...OK",
@@ -88,8 +92,7 @@ class CheckDeployment(object):
endpoint = keystone_utils.get_endpoint(self.os_creds,
service,
interface='public')
- if not (verify_connectivity(urlparse(endpoint).hostname,
- urlparse(endpoint).port)):
+ if not (verify_connectivity(endpoint)):
raise Exception("{} endpoint {} is not reachable.".
format(service, endpoint))
LOGGER.info("Connectivity to endpoint '%s' %s ...OK",
@@ -125,6 +128,14 @@ class CheckDeployment(object):
LOGGER.error("Glance service ...FAILED")
raise error
+ def check_ext_net(self):
+ """ checks if external network exists """
+ ext_net = snaps_utils.get_ext_net_name(self.os_creds)
+ if ext_net:
+ LOGGER.info("External network found: %s" % ext_net)
+ else:
+ raise Exception("ERROR: No external networks in the deployment.")
+
def check_all(self):
"""
Calls all the class functions and returns 0 if all of them succeed.
@@ -147,6 +158,7 @@ class CheckDeployment(object):
self.check_nova()
self.check_neutron()
self.check_glance()
+ self.check_ext_net()
return 0
diff --git a/functest/ci/testcases.yaml b/functest/ci/testcases.yaml
index ea9f4e7b..6b1eaa9c 100644
--- a/functest/ci/testcases.yaml
+++ b/functest/ci/testcases.yaml
@@ -236,7 +236,6 @@ tiers:
-
case_name: bgpvpn
project_name: sdnvpn
- enabled: false
criteria: 100
blocking: false
description: >-
diff --git a/functest/cli/commands/cli_os.py b/functest/cli/commands/cli_os.py
index e97ab080..71cd78c5 100644
--- a/functest/cli/commands/cli_os.py
+++ b/functest/cli/commands/cli_os.py
@@ -9,6 +9,7 @@
import os
+from urlparse import urlparse
import click
@@ -27,8 +28,8 @@ class OpenStack(object):
self.openstack_creds = CONST.__getattribute__('openstack_creds')
self.snapshot_file = CONST.__getattribute__('openstack_snapshot_file')
if self.os_auth_url:
- self.endpoint_ip = self.os_auth_url.rsplit("/")[2].rsplit(":")[0]
- self.endpoint_port = self.os_auth_url.rsplit("/")[2].rsplit(":")[1]
+ self.endpoint_ip = urlparse(self.os_auth_url).hostname
+ self.endpoint_port = urlparse(self.os_auth_url).port
def ping_endpoint(self):
if self.os_auth_url is None:
diff --git a/functest/opnfv_tests/openstack/rally/rally.py b/functest/opnfv_tests/openstack/rally/rally.py
index 0117e69c..0c657688 100644
--- a/functest/opnfv_tests/openstack/rally/rally.py
+++ b/functest/opnfv_tests/openstack/rally/rally.py
@@ -346,27 +346,24 @@ class RallyBase(testcase.TestCase):
LOGGER.info('No tests for scenario "%s"', test_name)
return
- cmd_line = ("rally task start --abort-on-sla-failure "
- "--task {0} "
- "--task-args \"{1}\""
- .format(task_file, self._build_task_args(test_name)))
- LOGGER.debug('running command line: %s', cmd_line)
-
- proc = subprocess.Popen(cmd_line, stdout=subprocess.PIPE,
- stderr=subprocess.STDOUT, shell=True)
+ cmd = (["rally", "task", "start", "--abort-on-sla-failure", "--task",
+ task_file, "--task-args",
+ str(self._build_task_args(test_name))])
+ LOGGER.debug('running command: %s', cmd)
+
+ proc = subprocess.Popen(cmd, stdout=subprocess.PIPE,
+ stderr=subprocess.STDOUT)
output = self._get_output(proc, test_name)
task_id = self.get_task_id(output)
LOGGER.debug('task_id : %s', task_id)
if task_id is None:
LOGGER.error('Failed to retrieve task_id, validating task...')
- cmd_line = ("rally task validate "
- "--task {0} "
- "--task-args \"{1}\""
- .format(task_file, self._build_task_args(test_name)))
- LOGGER.debug('running command line: %s', cmd_line)
- proc = subprocess.Popen(cmd_line, stdout=subprocess.PIPE,
- stderr=subprocess.STDOUT, shell=True)
+ cmd = (["rally", "task", "validate", "--task", task_file,
+ "--task-args", str(self._build_task_args(test_name))])
+ LOGGER.debug('running command: %s', cmd)
+ proc = subprocess.Popen(cmd, stdout=subprocess.PIPE,
+ stderr=subprocess.STDOUT)
output = self.get_cmd_output(proc)
LOGGER.error("Task validation result:" + "\n" + output)
return
@@ -380,17 +377,18 @@ class RallyBase(testcase.TestCase):
# write html report file
report_html_name = 'opnfv-{}.html'.format(test_name)
report_html_dir = os.path.join(self.RESULTS_DIR, report_html_name)
- cmd_line = "rally task report {} --out {}".format(task_id,
- report_html_dir)
+ cmd = (["rally", "task", "report", task_id, "--out", report_html_dir])
- LOGGER.debug('running command line: %s', cmd_line)
- os.popen(cmd_line)
+ LOGGER.debug('running command: %s', cmd)
+ subprocess.Popen(cmd, stdout=subprocess.PIPE,
+ stderr=subprocess.STDOUT)
# get and save rally operation JSON result
- cmd_line = "rally task results %s" % task_id
- LOGGER.debug('running command line: %s', cmd_line)
- cmd = os.popen(cmd_line)
- json_results = cmd.read()
+ cmd = (["rally", "task", "results", task_id])
+ LOGGER.debug('running command: %s', cmd)
+ proc = subprocess.Popen(cmd, stdout=subprocess.PIPE,
+ stderr=subprocess.STDOUT)
+ json_results = self.get_cmd_output(proc)
report_json_name = 'opnfv-{}.json'.format(test_name)
report_json_dir = os.path.join(self.RESULTS_DIR, report_json_name)
with open(report_json_dir, 'w') as r_file:
diff --git a/functest/opnfv_tests/openstack/snaps/snaps_utils.py b/functest/opnfv_tests/openstack/snaps/snaps_utils.py
index c3cd6245..284e88b5 100644
--- a/functest/opnfv_tests/openstack/snaps/snaps_utils.py
+++ b/functest/opnfv_tests/openstack/snaps/snaps_utils.py
@@ -5,17 +5,25 @@
#
# http://www.apache.org/licenses/LICENSE-2.0
+from functest.utils.constants import CONST
+
from snaps.openstack.utils import neutron_utils, nova_utils
def get_ext_net_name(os_creds):
"""
- Returns the first external network name
+ Returns the configured external network name or
+ the first retrieved external network name
:param: os_creds: an instance of snaps OSCreds object
:return:
"""
neutron = neutron_utils.neutron_client(os_creds)
ext_nets = neutron_utils.get_external_networks(neutron)
+ if (hasattr(CONST, 'EXTERNAL_NETWORK')):
+ extnet_config = CONST.__getattribute__('EXTERNAL_NETWORK')
+ for ext_net in ext_nets:
+ if ext_net.name == extnet_config:
+ return extnet_config
return ext_nets[0].name if ext_nets else ""
diff --git a/functest/tests/unit/ci/test_check_deployment.py b/functest/tests/unit/ci/test_check_deployment.py
index 1f44d078..24e3ce53 100644
--- a/functest/tests/unit/ci/test_check_deployment.py
+++ b/functest/tests/unit/ci/test_check_deployment.py
@@ -170,6 +170,23 @@ class CheckDeploymentTesting(unittest.TestCase):
self.assertRaises(Exception)
self.assertTrue(m.called)
+ @mock.patch('functest.ci.check_deployment.LOGGER.info')
+ @mock.patch('functest.opnfv_tests.openstack.snaps.snaps_utils.'
+ 'get_ext_net_name', return_value='ext-net')
+ def test_check_extnet(self, mock_getext, mock_loginfo):
+ self.deployment.check_ext_net()
+ self.assertTrue(mock_getext.called)
+ mock_loginfo.assert_called_once_with("External network found: ext-net")
+
+ @mock.patch('functest.opnfv_tests.openstack.snaps.snaps_utils.'
+ 'get_ext_net_name', return_value='')
+ def test_check_extnet_None(self, mock_getext):
+ with self.assertRaises(Exception) as context:
+ self.deployment.check_ext_net()
+ self.assertTrue(mock_getext.called)
+ msg = 'ERROR: No external networks in the deployment.'
+ self.assertTrue(msg in context)
+
if __name__ == "__main__":
logging.disable(logging.CRITICAL)
diff --git a/functest/tests/unit/openstack/rally/test_rally.py b/functest/tests/unit/openstack/rally/test_rally.py
index 83f0c86a..450eb85b 100644
--- a/functest/tests/unit/openstack/rally/test_rally.py
+++ b/functest/tests/unit/openstack/rally/test_rally.py
@@ -260,13 +260,10 @@ class OSRallyTesting(unittest.TestCase):
return_value=True)
@mock.patch('functest.opnfv_tests.openstack.rally.rally.subprocess.Popen')
@mock.patch('functest.opnfv_tests.openstack.rally.rally.os.makedirs')
- @mock.patch('functest.opnfv_tests.openstack.rally.rally.os.popen')
@mock.patch('functest.opnfv_tests.openstack.rally.rally.LOGGER.info')
@mock.patch('functest.opnfv_tests.openstack.rally.rally.LOGGER.error')
def test_run_task_default(self, mock_logger_error, mock_logger_info,
- mock_popen, *args):
- attrs = {'read.return_value': 'json_result'}
- mock_popen.return_value.configure_mock(**attrs)
+ *args):
self.rally_base._run_task('test_name')
text = 'Test scenario: "test_name" OK.\n'
mock_logger_info.assert_any_call(text)