Skip to content

slapconfiguration: unwrap shared instances when serialisation is json-in-xml

Summary

Teach slapconfiguration.jsonschema to transparently unwrap every entry of slave-instance-list when the SR serialisation is json-in-xml, mirroring the existing main-parameter unwrap at line 687.

So far it is only done when the slave instances "validated", in rapid-cdn latest software release they are not, which create a gap.

Why

In JsonSchema._expandParameterDict:

  • Line 686-687 unwraps the main parameter_dict when serialisation is json-in-xml.
  • Line 647-651 (_validateShared) unwraps each slave entry, but only inside the if validate.shared: branch (line 706).

Rapid-CDN's slap-configuration recipe sets validate-parameters = main (instance.cfg.in:82), so the slave unwrap path is skipped. The slave list reaches the consuming Jinja2 templates as {'_': '...json...', 'slave_reference': '...'} instead of decoded dicts, and every slave.get('url') returns None — silent mis-configuration.

This is SR-67143: rapid-cdn rejected a slave submitted with json-in-xml serialisation. Łukas worked around it on rapid-cdn master with 5b05605833 (per-slave-type serialisation: xml override). This MR is the proper fix.

What changes

  • slapos/recipe/slapconfiguration.py: in JsonSchema._expandParameterDict, after the main-param unwrap(), also unwrap each entry of options['slave-instance-list']. slave_reference is system-injected outside the json-in-xml payload, so preserve it across the unwrap.
  • Backward-compatible: _validateShared's subsequent unwrap() (line 651) becomes a no-op on already-decoded dicts (librecipe/init.py:53-56 catches KeyError/TypeError and returns the value unchanged).

Test plan

  • Updated test_jsonschema_shared_valid_and_invalid_skip_shared — the assertion was locking in the pre-fix wrapped form; now expects the unwrapped form, uniform across the 3 subclass variants (serialise=True/False × xml/json-in-xml).
  • Added test_jsonschema_shared_unwrapped_when_skip_shared_validation in JsonSchemaTestMisc — explicit regression test for this code path.
  • Add a test for mix slave list.
  • CI green on cookbook unit-test suite.

Follow-up

After this MR is merged and a new slapos.cookbook egg is released, the rapid-cdn follow-up !2095 will:

  • Revert Łukas's per-slave-type serialisation: xml override.
  • Bump the slapos.cookbook pin in stack/slapos.cfg:407.
  • Add an end-to-end test (TestSlaveJsonInXmlSerialisation) for json-in-xml-encoded slave parameters.

🤖 Generated with Claude Code

Edited by Cédric Le Ninivin

Merge request reports