test supporting API v1.1
Updating some of the test to support api v1.1
Change-Id: I22c8650d8be02031204b23b7d39c6c6fc5294ca9
diff --git a/kong/tests/__init__.py b/kong/tests/__init__.py
index c475488..b288ada 100644
--- a/kong/tests/__init__.py
+++ b/kong/tests/__init__.py
@@ -96,37 +96,18 @@
# 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):
diff --git a/kong/tests/test_images.py b/kong/tests/test_images.py
index 8f7b9cd..d8a4721 100644
--- a/kong/tests/test_images.py
+++ b/kong/tests/test_images.py
@@ -1,5 +1,6 @@
import json
import os
+import re
from kong import openstack
from kong import tests
@@ -15,23 +16,15 @@
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 @@
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 @@
"""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'])
diff --git a/kong/tests/test_servers.py b/kong/tests/test_servers.py
index 8824f92..5e27194 100644
--- a/kong/tests/test_servers.py
+++ b/kong/tests/test_servers.py
@@ -18,6 +18,10 @@
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 @@
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 @@
_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 @@
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 @@
_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 @@
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 @@
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):