diff mbox series

[2/3] selftest/bblayers: Refactor JSON schema validation

Message ID 20251023072513.280477-2-yoann.congal@smile.fr
State Accepted, archived
Commit b10b4d5b6376fd828c1cb843ea2e24da298657b6
Headers show
Series [1/3] meta/files: Add a jsonschema for bitbake-setup configuration files | expand

Commit Message

Yoann Congal Oct. 23, 2025, 7:25 a.m. UTC
From: Yoann Congal <yoann.congal@smile.fr>

* Extract a function "validate_json"
* Allow to specify the schema relative to $COREBASE/meta/files/
* Specify the Base URI to allow schema to reference each other

Signed-off-by: Yoann Congal <yoann.congal@smile.fr>
---
RFC: Maybe I should split this commit?
---
 meta/lib/oeqa/selftest/cases/bblayers.py | 21 +++++++++++++++------
 1 file changed, 15 insertions(+), 6 deletions(-)

Comments

Mathieu Dubois-Briand Oct. 24, 2025, 6:32 a.m. UTC | #1
On Thu Oct 23, 2025 at 9:25 AM CEST, Yoann Congal via lists.openembedded.org wrote:
> From: Yoann Congal <yoann.congal@smile.fr>
>
> * Extract a function "validate_json"
> * Allow to specify the schema relative to $COREBASE/meta/files/
> * Specify the Base URI to allow schema to reference each other
>
> Signed-off-by: Yoann Congal <yoann.congal@smile.fr>
> ---
> RFC: Maybe I should split this commit?
> ---
>  meta/lib/oeqa/selftest/cases/bblayers.py | 21 +++++++++++++++------
>  1 file changed, 15 insertions(+), 6 deletions(-)
>
> diff --git a/meta/lib/oeqa/selftest/cases/bblayers.py b/meta/lib/oeqa/selftest/cases/bblayers.py
> index 982287c9a5..43a158fcf2 100644
> --- a/meta/lib/oeqa/selftest/cases/bblayers.py
> +++ b/meta/lib/oeqa/selftest/cases/bblayers.py
> @@ -136,15 +136,24 @@ class BitbakeLayers(OESelftestTestCase):
>          self.assertTrue(os.path.isfile(recipe_file), msg = "Can't find recipe file for %s" % recipe)
>          return os.path.basename(recipe_file)
>  
> -    def validate_layersjson(self, json):
> -        python = os.path.join(get_bb_var('STAGING_BINDIR', 'python3-jsonschema-native'), 'nativepython3')
> -        jsonvalidator = os.path.join(get_bb_var('STAGING_BINDIR', 'python3-jsonschema-native'), 'jsonschema')
> -        jsonschema = os.path.join(get_bb_var('COREBASE'), 'meta/files/layers.schema.json')
> -        result = runCmd("{} {} -i {} {}".format(python, jsonvalidator, json, jsonschema))
> +    def validate_json(self, json, jsonschema):
> +        staging_bindir = get_bb_var('STAGING_BINDIR', 'python3-jsonschema-native')
> +        python = os.path.join(staging_bindir, 'nativepython3')
> +        jsonvalidator = os.path.join(staging_bindir, 'jsonschema')
> +        schemas_dir = os.path.join(get_bb_var('COREBASE'), "meta/files/")
> +        if not os.path.isabs(jsonschema):
> +            jsonschema = os.path.join(schemas_dir, jsonschema)
> +
> +        result = runCmd(
> +            "{} {} -i {} --base-uri file://{}/ {}".format(
> +                python, jsonvalidator, json, schemas_dir, jsonschema
> +            )
> +        )
>  
>      def test_validate_examplelayersjson(self):
>          json = os.path.join(get_bb_var('COREBASE'), "meta/files/layers.example.json")
> -        self.validate_layersjson(json)
> +        jsonschema = "layers.schema.json"
> +        self.validate_json(json, jsonschema)

Hi Yoann,

Did you forget to replace some uses of validate_layersjson() or did I
miss a commit? I still have 5 calls to it in bblayers.py, after your
patches are applied.

2025-10-23 14:30:16,772 - oe-selftest - INFO - testtools.testresult.real._StringException: Traceback (most recent call last):
  File "/srv/pokybuild/yocto-worker/oe-selftest-fedora/build/layers/openembedded-core/meta/lib/oeqa/selftest/cases/bblayers.py", line 175, in test_bitbakelayers_setup
    self.validate_layersjson(jsonfile)
    ^^^^^^^^^^^^^^^^^^^^^^^^
