#1210 Allow passing `--platform-id` (`-p`) to build_module_locally.
Merged 5 months ago by mprahl. Opened 5 months ago by jkaluza.
jkaluza/fm-orchestrator offline-builds-3  into  master

@@ -110,9 +110,11 @@ 

  @manager.option('-s', '--set-stream', action='append', default=[], dest='default_streams')

  @manager.option('-r', '--platform-repo-file', action='append', default=[],

                  dest='platform_repofiles')

+ @manager.option('-p', '--platform-id', action='store', default=None,

+                 dest='platform_id')

  def build_module_locally(local_build_nsvs=None, yaml_file=None, srpms=None,

                           stream=None, skiptests=False, default_streams=None,

-                          offline=False, platform_repofiles=None):

+                          offline=False, platform_repofiles=None, platform_id=None):

      """ Performs local module build using Mock

      """

      if 'SERVER_NAME' not in app.config or not app.config['SERVER_NAME']:

@@ -139,7 +141,7 @@ 

  

          db.create_all()

          if offline:

-             import_builds_from_local_dnf_repos()

+             import_builds_from_local_dnf_repos(platform_id)

          load_local_builds(local_build_nsvs)

  

          params = {}

@@ -485,12 +485,15 @@ 

      return dnf_base.conf.releasever

  

  

- def import_builds_from_local_dnf_repos():

+ def import_builds_from_local_dnf_repos(platform_id=None):

      """

      Imports the module builds from all available local repositories to MBS DB.

  

      This is used when building modules locally without any access to MBS infra.

      This method also generates and imports the base module according to /etc/os-release.

+ 

+     :param str platform_id: The `name:stream` of a fake platform module to generate in this

+         method. When not set, the /etc/os-release is parsed to get the PLATFORM_ID.

      """

      # Import DNF here to not force it as a hard MBS dependency.

      import dnf

@@ -517,13 +520,13 @@ 

  

                  import_mmd(session, mmd)

  

-     # Parse the /etc/os-release to find out the local platform:stream.

-     platform_id = None

-     with open("/etc/os-release", "r") as fd:

-         for l in fd.readlines():

-             if not l.startswith("PLATFORM_ID"):

-                 continue

-             platform_id = l.split("=")[1].strip("\"' \n")

+     if not platform_id:

+         # Parse the /etc/os-release to find out the local platform:stream.

+         with open("/etc/os-release", "r") as fd:

+             for l in fd.readlines():

+                 if not l.startswith("PLATFORM_ID"):

+                     continue

+                 platform_id = l.split("=")[1].strip("\"' \n")

      if not platform_id:

          raise ValueError("Cannot get PLATFORM_ID from /etc/os-release.")

  

@@ -1342,3 +1342,11 @@ 

              module_build = models.ModuleBuild.get_build_from_nsvc(

                  db.session, "platform", "x", 1, "000000")

              assert module_build

+ 

+     def test_import_builds_from_local_dnf_repos_platform_id(self):

+         with patch("dnf.Base"):

+             module_build_service.utils.import_builds_from_local_dnf_repos(platform_id="platform:y")

+ 

+             module_build = models.ModuleBuild.get_build_from_nsvc(

+                 db.session, "platform", "y", 1, "000000")

+             assert module_build

Currently, the PLATFORM_ID is parsed from the /etc/os-release. This
is good default value, but sometimes you want to build module locally
against the different platform stream.

For example building on platform:f29 against the platform:f30 modules. In
that case, we need to be able to override the host PLATFORM_ID and
set it manually chosen value.

:thumbsup:
Can you check on the tests? Maybe rebasing it will resolve the issue.

rebased onto 40ed1cb

5 months ago

pretty please pagure-ci rebuild

5 months ago

pretty please pagure-ci rebuild

5 months ago

@jkaluza do the tests pass locally?

Commit 4858e64 fixes this pull-request

Pull-Request has been merged by mprahl

5 months ago

Pull-Request has been merged by mprahl

5 months ago