From 26e7207b6bcf3900f8d23218637871a5903ca715 Mon Sep 17 00:00:00 2001 From: Julien Fortin Date: Mon, 27 Jun 2016 00:24:18 +0100 Subject: [PATCH] nlmanager: nlpacket: throw an error if the user of nlmanager tries to encode an attribute that we haven't added an encode() method for + adding one byte attribute class for protodown operations. Ticket: CM-11581 Reviewed By: CCR-4721 Testing Done: Smoke + custom interface file with clag bond that requires protodown. - nlmanager will now throw an exception if a user is trying to use the default attribute class when in fact he should use a more specific attribute class. - The protodown implementation needed to use a one byte attribute to set the protodown state Signed-off-by: Julien Fortin --- nlmanager/nlpacket.py | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/nlmanager/nlpacket.py b/nlmanager/nlpacket.py index 8b1a951..83e8c12 100644 --- a/nlmanager/nlpacket.py +++ b/nlmanager/nlpacket.py @@ -205,6 +205,10 @@ class Attribute(object): return raw def encode(self): + + if not self.LEN: + raise Exception('Please define an encode() method in your child attribute class, or do not use AttributeGeneric') + length = self.HEADER_LEN + self.LEN attr_type_with_flags = self.atype @@ -447,6 +451,14 @@ class AttributeGeneric(Attribute): raise +class AttributeOneByteValue(AttributeGeneric): + + def __init__(self, atype, string, logger): + Attribute.__init__(self, atype, string, logger) + self.PACK = '=B' + self.LEN = calcsize(self.PACK) + + class AttributeIFLA_AF_SPEC(Attribute): """ value will be a dictionary such as: @@ -1638,7 +1650,7 @@ class Link(NetlinkPacket): IFLA_PHYS_SWITCH_ID : ('IFLA_PHYS_SWITCH_ID', AttributeGeneric), IFLA_LINK_NETNSID : ('IFLA_LINK_NETNSID', AttributeGeneric), IFLA_PHYS_PORT_NAME : ('IFLA_PHYS_PORT_NAME', AttributeGeneric), - IFLA_PROTO_DOWN : ('IFLA_PROTO_DOWN', AttributeGeneric), + IFLA_PROTO_DOWN : ('IFLA_PROTO_DOWN', AttributeOneByteValue), IFLA_LINKPROTODOWN : ('IFLA_LINKPROTODOWN', AttributeGeneric) }