diff --git a/zun/db/sqlalchemy/alembic/versions/271c7f45982d_add_started_at_to_container.py b/zun/db/sqlalchemy/alembic/versions/271c7f45982d_add_started_at_to_container.py new file mode 100644 index 000000000..9024b4bed --- /dev/null +++ b/zun/db/sqlalchemy/alembic/versions/271c7f45982d_add_started_at_to_container.py @@ -0,0 +1,34 @@ +# 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. + +"""add started_at to containers + +Revision ID: 271c7f45982d +Revises: cff60402dd86 +Create Date: 2018-05-03 11:27:00.722445 + +""" + +# revision identifiers, used by Alembic. +revision = '271c7f45982d' +down_revision = 'cff60402dd86' +branch_labels = None +depends_on = None + +from alembic import op +import sqlalchemy as sa + + +def upgrade(): + op.add_column('container', + sa.Column('started_at', sa.DateTime(), + nullable=True)) diff --git a/zun/db/sqlalchemy/models.py b/zun/db/sqlalchemy/models.py index b3f21ad7d..e66182529 100644 --- a/zun/db/sqlalchemy/models.py +++ b/zun/db/sqlalchemy/models.py @@ -169,6 +169,7 @@ class Container(Base): auto_heal = Column(Boolean, default=False) capsule_id = Column(Integer, ForeignKey('capsule.id', ondelete='CASCADE')) + started_at = Column(DateTime, default=timeutils.utcnow) class VolumeMapping(Base): diff --git a/zun/objects/container.py b/zun/objects/container.py index 01027aae7..774fa0855 100644 --- a/zun/objects/container.py +++ b/zun/objects/container.py @@ -59,7 +59,8 @@ class Container(base.ZunPersistentObject, base.ZunObject): # Version 1.28: Add 'Dead' to ContainerStatus # Version 1.29: Add 'Restarting' to ContainerStatus # Version 1.30: Add capsule_id attribute - VERSION = '1.30' + # Version 1.31: Add 'started_at' attribute + VERSION = '1.31' fields = { 'id': fields.IntegerField(), @@ -98,6 +99,7 @@ class Container(base.ZunPersistentObject, base.ZunObject): 'disk': fields.IntegerField(nullable=True), 'auto_heal': fields.BooleanField(nullable=True), 'capsule_id': fields.IntegerField(nullable=True), + 'started_at': fields.DateTimeField(nullable=True), } @staticmethod diff --git a/zun/tests/unit/db/utils.py b/zun/tests/unit/db/utils.py index de935b9fb..f7c3a9693 100644 --- a/zun/tests/unit/db/utils.py +++ b/zun/tests/unit/db/utils.py @@ -101,6 +101,7 @@ def get_test_container(**kwargs): 'disk': kwargs.get('disk', 20), 'auto_heal': kwargs.get('auto_heal', False), 'capsule_id': kwargs.get('capsule_id', 42), + 'started_at': kwargs.get('started_at'), } diff --git a/zun/tests/unit/objects/test_objects.py b/zun/tests/unit/objects/test_objects.py index a23f94794..1e16fdd7a 100644 --- a/zun/tests/unit/objects/test_objects.py +++ b/zun/tests/unit/objects/test_objects.py @@ -344,7 +344,7 @@ class TestObject(test_base.TestCase, _TestObject): # For more information on object version testing, read # https://docs.openstack.org/zun/latest/ object_data = { - 'Container': '1.30-fc17da52173f258245d424c9a5cf99c7', + 'Container': '1.31-4e1f27e1326bc42c7fa7ca0681bbe883', 'VolumeMapping': '1.1-50df6202f7846a136a91444c38eba841', 'Image': '1.1-330e6205c80b99b59717e1cfc6a79935', 'MyObj': '1.0-34c4b1aadefd177b13f9a2f894cc23cd',