From 8b61bf2b074fe4209832bb066b4b376c21f7c064 Mon Sep 17 00:00:00 2001 From: Thomas Mangin Date: Mon, 15 Jul 2024 20:38:20 +0100 Subject: [PATCH] fix software version feature --- .../bgp/message/open/capability/capabilities.py | 2 +- .../bgp/message/open/capability/capability.py | 2 +- .../message/open/capability/software_version.py | 16 ++++++++-------- 3 files changed, 10 insertions(+), 10 deletions(-) diff --git a/src/exabgp/bgp/message/open/capability/capabilities.py b/src/exabgp/bgp/message/open/capability/capabilities.py index 1388332d4..0c087dca0 100644 --- a/src/exabgp/bgp/message/open/capability/capabilities.py +++ b/src/exabgp/bgp/message/open/capability/capabilities.py @@ -147,7 +147,7 @@ def _software_version(self, neighbor): if not neighbor['capability']['software-version']: return - self[Capability.CODE.SOFTRWARE_VERSION] = SoftwareVersion() + self[Capability.CODE.SOFTWARE_VERSION] = SoftwareVersion() def _operational(self, neighbor): if not neighbor['capability']['operational']: diff --git a/src/exabgp/bgp/message/open/capability/capability.py b/src/exabgp/bgp/message/open/capability/capability.py index cb6d8226f..7b08a5c9b 100644 --- a/src/exabgp/bgp/message/open/capability/capability.py +++ b/src/exabgp/bgp/message/open/capability/capability.py @@ -107,7 +107,7 @@ class CODE(int): ROUTE_REFRESH_CISCO = _CapabilityCode(_CapabilityCode.ROUTE_REFRESH_CISCO) MULTISESSION_CISCO = _CapabilityCode(_CapabilityCode.MULTISESSION_CISCO) HOSTNAME = _CapabilityCode(_CapabilityCode.HOSTNAME) - SOFTRWARE_VERSION = _CapabilityCode(_CapabilityCode.SOFTWARE_VERSION) + SOFTWARE_VERSION = _CapabilityCode(_CapabilityCode.SOFTWARE_VERSION) OPERATIONAL = _CapabilityCode(_CapabilityCode.OPERATIONAL) AIGP = _CapabilityCode(_CapabilityCode.AIGP) # fmt: on diff --git a/src/exabgp/bgp/message/open/capability/software_version.py b/src/exabgp/bgp/message/open/capability/software_version.py index b7ce8f575..54b2afd84 100644 --- a/src/exabgp/bgp/message/open/capability/software_version.py +++ b/src/exabgp/bgp/message/open/capability/software_version.py @@ -15,23 +15,23 @@ @Capability.register() class SoftwareVersion(Capability): - ID = Capability.CODE.SOFTRWARE_VERSION + ID = Capability.CODE.SOFTWARE_VERSION SOFTWARE_VERSION_MAX_LEN = 64 def __init__(self): - self.software_version = f"ExaBGP/{version}" + software_version = f"ExaBGP/{version}" + if len(software_version) > self.SOFTWARE_VERSION_MAX_LEN: + software_version = software_version[:self.SOFTWARE_VERSION_MAX_LEN - 3] + '...' + self.software_version = software_version def __str__(self): - return f'SoftwareVersion({self.software_version})' + return 'SoftwareVersion(%s)' % self.software_version def json(self): - return f'{ "software-version": "{self.software_version}" }' + return '{ "software-version": "%s" }' % self.software_version def extract(self): - software_version = self.software_version.encode('utf-8') - if len(software_version) > self.SOFTWARE_VERSION_MAX_LEN: - software_version = software_version[: self.SOFTWARE_VERSION_MAX_LEN] - return [bytes([len(software_version)]) + software_version] + return [bytes([len(self.software_version)]) + self.software_version.encode('utf-8')] @staticmethod def unpack_capability(instance, data, capability=None): # pylint: disable=W0613