Enable running tests via testr

This also disables the functional tests from running. The code is still
left here for posterity. These are intended to be moved into tempest
test cases and thus will be removed entirely at that time.

Change-Id: I294671baead6e83a8312b41681e99d395f861209
This commit is contained in:
Clint Byrum 2013-04-24 17:30:35 -07:00
parent 36dea3a747
commit 8b8525260d
27 changed files with 76 additions and 68 deletions

4
.testr.conf Normal file
View File

@ -0,0 +1,4 @@
[DEFAULT]
test_command=${PYTHON:-python} -m subunit.run discover -t ./ . $LISTOPT $IDOPTION
test_id_option=--load-list $IDFILE
test_list_option=--list

View File

@ -16,21 +16,3 @@
# The code below enables nosetests to work with i18n _() blocks
import __builtin__
setattr(__builtin__, '_', lambda x: x)
import os
from heat.db.sqlalchemy.session import get_engine
def reset_db():
if os.path.exists('heat-test.db'):
os.remove('heat-test.db')
def setup():
from heat.db import migration
reset_db()
migration.db_sync()
engine = get_engine()
conn = engine.connect()

View File

@ -1,13 +0,0 @@
# vim: tabstop=4 shiftwidth=4 softtabstop=4
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.

View File

@ -32,6 +32,7 @@ from heat.engine import parser
from heat.engine import scheduler
from heat.engine.resource import Metadata
from heat.openstack.common import timeutils
from heat.tests.utils import setup_dummy_db
@attr(tag=['unit', 'resource'])
@ -39,10 +40,10 @@ from heat.openstack.common import timeutils
class AutoScalingTest(unittest.TestCase):
def setUp(self):
self.m = mox.Mox()
setup_dummy_db()
def tearDown(self):
self.m.UnsetStubs()
print "AutoScalingTest teardown complete"
def load_template(self):
self.path = os.path.dirname(os.path.realpath(__file__)).\

View File

@ -26,6 +26,7 @@ from heat.engine.resources import eip
from heat.engine import parser
from heat.engine import scheduler
from heat.tests.v1_1 import fakes
from heat.tests.utils import setup_dummy_db
@attr(tag=['unit', 'resource'])
@ -37,10 +38,10 @@ class EIPTest(unittest.TestCase):
self.m.StubOutWithMock(eip.ElasticIp, 'nova')
self.m.StubOutWithMock(eip.ElasticIpAssociation, 'nova')
self.m.StubOutWithMock(self.fc.servers, 'get')
setup_dummy_db()
def tearDown(self):
self.m.UnsetStubs()
print "EIPTest teardown complete"
def load_template(self):
self.path = os.path.dirname(os.path.realpath(__file__)).\

View File

@ -34,6 +34,7 @@ from heat.engine.properties import Properties
from heat.engine.resources import instance as instances
from heat.engine import watchrule
from heat.openstack.common import threadgroup
from heat.tests.utils import setup_dummy_db
tests_dir = os.path.dirname(os.path.realpath(__file__))
@ -108,10 +109,10 @@ class DummyThreadGroup(object):
class stackCreateTest(unittest.TestCase):
def setUp(self):
self.m = mox.Mox()
setup_dummy_db()
def tearDown(self):
self.m.UnsetStubs()
print "stackTest teardown complete"
def test_wordpress_single_instance_stack_create(self):
stack = get_wordpress_stack('test_stack', create_context(self.m))
@ -158,6 +159,7 @@ class stackServiceCreateUpdateDeleteTest(unittest.TestCase):
self.m = mox.Mox()
self.username = 'stack_service_create_test_user'
self.tenant = 'stack_service_create_test_tenant'
setup_dummy_db()
self.ctx = create_context(self.m, self.username, self.tenant)
self.man = service.EngineService('a-host', 'a-topic')
@ -436,6 +438,7 @@ class stackServiceTest(unittest.TestCase):
def setUp(self):
self.m = mox.Mox()
setup_dummy_db()
self.ctx = create_context(self.m, self.username, self.tenant)
setup_mocks(self.m, self.stack)
self.m.ReplayAll()

View File

