Moved parse_image_id() to data_utils
Change-Id: Ifde3ae48d2d988c3f712e0e5aec016b2390960a8
diff --git a/tempest/common/utils/data_utils.py b/tempest/common/utils/data_utils.py
index 2d540f4..752bc10 100644
--- a/tempest/common/utils/data_utils.py
+++ b/tempest/common/utils/data_utils.py
@@ -37,3 +37,10 @@
url += urllib.urlencode(params)
return url
+
+
+def parse_image_id(image_ref):
+ """Return the image id from a given image ref"""
+ temp = image_ref.rsplit('/')
+ #Return the last item, which is the image id
+ return temp[len(temp) - 1]
diff --git a/tempest/tests/test_authorization.py b/tempest/tests/test_authorization.py
index 9f3c34d..e66446d 100644
--- a/tempest/tests/test_authorization.py
+++ b/tempest/tests/test_authorization.py
@@ -4,9 +4,7 @@
from nose.tools import raises
from tempest import openstack
-from tempest.services.nova.json.images_client import ImagesClient
-from tempest.services.nova.json.servers_client import ServersClient
-from tempest.common.utils.data_utils import rand_name
+from tempest.common.utils.data_utils import rand_name, parse_image_id
from tempest import exceptions
from tempest.tests import utils
@@ -53,7 +51,7 @@
name = rand_name('image')
resp, body = cls.client.create_image(server['id'], name)
- image_id = cls._parse_image_id(resp['location'])
+ image_id = parse_image_id(resp['location'])
cls.images_client.wait_for_image_resp_code(image_id, 200)
cls.images_client.wait_for_image_status(image_id, 'ACTIVE')
resp, cls.image = cls.images_client.get_image(image_id)
@@ -162,9 +160,3 @@
finally:
# Reset the base_url...
self.other_client.base_url = saved_base_url
-
- @classmethod
- def _parse_image_id(self, image_ref):
- temp = image_ref.rsplit('/')
- #Return the last item, which is the image id
- return temp[len(temp) - 1]
diff --git a/tempest/tests/test_images.py b/tempest/tests/test_images.py
index 716da65..33020d6 100644
--- a/tempest/tests/test_images.py
+++ b/tempest/tests/test_images.py
@@ -5,11 +5,7 @@
from base_compute_test import BaseComputeTest
import tempest.config
from tempest import openstack
-
-
-def _parse_image_id(image_ref):
- temp = image_ref.rsplit('images/')
- return temp[1]
+from tempest.common.utils import data_utils
class ImagesTest(BaseComputeTest):
@@ -38,7 +34,7 @@
name = rand_name('image')
meta = {'image_type': 'test'}
resp, body = self.client.create_image(server['id'], name, meta)
- image_id = _parse_image_id(resp['location'])
+ image_id = data_utils.parse_image_id(resp['location'])
self.client.wait_for_image_resp_code(image_id, 200)
self.client.wait_for_image_status(image_id, 'ACTIVE')
@@ -78,7 +74,7 @@
pass
else:
- image_id = _parse_image_id(resp['location'])
+ image_id = data_utils.parse_image_id(resp['location'])
self.client.wait_for_image_resp_code(image_id, 200)
self.client.wait_for_image_status(image_id, 'ACTIVE')
self.client.delete_image(image_id)
diff --git a/tempest/tests/test_list_images.py b/tempest/tests/test_list_images.py
index 9d2bb1b..810e933 100644
--- a/tempest/tests/test_list_images.py
+++ b/tempest/tests/test_list_images.py
@@ -1,14 +1,8 @@
from nose.plugins.attrib import attr
from tempest import exceptions
-from tempest import openstack
from base_compute_test import BaseComputeTest
-from tempest.common.utils.data_utils import rand_name
-
-
-def _parse_image_id(image_ref):
- temp = image_ref.rsplit('/')
- return temp[len(temp) - 1]
+from tempest.common.utils.data_utils import rand_name, parse_image_id
class ListImagesTest(BaseComputeTest):
@@ -31,7 +25,7 @@
# Create images to be used in the filter tests
image1_name = rand_name('image')
resp, body = cls.client.create_image(cls.server1['id'], image1_name)
- cls.image1_id = _parse_image_id(resp['location'])
+ cls.image1_id = parse_image_id(resp['location'])
cls.client.wait_for_image_resp_code(cls.image1_id, 200)
cls.client.wait_for_image_status(cls.image1_id, 'ACTIVE')
resp, cls.image1 = cls.client.get_image(cls.image1_id)
@@ -41,14 +35,14 @@
# server will sometimes cause failures
image3_name = rand_name('image')
resp, body = cls.client.create_image(cls.server2['id'], image3_name)
- cls.image3_id = _parse_image_id(resp['location'])
+ cls.image3_id = parse_image_id(resp['location'])
cls.client.wait_for_image_resp_code(cls.image3_id, 200)
cls.client.wait_for_image_status(cls.image3_id, 'ACTIVE')
resp, cls.image3 = cls.client.get_image(cls.image3_id)
image2_name = rand_name('image')
resp, body = cls.client.create_image(cls.server1['id'], image2_name)
- cls.image2_id = _parse_image_id(resp['location'])
+ cls.image2_id = parse_image_id(resp['location'])
cls.client.wait_for_image_resp_code(cls.image2_id, 200)
cls.client.wait_for_image_status(cls.image2_id, 'ACTIVE')
resp, cls.image2 = cls.client.get_image(cls.image2_id)