Merge "Add processed field with current time"

This commit is contained in:
Jenkins 2017-08-14 14:35:55 +00:00 committed by Gerrit Code Review
commit 047ecdffd7
10 changed files with 115 additions and 75 deletions

View File

@ -11,6 +11,7 @@
# 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.
from datetime import datetime
from oslo_log import log
@ -22,7 +23,6 @@ LOG = log.getLogger(__name__)
class InstanceController(base_controller.BaseController):
def __init__(self, config, database_adapter):
self.config = config
self.database_adapter = database_adapter
@ -44,6 +44,7 @@ class InstanceController(base_controller.BaseController):
start=create_date,
end=None,
name=name,
processed=datetime.utcnow(),
flavor=flavor,
image_meta=image_meta,
metadata=self._filter_metadata(metadata))
@ -53,11 +54,15 @@ class InstanceController(base_controller.BaseController):
def delete_instance(self, instance_id, delete_date):
if not self.database_adapter.has_active_entity(instance_id):
raise exception.EntityNotFoundException(
"InstanceId: {0} Not Found".format(instance_id))
"InstanceId: {0} Not Found".format(instance_id))
delete_date = self._validate_and_parse_date(delete_date)
LOG.info("Instance %s deleted on %s", instance_id, delete_date)
self.database_adapter.close_active_entity(instance_id, delete_date)
instance = self.database_adapter.get_active_entity(instance_id)
instance.end = instance.last_event = delete_date
instance.processed = datetime.utcnow()
self.database_adapter.update_active_entity(instance)
def resize_instance(self, instance_id, flavor, resize_date):
resize_date = self._validate_and_parse_date(resize_date)
@ -65,11 +70,15 @@ class InstanceController(base_controller.BaseController):
try:
instance = self.database_adapter.get_active_entity(instance_id)
if flavor != instance.flavor:
self.database_adapter.close_active_entity(instance_id, resize_date)
instance.end = instance.last_event = resize_date
instance.processed = datetime.utcnow()
self.database_adapter.update_active_entity(instance)
instance.flavor = flavor
instance.start = resize_date
instance.end = None
instance.last_event = resize_date
instance.processed = datetime.utcnow()
self.database_adapter.insert_entity(instance)
except exception.EntityNotFoundException as e:
LOG.error("Trying to resize an instance with id '%s' not in the database yet.", instance_id)
@ -83,11 +92,16 @@ class InstanceController(base_controller.BaseController):
instance_id, instance.project_id, image_meta, rebuild_date)
if instance.image_meta != image_meta:
self.database_adapter.close_active_entity(instance_id, rebuild_date)
instance.end = instance.last_event = rebuild_date
instance.processed = datetime.utcnow()
self.database_adapter.update_active_entity(instance)
instance.image_meta = image_meta
instance.start = rebuild_date
instance.end = None
instance.last_event = rebuild_date
instance.processed = datetime.utcnow()
self.database_adapter.insert_entity(instance)
def list_instances(self, project_id, start, end):

View File

