From 2f161b0ae6347368746c1eef5f51e5cee7521f8d Mon Sep 17 00:00:00 2001 From: Goutham Pratapa Date: Fri, 17 Feb 2017 11:06:20 +0530 Subject: [PATCH] Change display output while listing sync_jobs Currently while listing the sync_jobs.Kingbird doesnt display the parameter (created_at) and source_region in the job_details. Change-Id: I4814f8039dfc080dc340a15c94d0292e57604e1b --- kingbird/api/controllers/sync_manager.py | 4 ++-- kingbird/db/api.py | 6 ++--- kingbird/db/sqlalchemy/api.py | 23 +++++++++++++------ .../migrate_repo/versions/006_sync_job.py | 4 +++- kingbird/db/sqlalchemy/models.py | 4 +++- .../unit/db/test_resource_sync_db_api.py | 22 +++++++++++------- 6 files changed, 41 insertions(+), 22 deletions(-) diff --git a/kingbird/api/controllers/sync_manager.py b/kingbird/api/controllers/sync_manager.py index a2c88f8..0ba3a56 100644 --- a/kingbird/api/controllers/sync_manager.py +++ b/kingbird/api/controllers/sync_manager.py @@ -115,8 +115,8 @@ class ResourceSyncController(object): for keypair in source_keys: try: db_api.resource_sync_create(context, result, - region, keypair, - consts.KEYPAIR) + region, source_region, + keypair, consts.KEYPAIR) except exceptions.JobNotFound: pecan.abort(404, _('Job not found')) return self._keypair_sync(job_id, user_id, payload, context, diff --git a/kingbird/db/api.py b/kingbird/db/api.py index b1c0fdc..db10b76 100644 --- a/kingbird/db/api.py +++ b/kingbird/db/api.py @@ -170,10 +170,10 @@ def sync_job_delete(context, job_id): return IMPL.sync_job_delete(context, job_id) -def resource_sync_create(context, job, region, resource, +def resource_sync_create(context, job, region, source_region, resource, resource_type): - return IMPL.resource_sync_create(context, job, region, resource, - resource_type) + return IMPL.resource_sync_create(context, job, region, source_region, + resource, resource_type) def resource_sync_update(context, job_id, region, resource, status): diff --git a/kingbird/db/sqlalchemy/api.py b/kingbird/db/sqlalchemy/api.py index dd41c3d..e6674dd 100644 --- a/kingbird/db/sqlalchemy/api.py +++ b/kingbird/db/sqlalchemy/api.py @@ -413,7 +413,11 @@ def sync_job_list(context, action=None): result = dict() result['id'] = row.id result['sync_status'] = row.sync_status - result['updated_at'] = row.updated_at + result['created_at'] = row.created_at + if row.updated_at: + result['updated_at'] = row.updated_at + else: + result['updated_at'] = "None" output.append(result) return output @@ -461,15 +465,16 @@ def sync_job_delete(context, job_id): ########################## @require_context -def resource_sync_create(context, job, region, resource, - resource_type): +def resource_sync_create(context, job, region, source_region, + resource, resource_type): if not job: raise exception.JobNotFound() with write_session() as session: rsc = models.ResourceSync() rsc.sync_job = job rsc.resource = resource - rsc.region = region + rsc.target_region = region + rsc.source_region = source_region rsc.resource_type = resource_type session.add(rsc) return rsc @@ -479,7 +484,7 @@ def resource_sync_create(context, job, region, resource, def resource_sync_update(context, job_id, region, resource, status): with write_session() as session: resource_sync_ref = session.query(models.ResourceSync).\ - filter_by(job_id=job_id, region=region, resource=resource).\ + filter_by(job_id=job_id, target_region=region, resource=resource).\ first() if not resource_sync_ref: raise exception.JobNotFound() @@ -515,11 +520,15 @@ def resource_sync_list_by_job(context, job_id): raise exception.JobNotFound() for row in rows: result = dict() - result['region'] = row.region + result['target_region'] = row.target_region + result['source_region'] = row.source_region result['resource'] = row.resource result['resource_type'] = row.resource_type result['sync_status'] = row.sync_status - result['updated_at'] = row.updated_at.isoformat() + if row.updated_at: + result['updated_at'] = row.updated_at.isoformat() + else: + result['updated_at'] = "None" result['created_at'] = row.created_at.isoformat() output.append(result) return output diff --git a/kingbird/db/sqlalchemy/migrate_repo/versions/006_sync_job.py b/kingbird/db/sqlalchemy/migrate_repo/versions/006_sync_job.py index 75d0eee..00a25ef 100644 --- a/kingbird/db/sqlalchemy/migrate_repo/versions/006_sync_job.py +++ b/kingbird/db/sqlalchemy/migrate_repo/versions/006_sync_job.py @@ -43,7 +43,9 @@ def upgrade(migrate_engine): sqlalchemy.Column('job_id', sqlalchemy.String(36), sqlalchemy.ForeignKey('sync_job.id'), primary_key=True), - sqlalchemy.Column('region', sqlalchemy.String(36), + sqlalchemy.Column('source_region', sqlalchemy.String(36), + primary_key=True), + sqlalchemy.Column('target_region', sqlalchemy.String(36), primary_key=True), sqlalchemy.Column('resource', sqlalchemy.String(36), primary_key=True), diff --git a/kingbird/db/sqlalchemy/models.py b/kingbird/db/sqlalchemy/models.py index 488ffef..0cfc399 100644 --- a/kingbird/db/sqlalchemy/models.py +++ b/kingbird/db/sqlalchemy/models.py @@ -174,7 +174,9 @@ class ResourceSync(BASE, KingbirdBase): job_id = Column('job_id', String(36), ForeignKey('sync_job.id'), primary_key=True) - region = Column('region', String(36), primary_key=True) + source_region = Column('source_region', String(36), primary_key=True) + + target_region = Column('target_region', String(36), primary_key=True) resource = Column('resource', String(36), primary_key=True) diff --git a/kingbird/tests/unit/db/test_resource_sync_db_api.py b/kingbird/tests/unit/db/test_resource_sync_db_api.py index af8ec1f..b739a7b 100644 --- a/kingbird/tests/unit/db/test_resource_sync_db_api.py +++ b/kingbird/tests/unit/db/test_resource_sync_db_api.py @@ -112,7 +112,8 @@ class DBAPIResourceSyncTest(base.KingbirdTestCase): job = self.sync_job_create(self.ctx, job_id=UUID1) resource_sync_create = self.resource_sync_create( self.ctx, job=job, region='Fake_region', - resource='fake_key', resource_type='keypair') + source_region='Fake_region2', resource='fake_key', + resource_type='keypair') self.assertIsNotNone(resource_sync_create) self.assertEqual(consts.JOB_PROGRESS, resource_sync_create.sync_status) @@ -120,7 +121,8 @@ class DBAPIResourceSyncTest(base.KingbirdTestCase): job = self.sync_job_create(self.ctx, job_id=UUID1) resource_sync_create = self.resource_sync_create( self.ctx, job=job, region='Fake_region', - resource='fake_key', resource_type='keypair') + source_region='Fake_region2', resource='fake_key', + resource_type='keypair') self.assertIsNotNone(resource_sync_create) status = db_api.resource_sync_status(self.ctx, job.id) self.assertEqual(consts.JOB_PROGRESS, status[0]) @@ -129,7 +131,8 @@ class DBAPIResourceSyncTest(base.KingbirdTestCase): job = self.sync_job_create(self.ctx, job_id=UUID1) resource_sync_create = self.resource_sync_create( self.ctx, job=job, region='Fake_region', - resource='fake_key', resource_type='keypair') + source_region='Fake_region2', resource='fake_key', + resource_type='keypair') self.assertIsNotNone(resource_sync_create) self.assertEqual(consts.JOB_PROGRESS, resource_sync_create.sync_status) db_api.resource_sync_update( @@ -141,7 +144,8 @@ class DBAPIResourceSyncTest(base.KingbirdTestCase): job = self.sync_job_create(self.ctx, job_id=UUID1) self.assertIsNotNone(job) resource_sync_create = self.resource_sync_create( - self.ctx, job=job, region='Fake_region', resource='fake_key', + self.ctx, job=job, region='Fake_region', + source_region='Fake_region2', resource='fake_key', resource_type='keypair') self.assertIsNotNone(resource_sync_create) self.assertEqual(job.id, resource_sync_create.job_id) @@ -151,7 +155,8 @@ class DBAPIResourceSyncTest(base.KingbirdTestCase): job = self.sync_job_create(self.ctx, job_id=UUID1) self.assertIsNotNone(job) self.resource_sync_create( - self.ctx, job=job, region='Fake_region', resource='fake_key', + self.ctx, job=job, region='Fake_region', + source_region='Fake_region2', resource='fake_key', resource_type='keypair') db_api.sync_job_delete(self.ctx, job_id) updated_job = db_api.sync_job_list(self.ctx) @@ -160,9 +165,10 @@ class DBAPIResourceSyncTest(base.KingbirdTestCase): def test_composite_primary_key(self): job = self.sync_job_create(self.ctx, job_id=UUID1) self.resource_sync_create( - self.ctx, job=job, region='Fake_region', resource='fake_key', + self.ctx, job=job, region='Fake_region', + source_region='Fake_region2', resource='fake_key', resource_type='keypair') self.assertRaises(oslo_db.exception.DBDuplicateEntry, self.resource_sync_create, self.ctx, job=job, - region='Fake_region', resource='fake_key', - resource_type='keypair') + region='Fake_region', source_region='Fake_region2', + resource='fake_key', resource_type='keypair')