File tree 2 files changed +13
-11
lines changed
2 files changed +13
-11
lines changed Original file line number Diff line number Diff line change 4
4
import jinja2
5
5
import netaddr
6
6
7
+ from .log import log_err
7
8
8
9
class TemplateFabric (object ):
9
10
""" Fabric for rendering jinja2 templates """
@@ -97,12 +98,11 @@ def pfx_filter(value):
97
98
intf , ip_address = key
98
99
if '/' not in ip_address :
99
100
if TemplateFabric .is_ipv4 (ip_address ):
100
- new_ip_address = "%s/32" % ip_address
101
+ table [( intf , "%s/32" % ip_address )] = val
101
102
elif TemplateFabric .is_ipv6 (ip_address ):
102
- new_ip_address = "%s/128" % ip_address
103
+ table [( intf , "%s/128" % ip_address )] = val
103
104
else :
104
- raise ValueError ("'%s' is invalid ip address" % ip_address )
105
- table [(intf , new_ip_address )] = val
105
+ log_err ("'%s' is invalid ip address" % ip_address )
106
106
else :
107
107
table [key ] = val
108
108
return table
Original file line number Diff line number Diff line change 1
1
from app .template import TemplateFabric
2
2
from collections import OrderedDict
3
+ import pytest
4
+
3
5
4
6
def test_pfx_filter_none ():
5
7
res = TemplateFabric .pfx_filter (None )
@@ -126,12 +128,12 @@ def test_pfx_filter_pfx_comprehensive():
126
128
res = TemplateFabric .pfx_filter (src )
127
129
assert res == expected
128
130
129
- def test_pfx_filter_pfx_exception ():
131
+ @pytest .fixture
132
+ def test_pfx_filter_wrong_ip (caplog ):
130
133
src = {
131
- ('Loopback0' , '23asef45 ' ): {},
134
+ ('Loopback0' , 'wrong_ip ' ): {},
132
135
}
133
- try :
134
- res = TemplateFabric .pfx_filter (src )
135
- assert False , "Exception wasn't raised"
136
- except ValueError as e :
137
- assert str (e ) == "'23asef45' is invalid ip address"
136
+ res = TemplateFabric .pfx_filter (src )
137
+ assert "'wrong_ip' is invalid ip address" in caplog .text
138
+ assert isinstance (res , OrderedDict ) and len (res ) == 0
139
+
You can’t perform that action at this time.
0 commit comments