Make tests start with a clean database for every test.
This commit is contained in:
commit
ed7c71f56c
@ -105,18 +105,7 @@ def main():
|
|||||||
logging.setup()
|
logging.setup()
|
||||||
interface = os.environ.get('DNSMASQ_INTERFACE', 'br0')
|
interface = os.environ.get('DNSMASQ_INTERFACE', 'br0')
|
||||||
if int(os.environ.get('TESTING', '0')):
|
if int(os.environ.get('TESTING', '0')):
|
||||||
FLAGS.fake_rabbit = True
|
from nova.tests import fake_flags
|
||||||
FLAGS.network_size = 16
|
|
||||||
FLAGS.connection_type = 'fake'
|
|
||||||
FLAGS.fake_network = True
|
|
||||||
FLAGS.auth_driver = 'nova.auth.dbdriver.DbDriver'
|
|
||||||
FLAGS.num_networks = 5
|
|
||||||
path = os.path.abspath(os.path.join(os.path.dirname(__file__),
|
|
||||||
'..',
|
|
||||||
'nova',
|
|
||||||
'tests',
|
|
||||||
'tests.sqlite'))
|
|
||||||
FLAGS.sql_connection = 'sqlite:///%s' % path
|
|
||||||
action = argv[1]
|
action = argv[1]
|
||||||
if action in ['add', 'del', 'old']:
|
if action in ['add', 'del', 'old']:
|
||||||
mac = argv[2]
|
mac = argv[2]
|
||||||
|
@ -324,8 +324,9 @@ DEFINE_string('state_path', os.path.join(os.path.dirname(__file__), '../'),
|
|||||||
DEFINE_string('logdir', None, 'output to a per-service log file in named '
|
DEFINE_string('logdir', None, 'output to a per-service log file in named '
|
||||||
'directory')
|
'directory')
|
||||||
|
|
||||||
|
DEFINE_string('sqlite_db', 'nova.sqlite', 'file name for sqlite')
|
||||||
DEFINE_string('sql_connection',
|
DEFINE_string('sql_connection',
|
||||||
'sqlite:///$state_path/nova.sqlite',
|
'sqlite:///$state_path/$sqlite_db',
|
||||||
'connection string for sql database')
|
'connection string for sql database')
|
||||||
DEFINE_integer('sql_idle_timeout',
|
DEFINE_integer('sql_idle_timeout',
|
||||||
3600,
|
3600,
|
||||||
|
32
nova/test.py
32
nova/test.py
@ -22,26 +22,28 @@ Allows overriding of flags for use of fakes,
|
|||||||
and some black magic for inline callbacks.
|
and some black magic for inline callbacks.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
|
||||||
import datetime
|
import datetime
|
||||||
|
import os
|
||||||
|
import shutil
|
||||||
import uuid
|
import uuid
|
||||||
import unittest
|
import unittest
|
||||||
|
|
||||||
import mox
|
import mox
|
||||||
|
import shutil
|
||||||
import stubout
|
import stubout
|
||||||
|
|
||||||
from nova import context
|
from nova import context
|
||||||
from nova import db
|
from nova import db
|
||||||
from nova import fakerabbit
|
from nova import fakerabbit
|
||||||
from nova import flags
|
from nova import flags
|
||||||
from nova import log as logging
|
|
||||||
from nova import rpc
|
from nova import rpc
|
||||||
from nova import service
|
from nova import service
|
||||||
from nova.network import manager as network_manager
|
|
||||||
|
|
||||||
|
|
||||||
FLAGS = flags.FLAGS
|
FLAGS = flags.FLAGS
|
||||||
flags.DEFINE_bool('flush_db', True,
|
flags.DEFINE_string('sqlite_clean_db', 'clean.sqlite',
|
||||||
'Flush the database before running fake tests')
|
'File name of clean sqlite db')
|
||||||
flags.DEFINE_bool('fake_tests', True,
|
flags.DEFINE_bool('fake_tests', True,
|
||||||
'should we use everything for testing')
|
'should we use everything for testing')
|
||||||
|
|
||||||
@ -66,15 +68,8 @@ class TestCase(unittest.TestCase):
|
|||||||
# now that we have some required db setup for the system
|
# now that we have some required db setup for the system
|
||||||
# to work properly.
|
# to work properly.
|
||||||
self.start = datetime.datetime.utcnow()
|
self.start = datetime.datetime.utcnow()
|
||||||
ctxt = context.get_admin_context()
|
shutil.copyfile(os.path.join(FLAGS.state_path, FLAGS.sqlite_clean_db),
|
||||||
if db.network_count(ctxt) != 5:
|
os.path.join(FLAGS.state_path, FLAGS.sqlite_db))
|
||||||
network_manager.VlanManager().create_networks(ctxt,
|
|
||||||
FLAGS.fixed_range,
|
|
||||||
5, 16,
|
|
||||||
FLAGS.fixed_range_v6,
|
|
||||||
FLAGS.vlan_start,
|
|
||||||
FLAGS.vpn_start,
|
|
||||||
)
|
|
||||||
|
|
||||||
# emulate some of the mox stuff, we can't use the metaclass
|
# emulate some of the mox stuff, we can't use the metaclass
|
||||||
# because it screws with our generators
|
# because it screws with our generators
|
||||||
@ -96,17 +91,6 @@ class TestCase(unittest.TestCase):
|
|||||||
self.mox.VerifyAll()
|
self.mox.VerifyAll()
|
||||||
super(TestCase, self).tearDown()
|
super(TestCase, self).tearDown()
|
||||||
finally:
|
finally:
|
||||||
try:
|
|
||||||
# Clean up any ips associated during the test.
|
|
||||||
ctxt = context.get_admin_context()
|
|
||||||
db.fixed_ip_disassociate_all_by_timeout(ctxt, FLAGS.host,
|
|
||||||
self.start)
|
|
||||||
db.network_disassociate_all(ctxt)
|
|
||||||
|
|
||||||
db.security_group_destroy_all(ctxt)
|
|
||||||
except Exception:
|
|
||||||
pass
|
|
||||||
|
|
||||||
# Clean out fake_rabbit's queue if we used it
|
# Clean out fake_rabbit's queue if we used it
|
||||||
if FLAGS.fake_rabbit:
|
if FLAGS.fake_rabbit:
|
||||||
fakerabbit.reset_all()
|
fakerabbit.reset_all()
|
||||||
|
@ -37,5 +37,30 @@ setattr(__builtin__, '_', lambda x: x)
|
|||||||
|
|
||||||
|
|
||||||
def setup():
|
def setup():
|
||||||
|
import os
|
||||||
|
import shutil
|
||||||
|
|
||||||
|
from nova import context
|
||||||
|
from nova import flags
|
||||||
from nova.db import migration
|
from nova.db import migration
|
||||||
|
from nova.network import manager as network_manager
|
||||||
|
from nova.tests import fake_flags
|
||||||
|
|
||||||
|
FLAGS = flags.FLAGS
|
||||||
|
|
||||||
|
testdb = os.path.join(FLAGS.state_path, FLAGS.sqlite_db)
|
||||||
|
if os.path.exists(testdb):
|
||||||
|
os.unlink(testdb)
|
||||||
migration.db_sync()
|
migration.db_sync()
|
||||||
|
ctxt = context.get_admin_context()
|
||||||
|
network_manager.VlanManager().create_networks(ctxt,
|
||||||
|
FLAGS.fixed_range,
|
||||||
|
FLAGS.num_networks,
|
||||||
|
FLAGS.network_size,
|
||||||
|
FLAGS.fixed_range_v6,
|
||||||
|
FLAGS.vlan_start,
|
||||||
|
FLAGS.vpn_start,
|
||||||
|
)
|
||||||
|
|
||||||
|
cleandb = os.path.join(FLAGS.state_path, FLAGS.sqlite_clean_db)
|
||||||
|
shutil.copyfile(testdb, cleandb)
|
||||||
|
@ -16,7 +16,7 @@
|
|||||||
# under the License.
|
# under the License.
|
||||||
|
|
||||||
import webob.dec
|
import webob.dec
|
||||||
import unittest
|
from nova import test
|
||||||
|
|
||||||
from nova import context
|
from nova import context
|
||||||
from nova import flags
|
from nova import flags
|
||||||
@ -33,7 +33,7 @@ def simple_wsgi(req):
|
|||||||
return ""
|
return ""
|
||||||
|
|
||||||
|
|
||||||
class RateLimitingMiddlewareTest(unittest.TestCase):
|
class RateLimitingMiddlewareTest(test.TestCase):
|
||||||
|
|
||||||
def test_get_action_name(self):
|
def test_get_action_name(self):
|
||||||
middleware = RateLimitingMiddleware(simple_wsgi)
|
middleware = RateLimitingMiddleware(simple_wsgi)
|
||||||
|
@ -15,13 +15,13 @@
|
|||||||
# License for the specific language governing permissions and limitations
|
# License for the specific language governing permissions and limitations
|
||||||
# under the License.
|
# under the License.
|
||||||
|
|
||||||
import unittest
|
|
||||||
|
|
||||||
import stubout
|
import stubout
|
||||||
import webob
|
import webob
|
||||||
from paste import urlmap
|
from paste import urlmap
|
||||||
|
|
||||||
from nova import flags
|
from nova import flags
|
||||||
|
from nova import test
|
||||||
from nova.api import openstack
|
from nova.api import openstack
|
||||||
from nova.api.openstack import ratelimiting
|
from nova.api.openstack import ratelimiting
|
||||||
from nova.api.openstack import auth
|
from nova.api.openstack import auth
|
||||||
@ -30,9 +30,10 @@ from nova.tests.api.openstack import fakes
|
|||||||
FLAGS = flags.FLAGS
|
FLAGS = flags.FLAGS
|
||||||
|
|
||||||
|
|
||||||
class AdminAPITest(unittest.TestCase):
|
class AdminAPITest(test.TestCase):
|
||||||
|
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
|
super(AdminAPITest, self).setUp()
|
||||||
self.stubs = stubout.StubOutForTesting()
|
self.stubs = stubout.StubOutForTesting()
|
||||||
fakes.FakeAuthManager.auth_data = {}
|
fakes.FakeAuthManager.auth_data = {}
|
||||||
fakes.FakeAuthDatabase.data = {}
|
fakes.FakeAuthDatabase.data = {}
|
||||||
@ -44,6 +45,7 @@ class AdminAPITest(unittest.TestCase):
|
|||||||
def tearDown(self):
|
def tearDown(self):
|
||||||
self.stubs.UnsetAll()
|
self.stubs.UnsetAll()
|
||||||
FLAGS.allow_admin_api = self.allow_admin
|
FLAGS.allow_admin_api = self.allow_admin
|
||||||
|
super(AdminAPITest, self).tearDown()
|
||||||
|
|
||||||
def test_admin_enabled(self):
|
def test_admin_enabled(self):
|
||||||
FLAGS.allow_admin_api = True
|
FLAGS.allow_admin_api = True
|
||||||
@ -58,8 +60,5 @@ class AdminAPITest(unittest.TestCase):
|
|||||||
# We should still be able to access public operations.
|
# We should still be able to access public operations.
|
||||||
req = webob.Request.blank('/v1.0/flavors')
|
req = webob.Request.blank('/v1.0/flavors')
|
||||||
res = req.get_response(fakes.wsgi_app())
|
res = req.get_response(fakes.wsgi_app())
|
||||||
self.assertEqual(res.status_int, 200)
|
|
||||||
# TODO: Confirm admin operations are unavailable.
|
# TODO: Confirm admin operations are unavailable.
|
||||||
|
self.assertEqual(res.status_int, 200)
|
||||||
if __name__ == '__main__':
|
|
||||||
unittest.main()
|
|
||||||
|
@ -15,17 +15,17 @@
|
|||||||
# License for the specific language governing permissions and limitations
|
# License for the specific language governing permissions and limitations
|
||||||
# under the License.
|
# under the License.
|
||||||
|
|
||||||
import unittest
|
|
||||||
import webob.exc
|
import webob.exc
|
||||||
import webob.dec
|
import webob.dec
|
||||||
|
|
||||||
from webob import Request
|
from webob import Request
|
||||||
|
|
||||||
|
from nova import test
|
||||||
from nova.api import openstack
|
from nova.api import openstack
|
||||||
from nova.api.openstack import faults
|
from nova.api.openstack import faults
|
||||||
|
|
||||||
|
|
||||||
class APITest(unittest.TestCase):
|
class APITest(test.TestCase):
|
||||||
|
|
||||||
def _wsgi_app(self, inner_app):
|
def _wsgi_app(self, inner_app):
|
||||||
# simpler version of the app than fakes.wsgi_app
|
# simpler version of the app than fakes.wsgi_app
|
||||||
|
@ -16,7 +16,6 @@
|
|||||||
# under the License.
|
# under the License.
|
||||||
|
|
||||||
import datetime
|
import datetime
|
||||||
import unittest
|
|
||||||
|
|
||||||
import stubout
|
import stubout
|
||||||
import webob
|
import webob
|
||||||
@ -27,12 +26,14 @@ import nova.api.openstack.auth
|
|||||||
import nova.auth.manager
|
import nova.auth.manager
|
||||||
from nova import auth
|
from nova import auth
|
||||||
from nova import context
|
from nova import context
|
||||||
|
from nova import test
|
||||||
from nova.tests.api.openstack import fakes
|
from nova.tests.api.openstack import fakes
|
||||||
|
|
||||||
|
|
||||||
class Test(unittest.TestCase):
|
class Test(test.TestCase):
|
||||||
|
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
|
super(Test, self).setUp()
|
||||||
self.stubs = stubout.StubOutForTesting()
|
self.stubs = stubout.StubOutForTesting()
|
||||||
self.stubs.Set(nova.api.openstack.auth.AuthMiddleware,
|
self.stubs.Set(nova.api.openstack.auth.AuthMiddleware,
|
||||||
'__init__', fakes.fake_auth_init)
|
'__init__', fakes.fake_auth_init)
|
||||||
@ -45,6 +46,7 @@ class Test(unittest.TestCase):
|
|||||||
def tearDown(self):
|
def tearDown(self):
|
||||||
self.stubs.UnsetAll()
|
self.stubs.UnsetAll()
|
||||||
fakes.fake_data_store = {}
|
fakes.fake_data_store = {}
|
||||||
|
super(Test, self).tearDown()
|
||||||
|
|
||||||
def test_authorize_user(self):
|
def test_authorize_user(self):
|
||||||
f = fakes.FakeAuthManager()
|
f = fakes.FakeAuthManager()
|
||||||
@ -128,8 +130,9 @@ class Test(unittest.TestCase):
|
|||||||
self.assertEqual(result.status, '401 Unauthorized')
|
self.assertEqual(result.status, '401 Unauthorized')
|
||||||
|
|
||||||
|
|
||||||
class TestLimiter(unittest.TestCase):
|
class TestLimiter(test.TestCase):
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
|
super(TestLimiter, self).setUp()
|
||||||
self.stubs = stubout.StubOutForTesting()
|
self.stubs = stubout.StubOutForTesting()
|
||||||
self.stubs.Set(nova.api.openstack.auth.AuthMiddleware,
|
self.stubs.Set(nova.api.openstack.auth.AuthMiddleware,
|
||||||
'__init__', fakes.fake_auth_init)
|
'__init__', fakes.fake_auth_init)
|
||||||
@ -141,6 +144,7 @@ class TestLimiter(unittest.TestCase):
|
|||||||
def tearDown(self):
|
def tearDown(self):
|
||||||
self.stubs.UnsetAll()
|
self.stubs.UnsetAll()
|
||||||
fakes.fake_data_store = {}
|
fakes.fake_data_store = {}
|
||||||
|
super(TestLimiter, self).tearDown()
|
||||||
|
|
||||||
def test_authorize_token(self):
|
def test_authorize_token(self):
|
||||||
f = fakes.FakeAuthManager()
|
f = fakes.FakeAuthManager()
|
||||||
@ -161,7 +165,3 @@ class TestLimiter(unittest.TestCase):
|
|||||||
result = req.get_response(fakes.wsgi_app())
|
result = req.get_response(fakes.wsgi_app())
|
||||||
self.assertEqual(result.status, '200 OK')
|
self.assertEqual(result.status, '200 OK')
|
||||||
self.assertEqual(result.headers['X-Test-Success'], 'True')
|
self.assertEqual(result.headers['X-Test-Success'], 'True')
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
|
||||||
unittest.main()
|
|
||||||
|
@ -19,14 +19,14 @@
|
|||||||
Test suites for 'common' code used throughout the OpenStack HTTP API.
|
Test suites for 'common' code used throughout the OpenStack HTTP API.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
import unittest
|
|
||||||
|
|
||||||
from webob import Request
|
from webob import Request
|
||||||
|
|
||||||
|
from nova import test
|
||||||
from nova.api.openstack.common import limited
|
from nova.api.openstack.common import limited
|
||||||
|
|
||||||
|
|
||||||
class LimiterTest(unittest.TestCase):
|
class LimiterTest(test.TestCase):
|
||||||
"""
|
"""
|
||||||
Unit tests for the `nova.api.openstack.common.limited` method which takes
|
Unit tests for the `nova.api.openstack.common.limited` method which takes
|
||||||
in a list of items and, depending on the 'offset' and 'limit' GET params,
|
in a list of items and, depending on the 'offset' and 'limit' GET params,
|
||||||
@ -37,6 +37,7 @@ class LimiterTest(unittest.TestCase):
|
|||||||
"""
|
"""
|
||||||
Run before each test.
|
Run before each test.
|
||||||
"""
|
"""
|
||||||
|
super(LimiterTest, self).setUp()
|
||||||
self.tiny = range(1)
|
self.tiny = range(1)
|
||||||
self.small = range(10)
|
self.small = range(10)
|
||||||
self.medium = range(1000)
|
self.medium = range(1000)
|
||||||
|
@ -15,15 +15,15 @@
|
|||||||
# License for the specific language governing permissions and limitations
|
# License for the specific language governing permissions and limitations
|
||||||
# under the License.
|
# under the License.
|
||||||
|
|
||||||
import unittest
|
|
||||||
import webob
|
import webob
|
||||||
import webob.dec
|
import webob.dec
|
||||||
import webob.exc
|
import webob.exc
|
||||||
|
|
||||||
|
from nova import test
|
||||||
from nova.api.openstack import faults
|
from nova.api.openstack import faults
|
||||||
|
|
||||||
|
|
||||||
class TestFaults(unittest.TestCase):
|
class TestFaults(test.TestCase):
|
||||||
|
|
||||||
def test_fault_parts(self):
|
def test_fault_parts(self):
|
||||||
req = webob.Request.blank('/.xml')
|
req = webob.Request.blank('/.xml')
|
||||||
|
@ -15,18 +15,18 @@
|
|||||||
# License for the specific language governing permissions and limitations
|
# License for the specific language governing permissions and limitations
|
||||||
# under the License.
|
# under the License.
|
||||||
|
|
||||||
import unittest
|
|
||||||
|
|
||||||
import stubout
|
import stubout
|
||||||
import webob
|
import webob
|
||||||
|
|
||||||
|
from nova import test
|
||||||
import nova.api
|
import nova.api
|
||||||
from nova.api.openstack import flavors
|
from nova.api.openstack import flavors
|
||||||
from nova.tests.api.openstack import fakes
|
from nova.tests.api.openstack import fakes
|
||||||
|
|
||||||
|
|
||||||
class FlavorsTest(unittest.TestCase):
|
class FlavorsTest(test.TestCase):
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
|
super(FlavorsTest, self).setUp()
|
||||||
self.stubs = stubout.StubOutForTesting()
|
self.stubs = stubout.StubOutForTesting()
|
||||||
fakes.FakeAuthManager.auth_data = {}
|
fakes.FakeAuthManager.auth_data = {}
|
||||||
fakes.FakeAuthDatabase.data = {}
|
fakes.FakeAuthDatabase.data = {}
|
||||||
@ -36,6 +36,7 @@ class FlavorsTest(unittest.TestCase):
|
|||||||
|
|
||||||
def tearDown(self):
|
def tearDown(self):
|
||||||
self.stubs.UnsetAll()
|
self.stubs.UnsetAll()
|
||||||
|
super(FlavorsTest, self).tearDown()
|
||||||
|
|
||||||
def test_get_flavor_list(self):
|
def test_get_flavor_list(self):
|
||||||
req = webob.Request.blank('/v1.0/flavors')
|
req = webob.Request.blank('/v1.0/flavors')
|
||||||
@ -43,6 +44,3 @@ class FlavorsTest(unittest.TestCase):
|
|||||||
|
|
||||||
def test_get_flavor_by_id(self):
|
def test_get_flavor_by_id(self):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
if __name__ == '__main__':
|
|
||||||
unittest.main()
|
|
||||||
|
@ -22,7 +22,6 @@ and as a WSGI layer
|
|||||||
|
|
||||||
import json
|
import json
|
||||||
import datetime
|
import datetime
|
||||||
import unittest
|
|
||||||
|
|
||||||
import stubout
|
import stubout
|
||||||
import webob
|
import webob
|
||||||
@ -30,6 +29,7 @@ import webob
|
|||||||
from nova import context
|
from nova import context
|
||||||
from nova import exception
|
from nova import exception
|
||||||
from nova import flags
|
from nova import flags
|
||||||
|
from nova import test
|
||||||
from nova import utils
|
from nova import utils
|
||||||
import nova.api.openstack
|
import nova.api.openstack
|
||||||
from nova.api.openstack import images
|
from nova.api.openstack import images
|
||||||
@ -130,12 +130,13 @@ class BaseImageServiceTests(object):
|
|||||||
self.assertEquals(1, num_images)
|
self.assertEquals(1, num_images)
|
||||||
|
|
||||||
|
|
||||||
class LocalImageServiceTest(unittest.TestCase,
|
class LocalImageServiceTest(test.TestCase,
|
||||||
BaseImageServiceTests):
|
BaseImageServiceTests):
|
||||||
|
|
||||||
"""Tests the local image service"""
|
"""Tests the local image service"""
|
||||||
|
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
|
super(LocalImageServiceTest, self).setUp()
|
||||||
self.stubs = stubout.StubOutForTesting()
|
self.stubs = stubout.StubOutForTesting()
|
||||||
service_class = 'nova.image.local.LocalImageService'
|
service_class = 'nova.image.local.LocalImageService'
|
||||||
self.service = utils.import_object(service_class)
|
self.service = utils.import_object(service_class)
|
||||||
@ -145,14 +146,16 @@ class LocalImageServiceTest(unittest.TestCase,
|
|||||||
self.service.delete_all()
|
self.service.delete_all()
|
||||||
self.service.delete_imagedir()
|
self.service.delete_imagedir()
|
||||||
self.stubs.UnsetAll()
|
self.stubs.UnsetAll()
|
||||||
|
super(LocalImageServiceTest, self).tearDown()
|
||||||
|
|
||||||
|
|
||||||
class GlanceImageServiceTest(unittest.TestCase,
|
class GlanceImageServiceTest(test.TestCase,
|
||||||
BaseImageServiceTests):
|
BaseImageServiceTests):
|
||||||
|
|
||||||
"""Tests the local image service"""
|
"""Tests the local image service"""
|
||||||
|
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
|
super(GlanceImageServiceTest, self).setUp()
|
||||||
self.stubs = stubout.StubOutForTesting()
|
self.stubs = stubout.StubOutForTesting()
|
||||||
fakes.stub_out_glance(self.stubs)
|
fakes.stub_out_glance(self.stubs)
|
||||||
fakes.stub_out_compute_api_snapshot(self.stubs)
|
fakes.stub_out_compute_api_snapshot(self.stubs)
|
||||||
@ -163,9 +166,10 @@ class GlanceImageServiceTest(unittest.TestCase,
|
|||||||
|
|
||||||
def tearDown(self):
|
def tearDown(self):
|
||||||
self.stubs.UnsetAll()
|
self.stubs.UnsetAll()
|
||||||
|
super(GlanceImageServiceTest, self).tearDown()
|
||||||
|
|
||||||
|
|
||||||
class ImageControllerWithGlanceServiceTest(unittest.TestCase):
|
class ImageControllerWithGlanceServiceTest(test.TestCase):
|
||||||
|
|
||||||
"""Test of the OpenStack API /images application controller"""
|
"""Test of the OpenStack API /images application controller"""
|
||||||
|
|
||||||
@ -194,6 +198,7 @@ class ImageControllerWithGlanceServiceTest(unittest.TestCase):
|
|||||||
'image_type': 'ramdisk'}]
|
'image_type': 'ramdisk'}]
|
||||||
|
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
|
super(ImageControllerWithGlanceServiceTest, self).setUp()
|
||||||
self.orig_image_service = FLAGS.image_service
|
self.orig_image_service = FLAGS.image_service
|
||||||
FLAGS.image_service = 'nova.image.glance.GlanceImageService'
|
FLAGS.image_service = 'nova.image.glance.GlanceImageService'
|
||||||
self.stubs = stubout.StubOutForTesting()
|
self.stubs = stubout.StubOutForTesting()
|
||||||
@ -208,6 +213,7 @@ class ImageControllerWithGlanceServiceTest(unittest.TestCase):
|
|||||||
def tearDown(self):
|
def tearDown(self):
|
||||||
self.stubs.UnsetAll()
|
self.stubs.UnsetAll()
|
||||||
FLAGS.image_service = self.orig_image_service
|
FLAGS.image_service = self.orig_image_service
|
||||||
|
super(ImageControllerWithGlanceServiceTest, self).tearDown()
|
||||||
|
|
||||||
def test_get_image_index(self):
|
def test_get_image_index(self):
|
||||||
req = webob.Request.blank('/v1.0/images')
|
req = webob.Request.blank('/v1.0/images')
|
||||||
|
@ -1,15 +1,16 @@
|
|||||||
import httplib
|
import httplib
|
||||||
import StringIO
|
import StringIO
|
||||||
import time
|
import time
|
||||||
import unittest
|
|
||||||
import webob
|
import webob
|
||||||
|
|
||||||
|
from nova import test
|
||||||
import nova.api.openstack.ratelimiting as ratelimiting
|
import nova.api.openstack.ratelimiting as ratelimiting
|
||||||
|
|
||||||
|
|
||||||
class LimiterTest(unittest.TestCase):
|
class LimiterTest(test.TestCase):
|
||||||
|
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
|
super(LimiterTest, self).setUp()
|
||||||
self.limits = {
|
self.limits = {
|
||||||
'a': (5, ratelimiting.PER_SECOND),
|
'a': (5, ratelimiting.PER_SECOND),
|
||||||
'b': (5, ratelimiting.PER_MINUTE),
|
'b': (5, ratelimiting.PER_MINUTE),
|
||||||
@ -83,9 +84,10 @@ class FakeLimiter(object):
|
|||||||
return self._delay
|
return self._delay
|
||||||
|
|
||||||
|
|
||||||
class WSGIAppTest(unittest.TestCase):
|
class WSGIAppTest(test.TestCase):
|
||||||
|
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
|
super(WSGIAppTest, self).setUp()
|
||||||
self.limiter = FakeLimiter(self)
|
self.limiter = FakeLimiter(self)
|
||||||
self.app = ratelimiting.WSGIApp(self.limiter)
|
self.app = ratelimiting.WSGIApp(self.limiter)
|
||||||
|
|
||||||
@ -206,7 +208,7 @@ def wire_HTTPConnection_to_WSGI(host, app):
|
|||||||
httplib.HTTPConnection = HTTPConnectionDecorator(httplib.HTTPConnection)
|
httplib.HTTPConnection = HTTPConnectionDecorator(httplib.HTTPConnection)
|
||||||
|
|
||||||
|
|
||||||
class WSGIAppProxyTest(unittest.TestCase):
|
class WSGIAppProxyTest(test.TestCase):
|
||||||
|
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
"""Our WSGIAppProxy is going to call across an HTTPConnection to a
|
"""Our WSGIAppProxy is going to call across an HTTPConnection to a
|
||||||
@ -218,6 +220,7 @@ class WSGIAppProxyTest(unittest.TestCase):
|
|||||||
at the WSGIApp. And the limiter isn't real -- it's a fake that
|
at the WSGIApp. And the limiter isn't real -- it's a fake that
|
||||||
behaves the way we tell it to.
|
behaves the way we tell it to.
|
||||||
"""
|
"""
|
||||||
|
super(WSGIAppProxyTest, self).setUp()
|
||||||
self.limiter = FakeLimiter(self)
|
self.limiter = FakeLimiter(self)
|
||||||
app = ratelimiting.WSGIApp(self.limiter)
|
app = ratelimiting.WSGIApp(self.limiter)
|
||||||
wire_HTTPConnection_to_WSGI('100.100.100.100:80', app)
|
wire_HTTPConnection_to_WSGI('100.100.100.100:80', app)
|
||||||
@ -238,7 +241,3 @@ class WSGIAppProxyTest(unittest.TestCase):
|
|||||||
self.limiter.mock('murder', 'brutus', None)
|
self.limiter.mock('murder', 'brutus', None)
|
||||||
self.proxy.perform('stab', 'brutus')
|
self.proxy.perform('stab', 'brutus')
|
||||||
self.assertRaises(AssertionError, shouldRaise)
|
self.assertRaises(AssertionError, shouldRaise)
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
|
||||||
unittest.main()
|
|
||||||
|
@ -17,13 +17,13 @@
|
|||||||
|
|
||||||
import datetime
|
import datetime
|
||||||
import json
|
import json
|
||||||
import unittest
|
|
||||||
|
|
||||||
import stubout
|
import stubout
|
||||||
import webob
|
import webob
|
||||||
|
|
||||||
from nova import db
|
from nova import db
|
||||||
from nova import flags
|
from nova import flags
|
||||||
|
from nova import test
|
||||||
import nova.api.openstack
|
import nova.api.openstack
|
||||||
from nova.api.openstack import servers
|
from nova.api.openstack import servers
|
||||||
import nova.db.api
|
import nova.db.api
|
||||||
@ -113,9 +113,10 @@ def fake_compute_api(cls, req, id):
|
|||||||
return True
|
return True
|
||||||
|
|
||||||
|
|
||||||
class ServersTest(unittest.TestCase):
|
class ServersTest(test.TestCase):
|
||||||
|
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
|
super(ServersTest, self).setUp()
|
||||||
self.stubs = stubout.StubOutForTesting()
|
self.stubs = stubout.StubOutForTesting()
|
||||||
fakes.FakeAuthManager.auth_data = {}
|
fakes.FakeAuthManager.auth_data = {}
|
||||||
fakes.FakeAuthDatabase.data = {}
|
fakes.FakeAuthDatabase.data = {}
|
||||||
@ -146,6 +147,7 @@ class ServersTest(unittest.TestCase):
|
|||||||
def tearDown(self):
|
def tearDown(self):
|
||||||
self.stubs.UnsetAll()
|
self.stubs.UnsetAll()
|
||||||
FLAGS.allow_admin_api = self.allow_admin
|
FLAGS.allow_admin_api = self.allow_admin
|
||||||
|
super(ServersTest, self).tearDown()
|
||||||
|
|
||||||
def test_get_server_by_id(self):
|
def test_get_server_by_id(self):
|
||||||
req = webob.Request.blank('/v1.0/servers/1')
|
req = webob.Request.blank('/v1.0/servers/1')
|
||||||
@ -429,7 +431,3 @@ class ServersTest(unittest.TestCase):
|
|||||||
res = req.get_response(fakes.wsgi_app())
|
res = req.get_response(fakes.wsgi_app())
|
||||||
self.assertEqual(res.status, '202 Accepted')
|
self.assertEqual(res.status, '202 Accepted')
|
||||||
self.assertEqual(self.server_delete_called, True)
|
self.assertEqual(self.server_delete_called, True)
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
|
||||||
unittest.main()
|
|
||||||
|
@ -15,19 +15,20 @@
|
|||||||
# License for the specific language governing permissions and limitations
|
# License for the specific language governing permissions and limitations
|
||||||
# under the License.
|
# under the License.
|
||||||
|
|
||||||
import unittest
|
|
||||||
|
|
||||||
import stubout
|
import stubout
|
||||||
|
|
||||||
|
from nova import test
|
||||||
from nova.api.openstack import shared_ip_groups
|
from nova.api.openstack import shared_ip_groups
|
||||||
|
|
||||||
|
|
||||||
class SharedIpGroupsTest(unittest.TestCase):
|
class SharedIpGroupsTest(test.TestCase):
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
|
super(SharedIpGroupsTest, self).setUp()
|
||||||
self.stubs = stubout.StubOutForTesting()
|
self.stubs = stubout.StubOutForTesting()
|
||||||
|
|
||||||
def tearDown(self):
|
def tearDown(self):
|
||||||
self.stubs.UnsetAll()
|
self.stubs.UnsetAll()
|
||||||
|
super(SharedIpGroupsTest, self).tearDown()
|
||||||
|
|
||||||
def test_get_shared_ip_groups(self):
|
def test_get_shared_ip_groups(self):
|
||||||
pass
|
pass
|
||||||
|
@ -13,7 +13,6 @@
|
|||||||
# License for the specific language governing permissions and limitations
|
# License for the specific language governing permissions and limitations
|
||||||
# under the License.
|
# under the License.
|
||||||
|
|
||||||
import unittest
|
|
||||||
|
|
||||||
import stubout
|
import stubout
|
||||||
import webob
|
import webob
|
||||||
@ -22,6 +21,7 @@ import json
|
|||||||
import nova.db
|
import nova.db
|
||||||
from nova import context
|
from nova import context
|
||||||
from nova import flags
|
from nova import flags
|
||||||
|
from nova import test
|
||||||
from nova.api.openstack import zones
|
from nova.api.openstack import zones
|
||||||
from nova.tests.api.openstack import fakes
|
from nova.tests.api.openstack import fakes
|
||||||
|
|
||||||
@ -60,8 +60,9 @@ def zone_get_all(context):
|
|||||||
password='qwerty')]
|
password='qwerty')]
|
||||||
|
|
||||||
|
|
||||||
class ZonesTest(unittest.TestCase):
|
class ZonesTest(test.TestCase):
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
|
super(ZonesTest, self).setUp()
|
||||||
self.stubs = stubout.StubOutForTesting()
|
self.stubs = stubout.StubOutForTesting()
|
||||||
fakes.FakeAuthManager.auth_data = {}
|
fakes.FakeAuthManager.auth_data = {}
|
||||||
fakes.FakeAuthDatabase.data = {}
|
fakes.FakeAuthDatabase.data = {}
|
||||||
@ -81,6 +82,7 @@ class ZonesTest(unittest.TestCase):
|
|||||||
def tearDown(self):
|
def tearDown(self):
|
||||||
self.stubs.UnsetAll()
|
self.stubs.UnsetAll()
|
||||||
FLAGS.allow_admin_api = self.allow_admin
|
FLAGS.allow_admin_api = self.allow_admin
|
||||||
|
super(ZonesTest, self).tearDown()
|
||||||
|
|
||||||
def test_get_zone_list(self):
|
def test_get_zone_list(self):
|
||||||
req = webob.Request.blank('/v1.0/zones')
|
req = webob.Request.blank('/v1.0/zones')
|
||||||
@ -134,7 +136,3 @@ class ZonesTest(unittest.TestCase):
|
|||||||
self.assertEqual(res_dict['zone']['id'], 1)
|
self.assertEqual(res_dict['zone']['id'], 1)
|
||||||
self.assertEqual(res_dict['zone']['api_url'], 'http://foo.com')
|
self.assertEqual(res_dict['zone']['api_url'], 'http://foo.com')
|
||||||
self.assertFalse('username' in res_dict['zone'])
|
self.assertFalse('username' in res_dict['zone'])
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
|
||||||
unittest.main()
|
|
||||||
|
@ -21,7 +21,7 @@
|
|||||||
Test WSGI basics and provide some helper functions for other WSGI tests.
|
Test WSGI basics and provide some helper functions for other WSGI tests.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
import unittest
|
from nova import test
|
||||||
|
|
||||||
import routes
|
import routes
|
||||||
import webob
|
import webob
|
||||||
@ -29,7 +29,7 @@ import webob
|
|||||||
from nova import wsgi
|
from nova import wsgi
|
||||||
|
|
||||||
|
|
||||||
class Test(unittest.TestCase):
|
class Test(test.TestCase):
|
||||||
|
|
||||||
def test_debug(self):
|
def test_debug(self):
|
||||||
|
|
||||||
@ -92,7 +92,7 @@ class Test(unittest.TestCase):
|
|||||||
self.assertNotEqual(result.body, "123")
|
self.assertNotEqual(result.body, "123")
|
||||||
|
|
||||||
|
|
||||||
class SerializerTest(unittest.TestCase):
|
class SerializerTest(test.TestCase):
|
||||||
|
|
||||||
def match(self, url, accept, expect):
|
def match(self, url, accept, expect):
|
||||||
input_dict = dict(servers=dict(a=(2, 3)))
|
input_dict = dict(servers=dict(a=(2, 3)))
|
||||||
|
@ -29,8 +29,8 @@ FLAGS.auth_driver = 'nova.auth.dbdriver.DbDriver'
|
|||||||
flags.DECLARE('network_size', 'nova.network.manager')
|
flags.DECLARE('network_size', 'nova.network.manager')
|
||||||
flags.DECLARE('num_networks', 'nova.network.manager')
|
flags.DECLARE('num_networks', 'nova.network.manager')
|
||||||
flags.DECLARE('fake_network', 'nova.network.manager')
|
flags.DECLARE('fake_network', 'nova.network.manager')
|
||||||
FLAGS.network_size = 16
|
FLAGS.network_size = 8
|
||||||
FLAGS.num_networks = 5
|
FLAGS.num_networks = 2
|
||||||
FLAGS.fake_network = True
|
FLAGS.fake_network = True
|
||||||
flags.DECLARE('num_shelves', 'nova.volume.driver')
|
flags.DECLARE('num_shelves', 'nova.volume.driver')
|
||||||
flags.DECLARE('blades_per_shelf', 'nova.volume.driver')
|
flags.DECLARE('blades_per_shelf', 'nova.volume.driver')
|
||||||
@ -39,5 +39,5 @@ FLAGS.num_shelves = 2
|
|||||||
FLAGS.blades_per_shelf = 4
|
FLAGS.blades_per_shelf = 4
|
||||||
FLAGS.iscsi_num_targets = 8
|
FLAGS.iscsi_num_targets = 8
|
||||||
FLAGS.verbose = True
|
FLAGS.verbose = True
|
||||||
FLAGS.sql_connection = 'sqlite:///tests.sqlite'
|
FLAGS.sqlite_db = "tests.sqlite"
|
||||||
FLAGS.use_ipv6 = True
|
FLAGS.use_ipv6 = True
|
||||||
|
@ -311,4 +311,5 @@ class S3APITestCase(test.TestCase):
|
|||||||
self.auth_manager.delete_user('admin')
|
self.auth_manager.delete_user('admin')
|
||||||
self.auth_manager.delete_project('admin')
|
self.auth_manager.delete_project('admin')
|
||||||
stop_listening = defer.maybeDeferred(self.listening_port.stopListening)
|
stop_listening = defer.maybeDeferred(self.listening_port.stopListening)
|
||||||
|
super(S3APITestCase, self).tearDown()
|
||||||
return defer.DeferredList([stop_listening])
|
return defer.DeferredList([stop_listening])
|
||||||
|
@ -52,6 +52,7 @@ class DirectTestCase(test.TestCase):
|
|||||||
|
|
||||||
def tearDown(self):
|
def tearDown(self):
|
||||||
direct.ROUTES = {}
|
direct.ROUTES = {}
|
||||||
|
super(DirectTestCase, self).tearDown()
|
||||||
|
|
||||||
def test_delegated_auth(self):
|
def test_delegated_auth(self):
|
||||||
req = webob.Request.blank('/fake/context')
|
req = webob.Request.blank('/fake/context')
|
||||||
|
@ -42,15 +42,13 @@ class NetworkTestCase(test.TestCase):
|
|||||||
# flags in the corresponding section in nova-dhcpbridge
|
# flags in the corresponding section in nova-dhcpbridge
|
||||||
self.flags(connection_type='fake',
|
self.flags(connection_type='fake',
|
||||||
fake_call=True,
|
fake_call=True,
|
||||||
fake_network=True,
|
fake_network=True)
|
||||||
network_size=16,
|
|
||||||
num_networks=5)
|
|
||||||
self.manager = manager.AuthManager()
|
self.manager = manager.AuthManager()
|
||||||
self.user = self.manager.create_user('netuser', 'netuser', 'netuser')
|
self.user = self.manager.create_user('netuser', 'netuser', 'netuser')
|
||||||
self.projects = []
|
self.projects = []
|
||||||
self.network = utils.import_object(FLAGS.network_manager)
|
self.network = utils.import_object(FLAGS.network_manager)
|
||||||
self.context = context.RequestContext(project=None, user=self.user)
|
self.context = context.RequestContext(project=None, user=self.user)
|
||||||
for i in range(5):
|
for i in range(FLAGS.num_networks):
|
||||||
name = 'project%s' % i
|
name = 'project%s' % i
|
||||||
project = self.manager.create_project(name, 'netuser', name)
|
project = self.manager.create_project(name, 'netuser', name)
|
||||||
self.projects.append(project)
|
self.projects.append(project)
|
||||||
@ -195,7 +193,7 @@ class NetworkTestCase(test.TestCase):
|
|||||||
first = self._create_address(0)
|
first = self._create_address(0)
|
||||||
lease_ip(first)
|
lease_ip(first)
|
||||||
instance_ids = []
|
instance_ids = []
|
||||||
for i in range(1, 5):
|
for i in range(1, FLAGS.num_networks):
|
||||||
instance_ref = self._create_instance(i, mac=utils.generate_mac())
|
instance_ref = self._create_instance(i, mac=utils.generate_mac())
|
||||||
instance_ids.append(instance_ref['id'])
|
instance_ids.append(instance_ref['id'])
|
||||||
address = self._create_address(i, instance_ref['id'])
|
address = self._create_address(i, instance_ref['id'])
|
||||||
|
@ -207,9 +207,9 @@ class LibvirtConnTestCase(test.TestCase):
|
|||||||
db.instance_destroy(user_context, instance_ref['id'])
|
db.instance_destroy(user_context, instance_ref['id'])
|
||||||
|
|
||||||
def tearDown(self):
|
def tearDown(self):
|
||||||
super(LibvirtConnTestCase, self).tearDown()
|
|
||||||
self.manager.delete_project(self.project)
|
self.manager.delete_project(self.project)
|
||||||
self.manager.delete_user(self.user)
|
self.manager.delete_user(self.user)
|
||||||
|
super(LibvirtConnTestCase, self).tearDown()
|
||||||
|
|
||||||
|
|
||||||
class IptablesFirewallTestCase(test.TestCase):
|
class IptablesFirewallTestCase(test.TestCase):
|
||||||
@ -390,6 +390,7 @@ class NWFilterTestCase(test.TestCase):
|
|||||||
def tearDown(self):
|
def tearDown(self):
|
||||||
self.manager.delete_project(self.project)
|
self.manager.delete_project(self.project)
|
||||||
self.manager.delete_user(self.user)
|
self.manager.delete_user(self.user)
|
||||||
|
super(NWFilterTestCase, self).tearDown()
|
||||||
|
|
||||||
def test_cidr_rule_nwfilter_xml(self):
|
def test_cidr_rule_nwfilter_xml(self):
|
||||||
cloud_controller = cloud.CloudController()
|
cloud_controller = cloud.CloudController()
|
||||||
|
@ -61,8 +61,8 @@ import unittest
|
|||||||
import sys
|
import sys
|
||||||
|
|
||||||
from nose import config
|
from nose import config
|
||||||
from nose import result
|
|
||||||
from nose import core
|
from nose import core
|
||||||
|
from nose import result
|
||||||
|
|
||||||
from nova import log as logging
|
from nova import log as logging
|
||||||
from nova.tests import fake_flags
|
from nova.tests import fake_flags
|
||||||
@ -280,10 +280,6 @@ class NovaTestRunner(core.TextTestRunner):
|
|||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
logging.setup()
|
logging.setup()
|
||||||
testdir = os.path.abspath(os.path.join("nova", "tests"))
|
|
||||||
testdb = os.path.join(testdir, "tests.sqlite")
|
|
||||||
if os.path.exists(testdb):
|
|
||||||
os.unlink(testdb)
|
|
||||||
# If any argument looks like a test name but doesn't have "nova.tests" in
|
# 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
|
# front of it, automatically add that so we don't have to type as much
|
||||||
argv = []
|
argv = []
|
||||||
@ -293,6 +289,7 @@ if __name__ == '__main__':
|
|||||||
else:
|
else:
|
||||||
argv.append(x)
|
argv.append(x)
|
||||||
|
|
||||||
|
testdir = os.path.abspath(os.path.join("nova", "tests"))
|
||||||
c = config.Config(stream=sys.stdout,
|
c = config.Config(stream=sys.stdout,
|
||||||
env=os.environ,
|
env=os.environ,
|
||||||
verbosity=3,
|
verbosity=3,
|
||||||
|
Loading…
Reference in New Issue
Block a user