test supporting API v1.1

Updating some of the test to support api v1.1

Change-Id: I22c8650d8be02031204b23b7d39c6c6fc5294ca9
This commit is contained in:
Aaron Lee 2011-10-18 17:07:19 -05:00
parent 78dbb64366
commit 35b8c921e9
5 changed files with 40 additions and 61 deletions

View File

@ -13,7 +13,7 @@ class Client(object):
self.host = host
self.username = username
self.password = password
self.timeout = timeout
self.timeout = int(timeout)
def _get_ssh_connection(self):
"""Returns an ssh connection to the specified host"""

View File

@ -10,4 +10,5 @@ class Manager(object):
nova['port'],
nova['ver'],
nova['user'],
nova['key'])
nova['key'],
nova['project'])

View File

@ -96,37 +96,18 @@ class FunctionalTest(unittest2.TestCase):
# Swift Setup
if 'swift' in self.config:
self.swift['auth_host'] = self.config['swift']['auth_host']
self.swift['auth_port'] = self.config['swift']['auth_port']
self.swift['auth_prefix'] = self.config['swift']['auth_prefix']
self.swift['auth_ssl'] = self.config['swift']['auth_ssl']
self.swift['account'] = self.config['swift']['account']
self.swift['username'] = self.config['swift']['username']
self.swift['password'] = self.config['swift']['password']
self.swift = self.config['swift']
self.swift['ver'] = 'v1.0' # need to find a better way to get this
# Glance Setup
self.glance['host'] = self.config['glance']['host']
self.glance['port'] = self.config['glance']['port']
if 'apiver' in self.config['glance']:
self.glance['apiver'] = self.config['glance']['apiver']
self.glance = self.config['glance']
if 'nova' in self.config:
self.nova['host'] = self.config['nova']['host']
self.nova['port'] = self.config['nova']['port']
self.nova = self.config['nova']
self.nova['ver'] = self.config['nova']['apiver']
self.nova['user'] = self.config['nova']['user']
self.nova['key'] = self.config['nova']['key']
self.nova['flavor_ref'] = self.config['nova']['flavor_ref']
self.nova['flavor_ref_alt'] = self.config['nova']['flavor_ref_alt']
self.nova['ssh_timeout'] = self.config['nova']['ssh_timeout']
self.nova['build_timeout'] = self.config['nova']['build_timeout']
if 'keystone' in self.config:
self.keystone['host'] = self.config['keystone']['host']
self.keystone['port'] = self.config['keystone']['port']
self.keystone['apiver'] = self.config['keystone']['apiver']
self.keystone['user'] = self.config['keystone']['user']
self.keystone = self.config['keystone']
self.keystone['pass'] = self.config['keystone']['password']
def _md5sum_file(self, path):

View File

@ -1,5 +1,6 @@
import json
import os
import re
from kong import openstack
from kong import tests
@ -15,23 +16,15 @@ class ImagesTest(tests.FunctionalTest):
image_id = str(image['id'])
mgmt_url = self.os.nova.management_url
mgmt_url = re.sub(r'1//', r'1/', mgmt_url) # TODO: is this a bug in Nova?
bmk_url = re.sub(r'v1.1\/', r'', mgmt_url)
self_link = {'rel': 'self',
'href': os.path.join(mgmt_url, 'images', image_id)}
bookmark_link = {'rel': 'bookmark',
'href': os.path.join(bmk_url, 'images', image_id)}
self_link = os.path.join(mgmt_url, 'images', image_id)
bookmark_link = os.path.join(bmk_url, 'images', image_id)
expected_links = [
{
'rel': 'self',
'href': self_link,
},
{
'rel': 'bookmark',
'href': bookmark_link,
},
]
self.assertEqual(image['links'], expected_links)
self.assertIn(bookmark_link, image['links'])
self.assertIn(self_link, image['links'])
def _assert_image_entity_basic(self, image):
actual_keys = set(image.keys())
@ -50,14 +43,16 @@ class ImagesTest(tests.FunctionalTest):
keys.remove('server')
actual_keys = set(keys)
expected_keys = set((
'created',
'id',
'links',
'metadata',
'minDisk',
'minRam',
'name',
'progress',
'created',
'updated',
'status',
'metadata',
'links',
'updated',
))
self.assertEqual(actual_keys, expected_keys)
@ -80,7 +75,6 @@ class ImagesTest(tests.FunctionalTest):
"""List all images in detail"""
response, body = self.os.nova.request('GET', '/images/detail')
self.assertEqual(response['status'], '200')
resp_body = json.loads(body)
self.assertEqual(resp_body.keys(), ['images'])

