Skip to content

Commit 22fc3cc

Browse files
author
Rob
authored
Merge branch 'master' into feature/fix-regex
2 parents 48ba592 + c4f8ed5 commit 22fc3cc

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

50 files changed

+258
-245
lines changed

.travis.yml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ python:
33
- "3.6"
44
- "3.7"
55
# command to install dependencies
6-
install: "pip install -r requirements.txt -r test-requirements.txt"
6+
install: "pip install -r requirements.txt -r test-requirements.txt . && pip install flake8"
77
# command to run tests
8-
script: pytest tests/
8+
script:
9+
- python -m unittest discover -s . -p '*_test.py'
10+
- flake8 . --count --select=W291,W293,W391 --statistics

capirca/aclgen.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -507,7 +507,8 @@ def Run(base_directory, definitions_directory, policy_file, output_directory,
507507
result.get()
508508
except (ACLParserError, ACLGeneratorError) as e:
509509
with_errors = True
510-
logging.warning('\n\nerror encountered in rendering process:\n%s\n\n', e)
510+
logging.warning('\n\nerror encountered in rendering '
511+
'process:\n%s\n\n', e)
511512

512513
# actually write files to disk
513514
WriteFiles(write_files)

capirca/lib/aclgenerator.py

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -39,10 +39,6 @@ class NoPlatformPolicyError(Error):
3939
"""Raised when a policy is received that doesn't support this platform."""
4040

4141

42-
class UnsupportedFilter(Error):
43-
"""Raised when we see an inappropriate filter."""
44-
45-
4642
class UnknownIcmpTypeError(Error):
4743
"""Raised when we see an unknown icmp-type."""
4844

@@ -55,7 +51,7 @@ class EstablishedError(Error):
5551
"""Raised when a term has established option with inappropriate protocol."""
5652

5753

58-
class UnsupportedAF(Error):
54+
class UnsupportedAFError(Error):
5955
"""Raised when provided an unsupported address family."""
6056

6157

@@ -67,7 +63,7 @@ class UnsupportedFilterError(Error):
6763
"""Raised when we see an inappropriate filter."""
6864

6965

70-
class UnsupportedTargetOption(Error):
66+
class UnsupportedTargetOptionError(Error):
7167
"""Raised when a filter has an impermissible default action specified."""
7268

7369

@@ -151,7 +147,7 @@ def NormalizeAddressFamily(self, af):
151147
af: Numeric address family value
152148
153149
Raises:
154-
UnsupportedAF: Address family not in keys or values of our AF_MAP.
150+
UnsupportedAFError: Address family not in keys or values of our AF_MAP.
155151
"""
156152
# ensure address family (af) is valid
157153
if af in self.AF_MAP_BY_NUMBER:
@@ -160,8 +156,8 @@ def NormalizeAddressFamily(self, af):
160156
# convert AF name to number (e.g. 'inet' becomes 4, 'inet6' becomes 6)
161157
af = self.AF_MAP[af]
162158
else:
163-
raise UnsupportedAF('Address family %s is not supported, term %s.' % (
164-
af, self.term.name))
159+
raise UnsupportedAFError('Address family %s is not supported, '
160+
'term %s.' % (af, self.term.name))
165161
return af
166162

167163
def NormalizeIcmpTypes(self, icmp_types, protocols, af):
@@ -417,9 +413,10 @@ def FixHighPorts(self, term, af='inet', all_protocols_stateful=False):
417413
Copy of term that has been fixed
418414
419415
Raises:
420-
UnsupportedAF: Address family provided but unsupported.
416+
UnsupportedAFError: Address family provided but unsupported.
421417
UnsupportedFilter: Protocols do not match the address family.
422418
EstablishedError: Established option used with inappropriate protocol.
419+
UnsupportedFilterError: Filter does not support protocols with AF.
423420
"""
424421
mod = term
425422

@@ -431,15 +428,18 @@ def FixHighPorts(self, term, af='inet', all_protocols_stateful=False):
431428

432429
# Check that the address family matches the protocols.
433430
if af not in self._SUPPORTED_AF:
434-
raise UnsupportedAF('\nAddress family %s, found in %s, '
435-
'unsupported by %s' % (af, term.name, self._PLATFORM))
431+
raise UnsupportedAFError(
432+
'\nAddress family %s, found in %s, unsupported '
433+
'by %s' % (af, term.name, self._PLATFORM))
436434
if af in self._FILTER_BLACKLIST:
437435
unsupported_protocols = self._FILTER_BLACKLIST[af].intersection(protocols)
438436
if unsupported_protocols:
439-
raise UnsupportedFilter('\n%s targets do not support protocol(s) %s '
440-
'with address family %s (in %s)' %
441-
(self._PLATFORM, unsupported_protocols,
442-
af, term.name))
437+
raise UnsupportedFilterError(
438+
'\n%s targets do not support protocol(s) %s '
439+
'with address family %s (in %s)' % (self._PLATFORM,
440+
unsupported_protocols,
441+
af,
442+
term.name))
443443

444444
# Many renders expect high ports for terms with the established option.
445445
for opt in [str(x) for x in term.option]:

capirca/lib/aruba.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -309,7 +309,7 @@ def _TranslatePolicy(self, pol, exp_info):
309309

310310
if term.expiration <= current_date:
311311
logging.warning('WARNING: Term %s in policy %s is expired and '
312-
'will not be rendered.', term.name, filter_name)
312+
'will not be rendered.', term.name, filter_name)
313313
continue
314314

