Exemple #1
0
    def test_modify_configuration_first_level(self):

        # Add a device to it
        tb = Genie.testbed = Testbed()
        dev1 = Device(testbed=tb, name='dev1', os='nxos')
        dev2 = Device(testbed=tb, name='dev2', os='nxos')
        rip = Rip(instance_id=5)
        rip.add_force_vrf(None)
        dev1.add_feature(rip)
        dev2.add_feature(rip)

        # Can either confgiure via kwargs, or attributes
        output = rip.build_config(apply=False)
        self.assertMultiLineDictEqual(output, {
            'dev1':
            'feature rip\n'
            'router rip 5\n'
            ' address-family ipv4 unicast\n'
            '  exit\n'
            ' exit',
            'dev2':
            'feature rip\n'
            'router rip 5\n'
            ' address-family ipv4 unicast\n'
            '  exit\n'
            ' exit',
            })

        self.assertEqual(rip.device_attr['dev1'].shutdown, None)
        self.assertEqual(rip.device_attr['dev2'].shutdown, None)

        rip.shutdown = False
        output = rip.build_config(attributes='device_attr__dev1__shutdown', apply=False)
        self.assertMultiLineDictEqual(output, {
            'dev1':
            'router rip 5\n'
            ' no shutdown\n'
            ' exit',
            })

        rip.shutdown = False
        output = rip.build_config(attributes='device_attr__*__shutdown', apply=False)
        self.assertMultiLineDictEqual(output, {
            'dev1':
            'router rip 5\n'
            ' no shutdown\n'
            ' exit',
            'dev2':
            'router rip 5\n'
            ' no shutdown\n'
            ' exit',
            })
Exemple #2
0
    def test_no_device_configuration(self):
        tb = Genie.testbed = Testbed()
        dev1 = Device(testbed=tb, name='dev1', os='nxos')
        dev2 = Device(testbed=tb, name='dev2', os='nxos')

        rip = Rip(instance_id=1)
        rip.add_force_vrf(None)

        # Default configuration, let's make sure it works
        output = rip.build_config(apply=False)
        self.assertMultiLineDictEqual(output, {})

        rip.shutdown = False
        rip.device_attr['dev1'].vrf_attr[None].address_family_attr['ipv4 unicast'].maximum_paths = 2
        rip.device_attr['dev1'].vrf_attr[None].address_family_attr['ipv4 unicast'].default_metric = 1
        rip.device_attr['dev1'].vrf_attr[None].address_family_attr['ipv4 unicast'].distance = 120
        rip.device_attr['dev1'].vrf_attr[None].address_family_attr['ipv4 unicast'].redistribute_direct_rmap\
            = 'rmap1'
        rip.device_attr['dev1'].vrf_attr[None].address_family_attr['ipv4 unicast'].redistribute_static_rmap\
            = 'rmap2'
        rip.device_attr['dev1'].vrf_attr[None].address_family_attr['ipv4 unicast'].redistribute_lisp_rmap\
            = 'rmap3'
        rip.device_attr['dev1'].vrf_attr[None].address_family_attr['ipv6 unicast'].maximum_paths = 7
        rip.device_attr['dev1'].vrf_attr[None].address_family_attr['ipv6 unicast'].default_metric = 3
        rip.device_attr['dev1'].vrf_attr[None].address_family_attr['ipv6 unicast'].distance = 120
        rip.device_attr['dev1'].vrf_attr[None].address_family_attr['ipv6 unicast'].redistribute_direct_rmap\
            = 'rmap4'
        rip.device_attr['dev1'].vrf_attr[None].address_family_attr['ipv6 unicast'].redistribute_static_rmap\
            = 'rmap5'
        rip.device_attr['dev1'].vrf_attr[None].address_family_attr['ipv6 unicast'].redistribute_lisp_rmap\
            = 'rmap6'

        rip.device_attr['dev2'].vrf_attr[None].address_family_attr['ipv4 unicast'].maximum_paths = 4
        rip.device_attr['dev2'].vrf_attr[None].address_family_attr['ipv4 unicast'].default_metric = 3
        rip.device_attr['dev2'].vrf_attr[None].address_family_attr['ipv4 unicast'].distance = 122
        rip.device_attr['dev2'].vrf_attr[None].address_family_attr['ipv4 unicast'].redistribute_direct_rmap\
            = 'rmap_direct'
        rip.device_attr['dev2'].vrf_attr[None].address_family_attr['ipv4 unicast'].redistribute_static_rmap\
            = 'rmap_static'
        rip.device_attr['dev2'].vrf_attr[None].address_family_attr['ipv4 unicast'].redistribute_lisp_rmap\
            = 'rmap_lisp'
        rip.device_attr['dev2'].vrf_attr[None].address_family_attr['ipv6 unicast'].maximum_paths = 7
        rip.device_attr['dev2'].vrf_attr[None].address_family_attr['ipv6 unicast'].default_metric = 3
        rip.device_attr['dev2'].vrf_attr[None].address_family_attr['ipv6 unicast'].distance = 120
        rip.device_attr['dev2'].vrf_attr[None].address_family_attr['ipv6 unicast'].redistribute_direct_rmap\
            = 'rmap_direct_ipv6'
        rip.device_attr['dev2'].vrf_attr[None].address_family_attr['ipv6 unicast'].redistribute_static_rmap\
            = 'rmap_static_ipv6'
        rip.device_attr['dev2'].vrf_attr[None].address_family_attr['ipv6 unicast'].redistribute_lisp_rmap\
            = 'rmap_lisp_ipv6'

        expected_output = rip.build_config(apply=False)
        self.assertMultiLineDictEqual(output, {})

        output = rip.build_config(apply=True)

        expected_output = None
        self.assertEqual(output, expected_output)