@ -24,6 +24,7 @@ from heat.engine import resource
from heat.engine import template
from heat.engine import event
from heat.tests.utils import setup_dummy_db
from heat.tests import generic_resource as generic_rsrc
@ -46,6 +47,7 @@ class EventTest(unittest.TestCase):
self.m = mox.Mox()
setup_dummy_db()
self.ctx = context.get_admin_context()
self.m.StubOutWithMock(self.ctx, 'username')
self.ctx.username = self.username

View File

@ -27,6 +27,7 @@ from heat.common import template_format
from heat.engine import parser
from heat.engine import scheduler
from heat.openstack.common import uuidutils
from heat.tests.utils import setup_dummy_db
@attr(tag=['unit', 'resource', 'instance'])
@ -37,10 +38,10 @@ class instancesTest(unittest.TestCase):
self.fc = fakes.FakeClient()
self.path = os.path.dirname(os.path.realpath(__file__)).\
replace('heat/tests', 'templates')
setup_dummy_db()
def tearDown(self):
self.m.UnsetStubs()
print "instancesTest teardown complete"
def test_instance_create(self):
f = open("%s/WordPress_Single_Instance_gold.template" % self.path)

View File

@ -30,6 +30,7 @@ from heat.engine.resources import instance
from heat.engine.resources import loadbalancer
from heat.engine import parser
from heat.engine import scheduler
from heat.tests.utils import setup_dummy_db
@attr(tag=['unit', 'resource'])
@ -39,10 +40,10 @@ class InstanceGroupTest(unittest.TestCase):
self.fc = fakes.FakeClient()
self.m = mox.Mox()
self.m.StubOutWithMock(loadbalancer.LoadBalancer, 'reload')
setup_dummy_db()
def tearDown(self):
self.m.UnsetStubs()
print "InstanceGroupTest teardown complete"
def load_template(self):
self.path = os.path.dirname(os.path.realpath(__file__)).\

View File

@ -33,6 +33,7 @@ from heat.engine.resources import user
from heat.engine.resources import loadbalancer as lb
from heat.engine.resources import wait_condition as wc
from heat.engine.resource import Metadata
from heat.tests.utils import setup_dummy_db
from heat.tests.v1_1 import fakes
from heat.tests import fakes as test_fakes
@ -63,6 +64,7 @@ class LoadBalancerTest(unittest.TestCase):
cfg.CONF.set_default('heat_waitcondition_server_url',
'http://127.0.0.1:8000/v1/waitcondition')
setup_dummy_db()
def tearDown(self):
self.m.UnsetStubs()

View File

@ -21,6 +21,7 @@ from nose.plugins.attrib import attr
from oslo.config import cfg
from heat.tests import fakes
from heat.tests.utils import setup_dummy_db
from heat.tests.utils import stack_delete_after
from heat.common import identifier
@ -129,6 +130,7 @@ class MetadataRefreshTest(unittest.TestCase):
self.m = mox.Mox()
self.m.StubOutWithMock(eventlet, 'sleep')
self.fc = fakes.FakeKeystoneClient()
setup_dummy_db()
def tearDown(self):
self.m.UnsetStubs()
@ -189,6 +191,7 @@ class MetadataRefreshTest(unittest.TestCase):
class WaitCondMetadataUpdateTest(unittest.TestCase):
def setUp(self):
self.m = mox.Mox()
setup_dummy_db()
self.ctx = context.get_admin_context()
self.ctx.tenant_id = 'test_tenant'
self.fc = fakes.FakeKeystoneClient()

View File

@ -24,6 +24,7 @@ from heat.common import template_format
from heat.engine import parser
from heat.engine.resources import stack as nested_stack
from heat.common import urlfetch
from heat.tests.utils import setup_dummy_db
@attr(tag=['unit', 'resource'])
@ -50,6 +51,7 @@ Outputs:
def setUp(self):
self.m = mox.Mox()
self.m.StubOutWithMock(urlfetch, 'get')
setup_dummy_db()
def tearDown(self):
self.m.UnsetStubs()

View File

