Merge "Move share code to _create_server_with_group"
diff --git a/tempest/api/compute/admin/test_servers_on_multinodes.py b/tempest/api/compute/admin/test_servers_on_multinodes.py
index 18c974a..d32a5b4 100644
--- a/tempest/api/compute/admin/test_servers_on_multinodes.py
+++ b/tempest/api/compute/admin/test_servers_on_multinodes.py
@@ -43,6 +43,28 @@
return cls.os_admin.servers_client.show_server(
server_id)['server']['OS-EXT-SRV-ATTR:host']
+ def _create_servers_with_group(self, policy):
+ group_id = self.create_test_server_group(policy=[policy])['id']
+ hints = {'group': group_id}
+ reservation_id = self.create_test_server(
+ scheduler_hints=hints, wait_until='ACTIVE', min_count=2,
+ return_reservation_id=True)['reservation_id']
+
+ # Get the servers using the reservation_id.
+ servers = self.servers_client.list_servers(
+ detail=True, reservation_id=reservation_id)['servers']
+ self.assertEqual(2, len(servers))
+
+ # Assert the servers are in the group.
+ server_group = self.server_groups_client.show_server_group(
+ group_id)['server_group']
+ hosts = {}
+ for server in servers:
+ self.assertIn(server['id'], server_group['members'])
+ hosts[server['id']] = self._get_host(server['id'])
+
+ return hosts
+
@decorators.idempotent_id('26a9d5df-6890-45f2-abc4-a659290cb130')
@testtools.skipUnless(
compute.is_scheduler_filter_enabled("SameHostFilter"),
@@ -87,28 +109,8 @@
Creates two servers in an anti-affinity server group and
asserts the servers are in the group and on different hosts.
"""
- group_id = self.create_test_server_group(
- policy=['anti-affinity'])['id']
- hints = {'group': group_id}
- reservation_id = self.create_test_server(
- scheduler_hints=hints, wait_until='ACTIVE', min_count=2,
- return_reservation_id=True)['reservation_id']
-
- # Get the servers using the reservation_id.
- servers = self.servers_client.list_servers(
- detail=True, reservation_id=reservation_id)['servers']
- self.assertEqual(2, len(servers))
-
- # Assert the servers are in the group.
- server_group = self.server_groups_client.show_server_group(
- group_id)['server_group']
- hosts = {}
- for server in servers:
- self.assertIn(server['id'], server_group['members'])
- hosts[server['id']] = self._get_host(server['id'])
-
- # Assert the servers are on different hosts.
- hostnames = list(hosts.values())
+ hosts = self._create_servers_with_group('anti-affinity')
+ hostnames = hosts.values()
self.assertNotEqual(hostnames[0], hostnames[1],
'Servers are on the same host: %s' % hosts)
@@ -122,26 +124,7 @@
Creates two servers in an affinity server group and
asserts the servers are in the group and on same host.
"""
- group_id = self.create_test_server_group(policy=['affinity'])['id']
- hints = {'group': group_id}
- reservation_id = self.create_test_server(
- scheduler_hints=hints, wait_until='ACTIVE', min_count=2,
- return_reservation_id=True)['reservation_id']
-
- # Get the servers using the reservation_id.
- servers = self.servers_client.list_servers(
- detail=True, reservation_id=reservation_id)['servers']
- self.assertEqual(2, len(servers))
-
- # Assert the servers are in the group.
- server_group = self.server_groups_client.show_server_group(
- group_id)['server_group']
- hosts = {}
- for server in servers:
- self.assertIn(server['id'], server_group['members'])
- hosts[server['id']] = self._get_host(server['id'])
-
- # Assert the servers are on same host.
+ hosts = self._create_servers_with_group('affinity')
hostnames = hosts.values()
self.assertEqual(hostnames[0], hostnames[1],
'Servers are on the different hosts: %s' % hosts)