From 23df2650371345f05f75208a9e35d7ca0b6421e4 Mon Sep 17 00:00:00 2001 From: Mark McLoughlin Date: Tue, 17 Jul 2012 04:10:18 +0100 Subject: [PATCH] Remove unused get_{id,version}_from_href() The former is only used in the compute API in Nova to e.g. get an image or flavor ID from a client supplied ref. The latter is unused even in Nova since the removal of the 1.0 API. Change-Id: I4e00ca816820cb51c0ab3d4d864766d981854939 --- cinder/api/openstack/common.py | 33 -------------- cinder/tests/api/openstack/test_common.py | 54 ----------------------- 2 files changed, 87 deletions(-) diff --git a/cinder/api/openstack/common.py b/cinder/api/openstack/common.py index c3e09133e..0ebe610e0 100644 --- a/cinder/api/openstack/common.py +++ b/cinder/api/openstack/common.py @@ -138,19 +138,6 @@ def limited_by_marker(items, request, max_limit=FLAGS.osapi_max_limit): return items[start_index:range_end] -def get_id_from_href(href): - """Return the id or uuid portion of a url. - - Given: 'http://www.foo.com/bar/123?q=4' - Returns: '123' - - Given: 'http://www.foo.com/bar/abc123?q=4' - Returns: 'abc123' - - """ - return urlparse.urlsplit("%s" % href).path.split('/')[-1] - - def remove_version_from_href(href): """Removes the first api version from the href. @@ -181,26 +168,6 @@ def remove_version_from_href(href): return urlparse.urlunsplit(parsed_url) -def get_version_from_href(href): - """Returns the api version in the href. - - Returns the api version in the href. - If no version is found, '2' is returned - - Given: 'http://www.cinder.com/123' - Returns: '2' - - Given: 'http://www.cinder.com/v1.1' - Returns: '1.1' - - """ - try: - expression = r'/v([0-9]+|[0-9]+\.[0-9]+)(/|$)' - return re.findall(expression, href)[0][0] - except IndexError: - return '2' - - def dict_to_query_str(params): # TODO(throughnothing): we should just use urllib.urlencode instead of this # But currently we don't work with urlencoded url's diff --git a/cinder/tests/api/openstack/test_common.py b/cinder/tests/api/openstack/test_common.py index a004ff568..ff153baea 100644 --- a/cinder/tests/api/openstack/test_common.py +++ b/cinder/tests/api/openstack/test_common.py @@ -245,57 +245,3 @@ class MiscFunctionsTest(test.TestCase): self.assertRaises(ValueError, common.remove_version_from_href, fixture) - - def test_get_id_from_href_with_int_url(self): - fixture = 'http://www.testsite.com/dir/45' - actual = common.get_id_from_href(fixture) - expected = '45' - self.assertEqual(actual, expected) - - def test_get_id_from_href_with_int(self): - fixture = '45' - actual = common.get_id_from_href(fixture) - expected = '45' - self.assertEqual(actual, expected) - - def test_get_id_from_href_with_int_url_query(self): - fixture = 'http://www.testsite.com/dir/45?asdf=jkl' - actual = common.get_id_from_href(fixture) - expected = '45' - self.assertEqual(actual, expected) - - def test_get_id_from_href_with_uuid_url(self): - fixture = 'http://www.testsite.com/dir/abc123' - actual = common.get_id_from_href(fixture) - expected = "abc123" - self.assertEqual(actual, expected) - - def test_get_id_from_href_with_uuid_url_query(self): - fixture = 'http://www.testsite.com/dir/abc123?asdf=jkl' - actual = common.get_id_from_href(fixture) - expected = "abc123" - self.assertEqual(actual, expected) - - def test_get_id_from_href_with_uuid(self): - fixture = 'abc123' - actual = common.get_id_from_href(fixture) - expected = 'abc123' - self.assertEqual(actual, expected) - - def test_get_version_from_href(self): - fixture = 'http://www.testsite.com/v1.1/images' - expected = '1.1' - actual = common.get_version_from_href(fixture) - self.assertEqual(actual, expected) - - def test_get_version_from_href_2(self): - fixture = 'http://www.testsite.com/v1.1' - expected = '1.1' - actual = common.get_version_from_href(fixture) - self.assertEqual(actual, expected) - - def test_get_version_from_href_default(self): - fixture = 'http://www.testsite.com/images' - expected = '2' - actual = common.get_version_from_href(fixture) - self.assertEqual(actual, expected) -- 2.45.2