pyangbind icon indicating copy to clipboard operation
pyangbind copied to clipboard

XML serialisation/deserialisation

Open CC-vga opened this issue 5 years ago • 6 comments

Hello,

Could you help me please to fix an XML serialisation/deserialisation problem?

  • I have a custom yang model, my-topology.yang, which is valid according to pyang.
  • I already obtained the pyangbind objects of that model.
  • I constructed a python object and serialise it into XML (no problem on this step)
  • I want now to deserialise the XML back to a python object, and I get the following exception: 'key value must be valid, {'error-string': 'talker_address must be of a type compatible with yang:mac-address', 'defined-type': 'yang:mac-address', 'generated-type': 'YANGDynClass(base=RestrictedClassType(base_type=six.text_type, restriction_dict={\'pattern\': \'[0-9a-fA-F]{2}(:[0-9a-fA-F]{2}){5}\'}), is_leaf=True, yang_name="talker-address", parent=self, path_helper=self._path_helper, extmethods=self._extmethods, register_paths=True, is_keyval=True, namespace=\'https://domain.com/my-topology\', defining_module=\'my-topology\', yang_type=\'yang:mac-address\', is_config=True)'}' Note: I have also other field of the same type yang:mac-address, and I have no problems serialising/deserialising my_topology when using only that field.

Operating system: Windows 10 Python version: 3.7 pyangbind version: 0.8.1

Validation done under Operating system: CentOS Linux 7 pyang version: 2.1

Thank you in advance Voica

CC-vga avatar Jan 28 '20 09:01 CC-vga

Can you paste a minimal working example that exhibits the problem? (i.e. yang and relevant python code)

unsignedint avatar Feb 16 '20 05:02 unsignedint

The fragment of the yang model is: module CC-topology { yang-version "1";

namespace "https://comcores.com/CC-topology";

prefix "CC-topo";

import ietf-yang-types { prefix yang; }

import ieee802-dot1q-tsn-types { prefix dot1q-tsn-types; }

grouping end-system-grouping { list user-network-configuration-information-list { key "talker-address unique-id"; leaf talker-address { type yang:mac-address; } ... } }

container network { list end-systems { key "host-name"; leaf host-name { type string; } leaf address { type yang:mac-address; } uses end-system-grouping; } ... } }

The problematic XML fragment is: <CC-topology xmlns="https://comcores.com/CC-topology"> ES1

00:95:f8:ce:a0:01
00:95:f8:ce:a0:01 ... ... ... </CC-topology>

Though the following fragment is decoded just fine: <CC-topology xmlns="https://comcores.com/CC-topology"> ES1

00:95:f8:ce:a0:01
... </CC-topology>

CC-vga avatar Feb 26 '20 16:02 CC-vga

@CC-vga I think you need to make use of Markdown to encapsulate your YANG, and especially your XML, in a pre-formatted code block so it renders correctly. The XML in particular has lost all its elements.

chrisy avatar Feb 26 '20 21:02 chrisy

Hope that now is readable!

The fragment of the yang model is: module CC-topology { yang-version "1";

namespace "https://comcores.com/CC-topology";

prefix "CC-topo";

import ietf-yang-types {
    prefix yang;
}

import ieee802-dot1q-tsn-types {
    prefix dot1q-tsn-types;
}

grouping end-system-grouping {
    list user-network-configuration-information-list {
        key "talker-address unique-id";
        leaf talker-address {
            type yang:mac-address;
        }
        ...
    }
}

container network {
    list end-systems {
        key "host-name";
        leaf host-name {
            type string;
        }
        leaf address {
            type yang:mac-address;
        }
        uses end-system-grouping;
    }
    ...
}

}

The problematic XML fragment is: <CC-topology xmlns="https://comcores.com/CC-topology"> <network> <end-systems> <host-name>ES1</host-name> <address>00:95:f8:ce:a0:01</address> <user-network-configuration-information-list> <talker-address>00:95:f8:ce:a0:01</talker-address> ... </user-network-configuration-information-list> ... </end-systems> ... </network> </CC-topology>

Though the following fragment is decoded just fine: <CC-topology xmlns="https://comcores.com/CC-topology"> <network> <end-systems> <host-name>ES1</host-name> <address>00:95:f8:ce:a0:01</address> </end-systems> ... </network> </CC-topology>

CC-vga avatar Feb 27 '20 13:02 CC-vga

@CC-vga Hi, Any progress with above issue..? Thanks.

eduardpo avatar Feb 08 '22 15:02 eduardpo

Hello, Unfortunately I didn't hear anything new! All best Voica

CC-vga avatar Feb 09 '22 15:02 CC-vga

Hi,

Could you please try again with recent versions of pyangbind?

Thanks.

JoseIgnacioTamayo avatar Oct 13 '23 07:10 JoseIgnacioTamayo

Closing issue without recent updates.

JoseIgnacioTamayo avatar Feb 22 '24 07:02 JoseIgnacioTamayo