@ -12,6 +12,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.
from datetime import datetime
from datetime import timedelta
from oslo_log import log
@ -24,7 +25,6 @@ LOG = log.getLogger(__name__)
class VolumeController(base_controller.BaseController):
def __init__(self, config, database_adapter):
self.database_adapter = database_adapter
self.volume_existence_threshold = timedelta(0, config.entities.volume_existence_threshold)
@ -41,7 +41,7 @@ class VolumeController(base_controller.BaseController):
volume_type_name = self._get_volume_type_name(volume_type)
entity = model.Volume(volume_id, project_id, start, None, volume_type_name, size, start, volume_name,
attached_to)
datetime.utcnow(), attached_to)
self.database_adapter.insert_entity(entity)
def detach_volume(self, volume_id, date, attachments):
@ -68,6 +68,8 @@ class VolumeController(base_controller.BaseController):
if volume and volume.name != volume_name:
LOG.info("volume %s renamed from %s to %s", volume_id, volume.name, volume_name)
volume.name = volume_name
volume.processed = datetime.utcnow()
self.database_adapter.update_active_entity(volume)
except exception.EntityNotFoundException:
LOG.error("Trying to update a volume with id '%s' not in the database yet.", volume_id)
@ -78,13 +80,15 @@ class VolumeController(base_controller.BaseController):
volume = self.database_adapter.get_active_entity(volume_id)
LOG.info("volume %s updated in project %s to size %s on %s",
volume_id, volume.project_id, size, update_date)
self.database_adapter.close_active_entity(volume_id, update_date)
volume.end = volume.last_event = update_date
volume.processed = datetime.utcnow()
self.database_adapter.update_active_entity(volume)
volume.size = size
volume.start = update_date
volume.end = None
volume.last_event = update_date
volume.processed = datetime.utcnow()
self.database_adapter.insert_entity(volume)
except exception.EntityNotFoundException as e:
LOG.error("Trying to update a volume with id '%s' not in the database yet.", volume_id)
@ -94,12 +98,15 @@ class VolumeController(base_controller.BaseController):
delete_date = self._localize_date(self._validate_and_parse_date(delete_date))
LOG.info("volume %s deleted on %s", volume_id, delete_date)
try:
volume = self.database_adapter.get_active_entity(volume_id)
if self.database_adapter.count_entity_entries(volume_id) > 1:
volume = self.database_adapter.get_active_entity(volume_id)
if delete_date - volume.start < self.volume_existence_threshold:
self.database_adapter.delete_active_entity(volume_id)
return
self.database_adapter.close_active_entity(volume_id, delete_date)
volume.end = volume.last_event = delete_date
volume.processed = datetime.utcnow()
self.database_adapter.update_active_entity(volume)
except exception.EntityNotFoundException as e:
LOG.error("Trying to delete a volume with id '%s' not in the database yet.", volume_id)
raise e
@ -109,28 +116,37 @@ class VolumeController(base_controller.BaseController):
date = self._localize_date(date)
volume.last_event = date
existing_attachments = volume.attached_to
volume.attached_to = attachments
volume.processed = datetime.utcnow()
if existing_attachments or self._is_within_threshold(date, volume):
volume.attached_to = attachments
self.database_adapter.update_active_entity(volume)
else:
self._close_volume(volume_id, volume, date)
self._close_active_volume_create_new_with_attachments(attachments, date, volume)
def _volume_detach_instance(self, volume_id, date, attachments):
volume = self.database_adapter.get_active_entity(volume_id)
date = self._localize_date(date)
volume.last_event = date
volume.attached_to = attachments
volume.processed = datetime.utcnow()
if attachments or self._is_within_threshold(date, volume):
volume.attached_to = attachments
LOG.info("Live attach for volume %s with %s", volume.entity_id, volume.attached_to)
self.database_adapter.update_active_entity(volume)
else:
self._close_volume(volume_id, volume, date)
self._close_active_volume_create_new_with_attachments(attachments, date, volume)
def _close_volume(self, volume_id, volume, date):
self.database_adapter.close_active_entity(volume_id, date)
def _close_active_volume_create_new_with_attachments(self, attachments, date, volume):
LOG.info("closing volume %s with attached %s", volume.entity_id, volume.attached_to)
volume.end = date
self.database_adapter.update_active_entity(volume)
volume.attached_to = attachments
volume.start = date
volume.end = None
volume.processed = datetime.utcnow()
LOG.info("Creating volume %s with attachments with %s", volume.entity_id, volume.attached_to)
self.database_adapter.insert_entity(volume)
def _is_within_threshold(self, date, volume):

View File

