Merge remote-tracking branch 'upstream/master'

This commit is contained in:
Raghu Rao 2013-08-13 16:45:20 -05:00
commit a078990aa5
22 changed files with 220 additions and 92 deletions

1
.gitignore vendored
View File

@ -1,4 +1,5 @@
.idea/ .idea/
.venv/
*.pyc *.pyc
local_settings.py local_settings.py

View File

@ -6,3 +6,4 @@ librabbitmq>=1.0.0
prettytable>=0.7.2 prettytable>=0.7.2
argparse argparse
Pympler Pympler
requests

4
etc/test-requires.txt Normal file
View File

@ -0,0 +1,4 @@
nose
coverage
mox
nose-exclude

View File

@ -33,16 +33,21 @@ from stacktach import models
from stacktach.reconciler import Reconciler from stacktach.reconciler import Reconciler
OLD_LAUNCHES_QUERY = """ OLD_LAUNCHES_QUERY = """
select * from stacktach_instanceusage where select stacktach_instanceusage.id,
launched_at is not null and stacktach_instanceusage.instance,
launched_at < %s and stacktach_instanceusage.launched_at from stacktach_instanceusage
instance not in left outer join stacktach_instancedeletes on
(select distinct(instance) stacktach_instanceusage.instance = stacktach_instancedeletes.instance
from stacktach_instancedeletes where left outer join stacktach_instancereconcile on
deleted_at < %s union stacktach_instanceusage.instance = stacktach_instancereconcile.instance
select distinct(instance) where (
from stacktach_instancereconcile where stacktach_instancereconcile.deleted_at is null and (
deleted_at < %s);""" stacktach_instancedeletes.deleted_at is null or
stacktach_instancedeletes.deleted_at > %s
)
or (stacktach_instancereconcile.deleted_at is not null and
stacktach_instancereconcile.deleted_at > %s)
) and stacktach_instanceusage.launched_at < %s;"""
reconciler = None reconciler = None

7
run_tests_venv.sh Executable file
View File

@ -0,0 +1,7 @@
#!/bin/sh
virtualenv .venv
. .venv/bin/activate
pip install -r etc/pip-requires.txt
pip install -r etc/test-requires.txt
nosetests tests --exclude-dir=stacktach --with-coverage --cover-package=stacktach,worker,verifier --cover-erase

View File

@ -290,6 +290,10 @@ def get_db_objects(klass, request, default_order_by, direction='desc',
offset = request.GET.get('offset') offset = request.GET.get('offset')
limit = request.GET.get('limit', DEFAULT_LIMIT) limit = request.GET.get('limit', DEFAULT_LIMIT)
if limit:
limit = int(limit)
if limit > HARD_LIMIT: if limit > HARD_LIMIT:
limit = HARD_LIMIT limit = HARD_LIMIT
if offset: if offset:

View File

@ -95,6 +95,7 @@ class GlanceNotification(Notification):
def __init__(self, body, deployment, routing_key, json): def __init__(self, body, deployment, routing_key, json):
super(GlanceNotification, self).__init__(body, deployment, super(GlanceNotification, self).__init__(body, deployment,
routing_key, json) routing_key, json)
if isinstance(self.payload, dict):
self.properties = self.payload.get('properties', {}) self.properties = self.payload.get('properties', {})
self.image_type = image_type.get_numeric_code(self.payload) self.image_type = image_type.get_numeric_code(self.payload)
self.status = self.payload.get('status', None) self.status = self.payload.get('status', None)
@ -110,10 +111,22 @@ class GlanceNotification(Notification):
'audit_period_ending', None) 'audit_period_ending', None)
self.audit_period_ending = audit_period_ending and \ self.audit_period_ending = audit_period_ending and \
utils.str_time_to_unix(audit_period_ending) utils.str_time_to_unix(audit_period_ending)
else:
self.properties = {}
self.image_type = None
self.status = None
self.uuid = None
self.size = None
self.created_at = None
self.audit_period_beginning = None
self.audit_period_ending = None
@property @property
def owner(self): def owner(self):
if isinstance(self.payload, dict):
return self.payload.get('owner', None) return self.payload.get('owner', None)
else:
return None
@property @property
def instance(self): def instance(self):
@ -121,7 +134,10 @@ class GlanceNotification(Notification):
@property @property
def deleted_at(self): def deleted_at(self):
deleted_at = self.body.get('deleted_at', None) deleted_at = self.body.get('deleted_at', None)
if isinstance(self.payload, dict):
deleted_at = deleted_at or self.payload.get('deleted_at', None) deleted_at = deleted_at or self.payload.get('deleted_at', None)
return deleted_at and utils.str_time_to_unix(deleted_at) return deleted_at and utils.str_time_to_unix(deleted_at)
def save(self): def save(self):

View File

@ -98,7 +98,7 @@ def _configure(logger, name):
class ExchangeLogger(): class ExchangeLogger():
def __init__(self, exchange, name='stacktach-default'): def __init__(self, exchange, name='stacktach-default'):
self.logger = logging.getLogger(name) self.logger = logging.getLogger(__name__)
_configure(self.logger, name) _configure(self.logger, name)
self.exchange = exchange self.exchange = exchange

View File

@ -19,7 +19,9 @@
# IN THE SOFTWARE. # IN THE SOFTWARE.
import os import os
import re
import sys import sys
import unittest
def setup_sys_path(): def setup_sys_path():
@ -44,4 +46,58 @@ setup_environment()
from stacktach import stacklog from stacktach import stacklog
stacklog.set_default_logger_location("%s.log") stacklog.set_default_logger_location("/tmp/%s.log")
class _AssertRaisesContext(object):
"""A context manager used to implement TestCase.assertRaises* methods."""
def __init__(self, expected, test_case, expected_regexp=None):
self.expected = expected
self.failureException = test_case.failureException
self.expected_regexp = expected_regexp
def __enter__(self):
return self
def __exit__(self, exc_type, exc_value, tb):
if exc_type is None:
try:
exc_name = self.expected.__name__
except AttributeError:
exc_name = str(self.expected)
raise self.failureException(
"{0} not raised".format(exc_name))
if not issubclass(exc_type, self.expected):
# let unexpected exceptions pass through
return False
self.exception = exc_value # store for later retrieval
if self.expected_regexp is None:
return True
expected_regexp = self.expected_regexp
if isinstance(expected_regexp, basestring):
expected_regexp = re.compile(expected_regexp)
if not expected_regexp.search(str(exc_value)):
raise self.failureException('"%s" does not match "%s"' %
(expected_regexp.pattern, str(exc_value)))
return True
class StacktachBaseTestCase(unittest.TestCase):
def assertIsNotNone(self, obj, msg=None):
self.assertTrue(obj is not None, msg)
def assertIsNone(self, obj, msg=None):
self.assertTrue(obj is None, msg)
def assertIsInstance(self, obj, cls, msg=None):
self.assertTrue(isinstance(obj, cls), msg)
def assertRaises(self, excClass, callableObj=None, *args, **kwargs):
context = _AssertRaisesContext(excClass, self)
if callableObj is None:
return context
with context:
callableObj(*args, **kwargs)

View File

@ -20,11 +20,11 @@
import datetime import datetime
import decimal import decimal
import unittest
from stacktach import datetime_to_decimal from stacktach import datetime_to_decimal
from tests.unit import StacktachBaseTestCase
class DatetimeToDecimalTestCase(unittest.TestCase): class DatetimeToDecimalTestCase(StacktachBaseTestCase):
def test_datetime_to_decimal(self): def test_datetime_to_decimal(self):
expected_decimal = decimal.Decimal('1356093296.123') expected_decimal = decimal.Decimal('1356093296.123')

View File

@ -20,7 +20,6 @@
import datetime import datetime
import json import json
import unittest
from django.db.models import FieldDoesNotExist from django.db.models import FieldDoesNotExist
from django.db import transaction from django.db import transaction
@ -29,13 +28,14 @@ import mox
from stacktach import dbapi from stacktach import dbapi
from stacktach import models from stacktach import models
from stacktach import utils as stacktach_utils from stacktach import utils as stacktach_utils
from tests.unit import StacktachBaseTestCase
import utils import utils
from utils import INSTANCE_ID_1 from utils import INSTANCE_ID_1
from utils import MESSAGE_ID_1 from utils import MESSAGE_ID_1
from utils import MESSAGE_ID_2 from utils import MESSAGE_ID_2
class DBAPITestCase(unittest.TestCase): class DBAPITestCase(StacktachBaseTestCase):
def setUp(self): def setUp(self):
self.mox = mox.Mox() self.mox = mox.Mox()
dne_exception = models.InstanceExists.DoesNotExist dne_exception = models.InstanceExists.DoesNotExist
@ -195,7 +195,7 @@ class DBAPITestCase(unittest.TestCase):
def test_get_db_objects_limit(self): def test_get_db_objects_limit(self):
fake_model = self.make_fake_model() fake_model = self.make_fake_model()
fake_request = self.mox.CreateMockAnything() fake_request = self.mox.CreateMockAnything()
fake_request.GET = {'limit': 1} fake_request.GET = {'limit': '1'}
self.mox.StubOutWithMock(dbapi, '_get_filter_args') self.mox.StubOutWithMock(dbapi, '_get_filter_args')
dbapi._get_filter_args(fake_model, fake_request, dbapi._get_filter_args(fake_model, fake_request,
custom_filters=None).AndReturn({}) custom_filters=None).AndReturn({})
@ -215,7 +215,7 @@ class DBAPITestCase(unittest.TestCase):
def test_get_db_objects_hard_limit(self): def test_get_db_objects_hard_limit(self):
fake_model = self.make_fake_model() fake_model = self.make_fake_model()
fake_request = self.mox.CreateMockAnything() fake_request = self.mox.CreateMockAnything()
fake_request.GET = {'limit': dbapi.HARD_LIMIT + 1} fake_request.GET = {'limit': str(dbapi.HARD_LIMIT + 1)}
self.mox.StubOutWithMock(dbapi, '_get_filter_args') self.mox.StubOutWithMock(dbapi, '_get_filter_args')
dbapi._get_filter_args(fake_model, fake_request, dbapi._get_filter_args(fake_model, fake_request,
custom_filters=None).AndReturn({}) custom_filters=None).AndReturn({})
@ -236,7 +236,7 @@ class DBAPITestCase(unittest.TestCase):
def test_get_db_objects_offset(self): def test_get_db_objects_offset(self):
fake_model = self.make_fake_model() fake_model = self.make_fake_model()
fake_request = self.mox.CreateMockAnything() fake_request = self.mox.CreateMockAnything()
fake_request.GET = {'offset': 1} fake_request.GET = {'offset': '1'}
self.mox.StubOutWithMock(dbapi, '_get_filter_args') self.mox.StubOutWithMock(dbapi, '_get_filter_args')
dbapi._get_filter_args(fake_model, fake_request, dbapi._get_filter_args(fake_model, fake_request,
custom_filters=None).AndReturn({}) custom_filters=None).AndReturn({})
@ -256,7 +256,7 @@ class DBAPITestCase(unittest.TestCase):
def test_get_db_objects_offset_and_limit(self): def test_get_db_objects_offset_and_limit(self):
fake_model = self.make_fake_model() fake_model = self.make_fake_model()
fake_request = self.mox.CreateMockAnything() fake_request = self.mox.CreateMockAnything()
fake_request.GET = {'offset': 2, 'limit': 2} fake_request.GET = {'offset': '2', 'limit': '2'}
self.mox.StubOutWithMock(dbapi, '_get_filter_args') self.mox.StubOutWithMock(dbapi, '_get_filter_args')
dbapi._get_filter_args(fake_model, fake_request, dbapi._get_filter_args(fake_model, fake_request,
custom_filters=None).AndReturn({}) custom_filters=None).AndReturn({})

View File

@ -18,12 +18,11 @@
# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS # FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
# IN THE SOFTWARE. # IN THE SOFTWARE.
import unittest
from stacktach import image_type from stacktach import image_type
from tests.unit import StacktachBaseTestCase
class ImageTypeTestCase(unittest.TestCase): class ImageTypeTestCase(StacktachBaseTestCase):
# Abstractions # Abstractions
def _test_get_numeric_code(self, image, os_type, os_distro, expected, def _test_get_numeric_code(self, image, os_type, os_distro, expected,

View File

@ -18,11 +18,11 @@
# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS # FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
# IN THE SOFTWARE. # IN THE SOFTWARE.
import unittest
from stacktach.models import RawData, GlanceRawData, GenericRawData from stacktach.models import RawData, GlanceRawData, GenericRawData
from tests.unit import StacktachBaseTestCase
class ModelsTestCase(unittest.TestCase): class ModelsTestCase(StacktachBaseTestCase):
def test_get_name_for_rawdata(self): def test_get_name_for_rawdata(self):
self.assertEquals(RawData.get_name(), 'RawData') self.assertEquals(RawData.get_name(), 'RawData')

View File

@ -18,7 +18,7 @@
# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS # FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
# IN THE SOFTWARE. # IN THE SOFTWARE.
import unittest import json
import mox import mox
@ -29,6 +29,7 @@ from stacktach.notification import Notification
from stacktach.notification import NovaNotification from stacktach.notification import NovaNotification
from stacktach.notification import GlanceNotification from stacktach.notification import GlanceNotification
from stacktach import db from stacktach import db
from tests.unit import StacktachBaseTestCase
from tests.unit.utils import REQUEST_ID_1 from tests.unit.utils import REQUEST_ID_1
from tests.unit.utils import DECIMAL_DUMMY_TIME from tests.unit.utils import DECIMAL_DUMMY_TIME
from tests.unit.utils import DUMMY_TIME from tests.unit.utils import DUMMY_TIME
@ -38,7 +39,7 @@ from tests.unit.utils import INSTANCE_ID_1
from tests.unit.utils import MESSAGE_ID_1 from tests.unit.utils import MESSAGE_ID_1
class NovaNotificationTestCase(unittest.TestCase): class NovaNotificationTestCase(StacktachBaseTestCase):
def setUp(self): def setUp(self):
self.mox = mox.Mox() self.mox = mox.Mox()
@ -119,13 +120,13 @@ class NovaNotificationTestCase(unittest.TestCase):
} }
deployment = "1" deployment = "1"
routing_key = "monitor.info" routing_key = "monitor.info"
json = '{["routing_key", {%s}]}' % body json_body = json.dumps([routing_key, body])
raw = self.mox.CreateMockAnything() raw = self.mox.CreateMockAnything()
self.mox.StubOutWithMock(db, 'create_nova_rawdata') self.mox.StubOutWithMock(db, 'create_nova_rawdata')
db.create_nova_rawdata( db.create_nova_rawdata(
deployment="1", deployment="1",
tenant=TENANT_ID_1, tenant=TENANT_ID_1,
json=json, json=json_body,
routing_key=routing_key, routing_key=routing_key,
when=utils.str_time_to_unix(TIMESTAMP_1), when=utils.str_time_to_unix(TIMESTAMP_1),
publisher="compute.global.preprod-ord.ohthree.com", publisher="compute.global.preprod-ord.ohthree.com",
@ -145,12 +146,12 @@ class NovaNotificationTestCase(unittest.TestCase):
self.mox.ReplayAll() self.mox.ReplayAll()
notification = NovaNotification(body, deployment, routing_key, json) notification = NovaNotification(body, deployment, routing_key, json_body)
self.assertEquals(notification.save(), raw) self.assertEquals(notification.save(), raw)
self.mox.VerifyAll() self.mox.VerifyAll()
class GlanceNotificationTestCase(unittest.TestCase): class GlanceNotificationTestCase(StacktachBaseTestCase):
def setUp(self): def setUp(self):
self.mox = mox.Mox() self.mox = mox.Mox()
@ -174,13 +175,13 @@ class GlanceNotificationTestCase(unittest.TestCase):
} }
deployment = "1" deployment = "1"
routing_key = "glance_monitor.info" routing_key = "glance_monitor.info"
json = '{["routing_key", {%s}]}' % body json_body = json.dumps([routing_key, body])
raw = self.mox.CreateMockAnything() raw = self.mox.CreateMockAnything()
self.mox.StubOutWithMock(db, 'create_glance_rawdata') self.mox.StubOutWithMock(db, 'create_glance_rawdata')
db.create_glance_rawdata( db.create_glance_rawdata(
deployment="1", deployment="1",
owner=TENANT_ID_1, owner=TENANT_ID_1,
json=json, json=json_body,
routing_key=routing_key, routing_key=routing_key,
when=utils.str_time_to_unix("2013-06-20 17:31:57.939614"), when=utils.str_time_to_unix("2013-06-20 17:31:57.939614"),
publisher="glance-api01-r2961.global.preprod-ord.ohthree.com", publisher="glance-api01-r2961.global.preprod-ord.ohthree.com",
@ -196,7 +197,42 @@ class GlanceNotificationTestCase(unittest.TestCase):
self.mox.ReplayAll() self.mox.ReplayAll()
notification = GlanceNotification(body, deployment, routing_key, notification = GlanceNotification(body, deployment, routing_key,
json) json_body)
self.assertEquals(notification.save(), raw)
self.mox.VerifyAll()
def test_save_should_persist_glance_rawdata_erro_payload_to_database(self):
body = {
"event_type": "image.upload",
"timestamp": "2013-06-20 17:31:57.939614",
"publisher_id": "glance-api01-r2961.global.preprod-ord.ohthree.com",
"payload": "error_message"
}
deployment = "1"
routing_key = "glance_monitor.error"
json_body = json.dumps([routing_key, body])
raw = self.mox.CreateMockAnything()
self.mox.StubOutWithMock(db, 'create_glance_rawdata')
db.create_glance_rawdata(
deployment="1",
owner=None,
json=json_body,
routing_key=routing_key,
when=utils.str_time_to_unix("2013-06-20 17:31:57.939614"),
publisher="glance-api01-r2961.global.preprod-ord.ohthree.com",
event="image.upload",
service="glance-api01-r2961",
host="global.preprod-ord.ohthree.com",
instance=None,
request_id='',
image_type=None,
status=None,
uuid=None).AndReturn(raw)
self.mox.ReplayAll()
notification = GlanceNotification(body, deployment, routing_key,
json_body)
self.assertEquals(notification.save(), raw) self.assertEquals(notification.save(), raw)
self.mox.VerifyAll() self.mox.VerifyAll()
@ -226,7 +262,7 @@ class GlanceNotificationTestCase(unittest.TestCase):
} }
deployment = "1" deployment = "1"
routing_key = "glance_monitor.info" routing_key = "glance_monitor.info"
json = '{["routing_key", {%s}]}' % body json_body = json.dumps([routing_key, body])
self.mox.StubOutWithMock(db, 'create_image_exists') self.mox.StubOutWithMock(db, 'create_image_exists')
self.mox.StubOutWithMock(db, 'get_image_usage') self.mox.StubOutWithMock(db, 'get_image_usage')
@ -247,7 +283,7 @@ class GlanceNotificationTestCase(unittest.TestCase):
self.mox.ReplayAll() self.mox.ReplayAll()
notification = GlanceNotification(body, deployment, routing_key, notification = GlanceNotification(body, deployment, routing_key,
json) json_body)
notification.save_exists(raw) notification.save_exists(raw)
self.mox.VerifyAll() self.mox.VerifyAll()
@ -280,7 +316,7 @@ class GlanceNotificationTestCase(unittest.TestCase):
} }
deployment = "1" deployment = "1"
routing_key = "glance_monitor.info" routing_key = "glance_monitor.info"
json = '{["routing_key", {%s}]}' % body json_body = json.dumps([routing_key, body])
self.mox.StubOutWithMock(db, 'create_image_exists') self.mox.StubOutWithMock(db, 'create_image_exists')
self.mox.StubOutWithMock(db, 'get_image_usage') self.mox.StubOutWithMock(db, 'get_image_usage')
@ -306,7 +342,7 @@ class GlanceNotificationTestCase(unittest.TestCase):
self.mox.ReplayAll() self.mox.ReplayAll()
notification = GlanceNotification(body, deployment, routing_key, notification = GlanceNotification(body, deployment, routing_key,
json) json_body)
notification.save_exists(raw) notification.save_exists(raw)
self.mox.VerifyAll() self.mox.VerifyAll()
@ -337,7 +373,7 @@ class GlanceNotificationTestCase(unittest.TestCase):
} }
deployment = "1" deployment = "1"
routing_key = "glance_monitor.info" routing_key = "glance_monitor.info"
json = '{["routing_key", {%s}]}' % body json_body = json.dumps([routing_key, body])
self.mox.StubOutWithMock(db, 'create_image_exists') self.mox.StubOutWithMock(db, 'create_image_exists')
self.mox.StubOutWithMock(db, 'get_image_usage') self.mox.StubOutWithMock(db, 'get_image_usage')
@ -359,7 +395,7 @@ class GlanceNotificationTestCase(unittest.TestCase):
self.mox.ReplayAll() self.mox.ReplayAll()
notification = GlanceNotification(body, deployment, routing_key, notification = GlanceNotification(body, deployment, routing_key,
json) json_body)
notification.save_exists(raw) notification.save_exists(raw)
self.mox.VerifyAll() self.mox.VerifyAll()
@ -380,7 +416,7 @@ class GlanceNotificationTestCase(unittest.TestCase):
} }
deployment = "1" deployment = "1"
routing_key = "glance_monitor.info" routing_key = "glance_monitor.info"
json = '{["routing_key", {%s}]}' % body json_body = json.dumps([routing_key, body])
self.mox.StubOutWithMock(db, 'create_image_usage') self.mox.StubOutWithMock(db, 'create_image_usage')
db.create_image_usage( db.create_image_usage(
@ -391,7 +427,8 @@ class GlanceNotificationTestCase(unittest.TestCase):
uuid=uuid).AndReturn(raw) uuid=uuid).AndReturn(raw)
self.mox.ReplayAll() self.mox.ReplayAll()
notification = GlanceNotification(body, deployment, routing_key, json) notification = GlanceNotification(body, deployment, routing_key,
json_body)
notification.save_usage(raw) notification.save_usage(raw)
self.mox.VerifyAll() self.mox.VerifyAll()
@ -409,7 +446,7 @@ class GlanceNotificationTestCase(unittest.TestCase):
} }
deployment = "1" deployment = "1"
routing_key = "glance_monitor.info" routing_key = "glance_monitor.info"
json = '{["routing_key", {%s}]}' % body json_body = json.dumps([routing_key, body])
self.mox.StubOutWithMock(db, 'create_image_delete') self.mox.StubOutWithMock(db, 'create_image_delete')
db.create_image_delete( db.create_image_delete(
@ -418,12 +455,13 @@ class GlanceNotificationTestCase(unittest.TestCase):
deleted_at=utils.str_time_to_unix(deleted_at)).AndReturn(raw) deleted_at=utils.str_time_to_unix(deleted_at)).AndReturn(raw)
self.mox.ReplayAll() self.mox.ReplayAll()
notification = GlanceNotification(body, deployment, routing_key, json) notification = GlanceNotification(body, deployment, routing_key,
json_body)
notification.save_delete(raw) notification.save_delete(raw)
self.mox.VerifyAll() self.mox.VerifyAll()
class NotificationTestCase(unittest.TestCase): class NotificationTestCase(StacktachBaseTestCase):
def setUp(self): def setUp(self):
self.mox = mox.Mox() self.mox = mox.Mox()
@ -447,13 +485,13 @@ class NotificationTestCase(unittest.TestCase):
} }
deployment = "1" deployment = "1"
routing_key = "generic_monitor.info" routing_key = "generic_monitor.info"
json = '{["routing_key", {%s}]}' % body json_body = json.dumps([routing_key, body])
raw = self.mox.CreateMockAnything() raw = self.mox.CreateMockAnything()
self.mox.StubOutWithMock(db, 'create_generic_rawdata') self.mox.StubOutWithMock(db, 'create_generic_rawdata')
db.create_generic_rawdata( db.create_generic_rawdata(
deployment="1", deployment="1",
tenant=TENANT_ID_1, tenant=TENANT_ID_1,
json=json, json=json_body,
routing_key=routing_key, routing_key=routing_key,
when=utils.str_time_to_unix(TIMESTAMP_1), when=utils.str_time_to_unix(TIMESTAMP_1),
publisher="glance-api01-r2961.global.preprod-ord.ohthree.com", publisher="glance-api01-r2961.global.preprod-ord.ohthree.com",
@ -466,6 +504,6 @@ class NotificationTestCase(unittest.TestCase):
self.mox.ReplayAll() self.mox.ReplayAll()
notification = Notification(body, deployment, routing_key, json) notification = Notification(body, deployment, routing_key, json_body)
self.assertEquals(notification.save(), raw) self.assertEquals(notification.save(), raw)
self.mox.VerifyAll() self.mox.VerifyAll()

View File

@ -19,7 +19,6 @@
# IN THE SOFTWARE. # IN THE SOFTWARE.
import datetime import datetime
import unittest
import mox import mox
import requests import requests
@ -30,6 +29,7 @@ from stacktach import utils as stackutils
from stacktach.reconciler import exceptions from stacktach.reconciler import exceptions
from stacktach.reconciler import nova from stacktach.reconciler import nova
from stacktach.reconciler import utils as rec_utils from stacktach.reconciler import utils as rec_utils
from tests.unit import StacktachBaseTestCase
from tests.unit import utils from tests.unit import utils
from tests.unit.utils import INSTANCE_ID_1 from tests.unit.utils import INSTANCE_ID_1
from tests.unit.utils import TENANT_ID_1 from tests.unit.utils import TENANT_ID_1
@ -45,7 +45,7 @@ DEFAULT_OS_VERSION = "1.1"
DEFAULT_RAX_OPTIONS = "rax_ops" DEFAULT_RAX_OPTIONS = "rax_ops"
class ReconcilerTestCase(unittest.TestCase): class ReconcilerTestCase(StacktachBaseTestCase):
def setUp(self): def setUp(self):
self.mox = mox.Mox() self.mox = mox.Mox()
self.client = self.mox.CreateMockAnything() self.client = self.mox.CreateMockAnything()
@ -415,7 +415,7 @@ json_bridge_config = {
} }
class NovaJSONBridgeClientTestCase(unittest.TestCase): class NovaJSONBridgeClientTestCase(StacktachBaseTestCase):
def setUp(self): def setUp(self):
self.mox = mox.Mox() self.mox = mox.Mox()
self.client = nova.JSONBridgeClient(json_bridge_config) self.client = nova.JSONBridgeClient(json_bridge_config)

View File

@ -1,14 +1,13 @@
import glob import glob
import logging import logging
import os import os
from unittest import TestCase
import mox import mox
from stacktach import stacklog from stacktach import stacklog
import __builtin__ import __builtin__
from stacktach.stacklog import ExchangeLogger from stacktach.stacklog import ExchangeLogger
from tests.unit import StacktachBaseTestCase
class StacklogTestCase(StacktachBaseTestCase):
class StacklogTestCase(TestCase):
def setUp(self): def setUp(self):
self.mox = mox.Mox() self.mox = mox.Mox()
@ -30,7 +29,7 @@ class StacklogTestCase(TestCase):
os.remove(file) os.remove(file)
class ExchangeLoggerTestCase(TestCase): class ExchangeLoggerTestCase(StacktachBaseTestCase):
def setUp(self): def setUp(self):
self.mox = mox.Mox() self.mox = mox.Mox()
@ -40,11 +39,11 @@ class ExchangeLoggerTestCase(TestCase):
def _setup_logger_mocks(self, name='name'): def _setup_logger_mocks(self, name='name'):
mock_logger = self.mox.CreateMockAnything() mock_logger = self.mox.CreateMockAnything()
self.mox.StubOutWithMock(logging, 'getLogger') self.mox.StubOutWithMock(logging, 'getLogger')
logging.getLogger(name).AndReturn(mock_logger) logging.getLogger(stacklog.__name__).AndReturn(mock_logger)
mock_logger.setLevel(logging.DEBUG) mock_logger.setLevel(logging.DEBUG)
self.mox.StubOutClassWithMocks(logging.handlers, self.mox.StubOutClassWithMocks(logging.handlers,
'TimedRotatingFileHandler') 'TimedRotatingFileHandler')
filename = "{0}.log".format(name) filename = "/tmp/{0}.log".format(name)
handler = logging.handlers.TimedRotatingFileHandler( handler = logging.handlers.TimedRotatingFileHandler(
filename, backupCount=3, interval=1, when='midnight') filename, backupCount=3, interval=1, when='midnight')
self.mox.StubOutClassWithMocks(logging, 'Formatter') self.mox.StubOutClassWithMocks(logging, 'Formatter')

View File

@ -20,7 +20,6 @@
import datetime import datetime
import json import json
import unittest
import mox import mox
@ -40,9 +39,10 @@ from utils import IMAGE_UUID_1
from stacktach import stacklog from stacktach import stacklog
from stacktach import notification from stacktach import notification
from stacktach import views from stacktach import views
from tests.unit import StacktachBaseTestCase
class StacktachRawParsingTestCase(unittest.TestCase): class StacktachRawParsingTestCase(StacktachBaseTestCase):
def setUp(self): def setUp(self):
self.mox = mox.Mox() self.mox = mox.Mox()
views.STACKDB = self.mox.CreateMockAnything() views.STACKDB = self.mox.CreateMockAnything()
@ -101,7 +101,7 @@ class StacktachRawParsingTestCase(unittest.TestCase):
self.mox.VerifyAll() self.mox.VerifyAll()
class StacktachLifecycleTestCase(unittest.TestCase): class StacktachLifecycleTestCase(StacktachBaseTestCase):
def setUp(self): def setUp(self):
self.mox = mox.Mox() self.mox = mox.Mox()
views.STACKDB = self.mox.CreateMockAnything() views.STACKDB = self.mox.CreateMockAnything()
@ -287,7 +287,7 @@ class StacktachLifecycleTestCase(unittest.TestCase):
self.mox.VerifyAll() self.mox.VerifyAll()
class StacktachUsageParsingTestCase(unittest.TestCase): class StacktachUsageParsingTestCase(StacktachBaseTestCase):
def setUp(self): def setUp(self):
self.mox = mox.Mox() self.mox = mox.Mox()
views.STACKDB = self.mox.CreateMockAnything() views.STACKDB = self.mox.CreateMockAnything()
@ -830,7 +830,7 @@ class StacktachUsageParsingTestCase(unittest.TestCase):
self.mox.VerifyAll() self.mox.VerifyAll()
class StacktachImageUsageParsingTestCase(unittest.TestCase): class StacktachImageUsageParsingTestCase(StacktachBaseTestCase):
def setUp(self): def setUp(self):
self.mox = mox.Mox() self.mox = mox.Mox()
views.STACKDB = self.mox.CreateMockAnything() views.STACKDB = self.mox.CreateMockAnything()

View File

@ -18,17 +18,15 @@
# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS # FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
# IN THE SOFTWARE. # IN THE SOFTWARE.
import datetime
import unittest
import mox import mox
from stacktach import db from stacktach import db
from stacktach import stacklog from stacktach import stacklog
from stacktach import models from stacktach import models
from tests.unit import StacktachBaseTestCase
class StacktachDBTestCase(unittest.TestCase): class StacktachDBTestCase(StacktachBaseTestCase):
def setUp(self): def setUp(self):
self.mox = mox.Mox() self.mox = mox.Mox()
self.log = self.mox.CreateMockAnything() self.log = self.mox.CreateMockAnything()

View File

@ -18,17 +18,16 @@
# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS # FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
# IN THE SOFTWARE. # IN THE SOFTWARE.
import unittest
import mox import mox
from stacktach import utils as stacktach_utils from stacktach import utils as stacktach_utils
from utils import INSTANCE_ID_1 from utils import INSTANCE_ID_1
from utils import MESSAGE_ID_1 from utils import MESSAGE_ID_1
from utils import REQUEST_ID_1 from utils import REQUEST_ID_1
from tests.unit import StacktachBaseTestCase
class StacktachUtilsTestCase(unittest.TestCase): class StacktachUtilsTestCase(StacktachBaseTestCase):
def setUp(self): def setUp(self):
self.mox = mox.Mox() self.mox = mox.Mox()

View File

@ -21,7 +21,6 @@
import datetime import datetime
import decimal import decimal
import json import json
import unittest
import mox import mox
@ -33,8 +32,10 @@ from utils import INSTANCE_ID_1
from utils import INSTANCE_ID_2 from utils import INSTANCE_ID_2
from utils import REQUEST_ID_1 from utils import REQUEST_ID_1
from tests.unit import StacktachBaseTestCase
class StackyServerTestCase(unittest.TestCase):
class StackyServerTestCase(StacktachBaseTestCase):
def setUp(self): def setUp(self):
self.mox = mox.Mox() self.mox = mox.Mox()
self.mox.StubOutWithMock(models, 'RawData', use_mock_anything=True) self.mox.StubOutWithMock(models, 'RawData', use_mock_anything=True)

View File

@ -22,7 +22,6 @@ import datetime
import decimal import decimal
import json import json
import time import time
import unittest
import uuid import uuid
@ -51,9 +50,10 @@ from verifier import AmbiguousResults
from verifier import FieldMismatch from verifier import FieldMismatch
from verifier import NotFound from verifier import NotFound
from verifier import VerificationException from verifier import VerificationException
from tests.unit import StacktachBaseTestCase
class VerifierTestCase(unittest.TestCase): class VerifierTestCase(StacktachBaseTestCase):
def setUp(self): def setUp(self):
self.mox = mox.Mox() self.mox = mox.Mox()
self.mox.StubOutWithMock(models, 'RawData', use_mock_anything=True) self.mox.StubOutWithMock(models, 'RawData', use_mock_anything=True)

View File

@ -19,7 +19,6 @@
# IN THE SOFTWARE. # IN THE SOFTWARE.
import json import json
import unittest
import kombu import kombu
import mox import mox
@ -27,9 +26,10 @@ import mox
from stacktach import db from stacktach import db
from stacktach import views from stacktach import views
import worker.worker as worker import worker.worker as worker
from tests.unit import StacktachBaseTestCase
class ConsumerTestCase(unittest.TestCase): class ConsumerTestCase(StacktachBaseTestCase):
def setUp(self): def setUp(self):
self.mox = mox.Mox() self.mox = mox.Mox()