#363 Add Event.requested_rebuilds to store the artifacts requested to rebuild for manual rebuild.
Merged 2 months ago by jkaluza. Opened 2 months ago by jkaluza.
jkaluza/freshmaker factory-3861  into  master

@@ -0,0 +1,22 @@ 

+ """Add requested_rebuilds column to events table.

+ 

+ Revision ID: 5a555923da42

+ Revises: 8eeddff9a4f3

+ Create Date: 2019-02-07 08:22:29.216868

+ 

+ """

+ 

+ # revision identifiers, used by Alembic.

+ revision = '5a555923da42'

+ down_revision = '8eeddff9a4f3'

+ 

+ from alembic import op

+ import sqlalchemy as sa

+ 

+ 

+ def upgrade():

+     op.add_column('events', sa.Column('requested_rebuilds', sa.String(), nullable=True))

+ 

+ 

+ def downgrade():

+     op.drop_column('events', 'requested_rebuilds')

file modified
+6

@@ -151,6 +151,10 @@ 

      dry_run = db.Column(db.Boolean, default=False)

      # For manual rebuilds, set to user requesting the rebuild. Otherwise null.

      requester = db.Column(db.String, nullable=True)

+     # For manual rebuilds, contains the white-space separate list of artifacts

+     # (for example NVR of container images) to rebuild if passed using the

+     # REST API.

+     requested_rebuilds = db.Column(db.String, nullable=True)

  

      manual_triggered = db.Column(

          db.Boolean,

@@ -355,6 +359,8 @@ 

              "url": event_url,

              "dry_run": self.dry_run,

              "requester": self.requester,

+             "requested_rebuilds": (self.requested_rebuilds.split(" ")

+                                    if self.requested_rebuilds else []),

          }

  

      def find_dependent_events(self):

file modified
+1

@@ -268,6 +268,7 @@ 

          # to check for the event status.

          db_event = models.Event.get_or_create_from_event(db.session, event)

          db_event.requester = g.user.username

+         db_event.requested_rebuilds = " ".join(event.container_images)

          db.session.commit()

  

          # Forward the POST data (including the msg_id of the database event we

file modified
+1

@@ -175,6 +175,7 @@ 

              'state_name': 'INITIALIZED',

              'state_reason': None,

              'url': 'http://localhost:5001/api/1/events/1',

+             'requested_rebuilds': [],

          })

  

  

file modified
+24 -1

@@ -487,7 +487,8 @@ 

              u'state_reason': None,

              u'url': u'/api/1/events/1',

              u'dry_run': False,

-             u'requester': 'tester1'})

+             u'requester': 'tester1',

+             u'requested_rebuilds': []})

          publish.assert_called_once_with(

              'manual.rebuild',

              {'msg_id': 'manual_rebuild_123', u'errata_id': 1})

@@ -512,6 +513,28 @@ 

              'manual.rebuild',

              {'msg_id': 'manual_rebuild_123', u'errata_id': 1, 'dry_run': True})

  

+     @patch('freshmaker.messaging.publish')

+     @patch('freshmaker.parsers.internal.manual_rebuild.ErrataAdvisory.'

+            'from_advisory_id')

+     @patch('freshmaker.parsers.internal.manual_rebuild.time.time')

+     def test_manual_rebuild_container_images(self, time, from_advisory_id, publish):

+         time.return_value = 123

+         from_advisory_id.return_value = ErrataAdvisory(

+             123, 'name', 'REL_PREP', ['rpm'])

+ 

+         resp = self.client.post(

+             '/api/1/builds/', data=json.dumps({

+                 'errata_id': 1, 'container_images': ["foo-1-1", "bar-1-1"]}),

+             content_type='application/json')

+         data = json.loads(resp.get_data(as_text=True))

+ 

+         # Other fields are predictible.

+         self.assertEqual(data['requested_rebuilds'], ["foo-1-1", "bar-1-1"])

+         publish.assert_called_once_with(

+             'manual.rebuild',

+             {'msg_id': 'manual_rebuild_123', u'errata_id': 1,

+              'container_images': ["foo-1-1", "bar-1-1"]})

+ 

  

  class TestOpenIDCLogin(ViewBaseTest):

      """Test that OpenIDC login"""

Freshmaker user can request manual rebuild of some artifacts (currently
just container images). We did not store the list of artifacts user
requested anywhere which makes it hard to debug possible issues and also
forces requester to remember what were the container images he asked for.

In this commit, new requested_rebuilds column is created to store
that list and it is also provided in REST API.

The name of this column is artifact-type agnostic so we can use the same
field also for other artifact types (like image repository, modules, ...).

Pull-Request has been merged by jkaluza

2 months ago