@ -13,6 +13,7 @@
# limitations under the License.
import abc
import six
from almanach.core import exception
@ -20,8 +21,7 @@ from almanach.core import exception
@six.add_metaclass(abc.ABCMeta)
class Entity(object):
def __init__(self, entity_id, project_id, start, end, last_event, name, entity_type):
def __init__(self, entity_id, project_id, start, end, last_event, name, entity_type, processed):
self.entity_id = entity_id
self.project_id = project_id
self.start = start
@ -29,6 +29,7 @@ class Entity(object):
self.last_event = last_event
self.name = name
self.entity_type = entity_type
self.processed = processed
def as_dict(self):
return dict(
@ -39,6 +40,7 @@ class Entity(object):
last_event=self.last_event,
name=self.name,
entity_type=self.entity_type,
processed=self.processed,
)
@staticmethod
@ -61,8 +63,9 @@ class Entity(object):
class Instance(Entity):
TYPE = 'instance'
def __init__(self, entity_id, project_id, start, end, flavor, last_event, name, image_meta=None, metadata=None):
super(Instance, self).__init__(entity_id, project_id, start, end, last_event, name, self.TYPE)
def __init__(self, entity_id, project_id, start, end, flavor, last_event, name, processed, image_meta=None,
metadata=None):
super(Instance, self).__init__(entity_id, project_id, start, end, last_event, name, self.TYPE, processed)
self.flavor = flavor
self.metadata = metadata or dict()
self.image_meta = image_meta or dict()
@ -96,6 +99,7 @@ class Instance(Entity):
end=d.get('end'),
last_event=d.get('last_event'),
name=d.get('name'),
processed=d.get('processed'),
flavor=d.get('flavor'),
image_meta=d.get('os') or d.get('image_meta'),
metadata=Instance._unserialize_metadata(d),
@ -125,8 +129,9 @@ class Instance(Entity):
class Volume(Entity):
TYPE = 'volume'
def __init__(self, entity_id, project_id, start, end, volume_type, size, last_event, name, attached_to=None):
super(Volume, self).__init__(entity_id, project_id, start, end, last_event, name, self.TYPE)
def __init__(self, entity_id, project_id, start, end, volume_type, size, last_event, name, processed,
attached_to=None):
super(Volume, self).__init__(entity_id, project_id, start, end, last_event, name, self.TYPE, processed)
self.volume_type = volume_type
self.size = size
self.attached_to = attached_to or []
@ -153,6 +158,7 @@ class Volume(Entity):
end=d.get('end'),
last_event=d.get('last_event'),
name=d.get('name'),
processed=d.get('processed'),
volume_type=d.get('volume_type'),
size=d.get('size'),
attached_to=d.get('attached_to'),
@ -160,7 +166,6 @@ class Volume(Entity):
class VolumeType(object):
def __init__(self, volume_type_id, volume_type_name):
self.volume_type_id = volume_type_id
self.volume_type_name = volume_type_name
@ -187,4 +192,4 @@ def get_entity_from_dict(d):
elif entity_type == Volume.TYPE:
return Volume.from_dict(d)
raise exception.EntityTypeNotSupportedException(
'Unsupported entity type: "{}"'.format(entity_type))
'Unsupported entity type: "{}"'.format(entity_type))

View File

@ -66,10 +66,6 @@ class BaseDriver(object):
def insert_entity(self, entity):
pass
@abc.abstractmethod
def close_active_entity(self, entity_id, end):
pass
@abc.abstractmethod
def update_active_entity(self, entity):
pass

View File

@ -11,7 +11,6 @@
# 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.
import pymongo
from almanach.core import exception
@ -21,7 +20,6 @@ from almanach.storage.drivers import base_driver
class MongoDbDriver(base_driver.BaseDriver):
def __init__(self, config, db=None):
super(MongoDbDriver, self).__init__(config)
self.db = db
@ -79,9 +77,6 @@ class MongoDbDriver(base_driver.BaseDriver):
}, {"_id": 0})
return [get_entity_from_dict(entity) for entity in entities]
def close_active_entity(self, entity_id, end):
self.db.entity.update({"entity_id": entity_id, "end": None}, {"$set": {"end": end, "last_event": end}})
def insert_entity(self, entity):
self.db.entity.insert(entity.as_dict())

