Pull in changes from stacktester.
diff --git a/kong/tests/test_flavors.py b/kong/tests/test_flavors.py
index 0fb3258..73b70a9 100644
--- a/kong/tests/test_flavors.py
+++ b/kong/tests/test_flavors.py
@@ -46,13 +46,11 @@
flavor_id = str(flavor['id'])
host = self.os.config.nova.host
port = self.os.config.nova.port
- api_url = '%s:%s' % (host, port)
- base_url = os.path.join(api_url, self.os.config.nova.base_url,
- self.os.config.nova.project_id)
- api_url = os.path.join(api_url, self.os.config.nova.project_id)
+ mgmt_url = self.os.nova.management_url
+ bmk_url = re.sub(r'v1.1\/', r'', mgmt_url)
- self_link = 'http://' + os.path.join(base_url, 'flavors', flavor_id)
- bookmark_link = 'http://' + os.path.join(api_url, 'flavors', flavor_id)
+ self_link = os.path.join(mgmt_url, 'flavors', flavor_id)
+ bookmark_link = os.path.join(bmk_url, 'flavors', flavor_id)
expected_links = [
{
diff --git a/kong/tests/test_images.py b/kong/tests/test_images.py
index 0b43182..7d2c9ce 100644
--- a/kong/tests/test_images.py
+++ b/kong/tests/test_images.py
@@ -11,23 +11,14 @@
super(ImagesTest, self).setUp()
self.os = openstack.Manager(self.nova)
- host = self.os.config.nova.host
- port = self.os.config.nova.port
- self.base_url = '%s:%s' % (host, port)
- self.api_url = os.path.join(self.base_url, self.os.config.nova.base_url)
-
- def tearDown(self):
- pass
-
def _assert_image_links(self, image):
image_id = str(image['id'])
- self_link = 'http://' + os.path.join(self.api_url,
- self.os.config.nova.project_id,
- 'images', image_id)
- bookmark_link = 'http://' + os.path.join(self.base_url,
- self.os.config.nova.project_id,
- 'images', image_id)
+ mgmt_url = self.os.nova.management_url
+ bmk_url = re.sub(r'v1.1\/', r'', mgmt_url)
+
+ self_link = os.path.join(mgmt_url, 'images', image_id)
+ bookmark_link = os.path.join(bmk_url, 'images', image_id)
expected_links = [
{
diff --git a/kong/tests/test_server_actions.py b/kong/tests/test_server_actions.py
index e2190cf..f995c67 100644
--- a/kong/tests/test_server_actions.py
+++ b/kong/tests/test_server_actions.py
@@ -23,21 +23,22 @@
self.flavor_ref = self.os.config.env.flavor_ref
self.flavor_ref_alt = self.os.config.env.flavor_ref_alt
self.ssh_timeout = self.os.config.nova.ssh_timeout
+ self.build_timeout = self.os.config.nova.build_timeout
self.server_password = 'testpwd'
- self.server_name = 'testserver'
+ self.server_name = 'stacktester1'
expected_server = {
- 'name' : self.server_name,
- 'imageRef' : self.image_ref,
- 'flavorRef' : self.flavor_ref,
- 'adminPass' : self.server_password,
+ 'name': self.server_name,
+ 'imageRef': self.image_ref,
+ 'flavorRef': self.flavor_ref,
+ 'adminPass': self.server_password,
}
created_server = self.os.nova.create_server(expected_server)
self.server_id = created_server['id']
- self._wait_for_status(self.server_id, 'ACTIVE')
+ self._wait_for_server_status(self.server_id, 'ACTIVE')
server = self.os.nova.get_server(self.server_id)
@@ -59,9 +60,10 @@
client = self._get_ssh_client(_password)
self.assertTrue(client.test_connection_auth())
- def _wait_for_status(self, server_id, status):
+ def _wait_for_server_status(self, server_id, status):
try:
- self.os.nova.wait_for_server_status(server_id, status)
+ self.os.nova.wait_for_server_status(server_id, status,
+ timeout=self.build_timeout)
except exceptions.TimeoutException:
self.fail("Server failed to change status to %s" % status)
@@ -71,14 +73,18 @@
uptime = float(output.split().pop(0))
return time.time() - uptime
- def _write_file(self, filename, contents):
- return self._exec_command("echo -n %s > %s" % (contents, filename))
+ def _write_file(self, filename, contents, password=None):
+ command = "echo -n %s > %s" % (contents, filename)
+ return self._exec_command(command, password)
- def _read_file(self, filename):
- return self._exec_command("cat %s" % filename)
+ def _read_file(self, filename, password=None):
+ command = "cat %s" % filename
+ return self._exec_command(command, password)
- def _exec_command(self, command):
- client = self._get_ssh_client(self.server_password)
+ def _exec_command(self, command, password=None):
+ if password is None:
+ password = self.server_password
+ client = self._get_ssh_client(password)
return client.exec_command(command)
def test_reboot_server_soft(self):
@@ -88,21 +94,17 @@
initial_time_started = self._get_boot_time()
# Make reboot request
- post_body = json.dumps({
- 'reboot' : {
- 'type' : 'SOFT',
- }
- })
+ post_body = json.dumps({'reboot': {'type': 'SOFT'}})
url = "/servers/%s/action" % self.server_id
response, body = self.os.nova.request('POST', url, body=post_body)
self.assertEqual(response['status'], '202')
# Assert status transition
# KNOWN-ISSUE
- #self.os.nova.wait_for_server_status(self.server_id, 'REBOOT')
+ #self._wait_for_server_status(self.server_id, 'REBOOT')
ssh_client = self._get_ssh_client(self.server_password)
ssh_client.connect_until_closed()
- self.os.nova.wait_for_server_status(self.server_id, 'ACTIVE')
+ self._wait_for_server_status(self.server_id, 'ACTIVE')
# SSH and verify uptime is less than before
post_reboot_time_started = self._get_boot_time()
@@ -115,21 +117,17 @@
initial_time_started = self._get_boot_time()
# Make reboot request
- post_body = json.dumps({
- 'reboot' : {
- 'type' : 'HARD',
- }
- })
+ post_body = json.dumps({'reboot': {'type': 'HARD'}})
url = "/servers/%s/action" % self.server_id
response, body = self.os.nova.request('POST', url, body=post_body)
self.assertEqual(response['status'], '202')
# Assert status transition
# KNOWN-ISSUE
- #self.os.nova.wait_for_server_status(self.server_id, 'HARD_REBOOT')
+ #self._wait_for_server_status(self.server_id, 'HARD_REBOOT')
ssh_client = self._get_ssh_client(self.server_password)
ssh_client.connect_until_closed()
- self.os.nova.wait_for_server_status(self.server_id, 'ACTIVE')
+ self._wait_for_server_status(self.server_id, 'ACTIVE')
# SSH and verify uptime is less than before
post_reboot_time_started = self._get_boot_time()
@@ -142,46 +140,44 @@
self._assert_ssh_password()
# Change server password
- post_body = json.dumps({
- 'changePassword' : {
- 'adminPass' : 'test123',
- }
- })
+ post_body = json.dumps({'changePassword': {'adminPass': 'test123'}})
url = '/servers/%s/action' % self.server_id
response, body = self.os.nova.request('POST', url, body=post_body)
# Assert status transition
self.assertEqual('202', response['status'])
# KNOWN-ISSUE
- #self.os.nova.wait_for_server_status(self.server_id, 'PASSWORD')
- self.os.nova.wait_for_server_status(self.server_id, 'ACTIVE')
+ self._wait_for_server_status(self.server_id, 'PASSWORD')
+ self._wait_for_server_status(self.server_id, 'ACTIVE')
# SSH into server using new password
self._assert_ssh_password('test123')
- def test_rebuild_server(self):
+ def test_rebuild(self):
"""Rebuild a server"""
- filename = '/tmp/testfile'
- contents = 'WORDS'
- self._write_file(filename, contents)
- self.assertEqual(self._read_file(filename), contents)
+ FILENAME = '/tmp/testfile'
+ CONTENTS = 'WORDS'
+
+ # write file to server
+ self._write_file(FILENAME, CONTENTS)
+ self.assertEqual(self._read_file(FILENAME), CONTENTS)
# Make rebuild request
- post_body = json.dumps({
- 'rebuild' : {
- 'imageRef' : self.image_ref_alt,
- }
- })
+ post_body = json.dumps({'rebuild': {'imageRef': self.image_ref_alt}})
url = '/servers/%s/action' % self.server_id
response, body = self.os.nova.request('POST', url, body=post_body)
- # Ensure correct status transition
+ # check output
self.assertEqual('202', response['status'])
+ rebuilt_server = json.loads(body)['server']
+ generated_password = rebuilt_server['adminPass']
+
+ # Ensure correct status transition
# KNOWN-ISSUE
- #self.os.nova.wait_for_server_status(self.server_id, 'REBUILD')
- self.os.nova.wait_for_server_status(self.server_id, 'BUILD')
- self.os.nova.wait_for_server_status(self.server_id, 'ACTIVE')
+ #self._wait_for_server_status(self.server_id, 'REBUILD')
+ self._wait_for_server_status(self.server_id, 'BUILD')
+ self._wait_for_server_status(self.server_id, 'ACTIVE')
# Treats an issue where we ssh'd in too soon after rebuild
time.sleep(30)
@@ -193,28 +189,67 @@
self.assertTrue(ref_match or id_match)
# SSH into the server to ensure it came back up
- self._assert_ssh_password()
+ self._assert_ssh_password(generated_password)
# make sure file is gone
- self.assertEqual(self._read_file(filename), '')
+ self.assertEqual(self._read_file(FILENAME, generated_password), '')
+
+ # test again with a specified password
+ self._write_file(FILENAME, CONTENTS, generated_password)
+ _contents = self._read_file(FILENAME, generated_password)
+ self.assertEqual(_contents, CONTENTS)
+
+ specified_password = 'some_password'
+
+ # Make rebuild request
+ post_body = json.dumps({
+ 'rebuild': {
+ 'imageRef': self.image_ref,
+ 'adminPass': specified_password,
+ }
+ })
+ url = '/servers/%s/action' % self.server_id
+ response, body = self.os.nova.request('POST', url, body=post_body)
+
+ # check output
+ self.assertEqual('202', response['status'])
+ rebuilt_server = json.loads(body)['server']
+ self.assertEqual(rebuilt_server['adminPass'], specified_password)
+
+ # Ensure correct status transition
+ # KNOWN-ISSUE
+ #self._wait_for_server_status(self.server_id, 'REBUILD')
+ self._wait_for_server_status(self.server_id, 'BUILD')
+ self._wait_for_server_status(self.server_id, 'ACTIVE')
+
+ # Treats an issue where we ssh'd in too soon after rebuild
+ time.sleep(30)
+
+ # Check that the instance's imageRef matches the new imageRef
+ server = self.os.nova.get_server(self.server_id)
+ ref_match = self.image_ref == server['image']['links'][0]['href']
+ id_match = self.image_ref == server['image']['id']
+ self.assertTrue(ref_match or id_match)
+
+ # SSH into the server to ensure it came back up
+ self._assert_ssh_password(specified_password)
+
+ # make sure file is gone
+ self.assertEqual(self._read_file(FILENAME, specified_password), '')
@unittest.skipIf(not multi_node, 'Multiple compute nodes required')
def test_resize_server_confirm(self):
"""Resize a server"""
# Make resize request
- post_body = json.dumps({
- 'resize' : {
- 'flavorRef': self.flavor_ref_alt,
- }
- })
+ post_body = json.dumps({'resize': {'flavorRef': self.flavor_ref_alt}})
url = '/servers/%s/action' % self.server_id
response, body = self.os.nova.request('POST', url, body=post_body)
# Wait for status transition
self.assertEqual('202', response['status'])
# KNOWN-ISSUE
- #self.os.nova.wait_for_server_status(self.server_id, 'VERIFY_RESIZE')
- self.os.nova.wait_for_server_status(self.server_id, 'RESIZE-CONFIRM')
+ #self._wait_for_server_status(self.server_id, 'VERIFY_RESIZE')
+ self._wait_for_server_status(self.server_id, 'RESIZE-CONFIRM')
# Ensure API reports new flavor
server = self.os.nova.get_server(self.server_id)
@@ -224,15 +259,13 @@
self._assert_ssh_password()
# Make confirmResize request
- post_body = json.dumps({
- 'confirmResize' : 'null'
- })
+ post_body = json.dumps({'confirmResize': 'null'})
url = '/servers/%s/action' % self.server_id
response, body = self.os.nova.request('POST', url, body=post_body)
# Wait for status transition
self.assertEqual('204', response['status'])
- self.os.nova.wait_for_server_status(self.server_id, 'ACTIVE')
+ self._wait_for_server_status(self.server_id, 'ACTIVE')
# Ensure API still reports new flavor
server = self.os.nova.get_server(self.server_id)
@@ -243,19 +276,15 @@
"""Resize a server, then revert"""
# Make resize request
- post_body = json.dumps({
- 'resize' : {
- 'flavorRef': self.flavor_ref_alt,
- }
- })
+ post_body = json.dumps({'resize': {'flavorRef': self.flavor_ref_alt}})
url = '/servers/%s/action' % self.server_id
response, body = self.os.nova.request('POST', url, body=post_body)
# Wait for status transition
self.assertEqual('202', response['status'])
# KNOWN-ISSUE
- #self.os.nova.wait_for_server_status(self.server_id, 'VERIFY_RESIZE')
- self.os.nova.wait_for_server_status(self.server_id, 'RESIZE-CONFIRM')
+ #self._wait_for_server_status(self.server_id, 'VERIFY_RESIZE')
+ self._wait_for_server_status(self.server_id, 'RESIZE-CONFIRM')
# SSH into the server to ensure it came back up
self._assert_ssh_password()
@@ -265,15 +294,13 @@
self.assertEqual(self.flavor_ref_alt, server['flavor']['id'])
# Make revertResize request
- post_body = json.dumps({
- 'revertResize' : 'null'
- })
+ post_body = json.dumps({'revertResize': 'null'})
url = '/servers/%s/action' % self.server_id
response, body = self.os.nova.request('POST', url, body=post_body)
# Assert status transition
self.assertEqual('202', response['status'])
- self.os.nova.wait_for_server_status(self.server_id, 'ACTIVE')
+ self._wait_for_server_status(self.server_id, 'ACTIVE')
# Ensure flavor ref was reverted to original
server = self.os.nova.get_server(self.server_id)
@@ -288,13 +315,14 @@
self.image_ref = self.os.config.env.image_ref
self.flavor_ref = self.os.config.env.flavor_ref
self.ssh_timeout = self.os.config.nova.ssh_timeout
+ self.build_timeout = self.os.config.nova.build_timeout
- self.server_name = 'testserver'
+ self.server_name = 'stacktester1'
expected_server = {
- 'name' : self.server_name,
- 'imageRef' : self.image_ref,
- 'flavorRef' : self.flavor_ref,
+ 'name': self.server_name,
+ 'imageRef': self.image_ref,
+ 'flavorRef': self.flavor_ref,
}
created_server = self.os.nova.create_server(expected_server)
@@ -303,9 +331,10 @@
def tearDown(self):
self.os.nova.delete_server(self.server_id)
- def _wait_for_status(self, server_id, status):
+ def _wait_for_server_status(self, server_id, status):
try:
- self.os.nova.wait_for_server_status(server_id, status)
+ self.os.nova.wait_for_server_status(server_id, status,
+ timeout=self.build_timeout)
except exceptions.TimeoutException:
self.fail("Server failed to change status to %s" % status)
@@ -313,19 +342,17 @@
"""Create image from an existing server"""
# Wait for server to come up before running this test
- self._wait_for_status(self.server_id, 'ACTIVE')
+ self._wait_for_server_status(self.server_id, 'ACTIVE')
# Create snapshot
- image_data = {'name' : 'backup'}
+ image_data = {'name': 'backup'}
req_body = json.dumps({'createImage': image_data})
url = '/servers/%s/action' % self.server_id
response, body = self.os.nova.request('POST', url, body=req_body)
- print response
- print body
self.assertEqual(response['status'], '202')
image_ref = response['location']
- snapshot_id = image_ref.rsplit('/',1)[1]
+ snapshot_id = image_ref.rsplit('/', 1)[1]
# Get snapshot and check its attributes
resp, body = self.os.nova.request('GET', '/images/%s' % snapshot_id)
@@ -344,7 +371,7 @@
"""Ensure inability to snapshot server in BUILD state"""
# Create snapshot
- req_body = json.dumps({'createImage': {'name' : 'backup'}})
+ req_body = json.dumps({'createImage': {'name': 'backup'}})
url = '/servers/%s/action' % self.server_id
response, body = self.os.nova.request('POST', url, body=req_body)
diff --git a/kong/tests/test_server_addresses.py b/kong/tests/test_server_addresses.py
deleted file mode 100644
index 96d66b8..0000000
--- a/kong/tests/test_server_addresses.py
+++ /dev/null
@@ -1,63 +0,0 @@
-
-import json
-import os
-
-from kong import exceptions
-from kong import openstack
-from kong import tests
-
-
-class ServerAddressesTest(tests.FunctionalTest):
-
- @classmethod
- def setUpClass(self):
- super(ServerAddressesTest, self).setUp()
- self.os = openstack.Manager(self.nova)
- self.image_ref = self.os.config.env.image_ref
- self.flavor_ref = self.os.config.env.flavor_ref
-
- def setUp(self):
- server = {
- 'name' : 'testserver',
- 'imageRef' : self.image_ref,
- 'flavorRef' : self.flavor_ref,
- }
-
- created_server = self.os.nova.create_server(server)
- self.server_id = created_server['id']
- self.os.nova.wait_for_server_status(self.server_id, 'ACTIVE')
-
- def tearDown(self):
- self.os.nova.delete_server(self.server_id)
-
- def test_server_addresses(self):
- """Retrieve server addresses information"""
- url = '/servers/%s' % self.server_id
- response, body = self.os.nova.request('GET', url)
- self.assertEqual(response.status, 200)
- body = json.loads(body)
- self.assertTrue('addresses' in body['server'].keys())
- server_addresses = body['server']['addresses']
-
- url = '/servers/%s/ips' % self.server_id
- response, body = self.os.nova.request('GET', url)
- self.assertEqual(response.status, 200)
- body = json.loads(body)
- self.assertEqual(body.keys(), ['addresses'])
- ips_addresses = body['addresses']
-
- self.assertEqual(server_addresses, ips_addresses)
-
- # Now validate entities within addresses containers if available
- for (network, network_data) in ips_addresses.items():
- # Ensure we can query for each particular network
- url = '/servers/%s/ips/%s' % (self.server_id, network)
- response, body = self.os.nova.request('GET', url)
- self.assertEqual(response.status, 200)
- body = json.loads(body)
- self.assertEqual(body.keys(), [network])
- self.assertEqual(body[network], network_data)
-
- for ip_data in network_data:
- self.assertEqual(set(ip_data.keys()),
- set(['addr', 'version']))
diff --git a/kong/tests/test_server_meta.py b/kong/tests/test_server_meta.py
deleted file mode 100644
index 44630bc..0000000
--- a/kong/tests/test_server_meta.py
+++ /dev/null
@@ -1,172 +0,0 @@
-
-import json
-
-from kong import openstack
-from kong import tests
-
-
-class ServersMetadataTest(tests.FunctionalTest):
- @classmethod
- def setUpClass(self):
- super(ServersMetadataTest, self).setUp()
- self.os = openstack.Manager(self.nova)
- self.image_ref = self.os.config.env.image_ref
- self.flavor_ref = self.os.config.env.flavor_ref
-
- def setUp(self):
- server = {
- 'name' : 'testserver',
- 'imageRef' : self.image_ref,
- 'flavorRef' : self.flavor_ref,
- 'metadata' : {
- 'testEntry' : 'testValue',
- },
- }
-
- created_server = self.os.nova.create_server(server)
- self.server_id = created_server['id']
-
- def tearDown(self):
- self.os.nova.delete_server(self.server_id)
-
-
- def test_get_server_metadata(self):
- """Retrieve metadata for a server"""
-
- url = '/servers/%s/metadata' % self.server_id
- response, body = self.os.nova.request('GET', url)
- self.assertEqual(200, response.status)
-
- result = json.loads(body)
- expected = {
- 'metadata' : {
- 'testEntry' : 'testValue',
- },
- }
- self.assertEqual(expected, result)
-
- def test_post_server_metadata(self):
- """Create or update metadata for a server"""
-
- post_metadata = {
- 'metadata' : {
- 'new_entry1' : 'new_value1',
- 'new_entry2' : 'new_value2',
- },
- }
- post_body = json.dumps(post_metadata)
-
- url = '/servers/%s/metadata' % self.server_id
- response, body = self.os.nova.request('POST', url, body=post_body)
- self.assertEqual(200, response.status)
-
- url = '/servers/%s/metadata' % self.server_id
- response, body = self.os.nova.request('GET', url)
- self.assertEqual(200, response.status)
-
- result = json.loads(body)
- expected = post_metadata
- expected['metadata']['testEntry'] = 'testValue'
- self.assertEqual(expected, result)
-
- def test_put_server_metadata(self):
- """Overwrite all metadata for a server"""
-
- expected = {
- 'metadata' : {
- 'new_entry1' : 'new_value1',
- 'new_entry2' : 'new_value2',
- },
- }
-
- url = '/servers/%s/metadata' % self.server_id
- post_body = json.dumps(expected)
- response, body = self.os.nova.request('PUT', url, body=post_body)
- self.assertEqual(200, response.status)
-
- url = '/servers/%s/metadata' % self.server_id
- response, body = self.os.nova.request('GET', url)
- self.assertEqual(200, response.status)
-
- result = json.loads(body)
- # We want to make sure 'testEntry' was removed
- self.assertEqual(expected, result)
-
- def test_get_server_metadata_key(self):
- """Retrieve specific metadata key for a server"""
-
- url = '/servers/%s/metadata/testEntry' % self.server_id
- response, body = self.os.nova.request('GET', url)
- self.assertEqual(200, response.status)
-
- result = json.loads(body)
- expected = {
- 'meta':{
- 'testEntry':'testValue',
- },
- }
-
- self.assertDictEqual(expected, result)
-
- def test_add_server_metadata_key(self):
- """Set specific metadata key on a server"""
-
- expected_meta = {
- 'meta' : {
- 'new_meta1' : 'new_value1',
- },
- }
-
- put_body = json.dumps(expected_meta)
-
- url = '/servers/%s/metadata/new_meta1' % self.server_id
- response, body = self.os.nova.request('PUT', url, body=put_body)
- self.assertEqual(200, response.status)
- result = json.loads(body)
- self.assertDictEqual(expected_meta, result)
-
- expected_metadata = {
- 'metadata' : {
- 'testEntry' : 'testValue',
- 'new_meta1' : 'new_value1',
- },
- }
-
- # Now check all metadata to make sure the other values are there
- url = '/servers/%s/metadata' % self.server_id
- response, body = self.os.nova.request('GET', url)
- result = json.loads(body)
- self.assertDictEqual(expected_metadata, result)
-
- def test_update_server_metadata_key(self):
- """Update specific metadata key for a server"""
-
- expected_meta = {
- 'meta' : {
- 'testEntry' : 'testValue2',
- },
- }
- put_body = json.dumps(expected_meta)
-
- url = '/servers/%s/metadata/testEntry' % self.server_id
- response, body = self.os.nova.request('PUT', url, body=put_body)
- self.assertEqual(200, response.status)
- result = json.loads(body)
- self.assertEqual(expected_meta, result)
-
- def test_delete_server_metadata_key(self):
- """Delete metadata for a server"""
-
- url = '/servers/%s/metadata/testEntry' % self.server_id
- response, body = self.os.nova.request('DELETE', url)
- self.assertEquals(204, response.status)
-
- url = '/servers/%s/metadata/testEntry' % self.server_id
- response, body = self.os.nova.request('GET', url)
- self.assertEquals(404, response.status)
-
- url = '/servers/%s/metadata' % self.server_id
- response, body = self.os.nova.request('GET', url)
- self.assertEquals(200, response.status)
- result = json.loads(body)
- self.assertDictEqual({'metadata':{}}, result)