Skip to content

Commit

Permalink
Converting all tests to use _ParseLine (#356)
Browse files Browse the repository at this point in the history
* saving progress

* Fixing up rest of the tests.

* Running formatter.

* Removing unused imports variables and formatting again.

* Fixing a few more formatting issues.
  • Loading branch information
ankenyr committed Mar 6, 2024
1 parent ab8d835 commit 8ba9321
Show file tree
Hide file tree
Showing 68 changed files with 1,637 additions and 2,474 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,9 @@ ip access-list test-filter

remark good-term-2
permit tcp 10.1.1.0/24 any eq ssh
permit tcp 10.1.1.0/24 any eq 6537


remark good-term-3
permit tcp 10.1.1.0/24 any eq ssh
permit tcp 10.1.1.0/24 any eq 6537

exit
Expand Down
36 changes: 14 additions & 22 deletions tests/regression/arista/arista_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,9 @@
# limitations under the License.
"""Tests for arista acl rendering module."""

from unittest import mock

from absl.testing import absltest

from aerleon.lib import arista, nacaddr, naming, policy
from aerleon.lib import arista, naming, policy
from tests.regression_utils import capture

GOOD_HEADER = """
Expand Down Expand Up @@ -210,11 +208,11 @@
class AristaTest(absltest.TestCase):
def setUp(self):
super().setUp()
self.naming = mock.create_autospec(naming.Naming)
self.naming = naming.Naming()

@capture.stdout
def testRemark(self):
self.naming.GetNetAddr.return_value = [nacaddr.IP('10.1.1.1/32')]
self.naming._ParseLine('SOME_HOST = 10.1.1.1/32', 'networks')

pol = policy.ParsePolicy(GOOD_HEADER_3 + GOOD_TERM_4, self.naming)
acl = arista.Arista(pol, EXP_INFO)
Expand All @@ -225,7 +223,6 @@ def testRemark(self):
expected = 'test-filter remark'
self.assertNotIn(expected, str(acl), str(acl))

self.naming.GetNetAddr.assert_called_once_with('SOME_HOST')
print(acl)

@capture.stdout
Expand All @@ -238,18 +235,21 @@ def testExtendedEosSyntax(self):

@capture.stdout
def testESPIsAnInteger(self):
self.naming._ParseLine('SOME_HOST = 10.0.0.1/32', 'networks')
acl = arista.Arista(policy.ParsePolicy(GOOD_HEADER + GOOD_TERM_5, self.naming), EXP_INFO)
self.assertIn('permit 50', str(acl))
print(acl)

@capture.stdout
def testAHIsAnInteger(self):
self.naming._ParseLine('SOME_HOST = 10.0.0.1/32', 'networks')
acl = arista.Arista(policy.ParsePolicy(GOOD_HEADER + GOOD_TERM_6, self.naming), EXP_INFO)
self.assertIn('permit 51', str(acl))
print(acl)

@capture.stdout
def testAHAndESPAreIntegers(self):
self.naming._ParseLine('SOME_HOST = 10.0.0.1/32', 'networks')
acl = arista.Arista(policy.ParsePolicy(GOOD_HEADER + GOOD_TERM_7, self.naming), EXP_INFO)
self.assertIn('permit 50', str(acl))
self.assertIn('permit 51', str(acl))
Expand All @@ -273,8 +273,10 @@ def testBuildWarningTokens(self):

@capture.stdout
def testStandardTermHost(self):
self.naming.GetNetAddr.return_value = [nacaddr.IP('10.1.1.0/24')]
self.naming.GetServiceByProto.return_value = ['22', '6537']
self.naming._ParseLine('SOME_HOST = 10.1.1.0/24', 'networks')
self.naming._ParseLine('SOME_HOST2 = 10.1.1.0/24', 'networks')
self.naming._ParseLine('SSH = 22/tcp', 'services')
self.naming._ParseLine('GOPENFLOW = 6537/tcp', 'services')

pol = policy.ParsePolicy(GOOD_HEADER_2 + GOOD_TERM_2 + GOOD_TERM_3, self.naming)
acl = arista.Arista(pol, EXP_INFO)
Expand All @@ -286,15 +288,10 @@ def testStandardTermHost(self):
expected = ' permit tcp 10.1.1.0/24 any eq 6537'
self.assertIn(expected, str(acl), str(acl))

self.naming.GetNetAddr.assert_has_calls([mock.call('SOME_HOST'), mock.call('SOME_HOST2')])
self.naming.GetServiceByProto.assert_has_calls(
[mock.call('SSH', 'tcp'), mock.call('GOPENFLOW', 'tcp')]
)

@capture.stdout
def testStandardTermHostV6(self):
self.naming.GetNetAddr.return_value = [nacaddr.IP('2620:1::/64')]
self.naming.GetServiceByProto.return_value = ['22']
self.naming._ParseLine('SOME_HOST = 2620:1::/64', 'networks')
self.naming._ParseLine('SSH = 22/tcp', 'services')

pol = policy.ParsePolicy(GOOD_HEADER_IPV6 + GOOD_TERM_2, self.naming)
acl = arista.Arista(pol, EXP_INFO)
Expand All @@ -304,12 +301,9 @@ def testStandardTermHostV6(self):
expected = ' permit tcp 2620:1::/64 any eq ssh'
self.assertIn(expected, str(acl), str(acl))

self.naming.GetNetAddr.assert_has_calls([mock.call('SOME_HOST')])
self.naming.GetServiceByProto.assert_has_calls([mock.call('SSH', 'tcp')])

@capture.stdout
def testStandardTermV4(self):
self.naming.GetNetAddr.return_value = [nacaddr.IP('10.1.1.0/24')]
self.naming._ParseLine('SOME_HOST = 10.1.1.0/24', 'networks')

pol = policy.ParsePolicy(GOOD_HEADER_3 + GOOD_TERM_4, self.naming)
acl = arista.Arista(pol, EXP_INFO)
Expand All @@ -319,11 +313,9 @@ def testStandardTermV4(self):
expected = ' permit 10.1.1.0/24\n'
self.assertIn(expected, str(acl), str(acl))

self.naming.GetNetAddr.assert_has_calls([mock.call('SOME_HOST')])

@capture.stdout
def testSIPUsesInt(self):
self.naming.GetServiceByProto.return_value = ['5060']
self.naming._ParseLine('SIP = 5060/udp', 'services')
pol = policy.ParsePolicy(GOOD_HEADER + GOOD_TERM_8, self.naming)
acl = arista.Arista(pol, EXP_INFO)
print(acl)
Expand Down

0 comments on commit 8ba9321

Please sign in to comment.