View File

@ -18,6 +18,10 @@ class ServersTest(tests.FunctionalTest):
self.ssh_timeout = self.nova['ssh_timeout']
self.build_timeout = self.nova['build_timeout']
def tearDown(self):
if getattr(self, 'server_id', False):
self.os.nova.delete_server(self.server_id)
def _assert_server_entity(self, server):
actual_keys = set(server.keys())
expected_keys = set((
@ -49,10 +53,10 @@ class ServersTest(tests.FunctionalTest):
base_url = os.path.join(api_url, self.nova['apiver'])
self_link = 'http://' + os.path.join(base_url,
# self.os.config.nova.project_id,
self.os.nova.project_id,
'servers', server_id)
bookmark_link = 'http://' + os.path.join(api_url,
# self.os.config.nova.project_id,
self.os.nova.project_id,
'servers', server_id)
expected_links = [
@ -91,6 +95,7 @@ class ServersTest(tests.FunctionalTest):
_body = json.loads(body)
self.assertEqual(_body.keys(), ['server'])
created_server = _body['server']
self.server_id = created_server['id'] # for the tearDown
admin_pass = created_server.pop('adminPass')
self._assert_server_entity(created_server)
@ -112,10 +117,9 @@ class ServersTest(tests.FunctionalTest):
self.fail("Failed to retrieve IP address from server entity")
# Assert password works
client = ssh.Client(ip, 'root', admin_pass, self.ssh_timeout)
self.assertTrue(client.test_connection_auth())
self.os.nova.delete_server(server['id'])
if int(self.nova['ssh_timeout']) > 0:
client = ssh.Client(ip, 'root', admin_pass, self.ssh_timeout)
self.assertTrue(client.test_connection_auth())
test_build_server.tags = ['nova', 'glance']
def test_build_server_with_file(self):
@ -149,6 +153,7 @@ class ServersTest(tests.FunctionalTest):
_body = json.loads(body)
self.assertEqual(_body.keys(), ['server'])
created_server = _body['server']
self.server_id = _body['server']['id']
admin_pass = created_server.pop('adminPass', None)
self._assert_server_entity(created_server)
@ -170,11 +175,10 @@ class ServersTest(tests.FunctionalTest):
self.fail("Failed to retrieve IP address from server entity")
# Assert injected file is on instance, also verifying password works
client = ssh.Client(ip, 'root', admin_pass, self.ssh_timeout)
injected_file = client.exec_command('cat /etc/test.txt')
self.assertEqual(injected_file, file_contents)
self.os.nova.delete_server(server['id'])
if int(self.nova['ssh_timeout']) > 0:
client = ssh.Client(ip, 'root', admin_pass, self.ssh_timeout)
injected_file = client.exec_command('cat /etc/test.txt')
self.assertEqual(injected_file, file_contents)
test_build_server_with_file.tags = ['nova', 'glance']
def test_build_server_with_password(self):
@ -224,11 +228,10 @@ class ServersTest(tests.FunctionalTest):
except KeyError:
self.fail("Failed to retrieve IP address from server entity")
# Assert password was set to that in request
client = ssh.Client(ip, 'root', server_password, self.ssh_timeout)
self.assertTrue(client.test_connection_auth())
self.os.nova.delete_server(server['id'])
# Assert password was set to that in request ( if ssh_timeout is > 0
if int(self.nova['ssh_timeout']) > 0:
client = ssh.Client(ip, 'root', server_password, self.ssh_timeout)
self.assertTrue(client.test_connection_auth())
test_build_server_with_password.tags = ['nova', 'glance']
def test_delete_server_building(self):