Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

snmp: T5855: migrate "set service lldp snmp enable" to "set service lldp snmp" #2687

Merged
merged 2 commits into from
Dec 25, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion data/templates/lldp/lldpd.j2
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
### Autogenerated by lldp.py ###
DAEMON_ARGS="-M 4 {{ '-x' if snmp.enable is vyos_defined }} {{ '-c' if legacy_protocols.cdp is vyos_defined }} {{ '-e' if legacy_protocols.edp is vyos_defined }} {{ '-f' if legacy_protocols.fdp is vyos_defined }} {{ '-s' if legacy_protocols.sonmp is vyos_defined }}"
DAEMON_ARGS="-M 4 {{ '-x' if snmp is vyos_defined }} {{ '-c' if legacy_protocols.cdp is vyos_defined }} {{ '-e' if legacy_protocols.edp is vyos_defined }} {{ '-f' if legacy_protocols.fdp is vyos_defined }} {{ '-s' if legacy_protocols.sonmp is vyos_defined }}"
2 changes: 1 addition & 1 deletion interface-definitions/include/version/lldp-version.xml.i
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
<!-- include start from include/version/lldp-version.xml.i -->
<syntaxVersion component='lldp' version='1'></syntaxVersion>
<syntaxVersion component='lldp' version='2'></syntaxVersion>
<!-- include end -->
15 changes: 4 additions & 11 deletions interface-definitions/lldp.xml.in
Original file line number Diff line number Diff line change
Expand Up @@ -175,19 +175,12 @@
<multi/>
</properties>
</leafNode>
<node name="snmp">
<leafNode name="snmp">
<properties>
<help>SNMP parameters for LLDP</help>
<help>Enable SNMP queries of the LLDP database</help>
<valueless/>
</properties>
<children>
<leafNode name="enable">
<properties>
<help>Enable SNMP queries of the LLDP database</help>
<valueless/>
</properties>
</leafNode>
</children>
</node>
</leafNode>
</children>
</node>
</children>
Expand Down
3 changes: 3 additions & 0 deletions smoketest/configs/ospf-small
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,9 @@ service {
lldp {
interface all {
}
snmp {
enable
}
}
snmp {
community public {
Expand Down
16 changes: 15 additions & 1 deletion smoketest/scripts/cli/test_service_lldp.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/usr/bin/env python3
#
# Copyright (C) 2022 VyOS maintainers and contributors
# Copyright (C) 2022-2023 VyOS maintainers and contributors
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License version 2 or later as
Expand Down Expand Up @@ -122,6 +122,20 @@ def test_05_lldp_location(self):
self.assertIn(f'configure ports {interface} med location elin "{elin}"', config)
self.assertIn(f'configure system interface pattern "{interface}"', config)

def test_06_lldp_snmp(self):
self.cli_set(base_path + ['snmp'])

# verify - can not start lldp snmp without snmp beeing configured
with self.assertRaises(ConfigSessionError):
self.cli_commit()
self.cli_set(['service', 'snmp'])
self.cli_commit()

# SNMP required process to be started with -x option
tmp = read_file('/etc/default/lldpd')
self.assertIn('-x', tmp)

self.cli_delete(['service', 'snmp'])

if __name__ == '__main__':
unittest.main(verbosity=2)
5 changes: 2 additions & 3 deletions src/conf_mode/lldp.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,9 +86,9 @@ def verify(lldp):
raise ConfigError(f'Must define both longitude and latitude for "{interface}" location!')

# check options
if 'snmp' in lldp and 'enable' in lldp['snmp']:
if 'snmp' in lldp:
if 'system_snmp_enabled' not in lldp:
raise ConfigError('SNMP must be configured to enable LLDP SNMP')
raise ConfigError('SNMP must be configured to enable LLDP SNMP!')


def generate(lldp):
Expand Down Expand Up @@ -121,4 +121,3 @@ def apply(lldp):
except ConfigError as e:
print(e)
exit(1)

2 changes: 1 addition & 1 deletion src/conf_mode/snmp.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ def get_config(config=None):
if not conf.exists(base):
snmp.update({'deleted' : ''})

if conf.exists(['service', 'lldp', 'snmp', 'enable']):
if conf.exists(['service', 'lldp', 'snmp']):
snmp.update({'lldp_snmp' : ''})

if 'deleted' in snmp:
Expand Down
14 changes: 14 additions & 0 deletions src/migration-scripts/lldp/0-to-1
Original file line number Diff line number Diff line change
@@ -1,4 +1,18 @@
#!/usr/bin/env python3
#
# Copyright (C) 2020 VyOS maintainers and contributors
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License version 2 or later as
# published by the Free Software Foundation.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.

# Delete "set service lldp interface <interface> location civic-based" option
# as it was broken most of the time anyways
Expand Down
48 changes: 48 additions & 0 deletions src/migration-scripts/lldp/1-to-2
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
#!/usr/bin/env python3
#
# Copyright (C) 2023 VyOS maintainers and contributors
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License version 2 or later as
# published by the Free Software Foundation.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.

# T5855: migrate "set service lldp snmp enable" -> `set service lldp snmp"

import sys

from vyos.configtree import ConfigTree

if len(sys.argv) < 2:
print("Must specify file name!")
sys.exit(1)

file_name = sys.argv[1]

with open(file_name, 'r') as f:
config_file = f.read()

config = ConfigTree(config_file)
base = ['service', 'lldp']
if not config.exists(base):
# Nothing to do
sys.exit(0)

if config.exists(base + ['snmp']):
enabled = config.exists(base + ['snmp', 'enable'])
config.delete(base + ['snmp'])
if enabled: config.set(base + ['snmp'])

try:
with open(file_name, 'w') as f:
f.write(config.to_string())
except OSError as e:
print("Failed to save the modified config: {}".format(e))
sys.exit(1)
Loading