@ -26,6 +26,7 @@ from heat.common import template_format
from heat.engine import parser
from heat.engine import scheduler
from heat.openstack.common import uuidutils
from heat.tests.utils import setup_dummy_db
@attr(tag=['unit', 'resource', 'instance'])
@ -36,10 +37,10 @@ class nokeyTest(unittest.TestCase):
self.fc = fakes.FakeClient()
self.path = os.path.dirname(os.path.realpath(__file__)).\
replace('heat/tests', 'templates')
setup_dummy_db()
def tearDown(self):
self.m.UnsetStubs()
print "nokeyTest teardown complete"
def test_nokey_create(self):
f = open("%s/WordPress_NoKey.template" % self.path)

View File

@ -26,6 +26,7 @@ from heat.engine import parser
from heat.engine import parameters
from heat.engine import template
from heat.tests.utils import setup_dummy_db
from heat.tests.utils import stack_delete_after
from heat.tests import generic_resource as generic_rsrc
@ -300,6 +301,7 @@ class StackTest(unittest.TestCase):
self.m = mox.Mox()
setup_dummy_db()
self.ctx = context.get_admin_context()
self.m.StubOutWithMock(self.ctx, 'username')
self.ctx.username = self.username

View File

@ -31,6 +31,7 @@ from heat.engine.resources.quantum import floatingip
from heat.engine.resources.quantum import port
from heat.engine.resources.quantum.quantum import QuantumResource as qr
from heat.engine import parser
from heat.tests.utils import setup_dummy_db
class FakeQuantum():
@ -103,10 +104,10 @@ class QuantumTest(unittest.TestCase):
def setUp(self):
self.m = mox.Mox()
self.m.StubOutWithMock(net.Net, 'quantum')
setup_dummy_db()
def tearDown(self):
self.m.UnsetStubs()
print "QuantumTest teardown complete"
def load_template(self):
self.path = os.path.dirname(os.path.realpath(__file__)).\
@ -211,6 +212,7 @@ class QuantumFloatingIPTest(unittest.TestCase):
self.m.StubOutWithMock(floatingip.FloatingIP, 'quantum')
self.m.StubOutWithMock(floatingip.FloatingIPAssociation, 'quantum')
self.m.StubOutWithMock(port.Port, 'quantum')
setup_dummy_db()
def tearDown(self):
self.m.UnsetStubs()

View File

@ -25,6 +25,7 @@ from heat.engine import scheduler
from heat.openstack.common import uuidutils
from heat.tests import generic_resource as generic_rsrc
from heat.tests.utils import setup_dummy_db
@attr(tag=['unit', 'resource'])
@ -32,6 +33,7 @@ from heat.tests import generic_resource as generic_rsrc
class ResourceTest(unittest.TestCase):
def setUp(self):
self.m = mox.Mox()
setup_dummy_db()
self.stack = parser.Stack(None, 'test_stack', parser.Template({}),
stack_id=uuidutils.generate_uuid())
@ -322,6 +324,7 @@ class MetadataTest(unittest.TestCase):
'Type': 'Foo',
'Metadata': {'Test': 'Initial metadata'}
}
setup_dummy_db()
ctx = context.get_admin_context()
self.m.StubOutWithMock(ctx, 'username')
ctx.username = 'metadata_test_user'

View File

@ -27,7 +27,8 @@ from heat.openstack.common.importutils import try_import
from heat.engine.resources import s3
from heat.engine import parser
from heat.engine import scheduler
from utils import skip_if
from heat.tests.utils import setup_dummy_db
from heat.tests.utils import skip_if
swiftclient = try_import('swiftclient.client')
@ -44,10 +45,10 @@ class s3Test(unittest.TestCase):
self.m.StubOutWithMock(swiftclient.Connection, 'get_auth')
self.container_pattern = 'test_stack-test_resource-[0-9a-z]+'
setup_dummy_db()
def tearDown(self):
self.m.UnsetStubs()
print "s3Test teardown complete"
def load_template(self):
self.path = os.path.dirname(os.path.realpath(__file__)).\

View File

@ -22,6 +22,7 @@ from heat.engine import clients
from heat.common import context
from heat.common import template_format
from heat.engine import parser
from heat.tests.utils import setup_dummy_db
from heat.tests.v1_1 import fakes
from novaclient.v1_1 import security_groups as nova_sg
@ -68,6 +69,7 @@ Resources:
self.m.StubOutWithMock(nova_sg.SecurityGroupManager, 'delete')
self.m.StubOutWithMock(nova_sg.SecurityGroupManager, 'get')
self.m.StubOutWithMock(nova_sg.SecurityGroupManager, 'list')
setup_dummy_db()
def tearDown(self):
self.m.UnsetStubs()

