summaryrefslogtreecommitdiffstats
path: root/functest
diff options
context:
space:
mode:
authorJuha Kosonen <juha.kosonen@nokia.com>2018-01-30 14:59:05 +0200
committerJuha Kosonen <juha.kosonen@nokia.com>2018-01-30 14:59:05 +0200
commit3b36c06f9223322e23e3885759355593b3c598a3 (patch)
tree518c1f0c8684beaacc991943870423f73a7a86d0 /functest
parent8e416aee220bf6959e2e21f18a5ebfec1421858b (diff)
Remove duplicated code related to snaps creds
Add support for providing credentials in snaps_utils. JIRA: FUNCTEST-916 Change-Id: I3e027229d213d3791a115920f7012309cc027712 Signed-off-by: Juha Kosonen <juha.kosonen@nokia.com>
Diffstat (limited to 'functest')
-rw-r--r--functest/opnfv_tests/openstack/rally/rally.py15
-rw-r--r--functest/opnfv_tests/openstack/snaps/snaps_test_runner.py13
-rw-r--r--functest/opnfv_tests/openstack/snaps/snaps_utils.py19
-rw-r--r--functest/opnfv_tests/openstack/vping/vping_base.py11
-rw-r--r--functest/opnfv_tests/vnf/epc/juju_epc.py5
-rw-r--r--functest/tests/unit/openstack/rally/test_rally.py2
6 files changed, 24 insertions, 41 deletions
diff --git a/functest/opnfv_tests/openstack/rally/rally.py b/functest/opnfv_tests/openstack/rally/rally.py
index b3aaab65..59a67095 100644
--- a/functest/opnfv_tests/openstack/rally/rally.py
+++ b/functest/opnfv_tests/openstack/rally/rally.py
@@ -36,7 +36,6 @@ from snaps.config.network import NetworkConfig, SubnetConfig
from snaps.config.router import RouterConfig
from snaps.openstack.create_flavor import OpenStackFlavor
-from snaps.openstack.tests import openstack_tests
from snaps.openstack.utils import deploy_utils
LOGGER = logging.getLogger(__name__)
@@ -92,20 +91,8 @@ class RallyBase(testcase.TestCase):
def __init__(self, **kwargs):
"""Initialize RallyBase object."""
super(RallyBase, self).__init__(**kwargs)
- 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')
-
- self.os_creds = openstack_tests.get_credentials(
- os_env_file=CONST.__getattribute__('openstack_creds'),
- overrides=creds_override)
-
+ self.os_creds = kwargs.get('os_creds') or snaps_utils.get_credentials()
self.guid = '-' + str(uuid.uuid4())
-
self.creators = []
self.mode = ''
self.summary = []
diff --git a/functest/opnfv_tests/openstack/snaps/snaps_test_runner.py b/functest/opnfv_tests/openstack/snaps/snaps_test_runner.py
index 94c8af85..a2dadb75 100644
--- a/functest/opnfv_tests/openstack/snaps/snaps_test_runner.py
+++ b/functest/opnfv_tests/openstack/snaps/snaps_test_runner.py
@@ -17,7 +17,6 @@ from functest.opnfv_tests.openstack.snaps import snaps_utils
from functest.utils.constants import CONST
from snaps.openstack import create_flavor
-from snaps.openstack.tests import openstack_tests
class SnapsTestRunner(unit.Suite):
@@ -29,17 +28,7 @@ class SnapsTestRunner(unit.Suite):
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:
- creds_override = None
- if hasattr(CONST, 'snaps_os_creds_override'):
- creds_override = CONST.__getattribute__(
- 'snaps_os_creds_override')
- self.os_creds = openstack_tests.get_credentials(
- os_env_file=CONST.__getattribute__('openstack_creds'),
- proxy_settings_str=None, ssh_proxy_cmd=None,
- overrides=creds_override)
+ self.os_creds = kwargs.get('os_creds') or snaps_utils.get_credentials()
if 'ext_net_name' in kwargs:
self.ext_net_name = kwargs['ext_net_name']
diff --git a/functest/opnfv_tests/openstack/snaps/snaps_utils.py b/functest/opnfv_tests/openstack/snaps/snaps_utils.py
index 1153b63d..6b0ee497 100644
--- a/functest/opnfv_tests/openstack/snaps/snaps_utils.py
+++ b/functest/opnfv_tests/openstack/snaps/snaps_utils.py
@@ -11,6 +11,7 @@
from functest.utils.constants import CONST
+from snaps.openstack.tests import openstack_tests
from snaps.openstack.utils import neutron_utils, nova_utils
@@ -40,3 +41,21 @@ def get_active_compute_cnt(os_creds):
nova = nova_utils.nova_client(os_creds)
computes = nova_utils.get_availability_zone_hosts(nova, zone_name='nova')
return len(computes)
+
+
+def get_credentials(proxy_settings_str=None, ssh_proxy_cmd=None):
+ """
+ Returns snaps OSCreds object instance
+ :param: proxy_settings_str: proxy settings string <host>:<port>
+ :param: ssh_proxy_cmd: the SSH proxy command for the environment
+ :return: an instance of snaps OSCreds object
+ """
+ creds_override = None
+ if hasattr(CONST, 'snaps_os_creds_override'):
+ creds_override = CONST.__getattribute__(
+ 'snaps_os_creds_override')
+ os_creds = openstack_tests.get_credentials(
+ os_env_file=CONST.__getattribute__('openstack_creds'),
+ proxy_settings_str=proxy_settings_str, ssh_proxy_cmd=ssh_proxy_cmd,
+ overrides=creds_override)
+ return os_creds
diff --git a/functest/opnfv_tests/openstack/vping/vping_base.py b/functest/opnfv_tests/openstack/vping/vping_base.py
index b99fdf6b..7170101f 100644
--- a/functest/opnfv_tests/openstack/vping/vping_base.py
+++ b/functest/opnfv_tests/openstack/vping/vping_base.py
@@ -40,16 +40,7 @@ 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 = 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=getattr(CONST, 'openstack_creds'),
- overrides=creds_override)
-
+ self.os_creds = kwargs.get('os_creds') or snaps_utils.get_credentials()
self.creators = list()
self.image_creator = None
self.network_creator = None
diff --git a/functest/opnfv_tests/vnf/epc/juju_epc.py b/functest/opnfv_tests/vnf/epc/juju_epc.py
index aec00853..14329329 100644
--- a/functest/opnfv_tests/vnf/epc/juju_epc.py
+++ b/functest/opnfv_tests/vnf/epc/juju_epc.py
@@ -29,7 +29,6 @@ from snaps.openstack.create_network import (NetworkSettings,
from snaps.openstack.create_router import (RouterSettings, OpenStackRouter)
from snaps.openstack.create_flavor import (FlavorSettings, OpenStackFlavor)
from snaps.openstack.create_image import (ImageSettings, OpenStackImage)
-from snaps.openstack.tests import openstack_tests
from snaps.openstack.utils import keystone_utils
import yaml
@@ -66,9 +65,7 @@ class JujuEpc(vnf.VnfOnBoarding):
self.created_object = []
self.snaps_creds = ''
- self.os_creds = openstack_tests.get_credentials(
- os_env_file=CONST.__getattribute__('openstack_creds'))
-
+ self.os_creds = snaps_utils.get_credentials()
self.details['orchestrator'] = dict(
name=get_config("orchestrator.name", config_file),
version=get_config("orchestrator.version", config_file),
diff --git a/functest/tests/unit/openstack/rally/test_rally.py b/functest/tests/unit/openstack/rally/test_rally.py
index ba8a241f..92177f36 100644
--- a/functest/tests/unit/openstack/rally/test_rally.py
+++ b/functest/tests/unit/openstack/rally/test_rally.py
@@ -26,7 +26,7 @@ class OSRallyTesting(unittest.TestCase):
os_creds = OSCreds(
username='user', password='pass',
auth_url='http://foo.com:5000/v3', project_name='bar')
- with mock.patch('snaps.openstack.tests.openstack_tests.'
+ with mock.patch('functest.opnfv_tests.openstack.snaps.snaps_utils.'
'get_credentials', return_value=os_creds) as m:
self.rally_base = rally.RallyBase()
self.assertTrue(m.called)