Skip to content

Commit

Permalink
now like 'vpcs' are not excluded because they do not match pattern.
Browse files Browse the repository at this point in the history
  • Loading branch information
anton-sidelnikov committed Nov 25, 2024
1 parent 205bf1d commit 44bfa8f
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 7 deletions.
12 changes: 5 additions & 7 deletions otcextensions/common/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -159,13 +159,11 @@ def extract_url_parts(url: str, project_id: str) -> list:
url_parts = [x for x in path.split('/') if x != project_id]

# Exclude parts that are version identifiers
url_parts = list(
filter(
lambda x: not any(
c.isdigit() for c in x[1:]) and (x[0].lower() != 'v'),
url_parts
)
)
url_parts = list(filter(
lambda x: len(x) > 0 and not
(x.lower().startswith('v') and x[1:].isdigit()),
url_parts
))

# Strip out empty or None segments and return
return [part for part in url_parts if part]
4 changes: 4 additions & 0 deletions otcextensions/sdk/vpc/v1/_proxy.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
from openstack import exceptions
from openstack import proxy

from otcextensions.common.utils import extract_url_parts
from otcextensions.sdk.vpc.v1 import bandwidth as _bandwidth
from otcextensions.sdk.vpc.v1 import peering as _peering
from otcextensions.sdk.vpc.v1 import route as _route
Expand All @@ -31,6 +32,9 @@ class PublicInfo:
class Proxy(proxy.Proxy):
skip_discovery = True

def _extract_name(self, url, service_type=None, project_id=None):
return extract_url_parts(url, project_id)

# ======== Bandwidth ========
def assign_bandwidth(self, **attrs):
"""Assign bandwidth
Expand Down
14 changes: 14 additions & 0 deletions otcextensions/tests/unit/sdk/vpc/v1/test_proxy.py
Original file line number Diff line number Diff line change
Expand Up @@ -235,3 +235,17 @@ def test_subnet_delete(self):
'ignore_missing': True,
'base_path': subnet.vpc_subnet_base_path('vpc'),
})

class TestExtractName(TestVpcProxy):

def test_extract_name(self):

self.assertEqual(
['vpcs'],
self.proxy._extract_name('/v1/123/vpcs', project_id='123')
)
self.assertEqual(
[],
self.proxy._extract_name(
'/', project_id='123')
)

0 comments on commit 44bfa8f

Please sign in to comment.