Exemple #3
0
    def test_cfg(self):

        tb = Genie.testbed = Testbed()
        dev = Device(testbed=tb, name='PE1', os='nxos')

        rip = Rip(instance_id=1)
        rip.add_force_vrf(None)
        dev.add_feature(rip)
        rip.device_attr['PE1']

        output = rip.build_config(apply=False)

        self.assertMultiLineDictEqual(output, {'PE1':
            'feature rip\n'
            'router rip 1\n'
            ' address-family ipv4 unicast\n'
            '  exit\n'
            ' exit'
            })

        vrf1 = Vrf('vrf1')
        intf1 = Interface(device=dev, name='Ethernet0/0', vrf=vrf1)
        intf1.add_feature(rip)
        rip.address_families |= {AddressFamily.ipv6_unicast}
        rip.shutdown = False
        rip.device_attr['PE1'].vrf_attr[None].address_family_attr['ipv4 unicast'].maximum_paths = 2
        rip.device_attr['PE1'].vrf_attr[None].address_family_attr['ipv4 unicast'].default_metric = 1
        rip.device_attr['PE1'].vrf_attr[None].address_family_attr['ipv4 unicast'].distance = 120
        rip.device_attr['PE1'].vrf_attr[None].address_family_attr['ipv4 unicast'].redistribute_direct_rmap\
            = 'rmap1'
        rip.device_attr['PE1'].vrf_attr[None].address_family_attr['ipv4 unicast'].redistribute_static_rmap\
            = 'rmap2'
        rip.device_attr['PE1'].vrf_attr[None].address_family_attr['ipv4 unicast'].redistribute_lisp_rmap\
            = 'rmap3'
        rip.device_attr['PE1'].vrf_attr[None].address_family_attr['ipv6 unicast'].maximum_paths = 7
        rip.device_attr['PE1'].vrf_attr[None].address_family_attr['ipv6 unicast'].default_metric = 3
        rip.device_attr['PE1'].vrf_attr[None].address_family_attr['ipv6 unicast'].distance = 120
        rip.device_attr['PE1'].vrf_attr[None].address_family_attr['ipv6 unicast'].redistribute_direct_rmap\
            = 'rmap4'
        rip.device_attr['PE1'].vrf_attr[None].address_family_attr['ipv6 unicast'].redistribute_static_rmap\
            = 'rmap5'
        rip.device_attr['PE1'].vrf_attr[None].address_family_attr['ipv6 unicast'].redistribute_lisp_rmap\
            = 'rmap6'
        rip.device_attr['PE1'].vrf_attr['vrf1'].address_family_attr['ipv6 unicast'].\
            maximum_paths = 10
        rip.device_attr['PE1'].vrf_attr['vrf1'].address_family_attr['ipv6 unicast'].\
            default_metric = 7
        rip.device_attr['PE1'].vrf_attr['vrf1'].address_family_attr['ipv6 unicast'].\
            distance = 127
        rip.device_attr['PE1'].vrf_attr['vrf1'].address_family_attr['ipv6 unicast'].\
            redistribute_direct_rmap = 'rmap14'
        rip.device_attr['PE1'].vrf_attr['vrf1'].address_family_attr['ipv6 unicast'].\
            redistribute_static_rmap = 'rmap15'
        rip.device_attr['PE1'].vrf_attr['vrf1'].address_family_attr['ipv6 unicast'].\
            redistribute_lisp_rmap = 'rmap16'

        # rip.build_config(apply=False)
        output = rip.build_config(apply=False)

        expected_output = {'PE1': '''\
router rip 1
 no shutdown
 address-family ipv4 unicast
  default-metric 1
  distance 120
  maximum-paths 2
  redistribute lisp route-map rmap3
  redistribute direct route-map rmap1
  redistribute static route-map rmap2
  exit
 address-family ipv6 unicast
  default-metric 3
  distance 120
  maximum-paths 7
  redistribute lisp route-map rmap6
  redistribute direct route-map rmap4
  redistribute static route-map rmap5
  exit
 vrf vrf1
  address-family ipv4 unicast
   exit
  address-family ipv6 unicast
   default-metric 7
   distance 127
   maximum-paths 10
   redistribute lisp route-map rmap16
   redistribute direct route-map rmap14
   redistribute static route-map rmap15
   exit
  exit
 exit'''}
        self.maxDiff = None
        self.assertMultiLineDictEqual(output, expected_output)

        # Set a mock
        dev.cli = Mock()
        dev.configure = Mock()
        dev.add_feature(rip)
        # Mock config

        output = rip.build_config(apply=True)
