Skip to content

Commit

Permalink
Fix metric naming for the OBS (#172)
Browse files Browse the repository at this point in the history
Fix metric naming for the OBS

Tested with apimon test case

Reviewed-by: Tino Schr <None>
Reviewed-by: None <None>
  • Loading branch information
gtema authored Apr 23, 2021
1 parent 67a1e5c commit b93461e
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 4 deletions.
21 changes: 20 additions & 1 deletion otcextensions/sdk/obs/v1/_proxy.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
from urllib import parse

from otcextensions.sdk import ak_auth
from otcextensions.sdk import sdk_proxy

from otcextensions.sdk.obs.v1 import container as _container
from otcextensions.sdk.obs.v1 import obj as _obj

Expand All @@ -28,6 +28,25 @@ class Proxy(sdk_proxy.Proxy):
CONTAINER_ENDPOINT = \
'https://%(container)s.obs.%(region_name)s.otc.t-systems.com'

def _extract_name(self, url, service_type=None, project_id=None):
url_path = parse.urlparse(url).path.strip()
# Remove / from the beginning to keep the list indexes of interesting
# things consistent
if url_path.startswith('/'):
url_path = url_path[1:]

# Split url into parts and exclude potential project_id in some urls
url_parts = url_path.split('/')

# Strip out anything that's empty or None
parts = [part for part in url_parts if part]

# Getting the root of an endpoint is a bucket operation
if not parts:
return ['bucket']
else:
return ['object']

def get_container_endpoint(self, container):
"""Override to return mapped endpoint if override and region are set
Expand Down
22 changes: 19 additions & 3 deletions otcextensions/tests/unit/sdk/obs/v1/test_proxy.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,8 @@

from openstack.tests.unit import test_proxy_base

from otcextensions.sdk.obs.v1 import _proxy

from otcextensions.sdk.ak_auth import AKRequestsAuth

from otcextensions.sdk.obs.v1 import _proxy
from otcextensions.sdk.obs.v1 import container as _container
from otcextensions.sdk.obs.v1 import obj as _obj

Expand Down Expand Up @@ -183,3 +181,21 @@ def test_delete_object_metadata(self):
self.proxy.delete_object_metadata,
'container',
)


class TestExtractName(TestObsProxy):

def test_extract_name(self):

self.assertEqual(
['bucket'],
self.proxy._extract_name('/', project_id='123')
)
self.assertEqual(
['object'],
self.proxy._extract_name('/dummy', project_id='123')
)
self.assertEqual(
['object'],
self.proxy._extract_name('/dummy/dummy2', project_id='123')
)

0 comments on commit b93461e

Please sign in to comment.