Skip to content

Commit 0cb2168

Browse files
authored
Merge pull request #2274 from napalm-automation/iss2273
Fix issue with sanitized and filtered EOS configs
2 parents be6265e + 85deed9 commit 0cb2168

File tree

23 files changed

+2043
-5
lines changed

23 files changed

+2043
-5
lines changed

docs/conf.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -307,6 +307,7 @@
307307
"get_arp_table_with_vrf": "get_arp_table",
308308
"get_route_to_longer": "get_route_to",
309309
"get_config_sanitized": "get_config",
310+
"get_config_sanitized_filtered": "get_config",
310311
}
311312

312313

napalm/base/constants.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,3 +100,9 @@
100100
r"^((tacacs|radius) server [^\n]+\n(\s+[^\n]+\n)*\s+key) [^\n]+$": r"\1 <removed>",
101101
r"^(\s+ppp (chap|pap) password \d) .+$": r"\1 <removed>",
102102
}
103+
104+
EOS_SANITIZE_FILTERS = {
105+
**CISCO_SANITIZE_FILTERS,
106+
r"^(\s+aaa root secret \d) .+$": r"\1 <removed>",
107+
r"^(\s+username .+ (password|secret) \d) .+$": r"\1 <removed>",
108+
}

napalm/base/test/getters.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -541,6 +541,30 @@ def test_get_config_sanitized(self, test_case):
541541

542542
return get_config
543543

544+
@wrap_test_cases
545+
def test_get_config_sanitized_filtered(self, test_case):
546+
"""Test get_config with both sanitized=True and retrieve parameter."""
547+
return_config = {}
548+
get_config = self.device.get_config(retrieve="running", sanitized=True)
549+
assert isinstance(get_config, dict)
550+
assert helpers.test_model(models.ConfigDict, get_config)
551+
assert get_config["startup"] == ""
552+
assert get_config["candidate"] == ""
553+
assert get_config["running"] != ""
554+
return_config["running"] = get_config["running"]
555+
556+
get_config = self.device.get_config(retrieve="startup", sanitized=True)
557+
assert isinstance(get_config, dict)
558+
assert helpers.test_model(models.ConfigDict, get_config)
559+
assert get_config["running"] == ""
560+
assert get_config["candidate"] == ""
561+
562+
return_config["startup"] = get_config["startup"]
563+
564+
return_config["candidate"] = ""
565+
566+
return return_config
567+
544568
@wrap_test_cases
545569
def test_get_network_instances(self, test_case):
546570
"""Test get_network_instances method."""