Exemple #4
0
    def test_multi_device_configuration(self):
        tb = Genie.testbed = Testbed()
        dev1 = Device(testbed=tb, name='dev1', os='nxos')
        dev2 = Device(testbed=tb, name='dev2', os='nxos')

        rip = Rip(instance_id=1)
        rip.add_force_vrf(None)
        dev1.cli = Mock()
        dev1.configure = Mock()
        dev2.cli = Mock()
        dev2.configure = Mock()
        dev1.add_feature(rip)
        dev2.add_feature(rip)

        # Default configuration, let's make sure it works
        output = rip.build_config(apply=False)
        self.assertMultiLineDictEqual(output, {
            'dev1':
            'feature rip\n'
            'router rip 1\n'
            ' address-family ipv4 unicast\n'
            '  exit\n'
            ' exit',
            'dev2':
            'feature rip\n'
            'router rip 1\n'
            ' address-family ipv4 unicast\n'
            '  exit\n'
            ' exit'})

        rip.address_families |= {AddressFamily.ipv6_unicast}
        rip.shutdown = True
        rip.device_attr['dev1'].vrf_attr[None].address_family_attr['ipv4 unicast'].maximum_paths = 2
        rip.device_attr['dev1'].vrf_attr[None].address_family_attr['ipv4 unicast'].default_metric = 1
        rip.device_attr['dev1'].vrf_attr[None].address_family_attr['ipv4 unicast'].distance = 120
        rip.device_attr['dev1'].vrf_attr[None].address_family_attr['ipv4 unicast'].redistribute_direct_rmap\
            = 'rmap1'
        rip.device_attr['dev1'].vrf_attr[None].address_family_attr['ipv4 unicast'].redistribute_static_rmap\
            = 'rmap2'
        rip.device_attr['dev1'].vrf_attr[None].address_family_attr['ipv4 unicast'].redistribute_lisp_rmap\
            = 'rmap3'
        rip.device_attr['dev1'].vrf_attr[None].address_family_attr['ipv6 unicast'].maximum_paths = 7
        rip.device_attr['dev1'].vrf_attr[None].address_family_attr['ipv6 unicast'].default_metric = 3
        rip.device_attr['dev1'].vrf_attr[None].address_family_attr['ipv6 unicast'].distance = 120
        rip.device_attr['dev1'].vrf_attr[None].address_family_attr['ipv6 unicast'].redistribute_direct_rmap\
            = 'rmap4'
        rip.device_attr['dev1'].vrf_attr[None].address_family_attr['ipv6 unicast'].redistribute_static_rmap\
            = 'rmap5'
        rip.device_attr['dev1'].vrf_attr[None].address_family_attr['ipv6 unicast'].redistribute_lisp_rmap\
            = 'rmap6'

        rip.device_attr['dev2'].vrf_attr[None].address_family_attr['ipv4 unicast'].maximum_paths = 4
        rip.device_attr['dev2'].vrf_attr[None].address_family_attr['ipv4 unicast'].default_metric = 3
        rip.device_attr['dev2'].vrf_attr[None].address_family_attr['ipv4 unicast'].distance = 122
        rip.device_attr['dev2'].vrf_attr[None].address_family_attr['ipv4 unicast'].redistribute_direct_rmap\
            = 'rmap_direct'
        rip.device_attr['dev2'].vrf_attr[None].address_family_attr['ipv4 unicast'].redistribute_static_rmap\
            = 'rmap_static'
        rip.device_attr['dev2'].vrf_attr[None].address_family_attr['ipv4 unicast'].redistribute_lisp_rmap\
            = 'rmap_lisp'
        rip.device_attr['dev2'].vrf_attr[None].address_family_attr['ipv6 unicast'].maximum_paths = 7
        rip.device_attr['dev2'].vrf_attr[None].address_family_attr['ipv6 unicast'].default_metric = 3
        rip.device_attr['dev2'].vrf_attr[None].address_family_attr['ipv6 unicast'].distance = 120
        rip.device_attr['dev2'].vrf_attr[None].address_family_attr['ipv6 unicast'].redistribute_direct_rmap\
            = 'rmap_direct_ipv6'
        rip.device_attr['dev2'].vrf_attr[None].address_family_attr['ipv6 unicast'].redistribute_static_rmap\
            = 'rmap_static_ipv6'
        rip.device_attr['dev2'].vrf_attr[None].address_family_attr['ipv6 unicast'].redistribute_lisp_rmap\
            = 'rmap_lisp_ipv6'

        output = rip.build_config(apply=False)
        expected_output = {'dev1': '''\
router rip 1
 shutdown
 address-family ipv4 unicast
  default-metric 1
  distance 120
  maximum-paths 2
  redistribute lisp route-map rmap3
  redistribute direct route-map rmap1
  redistribute static route-map rmap2
  exit
 address-family ipv6 unicast
  default-metric 3
  distance 120
  maximum-paths 7
  redistribute lisp route-map rmap6
  redistribute direct route-map rmap4
  redistribute static route-map rmap5
  exit
 exit''',
'dev2': '''\
router rip 1
 shutdown
 address-family ipv4 unicast
  default-metric 3
  distance 122
  maximum-paths 4
  redistribute lisp route-map rmap_lisp
  redistribute direct route-map rmap_direct
  redistribute static route-map rmap_static
  exit
 address-family ipv6 unicast
  default-metric 3
  distance 120
  maximum-paths 7
  redistribute lisp route-map rmap_lisp_ipv6
  redistribute direct route-map rmap_direct_ipv6
  redistribute static route-map rmap_static_ipv6
  exit
 exit'''}
        self.maxDiff = None
        self.assertMultiLineDictEqual(output, expected_output)
        output = rip.build_config(apply=True)