View File

@ -16,13 +16,19 @@ from almanach.tests.tempest.tests.scenario import base
class TestVolumeCreationScenario(base.BaseAlmanachScenarioTest):
def test_create_volume(self):
volume = self.create_volume()
self.wait_for_notification(self._check_that_a_new_entity_is_created,
volume)
entities = self.get_tenant_entities(volume['os-vol-tenant-attr:tenant_id'])
self.assertEqual(1, len(entities))
self.assertEqual(volume['id'], entities[0]['entity_id'])
self.assertEqual(volume['volume_type'], entities[0]['volume_type'])
self.assertIsNotNone(entities[0]['start'])
self.assertIsNone(entities[0]['end'])
def _check_that_a_new_entity_is_created(self, volume):
entities = self.get_tenant_entities(volume['os-vol-tenant-attr:tenant_id'])
return len(entities) == 1

View File

@ -50,21 +50,6 @@ class TestInstanceController(base.BaseTestCase):
self.database_adapter.get_active_entity.assert_called_once_with(fake_instance.entity_id)
self.database_adapter.insert_entity.assert_called_once()
def test_resize_instance(self):
fake_instance = a(instance())
self.database_adapter.get_active_entity.return_value = fake_instance
dates_str = "2015-10-21T16:25:00.000000Z"
fake_instance.start = parse(dates_str)
fake_instance.end = None
fake_instance.last_event = parse(dates_str)
self.controller.resize_instance(fake_instance.entity_id, "newly_flavor", dates_str)
self.database_adapter.get_active_entity.assert_called_once_with(fake_instance.entity_id)
self.database_adapter.close_active_entity.assert_called_once_with(fake_instance.entity_id, parse(dates_str))
self.database_adapter.insert_entity.assert_called_once_with(fake_instance)
def test_instance_created_but_its_an_old_event(self):
fake_instance = a(instance()
.with_last_event(pytz.utc.localize(datetime(2015, 10, 21, 16, 29, 0))))
@ -87,12 +72,17 @@ class TestInstanceController(base.BaseTestCase):
self.database_adapter.insert_entity.assert_called_once()
def test_instance_deleted(self):
fake_instance = a(instance())
self.database_adapter.has_active_entity.return_value = True
self.database_adapter.get_active_entity.return_value = fake_instance
self.controller.delete_instance("id1", "2015-10-21T16:25:00.000000Z")
self.database_adapter.has_active_entity.assert_called_once_with("id1")
self.database_adapter.close_active_entity.assert_called_once_with("id1", parse("2015-10-21T16:25:00.000000Z"))
self.database_adapter.get_active_entity.assert_called_once_with("id1")
self.database_adapter.update_active_entity.assert_called_once_with(fake_instance)
self.assertEqual(fake_instance.end, parse("2015-10-21T16:25:00.000000Z"))
def test_instance_deleted_when_entity_not_found(self):
self.database_adapter.has_active_entity.return_value = False
@ -103,14 +93,20 @@ class TestInstanceController(base.BaseTestCase):
self.database_adapter.has_active_entity.assert_called_once_with("id1")
def test_list_instances(self):
self.database_adapter.get_all_entities_by_project.return_value = ["instance1", "instance2"]
def test_instance_resized(self):
fake_instance = a(instance())
self.database_adapter.get_active_entity.return_value = fake_instance
self.assertEqual(self.controller.list_instances("project_id", "start", "end"), ["instance1", "instance2"])
dates_str = "2015-10-21T16:25:00.000000Z"
fake_instance.start = parse(dates_str)
fake_instance.end = None
fake_instance.last_event = parse(dates_str)
self.database_adapter.get_all_entities_by_project.assert_called_once_with(
"project_id", "start", "end", model.Instance.TYPE
)
self.controller.resize_instance(fake_instance.entity_id, "newly_flavor", dates_str)
self.database_adapter.get_active_entity.assert_called_once_with(fake_instance.entity_id)
self.database_adapter.update_active_entity.assert_called_once_with(fake_instance)
self.database_adapter.insert_entity.assert_called_once_with(fake_instance)
def test_instance_rebuilded(self):
i = a(instance())
@ -129,5 +125,14 @@ class TestInstanceController(base.BaseTestCase):
)
self.database_adapter.get_active_entity.assert_has_calls(calls)
self.database_adapter.close_active_entity.assert_called_once()
self.database_adapter.update_active_entity.assert_called_once_with(i)
self.database_adapter.insert_entity.assert_called_once()
def test_list_instances(self):
self.database_adapter.get_all_entities_by_project.return_value = ["instance1", "instance2"]
self.assertEqual(self.controller.list_instances("project_id", "start", "end"), ["instance1", "instance2"])
self.database_adapter.get_all_entities_by_project.assert_called_once_with(
"project_id", "start", "end", model.Instance.TYPE
)

