#223 When renewing old compose, do not reuse newer compose, but always renegerate the compose instead.
Merged 11 months ago by jkaluza. Opened 11 months ago by jkaluza.
jkaluza/odcs renew-reuse  into  master

@@ -381,6 +381,17 @@ 

                        old_compose)

              continue

  

+         # In case of compose renewal, the compose.koji_event will be actually

+         # lower than the "old_compose"'s one - the `compose` might have been for

+         # example submitted 1 year ago, so koji_event will be one year old.

+         # But the `old_compose` was submitted few days ago at max.

+         # In this case, we must never reuse the newer compose for old one.

+         if compose.koji_event < old_compose.koji_event:

+             log.debug("%r: Cannot reuse %r - koji_event of current compose "

+                       "is lower than koji_event of old compose.", compose,

+                       old_compose)

+             continue

+ 

          if compose.source_type == PungiSourceType.KOJI_TAG:

              # For KOJI_TAG compose, check that all the inherited tags by our

              # Koji tag have not changed since previous old_compose.

@@ -223,6 +223,84 @@ 

          reused_c = get_reusable_compose(c)

          self.assertEqual(reused_c, old_c)

  

+     @patch("odcs.server.backend.koji_get_inherited_tags")

+     @patch("odcs.server.backend.create_koji_session")

+     def test_get_reusable_tag_compose(

+             self, create_koji_session, koji_get_inherited_tags):

+         koji_get_inherited_tags.return_value = ["foo", "bar"]

+         koji_session = MagicMock()

+         create_koji_session.return_value = koji_session

+         koji_session.tagChangedSinceEvent.return_value = False

+ 

+         old_c = Compose.create(

+             db.session, "me", PungiSourceType.KOJI_TAG, "foo",

+             COMPOSE_RESULTS["repository"], 3600, packages="ed")

+         old_c.koji_event = 1

+         old_c.state = COMPOSE_STATES["done"]

+         c = Compose.create(

+             db.session, "me", PungiSourceType.KOJI_TAG, "foo",

+             COMPOSE_RESULTS["repository"], 3600, packages="ed")

+         c.koji_event = 2

+         db.session.add(old_c)

+         db.session.add(c)

+         db.session.commit()

+ 

+         reused_c = get_reusable_compose(c)

+         self.assertEqual(reused_c, old_c)

+ 

+     @patch("odcs.server.backend.koji_get_inherited_tags")

+     @patch("odcs.server.backend.create_koji_session")

+     def test_get_reusable_tag_compose_tag_changed(

+             self, create_koji_session, koji_get_inherited_tags):

+         koji_get_inherited_tags.return_value = ["foo", "bar"]

+         koji_session = MagicMock()

+         create_koji_session.return_value = koji_session

+         koji_session.tagChangedSinceEvent.return_value = True

+ 

+         old_c = Compose.create(

+             db.session, "me", PungiSourceType.KOJI_TAG, "foo",

+             COMPOSE_RESULTS["repository"], 3600, packages="ed")

+         old_c.koji_event = 1

+         old_c.state = COMPOSE_STATES["done"]

+         c = Compose.create(

+             db.session, "me", PungiSourceType.KOJI_TAG, "foo",

+             COMPOSE_RESULTS["repository"], 3600, packages="ed")

+         c.koji_event = 2

+         db.session.add(old_c)

+         db.session.add(c)

+         db.session.commit()

+ 

+         reused_c = get_reusable_compose(c)

+         self.assertEqual(reused_c, None)

+ 

+     @patch("odcs.server.backend.koji_get_inherited_tags")

+     @patch("odcs.server.backend.create_koji_session")

+     def test_get_reusable_tag_compose_renew(

+             self, create_koji_session, koji_get_inherited_tags):

+         koji_get_inherited_tags.return_value = ["foo", "bar"]

+         koji_session = MagicMock()

+         create_koji_session.return_value = koji_session

+         koji_session.tagChangedSinceEvent.return_value = False

+ 

+         old_c = Compose.create(

+             db.session, "me", PungiSourceType.KOJI_TAG, "foo",

+             COMPOSE_RESULTS["repository"], 3600, packages="ed")

+         old_c.koji_event = 10

+         old_c.state = COMPOSE_STATES["done"]

+         c = Compose.create(

+             db.session, "me", PungiSourceType.KOJI_TAG, "foo",

+             COMPOSE_RESULTS["repository"], 3600, packages="ed")

+         # c.koji_event is lower than old_c.koji_event, because "c" is actually

+         # older than old_c and we are testing that its renewal does not reuse

+         # the newer "c" compose.

+         c.koji_event = 9

+         db.session.add(old_c)

+         db.session.add(c)

+         db.session.commit()

+ 

+         reused_c = get_reusable_compose(c)

+         self.assertEqual(reused_c, None)

+ 

      def test_get_reusable_compose_attrs_not_the_same(self):

          old_c = Compose.create(

              db.session, "me", PungiSourceType.REPO, os.path.join(thisdir, "repo"),

While debugging one ODCS issue with RCM team, I've tried renewing 14 days old compose and it actually reused the latest compose instead of generating the old compose again with original koji_event.

This was caused by the fact that the code to reuse already generated composes did not check the koji_event of current compose and always presumed that currently submitted compose is newer than the one submitted earlier.

rebased onto 058242e

11 months ago

Pull-Request has been merged by jkaluza

11 months ago