aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMorgan Richomme <morgan.richomme@orange.com>2017-07-12 15:12:22 +0000
committerGerrit Code Review <gerrit@opnfv.org>2017-07-12 15:12:22 +0000
commit0323218afb7500bac979e46aafc9c33d614c99d5 (patch)
tree48cecb3992b98dabcc30e1a27c97dd8de69a9082
parentf81e3d2cf3cf9b54f940a6e0ae0ea68db0e1f589 (diff)
parent3bb72f47f704f25d957d8f00b82360fe8b6b2f7a (diff)
Merge "Switch to check_deployment instead of check_os.sh"
-rw-r--r--docs/testing/user/configguide/configguide.rst2
-rw-r--r--functest/ci/check_os.sh123
-rw-r--r--functest/ci/prepare_env.py38
-rw-r--r--functest/cli/commands/cli_os.py5
-rw-r--r--functest/tests/unit/ci/test_prepare_env.py24
-rw-r--r--functest/tests/unit/cli/commands/test_cli_os.py10
-rw-r--r--setup.cfg1
7 files changed, 24 insertions, 179 deletions
diff --git a/docs/testing/user/configguide/configguide.rst b/docs/testing/user/configguide/configguide.rst
index 5c89cf0e..03b5c713 100644
--- a/docs/testing/user/configguide/configguide.rst
+++ b/docs/testing/user/configguide/configguide.rst
@@ -361,7 +361,7 @@ follows::
|-- __init__.py
|-- ci
| |-- __init__.py
- | |-- check_os.sh
+ | |-- check_deployment.py
| |-- config_functest.yaml
| |-- config_patch.yaml
| |-- generate_report.py
diff --git a/functest/ci/check_os.sh b/functest/ci/check_os.sh
deleted file mode 100644
index 7b66f3da..00000000
--- a/functest/ci/check_os.sh
+++ /dev/null
@@ -1,123 +0,0 @@
-#!/bin/bash
-#
-# Simple script to check the basic OpenStack clients
-#
-# Author:
-# jose.lausuch@ericsson.com
-#
-
-if [[ ${OS_INSECURE,,} == "true" ]]; then
- options='--insecure'
-else
- options=''
-fi
-
-declare -A service_cmd_array
-service_cmd_array['nova']="openstack $options server list"
-service_cmd_array['neutron']="openstack $options network list"
-service_cmd_array['keystone']="openstack $options endpoint list"
-service_cmd_array['cinder']="openstack $options volume list"
-service_cmd_array['glance']="openstack $options image list"
-
-MANDATORY_SERVICES='nova neutron keystone glance'
-OPTIONAL_SERVICES='cinder'
-
-verify_connectivity() {
- for i in $(seq 0 9); do
- if echo "test" | nc -v -w 10 $1 $2 &>/dev/null; then
- return 0
- fi
- sleep 1
- done
- return 1
-}
-
-verify_SSL_connectivity() {
- openssl s_client -connect $1:$2 &>/dev/null
- return $?
-}
-
-check_service() {
- local service cmd
- service=$1
- cmd=${service_cmd_array[$service]}
- if [ -z "$2" ]; then
- required='false'
- else
- required=$2
- fi
- echo ">>Checking ${service} service..."
- if ! openstack $options service list | grep -i ${service} > /dev/null; then
- if [ "$required" == 'false' ]; then
- echo "WARN: Optional Service ${service} is not enabled!"
- return
- else
- echo "ERROR: Required Service ${service} is not enabled!"
- exit 1
- fi
- fi
- $cmd &>/dev/null
- result=$?
- if [ $result -ne 0 ]; then
- echo "ERROR: Failed execution $cmd. The $service does not seem to be working."
- exit 1
- else
- echo " ...OK"
- fi
-}
-
-if [ -z $OS_AUTH_URL ];then
- echo "ERROR: OS_AUTH_URL environment variable missing... Have you sourced the OpenStack credentials?"
- exit 1
-fi
-
-
-echo "Checking OpenStack endpoints:"
-publicURL=$(openstack $options catalog show identity |awk '/public/ {print $4}')
-publicIP=$(echo $publicURL|sed 's/^.*http.*\:\/\///'|sed 's/.[^:]*$//')
-publicPort=$(echo $publicURL|grep -Po '(?<=:)\d+')
-https_enabled=$(echo $publicURL | grep 'https')
-if [[ -n $https_enabled ]]; then
- echo ">>Verifying SSL connectivity to the public endpoint $publicIP:$publicPort..."
- verify_SSL_connectivity $publicIP $publicPort
-else
- echo ">>Verifying connectivity to the public endpoint $publicIP:$publicPort..."
- verify_connectivity $publicIP $publicPort
-fi
-RETVAL=$?
-if [ $RETVAL -ne 0 ]; then
- echo "ERROR: Cannot talk to the public endpoint $publicIP:$publicPort ."
- echo "OS_AUTH_URL=$OS_AUTH_URL"
- exit 1
-fi
-echo " ...OK"
-
-
-echo "Checking Required OpenStack services:"
-for service in $MANDATORY_SERVICES; do
- check_service $service "true"
-done
-echo "Required OpenStack services are OK."
-
-echo "Checking Optional OpenStack services:"
-for service in $OPTIONAL_SERVICES; do
- check_service $service
-done
-
-echo "Checking External network..."
-networks=($(neutron $options net-list -F id | tail -n +4 | head -n -1 | awk '{print $2}'))
-is_external=False
-for net in "${networks[@]}"
-do
- is_external=$(neutron $options net-show $net|grep "router:external"|awk '{print $4}')
- if [ $is_external == "True" ]; then
- echo "External network found: $net"
- break
- fi
-done
-if [ $is_external == "False" ]; then
- echo "ERROR: There are no external networks in the deployment."
- exit 1
-fi
-
-exit 0
diff --git a/functest/ci/prepare_env.py b/functest/ci/prepare_env.py
index da3e6245..c40e3266 100644
--- a/functest/ci/prepare_env.py
+++ b/functest/ci/prepare_env.py
@@ -19,6 +19,7 @@ import fileinput
import yaml
+from functest.ci import check_deployment
import functest.utils.functest_utils as ft_utils
import functest.utils.openstack_utils as os_utils
from functest.utils.constants import CONST
@@ -177,26 +178,6 @@ def create_directories():
def source_rc_file():
print_separator()
- if CONST.__getattribute__('openstack_creds') is None:
- logger.warning("The environment variable 'creds' must be set and"
- "pointing to the local RC file. Using default: "
- "/home/opnfv/functest/conf/openstack.creds ...")
- os.path.join(
- CONST.__getattribute__('dir_functest_conf'), 'openstack.creds')
-
- if not os.path.isfile(CONST.__getattribute__('openstack_creds')):
- raise Exception(
- "OpenStack credentials file not provided. "
- "The OpenStack credentials must be in {}"
- .format(CONST.__getattribute__('openstack_creds')))
- else:
- logger.info("RC file provided in %s."
- % CONST.__getattribute__('openstack_creds'))
- if os.path.getsize(CONST.__getattribute__('openstack_creds')) == 0:
- raise Exception(
- "The OpenStack RC file {} is empty."
- .format(CONST.__getattribute__('openstack_creds')))
-
logger.info("Sourcing the OpenStack RC file...")
os_utils.source_credentials(CONST.__getattribute__('openstack_creds'))
for key, value in os.environ.iteritems():
@@ -250,18 +231,9 @@ def update_db_url():
def verify_deployment():
print_separator()
- logger.info("Verifying OpenStack services...")
- cmd = "check_os.sh"
-
- logger.debug("Executing command: %s" % cmd)
- p = subprocess.Popen(cmd, stdout=subprocess.PIPE, shell=True)
-
- while p.poll() is None:
- line = p.stdout.readline().rstrip()
- if "ERROR" in line:
- logger.error(line)
- raise Exception("Problem while running '{}'.".format(cmd))
- logger.info(line)
+ logger.info("Verifying OpenStack deployment...")
+ deployment = check_deployment.CheckDeployment()
+ deployment.check_all()
def install_rally():
@@ -364,11 +336,11 @@ def prepare_env(**kwargs):
return -1
elif kwargs['action'] == "start":
logger.info("######### Preparing Functest environment #########\n")
+ verify_deployment()
check_env_variables()
create_directories()
source_rc_file()
update_config_file()
- verify_deployment()
install_rally()
install_tempest()
create_flavor()
diff --git a/functest/cli/commands/cli_os.py b/functest/cli/commands/cli_os.py
index 44181d4f..f4ec1661 100644
--- a/functest/cli/commands/cli_os.py
+++ b/functest/cli/commands/cli_os.py
@@ -12,8 +12,8 @@ import os
import click
+from functest.ci import check_deployment
from functest.utils.constants import CONST
-import functest.utils.functest_utils as ft_utils
import functest.utils.openstack_clean as os_clean
import functest.utils.openstack_snapshot as os_snapshot
@@ -49,7 +49,8 @@ class CliOpenStack(object):
def check(self):
self.ping_endpoint()
- ft_utils.execute_command("check_os.sh", verbose=False)
+ deployment = check_deployment.CheckDeployment()
+ deployment.check_all()
def snapshot_create(self):
self.ping_endpoint()
diff --git a/functest/tests/unit/ci/test_prepare_env.py b/functest/tests/unit/ci/test_prepare_env.py
index 7d4b5fb2..7d5fa564 100644
--- a/functest/tests/unit/ci/test_prepare_env.py
+++ b/functest/tests/unit/ci/test_prepare_env.py
@@ -309,22 +309,18 @@ class PrepareEnvTesting(unittest.TestCase):
prepare_env.update_config_file()
self.assertTrue(mock_db_url.called)
- @mock.patch('functest.ci.prepare_env.logger.info')
- def test_verify_deployment_error(self, mock_logger_error):
- mock_popen = mock.Mock()
- attrs = {'poll.return_value': None,
- 'stdout.readline.return_value': 'ERROR'}
- mock_popen.configure_mock(**attrs)
+ def test_verify_deployment(self):
+ with mock.patch('functest.ci.check_deployment.CheckDeployment') \
+ as mock_check_deployment:
+ prepare_env.verify_deployment()
+ self.assertTrue(mock_check_deployment.called)
- with mock.patch('functest.ci.prepare_env.print_separator') as m, \
- mock.patch('functest.ci.prepare_env.subprocess.Popen',
- return_value=mock_popen), \
- self.assertRaises(Exception) as context:
+ def test_verify_deployment_error(self):
+ with mock.patch('functest.ci.prepare_env.'
+ 'check_deployment.CheckDeployment',
+ return_value=('test_', None)), \
+ self.assertRaises(Exception):
prepare_env.verify_deployment()
- self.assertTrue(m.called)
- msg = "Problem while running 'check_os.sh'."
- mock_logger_error.assert_called_once_with('ERROR')
- self.assertTrue(msg in context)
def _get_rally_creds(self):
return {"type": "ExistingCloud",
diff --git a/functest/tests/unit/cli/commands/test_cli_os.py b/functest/tests/unit/cli/commands/test_cli_os.py
index a3d930de..806bc931 100644
--- a/functest/tests/unit/cli/commands/test_cli_os.py
+++ b/functest/tests/unit/cli/commands/test_cli_os.py
@@ -59,12 +59,12 @@ class CliOpenStackTesting(unittest.TestCase):
self.endpoint_ip)
mock_exit.assert_called_once_with(0)
- @mock.patch('functest.cli.commands.cli_os.ft_utils.execute_command')
- def test_check(self, mock_ftutils_execute):
- with mock.patch.object(self.cli_os, 'ping_endpoint'):
+ def test_check(self):
+ with mock.patch.object(self.cli_os, 'ping_endpoint'), \
+ mock.patch('functest.cli.commands.cli_os.check_deployment.'
+ 'CheckDeployment') as mock_check_deployment:
self.cli_os.check()
- mock_ftutils_execute.assert_called_once_with(
- "check_os.sh", verbose=False)
+ self.assertTrue(mock_check_deployment.called)
@mock.patch('functest.cli.commands.cli_os.os.path.isfile',
return_value=False)
diff --git a/setup.cfg b/setup.cfg
index 27cd29cd..e29259f3 100644
--- a/setup.cfg
+++ b/setup.cfg
@@ -10,7 +10,6 @@ scripts =
docker/add_images.sh
docker/config_install_env.sh
functest/ci/download_images.sh
- functest/ci/check_os.sh
[entry_points]
console_scripts =