Skip to content

Commit 410a0ec

Browse files
[Fix] tests
1 parent 8d7edef commit 410a0ec

2 files changed

Lines changed: 17 additions & 15 deletions

File tree

otcextensions/sdk/vpcep/v1/_proxy.py

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
# License for the specific language governing permissions and limitations
1111
# under the License.
1212
#
13+
import re
1314
from openstack import exceptions
1415
from openstack import proxy
1516
from otcextensions.sdk.vpcep.v1 import connection as _connection
@@ -309,30 +310,31 @@ def get_target_service(self, name_or_id, ignore_missing=False):
309310
when no resource can be found.
310311
311312
"""
312-
try:
313-
base_path = _target_service.TargetService.base_path + \
314-
'?id={}'.format(name_or_id)
315-
return self._get(
316-
_target_service.TargetService,
317-
base_path=base_path,
318-
requires_id=False
313+
uuid_re = re.compile(
314+
r"^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$"
315+
)
316+
317+
if isinstance(name_or_id, str) and uuid_re.match(name_or_id):
318+
base_path = (
319+
_target_service.TargetService.base_path
320+
+ "?id={}".format(name_or_id)
321+
)
322+
else:
323+
base_path = (
324+
_target_service.TargetService.base_path
325+
+ "?endpoint_service_name={}".format(name_or_id)
319326
)
320-
except exceptions.ResourceNotFound:
321-
pass
322327

323328
try:
324-
base_path = _target_service.TargetService.base_path + \
325-
'?endpoint_service_name={}'.format(name_or_id)
326329
return self._get(
327330
_target_service.TargetService,
328331
base_path=base_path,
329-
requires_id=False
332+
requires_id=False,
330333
)
331334
except exceptions.ResourceNotFound:
332335
if ignore_missing:
333336
return None
334-
else:
335-
raise
337+
raise
336338

337339
# ======== VPCEP Resource Quota ========
338340

otcextensions/tests/unit/sdk/natv3/v3/test_gateway.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ def test_basic(self):
4646
sot = gateway.PrivateNatGateway()
4747
self.assertEqual('gateways', sot.resources_key)
4848
self.assertEqual('gateway', sot.resource_key)
49-
self.assertEqual('private-nat/gateways',
49+
self.assertEqual('/private-nat/gateways',
5050
sot.base_path)
5151
self.assertTrue(sot.allow_list)
5252

0 commit comments

Comments
 (0)