From 8edd1a296ce34dadfe2627be45bd653a3ae0cbb7 Mon Sep 17 00:00:00 2001 From: IluaAir Date: Thu, 11 Jun 2026 16:16:14 +0300 Subject: [PATCH] Add H3C device support with configuration and expected output files - Introduced support for H3C devices by adding a new configuration file `config.conf` containing interface and VLAN settings. - Created an expected output JSON file `config.expected.json` to validate the parsing of H3C configurations. - Updated the test model cases to include H3C for comprehensive testing of device parsing functionality. --- oxi/interfaces/models/h3c.py | 9 +- oxi/interfaces/models/templates/eltex.ttp | 6 +- oxi/interfaces/models/templates/h3c.ttp | 1 + oxi/interfaces/models/templates/huawei.ttp | 2 +- tests/fixtures/h3c/config.conf | 169 +++++++++++++++++++++ tests/fixtures/h3c/config.expected.json | 155 +++++++++++++++++++ tests/test_models.py | 1 + 7 files changed, 331 insertions(+), 12 deletions(-) create mode 100644 tests/fixtures/h3c/config.conf create mode 100644 tests/fixtures/h3c/config.expected.json diff --git a/oxi/interfaces/models/h3c.py b/oxi/interfaces/models/h3c.py index db2444f..3ad40da 100644 --- a/oxi/interfaces/models/h3c.py +++ b/oxi/interfaces/models/h3c.py @@ -14,11 +14,4 @@ class H3C(BaseDevice): vlans.append(item) continue vlans.extend({"vlan_id": vlan_id} for vlan_id in vlan_ids) - return vlans - - -if __name__ == "__main__": - with open("./test5.txt") as file: - data = file.read() - h3c = H3C(data) - print(h3c.parse()) \ No newline at end of file + return vlans \ No newline at end of file diff --git a/oxi/interfaces/models/templates/eltex.ttp b/oxi/interfaces/models/templates/eltex.ttp index b47e14b..57240b6 100644 --- a/oxi/interfaces/models/templates/eltex.ttp +++ b/oxi/interfaces/models/templates/eltex.ttp @@ -26,13 +26,13 @@ Active-image: {{ ignore }} {{ _start_ }} interface {{ interface | ORPHRASE }} ip address {{ ip_address }} {{ mask | to_cidr }} - name {{ description }} - description {{ description }} + name {{ description | ORPHRASE}} + description {{ description | ORPHRASE }} interface vlan {{ vlan_id | _start_ }} - name {{ name }} + name {{ name | ORPHRASE }} vlan {{ _db_ | _start_ }} vlan {{ vlan_ids | joinmatches(',') | unrange("-", ",") | split(",")}} diff --git a/oxi/interfaces/models/templates/h3c.ttp b/oxi/interfaces/models/templates/h3c.ttp index afbe090..dcf1e2c 100644 --- a/oxi/interfaces/models/templates/h3c.ttp +++ b/oxi/interfaces/models/templates/h3c.ttp @@ -21,6 +21,7 @@ default_system = { interface {{ interface }} + description {{ description | ORPHRASE }} ip address {{ ip_address }} {{ mask | to_cidr }} diff --git a/oxi/interfaces/models/templates/huawei.ttp b/oxi/interfaces/models/templates/huawei.ttp index e832977..4464e2c 100644 --- a/oxi/interfaces/models/templates/huawei.ttp +++ b/oxi/interfaces/models/templates/huawei.ttp @@ -20,7 +20,7 @@ default_system = { interface {{ interface }} - description {{ description }} + description {{ description | ORPHRASE }} ip address {{ ip_address }} {{ mask | to_cidr }} diff --git a/tests/fixtures/h3c/config.conf b/tests/fixtures/h3c/config.conf new file mode 100644 index 0000000..81eca56 --- /dev/null +++ b/tests/fixtures/h3c/config.conf @@ -0,0 +1,169 @@ +# H3C Comware Software, Version 7.1.070, Release 6616P01 +# Copyright (c) 2004-2021 New H3C Technologies Co., Ltd. All rights reserved. +# Last reboot reason : User reboot +# +# Boot image: flash:/s9820-cmw710-boot-r6616p01.bin +# Boot image version: 7.1.070, Release 6616P01 +# Compiled May 06 2021 11:00:00 +# System image: flash:/s9820-cmw710-system-r6616p01.bin +# System image version: 7.1.070, Release 6616P01 +# Compiled May 06 2021 11:00:00 +# +# +# MPU(M) Slot 1: +# H3C S9820-64H MPU(M) with 1 C2538 Processor(s) +# BOARD TYPE: S9820-64H +# DRAM: 8192M bytes +# FLASH: 3630M bytes +# NVRAM: 0K bytes +# PCB 1 Version: VER.A +# PCB 2 Version: VER.B +# PCB 3 Version: VER.A +# PCB 4 Version: VER.A +# Basic BootWare Version: 105 +# Extended BootWare Version: 108 +# CPLD 1 Version: 002 +# CPLD 2 Version: 027 +# CPLD 3 Version: 002 +# CPLD 4 Version: 002 +# FPGA 1 Version: 001 +# Release Version: H3C S9820-64H-6616P01 +# Patch Version: None +# Reboot Cause: UserReboot +# [SubSlot 0] 64QSFP28 +# +# MPU(S) Slot 2: +# H3C S9820-64H MPU(S) with 1 C2538 Processor(s) +# BOARD TYPE: S9820-64H +# DRAM: 8192M bytes +# FLASH: 3630M bytes +# NVRAM: 0K bytes +# PCB 1 Version: VER.A +# PCB 2 Version: VER.B +# PCB 3 Version: VER.A +# PCB 4 Version: VER.A +# Basic BootWare Version: 105 +# Extended BootWare Version: 108 +# CPLD 1 Version: 002 +# CPLD 2 Version: 027 +# CPLD 3 Version: 002 +# CPLD 4 Version: 002 +# FPGA 1 Version: 001 +# Release Version: H3C S9820-64H-6616P01 +# Patch Version: None +# Reboot Cause: IRFMergeReboot +# [SubSlot 0] 64QSFP28 +# Slot Type State Subslot Soft Ver Patch Ver +# 1 S9820-64H Master 0 S9820-64H-6616P01 None +# 2 S9820-64H Standby 0 S9820-64H-6616P01 None +# +vlan 1 +# +vlan 12 + name BGP to OSPF1 +# +vlan 13 + name BGP to OSPF2 +# +vlan 15 + name HW_TEST_1 + description HW_TEST_1 +# +vlan 222 + name MGMT + description MGMT +# +vlan 222 +# +vlan 1112 to 1116 +# +vlan 1122 + name DATA +# +vlan 1123 +# +vlan 1200 +# +vlan 1512 +# +vlan 1513 + description cluster HW_TEST_1 +# +vlan 2000 + description cluster HW_TEST_2 +# +vlan 3377 + name VRF3377 +# +irf-port 1/2 + port group interface HundredGigE1/0/63 + port group interface HundredGigE1/0/64 +# +irf-port 2/1 + port group interface HundredGigE2/0/63 + port group interface HundredGigE2/0/64 +# +interface Bridge-Aggregation1 + description HW_TEST_1 + port link-type trunk + undo port trunk permit vlan 1 + port trunk permit vlan 221 1112 to 1116 1512 2000 + link-aggregation mode dynamic +# +interface Bridge-Aggregation2 + description HW_TEST_2 + port link-type trunk + undo port trunk permit vlan 1 + port trunk permit vlan 221 1112 to 1116 1512 + link-aggregation mode dynamic +# +interface Bridge-Aggregation3 + description HW_TEST_3 + port link-type trunk + undo port trunk permit vlan 1 + port trunk permit vlan 221 1112 to 1116 1512 2000 + link-aggregation mode dynamic +# +interface Bridge-Aggregation4 + description HW_TEST_4 + port link-type trunk + undo port trunk permit vlan 1 + port trunk permit vlan 221 1112 to 1116 1512 + link-aggregation mode dynamic + # +interface NULL0 +# +interface Vlan-interface1 + dhcp client identifier ascii 0098a92d5735b0-VLAN0001 +# +interface Vlan-interface12 + description BGP to OSPF1 + mtu 9008 + ip address 15.12.16.246 255.255.255.252 +# +interface Vlan-interface3000 + description L3 to HW_TEST_3 + ip binding vpn-instance HW_TEST_3 + ip address 192.168.19.254 255.255.255.128 +# +interface HundredGigE1/0/3 + port link-mode bridge + description HW_TEST_1 + port link-type trunk + undo port trunk permit vlan 1 + port trunk permit vlan 221 1112 to 1116 1512 + storm-constrain broadcast pps 1100 1000 + storm-constrain multicast pps 1100 1000 + storm-constrain control shutdown + port link-aggregation group 2 +# +interface HundredGigE1/0/63 + description HW_TEST_2 +# +interface M-GigabitEthernet0/0/0 + ip address 192.168.10.101 255.255.255.0 + dhcp client identifier hex 0298a92d5735b0 +# +interface M-GigabitEthernet0/0/1 + dhcp client identifier hex 0298a92d5735b0 +# diff --git a/tests/fixtures/h3c/config.expected.json b/tests/fixtures/h3c/config.expected.json new file mode 100644 index 0000000..f255686 --- /dev/null +++ b/tests/fixtures/h3c/config.expected.json @@ -0,0 +1,155 @@ +{ + "system": { + "model": "S9820-64H", + "serial_number": "", + "version": "7.1.070" + }, + "interfaces": [ + { + "interface": "Bridge-Aggregation1", + "ip_address": null, + "mask": null, + "description": "HW_TEST_1" + }, + { + "interface": "Bridge-Aggregation2", + "ip_address": null, + "mask": null, + "description": "HW_TEST_2" + }, + { + "interface": "Bridge-Aggregation3", + "ip_address": null, + "mask": null, + "description": "HW_TEST_3" + }, + { + "interface": "Bridge-Aggregation4", + "ip_address": null, + "mask": null, + "description": "HW_TEST_4" + }, + { + "interface": "NULL0", + "ip_address": null, + "mask": null, + "description": null + }, + { + "interface": "Vlan-interface1", + "ip_address": null, + "mask": null, + "description": null + }, + { + "interface": "Vlan-interface12", + "ip_address": "15.12.16.246", + "mask": 30, + "description": "BGP to OSPF1" + }, + { + "interface": "Vlan-interface3000", + "ip_address": "192.168.19.254", + "mask": 25, + "description": "L3 to HW_TEST_3" + }, + { + "interface": "HundredGigE1/0/3", + "ip_address": null, + "mask": null, + "description": "HW_TEST_1" + }, + { + "interface": "HundredGigE1/0/63", + "ip_address": null, + "mask": null, + "description": "HW_TEST_2" + }, + { + "interface": "M-GigabitEthernet0/0/0", + "ip_address": "192.168.10.101", + "mask": 24, + "description": null + }, + { + "interface": "M-GigabitEthernet0/0/1", + "ip_address": null, + "mask": null, + "description": null + } + ], + "vlans": [ + { + "vlan_id": 1, + "description": null + }, + { + "vlan_id": 12, + "description": null + }, + { + "vlan_id": 13, + "description": null + }, + { + "vlan_id": 15, + "description": "HW_TEST_1" + }, + { + "vlan_id": 222, + "description": "MGMT" + }, + { + "vlan_id": 222, + "description": null + }, + { + "vlan_id": 1122, + "description": "DATA" + }, + { + "vlan_id": 1123, + "description": null + }, + { + "vlan_id": 1200, + "description": null + }, + { + "vlan_id": 1512, + "description": null + }, + { + "vlan_id": 1513, + "description": null + }, + { + "vlan_id": 2000, + "description": null + }, + { + "vlan_id": 3377, + "description": "HW_TEST_1" + }, + { + "vlan_id": 1112, + "description": null + }, + { + "vlan_id": 1113, + "description": null + }, + { + "vlan_id": 1114, + "description": null + }, + { + "vlan_id": 1115, + "description": null + }, + { + "vlan_id": 1116, + "description": null + } + ] +} \ No newline at end of file diff --git a/tests/test_models.py b/tests/test_models.py index f9f1f6f..d2222a3 100644 --- a/tests/test_models.py +++ b/tests/test_models.py @@ -12,6 +12,7 @@ MODEL_CASES = [ ("qtech", "config_2.conf", "config_2.expected.json"), ("huawei", "config.conf", "config.expected.json"), ("eltex", "config.conf", "config.expected.json"), + ("h3c", "config.conf", "config.expected.json"), ("quasar", "config_1.conf", "config_1.expected.json"), ("quasar", "config_2.conf", "config_2.expected.json"), ]