aboutsummaryrefslogtreecommitdiffstats
path: root/functest
diff options
context:
space:
mode:
Diffstat (limited to 'functest')
-rw-r--r--functest/opnfv_tests/openstack/snaps/api_check.py6
-rw-r--r--functest/opnfv_tests/openstack/snaps/connection_check.py6
-rw-r--r--functest/opnfv_tests/openstack/snaps/health_check.py6
-rw-r--r--functest/opnfv_tests/openstack/snaps/smoke.py6
-rw-r--r--functest/opnfv_tests/openstack/snaps/snaps_suite_builder.py4
-rw-r--r--functest/opnfv_tests/openstack/snaps/snaps_test_runner.py7
-rw-r--r--functest/opnfv_tests/openstack/snaps/snaps_utils.py6
-rw-r--r--functest/opnfv_tests/openstack/vping/vping_base.py64
-rw-r--r--functest/opnfv_tests/openstack/vping/vping_ssh.py8
-rw-r--r--functest/opnfv_tests/openstack/vping/vping_userdata.py4
-rw-r--r--functest/tests/unit/openstack/snaps/test_snaps.py301
-rw-r--r--functest/tests/unit/openstack/vping/__init__.py0
-rw-r--r--functest/tests/unit/openstack/vping/test_vping.py29
13 files changed, 263 insertions, 184 deletions
diff --git a/functest/opnfv_tests/openstack/snaps/api_check.py b/functest/opnfv_tests/openstack/snaps/api_check.py
index e708b4de..e8b9c322 100644
--- a/functest/opnfv_tests/openstack/snaps/api_check.py
+++ b/functest/opnfv_tests/openstack/snaps/api_check.py
@@ -1,3 +1,5 @@
+#!/usr/bin/env python
+
# Copyright (c) 2017 Cable Television Laboratories, Inc. and others.
#
# This program and the accompanying materials
@@ -6,6 +8,8 @@
#
# http://www.apache.org/licenses/LICENSE-2.0
+# pylint: disable=missing-docstring
+
import unittest
from functest.opnfv_tests.openstack.snaps import snaps_suite_builder
@@ -38,4 +42,4 @@ class ApiCheck(SnapsTestRunner):
ext_net_name=self.ext_net_name,
use_keystone=self.use_keystone,
image_metadata=self.image_metadata)
- return super(self.__class__, self).run()
+ return super(ApiCheck, self).run()
diff --git a/functest/opnfv_tests/openstack/snaps/connection_check.py b/functest/opnfv_tests/openstack/snaps/connection_check.py
index 1fc49349..f8bf8852 100644
--- a/functest/opnfv_tests/openstack/snaps/connection_check.py
+++ b/functest/opnfv_tests/openstack/snaps/connection_check.py
@@ -1,3 +1,5 @@
+#!/usr/bin/env python
+
# Copyright (c) 2017 Cable Television Laboratories, Inc. and others.
#
# This program and the accompanying materials
@@ -6,6 +8,8 @@
#
# http://www.apache.org/licenses/LICENSE-2.0
+# pylint: disable=missing-docstring
+
import unittest
from functest.opnfv_tests.openstack.snaps import snaps_suite_builder
@@ -37,4 +41,4 @@ class ConnectionCheck(SnapsTestRunner):
os_creds=self.os_creds,
ext_net_name=self.ext_net_name,
use_keystone=self.use_keystone)
- return super(self.__class__, self).run()
+ return super(ConnectionCheck, self).run()
diff --git a/functest/opnfv_tests/openstack/snaps/health_check.py b/functest/opnfv_tests/openstack/snaps/health_check.py
index 837c2eae..db882c38 100644
--- a/functest/opnfv_tests/openstack/snaps/health_check.py
+++ b/functest/opnfv_tests/openstack/snaps/health_check.py
@@ -1,3 +1,5 @@
+#!/usr/bin/env python
+
# Copyright (c) 2017 Cable Television Laboratories, Inc. and others.
#
# This program and the accompanying materials
@@ -6,6 +8,8 @@
#
# http://www.apache.org/licenses/LICENSE-2.0
+# pylint: disable=missing-docstring
+
import unittest
from functest.opnfv_tests.openstack.snaps.snaps_test_runner import (
@@ -42,4 +46,4 @@ class HealthCheck(SnapsTestRunner):
flavor_metadata=self.flavor_metadata,
image_metadata=self.image_metadata,
netconf_override=self.netconf_override))
- return super(self.__class__, self).run()
+ return super(HealthCheck, self).run()
diff --git a/functest/opnfv_tests/openstack/snaps/smoke.py b/functest/opnfv_tests/openstack/snaps/smoke.py
index ded149d0..ef6e5dc9 100644
--- a/functest/opnfv_tests/openstack/snaps/smoke.py
+++ b/functest/opnfv_tests/openstack/snaps/smoke.py
@@ -1,3 +1,5 @@
+#!/usr/bin/env python
+
# Copyright (c) 2017 Cable Television Laboratories, Inc. and others.
#
# This program and the accompanying materials
@@ -6,6 +8,8 @@
#
# http://www.apache.org/licenses/LICENSE-2.0
+# pylint: disable=missing-docstring
+
import unittest
from functest.opnfv_tests.openstack.snaps import snaps_suite_builder
@@ -41,4 +45,4 @@ class SnapsSmoke(SnapsTestRunner):
image_metadata=self.image_metadata,
use_floating_ips=self.use_fip,
netconf_override=self.netconf_override)
- return super(self.__class__, self).run()
+ return super(SnapsSmoke, self).run()
diff --git a/functest/opnfv_tests/openstack/snaps/snaps_suite_builder.py b/functest/opnfv_tests/openstack/snaps/snaps_suite_builder.py
index 3e7c0a39..c3d8c2d8 100644
--- a/functest/opnfv_tests/openstack/snaps/snaps_suite_builder.py
+++ b/functest/opnfv_tests/openstack/snaps/snaps_suite_builder.py
@@ -8,6 +8,8 @@
#
# http://www.apache.org/licenses/LICENSE-2.0
+# pylint: disable=missing-docstring
+
import logging
from snaps.openstack.tests.create_flavor_tests import (
@@ -119,6 +121,7 @@ def add_openstack_client_tests(suite, os_creds, ext_net_name,
def add_openstack_api_tests(suite, os_creds, ext_net_name, use_keystone=True,
image_metadata=None, log_level=logging.INFO):
+ # pylint: disable=too-many-arguments
"""
Adds tests written to exercise all existing OpenStack APIs
:param suite: the unittest.TestSuite object to which to add the tests
@@ -232,6 +235,7 @@ def add_openstack_integration_tests(suite, os_creds, ext_net_name,
image_metadata=None, use_floating_ips=True,
netconf_override=None,
log_level=logging.INFO):
+ # pylint: disable=too-many-arguments
"""
Adds tests written to exercise all long-running OpenStack integration tests
meaning they will be creating VM instances and potentially performing some
diff --git a/functest/opnfv_tests/openstack/snaps/snaps_test_runner.py b/functest/opnfv_tests/openstack/snaps/snaps_test_runner.py
index 6dc8288b..94c8af85 100644
--- a/functest/opnfv_tests/openstack/snaps/snaps_test_runner.py
+++ b/functest/opnfv_tests/openstack/snaps/snaps_test_runner.py
@@ -1,3 +1,5 @@
+#!/usr/bin/env python
+
# Copyright (c) 2017 Cable Television Laboratories, Inc. and others.
#
# This program and the accompanying materials
@@ -6,6 +8,8 @@
#
# http://www.apache.org/licenses/LICENSE-2.0
+# pylint: disable=missing-docstring
+
import logging
from functest.core import unit
@@ -17,13 +21,14 @@ from snaps.openstack.tests import openstack_tests
class SnapsTestRunner(unit.Suite):
+ # pylint: disable=too-many-instance-attributes
"""
This test executes the SNAPS Python Tests
"""
+
def __init__(self, **kwargs):
super(SnapsTestRunner, self).__init__(**kwargs)
self.logger = logging.getLogger(__name__)
-
if 'os_creds' in kwargs:
self.os_creds = kwargs['os_creds']
else:
diff --git a/functest/opnfv_tests/openstack/snaps/snaps_utils.py b/functest/opnfv_tests/openstack/snaps/snaps_utils.py
index 284e88b5..1153b63d 100644
--- a/functest/opnfv_tests/openstack/snaps/snaps_utils.py
+++ b/functest/opnfv_tests/openstack/snaps/snaps_utils.py
@@ -1,3 +1,5 @@
+#!/usr/bin/env python
+
# Copyright (c) 2015 All rights reserved
# This program and the accompanying materials
# are made available under the terms of the Apache License, Version 2.0
@@ -5,6 +7,8 @@
#
# http://www.apache.org/licenses/LICENSE-2.0
+# pylint: disable=missing-docstring
+
from functest.utils.constants import CONST
from snaps.openstack.utils import neutron_utils, nova_utils
@@ -19,7 +23,7 @@ def get_ext_net_name(os_creds):
"""
neutron = neutron_utils.neutron_client(os_creds)
ext_nets = neutron_utils.get_external_networks(neutron)
- if (hasattr(CONST, 'EXTERNAL_NETWORK')):
+ if hasattr(CONST, 'EXTERNAL_NETWORK'):
extnet_config = CONST.__getattribute__('EXTERNAL_NETWORK')
for ext_net in ext_nets:
if ext_net.name == extnet_config:
diff --git a/functest/opnfv_tests/openstack/vping/vping_base.py b/functest/opnfv_tests/openstack/vping/vping_base.py
index df9774ec..b99fdf6b 100644
--- a/functest/opnfv_tests/openstack/vping/vping_base.py
+++ b/functest/opnfv_tests/openstack/vping/vping_base.py
@@ -1,3 +1,5 @@
+#!/usr/bin/env python
+
# Copyright (c) 2017 Cable Television Laboratories, Inc. and others.
#
# This program and the accompanying materials
@@ -37,19 +39,15 @@ class VPingBase(testcase.TestCase):
def __init__(self, **kwargs):
super(VPingBase, self).__init__(**kwargs)
-
self.logger = logging.getLogger(__name__)
-
if 'os_creds' in kwargs:
self.os_creds = kwargs['os_creds']
else:
- creds_override = None
- if hasattr(CONST, 'snaps_os_creds_override'):
- creds_override = CONST.__getattribute__(
- 'snaps_os_creds_override')
-
+ creds_override = getattr(
+ CONST, 'snaps_os_creds_override') if hasattr(
+ CONST, 'snaps_os_creds_override') else None
self.os_creds = openstack_tests.get_credentials(
- os_env_file=CONST.__getattribute__('openstack_creds'),
+ os_env_file=getattr(CONST, 'openstack_creds'),
overrides=creds_override)
self.creators = list()
@@ -62,27 +60,24 @@ class VPingBase(testcase.TestCase):
# Shared metadata
self.guid = '-' + str(uuid.uuid4())
- self.router_name = CONST.__getattribute__(
- 'vping_router_name') + self.guid
- self.vm1_name = CONST.__getattribute__('vping_vm_name_1') + self.guid
- self.vm2_name = CONST.__getattribute__('vping_vm_name_2') + self.guid
-
- self.vm_boot_timeout = CONST.__getattribute__('vping_vm_boot_timeout')
- self.vm_delete_timeout = CONST.__getattribute__(
- 'vping_vm_delete_timeout')
- self.vm_ssh_connect_timeout = CONST.__getattribute__(
- 'vping_vm_ssh_connect_timeout')
- self.ping_timeout = CONST.__getattribute__('vping_ping_timeout')
+ self.router_name = getattr(CONST, 'vping_router_name') + self.guid
+ self.vm1_name = getattr(CONST, 'vping_vm_name_1') + self.guid
+ self.vm2_name = getattr(CONST, 'vping_vm_name_2') + self.guid
+
+ self.vm_boot_timeout = getattr(CONST, 'vping_vm_boot_timeout')
+ self.vm_delete_timeout = getattr(CONST, 'vping_vm_delete_timeout')
+ self.vm_ssh_connect_timeout = getattr(
+ CONST, 'vping_vm_ssh_connect_timeout')
+ self.ping_timeout = getattr(CONST, 'vping_ping_timeout')
self.flavor_name = 'vping-flavor' + self.guid
# Move this configuration option up for all tests to leverage
if hasattr(CONST, 'snaps_images_cirros'):
- self.cirros_image_config = CONST.__getattribute__(
- 'snaps_images_cirros')
+ self.cirros_image_config = getattr(CONST, 'snaps_images_cirros')
else:
self.cirros_image_config = None
- def run(self):
+ def run(self, **kwargs): # pylint: disable=too-many-locals
"""
Begins the test execution which should originate from the subclass
"""
@@ -95,7 +90,7 @@ class VPingBase(testcase.TestCase):
'%Y-%m-%d %H:%M:%S'))
image_base_name = '{}-{}'.format(
- CONST.__getattribute__('vping_image_name'),
+ getattr(CONST, 'vping_image_name'),
str(self.guid))
os_image_settings = openstack_tests.cirros_image_settings(
image_base_name, image_metadata=self.cirros_image_config)
@@ -105,26 +100,21 @@ class VPingBase(testcase.TestCase):
self.os_creds, os_image_settings)
self.creators.append(self.image_creator)
- private_net_name = CONST.__getattribute__(
- 'vping_private_net_name') + self.guid
- private_subnet_name = CONST.__getattribute__(
- 'vping_private_subnet_name') + self.guid
- private_subnet_cidr = CONST.__getattribute__(
- 'vping_private_subnet_cidr')
+ private_net_name = getattr(CONST, 'vping_private_net_name') + self.guid
+ private_subnet_name = getattr(
+ CONST, 'vping_private_subnet_name') + self.guid
+ private_subnet_cidr = getattr(CONST, 'vping_private_subnet_cidr')
vping_network_type = None
vping_physical_network = None
vping_segmentation_id = None
if hasattr(CONST, 'vping_network_type'):
- vping_network_type = CONST.__getattribute__(
- 'vping_network_type')
+ vping_network_type = getattr(CONST, 'vping_network_type')
if hasattr(CONST, 'vping_physical_network'):
- vping_physical_network = CONST.__getattribute__(
- 'vping_physical_network')
+ vping_physical_network = getattr(CONST, 'vping_physical_network')
if hasattr(CONST, 'vping_segmentation_id'):
- vping_segmentation_id = CONST.__getattribute__(
- 'vping_segmentation_id')
+ vping_segmentation_id = getattr(CONST, 'vping_segmentation_id')
self.logger.info(
"Creating network with name: '%s'", private_net_name)
@@ -154,7 +144,7 @@ class VPingBase(testcase.TestCase):
self.logger.info(
"Creating flavor with name: '%s'", self.flavor_name)
- scenario = CONST.__getattribute__('DEPLOY_SCENARIO')
+ scenario = getattr(CONST, 'DEPLOY_SCENARIO')
flavor_metadata = None
flavor_ram = 512
if 'ovs' in scenario or 'fdio' in scenario:
@@ -197,7 +187,7 @@ class VPingBase(testcase.TestCase):
Cleanup all OpenStack objects. Should be called on completion
:return:
"""
- if CONST.__getattribute__('vping_cleanup_objects') == 'True':
+ if getattr(CONST, 'vping_cleanup_objects') == 'True':
for creator in reversed(self.creators):
try:
creator.clean()
diff --git a/functest/opnfv_tests/openstack/vping/vping_ssh.py b/functest/opnfv_tests/openstack/vping/vping_ssh.py
index 7df767ed..57e177e5 100644
--- a/functest/opnfv_tests/openstack/vping/vping_ssh.py
+++ b/functest/opnfv_tests/openstack/vping/vping_ssh.py
@@ -1,5 +1,5 @@
#!/usr/bin/env python
-#
+
# Copyright (c) 2015 All rights reserved
# This program and the accompanying materials
# are made available under the terms of the Apache License, Version 2.0
@@ -7,12 +7,8 @@
#
# http://www.apache.org/licenses/LICENSE-2.0
-
"""vPingSSH testcase."""
-# This 1st import is here simply for pep8 as the 'os' package import appears
-# to be required for mock and the unit tests will fail without it
-import os # noqa # pylint: disable=unused-import
import time
from scp import SCPClient
@@ -53,7 +49,7 @@ class VPingSSH(vping_base.VPingBase):
self.sg_desc = CONST.__getattribute__('vping_sg_desc')
@energy.enable_recording
- def run(self):
+ def run(self, **kwargs):
"""
Excecute VPingSSH testcase.
diff --git a/functest/opnfv_tests/openstack/vping/vping_userdata.py b/functest/opnfv_tests/openstack/vping/vping_userdata.py
index ceba0917..76cdcf83 100644
--- a/functest/opnfv_tests/openstack/vping/vping_userdata.py
+++ b/functest/opnfv_tests/openstack/vping/vping_userdata.py
@@ -1,5 +1,5 @@
#!/usr/bin/env python
-#
+
# Copyright (c) 2015 All rights reserved
# This program and the accompanying materials
# are made available under the terms of the Apache License, Version 2.0
@@ -29,7 +29,7 @@ class VPingUserdata(vping_base.VPingBase):
kwargs["case_name"] = "vping_userdata"
super(VPingUserdata, self).__init__(**kwargs)
- def run(self):
+ def run(self, **kwargs):
"""
Sets up the OpenStack VM instance objects then executes the ping and
validates.
diff --git a/functest/tests/unit/openstack/snaps/test_snaps.py b/functest/tests/unit/openstack/snaps/test_snaps.py
index 9a360cbc..3d9e9df0 100644
--- a/functest/tests/unit/openstack/snaps/test_snaps.py
+++ b/functest/tests/unit/openstack/snaps/test_snaps.py
@@ -8,15 +8,15 @@
# pylint: disable=missing-docstring
-import mock
-import os
+import logging
import unittest
+import mock
from snaps.openstack.os_credentials import OSCreds
from functest.core.testcase import TestCase
-from functest.opnfv_tests.openstack.snaps import (connection_check, api_check,
- health_check, smoke)
+from functest.opnfv_tests.openstack.snaps import (
+ connection_check, api_check, health_check, smoke)
class ConnectionCheckTesting(unittest.TestCase):
@@ -35,40 +35,52 @@ class ConnectionCheckTesting(unittest.TestCase):
@mock.patch('functest.opnfv_tests.openstack.snaps.snaps_suite_builder.'
'add_openstack_client_tests')
- def test_run_success(self, add_os_client_tests):
- result = mock.MagicMock(name='unittest.TextTestResult')
- result.testsRun = 100
- result.failures = []
- result.errors = []
- with mock.patch('unittest.TextTestRunner.run', return_value=result):
- self.assertEquals(TestCase.EX_OK, self.connection_check.run())
- self.assertEquals(TestCase.EX_OK,
- self.connection_check.is_successful())
+ @mock.patch('unittest.TextTestRunner.run',
+ return_value=mock.MagicMock(name='unittest.TextTestResult'))
+ def test_run_success(self, *args):
+ args[0].return_value.testsRun = 100
+ args[0].return_value.failures = []
+ args[0].return_value.errors = []
+ self.assertEquals(TestCase.EX_OK, self.connection_check.run())
+ self.assertEquals(
+ TestCase.EX_OK, self.connection_check.is_successful())
+ args[0].assert_called_with(mock.ANY)
+ args[1].assert_called_with(
+ ext_net_name='foo', os_creds=self.os_creds, suite=mock.ANY,
+ use_keystone=True)
@mock.patch('functest.opnfv_tests.openstack.snaps.snaps_suite_builder.'
'add_openstack_client_tests')
- def test_run_1_of_100_failures(self, add_os_client_tests):
- result = mock.MagicMock(name='unittest.TextTestResult')
- result.testsRun = 100
- result.failures = ['foo']
- result.errors = []
- with mock.patch('unittest.TextTestRunner.run', return_value=result):
- self.assertEquals(TestCase.EX_OK, self.connection_check.run())
- self.assertEquals(TestCase.EX_TESTCASE_FAILED,
- self.connection_check.is_successful())
+ @mock.patch('unittest.TextTestRunner.run',
+ return_value=mock.MagicMock(name='unittest.TextTestResult'))
+ def test_run_1_of_100_ko(self, *args):
+ args[0].return_value.testsRun = 100
+ args[0].return_value.failures = ['foo']
+ args[0].return_value.errors = []
+ self.assertEquals(TestCase.EX_OK, self.connection_check.run())
+ self.assertEquals(
+ TestCase.EX_TESTCASE_FAILED, self.connection_check.is_successful())
+ args[0].assert_called_with(mock.ANY)
+ args[1].assert_called_with(
+ ext_net_name='foo', os_creds=self.os_creds, suite=mock.ANY,
+ use_keystone=True)
@mock.patch('functest.opnfv_tests.openstack.snaps.snaps_suite_builder.'
'add_openstack_client_tests')
- def test_run_1_of_100_failures_within_criteria(self, add_os_client_tests):
+ @mock.patch('unittest.TextTestRunner.run',
+ return_value=mock.MagicMock(name='unittest.TextTestResult'))
+ def test_run_1_of_100_ko_criteria(self, *args):
self.connection_check.criteria = 90
- result = mock.MagicMock(name='unittest.TextTestResult')
- result.testsRun = 100
- result.failures = ['foo']
- result.errors = []
- with mock.patch('unittest.TextTestRunner.run', return_value=result):
- self.assertEquals(TestCase.EX_OK, self.connection_check.run())
- self.assertEquals(TestCase.EX_OK,
- self.connection_check.is_successful())
+ args[0].return_value.testsRun = 100
+ args[0].return_value.failures = ['foo']
+ args[0].return_value.errors = []
+ self.assertEquals(TestCase.EX_OK, self.connection_check.run())
+ self.assertEquals(
+ TestCase.EX_OK, self.connection_check.is_successful())
+ args[0].assert_called_with(mock.ANY)
+ args[1].assert_called_with(
+ ext_net_name='foo', os_creds=self.os_creds, suite=mock.ANY,
+ use_keystone=True)
class APICheckTesting(unittest.TestCase):
@@ -87,40 +99,52 @@ class APICheckTesting(unittest.TestCase):
@mock.patch('functest.opnfv_tests.openstack.snaps.snaps_suite_builder.'
'add_openstack_api_tests')
- def test_run_success(self, add_tests):
- result = mock.MagicMock(name='unittest.TextTestResult')
- result.testsRun = 100
- result.failures = []
- result.errors = []
- with mock.patch('unittest.TextTestRunner.run', return_value=result):
- self.assertEquals(TestCase.EX_OK, self.api_check.run())
- self.assertEquals(TestCase.EX_OK,
- self.api_check.is_successful())
+ @mock.patch('unittest.TextTestRunner.run',
+ return_value=mock.MagicMock(name='unittest.TextTestResult'))
+ def test_run_success(self, *args):
+ args[0].return_value.testsRun = 100
+ args[0].return_value.failures = []
+ args[0].return_value.errors = []
+ self.assertEquals(TestCase.EX_OK, self.api_check.run())
+ self.assertEquals(
+ TestCase.EX_OK, self.api_check.is_successful())
+ args[0].assert_called_with(mock.ANY)
+ args[1].assert_called_with(
+ ext_net_name='foo', image_metadata=mock.ANY,
+ os_creds=self.os_creds, suite=mock.ANY, use_keystone=True)
@mock.patch('functest.opnfv_tests.openstack.snaps.snaps_suite_builder.'
'add_openstack_api_tests')
- def test_run_1_of_100_failures(self, add_tests):
- result = mock.MagicMock(name='unittest.TextTestResult')
- result.testsRun = 100
- result.failures = ['foo']
- result.errors = []
- with mock.patch('unittest.TextTestRunner.run', return_value=result):
- self.assertEquals(TestCase.EX_OK, self.api_check.run())
- self.assertEquals(TestCase.EX_TESTCASE_FAILED,
- self.api_check.is_successful())
+ @mock.patch('unittest.TextTestRunner.run',
+ return_value=mock.MagicMock(name='unittest.TextTestResult'))
+ def test_run_1_of_100_ko(self, *args):
+ args[0].return_value.testsRun = 100
+ args[0].return_value.failures = ['foo']
+ args[0].return_value.errors = []
+ self.assertEquals(TestCase.EX_OK, self.api_check.run())
+ self.assertEquals(
+ TestCase.EX_TESTCASE_FAILED, self.api_check.is_successful())
+ args[0].assert_called_with(mock.ANY)
+ args[1].assert_called_with(
+ ext_net_name='foo', image_metadata=mock.ANY,
+ os_creds=self.os_creds, suite=mock.ANY, use_keystone=True)
@mock.patch('functest.opnfv_tests.openstack.snaps.snaps_suite_builder.'
'add_openstack_api_tests')
- def test_run_1_of_100_failures_within_criteria(self, add_tests):
+ @mock.patch('unittest.TextTestRunner.run',
+ return_value=mock.MagicMock(name='unittest.TextTestResult'))
+ def test_run_1_of_100_ko_criteria(self, *args):
self.api_check.criteria = 90
- result = mock.MagicMock(name='unittest.TextTestResult')
- result.testsRun = 100
- result.failures = ['foo']
- result.errors = []
- with mock.patch('unittest.TextTestRunner.run', return_value=result):
- self.assertEquals(TestCase.EX_OK, self.api_check.run())
- self.assertEquals(TestCase.EX_OK,
- self.api_check.is_successful())
+ args[0].return_value.testsRun = 100
+ args[0].return_value.failures = ['foo']
+ args[0].return_value.errors = []
+ self.assertEquals(TestCase.EX_OK, self.api_check.run())
+ self.assertEquals(
+ TestCase.EX_OK, self.api_check.is_successful())
+ args[0].assert_called_with(mock.ANY)
+ args[1].assert_called_with(
+ ext_net_name='foo', image_metadata=mock.ANY,
+ os_creds=self.os_creds, suite=mock.ANY, use_keystone=True)
class HealthCheckTesting(unittest.TestCase):
@@ -137,42 +161,57 @@ class HealthCheckTesting(unittest.TestCase):
self.health_check = health_check.HealthCheck(
os_creds=self.os_creds, ext_net_name='foo')
- @mock.patch('functest.opnfv_tests.openstack.snaps.snaps_suite_builder.'
- 'add_openstack_client_tests')
- def test_run_success(self, add_tests):
- result = mock.MagicMock(name='unittest.TextTestResult')
- result.testsRun = 100
- result.failures = []
- result.errors = []
- with mock.patch('unittest.TextTestRunner.run', return_value=result):
- self.assertEquals(TestCase.EX_OK, self.health_check.run())
- self.assertEquals(TestCase.EX_OK,
- self.health_check.is_successful())
-
- @mock.patch('functest.opnfv_tests.openstack.snaps.snaps_suite_builder.'
- 'add_openstack_client_tests')
- def test_run_1_of_100_failures(self, add_tests):
- result = mock.MagicMock(name='unittest.TextTestResult')
- result.testsRun = 100
- result.failures = ['foo']
- result.errors = []
- with mock.patch('unittest.TextTestRunner.run', return_value=result):
- self.assertEquals(TestCase.EX_OK, self.health_check.run())
- self.assertEquals(TestCase.EX_TESTCASE_FAILED,
- self.health_check.is_successful())
-
- @mock.patch('functest.opnfv_tests.openstack.snaps.snaps_suite_builder.'
- 'add_openstack_client_tests')
- def test_run_1_of_100_failures_within_criteria(self, add_tests):
+ @mock.patch('snaps.openstack.tests.os_source_file_test.'
+ 'OSIntegrationTestCase.parameterize')
+ @mock.patch('unittest.TextTestRunner.run',
+ return_value=mock.MagicMock(name='unittest.TextTestResult'))
+ def test_run_success(self, *args):
+ args[0].return_value.testsRun = 100
+ args[0].return_value.failures = []
+ args[0].return_value.errors = []
+ self.assertEquals(TestCase.EX_OK, self.health_check.run())
+ self.assertEquals(
+ TestCase.EX_OK, self.health_check.is_successful())
+ args[0].assert_called_with(mock.ANY)
+ args[1].assert_called_with(
+ mock.ANY, ext_net_name='foo', flavor_metadata=None,
+ image_metadata=mock.ANY, netconf_override=None,
+ os_creds=self.os_creds, use_keystone=True)
+
+ @mock.patch('snaps.openstack.tests.os_source_file_test.'
+ 'OSIntegrationTestCase.parameterize')
+ @mock.patch('unittest.TextTestRunner.run',
+ return_value=mock.MagicMock(name='unittest.TextTestResult'))
+ def test_run_1_of_100_ko(self, *args):
+ args[0].return_value.testsRun = 100
+ args[0].return_value.failures = ['foo']
+ args[0].return_value.errors = []
+ self.assertEquals(TestCase.EX_OK, self.health_check.run())
+ self.assertEquals(
+ TestCase.EX_TESTCASE_FAILED, self.health_check.is_successful())
+ args[0].assert_called_with(mock.ANY)
+ args[1].assert_called_with(
+ mock.ANY, ext_net_name='foo', flavor_metadata=None,
+ image_metadata=mock.ANY, netconf_override=None,
+ os_creds=self.os_creds, use_keystone=True)
+
+ @mock.patch('snaps.openstack.tests.os_source_file_test.'
+ 'OSIntegrationTestCase.parameterize')
+ @mock.patch('unittest.TextTestRunner.run',
+ return_value=mock.MagicMock(name='unittest.TextTestResult'))
+ def test_run_1_of_100_ko_criteria(self, *args):
self.health_check.criteria = 90
- result = mock.MagicMock(name='unittest.TextTestResult')
- result.testsRun = 100
- result.failures = ['foo']
- result.errors = []
- with mock.patch('unittest.TextTestRunner.run', return_value=result):
- self.assertEquals(TestCase.EX_OK, self.health_check.run())
- self.assertEquals(TestCase.EX_OK,
- self.health_check.is_successful())
+ args[0].return_value.testsRun = 100
+ args[0].return_value.failures = ['foo']
+ args[0].return_value.errors = []
+ self.assertEquals(TestCase.EX_OK, self.health_check.run())
+ self.assertEquals(
+ TestCase.EX_OK, self.health_check.is_successful())
+ args[0].assert_called_with(mock.ANY)
+ args[1].assert_called_with(
+ mock.ANY, ext_net_name='foo', flavor_metadata=None,
+ image_metadata=mock.ANY, netconf_override=None,
+ os_creds=self.os_creds, use_keystone=True)
class SmokeTesting(unittest.TestCase):
@@ -191,40 +230,56 @@ class SmokeTesting(unittest.TestCase):
@mock.patch('functest.opnfv_tests.openstack.snaps.snaps_suite_builder.'
'add_openstack_integration_tests')
- @mock.patch('os.path.join', return_value=os.getcwd())
- def test_run_success(self, add_tests, cwd):
- result = mock.MagicMock(name='unittest.TextTestResult')
- result.testsRun = 100
- result.failures = []
- result.errors = []
- with mock.patch('unittest.TextTestRunner.run', return_value=result):
- self.assertEquals(TestCase.EX_OK, self.smoke.run())
- self.assertEquals(TestCase.EX_OK,
- self.smoke.is_successful())
+ @mock.patch('unittest.TextTestRunner.run',
+ return_value=mock.MagicMock(name='unittest.TextTestResult'))
+ def test_run_success(self, *args):
+ args[0].return_value.testsRun = 100
+ args[0].return_value.failures = []
+ args[0].return_value.errors = []
+ self.assertEquals(TestCase.EX_OK, self.smoke.run())
+ self.assertEquals(TestCase.EX_OK, self.smoke.is_successful())
+ args[0].assert_called_with(mock.ANY)
+ args[1].assert_called_with(
+ ext_net_name='foo', flavor_metadata=None, image_metadata=mock.ANY,
+ netconf_override=None, os_creds=self.os_creds,
+ suite=mock.ANY, use_floating_ips=True, use_keystone=True)
@mock.patch('functest.opnfv_tests.openstack.snaps.snaps_suite_builder.'
'add_openstack_integration_tests')
- @mock.patch('os.path.join', return_value=os.getcwd())
- def test_run_1_of_100_failures(self, add_tests, cwd):
- result = mock.MagicMock(name='unittest.TextTestResult')
- result.testsRun = 100
- result.failures = ['foo']
- result.errors = []
- with mock.patch('unittest.TextTestRunner.run', return_value=result):
- self.assertEquals(TestCase.EX_OK, self.smoke.run())
- self.assertEquals(TestCase.EX_TESTCASE_FAILED,
- self.smoke.is_successful())
+ @mock.patch('unittest.TextTestRunner.run',
+ return_value=mock.MagicMock(name='unittest.TextTestResult'))
+ def test_run_1_of_100_ko(self, *args):
+ args[0].return_value.testsRun = 100
+ args[0].return_value.failures = ['foo']
+ args[0].return_value.errors = []
+ self.assertEquals(TestCase.EX_OK, self.smoke.run())
+ self.assertEquals(
+ TestCase.EX_TESTCASE_FAILED, self.smoke.is_successful())
+ args[0].assert_called_with(mock.ANY)
+ args[1].assert_called_with(
+ ext_net_name='foo', flavor_metadata=None, image_metadata=mock.ANY,
+ netconf_override=mock.ANY, os_creds=self.os_creds,
+ suite=mock.ANY, use_floating_ips=True, use_keystone=True)
@mock.patch('functest.opnfv_tests.openstack.snaps.snaps_suite_builder.'
'add_openstack_integration_tests')
- @mock.patch('os.path.join', return_value=os.getcwd())
- def test_run_1_of_100_failures_within_criteria(self, add_tests, cwd):
+ @mock.patch('unittest.TextTestRunner.run',
+ return_value=mock.MagicMock(name='unittest.TextTestResult'))
+ def test_run_1_of_100_ko_criteria(self, *args):
self.smoke.criteria = 90
- result = mock.MagicMock(name='unittest.TextTestResult')
- result.testsRun = 100
- result.failures = ['foo']
- result.errors = []
- with mock.patch('unittest.TextTestRunner.run', return_value=result):
- self.assertEquals(TestCase.EX_OK, self.smoke.run())
- self.assertEquals(TestCase.EX_OK,
- self.smoke.is_successful())
+ args[0].return_value.testsRun = 100
+ args[0].return_value.failures = ['foo']
+ args[0].return_value.errors = []
+ self.assertEquals(TestCase.EX_OK, self.smoke.run())
+ self.assertEquals(
+ TestCase.EX_OK, self.smoke.is_successful())
+ args[0].assert_called_with(mock.ANY)
+ args[1].assert_called_with(
+ ext_net_name='foo', flavor_metadata=None, image_metadata=mock.ANY,
+ netconf_override=None, os_creds=self.os_creds,
+ suite=mock.ANY, use_floating_ips=True, use_keystone=True)
+
+
+if __name__ == "__main__":
+ logging.disable(logging.CRITICAL)
+ unittest.main(verbosity=2)
diff --git a/functest/tests/unit/openstack/vping/__init__.py b/functest/tests/unit/openstack/vping/__init__.py
new file mode 100644
index 00000000..e69de29b
--- /dev/null
+++ b/functest/tests/unit/openstack/vping/__init__.py
diff --git a/functest/tests/unit/openstack/vping/test_vping.py b/functest/tests/unit/openstack/vping/test_vping.py
index d494a795..42650dea 100644
--- a/functest/tests/unit/openstack/vping/test_vping.py
+++ b/functest/tests/unit/openstack/vping/test_vping.py
@@ -1,3 +1,5 @@
+#!/usr/bin/env python
+
# Copyright (c) 2017 Cable Television Laboratories, Inc. and others.
#
# All rights reserved. This program and the accompanying materials
@@ -8,6 +10,7 @@
# pylint: disable=missing-docstring
+import logging
import unittest
import mock
@@ -46,21 +49,25 @@ class VPingUserdataTesting(unittest.TestCase):
os_creds=self.os_creds)
@mock.patch('snaps.openstack.utils.deploy_utils.create_vm_instance')
- @mock.patch('functest.opnfv_tests.openstack.vping.vping_base.os.'
- 'path.exists', return_value=True)
+ @mock.patch('os.path.exists', return_value=True)
@mock.patch('snaps.openstack.create_flavor.OpenStackFlavor.create',
return_value=None)
@mock.patch('snaps.openstack.create_instance.OpenStackVmInstance.'
'get_port_ip', return_value='10.0.0.1')
@mock.patch('snaps.openstack.create_instance.OpenStackVmInstance.'
'vm_active', return_value=True)
- def test_vping_userdata(self, deploy_vm, path_exists, create_flavor,
- get_port_ip, vm_active):
+ @mock.patch('functest.opnfv_tests.openstack.snaps.snaps_utils.'
+ 'get_ext_net_name', return_value='foo')
+ def test_vping_userdata(self, *args):
+ # pylint: disable=unused-argument
with mock.patch('snaps.openstack.utils.deploy_utils.create_image',
return_value=OpenStackImage(self.os_creds, None)), \
mock.patch('snaps.openstack.utils.deploy_utils.create_network',
return_value=OpenStackNetwork(
self.os_creds, NetworkConfig(name='foo'))), \
+ mock.patch('snaps.openstack.utils.deploy_utils.create_router',
+ return_value=OpenStackRouter(
+ self.os_creds, RouterConfig(name='foo'))), \
mock.patch('snaps.openstack.utils.deploy_utils.'
'create_vm_instance',
return_value=OpenStackVmInstance(
@@ -91,8 +98,7 @@ class VPingSSHTesting(unittest.TestCase):
os_creds=self.os_creds)
@mock.patch('snaps.openstack.utils.deploy_utils.create_vm_instance')
- @mock.patch('functest.opnfv_tests.openstack.vping.vping_base.os.'
- 'path.exists', return_value=True)
+ @mock.patch('os.path.exists', return_value=True)
@mock.patch('snaps.openstack.create_flavor.OpenStackFlavor.create',
return_value=None)
@mock.patch('snaps.openstack.create_instance.OpenStackVmInstance.'
@@ -110,10 +116,8 @@ class VPingSSHTesting(unittest.TestCase):
'VPingSSH._do_vping_ssh', return_value=TestCase.EX_OK)
@mock.patch('functest.opnfv_tests.openstack.snaps.snaps_utils.'
'get_ext_net_name', return_value='foo')
- def test_vping_ssh(self, create_vm, path_exists,
- flavor_create, get_port_ip, vm_active, ssh_active,
- ssh_client, scp_client, trans_script, do_vping_ssh,
- ext_net_name):
+ def test_vping_ssh(self, *args):
+ # pylint: disable=unused-argument
os_vm_inst = mock.MagicMock(name='get_console_output')
os_vm_inst.get_console_output.return_value = 'vPing OK'
ssh_client = mock.MagicMock(name='get_transport')
@@ -159,3 +163,8 @@ class VPingSSHTesting(unittest.TestCase):
'OpenStackVmInstance.'
'ssh_client', return_value=ssh_client):
self.assertEquals(TestCase.EX_OK, self.vping_ssh.run())
+
+
+if __name__ == "__main__":
+ logging.disable(logging.CRITICAL)
+ unittest.main(verbosity=2)