#1566 Stop trying to validate non-existent metadata
Merged 2 years ago by lsedlar. Opened 2 years ago by lsedlar.
lsedlar/pungi no-file-no-validation  into  master

file modified
+3 -3
@@ -53,9 +53,9 @@ 

      Often caused by isos with duplicate metadata.

      Accessing the `images` attribute will raise an exception if there's a problem

      """

- 

-     compose = productmd.compose.Compose(compose.paths.compose.topdir())

-     return compose.images

+     if compose.im.images:

+         compose = productmd.compose.Compose(compose.paths.compose.topdir())

+         return compose.images

  

  

  def check_sanity(compose, variant, arch, image):

@@ -0,0 +1,58 @@ 

+ {

+     "header": {

+         "type": "productmd.images",

+         "version": "1.2"

+     },

+     "payload": {

+         "compose": {

+             "date": "20181001",

+             "id": "Mixed-1.0-20181001.n.0",

+             "respin": 0,

+             "type": "nightly"

+         },

+         "images": {

+             "Server": {

+                 "x86_64": [

+                     {

+                         "arch": "x86_64",

+                         "bootable": false,

+                         "checksums": {

+                             "md5": "c7977d67f6522bce7fb04c0818a3c744",

+                             "sha1": "c7d65673b2eb477016f9e09f321935bace545515",

+                             "sha256": "6d9cfc9be59cba96763dcca5d1b5759127d2f7920055b663dbcf29474bc368de"

+                         },

+                         "disc_count": 1,

+                         "disc_number": 1,

+                         "format": "iso",

+                         "implant_md5": "340b7dc15b9c74b8576b81c3b33fc3f2",

+                         "mtime": 1636012560,

+                         "path": "Server-Gluster/x86_64/iso/Gluster-2.3-DP-1-20211104.t.4-Server-x86_64-dvd1.iso",

+                         "size": 419840,

+                         "subvariant": "Server-Gluster",

+                         "type": "dvd",

+                         "volume_id": "Gluster-2.3 DP-1 Server.x86_64"

+                     },

+                     {

+                         "arch": "x86_64",

+                         "bootable": false,

+                         "checksums": {

+                             "md5": "a7977d67f6522bce7fb04c0818a3c744",

+                             "sha1": "a7d65673b2eb477016f9e09f321935bace545515",

+                             "sha256": "ad9cfc9be59cba96763dcca5d1b5759127d2f7920055b663dbcf29474bc368de"

+                         },

+                         "disc_count": 1,

+                         "disc_number": 1,

+                         "format": "iso",

+                         "implant_md5": "340b7dc15b9c74b8576b81c3b33fc3f2",

+                         "mtime": 1636012560,

+                         "path": "Server-Gluster/x86_64/iso/Gluster-2.3-DP-1-20211104.t.4-Server-x86_64-dvd1.iso",

+                         "size": 419840,

+                         "subvariant": "Server-Gluster",

+                         "type": "dvd",

+                         "volume_id": "Gluster-2.3 DP-1 Server.x86_64"

+                     }

+                 ]

+             }

+         }

+     }

+ }

file modified
+29 -1
@@ -4,7 +4,7 @@ 

  import os

  

  import pungi.phases.test as test_phase

- from tests.helpers import DummyCompose, PungiTestCase, touch

+ from tests.helpers import DummyCompose, PungiTestCase, touch, FIXTURE_DIR

  

  try:

      import dnf  # noqa: F401
@@ -305,3 +305,31 @@ 

          test_phase.check_image_sanity(compose)

  

          self.assertEqual(compose.log_warning.call_args_list, [])

+ 

+ 

+ class TestImageMetadataValidation(PungiTestCase):

+     def test_valid_metadata(self):

+         compose = mock.Mock()

+         compose.im.images = {"Server": mock.Mock()}

+         compose.paths.compose.topdir = lambda: os.path.join(

+             FIXTURE_DIR, "basic-metadata"

+         )

+ 

+         test_phase.check_image_metadata(compose)

+ 

+     def test_missing_metadata(self):

+         compose = mock.Mock()

+         compose.im.images = {}

+         compose.paths.compose.topdir = lambda: self.topdir

+ 

+         test_phase.check_image_metadata(compose)

+ 

+     def test_invalid_metadata(self):

+         compose = mock.Mock()

+         compose.im.images = {"Server": mock.Mock()}

+         compose.paths.compose.topdir = lambda: os.path.join(

+             FIXTURE_DIR, "invalid-image-metadata"

+         )

+ 

+         with self.assertRaises(RuntimeError):

+             test_phase.check_image_metadata(compose)

When a compose doesn't build any images, it won't produce any metadata file for them, and thus it makes no sense to validate it.

Fixes: https://pagure.io/pungi/issue/1565

rebased onto 9d02f87

2 years ago

Looks good to me. :thumbsup:

Testing this in my dev environment now.

This works in my testing. :thumbsup:

Pull-Request has been merged by lsedlar

2 years ago