View File

@ -27,6 +27,7 @@ from heat.openstack.common.importutils import try_import
from heat.engine.resources import swift
from heat.engine import parser
from heat.engine import scheduler
from heat.tests.utils import setup_dummy_db
from heat.tests.utils import skip_if
swiftclient = try_import('swiftclient.client')
@ -45,10 +46,10 @@ class swiftTest(unittest.TestCase):
self.m.StubOutWithMock(swiftclient.Connection, 'get_auth')
self.container_pattern = 'test_stack-test_resource-[0-9a-z]+'
setup_dummy_db()
def tearDown(self):
self.m.UnsetStubs()
print "swiftTest teardown complete"
def load_template(self):
self.path = os.path.dirname(os.path.realpath(__file__)).\

View File

@ -21,6 +21,7 @@ from heat.engine import clients
from heat.common import context
from heat.common import template_format
from heat.engine import parser
from heat.tests.utils import setup_dummy_db
@attr(tag=['unit'])
@ -99,6 +100,7 @@ class JsonYamlResolvedCompareTest(unittest.TestCase):
def setUp(self):
self.longMessage = True
self.maxDiff = None
setup_dummy_db()
def load_template(self, file_name):
self.path = os.path.dirname(os.path.realpath(__file__)).\

View File

@ -28,22 +28,26 @@ from heat.engine import parser
from heat.engine import scheduler
from heat.engine.resources import user
from heat.tests import fakes
from heat.tests.utils import setup_dummy_db
import keystoneclient.exceptions
@attr(tag=['unit', 'resource', 'User'])
@attr(speed='fast')
class UserTest(unittest.TestCase):
class UserPolicyTestCase(unittest.TestCase):
def setUp(self):
config.register_engine_opts()
self.m = mox.Mox()
self.fc = fakes.FakeKeystoneClient(username='test_stack.CfnUser')
cfg.CONF.set_default('heat_stack_user_role', 'stack_user_role')
setup_dummy_db()
def tearDown(self):
self.m.UnsetStubs()
print "UserTest teardown complete"
@attr(tag=['unit', 'resource', 'User'])
@attr(speed='fast')
class UserTest(UserPolicyTestCase):
def load_template(self, template_name='Rails_Single_Instance.template'):
self.path = os.path.dirname(os.path.realpath(__file__)).\
@ -226,16 +230,7 @@ class UserTest(unittest.TestCase):
@attr(tag=['unit', 'resource', 'AccessKey'])
@attr(speed='fast')
class AccessKeyTest(unittest.TestCase):
def setUp(self):
config.register_engine_opts()
self.m = mox.Mox()
self.fc = fakes.FakeKeystoneClient(username='test_stack.CfnUser')
cfg.CONF.set_default('heat_stack_user_role', 'stack_user_role')
def tearDown(self):
self.m.UnsetStubs()
print "AccessKey teardown complete"
class AccessKeyTest(UserPolicyTestCase):
def load_template(self):
self.path = os.path.dirname(os.path.realpath(__file__)).\
@ -345,15 +340,7 @@ class AccessKeyTest(unittest.TestCase):
@attr(tag=['unit', 'resource', 'AccessPolicy'])
@attr(speed='fast')
class AccessPolicyTest(unittest.TestCase):
def setUp(self):
self.m = mox.Mox()
self.fc = fakes.FakeKeystoneClient(username='test_stack.CfnUser')
cfg.CONF.set_default('heat_stack_user_role', 'stack_user_role')
def tearDown(self):
self.m.UnsetStubs()
print "UserTest teardown complete"
class AccessPolicyTest(UserPolicyTestCase):
def load_template(self):
template_name =\

View File

