Do not create server in test_list_servers_filter_by_exist_host

In test_list_servers_filter_by_exist_host, a server is created
using admin user, but in fact, we need not create that server,
instead, we can use the server created in resource_setup, because
admin user can list servers created by non-admin user.

This is to use the server created in resource_setup, both to make
the testcase faster and to make the code cleaner.

Change-Id: I89d0cdd31f26748f1364cfa57a80984566b3f850
This commit is contained in:
zhufl 2017-08-11 13:55:25 +08:00
parent 9619b9818f
commit 6491738fdc

View File

@ -13,9 +13,7 @@
# under the License.
from tempest.api.compute import base
from tempest.common import compute
from tempest.common import waiters
from tempest.lib.common import fixed_network
from tempest.lib.common.utils import data_utils
from tempest.lib import decorators
@ -126,26 +124,17 @@ class ServersAdminTestJSON(base.BaseV2ComputeAdminTest):
@decorators.idempotent_id('86c7a8f7-50cf-43a9-9bac-5b985317134f')
def test_list_servers_filter_by_exist_host(self):
# Filter the list of servers by existent host
name = data_utils.rand_name(self.__class__.__name__ + '-server')
network = self.get_tenant_network()
network_kwargs = fixed_network.set_networks_kwarg(network)
# We need to create the server as an admin, so we can't use
# self.create_test_server() here as this method creates the server
# in the "primary" (i.e non-admin) tenant.
test_server, _ = compute.create_test_server(
self.os_admin, wait_until="ACTIVE", name=name, **network_kwargs)
self.addCleanup(self.client.delete_server, test_server['id'])
server = self.client.show_server(test_server['id'])['server']
self.assertEqual(server['status'], 'ACTIVE')
server = self.client.show_server(self.s1_id)['server']
hostname = server['OS-EXT-SRV-ATTR:host']
params = {'host': hostname}
body = self.client.list_servers(**params)
servers = body['servers']
nonexistent_params = {'host': 'nonexistent_host'}
params = {'host': hostname, 'all_tenants': '1'}
servers = self.client.list_servers(**params)['servers']
self.assertIn(server['id'], map(lambda x: x['id'], servers))
nonexistent_params = {'host': 'nonexistent_host',
'all_tenants': '1'}
nonexistent_body = self.client.list_servers(**nonexistent_params)
nonexistent_servers = nonexistent_body['servers']
self.assertIn(test_server['id'], map(lambda x: x['id'], servers))
self.assertNotIn(test_server['id'],
self.assertNotIn(server['id'],
map(lambda x: x['id'], nonexistent_servers))
@decorators.idempotent_id('ee8ae470-db70-474d-b752-690b7892cab1')