Skip to content

Commit 7741347

Browse files
author
Glenn Van de Water
committed
Fix service discovery in functional tests
If a required service is not enabled then we skip the test. The discovery is done by tests/functional/base.py:is_service_enabled but this method is broken, credentials are not passed to the 'openstack service show' command so every call will fail and every test that relies on it will be skipped. This commit fixed that method and the issues that popped up when re-enabling tests. Network segment range: - issue where we assumed network-segment-range extension is always present - issue where we compare integers and string representations of numbers Subnet: - issue where we try to deepcopy an uncopyable object in UnsetSubnet Change-Id: Id3cc907c1ed2a25b49cf6f4a7233e0401a02383a Story: 2005169 Task: 29908
1 parent 28c06d0 commit 7741347

9 files changed

Lines changed: 41 additions & 41 deletions

File tree

openstackclient/network/v2/subnet.py

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -681,29 +681,30 @@ def get_parser(self, prog_name):
681681
def take_action(self, parsed_args):
682682
client = self.app.client_manager.network
683683
obj = client.find_subnet(parsed_args.subnet, ignore_missing=False)
684-
tmp_obj = copy.deepcopy(obj)
684+
685685
attrs = {}
686686
if parsed_args.dns_nameservers:
687-
_update_arguments(tmp_obj.dns_nameservers,
687+
attrs['dns_nameservers'] = copy.deepcopy(obj.dns_nameservers)
688+
_update_arguments(attrs['dns_nameservers'],
688689
parsed_args.dns_nameservers,
689690
'dns-nameserver')
690-
attrs['dns_nameservers'] = tmp_obj.dns_nameservers
691691
if parsed_args.host_routes:
692+
attrs['host_routes'] = copy.deepcopy(obj.host_routes)
692693
_update_arguments(
693-
tmp_obj.host_routes,
694+
attrs['host_routes'],
694695
convert_entries_to_nexthop(parsed_args.host_routes),
695696
'host-route')
696-
attrs['host_routes'] = tmp_obj.host_routes
697697
if parsed_args.allocation_pools:
698-
_update_arguments(tmp_obj.allocation_pools,
698+
attrs['allocation_pools'] = copy.deepcopy(obj.allocation_pools)
699+
_update_arguments(attrs['allocation_pools'],
699700
parsed_args.allocation_pools,
700701
'allocation-pool')
701-
attrs['allocation_pools'] = tmp_obj.allocation_pools
702+
702703
if parsed_args.service_types:
703-
_update_arguments(tmp_obj.service_types,
704+
attrs['service_types'] = copy.deepcopy(obj.service_types)
705+
_update_arguments(attrs['service_types'],
704706
parsed_args.service_types,
705707
'service-type')
706-
attrs['service_types'] = tmp_obj.service_types
707708
if attrs:
708709
client.update_subnet(obj, **attrs)
709710

openstackclient/tests/functional/base.py

Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
# under the License.
1212

1313
import os
14-
import re
1514
import shlex
1615
import subprocess
1716

@@ -30,8 +29,6 @@
3029
def execute(cmd, fail_ok=False, merge_stderr=False):
3130
"""Executes specified command for the given action."""
3231
cmdlist = shlex.split(cmd)
33-
result = ''
34-
result_err = ''
3532
stdout = subprocess.PIPE
3633
stderr = subprocess.STDOUT if merge_stderr else subprocess.PIPE
3734
proc = subprocess.Popen(cmdlist, stdout=stdout, stderr=stderr)
@@ -43,29 +40,33 @@ def execute(cmd, fail_ok=False, merge_stderr=False):
4340
return result
4441

4542

46-
def is_service_enabled(service):
47-
"""Ask client cloud if service is available"""
48-
try:
49-
ret = execute('openstack service show -f value -c enabled ' + service)
50-
except exceptions.CommandFailed:
51-
# We get here for multiple reasons, all of them mean that a working
52-
# service is not available
53-
return False
54-
55-
return "True" in ret
56-
57-
5843
class TestCase(testtools.TestCase):
5944

60-
delimiter_line = re.compile('^\+\-[\+\-]+\-\+$')
61-
6245
@classmethod
6346
def openstack(cls, cmd, cloud=ADMIN_CLOUD, fail_ok=False):
6447
"""Executes openstackclient command for the given action."""
6548
return execute(
6649
'openstack --os-cloud={cloud} '.format(cloud=cloud) +
6750
cmd, fail_ok=fail_ok)
6851

52+
@classmethod
53+
def is_service_enabled(cls, service):
54+
"""Ask client cloud if service is available"""
55+
cmd = ('service show -f value -c enabled {service}'
56+
.format(service=service))
57+
try:
58+
return "True" in cls.openstack(cmd)
59+
except exceptions.CommandFailed as e:
60+
if "No service with a type, name or ID of" in str(e):
61+
return False
62+
else:
63+
raise # Unable to determine if service is enabled
64+
65+
@classmethod
66+
def is_extension_enabled(cls, alias):
67+
"""Ask client cloud if extension is enabled"""
68+
return alias in cls.openstack('extension list -f value -c Alias')
69+
6970
@classmethod
7071
def get_openstack_configuration_value(cls, configuration):
7172
opts = cls.get_opts([configuration])

openstackclient/tests/functional/common/test_extension.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ class ExtensionTests(base.TestCase):
2626
@classmethod
2727
def setUpClass(cls):
2828
super(ExtensionTests, cls).setUpClass()
29-
cls.haz_network = base.is_service_enabled('network')
29+
cls.haz_network = cls.is_service_enabled('network')
3030

3131
def test_extension_list_compute(self):
3232
"""Test compute extension list"""

openstackclient/tests/functional/common/test_quota.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ class QuotaTests(base.TestCase):
2727
@classmethod
2828
def setUpClass(cls):
2929
super(QuotaTests, cls).setUpClass()
30-
cls.haz_network = base.is_service_enabled('network')
30+
cls.haz_network = cls.is_service_enabled('network')
3131
cls.PROJECT_NAME =\
3232
cls.get_openstack_configuration_value('auth.project_name')
3333

openstackclient/tests/functional/compute/v2/test_server.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616

1717
from tempest.lib import exceptions
1818

19-
from openstackclient.tests.functional import base
2019
from openstackclient.tests.functional.compute.v2 import common
2120
from openstackclient.tests.functional.volume.v2 import common as volume_common
2221

@@ -27,7 +26,7 @@ class ServerTests(common.ComputeTestCase):
2726
@classmethod
2827
def setUpClass(cls):
2928
super(ServerTests, cls).setUpClass()
30-
cls.haz_network = base.is_service_enabled('network')
29+
cls.haz_network = cls.is_service_enabled('network')
3130

3231
def test_server_list(self):
3332
"""Test server list, set"""

openstackclient/tests/functional/network/v2/common.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ class NetworkTests(base.TestCase):
2222
@classmethod
2323
def setUpClass(cls):
2424
super(NetworkTests, cls).setUpClass()
25-
cls.haz_network = base.is_service_enabled('network')
25+
cls.haz_network = cls.is_service_enabled('network')
2626

2727

2828
class NetworkTagTests(NetworkTests):

openstackclient/tests/functional/network/v2/test_network_segment_range.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@ def setUp(self):
2828
# Nothing in this class works with Nova Network
2929
if not self.haz_network:
3030
self.skipTest("No Network service present")
31+
if not self.is_extension_enabled('network-segment-range'):
32+
self.skipTest("No network-segment-range extension present")
3133
self.PROJECT_NAME = uuid.uuid4().hex
3234

3335
def test_network_segment_range_create_delete(self):
@@ -83,7 +85,7 @@ def test_network_segment_range_list(self):
8385
)
8486

8587
json_output = json.loads(self.openstack(
86-
'network segment list -f json'
88+
'network segment range list -f json'
8789
))
8890
item_map = {
8991
item.get('ID'): item.get('Name') for item in json_output
@@ -117,13 +119,11 @@ def test_network_segment_range_set_show(self):
117119
json_output["project_id"],
118120
)
119121

120-
new_minimum = '2010'
121-
new_maximum = '2060'
122+
new_minimum = 2010
123+
new_maximum = 2060
122124
cmd_output = self.openstack(
123-
'network segment range set ' +
124-
'--minimum ' + new_minimum + ' ' +
125-
'--maximum ' + new_maximum + ' ' +
126-
name
125+
'network segment range set --minimum {min} --maximum {max} {name}'
126+
.format(min=new_minimum, max=new_maximum, name=name)
127127
)
128128
self.assertOutput('', cmd_output)
129129

openstackclient/tests/functional/object/v1/common.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,4 +19,4 @@ class ObjectStoreTests(base.TestCase):
1919
@classmethod
2020
def setUpClass(cls):
2121
super(ObjectStoreTests, cls).setUpClass()
22-
cls.haz_object_store = base.is_service_enabled('object-store')
22+
cls.haz_object_store = cls.is_service_enabled('object-store')

openstackclient/tests/functional/volume/v1/common.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212

1313
import fixtures
1414

15-
from openstackclient.tests.functional import base
1615
from openstackclient.tests.functional.volume import base as volume_base
1716

1817

@@ -25,7 +24,7 @@ def setUpClass(cls):
2524
# TODO(dtroyer): This needs to be updated to specifically check for
2625
# Volume v1 rather than just 'volume', but for now
2726
# that is enough until we get proper version negotiation
28-
cls.haz_volume_v1 = base.is_service_enabled('volume')
27+
cls.haz_volume_v1 = cls.is_service_enabled('volume')
2928

3029
def setUp(self):
3130
super(BaseVolumeTests, self).setUp()

0 commit comments

Comments
 (0)