diff --git a/openstack_dashboard/test/integration_tests/helpers.py b/openstack_dashboard/test/integration_tests/helpers.py index 5c9958a0d5..5710ff70bf 100644 --- a/openstack_dashboard/test/integration_tests/helpers.py +++ b/openstack_dashboard/test/integration_tests/helpers.py @@ -11,6 +11,8 @@ # under the License. import os +import time +import uuid from selenium.webdriver.support import ui import testtools @@ -21,6 +23,25 @@ from openstack_dashboard.test.integration_tests.pages import loginpage from openstack_dashboard.test.integration_tests import webdriver +def gen_random_resource_name(resource="", timestamp=True): + """Generate random resource name using uuid and timestamp. + + Input fields are usually limited to 255 or 80 characters hence their + provide enough space for quite long resource names, but it might be + the case that maximum field length is quite restricted, it is then + necessary to consider using shorter resource argument or avoid using + timestamp by setting timestamp argument to False. + """ + fields = ["horizon"] + if resource: + fields.append(resource) + if timestamp: + tstamp = time.strftime("%d-%m-%H-%M-%S") + fields.append(tstamp) + fields.append(str(uuid.uuid4()).replace("-", "")) + return "_".join(fields) + + class BaseTestCase(testtools.TestCase): def setUp(self): diff --git a/openstack_dashboard/test/integration_tests/tests/test_flavors.py b/openstack_dashboard/test/integration_tests/tests/test_flavors.py index 07525faed9..810cb38dd7 100644 --- a/openstack_dashboard/test/integration_tests/tests/test_flavors.py +++ b/openstack_dashboard/test/integration_tests/tests/test_flavors.py @@ -10,13 +10,11 @@ # License for the specific language governing permissions and limitations # under the License. -import uuid - from openstack_dashboard.test.integration_tests import helpers class TestFlavors(helpers.AdminTestCase): - FLAVOR_NAME = 'horizonflavor_' + str(uuid.uuid4()) + FLAVOR_NAME = helpers.gen_random_resource_name("flavor") def test_flavor_create(self): """tests the flavor creation and deletion functionalities: diff --git a/openstack_dashboard/test/integration_tests/tests/test_image_create_delete.py b/openstack_dashboard/test/integration_tests/tests/test_image_create_delete.py index e22fb888d6..7c82af6899 100644 --- a/openstack_dashboard/test/integration_tests/tests/test_image_create_delete.py +++ b/openstack_dashboard/test/integration_tests/tests/test_image_create_delete.py @@ -10,13 +10,11 @@ # License for the specific language governing permissions and limitations # under the License. -import uuid - from openstack_dashboard.test.integration_tests import helpers class TestImage(helpers.TestCase): - IMAGE_NAME = 'horizonimage_' + str(uuid.uuid4()) + IMAGE_NAME = helpers.gen_random_resource_name("image") def test_image_create_delete(self): """tests the image creation and deletion functionalities: diff --git a/openstack_dashboard/test/integration_tests/tests/test_keypair.py b/openstack_dashboard/test/integration_tests/tests/test_keypair.py index 613d8d075e..45783b19e9 100644 --- a/openstack_dashboard/test/integration_tests/tests/test_keypair.py +++ b/openstack_dashboard/test/integration_tests/tests/test_keypair.py @@ -13,14 +13,12 @@ # License for the specific language governing permissions and limitations # under the License. -import uuid - from openstack_dashboard.test.integration_tests import helpers class TestKeypair(helpers.TestCase): """Checks that the user is able to create/delete keypair.""" - KEYPAIR_NAME = 'horizonkeypair_' + str(uuid.uuid4()) + KEYPAIR_NAME = helpers.gen_random_resource_name("keypair") def test_keypair(self): keypair_page = self.home_pg.go_to_accessandsecurity_keypairspage()