Merge remote-tracking branch 'upstream/master'
This commit is contained in:
commit
a078990aa5
1
.gitignore
vendored
1
.gitignore
vendored
@ -1,4 +1,5 @@
|
||||
.idea/
|
||||
.venv/
|
||||
|
||||
*.pyc
|
||||
local_settings.py
|
||||
|
@ -6,3 +6,4 @@ librabbitmq>=1.0.0
|
||||
prettytable>=0.7.2
|
||||
argparse
|
||||
Pympler
|
||||
requests
|
||||
|
4
etc/test-requires.txt
Normal file
4
etc/test-requires.txt
Normal file
@ -0,0 +1,4 @@
|
||||
nose
|
||||
coverage
|
||||
mox
|
||||
nose-exclude
|
@ -33,16 +33,21 @@ from stacktach import models
|
||||
from stacktach.reconciler import Reconciler
|
||||
|
||||
OLD_LAUNCHES_QUERY = """
|
||||
select * from stacktach_instanceusage where
|
||||
launched_at is not null and
|
||||
launched_at < %s and
|
||||
instance not in
|
||||
(select distinct(instance)
|
||||
from stacktach_instancedeletes where
|
||||
deleted_at < %s union
|
||||
select distinct(instance)
|
||||
from stacktach_instancereconcile where
|
||||
deleted_at < %s);"""
|
||||
select stacktach_instanceusage.id,
|
||||
stacktach_instanceusage.instance,
|
||||
stacktach_instanceusage.launched_at from stacktach_instanceusage
|
||||
left outer join stacktach_instancedeletes on
|
||||
stacktach_instanceusage.instance = stacktach_instancedeletes.instance
|
||||
left outer join stacktach_instancereconcile on
|
||||
stacktach_instanceusage.instance = stacktach_instancereconcile.instance
|
||||
where (
|
||||
stacktach_instancereconcile.deleted_at is null and (
|
||||
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
|
||||
|
||||
|
7
run_tests_venv.sh
Executable file
7
run_tests_venv.sh
Executable 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
|
||||
|
@ -290,6 +290,10 @@ def get_db_objects(klass, request, default_order_by, direction='desc',
|
||||
|
||||
offset = request.GET.get('offset')
|
||||
limit = request.GET.get('limit', DEFAULT_LIMIT)
|
||||
|
||||
if limit:
|
||||
limit = int(limit)
|
||||
|
||||
if limit > HARD_LIMIT:
|
||||
limit = HARD_LIMIT
|
||||
if offset:
|
||||
|
@ -95,25 +95,38 @@ class GlanceNotification(Notification):
|
||||
def __init__(self, body, deployment, routing_key, json):
|
||||
super(GlanceNotification, self).__init__(body, deployment,
|
||||
routing_key, json)
|
||||
self.properties = self.payload.get('properties', {})
|
||||
self.image_type = image_type.get_numeric_code(self.payload)
|
||||
self.status = self.payload.get('status', None)
|
||||
self.uuid = self.payload.get('id', None)
|
||||
self.size = self.payload.get('size', None)
|
||||
created_at = self.payload.get('created_at', None)
|
||||
self.created_at = created_at and utils.str_time_to_unix(created_at)
|
||||
audit_period_beginning = self.payload.get(
|
||||
'audit_period_beginning', None)
|
||||
self.audit_period_beginning = audit_period_beginning and\
|
||||
utils.str_time_to_unix(audit_period_beginning)
|
||||
audit_period_ending = self.payload.get(
|
||||
'audit_period_ending', None)
|
||||
self.audit_period_ending = audit_period_ending and \
|
||||
utils.str_time_to_unix(audit_period_ending)
|
||||
if isinstance(self.payload, dict):
|
||||
self.properties = self.payload.get('properties', {})
|
||||
self.image_type = image_type.get_numeric_code(self.payload)
|
||||
self.status = self.payload.get('status', None)
|
||||
self.uuid = self.payload.get('id', None)
|
||||
self.size = self.payload.get('size', None)
|
||||
created_at = self.payload.get('created_at', None)
|
||||
self.created_at = created_at and utils.str_time_to_unix(created_at)
|
||||
audit_period_beginning = self.payload.get(
|
||||
'audit_period_beginning', None)
|
||||
self.audit_period_beginning = audit_period_beginning and\
|
||||
utils.str_time_to_unix(audit_period_beginning)
|
||||
audit_period_ending = self.payload.get(
|
||||
'audit_period_ending', None)
|
||||
self.audit_period_ending = audit_period_ending and \
|
||||
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
|
||||
def owner(self):
|
||||
return self.payload.get('owner', None)
|
||||
if isinstance(self.payload, dict):
|
||||
return self.payload.get('owner', None)
|
||||
else:
|
||||
return None
|
||||
|
||||
@property
|
||||
def instance(self):
|
||||
@ -121,7 +134,10 @@ class GlanceNotification(Notification):
|
||||
@property
|
||||
def deleted_at(self):
|
||||
deleted_at = self.body.get('deleted_at', None)
|
||||
deleted_at = deleted_at or self.payload.get('deleted_at', None)
|
||||
|
||||
if isinstance(self.payload, dict):
|
||||
deleted_at = deleted_at or self.payload.get('deleted_at', None)
|
||||
|
||||
return deleted_at and utils.str_time_to_unix(deleted_at)
|
||||
|
||||
def save(self):
|
||||
|
@ -98,7 +98,7 @@ def _configure(logger, name):
|
||||
|
||||
class ExchangeLogger():
|
||||
def __init__(self, exchange, name='stacktach-default'):
|
||||
self.logger = logging.getLogger(name)
|
||||
self.logger = logging.getLogger(__name__)
|
||||
_configure(self.logger, name)
|
||||
self.exchange = exchange
|
||||
|
||||
|
@ -19,7 +19,9 @@
|
||||
# IN THE SOFTWARE.
|
||||
|
||||
import os
|
||||
import re
|
||||
import sys
|
||||
import unittest
|
||||
|
||||
|
||||
def setup_sys_path():
|
||||
@ -44,4 +46,58 @@ setup_environment()
|
||||
|
||||
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)
|
@ -20,11 +20,11 @@
|
||||
|
||||
import datetime
|
||||
import decimal
|
||||
import unittest
|
||||
|
||||
from stacktach import datetime_to_decimal
|
||||
from tests.unit import StacktachBaseTestCase
|
||||
|
||||
class DatetimeToDecimalTestCase(unittest.TestCase):
|
||||
class DatetimeToDecimalTestCase(StacktachBaseTestCase):
|
||||
|
||||
def test_datetime_to_decimal(self):
|
||||
expected_decimal = decimal.Decimal('1356093296.123')
|
||||
|
@ -20,7 +20,6 @@
|
||||
|
||||
import datetime
|
||||
import json
|
||||
import unittest
|
||||
|
||||
from django.db.models import FieldDoesNotExist
|
||||
from django.db import transaction
|
||||
@ -29,13 +28,14 @@ import mox
|
||||
from stacktach import dbapi
|
||||
from stacktach import models
|
||||
from stacktach import utils as stacktach_utils
|
||||
from tests.unit import StacktachBaseTestCase
|
||||
import utils
|
||||
from utils import INSTANCE_ID_1
|
||||
from utils import MESSAGE_ID_1
|
||||
from utils import MESSAGE_ID_2
|
||||
|
||||
|
||||
class DBAPITestCase(unittest.TestCase):
|
||||
class DBAPITestCase(StacktachBaseTestCase):
|
||||
def setUp(self):
|
||||
self.mox = mox.Mox()
|
||||
dne_exception = models.InstanceExists.DoesNotExist
|
||||
@ -195,7 +195,7 @@ class DBAPITestCase(unittest.TestCase):
|
||||
def test_get_db_objects_limit(self):
|
||||
fake_model = self.make_fake_model()
|
||||
fake_request = self.mox.CreateMockAnything()
|
||||
fake_request.GET = {'limit': 1}
|
||||
fake_request.GET = {'limit': '1'}
|
||||
self.mox.StubOutWithMock(dbapi, '_get_filter_args')
|
||||
dbapi._get_filter_args(fake_model, fake_request,
|
||||
custom_filters=None).AndReturn({})
|
||||
@ -215,7 +215,7 @@ class DBAPITestCase(unittest.TestCase):
|
||||
def test_get_db_objects_hard_limit(self):
|
||||
fake_model = self.make_fake_model()
|
||||
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')
|
||||
dbapi._get_filter_args(fake_model, fake_request,
|
||||
custom_filters=None).AndReturn({})
|
||||
@ -236,7 +236,7 @@ class DBAPITestCase(unittest.TestCase):
|
||||
def test_get_db_objects_offset(self):
|
||||
fake_model = self.make_fake_model()
|
||||
fake_request = self.mox.CreateMockAnything()
|
||||
fake_request.GET = {'offset': 1}
|
||||
fake_request.GET = {'offset': '1'}
|
||||
self.mox.StubOutWithMock(dbapi, '_get_filter_args')
|
||||
dbapi._get_filter_args(fake_model, fake_request,
|
||||
custom_filters=None).AndReturn({})
|
||||
@ -256,7 +256,7 @@ class DBAPITestCase(unittest.TestCase):
|
||||
def test_get_db_objects_offset_and_limit(self):
|
||||
fake_model = self.make_fake_model()
|
||||
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')
|
||||
dbapi._get_filter_args(fake_model, fake_request,
|
||||
custom_filters=None).AndReturn({})
|
||||
|
@ -18,12 +18,11 @@
|
||||
# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
|
||||
# IN THE SOFTWARE.
|
||||
|
||||
import unittest
|
||||
|
||||
from stacktach import image_type
|
||||
from tests.unit import StacktachBaseTestCase
|
||||
|
||||
|
||||
class ImageTypeTestCase(unittest.TestCase):
|
||||
class ImageTypeTestCase(StacktachBaseTestCase):
|
||||
|
||||
# Abstractions
|
||||
def _test_get_numeric_code(self, image, os_type, os_distro, expected,
|
||||
|
@ -18,11 +18,11 @@
|
||||
# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
|
||||
# IN THE SOFTWARE.
|
||||
|
||||
import unittest
|
||||
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):
|
||||
self.assertEquals(RawData.get_name(), 'RawData')
|
||||
|
||||
|
@ -18,7 +18,7 @@
|
||||
# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
|
||||
# IN THE SOFTWARE.
|
||||
|
||||
import unittest
|
||||
import json
|
||||
|
||||
import mox
|
||||
|
||||
@ -29,6 +29,7 @@ from stacktach.notification import Notification
|
||||
from stacktach.notification import NovaNotification
|
||||
from stacktach.notification import GlanceNotification
|
||||
from stacktach import db
|
||||
from tests.unit import StacktachBaseTestCase
|
||||
from tests.unit.utils import REQUEST_ID_1
|
||||
from tests.unit.utils import DECIMAL_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
|
||||
|
||||
|
||||
class NovaNotificationTestCase(unittest.TestCase):
|
||||
class NovaNotificationTestCase(StacktachBaseTestCase):
|
||||
|
||||
def setUp(self):
|
||||
self.mox = mox.Mox()
|
||||
@ -119,13 +120,13 @@ class NovaNotificationTestCase(unittest.TestCase):
|
||||
}
|
||||
deployment = "1"
|
||||
routing_key = "monitor.info"
|
||||
json = '{["routing_key", {%s}]}' % body
|
||||
json_body = json.dumps([routing_key, body])
|
||||
raw = self.mox.CreateMockAnything()
|
||||
self.mox.StubOutWithMock(db, 'create_nova_rawdata')
|
||||
db.create_nova_rawdata(
|
||||
deployment="1",
|
||||
tenant=TENANT_ID_1,
|
||||
json=json,
|
||||
json=json_body,
|
||||
routing_key=routing_key,
|
||||
when=utils.str_time_to_unix(TIMESTAMP_1),
|
||||
publisher="compute.global.preprod-ord.ohthree.com",
|
||||
@ -145,12 +146,12 @@ class NovaNotificationTestCase(unittest.TestCase):
|
||||
|
||||
self.mox.ReplayAll()
|
||||
|
||||
notification = NovaNotification(body, deployment, routing_key, json)
|
||||
notification = NovaNotification(body, deployment, routing_key, json_body)
|
||||
self.assertEquals(notification.save(), raw)
|
||||
self.mox.VerifyAll()
|
||||
|
||||
|
||||
class GlanceNotificationTestCase(unittest.TestCase):
|
||||
class GlanceNotificationTestCase(StacktachBaseTestCase):
|
||||
def setUp(self):
|
||||
self.mox = mox.Mox()
|
||||
|
||||
@ -174,13 +175,13 @@ class GlanceNotificationTestCase(unittest.TestCase):
|
||||
}
|
||||
deployment = "1"
|
||||
routing_key = "glance_monitor.info"
|
||||
json = '{["routing_key", {%s}]}' % body
|
||||
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=TENANT_ID_1,
|
||||
json=json,
|
||||
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",
|
||||
@ -196,7 +197,42 @@ class GlanceNotificationTestCase(unittest.TestCase):
|
||||
self.mox.ReplayAll()
|
||||
|
||||
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.mox.VerifyAll()
|
||||
|
||||
@ -226,7 +262,7 @@ class GlanceNotificationTestCase(unittest.TestCase):
|
||||
}
|
||||
deployment = "1"
|
||||
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, 'get_image_usage')
|
||||
@ -247,7 +283,7 @@ class GlanceNotificationTestCase(unittest.TestCase):
|
||||
self.mox.ReplayAll()
|
||||
|
||||
notification = GlanceNotification(body, deployment, routing_key,
|
||||
json)
|
||||
json_body)
|
||||
notification.save_exists(raw)
|
||||
self.mox.VerifyAll()
|
||||
|
||||
@ -280,7 +316,7 @@ class GlanceNotificationTestCase(unittest.TestCase):
|
||||
}
|
||||
deployment = "1"
|
||||
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, 'get_image_usage')
|
||||
@ -306,7 +342,7 @@ class GlanceNotificationTestCase(unittest.TestCase):
|
||||
self.mox.ReplayAll()
|
||||
|
||||
notification = GlanceNotification(body, deployment, routing_key,
|
||||
json)
|
||||
json_body)
|
||||
notification.save_exists(raw)
|
||||
self.mox.VerifyAll()
|
||||
|
||||
@ -337,7 +373,7 @@ class GlanceNotificationTestCase(unittest.TestCase):
|
||||
}
|
||||
deployment = "1"
|
||||
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, 'get_image_usage')
|
||||
@ -359,7 +395,7 @@ class GlanceNotificationTestCase(unittest.TestCase):
|
||||
self.mox.ReplayAll()
|
||||
|
||||
notification = GlanceNotification(body, deployment, routing_key,
|
||||
json)
|
||||
json_body)
|
||||
notification.save_exists(raw)
|
||||
self.mox.VerifyAll()
|
||||
|
||||
@ -380,7 +416,7 @@ class GlanceNotificationTestCase(unittest.TestCase):
|
||||
}
|
||||
deployment = "1"
|
||||
routing_key = "glance_monitor.info"
|
||||
json = '{["routing_key", {%s}]}' % body
|
||||
json_body = json.dumps([routing_key, body])
|
||||
|
||||
self.mox.StubOutWithMock(db, 'create_image_usage')
|
||||
db.create_image_usage(
|
||||
@ -391,7 +427,8 @@ class GlanceNotificationTestCase(unittest.TestCase):
|
||||
uuid=uuid).AndReturn(raw)
|
||||
self.mox.ReplayAll()
|
||||
|
||||
notification = GlanceNotification(body, deployment, routing_key, json)
|
||||
notification = GlanceNotification(body, deployment, routing_key,
|
||||
json_body)
|
||||
notification.save_usage(raw)
|
||||
self.mox.VerifyAll()
|
||||
|
||||
@ -409,7 +446,7 @@ class GlanceNotificationTestCase(unittest.TestCase):
|
||||
}
|
||||
deployment = "1"
|
||||
routing_key = "glance_monitor.info"
|
||||
json = '{["routing_key", {%s}]}' % body
|
||||
json_body = json.dumps([routing_key, body])
|
||||
|
||||
self.mox.StubOutWithMock(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)
|
||||
self.mox.ReplayAll()
|
||||
|
||||
notification = GlanceNotification(body, deployment, routing_key, json)
|
||||
notification = GlanceNotification(body, deployment, routing_key,
|
||||
json_body)
|
||||
notification.save_delete(raw)
|
||||
self.mox.VerifyAll()
|
||||
|
||||
|
||||
class NotificationTestCase(unittest.TestCase):
|
||||
class NotificationTestCase(StacktachBaseTestCase):
|
||||
def setUp(self):
|
||||
self.mox = mox.Mox()
|
||||
|
||||
@ -447,13 +485,13 @@ class NotificationTestCase(unittest.TestCase):
|
||||
}
|
||||
deployment = "1"
|
||||
routing_key = "generic_monitor.info"
|
||||
json = '{["routing_key", {%s}]}' % body
|
||||
json_body = json.dumps([routing_key, body])
|
||||
raw = self.mox.CreateMockAnything()
|
||||
self.mox.StubOutWithMock(db, 'create_generic_rawdata')
|
||||
db.create_generic_rawdata(
|
||||
deployment="1",
|
||||
tenant=TENANT_ID_1,
|
||||
json=json,
|
||||
json=json_body,
|
||||
routing_key=routing_key,
|
||||
when=utils.str_time_to_unix(TIMESTAMP_1),
|
||||
publisher="glance-api01-r2961.global.preprod-ord.ohthree.com",
|
||||
@ -466,6 +504,6 @@ class NotificationTestCase(unittest.TestCase):
|
||||
|
||||
self.mox.ReplayAll()
|
||||
|
||||
notification = Notification(body, deployment, routing_key, json)
|
||||
notification = Notification(body, deployment, routing_key, json_body)
|
||||
self.assertEquals(notification.save(), raw)
|
||||
self.mox.VerifyAll()
|
||||
|
@ -19,7 +19,6 @@
|
||||
# IN THE SOFTWARE.
|
||||
|
||||
import datetime
|
||||
import unittest
|
||||
|
||||
import mox
|
||||
import requests
|
||||
@ -30,6 +29,7 @@ from stacktach import utils as stackutils
|
||||
from stacktach.reconciler import exceptions
|
||||
from stacktach.reconciler import nova
|
||||
from stacktach.reconciler import utils as rec_utils
|
||||
from tests.unit import StacktachBaseTestCase
|
||||
from tests.unit import utils
|
||||
from tests.unit.utils import INSTANCE_ID_1
|
||||
from tests.unit.utils import TENANT_ID_1
|
||||
@ -45,7 +45,7 @@ DEFAULT_OS_VERSION = "1.1"
|
||||
DEFAULT_RAX_OPTIONS = "rax_ops"
|
||||
|
||||
|
||||
class ReconcilerTestCase(unittest.TestCase):
|
||||
class ReconcilerTestCase(StacktachBaseTestCase):
|
||||
def setUp(self):
|
||||
self.mox = mox.Mox()
|
||||
self.client = self.mox.CreateMockAnything()
|
||||
@ -415,7 +415,7 @@ json_bridge_config = {
|
||||
}
|
||||
|
||||
|
||||
class NovaJSONBridgeClientTestCase(unittest.TestCase):
|
||||
class NovaJSONBridgeClientTestCase(StacktachBaseTestCase):
|
||||
def setUp(self):
|
||||
self.mox = mox.Mox()
|
||||
self.client = nova.JSONBridgeClient(json_bridge_config)
|
||||
|
@ -1,14 +1,13 @@
|
||||
import glob
|
||||
import logging
|
||||
import os
|
||||
from unittest import TestCase
|
||||
import mox
|
||||
from stacktach import stacklog
|
||||
import __builtin__
|
||||
from stacktach.stacklog import ExchangeLogger
|
||||
from tests.unit import StacktachBaseTestCase
|
||||
|
||||
|
||||
class StacklogTestCase(TestCase):
|
||||
class StacklogTestCase(StacktachBaseTestCase):
|
||||
def setUp(self):
|
||||
self.mox = mox.Mox()
|
||||
|
||||
@ -30,7 +29,7 @@ class StacklogTestCase(TestCase):
|
||||
os.remove(file)
|
||||
|
||||
|
||||
class ExchangeLoggerTestCase(TestCase):
|
||||
class ExchangeLoggerTestCase(StacktachBaseTestCase):
|
||||
def setUp(self):
|
||||
self.mox = mox.Mox()
|
||||
|
||||
@ -40,11 +39,11 @@ class ExchangeLoggerTestCase(TestCase):
|
||||
def _setup_logger_mocks(self, name='name'):
|
||||
mock_logger = self.mox.CreateMockAnything()
|
||||
self.mox.StubOutWithMock(logging, 'getLogger')
|
||||
logging.getLogger(name).AndReturn(mock_logger)
|
||||
logging.getLogger(stacklog.__name__).AndReturn(mock_logger)
|
||||
mock_logger.setLevel(logging.DEBUG)
|
||||
self.mox.StubOutClassWithMocks(logging.handlers,
|
||||
'TimedRotatingFileHandler')
|
||||
filename = "{0}.log".format(name)
|
||||
filename = "/tmp/{0}.log".format(name)
|
||||
handler = logging.handlers.TimedRotatingFileHandler(
|
||||
filename, backupCount=3, interval=1, when='midnight')
|
||||
self.mox.StubOutClassWithMocks(logging, 'Formatter')
|
||||
|
@ -20,7 +20,6 @@
|
||||
|
||||
import datetime
|
||||
import json
|
||||
import unittest
|
||||
|
||||
import mox
|
||||
|
||||
@ -40,9 +39,10 @@ from utils import IMAGE_UUID_1
|
||||
from stacktach import stacklog
|
||||
from stacktach import notification
|
||||
from stacktach import views
|
||||
from tests.unit import StacktachBaseTestCase
|
||||
|
||||
|
||||
class StacktachRawParsingTestCase(unittest.TestCase):
|
||||
class StacktachRawParsingTestCase(StacktachBaseTestCase):
|
||||
def setUp(self):
|
||||
self.mox = mox.Mox()
|
||||
views.STACKDB = self.mox.CreateMockAnything()
|
||||
@ -101,7 +101,7 @@ class StacktachRawParsingTestCase(unittest.TestCase):
|
||||
self.mox.VerifyAll()
|
||||
|
||||
|
||||
class StacktachLifecycleTestCase(unittest.TestCase):
|
||||
class StacktachLifecycleTestCase(StacktachBaseTestCase):
|
||||
def setUp(self):
|
||||
self.mox = mox.Mox()
|
||||
views.STACKDB = self.mox.CreateMockAnything()
|
||||
@ -287,7 +287,7 @@ class StacktachLifecycleTestCase(unittest.TestCase):
|
||||
self.mox.VerifyAll()
|
||||
|
||||
|
||||
class StacktachUsageParsingTestCase(unittest.TestCase):
|
||||
class StacktachUsageParsingTestCase(StacktachBaseTestCase):
|
||||
def setUp(self):
|
||||
self.mox = mox.Mox()
|
||||
views.STACKDB = self.mox.CreateMockAnything()
|
||||
@ -830,7 +830,7 @@ class StacktachUsageParsingTestCase(unittest.TestCase):
|
||||
self.mox.VerifyAll()
|
||||
|
||||
|
||||
class StacktachImageUsageParsingTestCase(unittest.TestCase):
|
||||
class StacktachImageUsageParsingTestCase(StacktachBaseTestCase):
|
||||
def setUp(self):
|
||||
self.mox = mox.Mox()
|
||||
views.STACKDB = self.mox.CreateMockAnything()
|
||||
|
@ -18,17 +18,15 @@
|
||||
# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
|
||||
# IN THE SOFTWARE.
|
||||
|
||||
import datetime
|
||||
import unittest
|
||||
|
||||
import mox
|
||||
|
||||
from stacktach import db
|
||||
from stacktach import stacklog
|
||||
from stacktach import models
|
||||
from tests.unit import StacktachBaseTestCase
|
||||
|
||||
|
||||
class StacktachDBTestCase(unittest.TestCase):
|
||||
class StacktachDBTestCase(StacktachBaseTestCase):
|
||||
def setUp(self):
|
||||
self.mox = mox.Mox()
|
||||
self.log = self.mox.CreateMockAnything()
|
||||
|
@ -18,17 +18,16 @@
|
||||
# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
|
||||
# IN THE SOFTWARE.
|
||||
|
||||
import unittest
|
||||
|
||||
import mox
|
||||
|
||||
from stacktach import utils as stacktach_utils
|
||||
from utils import INSTANCE_ID_1
|
||||
from utils import MESSAGE_ID_1
|
||||
from utils import REQUEST_ID_1
|
||||
from tests.unit import StacktachBaseTestCase
|
||||
|
||||
|
||||
class StacktachUtilsTestCase(unittest.TestCase):
|
||||
class StacktachUtilsTestCase(StacktachBaseTestCase):
|
||||
def setUp(self):
|
||||
self.mox = mox.Mox()
|
||||
|
||||
|
@ -21,7 +21,6 @@
|
||||
import datetime
|
||||
import decimal
|
||||
import json
|
||||
import unittest
|
||||
|
||||
import mox
|
||||
|
||||
@ -33,8 +32,10 @@ from utils import INSTANCE_ID_1
|
||||
from utils import INSTANCE_ID_2
|
||||
from utils import REQUEST_ID_1
|
||||
|
||||
from tests.unit import StacktachBaseTestCase
|
||||
|
||||
class StackyServerTestCase(unittest.TestCase):
|
||||
|
||||
class StackyServerTestCase(StacktachBaseTestCase):
|
||||
def setUp(self):
|
||||
self.mox = mox.Mox()
|
||||
self.mox.StubOutWithMock(models, 'RawData', use_mock_anything=True)
|
||||
|
@ -22,7 +22,6 @@ import datetime
|
||||
import decimal
|
||||
import json
|
||||
import time
|
||||
import unittest
|
||||
import uuid
|
||||
|
||||
|
||||
@ -51,9 +50,10 @@ from verifier import AmbiguousResults
|
||||
from verifier import FieldMismatch
|
||||
from verifier import NotFound
|
||||
from verifier import VerificationException
|
||||
from tests.unit import StacktachBaseTestCase
|
||||
|
||||
|
||||
class VerifierTestCase(unittest.TestCase):
|
||||
class VerifierTestCase(StacktachBaseTestCase):
|
||||
def setUp(self):
|
||||
self.mox = mox.Mox()
|
||||
self.mox.StubOutWithMock(models, 'RawData', use_mock_anything=True)
|
||||
|
@ -19,7 +19,6 @@
|
||||
# IN THE SOFTWARE.
|
||||
|
||||
import json
|
||||
import unittest
|
||||
|
||||
import kombu
|
||||
import mox
|
||||
@ -27,9 +26,10 @@ import mox
|
||||
from stacktach import db
|
||||
from stacktach import views
|
||||
import worker.worker as worker
|
||||
from tests.unit import StacktachBaseTestCase
|
||||
|
||||
|
||||
class ConsumerTestCase(unittest.TestCase):
|
||||
class ConsumerTestCase(StacktachBaseTestCase):
|
||||
def setUp(self):
|
||||
self.mox = mox.Mox()
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user