Added negative tests for servers

Change-Id: I6285045f023881f66e4bb42a6a188c68796ea5f5
This commit is contained in:
Daryl Walleck 2011-11-15 18:36:39 -06:00
parent 8a84d2efc4
commit adea1fa839
5 changed files with 112 additions and 2 deletions

View File

@ -1,3 +1,4 @@
from storm import exceptions
import httplib2
import json
import storm.config
@ -93,4 +94,8 @@ class RestClient(object):
req_url = "%s/%s" % (self.base_url, url)
resp, body = self.http_obj.request(req_url, method,
headers=headers, body=body)
if resp.status == 400:
body = json.loads(body)
raise exceptions.BadRequest(body['badRequest']['message'])
return resp, body

View File

@ -74,7 +74,7 @@ class EnvironmentConfig(object):
@property
def flavor_ref(self):
"""Valid flavorRef to use"""
return int(self.get("flavor_ref", 1))
return self.get("flavor_ref", 1)
@property
def flavor_ref_alt(self):

View File

@ -8,3 +8,11 @@ class BuildErrorException(Exception):
"""Exception on server build"""
def __repr__(self):
return "Server failed into error status"
class BadRequest(Exception):
def __init__(self, message):
self.message = message
def __str__(self):
return repr(self.message)

View File

@ -36,4 +36,4 @@ class FlavorsTest(unittest.TestCase):
def test_get_flavor(self):
"""The expected flavor details should be returned"""
resp, flavor = self.client.get_flavor_details(self.flavor_id)
self.assertEqual(self.flavor_id, flavor['id'])
self.assertEqual(self.flavor_id, str(flavor['id']))

View File

@ -0,0 +1,97 @@
import unittest2 as unittest
import storm.config
import base64
from nose.plugins.attrib import attr
from storm import openstack
from storm.common.utils.data_utils import rand_name
from storm.common import ssh
from storm import exceptions
class ServersNegativeTest(unittest.TestCase):
@classmethod
def setUpClass(cls):
cls.os = openstack.Manager()
cls.client = cls.os.servers_client
cls.config = storm.config.StormConfig()
cls.image_ref = cls.config.env.image_ref
cls.flavor_ref = cls.config.env.flavor_ref
cls.ssh_timeout = cls.config.nova.ssh_timeout
def test_server_name_blank(self):
"""Create a server with name parameter empty"""
try:
resp, server = self.client.create_server('', self.image_ref,
self.flavor_ref)
except exceptions.BadRequest:
pass
else:
self.fail('Server name cannot be blank')
def test_personality_file_contents_not_encoded(self):
"""Use an unencoded file when creating a server with personality"""
file_contents = 'This is a test file.'
personality = [{'path': '/etc/testfile.txt',
'contents': file_contents}]
try:
resp, server = self.client.create_server('test',
self.image_ref,
self.flavor_ref,
personality=personality)
except exceptions.BadRequest:
pass
else:
self.fail('Unencoded file contents should not be accepted')
def test_create_with_invalid_image(self):
"""Create a server with an unknown image"""
try:
resp, server = self.client.create_server('fail', -1,
self.flavor_ref)
except exceptions.BadRequest:
pass
else:
self.fail('Cannot create a server with an invalid image')
def test_create_with_invalid_flavor(self):
"""Create a server with an unknown flavor"""
try:
self.client.create_server('fail', self.image_ref, -1)
except exceptions.BadRequest:
pass
else:
self.fail('Cannot create a server with an invalid flavor')
@unittest.expectedFailure
def test_invalid_access_ip_v4_address(self):
"""An access IPv4 address must match a valid address pattern"""
#Currently failing due to bug
accessIPv4 = '1.1.1.1.1.1'
name = rand_name('server')
try:
resp, server = self.client.create_server(name,
self.image_ref,
self.flavor_ref,
accessIPv4=accessIPv4)
except exceptions.BadRequest:
pass
else:
self.fail('Access IPv4 address must match the correct format')
@unittest.expectedFailure
def test_invalid_ip_v6_address(self):
"""An access IPv6 address must match a valid address pattern"""
#Currently failing due to bug
accessIPv6 = 'notvalid'
name = rand_name('server')
try:
resp, server = self.client.create_server(name,
self.image_ref,
self.flavor_ref,
accessIPv6=accessIPv6)
except exceptions.BadRequest:
pass
else:
self.fail('Access IPv6 address must match the correct format')