@ -25,6 +25,7 @@ from heat.engine.resources import instance as instances
from heat.engine import service
import heat.db.api as db_api
from heat.engine import parser
from heat.tests.utils import setup_dummy_db
test_template_volumeattach = '''
{
@ -272,10 +273,10 @@ class validateTest(unittest.TestCase):
def setUp(self):
self.m = mox.Mox()
self.fc = fakes.FakeClient()
setup_dummy_db()
def tearDown(self):
self.m.UnsetStubs()
print "volumeTest teardown complete"
def test_validate_volumeattach_valid(self):
t = template_format.parse(test_template_volumeattach % 'vdq')
@ -311,7 +312,6 @@ class validateTest(unittest.TestCase):
engine = service.EngineService('a', 't')
res = dict(engine.validate_template(None, t))
print 'res %s' % res
self.assertEqual(res['Description'], 'test.')
def test_validate_ref_invalid(self):

View File

@ -29,6 +29,7 @@ from heat.engine import scheduler
from heat.engine.resources import volume as vol
from heat.engine import clients
from heat.tests.v1_1 import fakes
from heat.tests.utils import setup_dummy_db
@attr(tag=['unit', 'resource', 'volume'])
@ -45,6 +46,7 @@ class VolumeTest(unittest.TestCase):
self.m.StubOutWithMock(self.fc.volumes, 'create_server_volume')
self.m.StubOutWithMock(self.fc.volumes, 'delete_server_volume')
self.m.StubOutWithMock(eventlet, 'sleep')
setup_dummy_db()
def tearDown(self):
self.m.UnsetStubs()

View File

@ -22,6 +22,7 @@ from heat.common import context
from heat.common import exception
from heat.common import template_format
from heat.engine import parser
from heat.tests.utils import setup_dummy_db
try:
from quantumclient.common.exceptions import QuantumClientException
@ -34,6 +35,7 @@ except ImportError:
class VPCTestBase(unittest.TestCase):
def setUp(self):
setup_dummy_db()
self.m = mox.Mox()
self.m.StubOutWithMock(quantumclient.Client, 'add_interface_router')
self.m.StubOutWithMock(quantumclient.Client, 'add_gateway_router')

View File

@ -25,6 +25,7 @@ import unittest
from heat.tests import fakes
from heat.tests.utils import stack_delete_after
from heat.tests.utils import setup_dummy_db
import heat.db.api as db_api
from heat.common import template_format
@ -79,8 +80,10 @@ test_template_wc_count = '''
@attr(tag=['unit', 'resource', 'WaitCondition'])
@attr(speed='slow')
class WaitConditionTest(unittest.TestCase):
def setUp(self):
config.register_engine_opts()
setup_dummy_db()
self.m = mox.Mox()
self.m.StubOutWithMock(wc.WaitConditionHandle,
'get_status')
@ -389,6 +392,7 @@ class WaitConditionHandleTest(unittest.TestCase):
'http://127.0.0.1:8000/v1/waitcondition')
self.fc = fakes.FakeKeystoneClient()
setup_dummy_db()
self.stack = self.create_stack()
def tearDown(self):

View File

@ -23,6 +23,7 @@ import heat.db.api as db_api
from heat.openstack.common import timeutils
from heat.engine import watchrule
from heat.engine import parser
from heat.tests import utils
class WatchData:
@ -44,6 +45,7 @@ class WatchRuleTest(unittest.TestCase):
def setUpClass(cls):
# Create a dummy stack in the DB as WatchRule instances
# must be associated with a stack
utils.setup_dummy_db()
ctx = context.get_admin_context()
ctx.username = 'dummyuser'
ctx.tenant_id = '123456'

View File

@ -14,6 +14,8 @@
import nose.plugins.skip as skip
from heat.db.sqlalchemy.session import get_engine
from heat.db import migration
class skip_test(object):
@ -70,7 +72,7 @@ def stack_delete_after(test_fn):
to ensure tests clean up their stacks regardless of test success/failure
"""
def wrapped_test(test_cls):
print "Running test", test_fn.__name__
#print "Running test", test_fn.__name__
try:
test_fn(test_cls)
finally:
@ -78,5 +80,11 @@ def stack_delete_after(test_fn):
test_cls.stack.delete()
except AttributeError:
print "Could not delete stack (already deleted?)"
print "Exited", test_fn.__name__
#print "Exited", test_fn.__name__
return wrapped_test
def setup_dummy_db():
migration.db_sync()
engine = get_engine()
conn = engine.connect()