Merge "Fix service discovery in functional tests"
This commit is contained in:
commit
17a2c67de9
openstackclient
@ -681,29 +681,30 @@ class UnsetSubnet(command.Command):
|
||||
def take_action(self, parsed_args):
|
||||
client = self.app.client_manager.network
|
||||
obj = client.find_subnet(parsed_args.subnet, ignore_missing=False)
|
||||
tmp_obj = copy.deepcopy(obj)
|
||||
|
||||
attrs = {}
|
||||
if parsed_args.dns_nameservers:
|
||||
_update_arguments(tmp_obj.dns_nameservers,
|
||||
attrs['dns_nameservers'] = copy.deepcopy(obj.dns_nameservers)
|
||||
_update_arguments(attrs['dns_nameservers'],
|
||||
parsed_args.dns_nameservers,
|
||||
'dns-nameserver')
|
||||
attrs['dns_nameservers'] = tmp_obj.dns_nameservers
|
||||
if parsed_args.host_routes:
|
||||
attrs['host_routes'] = copy.deepcopy(obj.host_routes)
|
||||
_update_arguments(
|
||||
tmp_obj.host_routes,
|
||||
attrs['host_routes'],
|
||||
convert_entries_to_nexthop(parsed_args.host_routes),
|
||||
'host-route')
|
||||
attrs['host_routes'] = tmp_obj.host_routes
|
||||
if parsed_args.allocation_pools:
|
||||
_update_arguments(tmp_obj.allocation_pools,
|
||||
attrs['allocation_pools'] = copy.deepcopy(obj.allocation_pools)
|
||||
_update_arguments(attrs['allocation_pools'],
|
||||
parsed_args.allocation_pools,
|
||||
'allocation-pool')
|
||||
attrs['allocation_pools'] = tmp_obj.allocation_pools
|
||||
|
||||
if parsed_args.service_types:
|
||||
_update_arguments(tmp_obj.service_types,
|
||||
attrs['service_types'] = copy.deepcopy(obj.service_types)
|
||||
_update_arguments(attrs['service_types'],
|
||||
parsed_args.service_types,
|
||||
'service-type')
|
||||
attrs['service_types'] = tmp_obj.service_types
|
||||
if attrs:
|
||||
client.update_subnet(obj, **attrs)
|
||||
|
||||
|
@ -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."""
|
||||
@ -66,6 +49,24 @@ class TestCase(testtools.TestCase):
|
||||
'openstack --os-cloud={cloud} '.format(cloud=cloud) +
|
||||
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])
|
||||
|
@ -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"""
|
||||
|
@ -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')
|
||||
|
||||
|
@ -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"""
|
||||
|
@ -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):
|
||||
|
@ -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)
|
||||
|
||||
|
@ -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')
|
||||
|
@ -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()
|
||||
|
Loading…
x
Reference in New Issue
Block a user