315315
new_terms.append(Term(term, filter_type, verbose))

capirca/lib/cisco.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -745,7 +745,9 @@ def __str__(self):
745745
and ('tcp-established' in opts or 'established' in opts)):
746746
if 'established' not in self.options:
747747
self.options.append('established')
748-
if ('ip' in protocol) and ('fragments' in opts):
748+
# Using both 'fragments' and 'is-fragment', ref Github Issue #187
749+
if ('ip' in protocol) and (('fragments' in opts) or
750+
('is-fragment' in opts)):
749751
if 'fragments' not in self.options:
750752
self.options.append('fragments')
751753
# ACL-based Forwarding
@@ -1077,6 +1079,7 @@ def _BuildTokens(self):
10771079

10781080
supported_sub_tokens.update({'option': {'established',
10791081
'tcp-established',
1082+
'is-fragment',
10801083
'fragments'},
10811084
# Warning, some of these are mapped
10821085
# differently. See _ACTION_TABLE
@@ -1159,7 +1162,7 @@ def _TranslatePolicy(self, pol, exp_info):
11591162
'in less than two weeks.', term.name, filter_name)
11601163
if term.expiration <= current_date:
11611164
logging.warning('WARNING: Term %s in policy %s is expired and '
1162-
'will not be rendered.', term.name, filter_name)
1165+
'will not be rendered.', term.name, filter_name)
11631166
continue
11641167

11651168
# render terms based on filter type

capirca/lib/ciscoasa.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,14 +21,14 @@
2121
from __future__ import unicode_literals
2222

2323
import datetime
24+
import ipaddress
2425
import logging
2526
import re
27+
from typing import cast
2628

2729
from capirca.lib import aclgenerator
2830
from capirca.lib import cisco
2931
from capirca.lib import nacaddr
30-
import ipaddress
31-
from typing import cast
3232

3333

3434
_ACTION_TABLE = {
@@ -365,4 +365,3 @@ def __str__(self):
365365

366366
# end for header, filter_name, filter_type...
367367
return '\n'.join(target)
368-

capirca/lib/ciscoxr.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,8 @@ def _BuildTokens(self):
6464

6565
def _GetObjectGroupTerm(self, term, filter_name, verbose=True):
6666
"""Returns an ObjectGroupTerm object."""
67-
return CiscoXRObjectGroupTerm(term, filter_name, platform=self._PLATFORM, verbose=verbose)
67+
return CiscoXRObjectGroupTerm(term, filter_name,
68+
platform=self._PLATFORM, verbose=verbose)
6869

6970

7071
class CiscoXRObjectGroupTerm(cisco.ObjectGroupTerm):

capirca/lib/juniper.py

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -122,11 +122,11 @@ class Term(aclgenerator.Term):
122122
"""Representation of an individual Juniper term.
123123
124124
This is mostly useful for the __str__() method.
125-
126-
Args:
127-
term: policy.Term object
128-
term_type: the address family for the term, one of "inet", "inet6",
129-
or "bridge"
125+
Attributes:
126+
term: The term object from policy.
127+
term_type: String indicating type of term, inet, inet6 icmp etc.
128+
enable_dsmo: Boolean to enable dsmo.
129+
noverbose: Boolean to disable verbosity.
130130
"""
131131
_PLATFORM = 'juniper'
132132
_DEFAULT_INDENT = 12
@@ -826,7 +826,7 @@ class Juniper(aclgenerator.ACLGenerator):
826826
This class takes a policy object and renders the output into a syntax
827827
which is understood by juniper routers.
828828
829-
Args:
829+
Attributes:
830830
pol: policy.Policy object
831831
"""
832832

@@ -906,7 +906,6 @@ def _TranslatePolicy(self, pol, exp_info):
906906
enable_dsmo = 'enable_dsmo' in filter_options[1:]
907907
noverbose = 'noverbose' in filter_options[1:]
908908

909-
910909
if not interface_specific:
911910
filter_options.remove('not-interface-specific')
912911
if enable_dsmo:
@@ -921,7 +920,7 @@ def _TranslatePolicy(self, pol, exp_info):
921920
new_terms = []
922921
for term in terms:
923922

924-
# if the inactive option is set, we should deactivate the term and remove the option
923+
# if inactive is set, deactivate the term and remove the option.
925924
if 'inactive' in term.option:
926925
term.inactive = True
927926
term.option.remove('inactive')

capirca/lib/junipersrx.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -448,8 +448,8 @@ def _TranslatePolicy(self, pol, exp_info):
448448
self._FixLargePolices(terms, filter_type)
449449
for term in terms:
450450
if set(['established', 'tcp-established']).intersection(term.option):
451-
logging.debug('Skipping established term %s ' +
452-
'because SRX is stateful.', term.name)
451+
logging.debug('Skipping established term %s because SRX is stateful.',
452+
term.name)
453453
continue
454454
term.name = self.FixTermLength(term.name)
455455
if term.name in term_dup_check:

capirca/lib/nacaddr.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@
2121
from __future__ import unicode_literals
2222

2323
import collections
24-
import itertools
2524
import ipaddress
25+
import itertools
2626
from typing import Union
2727

2828

0 commit comments

Comments
 (0)