AttributeError: 'BitbakeLayers' object has no attribute 'validate_layersjson'

https://autobuilder.yoctoproject.org/valkyrie/#/builders/48/builds/2499
https://autobuilder.yoctoproject.org/valkyrie/#/builders/35/builds/2589
https://autobuilder.yoctoproject.org/valkyrie/#/builders/23/builds/2737

I had a quick look at the v2 and I believe we have the same issue.

Thanks,
Mathieu
Yoann Congal Oct. 24, 2025, 6:47 a.m. UTC | #2
Le ven. 24 oct. 2025 à 08:32, Mathieu Dubois-Briand <
mathieu.dubois-briand@bootlin.com> a écrit :

> On Thu Oct 23, 2025 at 9:25 AM CEST, Yoann Congal via
> lists.openembedded.org wrote:
> > From: Yoann Congal <yoann.congal@smile.fr>
> >
> > * Extract a function "validate_json"
> > * Allow to specify the schema relative to $COREBASE/meta/files/
> > * Specify the Base URI to allow schema to reference each other
> >
> > Signed-off-by: Yoann Congal <yoann.congal@smile.fr>
> > ---
> > RFC: Maybe I should split this commit?
> > ---
> >  meta/lib/oeqa/selftest/cases/bblayers.py | 21 +++++++++++++++------
> >  1 file changed, 15 insertions(+), 6 deletions(-)
> >
> > diff --git a/meta/lib/oeqa/selftest/cases/bblayers.py
> b/meta/lib/oeqa/selftest/cases/bblayers.py
> > index 982287c9a5..43a158fcf2 100644
> > --- a/meta/lib/oeqa/selftest/cases/bblayers.py
> > +++ b/meta/lib/oeqa/selftest/cases/bblayers.py
> > @@ -136,15 +136,24 @@ class BitbakeLayers(OESelftestTestCase):
> >          self.assertTrue(os.path.isfile(recipe_file), msg = "Can't find
> recipe file for %s" % recipe)
> >          return os.path.basename(recipe_file)
> >
> > -    def validate_layersjson(self, json):
> > -        python = os.path.join(get_bb_var('STAGING_BINDIR',
> 'python3-jsonschema-native'), 'nativepython3')
> > -        jsonvalidator = os.path.join(get_bb_var('STAGING_BINDIR',
> 'python3-jsonschema-native'), 'jsonschema')
> > -        jsonschema = os.path.join(get_bb_var('COREBASE'),
> 'meta/files/layers.schema.json')
> > -        result = runCmd("{} {} -i {} {}".format(python, jsonvalidator,
> json, jsonschema))
> > +    def validate_json(self, json, jsonschema):
> > +        staging_bindir = get_bb_var('STAGING_BINDIR',
> 'python3-jsonschema-native')
> > +        python = os.path.join(staging_bindir, 'nativepython3')
> > +        jsonvalidator = os.path.join(staging_bindir, 'jsonschema')
> > +        schemas_dir = os.path.join(get_bb_var('COREBASE'),
> "meta/files/")
> > +        if not os.path.isabs(jsonschema):
> > +            jsonschema = os.path.join(schemas_dir, jsonschema)
> > +
> > +        result = runCmd(
> > +            "{} {} -i {} --base-uri file://{}/ {}".format(
> > +                python, jsonvalidator, json, schemas_dir, jsonschema
> > +            )
> > +        )
> >
> >      def test_validate_examplelayersjson(self):
> >          json = os.path.join(get_bb_var('COREBASE'),
> "meta/files/layers.example.json")
> > -        self.validate_layersjson(json)
> > +        jsonschema = "layers.schema.json"
> > +        self.validate_json(json, jsonschema)
>
> Hi Yoann,
>
> Did you forget to replace some uses of validate_layersjson() or did I
> miss a commit? I still have 5 calls to it in bblayers.py, after your
> patches are applied.
>

Yes I did in v1.


> 2025-10-23 14:30:16,772 - oe-selftest - INFO -
> testtools.testresult.real._StringException: Traceback (most recent call
> last):
>   File
> "/srv/pokybuild/yocto-worker/oe-selftest-fedora/build/layers/openembedded-core/meta/lib/oeqa/selftest/cases/bblayers.py",
> line 175, in test_bitbakelayers_setup
>     self.validate_layersjson(jsonfile)
>     ^^^^^^^^^^^^^^^^^^^^^^^^
> AttributeError: 'BitbakeLayers' object has no attribute
> 'validate_layersjson'
>
> https://autobuilder.yoctoproject.org/valkyrie/#/builders/48/builds/2499
> https://autobuilder.yoctoproject.org/valkyrie/#/builders/35/builds/2589
> https://autobuilder.yoctoproject.org/valkyrie/#/builders/23/builds/2737
>
> I had a quick look at the v2 and I believe we have the same issue.
>

I think I fixed that in v2 by keeping validate_layersjson() but changing it
to use the refactored function. Can you test this?

Thanks!

>
> Thanks,
> Mathieu
>
> --
> Mathieu Dubois-Briand, Bootlin
> Embedded Linux and Kernel engineering
> https://bootlin.com
>
>
Mathieu Dubois-Briand Oct. 24, 2025, 7:13 a.m. UTC | #3
On Fri Oct 24, 2025 at 8:47 AM CEST, Yoann Congal via lists.openembedded.org wrote:
> Le ven. 24 oct. 2025 à 08:32, Mathieu Dubois-Briand <
> mathieu.dubois-briand@bootlin.com> a écrit :
>
> Yes I did in v1.
>
>
>> 2025-10-23 14:30:16,772 - oe-selftest - INFO -
>> testtools.testresult.real._StringException: Traceback (most recent call
>> last):
>>   File
>> "/srv/pokybuild/yocto-worker/oe-selftest-fedora/build/layers/openembedded-core/meta/lib/oeqa/selftest/cases/bblayers.py",
>> line 175, in test_bitbakelayers_setup
>>     self.validate_layersjson(jsonfile)
>>     ^^^^^^^^^^^^^^^^^^^^^^^^
>> AttributeError: 'BitbakeLayers' object has no attribute
>> 'validate_layersjson'
>>
>> https://autobuilder.yoctoproject.org/valkyrie/#/builders/48/builds/2499
>> https://autobuilder.yoctoproject.org/valkyrie/#/builders/35/builds/2589
>> https://autobuilder.yoctoproject.org/valkyrie/#/builders/23/builds/2737
>>
>> I had a quick look at the v2 and I believe we have the same issue.
>>
>
> I think I fixed that in v2 by keeping validate_layersjson() but changing it
> to use the refactored function. Can you test this?
>

Sure, I will test it in my next run!
diff mbox series

Patch

diff --git a/meta/lib/oeqa/selftest/cases/bblayers.py b/meta/lib/oeqa/selftest/cases/bblayers.py
index 982287c9a5..43a158fcf2 100644
--- a/meta/lib/oeqa/selftest/cases/bblayers.py
+++ b/meta/lib/oeqa/selftest/cases/bblayers.py
@@ -136,15 +136,24 @@  class BitbakeLayers(OESelftestTestCase):
         self.assertTrue(os.path.isfile(recipe_file), msg = "Can't find recipe file for %s" % recipe)
         return os.path.basename(recipe_file)
 
-    def validate_layersjson(self, json):
-        python = os.path.join(get_bb_var('STAGING_BINDIR', 'python3-jsonschema-native'), 'nativepython3')
-        jsonvalidator = os.path.join(get_bb_var('STAGING_BINDIR', 'python3-jsonschema-native'), 'jsonschema')
-        jsonschema = os.path.join(get_bb_var('COREBASE'), 'meta/files/layers.schema.json')
-        result = runCmd("{} {} -i {} {}".format(python, jsonvalidator, json, jsonschema))
+    def validate_json(self, json, jsonschema):
+        staging_bindir = get_bb_var('STAGING_BINDIR', 'python3-jsonschema-native')
+        python = os.path.join(staging_bindir, 'nativepython3')
+        jsonvalidator = os.path.join(staging_bindir, 'jsonschema')
+        schemas_dir = os.path.join(get_bb_var('COREBASE'), "meta/files/")
+        if not os.path.isabs(jsonschema):
+            jsonschema = os.path.join(schemas_dir, jsonschema)
+
+        result = runCmd(
+            "{} {} -i {} --base-uri file://{}/ {}".format(
+                python, jsonvalidator, json, schemas_dir, jsonschema
+            )
+        )
 
     def test_validate_examplelayersjson(self):
         json = os.path.join(get_bb_var('COREBASE'), "meta/files/layers.example.json")
-        self.validate_layersjson(json)
+        jsonschema = "layers.schema.json"
+        self.validate_json(json, jsonschema)
 
     def test_bitbakelayers_setup(self):
         result = runCmd('bitbake-layers create-layers-setup {}'.format(self.testlayer_path))