Exemplo n.º 1
0
    def _fake_odcs_new_compose(self,
                               compose_source,
                               tag,
                               packages=None,
                               results=None,
                               builds=None,
                               arches=None):
        """
        Fake odcs.new_compose(...) method used in the dry run mode.

        Logs the arguments and emits fake ODCSComposeStateChangeEvent

        :rtype: dict
        :return: Fake odcs.new_compose dict.
        """
        self.handler.log_info(
            "DRY RUN: Calling fake odcs.new_compose with args: %r",
            (compose_source, tag, packages, results, arches))

        # In case we run in DRY_RUN mode, we need to initialize
        # FAKE_COMPOSE_ID to the id of last ODCS compose to give the IDs
        # increasing and unique even between Freshmaker restarts.
        fake_compose_id = Compose.get_lowest_compose_id(db.session) - 1
        if fake_compose_id >= 0:
            fake_compose_id = -1

        new_compose = {
            'id': fake_compose_id,
            'result_repofile':
            "http://localhost/{}.repo".format(fake_compose_id),
            'state': COMPOSE_STATES['done'],
            'results': results or ['boot.iso']
        }
        if builds:
            new_compose['builds'] = builds
        if arches:
            new_compose['arches'] = arches

        # Generate and inject the ODCSComposeStateChangeEvent event.
        event = ODCSComposeStateChangeEvent("fake_compose_msg", new_compose)
        event.dry_run = True
        self.handler.log_info("Injecting fake event: %r", event)
        work_queue_put(event)

        return new_compose
Exemplo n.º 2
0
 def test_get_lowest_compose_id(self):
     compose_id = Compose.get_lowest_compose_id(db.session)
     self.assertEqual(compose_id, -1)