Merge "create_server cleanup"
diff --git a/tempest/tests/compute/base.py b/tempest/tests/compute/base.py
index 2e5b4fe..94fff13 100644
--- a/tempest/tests/compute/base.py
+++ b/tempest/tests/compute/base.py
@@ -173,36 +173,21 @@
cls.clear_isolated_creds()
@classmethod
- def create_server(cls, image_id=None, flavor=None):
+ def create_server(cls, **kwargs):
"""Wrapper utility that returns a test server."""
- server_name = rand_name(cls.__name__ + "-instance")
-
- if not flavor:
- flavor = cls.flavor_ref
- if not image_id:
- image_id = cls.image_ref
+ name = rand_name(cls.__name__ + "-instance")
+ if 'name' in kwargs:
+ name = kwargs.pop('name')
+ flavor = kwargs.get('flavor', cls.flavor_ref)
+ image_id = kwargs.get('image_id', cls.image_ref)
resp, server = cls.servers_client.create_server(
- server_name, image_id, flavor)
- cls.servers_client.wait_for_server_status(server['id'], 'ACTIVE')
- cls.servers.append(server)
- return server
+ name, image_id, flavor, **kwargs)
- @classmethod
- def create_server_with_extras(cls, name, image_id=None,
- flavor=None, **kwargs):
- # TODO(sdague) transitional function because many
- # server tests were using extra args and resp so can't
- # easily be ported to create_server. Will be merged
- # later
- if not flavor:
- flavor = cls.flavor_ref
- if not image_id:
- image_id = cls.image_ref
+ if 'wait_until' in kwargs:
+ cls.servers_client.wait_for_server_status(
+ server['id'], kwargs['wait_until'])
- resp, server = cls.servers_client.create_server(name,
- image_id, flavor,
- **kwargs)
cls.servers.append(server)
return resp, server
diff --git a/tempest/tests/compute/images/test_images.py b/tempest/tests/compute/images/test_images.py
index d8d38aa..1e90202 100644
--- a/tempest/tests/compute/images/test_images.py
+++ b/tempest/tests/compute/images/test_images.py
@@ -51,12 +51,6 @@
def tearDown(self):
"""Terminate test instances created after a test is executed."""
- for server in self.servers:
- resp, body = self.servers_client.delete_server(server['id'])
- if resp['status'] == '204':
- self.servers.remove(server)
- self.servers_client.wait_for_server_termination(server['id'])
-
for image_id in self.image_ids:
self.client.delete_image(image_id)
self.image_ids.remove(image_id)
@@ -65,11 +59,7 @@
@attr(type='negative')
def test_create_image_from_deleted_server(self):
# An image should not be created if the server instance is removed
- server_name = rand_name('server')
- resp, server = self.servers_client.create_server(server_name,
- self.image_ref,
- self.flavor_ref)
- self.servers_client.wait_for_server_status(server['id'], 'ACTIVE')
+ resp, server = self.create_server(wait_until='ACTIVE')
# Delete server before trying to create server
self.servers_client.delete_server(server['id'])
@@ -114,7 +104,7 @@
@attr(type='negative')
def test_create_image_when_server_is_terminating(self):
# Return an error when creating image of server that is terminating
- server = self.create_server()
+ resp, server = self.create_server(wait_until='ACTIVE')
self.servers_client.delete_server(server['id'])
snapshot_name = rand_name('test-snap-')
@@ -124,11 +114,7 @@
@attr(type='negative')
def test_create_image_when_server_is_building(self):
# Return error when creating an image of a server that is building
- server_name = rand_name('test-vm-')
- resp, server = self.servers_client.create_server(server_name,
- self.image_ref,
- self.flavor_ref)
- self.servers.append(server)
+ resp, server = self.create_server(wait_until='BUILD')
snapshot_name = rand_name('test-snap-')
self.assertRaises(exceptions.Duplicate, self.client.create_image,
server['id'], snapshot_name)
@@ -137,7 +123,7 @@
@attr(type='negative')
def test_create_image_when_server_is_rebooting(self):
# Return error when creating an image of server that is rebooting
- server = self.create_server()
+ resp, server = self.create_server()
self.servers_client.reboot(server['id'], 'HARD')
snapshot_name = rand_name('test-snap-')
diff --git a/tempest/tests/compute/images/test_images_oneserver.py b/tempest/tests/compute/images/test_images_oneserver.py
index 34ea868..6d3f043 100644
--- a/tempest/tests/compute/images/test_images_oneserver.py
+++ b/tempest/tests/compute/images/test_images_oneserver.py
@@ -41,7 +41,7 @@
super(ImagesOneServerTestJSON, cls).setUpClass()
cls.client = cls.images_client
cls.servers_client = cls.servers_client
- cls.server = cls.create_server()
+ resp, cls.server = cls.create_server(wait_until='ACTIVE')
cls.image_ids = []
diff --git a/tempest/tests/compute/images/test_list_image_filters.py b/tempest/tests/compute/images/test_list_image_filters.py
index 56f388d..5038a65 100644
--- a/tempest/tests/compute/images/test_list_image_filters.py
+++ b/tempest/tests/compute/images/test_list_image_filters.py
@@ -30,16 +30,10 @@
super(ListImageFiltersTest, cls).setUpClass()
cls.client = cls.images_client
- name = rand_name('server')
- resp, cls.server1 = cls.servers_client.create_server(name,
- cls.image_ref,
- cls.flavor_ref)
- name = rand_name('server')
- resp, cls.server2 = cls.servers_client.create_server(name,
- cls.image_ref,
- cls.flavor_ref)
+ resp, cls.server1 = cls.create_server()
+ resp, cls.server2 = cls.create_server(wait_until='ACTIVE')
+ # NOTE(sdague) this is faster than doing the sync wait_util on both
cls.servers_client.wait_for_server_status(cls.server1['id'], 'ACTIVE')
- cls.servers_client.wait_for_server_status(cls.server2['id'], 'ACTIVE')
# Create images to be used in the filter tests
image1_name = rand_name('image')
@@ -71,8 +65,6 @@
cls.client.delete_image(cls.image1_id)
cls.client.delete_image(cls.image2_id)
cls.client.delete_image(cls.image3_id)
- cls.servers_client.delete_server(cls.server1['id'])
- cls.servers_client.delete_server(cls.server2['id'])
super(ListImageFiltersTest, cls).tearDownClass()
@attr(type='negative')
diff --git a/tempest/tests/compute/servers/test_disk_config.py b/tempest/tests/compute/servers/test_disk_config.py
index 671abf9..3a1ec20 100644
--- a/tempest/tests/compute/servers/test_disk_config.py
+++ b/tempest/tests/compute/servers/test_disk_config.py
@@ -37,14 +37,8 @@
@attr(type='positive')
def test_rebuild_server_with_manual_disk_config(self):
# A server should be rebuilt using the manual disk config option
- name = rand_name('server')
- resp, server = self.create_server_with_extras(name,
- self.image_ref,
- self.flavor_ref,
- disk_config='AUTO')
-
- #Wait for the server to become active
- self.client.wait_for_server_status(server['id'], 'ACTIVE')
+ resp, server = self.create_server(disk_config='AUTO',
+ wait_until='ACTIVE')
#Verify the specified attributes are set correctly
resp, server = self.client.get_server(server['id'])
@@ -67,14 +61,8 @@
@attr(type='positive')
def test_rebuild_server_with_auto_disk_config(self):
# A server should be rebuilt using the auto disk config option
- name = rand_name('server')
- resp, server = self.create_server_with_extras(name,
- self.image_ref,
- self.flavor_ref,
- disk_config='MANUAL')
-
- #Wait for the server to become active
- self.client.wait_for_server_status(server['id'], 'ACTIVE')
+ resp, server = self.create_server(disk_config='MANUAL',
+ wait_until='ACTIVE')
#Verify the specified attributes are set correctly
resp, server = self.client.get_server(server['id'])
@@ -98,14 +86,8 @@
@testtools.skipUnless(compute.RESIZE_AVAILABLE, 'Resize not available.')
def test_resize_server_from_manual_to_auto(self):
# A server should be resized from manual to auto disk config
- name = rand_name('server')
- resp, server = self.create_server_with_extras(name,
- self.image_ref,
- self.flavor_ref,
- disk_config='MANUAL')
-
- #Wait for the server to become active
- self.client.wait_for_server_status(server['id'], 'ACTIVE')
+ resp, server = self.create_server(disk_config='MANUAL',
+ wait_until='ACTIVE')
#Resize with auto option
self.client.resize(server['id'], self.flavor_ref_alt,
@@ -124,14 +106,8 @@
@testtools.skipUnless(compute.RESIZE_AVAILABLE, 'Resize not available.')
def test_resize_server_from_auto_to_manual(self):
# A server should be resized from auto to manual disk config
- name = rand_name('server')
- resp, server = self.create_server_with_extras(name,
- self.image_ref,
- self.flavor_ref,
- disk_config='AUTO')
-
- #Wait for the server to become active
- self.client.wait_for_server_status(server['id'], 'ACTIVE')
+ resp, server = self.create_server(disk_config='AUTO',
+ wait_until='ACTIVE')
#Resize with manual option
self.client.resize(server['id'], self.flavor_ref_alt,
diff --git a/tempest/tests/compute/servers/test_list_servers_negative.py b/tempest/tests/compute/servers/test_list_servers_negative.py
index 320f920..01b11e0 100644
--- a/tempest/tests/compute/servers/test_list_servers_negative.py
+++ b/tempest/tests/compute/servers/test_list_servers_negative.py
@@ -78,10 +78,10 @@
cls.existing_fixtures = []
cls.deleted_fixtures = []
for x in xrange(2):
- srv = cls.create_server()
+ resp, srv = cls.create_server()
cls.existing_fixtures.append(srv)
- srv = cls.create_server()
+ resp, srv = cls.create_server()
cls.client.delete_server(srv['id'])
# We ignore errors on termination because the server may
# be put into ERROR status on a quick spawn, then delete,
diff --git a/tempest/tests/compute/servers/test_server_actions.py b/tempest/tests/compute/servers/test_server_actions.py
index bc8e843..5046ec2 100644
--- a/tempest/tests/compute/servers/test_server_actions.py
+++ b/tempest/tests/compute/servers/test_server_actions.py
@@ -257,13 +257,9 @@
def rebuild_servers(cls):
# Destroy any existing server and creates a new one
cls.clear_servers()
- cls.name = rand_name('server')
- resp, server = cls.create_server_with_extras(cls.name,
- cls.image_ref,
- cls.flavor_ref)
+ resp, server = cls.create_server(wait_until='ACTIVE')
cls.server_id = server['id']
cls.password = server['adminPass']
- cls.client.wait_for_server_status(cls.server_id, 'ACTIVE')
class ServerActionsTestXML(ServerActionsTestJSON):
diff --git a/tempest/tests/compute/servers/test_server_metadata.py b/tempest/tests/compute/servers/test_server_metadata.py
index cdfe2f1..4b17fa2 100644
--- a/tempest/tests/compute/servers/test_server_metadata.py
+++ b/tempest/tests/compute/servers/test_server_metadata.py
@@ -83,11 +83,9 @@
for sz in [256, 257, 511, 1023]:
key = "k" * sz
meta = {key: 'data1'}
- name = rand_name('server')
self.assertRaises(exceptions.OverLimit,
- self.create_server_with_extras,
- name, self.image_ref,
- self.flavor_ref, meta=meta)
+ self.create_server,
+ meta=meta)
# no teardown - all creates should fail
@@ -95,11 +93,9 @@
def test_create_metadata_key_error(self):
# Blank key should trigger an error.
meta = {'': 'data1'}
- name = rand_name('server')
self.assertRaises(exceptions.BadRequest,
- self.create_server_with_extras,
- name, self.image_ref,
- self.flavor_ref, meta=meta)
+ self.create_server,
+ meta=meta)
def test_update_server_metadata(self):
# The server's metadata values should be updated to the
diff --git a/tempest/tests/compute/servers/test_server_personality.py b/tempest/tests/compute/servers/test_server_personality.py
index 816ca76..0bafc2c 100644
--- a/tempest/tests/compute/servers/test_server_personality.py
+++ b/tempest/tests/compute/servers/test_server_personality.py
@@ -35,7 +35,6 @@
def test_personality_files_exceed_limit(self):
# Server creation should fail if greater than the maximum allowed
# number of files are injected into the server.
- name = rand_name('server')
file_contents = 'This is a test file.'
personality = []
max_file_limit = \
@@ -45,9 +44,7 @@
personality.append({'path': path,
'contents': base64.b64encode(file_contents)})
try:
- self.create_server_with_extras(name, self.image_ref,
- self.flavor_ref,
- personality=personality)
+ self.create_server(personality=personality)
except exceptions.OverLimit:
pass
else:
@@ -58,7 +55,6 @@
# Server should be created successfully if maximum allowed number of
# files is injected into the server during creation.
try:
- name = rand_name('server')
file_contents = 'This is a test file.'
max_file_limit = \
@@ -71,9 +67,7 @@
'path': path,
'contents': base64.b64encode(file_contents),
})
- resp, server = self.create_server_with_extras(name, self.image_ref,
- self.flavor_ref,
- personality=person)
+ resp, server = self.create_server(personality=person)
self.assertEqual('202', resp['status'])
#Teardown
diff --git a/tempest/tests/compute/servers/test_servers.py b/tempest/tests/compute/servers/test_servers.py
index a912652..a8d28df 100644
--- a/tempest/tests/compute/servers/test_servers.py
+++ b/tempest/tests/compute/servers/test_servers.py
@@ -35,11 +35,7 @@
try:
server = None
- name = rand_name('server')
- resp, server = self.create_server_with_extras(name, self.image_ref,
- self.flavor_ref,
- adminPass='test'
- 'password')
+ resp, server = self.create_server(adminPass='testpassword')
#Verify the password is set correctly in the response
self.assertEqual('testpassword', server['adminPass'])
@@ -52,19 +48,16 @@
def test_create_with_existing_server_name(self):
# Creating a server with a name that already exists is allowed
+ # TODO(sdague): clear out try, we do cleanup one layer up
try:
id1 = None
id2 = None
server_name = rand_name('server')
- resp, server = self.create_server_with_extras(server_name,
- self.image_ref,
- self.flavor_ref)
- self.client.wait_for_server_status(server['id'], 'ACTIVE')
+ resp, server = self.create_server(name=server_name,
+ wait_until='ACTIVE')
id1 = server['id']
- resp, server = self.create_server_with_extras(server_name,
- self.image_ref,
- self.flavor_ref)
- self.client.wait_for_server_status(server['id'], 'ACTIVE')
+ resp, server = self.create_server(name=server_name,
+ wait_until='ACTIVE')
id2 = server['id']
self.assertNotEqual(id1, id2, "Did not create a new server")
resp, server = self.client.get_server(id1)
@@ -86,11 +79,7 @@
key_name = rand_name('key')
resp, keypair = self.keypairs_client.create_keypair(key_name)
resp, body = self.keypairs_client.list_keypairs()
- server_name = rand_name('server')
- resp, server = self.create_server_with_extras(server_name,
- self.image_ref,
- self.flavor_ref,
- key_name=key_name)
+ resp, server = self.create_server(key_name=key_name)
self.assertEqual('202', resp['status'])
self.client.wait_for_server_status(server['id'], 'ACTIVE')
resp, server = self.client.get_server(server['id'])
@@ -104,10 +93,7 @@
# The server name should be changed to the the provided value
try:
server = None
- name = rand_name('server')
- resp, server = self.create_server_with_extras(name, self.image_ref,
- self.flavor_ref)
- self.client.wait_for_server_status(server['id'], 'ACTIVE')
+ resp, server = self.create_server(wait_until='ACTIVE')
#Update the server with a new name
resp, server = self.client.update_server(server['id'],
@@ -129,10 +115,7 @@
# The server's access addresses should reflect the provided values
try:
server = None
- name = rand_name('server')
- resp, server = self.create_server_with_extras(name, self.image_ref,
- self.flavor_ref)
- self.client.wait_for_server_status(server['id'], 'ACTIVE')
+ resp, server = self.create_server(wait_until='ACTIVE')
#Update the IPv4 and IPv6 access addresses
resp, body = self.client.update_server(server['id'],
@@ -153,10 +136,7 @@
def test_delete_server_while_in_building_state(self):
# Delete a server while it's VM state is Building
- name = rand_name('server')
- resp, server = self.create_server_with_extras(name, self.image_ref,
- self.flavor_ref)
- self.client.wait_for_server_status(server['id'], 'BUILD')
+ resp, server = self.create_server(wait_until='BUILD')
resp, _ = self.client.delete_server(server['id'])
self.assertEqual('204', resp['status'])
diff --git a/tempest/tests/compute/servers/test_servers_negative.py b/tempest/tests/compute/servers/test_servers_negative.py
index 80358ec..366b630 100644
--- a/tempest/tests/compute/servers/test_servers_negative.py
+++ b/tempest/tests/compute/servers/test_servers_negative.py
@@ -41,8 +41,8 @@
# Create a server with name parameter empty
self.assertRaises(exceptions.BadRequest,
- self.create_server_with_extras,
- '', self.image_ref, self.flavor_ref)
+ self.create_server,
+ name='')
@attr(type='negative')
def test_personality_file_contents_not_encoded(self):
@@ -53,8 +53,7 @@
'contents': file_contents}]
self.assertRaises(exceptions.BadRequest,
- self.create_server_with_extras,
- 'fail', self.image_ref, self.flavor_ref,
+ self.create_server,
personality=person)
@attr(type='negative')
@@ -62,16 +61,16 @@
# Create a server with an unknown image
self.assertRaises(exceptions.BadRequest,
- self.create_server_with_extras,
- 'fail', -1, self.flavor_ref)
+ self.create_server,
+ image_id=-1)
@attr(type='negative')
def test_create_with_invalid_flavor(self):
# Create a server with an unknown flavor
self.assertRaises(exceptions.BadRequest,
- self.create_server_with_extras,
- 'fail', self.image_ref, -1)
+ self.create_server,
+ flavor=-1,)
@attr(type='negative')
def test_invalid_access_ip_v4_address(self):
@@ -79,8 +78,7 @@
IPv4 = '1.1.1.1.1.1'
self.assertRaises(exceptions.BadRequest,
- self.create_server_with_extras, "fail",
- self.image_ref, self.flavor_ref, accessIPv4=IPv4)
+ self.create_server, accessIPv4=IPv4)
@attr(type='negative')
def test_invalid_ip_v6_address(self):
@@ -89,18 +87,13 @@
IPv6 = 'notvalid'
self.assertRaises(exceptions.BadRequest,
- self.create_server_with_extras, "fail",
- self.image_ref, self.flavor_ref, accessIPv6=IPv6)
+ self.create_server, accessIPv6=IPv6)
@attr(type='negative')
def test_reboot_deleted_server(self):
# Reboot a deleted server
-
- self.name = rand_name('server')
- resp, create_server = self.create_server_with_extras(self.name,
- self.image_ref,
- self.flavor_ref)
- self.server_id = create_server['id']
+ resp, server = self.create_server()
+ self.server_id = server['id']
self.client.delete_server(self.server_id)
self.client.wait_for_server_termination(self.server_id)
self.assertRaises(exceptions.NotFound, self.client.reboot,
@@ -110,11 +103,8 @@
def test_rebuild_deleted_server(self):
# Rebuild a deleted server
- self.name = rand_name('server')
- resp, create_server = self.create_server_with_extras(self.name,
- self.image_ref,
- self.flavor_ref)
- self.server_id = create_server['id']
+ resp, server = self.create_server()
+ self.server_id = server['id']
self.client.delete_server(self.server_id)
self.client.wait_for_server_termination(self.server_id)
@@ -128,8 +118,8 @@
server_name = 12345
self.assertRaises(exceptions.BadRequest,
- self.create_server_with_extras,
- server_name, self.image_ref, self.flavor_ref)
+ self.create_server,
+ name=server_name)
@attr(type='negative')
def test_create_server_name_length_exceeds_256(self):
@@ -137,19 +127,17 @@
server_name = 'a' * 256
self.assertRaises(exceptions.BadRequest,
- self.create_server_with_extras,
- server_name, self.image_ref, self.flavor_ref)
+ self.create_server,
+ name=server_name)
@attr(type='negative')
def test_create_with_invalid_network_uuid(self):
# Pass invalid network uuid while creating a server
- server_name = rand_name('server')
networks = [{'fixed_ip': '10.0.1.1', 'uuid': 'a-b-c-d-e-f-g-h-i-j'}]
self.assertRaises(exceptions.BadRequest,
- self.create_server_with_extras,
- server_name, self.image_ref, self.flavor_ref,
+ self.create_server,
networks=networks)
@attr(type='negative')
@@ -157,21 +145,17 @@
# Pass a non existant keypair while creating a server
key_name = rand_name('key')
- server_name = rand_name('server')
self.assertRaises(exceptions.BadRequest,
- self.create_server_with_extras,
- server_name, self.image_ref, self.flavor_ref,
+ self.create_server,
key_name=key_name)
@attr(type='negative')
def test_create_server_metadata_exceeds_length_limit(self):
# Pass really long metadata while creating a server
- server_name = rand_name('server')
metadata = {'a': 'b' * 260}
self.assertRaises(exceptions.OverLimit,
- self.create_server_with_extras,
- server_name, self.image_ref, self.flavor_ref,
+ self.create_server,
meta=metadata)
@attr(type='negative')
@@ -252,8 +236,7 @@
security_groups = [{'name': 'does_not_exist'}]
self.assertRaises(exceptions.BadRequest,
- self.create_server_with_extras, 'fail',
- self.image_ref, self.flavor_ref,
+ self.create_server,
security_groups=security_groups)
@attr(type='negative')