napalm/eos/eos.py

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2085,7 +2085,7 @@ def get_config(self, retrieve="all", full=False, sanitized=False, format="text")
20852085
startup_cfg = str(output[0]["output"]) if get_startup else ""
20862086
if sanitized and startup_cfg:
20872087
startup_cfg = napalm.base.helpers.sanitize_config(
2088-
startup_cfg, c.CISCO_SANITIZE_FILTERS
2088+
startup_cfg, c.EOS_SANITIZE_FILTERS
20892089
)
20902090
return {
20912091
"startup": startup_cfg,
@@ -2094,17 +2094,28 @@ def get_config(self, retrieve="all", full=False, sanitized=False, format="text")
20942094
}
20952095
elif get_startup or get_running:
20962096
if retrieve == "running":
2097-
commands = ["show {}-config{}".format(retrieve, run_full)]
2097+
commands = [
2098+
"show {}-config{}{}".format(retrieve, run_full, run_sanitized)
2099+
]
20982100
elif retrieve == "startup":
20992101
commands = ["show {}-config".format(retrieve)]
21002102
output = self._run_commands(commands, encoding="text")
2103+
startup_cfg = str(output[0]["output"]) if get_startup else ""
2104+
if sanitized and get_startup and startup_cfg:
2105+
startup_cfg = napalm.base.helpers.sanitize_config(
2106+
startup_cfg, c.EOS_SANITIZE_FILTERS
2107+
)
21012108
return {
2102-
"startup": str(output[0]["output"]) if get_startup else "",
2109+
"startup": startup_cfg,
21032110
"running": str(output[0]["output"]) if get_running else "",
21042111
"candidate": "",
21052112
}
21062113
elif get_candidate:
2107-
commands = ["show session-config named {}".format(self.config_session)]
2114+
commands = [
2115+
"show session-config named {}{}".format(
2116+
self.config_session, run_sanitized
2117+
)
2118+
]
21082119
output = self._run_commands(commands, encoding="text")
21092120
return {"startup": "", "running": "", "candidate": str(output[0]["output"])}
21102121
elif retrieve == "candidate":
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"startup": "! Command: show startup-config\n! Startup-config last modified at Sun Sep 11 18:35:01 2016 by root\n! device: localhost (vEOS, EOS-4.15.2.1F)\n!\n! boot system flash:/vEOS-lab.swi\n!\nevent-handler dhclient\n trigger on-boot\n action bash sudo /mnt/flash/initialize_ma1.sh\n !\n transceiver qsfp default-mode 4x10G\n !\n spanning-tree mode mstp\n !\n aaa authorization exec default local\n !\n aaa root secret 5 $1$zr7sHZaW$WagNykw1d5wjy4ZhtMgUS/\n !\n username admin privilege 15 role network-admin secret 5 $1$VoQBHXed$4z2.EoAeoIY2SFme/Pz3Q/\n username vagrant privilege 15 role network-admin secret 5 $1$l/6gq.Qs$ifURvKWUYzLm0RqmRgr.W1\n !\n interface Ethernet1\n !\n interface Ethernet2\n !\n interface Management1\n ip address 10.0.2.15/24\n\t !\n\t no ip routing\n\t !\n\t management api http-commands\n\t no shutdown\n\t !\n\t !\n\t end\n",
2+
"startup": "! Command: show startup-config\n! Startup-config last modified at Sun Sep 11 18:35:01 2016 by root\n! device: localhost (vEOS, EOS-4.15.2.1F)\n!\n! boot system flash:/vEOS-lab.swi\n!\nevent-handler dhclient\n trigger on-boot\n action bash sudo /mnt/flash/initialize_ma1.sh\n !\n transceiver qsfp default-mode 4x10G\n !\n spanning-tree mode mstp\n !\n aaa authorization exec default local\n !\n aaa root secret 5 <removed>\n !\n username admin privilege 15 role network-admin secret 5 <removed>\n username vagrant privilege 15 role network-admin secret 5 <removed>\n !\n interface Ethernet1\n !\n interface Ethernet2\n !\n interface Management1\n ip address 10.0.2.15/24\n\t !\n\t no ip routing\n\t !\n\t management api http-commands\n\t no shutdown\n\t !\n\t !\n\t end\n",
33
"running": "! Command: show startup-config\n! Startup-config last modified at Sun Sep 11 18:35:01 2016 by root\n! device: localhost (vEOS, EOS-4.15.2.1F)\n!\n! boot system flash:/vEOS-lab.swi\n!\nevent-handler dhclient\n trigger on-boot\n action bash sudo /mnt/flash/initialize_ma1.sh\n !\n transceiver qsfp default-mode 4x10G\n !\n spanning-tree mode mstp\n !\n aaa authorization exec default local\n !\n aaa root secret 5 <removed>\n !\n username admin privilege 15 role network-admin secret 5 <removed>\n username vagrant privilege 15 role network-admin secret 5 <removed>\n !\n interface Ethernet1\n !\n interface Ethernet2\n !\n interface Management1\n ip address 10.0.2.15/24\n\t !\n\t no ip routing\n\t !\n\t management api http-commands\n\t no shutdown\n\t !\n\t !\n\t end\n",
44
"candidate": ""
55
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"running": "! Command: show running-config\n!\n! device: localhost (vEOS, EOS-4.15.2.1F)\n!\n! boot system flash:/vEOS-lab.swi\n!\nevent-handler dhclient\n trigger on-boot\n action bash sudo /mnt/flash/initialize_ma1.sh\n !\n transceiver qsfp default-mode 4x10G\n !\n spanning-tree mode mstp\n !\n aaa authorization exec default local\n !\n aaa root secret 5 <removed>\n !\n username admin privilege 15 role network-admin secret 5 <removed>\n username vagrant privilege 15 role network-admin secret 5 <removed>\n !\n interface Ethernet1\n !\n interface Ethernet2\n !\n interface Management1\n ip address 10.0.2.15/24\n\t !\n\t no ip routing\n\t !\n\t management api http-commands\n\t no shutdown\n\t !\n\t !\n\t end\n",
3+
"startup": "! Command: show startup-config\n! Startup-config last modified at Sun Sep 11 18:35:01 2016 by root\n! device: localhost (vEOS, EOS-4.15.2.1F)\n!\n! boot system flash:/vEOS-lab.swi\n!\nevent-handler dhclient\n trigger on-boot\n action bash sudo /mnt/flash/initialize_ma1.sh\n !\n transceiver qsfp default-mode 4x10G\n !\n spanning-tree mode mstp\n !\n aaa authorization exec default local\n !\n aaa root secret 5 <removed>\n !\n username admin privilege 15 role network-admin secret 5 <removed>\n username vagrant privilege 15 role network-admin secret 5 <removed>\n !\n interface Ethernet1\n !\n interface Ethernet2\n !\n interface Management1\n ip address 10.0.2.15/24\n\t !\n\t no ip routing\n\t !\n\t management api http-commands\n\t no shutdown\n\t !\n\t !\n\t end\n",
4+
"candidate": ""
5+
}
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
! Command: show running-config
2+
!
3+
! device: localhost (vEOS, EOS-4.15.2.1F)
4+
!
5+
! boot system flash:/vEOS-lab.swi
6+
!
7+
event-handler dhclient
8+
trigger on-boot
9+
action bash sudo /mnt/flash/initialize_ma1.sh
10+
!
11+
transceiver qsfp default-mode 4x10G
12+
!
13+
spanning-tree mode mstp
14+
!
15+
aaa authorization exec default local
16+
!
17+
aaa root secret 5 <removed>
18+
!
19+
username admin privilege 15 role network-admin secret 5 <removed>
20+
username vagrant privilege 15 role network-admin secret 5 <removed>
21+
!
22+
interface Ethernet1
23+
!
24+
interface Ethernet2
25+
!
26+
interface Management1
27+
ip address 10.0.2.15/24
28+
!
29+
no ip routing
30+
!
31+
management api http-commands
32+
no shutdown
33+
!
34+
!
35+
end
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
! Command: show startup-config
2+
! Startup-config last modified at Sun Sep 11 18:35:01 2016 by root
3+
! device: localhost (vEOS, EOS-4.15.2.1F)
4+
!
5+
! boot system flash:/vEOS-lab.swi
6+
!
7+
event-handler dhclient
8+
trigger on-boot
9+
action bash sudo /mnt/flash/initialize_ma1.sh
10+
!
11+
transceiver qsfp default-mode 4x10G
12+
!
13+
spanning-tree mode mstp
14+
!
15+
aaa authorization exec default local
16+
!
17+
aaa root secret 5 $1$zr7sHZaW$WagNykw1d5wjy4ZhtMgUS/
18+
!
19+
username admin privilege 15 role network-admin secret 5 $1$VoQBHXed$4z2.EoAeoIY2SFme/Pz3Q/
20+
username vagrant privilege 15 role network-admin secret 5 $1$l/6gq.Qs$ifURvKWUYzLm0RqmRgr.W1
21+
!
22+
interface Ethernet1
23+
!
24+
interface Ethernet2
25+
!
26+
interface Management1
27+
ip address 10.0.2.15/24
28+
!
29+
no ip routing
30+
!
31+
management api http-commands
32+
no shutdown
33+
!
34+
!
35+
end
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"startup": "!\n\n!\nversion 15.5\nservice timestamps debug datetime msec\nservice timestamps log datetime msec\nno platform punt-keepalive disable-kernel-core\nplatform console auto\n!\nhostname CSR1\n!\nboot-start-marker\nboot-end-marker\n!\n!\nenable password cisco\n!\naaa new-model\n!\n!\naaa authentication login default local\naaa authorization exec default local\n!\n!\n!\n!\n!\naaa session-id common\n!\nip vrf MGMT\n!\n!\n!\n!\n!\n!\n!\n!\n!\n\n\nip domain name example.local\n\n!\n!\n!\n!\n!\n!\n!\n!\n!\n!\nsubscriber templating\n!\nmultilink bundle-name authenticated\n!\n!\n!\n!\n!\n!\n!\n!\n!\n!\n!\n!\n!\nlicense udi pid CSR1000V sn 9OSEGKJXRHE\nspanning-tree extend system-id\n!\nusername cisco privilege 15 password 0 <removed>\n!\nredundancy\n!\n!\n!\n!\n!\n!\n!\n!\n!\n!\n!\n!\n!\n!\n!\n!\n!\n!\n!\n!\n!\n!\n!\ninterface Loopback0\n ip address 1.1.1.1 255.255.255.255\n!\ninterface GigabitEthernet1\n ip vrf forwarding MGMT\n ip address 192.168.35.121 255.255.255.0\n negotiation auto\n!\ninterface GigabitEthernet2\n ip address 10.1.1.1 255.255.255.0\n negotiation auto\n!\ninterface GigabitEthernet3\n no ip address\n shutdown\n negotiation auto\n!\nrouter ospf 1\n redistribute connected subnets\n network 10.1.1.0 0.0.0.255 area 0\n!\n!\nvirtual-service csr_mgmt\n!\nip forward-protocol nd\n!\nno ip http server\nno ip http secure-server\n!\n!\n!\n!\n!\n!\ncontrol-plane\n!\n !\n !\n !\n !\n!\n!\n!\n!\n!\nline con 0\nline vty 0 4\n!\n!\nend",
3+
"running": "!\n\n!\nversion 15.5\nservice timestamps debug datetime msec\nservice timestamps log datetime msec\nno platform punt-keepalive disable-kernel-core\nplatform console auto\n!\nhostname CSR1\n!\nboot-start-marker\nboot-end-marker\n!\n!\nenable password cisco\n!\naaa new-model\n!\n!\naaa authentication login default local\naaa authorization exec default local\n!\n!\n!\n!\n!\naaa session-id common\n!\nip vrf MGMT\n!\n!\n!\n!\n!\n!\n!\n!\n!\n\n\nip domain name example.local\n\n!\n!\n!\n!\n!\n!\n!\n!\n!\n!\nsubscriber templating\n!\nmultilink bundle-name authenticated\n!\n!\n!\n!\n!\n!\n!\n!\n!\n!\n!\n!\n!\nlicense udi pid CSR1000V sn 9OSEGKJXRHE\nspanning-tree extend system-id\n!\nusername cisco privilege 15 password 0 <removed>\n!\nredundancy\n!\n!\n!\n!\n!\n!\n!\n!\n!\n!\n!\n!\n!\n!\n!\n!\n!\n!\n!\n!\n!\n!\n!\ninterface Loopback0\n ip address 1.1.1.1 255.255.255.255\n!\ninterface GigabitEthernet1\n ip vrf forwarding MGMT\n ip address 192.168.35.121 255.255.255.0\n negotiation auto\n!\ninterface GigabitEthernet2\n ip address 10.1.1.1 255.255.255.0\n negotiation auto\n!\ninterface GigabitEthernet3\n no ip address\n shutdown\n negotiation auto\n!\nrouter ospf 1\n redistribute connected subnets\n network 10.1.1.0 0.0.0.255 area 0\n!\n!\nvirtual-service csr_mgmt\n!\nip forward-protocol nd\n!\nno ip http server\nno ip http secure-server\n!\n!\n!\n!\n!\n!\ncontrol-plane\n!\n !\n !\n !\n !\n!\n!\n!\n!\n!\nline con 0\nline vty 0 4\n!\n!\nend",
4+
"candidate": ""
5+
}
Lines changed: 151 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,151 @@
1+
Building configuration...
2+
3+
Current configuration : 1366 bytes
4+
!
5+
! Last configuration change at 18:41:02 UTC Thu Nov 24 2016
6+
!
7+
version 15.5
8+
service timestamps debug datetime msec
9+
service timestamps log datetime msec
10+
no platform punt-keepalive disable-kernel-core
11+
platform console auto
12+
!
13+
hostname CSR1
14+
!
15+
boot-start-marker
16+
boot-end-marker
17+
!
18+
!
19+
enable password cisco
20+
!
21+
aaa new-model
22+
!
23+
!
24+
aaa authentication login default local
25+
aaa authorization exec default local
26+
!
27+
!
28+
!
29+
!
30+
!
31+
aaa session-id common
32+
!
33+
ip vrf MGMT
34+
!
35+
!
36+
!
37+
!
38+
!
39+
!
40+
!
41+
!
42+
!
43+
44+
45+
ip domain name example.local
46+
47+
!
48+
!
49+
!
50+
!
51+
!
52+
!
53+
!
54+
!
55+
!
56+
!
57+
subscriber templating
58+
!
59+
multilink bundle-name authenticated
60+
!
61+
!
62+
!
63+
!
64+
!
65+
!
66+
!
67+
!
68+
!
69+
!
70+
!
71+
!
72+
!
73+
license udi pid CSR1000V sn 9OSEGKJXRHE
74+
spanning-tree extend system-id
75+
!
76+
username cisco privilege 15 password 0 cisco
77+
!
78+
redundancy
79+
!
80+
!
81+
!
82+
!
83+
!
84+
!
85+
!
86+
!
87+
!
88+
!
89+
!
90+
!
91+
!
92+
!
93+
!
94+
!
95+
!
96+
!
97+
!
98+
!
99+
!
100+
!
101+
!
102+
interface Loopback0
103+
ip address 1.1.1.1 255.255.255.255
104+
!
105+
interface GigabitEthernet1
106+
ip vrf forwarding MGMT
107+
ip address 192.168.35.121 255.255.255.0
108+
negotiation auto
109+
!
110+
interface GigabitEthernet2
111+
ip address 10.1.1.1 255.255.255.0
112+
negotiation auto
113+
!
114+
interface GigabitEthernet3
115+
no ip address
116+
shutdown
117+
negotiation auto
118+
!
119+
router ospf 1
120+
redistribute connected subnets
121+
network 10.1.1.0 0.0.0.255 area 0
122+
!
123+
!
124+
virtual-service csr_mgmt
125+
!
126+
ip forward-protocol nd
127+
!
128+
no ip http server
129+
no ip http secure-server
130+
!
131+
!
132+
!
133+
!
134+
!
135+
!
136+
control-plane
137+
!
138+
!
139+
!
140+
!
141+
!
142+
!
143+
!
144+
!
145+
!
146+
!
147+
line con 0
148+
line vty 0 4
149+
!
150+
!
151+
end

0 commit comments

Comments
 (0)