summaryrefslogtreecommitdiff
path: root/openstackclient/tests
diff options
context:
space:
mode:
Diffstat (limited to 'openstackclient/tests')
-rw-r--r--openstackclient/tests/functional/base.py35
-rw-r--r--openstackclient/tests/functional/common/test_extension.py2
-rw-r--r--openstackclient/tests/functional/common/test_quota.py2
-rw-r--r--openstackclient/tests/functional/compute/v2/test_server.py3
-rw-r--r--openstackclient/tests/functional/network/v2/common.py2
-rw-r--r--openstackclient/tests/functional/network/v2/test_network_segment_range.py14
-rw-r--r--openstackclient/tests/functional/object/v1/common.py2
-rw-r--r--openstackclient/tests/functional/volume/v1/common.py3
8 files changed, 31 insertions, 32 deletions
diff --git a/openstackclient/tests/functional/base.py b/openstackclient/tests/functional/base.py
index 7705c655..1414e6bb 100644
--- a/openstackclient/tests/functional/base.py
+++ b/openstackclient/tests/functional/base.py
@@ -11,7 +11,6 @@
# under the License.
import os
-import re
import shlex
import subprocess
@@ -30,8 +29,6 @@ ADMIN_CLOUD = os.environ.get('OS_ADMIN_CLOUD', 'devstack-admin')
def execute(cmd, fail_ok=False, merge_stderr=False):
"""Executes specified command for the given action."""
cmdlist = shlex.split(cmd)
- result = ''
- result_err = ''
stdout = subprocess.PIPE
stderr = subprocess.STDOUT if merge_stderr else subprocess.PIPE
proc = subprocess.Popen(cmdlist, stdout=stdout, stderr=stderr)
@@ -43,22 +40,8 @@ def execute(cmd, fail_ok=False, merge_stderr=False):
return result
-def is_service_enabled(service):
- """Ask client cloud if service is available"""
- try:
- ret = execute('openstack service show -f value -c enabled ' + service)
- except exceptions.CommandFailed:
- # We get here for multiple reasons, all of them mean that a working
- # service is not available
- return False
-
- return "True" in ret
-
-
class TestCase(testtools.TestCase):
- delimiter_line = re.compile('^\+\-[\+\-]+\-\+$')
-
@classmethod
def openstack(cls, cmd, cloud=ADMIN_CLOUD, fail_ok=False):
"""Executes openstackclient command for the given action."""
@@ -67,6 +50,24 @@ class TestCase(testtools.TestCase):
cmd, fail_ok=fail_ok)
@classmethod
+ def is_service_enabled(cls, service):
+ """Ask client cloud if service is available"""
+ cmd = ('service show -f value -c enabled {service}'
+ .format(service=service))
+ try:
+ return "True" in cls.openstack(cmd)
+ except exceptions.CommandFailed as e:
+ if "No service with a type, name or ID of" in str(e):
+ return False
+ else:
+ raise # Unable to determine if service is enabled
+
+ @classmethod
+ def is_extension_enabled(cls, alias):
+ """Ask client cloud if extension is enabled"""
+ return alias in cls.openstack('extension list -f value -c Alias')
+
+ @classmethod
def get_openstack_configuration_value(cls, configuration):
opts = cls.get_opts([configuration])
return cls.openstack('configuration show ' + opts)
diff --git a/openstackclient/tests/functional/common/test_extension.py b/openstackclient/tests/functional/common/test_extension.py
index db50855f..92efabef 100644
--- a/openstackclient/tests/functional/common/test_extension.py
+++ b/openstackclient/tests/functional/common/test_extension.py
@@ -26,7 +26,7 @@ class ExtensionTests(base.TestCase):
@classmethod
def setUpClass(cls):
super(ExtensionTests, cls).setUpClass()
- cls.haz_network = base.is_service_enabled('network')
+ cls.haz_network = cls.is_service_enabled('network')
def test_extension_list_compute(self):
"""Test compute extension list"""
diff --git a/openstackclient/tests/functional/common/test_quota.py b/openstackclient/tests/functional/common/test_quota.py
index 85942281..9c057460 100644
--- a/openstackclient/tests/functional/common/test_quota.py
+++ b/openstackclient/tests/functional/common/test_quota.py
@@ -27,7 +27,7 @@ class QuotaTests(base.TestCase):
@classmethod
def setUpClass(cls):
super(QuotaTests, cls).setUpClass()
- cls.haz_network = base.is_service_enabled('network')
+ cls.haz_network = cls.is_service_enabled('network')
cls.PROJECT_NAME =\
cls.get_openstack_configuration_value('auth.project_name')
diff --git a/openstackclient/tests/functional/compute/v2/test_server.py b/openstackclient/tests/functional/compute/v2/test_server.py
index 3cb72d9f..c8fb44d3 100644
--- a/openstackclient/tests/functional/compute/v2/test_server.py
+++ b/openstackclient/tests/functional/compute/v2/test_server.py
@@ -16,7 +16,6 @@ import uuid
from tempest.lib import exceptions
-from openstackclient.tests.functional import base
from openstackclient.tests.functional.compute.v2 import common
from openstackclient.tests.functional.volume.v2 import common as volume_common
@@ -27,7 +26,7 @@ class ServerTests(common.ComputeTestCase):
@classmethod
def setUpClass(cls):
super(ServerTests, cls).setUpClass()
- cls.haz_network = base.is_service_enabled('network')
+ cls.haz_network = cls.is_service_enabled('network')
def test_server_list(self):
"""Test server list, set"""
diff --git a/openstackclient/tests/functional/network/v2/common.py b/openstackclient/tests/functional/network/v2/common.py
index a18bc48f..5243ecd0 100644
--- a/openstackclient/tests/functional/network/v2/common.py
+++ b/openstackclient/tests/functional/network/v2/common.py
@@ -22,7 +22,7 @@ class NetworkTests(base.TestCase):
@classmethod
def setUpClass(cls):
super(NetworkTests, cls).setUpClass()
- cls.haz_network = base.is_service_enabled('network')
+ cls.haz_network = cls.is_service_enabled('network')
class NetworkTagTests(NetworkTests):
diff --git a/openstackclient/tests/functional/network/v2/test_network_segment_range.py b/openstackclient/tests/functional/network/v2/test_network_segment_range.py
index 95402dcb..c42f8744 100644
--- a/openstackclient/tests/functional/network/v2/test_network_segment_range.py
+++ b/openstackclient/tests/functional/network/v2/test_network_segment_range.py
@@ -28,6 +28,8 @@ class NetworkSegmentRangeTests(common.NetworkTests):
# Nothing in this class works with Nova Network
if not self.haz_network:
self.skipTest("No Network service present")
+ if not self.is_extension_enabled('network-segment-range'):
+ self.skipTest("No network-segment-range extension present")
self.PROJECT_NAME = uuid.uuid4().hex
def test_network_segment_range_create_delete(self):
@@ -83,7 +85,7 @@ class NetworkSegmentRangeTests(common.NetworkTests):
)
json_output = json.loads(self.openstack(
- 'network segment list -f json'
+ 'network segment range list -f json'
))
item_map = {
item.get('ID'): item.get('Name') for item in json_output
@@ -117,13 +119,11 @@ class NetworkSegmentRangeTests(common.NetworkTests):
json_output["project_id"],
)
- new_minimum = '2010'
- new_maximum = '2060'
+ new_minimum = 2010
+ new_maximum = 2060
cmd_output = self.openstack(
- 'network segment range set ' +
- '--minimum ' + new_minimum + ' ' +
- '--maximum ' + new_maximum + ' ' +
- name
+ 'network segment range set --minimum {min} --maximum {max} {name}'
+ .format(min=new_minimum, max=new_maximum, name=name)
)
self.assertOutput('', cmd_output)
diff --git a/openstackclient/tests/functional/object/v1/common.py b/openstackclient/tests/functional/object/v1/common.py
index 44771aaa..b0133430 100644
--- a/openstackclient/tests/functional/object/v1/common.py
+++ b/openstackclient/tests/functional/object/v1/common.py
@@ -19,4 +19,4 @@ class ObjectStoreTests(base.TestCase):
@classmethod
def setUpClass(cls):
super(ObjectStoreTests, cls).setUpClass()
- cls.haz_object_store = base.is_service_enabled('object-store')
+ cls.haz_object_store = cls.is_service_enabled('object-store')
diff --git a/openstackclient/tests/functional/volume/v1/common.py b/openstackclient/tests/functional/volume/v1/common.py
index bb3c674e..04eb1f48 100644
--- a/openstackclient/tests/functional/volume/v1/common.py
+++ b/openstackclient/tests/functional/volume/v1/common.py
@@ -12,7 +12,6 @@
import fixtures
-from openstackclient.tests.functional import base
from openstackclient.tests.functional.volume import base as volume_base
@@ -25,7 +24,7 @@ class BaseVolumeTests(volume_base.BaseVolumeTests):
# TODO(dtroyer): This needs to be updated to specifically check for
# Volume v1 rather than just 'volume', but for now
# that is enough until we get proper version negotiation
- cls.haz_volume_v1 = base.is_service_enabled('volume')
+ cls.haz_volume_v1 = cls.is_service_enabled('volume')
def setUp(self):
super(BaseVolumeTests, self).setUp()