merged upstream
This commit is contained in:
@@ -30,5 +30,3 @@
|
||||
.. moduleauthor:: Manish Singh <yosh@gimp.org>
|
||||
.. moduleauthor:: Andy Smith <andy@anarkystic.com>
|
||||
"""
|
||||
|
||||
from exception import *
|
||||
|
@@ -136,6 +136,22 @@ class CloudTestCase(test.TestCase):
|
||||
db.instance_destroy(self.context, inst['id'])
|
||||
db.floating_ip_destroy(self.context, address)
|
||||
|
||||
def test_describe_security_groups(self):
|
||||
"""Makes sure describe_security_groups works and filters results."""
|
||||
sec = db.security_group_create(self.context,
|
||||
{'project_id': self.context.project_id,
|
||||
'name': 'test'})
|
||||
result = self.cloud.describe_security_groups(self.context)
|
||||
# NOTE(vish): should have the default group as well
|
||||
self.assertEqual(len(result['securityGroupInfo']), 2)
|
||||
result = self.cloud.describe_security_groups(self.context,
|
||||
group_name=[sec['name']])
|
||||
self.assertEqual(len(result['securityGroupInfo']), 1)
|
||||
self.assertEqual(
|
||||
result['securityGroupInfo'][0]['groupName'],
|
||||
sec['name'])
|
||||
db.security_group_destroy(self.context, sec['id'])
|
||||
|
||||
def test_describe_volumes(self):
|
||||
"""Makes sure describe_volumes works and filters results."""
|
||||
vol1 = db.volume_create(self.context, {})
|
||||
@@ -294,19 +310,6 @@ class CloudTestCase(test.TestCase):
|
||||
LOG.debug(_("Terminating instance %s"), instance_id)
|
||||
rv = self.compute.terminate_instance(instance_id)
|
||||
|
||||
def test_describe_instances(self):
|
||||
"""Makes sure describe_instances works."""
|
||||
instance1 = db.instance_create(self.context, {'host': 'host2'})
|
||||
comp1 = db.service_create(self.context, {'host': 'host2',
|
||||
'availability_zone': 'zone1',
|
||||
'topic': "compute"})
|
||||
result = self.cloud.describe_instances(self.context)
|
||||
self.assertEqual(result['reservationSet'][0]
|
||||
['instancesSet'][0]
|
||||
['placement']['availabilityZone'], 'zone1')
|
||||
db.instance_destroy(self.context, instance1['id'])
|
||||
db.service_destroy(self.context, comp1['id'])
|
||||
|
||||
@staticmethod
|
||||
def _fake_set_image_description(ctxt, image_id, description):
|
||||
from nova.objectstore import handler
|
||||
|
@@ -2,6 +2,7 @@
|
||||
|
||||
# Copyright 2010 United States Government as represented by the
|
||||
# Administrator of the National Aeronautics and Space Administration.
|
||||
# Copyright 2011 Justin Santa Barbara
|
||||
# All Rights Reserved.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License"); you may
|
||||
@@ -31,6 +32,7 @@ import string
|
||||
import struct
|
||||
import sys
|
||||
import time
|
||||
import types
|
||||
from xml.sax import saxutils
|
||||
import re
|
||||
import netaddr
|
||||
@@ -499,3 +501,52 @@ def ensure_b64_encoding(val):
|
||||
return val
|
||||
except TypeError:
|
||||
return base64.b64encode(val)
|
||||
|
||||
|
||||
def get_from_path(items, path):
|
||||
""" Returns a list of items matching the specified path. Takes an
|
||||
XPath-like expression e.g. prop1/prop2/prop3, and for each item in items,
|
||||
looks up items[prop1][prop2][prop3]. Like XPath, if any of the
|
||||
intermediate results are lists it will treat each list item individually.
|
||||
A 'None' in items or any child expressions will be ignored, this function
|
||||
will not throw because of None (anywhere) in items. The returned list
|
||||
will contain no None values."""
|
||||
|
||||
if path is None:
|
||||
raise exception.Error("Invalid mini_xpath")
|
||||
|
||||
(first_token, sep, remainder) = path.partition("/")
|
||||
|
||||
if first_token == "":
|
||||
raise exception.Error("Invalid mini_xpath")
|
||||
|
||||
results = []
|
||||
|
||||
if items is None:
|
||||
return results
|
||||
|
||||
if not isinstance(items, types.ListType):
|
||||
# Wrap single objects in a list
|
||||
items = [items]
|
||||
|
||||
for item in items:
|
||||
if item is None:
|
||||
continue
|
||||
get_method = getattr(item, "get", None)
|
||||
if get_method is None:
|
||||
continue
|
||||
child = get_method(first_token)
|
||||
if child is None:
|
||||
continue
|
||||
if isinstance(child, types.ListType):
|
||||
# Flatten intermediate lists
|
||||
for x in child:
|
||||
results.append(x)
|
||||
else:
|
||||
results.append(child)
|
||||
|
||||
if not sep:
|
||||
# No more tokens
|
||||
return results
|
||||
else:
|
||||
return get_from_path(results, remainder)
|
||||
|
30
run_tests.py
30
run_tests.py
@@ -38,7 +38,22 @@
|
||||
# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||
# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
"""Unittest runner for Nova.
|
||||
|
||||
To run all tests
|
||||
python run_tests.py
|
||||
|
||||
To run a single test:
|
||||
python run_tests.py test_compute:ComputeTestCase.test_run_terminate
|
||||
|
||||
To run a single test module:
|
||||
python run_tests.py test_compute
|
||||
|
||||
or
|
||||
|
||||
python run_tests.py api.test_wsgi
|
||||
|
||||
"""
|
||||
|
||||
import gettext
|
||||
import os
|
||||
@@ -49,14 +64,10 @@ from nose import config
|
||||
from nose import core
|
||||
from nose import result
|
||||
|
||||
from nova import flags
|
||||
from nova import log as logging
|
||||
from nova.tests import fake_flags
|
||||
|
||||
|
||||
FLAGS = flags.FLAGS
|
||||
|
||||
|
||||
class _AnsiColorizer(object):
|
||||
"""
|
||||
A colorizer is an object that loosely wraps around a stream, allowing
|
||||
@@ -265,6 +276,15 @@ class NovaTestRunner(core.TextTestRunner):
|
||||
|
||||
if __name__ == '__main__':
|
||||
logging.setup()
|
||||
# If any argument looks like a test name but doesn't have "nova.tests" in
|
||||
# front of it, automatically add that so we don't have to type as much
|
||||
argv = []
|
||||
for x in sys.argv:
|
||||
if x.startswith('test_'):
|
||||
argv.append('nova.tests.%s' % x)
|
||||
else:
|
||||
argv.append(x)
|
||||
|
||||
testdir = os.path.abspath(os.path.join("nova","tests"))
|
||||
c = config.Config(stream=sys.stdout,
|
||||
env=os.environ,
|
||||
@@ -275,4 +295,4 @@ if __name__ == '__main__':
|
||||
runner = NovaTestRunner(stream=c.stream,
|
||||
verbosity=c.verbosity,
|
||||
config=c)
|
||||
sys.exit(not core.run(config=c, testRunner=runner))
|
||||
sys.exit(not core.run(config=c, testRunner=runner, argv=argv))
|
||||
|
11
run_tests.sh
11
run_tests.sh
@@ -40,6 +40,17 @@ done
|
||||
function run_tests {
|
||||
# Just run the test suites in current environment
|
||||
${wrapper} $NOSETESTS 2> run_tests.log
|
||||
# If we get some short import error right away, print the error log directly
|
||||
RESULT=$?
|
||||
if [ "$RESULT" -ne "0" ];
|
||||
then
|
||||
ERRSIZE=`wc -l run_tests.log | awk '{print \$1}'`
|
||||
if [ "$ERRSIZE" -lt "40" ];
|
||||
then
|
||||
cat run_tests.err.log
|
||||
fi
|
||||
fi
|
||||
return $RESULT
|
||||
}
|
||||
|
||||
NOSETESTS="python run_tests.py $noseargs"
|
||||
|
Reference in New Issue
Block a user