View File

@ -44,13 +44,12 @@ class TestVolumeController(base.BaseTestCase):
date = datetime(fake_volume.start.year, fake_volume.start.month, fake_volume.start.day, fake_volume.start.hour,
fake_volume.start.minute, fake_volume.start.second, fake_volume.start.microsecond)
date = date + timedelta(1)
expected_date = pytz.utc.localize(date)
self.controller.delete_volume(fake_volume.entity_id, date.strftime("%Y-%m-%dT%H:%M:%S.%fZ"))
self.database_adapter.count_entity_entries.assert_called_once_with(fake_volume.entity_id)
self.database_adapter.get_active_entity.assert_called_once_with(fake_volume.entity_id)
self.database_adapter.close_active_entity.assert_called_once_with(fake_volume.entity_id, expected_date)
self.database_adapter.update_active_entity.assert_called_once_with(fake_volume)
def test_volume_deleted_within_volume_existance_threshold(self):
fake_volume = a(volume())
@ -70,16 +69,16 @@ class TestVolumeController(base.BaseTestCase):
def test_volume_deleted_within_volume_existance_threshold_but_with_only_one_entry(self):
fake_volume = a(volume())
self.database_adapter.count_entity_entries.return_value = 1
self.database_adapter.get_active_entity.return_value = fake_volume
date = datetime(fake_volume.start.year, fake_volume.start.month, fake_volume.start.day, fake_volume.start.hour,
fake_volume.start.minute, fake_volume.start.second, fake_volume.start.microsecond)
date = date + timedelta(0, 5)
expected_date = pytz.utc.localize(date)
self.controller.delete_volume(fake_volume.entity_id, date.strftime("%Y-%m-%dT%H:%M:%S.%fZ"))
self.database_adapter.count_entity_entries.assert_called_once_with(fake_volume.entity_id)
self.database_adapter.close_active_entity.assert_called_once_with(fake_volume.entity_id, expected_date)
self.database_adapter.update_active_entity.assert_called_once_with(fake_volume)
def test_list_volumes(self):
self.database_adapter.get_all_entities_by_project.return_value = ["volume2", "volume3"]
@ -176,7 +175,7 @@ class TestVolumeController(base.BaseTestCase):
self.database_adapter.get_active_entity.assert_called_once_with(some_volume.entity_id)
def test_volume_updated(self):
def test_volume_resize(self):
fake_volume = a(volume())
dates_str = "2015-10-21T16:25:00.000000Z"
fake_volume.size = "new_size"
@ -188,7 +187,7 @@ class TestVolumeController(base.BaseTestCase):
self.controller.resize_volume(fake_volume.entity_id, "new_size", dates_str)
self.database_adapter.get_active_entity.assert_called_once_with(fake_volume.entity_id)
self.database_adapter.close_active_entity.assert_called_once_with(fake_volume.entity_id, parse(dates_str))
self.database_adapter.update_active_entity.assert_called_once_with(fake_volume)
self.database_adapter.insert_entity.assert_called_once_with(fake_volume)
def test_volume_attach_with_no_existing_attachment(self):
@ -250,7 +249,7 @@ class TestVolumeController(base.BaseTestCase):
)
self.database_adapter.get_active_entity.assert_called_once_with(fake_volume.entity_id)
self.database_adapter.close_active_entity.assert_called_once_with(fake_volume.entity_id, expected_date)
self.database_adapter.update_active_entity.assert_called_once_with(fake_volume)
self.database_adapter.insert_entity.assert_called_once_with(new_volume)
def test_volume_detach_with_two_attachments(self):
@ -299,7 +298,7 @@ class TestVolumeController(base.BaseTestCase):
self.assertEqual(fake_volume.attached_to, [])
self.database_adapter.get_active_entity.assert_called_once_with(fake_volume.entity_id)
self.database_adapter.close_active_entity.assert_called_once_with(fake_volume.entity_id, expected_date)
self.database_adapter.update_active_entity.assert_called_once_with(fake_volume)
self.database_adapter.insert_entity.assert_called_once_with(new_volume)
def test_rename_volume(self):

