#1080 Do not retreive rpm info if there is an empty rpm list
Merged 8 months ago by jkaluza. Opened 8 months ago by vmaljulin.
vmaljulin/fm-orchestrator FACTORY-3549  into  master

@@ -178,26 +178,27 @@ 

                       for f in os.listdir(self.resultsdir)

                       if f.endswith(".rpm")]

  

-         output = subprocess.check_output(['rpm',

-                                           '--queryformat',

-                                           '%{NAME} %{EPOCHNUM} %{VERSION} %{RELEASE} %{ARCH}\n',

-                                           '-qp'] + rpm_files,

-                                          cwd=self.resultsdir,

-                                          universal_newlines=True)

-         nevras = output.strip().split('\n')

-         if len(nevras) != len(rpm_files):

-             raise RuntimeError("rpm -qp returned an unexpected number of lines")

- 

-         for rpm_file, nevra in zip(rpm_files, nevras):

-             name, epoch, version, release, arch = nevra.split()

- 

-             if m1.last_batch_id() == m1.batch:

-                 # If RPM is filtered-out, do not add it to artifacts list.

-                 if name in m1_mmd.get_rpm_filter().get():

-                     continue

- 

-             pkglist_f.write(rpm_file + '\n')

-             artifacts.add('{}-{}:{}-{}.{}'.format(name, epoch, version, release, arch))

+         if rpm_files:

+             output = subprocess.check_output(['rpm',

+                                               '--queryformat',

+                                               '%{NAME} %{EPOCHNUM} %{VERSION} %{RELEASE} %{ARCH}\n',

+                                               '-qp'] + rpm_files,

+                                              cwd=self.resultsdir,

+                                              universal_newlines=True)

+             nevras = output.strip().split('\n')

+             if len(nevras) != len(rpm_files):

+                 raise RuntimeError("rpm -qp returned an unexpected number of lines")

+ 

+             for rpm_file, nevra in zip(rpm_files, nevras):

+                 name, epoch, version, release, arch = nevra.split()

+ 

+                 if m1.last_batch_id() == m1.batch:

+                     # If RPM is filtered-out, do not add it to artifacts list.

+                     if name in m1_mmd.get_rpm_filter().get():

+                         continue

+ 

+                 pkglist_f.write(rpm_file + '\n')

+                 artifacts.add('{}-{}:{}-{}.{}'.format(name, epoch, version, release, arch))

  

          pkglist_f.close()

          m1_mmd.set_rpm_artifacts(artifacts)

@@ -159,3 +159,19 @@ 

                  pkglist = fd.read().strip()

                  rpm_names = [kobo.rpmlib.parse_nvr(rpm)["name"] for rpm in pkglist.split('\n')]

                  assert "ed" in rpm_names

+ 

+     @mock.patch("module_build_service.conf.system", new="mock")

+     def test_createrepo_empty_rmp_list(self, *args):

+         with make_session(conf) as session:

+             module = self._create_module_with_filters(session, 3, koji.BUILD_STATES['COMPLETE'])

+ 

+             builder = MockModuleBuilder("mcurlej", module, conf, module.koji_tag,

+                                         module.component_builds)

+             builder.resultsdir = self.resultdir

+             rpms = []

+             with mock.patch("os.listdir", return_value=rpms):

+                 builder._createrepo()

+ 

+             with open(os.path.join(self.resultdir, "pkglist"), "r") as fd:

+                 pkglist = fd.read().strip()

+                 assert not pkglist

Also why not to switch to use librpm as well?

LGTM.

@ignatenkobrain Do you mean import rpm?

Hm, can you remove this empty line :D? No big deal, but I think we don't do empty lines after if anywhere in the code.

rebased onto f3c8654

8 months ago

Tests are passing here locally.

Commit 98aa2ea fixes this pull-request

Pull-Request has been merged by jkaluza

8 months ago

Pull-Request has been merged by jkaluza

8 months ago