summaryrefslogtreecommitdiff
path: root/src/conf_mode/snmp.py
diff options
context:
space:
mode:
authorChristian Poessinger <christian@poessinger.com>2020-02-09 18:01:08 +0100
committerChristian Poessinger <christian@poessinger.com>2020-02-09 18:01:22 +0100
commit1b156e160c1d3d12b27bbf68645663d99795c2b0 (patch)
treed54dac6954c404c97616a3a004761d150a3557f8 /src/conf_mode/snmp.py
parente76325e6902b9a857b9e544accd5b020439aa8e7 (diff)
downloadvyos-1x-1b156e160c1d3d12b27bbf68645663d99795c2b0.tar.gz
vyos-1x-1b156e160c1d3d12b27bbf68645663d99795c2b0.zip
snmp: T1931: instead of searching a pseudo marker find real marker in config
As we need to operate with usmUser, we can search for it directly if its present or not. There is always one usmUser entry for the system user.
Diffstat (limited to 'src/conf_mode/snmp.py')
-rwxr-xr-xsrc/conf_mode/snmp.py51
1 files changed, 23 insertions, 28 deletions
diff --git a/src/conf_mode/snmp.py b/src/conf_mode/snmp.py
index db5f552fc..b0ceb22b4 100755
--- a/src/conf_mode/snmp.py
+++ b/src/conf_mode/snmp.py
@@ -751,7 +751,7 @@ def apply(snmp):
with open(config_file_user, 'r') as f:
for line in f:
# Search for our magic string inside the file
- if '**** DO NOT EDIT THIS FILE ****' in line:
+ if 'usmUser' in line:
ready = True
break
@@ -759,33 +759,28 @@ def apply(snmp):
# thus we need to re-open and re-read the file as the content changed.
# After that we can no read the encrypted password from the config and
# replace the CLI plaintext password with its encrypted version.
- ready = False
- while not ready:
- while not os.path.exists(config_file_user):
- sleep(0.1)
-
- with open(config_file_user, 'r') as f:
- engineID = ''
- for line in f:
- if line.startswith('usmUser'):
- string = line.split(' ')
- cfg = {
- 'user': string[4].replace(r'"', ''),
- 'auth_pw': string[8],
- 'priv_pw': string[10]
- }
- # No need to take care about the VyOS internal user
- if cfg['user'] == snmp['vyos_user']:
- ready = True
- continue
-
- # Now update the running configuration
- #
- # Currently when executing os.system() the environment does not have the vyos_libexec_dir variable set, see T685
- os.system('vyos_libexec_dir=/usr/libexec/vyos /opt/vyatta/sbin/my_set service snmp v3 user "{0}" auth encrypted-key {1} > /dev/null'.format(cfg['user'], cfg['auth_pw']))
- os.system('vyos_libexec_dir=/usr/libexec/vyos /opt/vyatta/sbin/my_set service snmp v3 user "{0}" privacy encrypted-key {1} > /dev/null'.format(cfg['user'], cfg['priv_pw']))
- os.system('vyos_libexec_dir=/usr/libexec/vyos /opt/vyatta/sbin/my_delete service snmp v3 user "{0}" auth plaintext-key > /dev/null'.format(cfg['user']))
- os.system('vyos_libexec_dir=/usr/libexec/vyos /opt/vyatta/sbin/my_delete service snmp v3 user "{0}" privacy plaintext-key > /dev/null'.format(cfg['user']))
+ with open(config_file_user, 'r') as f:
+ engineID = ''
+ for line in f:
+ if line.startswith('usmUser'):
+ string = line.split(' ')
+ cfg = {
+ 'user': string[4].replace(r'"', ''),
+ 'auth_pw': string[8],
+ 'priv_pw': string[10]
+ }
+ # No need to take care about the VyOS internal user
+ if cfg['user'] == snmp['vyos_user']:
+ ready = True
+ continue
+
+ # Now update the running configuration
+ #
+ # Currently when executing os.system() the environment does not have the vyos_libexec_dir variable set, see T685
+ os.system('vyos_libexec_dir=/usr/libexec/vyos /opt/vyatta/sbin/my_set service snmp v3 user "{0}" auth encrypted-key {1} > /dev/null'.format(cfg['user'], cfg['auth_pw']))
+ os.system('vyos_libexec_dir=/usr/libexec/vyos /opt/vyatta/sbin/my_set service snmp v3 user "{0}" privacy encrypted-key {1} > /dev/null'.format(cfg['user'], cfg['priv_pw']))
+ os.system('vyos_libexec_dir=/usr/libexec/vyos /opt/vyatta/sbin/my_delete service snmp v3 user "{0}" auth plaintext-key > /dev/null'.format(cfg['user']))
+ os.system('vyos_libexec_dir=/usr/libexec/vyos /opt/vyatta/sbin/my_delete service snmp v3 user "{0}" privacy plaintext-key > /dev/null'.format(cfg['user']))
# Enable AgentX in FRR
os.system('vtysh -c "configure terminal" -c "agentx" >/dev/null')