View File

@ -30,6 +30,7 @@ class TestModel(base.BaseTestCase):
project_id='project_id',
start=datetime(2014, 1, 1, 0, 0, 0, 0, pytz.utc),
end=None,
processed=datetime(2014, 1, 1, 0, 0, 0, 0, pytz.utc),
flavor='flavor_id',
image_meta=dict(os_type='linux', distro='Ubuntu', version='16.04'),
last_event=datetime(2014, 1, 1, 0, 0, 0, 0, pytz.utc),
@ -61,6 +62,7 @@ class TestModel(base.BaseTestCase):
'start': datetime(2014, 1, 1, 0, 0, 0, 0, pytz.utc),
'end': None,
'last_event': datetime(2014, 1, 1, 0, 0, 0, 0, pytz.utc),
'processed': datetime(2014, 1, 1, 0, 0, 0, 0, pytz.utc),
'flavor': 'flavor_id',
'image_meta': {
'os_type': 'linux',
@ -79,6 +81,7 @@ class TestModel(base.BaseTestCase):
self.assertEqual('linux', instance.image_meta['os_type'])
self.assertEqual('Ubuntu', instance.image_meta['distro'])
self.assertEqual('16.04', instance.image_meta['version'])
self.assertEqual(datetime(2014, 1, 1, 0, 0, 0, 0, pytz.utc), instance.processed)
self.assertEqual(datetime(2014, 1, 1, 0, 0, 0, 0, pytz.utc), instance.last_event)
self.assertEqual(datetime(2014, 1, 1, 0, 0, 0, 0, pytz.utc), instance.start)
self.assertIsNone(instance.end)
@ -91,6 +94,7 @@ class TestModel(base.BaseTestCase):
'start': datetime(2014, 1, 1, 0, 0, 0, 0, pytz.utc),
'end': None,
'last_event': datetime(2014, 1, 1, 0, 0, 0, 0, pytz.utc),
'processed': datetime(2014, 1, 1, 0, 0, 0, 0, pytz.utc),
'flavor': 'flavor_id',
'os': {
'os_type': 'linux',
@ -110,6 +114,7 @@ class TestModel(base.BaseTestCase):
self.assertEqual('Ubuntu', instance.image_meta['distro'])
self.assertEqual('16.04', instance.image_meta['version'])
self.assertEqual(datetime(2014, 1, 1, 0, 0, 0, 0, pytz.utc), instance.last_event)
self.assertEqual(datetime(2014, 1, 1, 0, 0, 0, 0, pytz.utc), instance.processed)
self.assertEqual(datetime(2014, 1, 1, 0, 0, 0, 0, pytz.utc), instance.start)
self.assertIsNone(instance.end)
@ -154,6 +159,7 @@ class TestModel(base.BaseTestCase):
project_id='project_id',
start=datetime(2014, 1, 1, 0, 0, 0, 0, pytz.utc),
end=None,
processed=None,
flavor='flavor_id',
image_meta=dict(os_type='linux', distro='Ubuntu', version='16.04'),
last_event=datetime(2014, 1, 1, 0, 0, 0, 0, pytz.utc),
@ -166,6 +172,7 @@ class TestModel(base.BaseTestCase):
project_id='project_id',
start=datetime(2014, 1, 1, 0, 0, 0, 0, pytz.utc),
end=None,
processed=None,
flavor='flavor_id',
image_meta=dict(os_type='linux', distro='Ubuntu', version='16.04'),
last_event=datetime(2014, 1, 1, 0, 0, 0, 0, pytz.utc),
@ -179,6 +186,7 @@ class TestModel(base.BaseTestCase):
project_id='project_id',
start=datetime(2014, 1, 1, 0, 0, 0, 0, pytz.utc),
end=None,
processed=None,
flavor='flavor_id',
image_meta=dict(os_type='linux', distro='Centos', version='7'),
last_event=datetime(2014, 1, 1, 0, 0, 0, 0, pytz.utc),
@ -192,6 +200,7 @@ class TestModel(base.BaseTestCase):
project_id='project_id',
start=datetime(2014, 1, 1, 0, 0, 0, 0, pytz.utc),
end=None,
processed=None,
flavor='another_flavor',
image_meta=dict(os_type='linux', distro='Ubuntu', version='16.04'),
last_event=datetime(2014, 1, 1, 0, 0, 0, 0, pytz.utc),
@ -205,6 +214,7 @@ class TestModel(base.BaseTestCase):
project_id='project_id',
start=datetime(2014, 1, 1, 0, 0, 0, 0, pytz.utc),
end=None,
processed=None,
flavor='flavor_id',
image_meta=dict(os_type='linux', distro='Ubuntu', version='16.04'),
last_event=datetime(2014, 1, 1, 0, 0, 0, 0, pytz.utc),
@ -223,6 +233,7 @@ class TestModel(base.BaseTestCase):
project_id='project_id',
start=datetime(2014, 1, 1, 0, 0, 0, 0, pytz.utc),
end=None,
processed=datetime(2014, 1, 1, 0, 0, 0, 0, pytz.utc),
last_event=datetime(2014, 1, 1, 0, 0, 0, 0, pytz.utc),
name='volume_name',
volume_type='volume_type_id',
@ -272,6 +283,7 @@ class TestModel(base.BaseTestCase):
project_id='project_id',
start=datetime(2014, 1, 1, 0, 0, 0, 0, pytz.utc),
end=None,
processed=None,
last_event=datetime(2014, 1, 1, 0, 0, 0, 0, pytz.utc),
name='volume_name',
volume_type='volume_type_id',
@ -284,6 +296,7 @@ class TestModel(base.BaseTestCase):
project_id='project_id',
start=datetime(2014, 1, 1, 0, 0, 0, 0, pytz.utc),
end=None,
processed=None,
last_event=datetime(2014, 1, 1, 0, 0, 0, 0, pytz.utc),
name='volume_name',
volume_type='volume_type_id',

View File

@ -300,15 +300,6 @@ class TestMongoDbDriver(base.BaseTestCase):
self.assertEqual(1, len(entities))
self.assertEqual("instance with end date", entities[0].name)
def test_close_active_entity(self):
fake_entity = a(instance())
end_date = datetime(2015, 10, 21, 16, 29, 0)
self.db.entity.insert(fake_entity.as_dict())
self.adapter.close_active_entity(fake_entity.entity_id, end_date)
self.assertEqual(self.db.entity.find_one({"entity_id": fake_entity.entity_id})["end"], end_date)
def test_update_closed_entity(self):
fake_entity = a(instance().with_end(2016, 3, 2, 0, 0, 0))