Skip to content
This repository has been archived by the owner on Feb 20, 2018. It is now read-only.

Commit

Permalink
Deleted field for session model
Browse files Browse the repository at this point in the history
  • Loading branch information
Stanislav Zubov authored and Stanislav Zubov committed Oct 14, 2015
1 parent e8d7aa9 commit c68a457
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 5 deletions.
1 change: 1 addition & 0 deletions core/db/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ class Session(Base, FeaturesMixin):
run_script = Column(String)
created = Column(DateTime, default=datetime.now)
modified = Column(DateTime, default=datetime.now)
deleted = Column(DateTime)

# State
status = Column(Enum('unknown', 'running', 'succeed', 'failed', 'waiting',
Expand Down
8 changes: 4 additions & 4 deletions core/sessions.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,10 @@ def delete(self, message=""):
if self.vnc_recorder:
self.vnc_recorder.stop()

self.closed = True
self.deleted = datetime.now()
self.save()

current_app.sessions.remove(self)
if hasattr(self, "endpoint"):
log.info("Deleting VM for session: %s" % self.id)
Expand All @@ -125,15 +129,11 @@ def delete(self, message=""):

def succeed(self):
self.status = "succeed"
self.closed = True
self.save()
self.delete()

def failed(self, tb="Session closed by user"):
self.status = "failed"
self.closed = True
self.error = tb
self.save()
self.delete(tb)

def set_vm(self, endpoint):
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
"""deleted_field_for_session
Revision ID: 1de18183a7da
Revises: 3d52588e4d9c
Create Date: 2015-10-07 18:20:57.252212
"""

# revision identifiers, used by Alembic.
revision = '1de18183a7da'
down_revision = '3d52588e4d9c'

from alembic import op
import sqlalchemy as sa


def upgrade():
op.add_column('sessions', sa.Column('deleted', sa.DateTime(),
nullable=True))


def downgrade():
op.drop_column('sessions', 'deleted')
2 changes: 1 addition & 1 deletion migrations/migrations.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@


def run(connection_string):
revision = "3d52588e4d9c"
revision = "1de18183a7da"

alembic_cfg.set_main_option("sqlalchemy.url", connection_string)
try:
Expand Down
2 changes: 2 additions & 0 deletions tests/unit/test_commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,8 @@ def setUp(self):
def tearDown(self):
with patch(
'flask.current_app.sessions', Mock()
), patch(
'flask.current_app.database', Mock()
), patch(
'vmpool.endpoint.delete_vm', Mock()
):
Expand Down

0 comments on commit c68a457

Please sign in to comment.