Merge "Move list_hosts to resource_setup in test_hosts_negative"
diff --git a/tempest/api/compute/admin/test_hosts_negative.py b/tempest/api/compute/admin/test_hosts_negative.py
index c270829..3821b22 100644
--- a/tempest/api/compute/admin/test_hosts_negative.py
+++ b/tempest/api/compute/admin/test_hosts_negative.py
@@ -13,7 +13,6 @@
# under the License.
from tempest.api.compute import base
-from tempest.common.utils import data_utils
from tempest.lib import exceptions as lib_exc
from tempest import test
@@ -27,11 +26,13 @@
cls.client = cls.os_adm.hosts_client
cls.non_admin_client = cls.os.hosts_client
- def _get_host_name(self):
- hosts = self.client.list_hosts()['hosts']
- self.assertGreaterEqual(len(hosts), 1)
- hostname = hosts[0]['host_name']
- return hostname
+ @classmethod
+ def resource_setup(cls):
+ super(HostsAdminNegativeTestJSON, cls).resource_setup()
+ hosts = cls.client.list_hosts()['hosts']
+ if not hosts:
+ raise lib_exc.NotFound("no host found")
+ cls.hostname = hosts[0]['host_name']
@test.attr(type=['negative'])
@test.idempotent_id('dd032027-0210-4d9c-860e-69b1b8deed5f')
@@ -42,27 +43,22 @@
@test.attr(type=['negative'])
@test.idempotent_id('e75b0a1a-041f-47a1-8b4a-b72a6ff36d3f')
def test_show_host_detail_with_nonexistent_hostname(self):
- nonexitent_hostname = data_utils.rand_name('rand_hostname')
self.assertRaises(lib_exc.NotFound,
- self.client.show_host, nonexitent_hostname)
+ self.client.show_host, 'nonexistent_hostname')
@test.attr(type=['negative'])
@test.idempotent_id('19ebe09c-bfd4-4b7c-81a2-e2e0710f59cc')
def test_show_host_detail_with_non_admin_user(self):
- hostname = self._get_host_name()
-
self.assertRaises(lib_exc.Forbidden,
self.non_admin_client.show_host,
- hostname)
+ self.hostname)
@test.attr(type=['negative'])
@test.idempotent_id('e40c72b1-0239-4ed6-ba21-81a184df1f7c')
def test_update_host_with_non_admin_user(self):
- hostname = self._get_host_name()
-
self.assertRaises(lib_exc.Forbidden,
self.non_admin_client.update_host,
- hostname,
+ self.hostname,
status='enable',
maintenance_mode='enable')
@@ -70,11 +66,9 @@
@test.idempotent_id('fbe2bf3e-3246-4a95-a59f-94e4e298ec77')
def test_update_host_with_invalid_status(self):
# 'status' can only be 'enable' or 'disable'
- hostname = self._get_host_name()
-
self.assertRaises(lib_exc.BadRequest,
self.client.update_host,
- hostname,
+ self.hostname,
status='invalid',
maintenance_mode='enable')
@@ -82,11 +76,9 @@
@test.idempotent_id('ab1e230e-5e22-41a9-8699-82b9947915d4')
def test_update_host_with_invalid_maintenance_mode(self):
# 'maintenance_mode' can only be 'enable' or 'disable'
- hostname = self._get_host_name()
-
self.assertRaises(lib_exc.BadRequest,
self.client.update_host,
- hostname,
+ self.hostname,
status='enable',
maintenance_mode='invalid')
@@ -94,73 +86,57 @@
@test.idempotent_id('0cd85f75-6992-4a4a-b1bd-d11e37fd0eee')
def test_update_host_without_param(self):
# 'status' or 'maintenance_mode' needed for host update
- hostname = self._get_host_name()
-
self.assertRaises(lib_exc.BadRequest,
self.client.update_host,
- hostname)
+ self.hostname)
@test.attr(type=['negative'])
@test.idempotent_id('23c92146-2100-4d68-b2d6-c7ade970c9c1')
def test_update_nonexistent_host(self):
- nonexitent_hostname = data_utils.rand_name('rand_hostname')
-
self.assertRaises(lib_exc.NotFound,
self.client.update_host,
- nonexitent_hostname,
+ 'nonexistent_hostname',
status='enable',
maintenance_mode='enable')
@test.attr(type=['negative'])
@test.idempotent_id('0d981ac3-4320-4898-b674-82b61fbb60e4')
def test_startup_nonexistent_host(self):
- nonexitent_hostname = data_utils.rand_name('rand_hostname')
-
self.assertRaises(lib_exc.NotFound,
self.client.startup_host,
- nonexitent_hostname)
+ 'nonexistent_hostname')
@test.attr(type=['negative'])
@test.idempotent_id('9f4ebb7e-b2ae-4e5b-a38f-0fd1bb0ddfca')
def test_startup_host_with_non_admin_user(self):
- hostname = self._get_host_name()
-
self.assertRaises(lib_exc.Forbidden,
self.non_admin_client.startup_host,
- hostname)
+ self.hostname)
@test.attr(type=['negative'])
@test.idempotent_id('9e637444-29cf-4244-88c8-831ae82c31b6')
def test_shutdown_nonexistent_host(self):
- nonexitent_hostname = data_utils.rand_name('rand_hostname')
-
self.assertRaises(lib_exc.NotFound,
self.client.shutdown_host,
- nonexitent_hostname)
+ 'nonexistent_hostname')
@test.attr(type=['negative'])
@test.idempotent_id('a803529c-7e3f-4d3c-a7d6-8e1c203d27f6')
def test_shutdown_host_with_non_admin_user(self):
- hostname = self._get_host_name()
-
self.assertRaises(lib_exc.Forbidden,
self.non_admin_client.shutdown_host,
- hostname)
+ self.hostname)
@test.attr(type=['negative'])
@test.idempotent_id('f86bfd7b-0b13-4849-ae29-0322e83ee58b')
def test_reboot_nonexistent_host(self):
- nonexitent_hostname = data_utils.rand_name('rand_hostname')
-
self.assertRaises(lib_exc.NotFound,
self.client.reboot_host,
- nonexitent_hostname)
+ 'nonexistent_hostname')
@test.attr(type=['negative'])
@test.idempotent_id('02d79bb9-eb57-4612-abf6-2cb38897d2f8')
def test_reboot_host_with_non_admin_user(self):
- hostname = self._get_host_name()
-
self.assertRaises(lib_exc.Forbidden,
self.non_admin_client.reboot_host,
- hostname)
+ self.hostname)