aboutsummaryrefslogtreecommitdiffstats
path: root/functest
diff options
context:
space:
mode:
Diffstat (limited to 'functest')
-rwxr-xr-xfunctest/ci/check_os.sh24
-rw-r--r--functest/ci/config_functest.yaml6
-rwxr-xr-xfunctest/ci/prepare_env.py2
-rw-r--r--functest/core/feature.py18
-rw-r--r--functest/tests/unit/ci/test_prepare_env.py8
-rw-r--r--functest/tests/unit/core/test_feature.py23
-rw-r--r--functest/tests/unit/utils/test_openstack_snapshot.py13
-rw-r--r--functest/tests/unit/utils/test_openstack_utils.py16
-rwxr-xr-xfunctest/utils/openstack_clean.py10
-rwxr-xr-xfunctest/utils/openstack_snapshot.py9
-rw-r--r--functest/utils/openstack_utils.py26
11 files changed, 94 insertions, 61 deletions
diff --git a/functest/ci/check_os.sh b/functest/ci/check_os.sh
index ce0bc20c..7b66f3da 100755
--- a/functest/ci/check_os.sh
+++ b/functest/ci/check_os.sh
@@ -6,12 +6,18 @@
# jose.lausuch@ericsson.com
#
+if [[ ${OS_INSECURE,,} == "true" ]]; then
+ options='--insecure'
+else
+ options=''
+fi
+
declare -A service_cmd_array
-service_cmd_array['nova']='openstack server list'
-service_cmd_array['neutron']='openstack network list'
-service_cmd_array['keystone']='openstack endpoint list'
-service_cmd_array['cinder']='openstack volume list'
-service_cmd_array['glance']='openstack image list'
+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'
@@ -41,7 +47,7 @@ check_service() {
required=$2
fi
echo ">>Checking ${service} service..."
- if ! openstack service list | grep -i ${service} > /dev/null; then
+ if ! openstack $options service list | grep -i ${service} > /dev/null; then
if [ "$required" == 'false' ]; then
echo "WARN: Optional Service ${service} is not enabled!"
return
@@ -67,7 +73,7 @@ fi
echo "Checking OpenStack endpoints:"
-publicURL=$(openstack catalog show identity |awk '/public/ {print $4}')
+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')
@@ -99,11 +105,11 @@ for service in $OPTIONAL_SERVICES; do
done
echo "Checking External network..."
-networks=($(neutron net-list -F id | tail -n +4 | head -n -1 | awk '{print $2}'))
+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 net-show $net|grep "router:external"|awk '{print $4}')
+ is_external=$(neutron $options net-show $net|grep "router:external"|awk '{print $4}')
if [ $is_external == "True" ]; then
echo "External network found: $net"
break
diff --git a/functest/ci/config_functest.yaml b/functest/ci/config_functest.yaml
index 60270b6c..623092a5 100644
--- a/functest/ci/config_functest.yaml
+++ b/functest/ci/config_functest.yaml
@@ -62,9 +62,9 @@ general:
snaps:
use_keystone: True
use_floating_ips: True
-# images:
-# cirros:
-# disk_url: http://download.cirros-cloud.net/0.3.5/cirros-0.3.5-x86_64-disk.img
+ images:
+ cirros:
+ disk_file: /home/opnfv/functest/images/cirros-0.3.5-x86_64-disk.img
# ARM
# disk_url: http://download.cirros-cloud.net/daily/20161201/cirros-d161201-aarch64-disk.img
# kernel_url: http://download.cirros-cloud.net/daily/20161201/cirros-d161201-aarch64-kernel
diff --git a/functest/ci/prepare_env.py b/functest/ci/prepare_env.py
index 5326c50b..64fcc925 100755
--- a/functest/ci/prepare_env.py
+++ b/functest/ci/prepare_env.py
@@ -366,7 +366,6 @@ def main(**kwargs):
elif kwargs['action'] == "start":
logger.info("######### Preparing Functest environment #########\n")
check_env_variables()
- get_deployment_handler()
create_directories()
source_rc_file()
update_config_file()
@@ -377,7 +376,6 @@ def main(**kwargs):
with open(CONST.__getattribute__('env_active'), "w") as env_file:
env_file.write("1")
check_environment()
- print_deployment_info()
elif kwargs['action'] == "check":
check_environment()
except Exception as e:
diff --git a/functest/core/feature.py b/functest/core/feature.py
index d53eb7d0..010ff4bc 100644
--- a/functest/core/feature.py
+++ b/functest/core/feature.py
@@ -33,6 +33,24 @@ class Feature(base.TestCase):
super(Feature, self).__init__(**kwargs)
self.result_file = "{}/{}.log".format(
CONST.__getattribute__('dir_results'), self.case_name)
+ try:
+ module = kwargs['run']['module']
+ self.logger = logging.getLogger(module)
+ except KeyError:
+ self.__logger.warning(
+ "Cannot get module name %s. Using %s as fallback",
+ kwargs, self.case_name)
+ self.logger = logging.getLogger(self.case_name)
+ handler = logging.StreamHandler()
+ handler.setLevel(logging.WARN)
+ self.logger.addHandler(handler)
+ handler = logging.FileHandler(self.result_file)
+ handler.setLevel(logging.DEBUG)
+ self.logger.addHandler(handler)
+ formatter = logging.Formatter(
+ '%(asctime)s - %(name)s - %(levelname)s - %(message)s')
+ handler.setFormatter(formatter)
+ self.logger.addHandler(handler)
def execute(self, **kwargs):
"""Execute the Python method.
diff --git a/functest/tests/unit/ci/test_prepare_env.py b/functest/tests/unit/ci/test_prepare_env.py
index f3e15a01..69abd643 100644
--- a/functest/tests/unit/ci/test_prepare_env.py
+++ b/functest/tests/unit/ci/test_prepare_env.py
@@ -424,7 +424,6 @@ class PrepareEnvTesting(unittest.TestCase):
mock_logger_info.assert_any_call("Functest environment"
" is installed.")
- @mock.patch('functest.ci.prepare_env.print_deployment_info')
@mock.patch('functest.ci.prepare_env.check_environment')
@mock.patch('functest.ci.prepare_env.create_flavor')
@mock.patch('functest.ci.prepare_env.install_tempest')
@@ -433,21 +432,19 @@ class PrepareEnvTesting(unittest.TestCase):
@mock.patch('functest.ci.prepare_env.update_config_file')
@mock.patch('functest.ci.prepare_env.source_rc_file')
@mock.patch('functest.ci.prepare_env.create_directories')
- @mock.patch('functest.ci.prepare_env.get_deployment_handler')
@mock.patch('functest.ci.prepare_env.check_env_variables')
@mock.patch('functest.ci.prepare_env.logger.info')
- def test_main_start(self, mock_logger_info, mock_env_var, mock_dep_handler,
+ def test_main_start(self, mock_logger_info, mock_env_var,
mock_create_dir, mock_source_rc, mock_update_config,
mock_verify_depl, mock_install_rally,
mock_install_temp, mock_create_flavor,
- mock_check_env, mock_print_info):
+ mock_check_env):
with mock.patch("__builtin__.open", mock.mock_open()) as m:
args = {'action': 'start'}
self.assertEqual(prepare_env.main(**args), 0)
mock_logger_info.assert_any_call("######### Preparing Functest "
"environment #########\n")
self.assertTrue(mock_env_var.called)
- self.assertTrue(mock_dep_handler.called)
self.assertTrue(mock_create_dir.called)
self.assertTrue(mock_source_rc.called)
self.assertTrue(mock_update_config.called)
@@ -458,7 +455,6 @@ class PrepareEnvTesting(unittest.TestCase):
m.assert_called_once_with(
CONST.__getattribute__('env_active'), "w")
self.assertTrue(mock_check_env.called)
- self.assertTrue(mock_print_info.called)
@mock.patch('functest.ci.prepare_env.check_environment')
def test_main_check(self, mock_check_env):
diff --git a/functest/tests/unit/core/test_feature.py b/functest/tests/unit/core/test_feature.py
index 0160c8e1..988981ef 100644
--- a/functest/tests/unit/core/test_feature.py
+++ b/functest/tests/unit/core/test_feature.py
@@ -38,12 +38,26 @@ class FeatureTestingBase(unittest.TestCase):
self.assertEqual(self.feature.start_time, 1)
self.assertEqual(self.feature.stop_time, 2)
+ def test_logger_module_ko(self):
+ with mock.patch('six.moves.builtins.open'):
+ self.feature = feature.Feature(
+ project_name=self._project_name, case_name=self._case_name)
+ self.assertEqual(self.feature.logger.name, self._case_name)
+
+ def test_logger_module(self):
+ with mock.patch('six.moves.builtins.open'):
+ self.feature = feature.Feature(
+ project_name=self._project_name, case_name=self._case_name,
+ run={'module': 'bar'})
+ self.assertEqual(self.feature.logger.name, 'bar')
+
class FeatureTesting(FeatureTestingBase):
def setUp(self):
- self.feature = feature.Feature(
- project_name=self._project_name, case_name=self._case_name)
+ with mock.patch('six.moves.builtins.open'):
+ self.feature = feature.Feature(
+ project_name=self._project_name, case_name=self._case_name)
def test_run_exc(self):
# pylint: disable=bad-continuation
@@ -60,8 +74,9 @@ class FeatureTesting(FeatureTestingBase):
class BashFeatureTesting(FeatureTestingBase):
def setUp(self):
- self.feature = feature.BashFeature(
- project_name=self._project_name, case_name=self._case_name)
+ with mock.patch('six.moves.builtins.open'):
+ self.feature = feature.BashFeature(
+ project_name=self._project_name, case_name=self._case_name)
@mock.patch("functest.utils.functest_utils.execute_command")
def test_run_no_cmd(self, mock_method=None):
diff --git a/functest/tests/unit/utils/test_openstack_snapshot.py b/functest/tests/unit/utils/test_openstack_snapshot.py
index 8b3635ea..33e74609 100644
--- a/functest/tests/unit/utils/test_openstack_snapshot.py
+++ b/functest/tests/unit/utils/test_openstack_snapshot.py
@@ -12,7 +12,7 @@ import unittest
from functest.utils import openstack_snapshot
-class OSTackerTesting(unittest.TestCase):
+class OSSnapshotTesting(unittest.TestCase):
def _get_instance(self, key):
mock_obj = mock.Mock()
@@ -26,6 +26,8 @@ class OSTackerTesting(unittest.TestCase):
self.test_list = [self._get_instance(1), self._get_instance(2)]
self.update_list = {'id1': 'name1', 'id2': 'name2'}
self.update_floatingips = {'id1': 'ip1', 'id2': 'ip2'}
+ self.floatingips_list = [{'id': 'id1', 'floating_ip_address': 'ip1'},
+ {'id': 'id2', 'floating_ip_address': 'ip2'}]
self.test_dict_list = [{'id': 'id1', 'name': 'name1', 'ip': 'ip1'},
{'id': 'id2', 'name': 'name2', 'ip': 'ip2'}]
@@ -138,8 +140,9 @@ class OSTackerTesting(unittest.TestCase):
@mock.patch('functest.utils.openstack_snapshot.logger.debug')
def test_get_floatingips(self, mock_logger_debug):
with mock.patch('functest.utils.openstack_snapshot.os_utils'
- '.get_floating_ips', return_value=self.test_list):
- resp = openstack_snapshot.get_floatinips(self.client)
+ '.get_floating_ips',
+ return_value=self.floatingips_list):
+ resp = openstack_snapshot.get_floatingips(self.client)
mock_logger_debug.assert_called_once_with("Getting Floating "
"IPs...")
self.assertDictEqual(resp, {'floatingips':
@@ -149,7 +152,7 @@ class OSTackerTesting(unittest.TestCase):
def test_get_floatingips_missing_floatingips(self, mock_logger_debug):
with mock.patch('functest.utils.openstack_snapshot.os_utils'
'.get_floating_ips', return_value=[]):
- resp = openstack_snapshot.get_floatinips(self.client)
+ resp = openstack_snapshot.get_floatingips(self.client)
mock_logger_debug.assert_called_once_with("Getting Floating "
"IPs...")
self.assertDictEqual(resp, {'floatingips': {}})
@@ -213,7 +216,7 @@ class OSTackerTesting(unittest.TestCase):
return_value=self.update_list), \
mock.patch('functest.utils.openstack_snapshot.get_security_groups',
return_value=self.update_list), \
- mock.patch('functest.utils.openstack_snapshot.get_floatinips',
+ mock.patch('functest.utils.openstack_snapshot.get_floatingips',
return_value=self.update_floatingips), \
mock.patch('functest.utils.openstack_snapshot.get_users',
return_value=self.update_list), \
diff --git a/functest/tests/unit/utils/test_openstack_utils.py b/functest/tests/unit/utils/test_openstack_utils.py
index 8dab87bb..fa0e0f5e 100644
--- a/functest/tests/unit/utils/test_openstack_utils.py
+++ b/functest/tests/unit/utils/test_openstack_utils.py
@@ -75,9 +75,8 @@ class OSUtilsTesting(unittest.TestCase):
self.availability_zone = mock_obj
mock_obj = mock.Mock()
- attrs = {'id': 'floating_id',
- 'zoneName': 'test_floating_ip',
- 'status': 'ok'}
+ attrs = {'floating_network_id': 'floating_id',
+ 'floating_ip_address': 'test_floating_ip'}
mock_obj.configure_mock(**attrs)
self.floating_ip = mock_obj
@@ -113,8 +112,6 @@ class OSUtilsTesting(unittest.TestCase):
'aggregates.delete.return_value': mock.Mock(),
'availability_zones.list.return_value':
[self.availability_zone],
- 'floating_ips.list.return_value': [self.floating_ip],
- 'floating_ips.delete.return_value': mock.Mock(),
'hypervisors.list.return_value': [self.hypervisor],
'create.return_value': mock.Mock(),
'add_security_group.return_value': mock.Mock(),
@@ -271,7 +268,10 @@ class OSUtilsTesting(unittest.TestCase):
'create_security_group.return_value': {'security_group':
self.sec_group},
'update_quota.return_value': mock.Mock(),
- 'delete_security_group.return_value': mock.Mock()
+ 'delete_security_group.return_value': mock.Mock(),
+ 'list_floatingips.return_value': {'floatingips':
+ [self.floating_ip]},
+ 'delete_floatingip.return_value': mock.Mock(),
}
self.neutron_client.configure_mock(**attrs)
@@ -721,7 +721,7 @@ class OSUtilsTesting(unittest.TestCase):
def test_get_floating_ips_default(self):
self.assertEqual(openstack_utils.
- get_floating_ips(self.nova_client),
+ get_floating_ips(self.neutron_client),
[self.floating_ip])
@mock.patch('functest.utils.openstack_utils.logger.error')
@@ -867,7 +867,7 @@ class OSUtilsTesting(unittest.TestCase):
def test_delete_floating_ip_default(self):
self.assertTrue(openstack_utils.
- delete_floating_ip(self.nova_client,
+ delete_floating_ip(self.neutron_client,
'floating_ip_id'))
@mock.patch('functest.utils.openstack_utils.logger.error')
diff --git a/functest/utils/openstack_clean.py b/functest/utils/openstack_clean.py
index 29ebb336..b5167893 100755
--- a/functest/utils/openstack_clean.py
+++ b/functest/utils/openstack_clean.py
@@ -138,9 +138,9 @@ def remove_volumes(cinder_client, default_volumes):
"NOT be deleted.")
-def remove_floatingips(nova_client, default_floatingips):
+def remove_floatingips(neutron_client, default_floatingips):
logger.debug("Removing floating IPs...")
- floatingips = os_utils.get_floating_ips(nova_client)
+ floatingips = os_utils.get_floating_ips(neutron_client)
if floatingips is None or len(floatingips) == 0:
logger.debug("No floating IPs found.")
return
@@ -154,7 +154,7 @@ def remove_floatingips(nova_client, default_floatingips):
if (fip_id not in default_floatingips and
fip_ip not in default_floatingips.values()):
logger.debug("Removing floating IP %s ..." % fip_id)
- if os_utils.delete_floating_ip(nova_client, fip_id):
+ if os_utils.delete_floating_ip(neutron_client, fip_id):
logger.debug(" > Done!")
deleted += 1
else:
@@ -166,7 +166,7 @@ def remove_floatingips(nova_client, default_floatingips):
timeout = 50
while timeout > 0:
- floatingips = os_utils.get_floating_ips(nova_client)
+ floatingips = os_utils.get_floating_ips(neutron_client)
if floatingips is None or len(floatingips) == (init_len - deleted):
break
else:
@@ -419,7 +419,7 @@ def main():
separator()
remove_volumes(cinder_client, default_volumes)
separator()
- remove_floatingips(nova_client, default_floatingips)
+ remove_floatingips(neutron_client, default_floatingips)
separator()
remove_networks(neutron_client, default_networks, default_routers)
separator()
diff --git a/functest/utils/openstack_snapshot.py b/functest/utils/openstack_snapshot.py
index c6c1615a..f4ef751c 100755
--- a/functest/utils/openstack_snapshot.py
+++ b/functest/utils/openstack_snapshot.py
@@ -98,13 +98,14 @@ def get_security_groups(neutron_client):
return {'secgroups': dic_secgroups}
-def get_floatinips(nova_client):
+def get_floatingips(neutron_client):
logger.debug("Getting Floating IPs...")
dic_floatingips = {}
- floatingips = os_utils.get_floating_ips(nova_client)
+ floatingips = os_utils.get_floating_ips(neutron_client)
if not (floatingips is None or len(floatingips) == 0):
for floatingip in floatingips:
- dic_floatingips.update({floatingip.id: floatingip.ip})
+ dic_floatingips.update({floatingip['id']:
+ floatingip['floating_ip_address']})
return {'floatingips': dic_floatingips}
@@ -150,7 +151,7 @@ def main():
snapshot.update(get_networks(neutron_client))
snapshot.update(get_routers(neutron_client))
snapshot.update(get_security_groups(neutron_client))
- snapshot.update(get_floatinips(nova_client))
+ snapshot.update(get_floatingips(neutron_client))
snapshot.update(get_users(keystone_client))
snapshot.update(get_tenants(keystone_client))
diff --git a/functest/utils/openstack_utils.py b/functest/utils/openstack_utils.py
index 3e27d672..a50bf179 100644
--- a/functest/utils/openstack_utils.py
+++ b/functest/utils/openstack_utils.py
@@ -181,14 +181,10 @@ def get_endpoint(service_type, endpoint_type='publicURL'):
def get_session(other_creds={}):
auth = get_session_auth(other_creds)
- cacert = os.getenv('OS_CACERT')
- if cacert is not None:
- if not os.path.isfile(cacert):
- raise Exception("The 'OS_CACERT' environment"
- "variable is set to %s but the file"
- "does not exist.", cacert)
-
- return session.Session(auth=auth, verify=cacert)
+ https_cacert = os.getenv('OS_CACERT', '')
+ https_insecure = os.getenv('OS_INSECURE', '').lower() == 'true'
+ return session.Session(auth=auth,
+ verify=(https_cacert or not https_insecure))
# *********************************************
@@ -426,12 +422,12 @@ def get_or_create_flavor(flavor_name, ram, disk, vcpus, public=True):
return flavor_exists, flavor_id
-def get_floating_ips(nova_client):
+def get_floating_ips(neutron_client):
try:
- floating_ips = nova_client.floating_ips.list()
- return floating_ips
+ floating_ips = neutron_client.list_floatingips()
+ return floating_ips['floatingips']
except Exception as e:
- logger.error("Error [get_floating_ips(nova_client)]: %s" % e)
+ logger.error("Error [get_floating_ips(neutron_client)]: %s" % e)
return None
@@ -594,12 +590,12 @@ def delete_instance(nova_client, instance_id):
return False
-def delete_floating_ip(nova_client, floatingip_id):
+def delete_floating_ip(neutron_client, floatingip_id):
try:
- nova_client.floating_ips.delete(floatingip_id)
+ neutron_client.delete_floatingip(floatingip_id)
return True
except Exception as e:
- logger.error("Error [delete_floating_ip(nova_client, '%s')]: %s"
+ logger.error("Error [delete_floating_ip(neutron_client, '%s')]: %s"
% (floatingip_id, e))
return False