Esempio n. 1
0
def _next_hop():
    next_hop = choice(NEXT_HOPS)
    if next_hop is 'Null0':
        return (next_hop, None)
    ip1 = random_int(0, 223)
    ip2 = random_int(0, 255)
    ip3 = random_int(0, 255)
    ip4 = random_int(0, 255)
    ip_addr = "%s.%s.%s.%s" % (ip1, ip2, ip3, ip4)
    if next_hop is 'IP':
        return (ip_addr, None)
    return (next_hop, ip_addr)
Esempio n. 2
0
 def test_delete_and_return_true(self):
     for dut in self.duts:
         vid = str(random_int(2, 4094))
         dut.config('vlan %s' % vid)
         result = dut.api('vlans').delete(vid)
         self.assertTrue(result, 'dut=%s' % dut)
         config = dut.run_commands('show vlan')
         self.assertNotIn(vid, config[0]['vlans'])
Esempio n. 3
0
 def test_create_and_return_true(self):
     for dut in self.duts:
         dut.config('no vlan 2-4094')
         vid = str(random_int(2, 4094))
         result = dut.api('vlans').create(vid)
         self.assertTrue(result, 'dut=%s' % dut)
         config = dut.run_commands('show vlan')
         self.assertIn(vid, config[0]['vlans'], 'dut=%s' % dut)
Esempio n. 4
0
 def test_config_multiple_commands(self):
     for dut in self.duts:
         commands = list()
         for i in range(1, random_int(10, 200)):
             commands.append('hostname %s' % random_string(5, 20))
         result = dut.config(commands[:])
         self.assertIsInstance(result, list, 'dut=%s' % dut)
         self.assertEqual(len(result), len(commands), 'dut=%s' % dut)
Esempio n. 5
0
 def test_enable_multiple_commands(self):
     for dut in self.duts:
         commands = list()
         for i in range(1, random_int(10, 200)):
             commands.append('show version')
         result = dut.run_commands(commands[:])
         self.assertIsInstance(result, list, 'dut=%s' % dut)
         self.assertEqual(len(result), len(commands), 'dut=%s' % dut)
Esempio n. 6
0
 def test_delete_and_return_true(self):
     for dut in self.duts:
         vid = str(random_int(2, 4094))
         dut.config('vlan %s' % vid)
         result = dut.api('vlans').delete(vid)
         self.assertTrue(result, 'dut=%s' % dut)
         config = dut.run_commands('show vlan')
         self.assertNotIn(vid, config[0]['vlans'])
Esempio n. 7
0
 def test_set_minimum_links_with_value(self):
     minlinks = random_int(1, 16)
     cmds = [
         'interface Port-Channel1',
         'port-channel min-links %s' % minlinks
     ]
     func = function('set_minimum_links', 'Port-Channel1', minlinks)
     self.eapi_positive_config_test(func, cmds)
Esempio n. 8
0
 def test_enable_multiple_commands(self):
     for dut in self.duts:
         commands = list()
         for i in range(1, random_int(10, 200)):
             commands.append('show version')
         result = dut.run_commands(commands[:])
         self.assertIsInstance(result, list, 'dut=%s' % dut)
         self.assertEqual(len(result), len(commands), 'dut=%s' % dut)
Esempio n. 9
0
 def test_config_multiple_commands(self):
     for dut in self.duts:
         commands = list()
         for i in range(1, random_int(10, 200)):
             commands.append('hostname %s' % random_string(5, 20))
         result = dut.config(commands[:])
         self.assertIsInstance(result, list, 'dut=%s' % dut)
         self.assertEqual(len(result), len(commands), 'dut=%s' % dut)
Esempio n. 10
0
 def test_create_and_return_true(self):
     for dut in self.duts:
         dut.config('no vlan 2-4094')
         vid = str(random_int(2, 4094))
         result = dut.api('vlans').create(vid)
         self.assertTrue(result, 'dut=%s' % dut)
         config = dut.run_commands('show vlan')
         self.assertIn(vid, config[0]['vlans'], 'dut=%s' % dut)
Esempio n. 11
0
 def test_set_state_suspend(self):
     for dut in self.duts:
         vid = str(random_int(2, 4095))
         dut.config(['no vlan %s' % vid, 'vlan %s' % vid, 'state active'])
         result = dut.api('vlans').set_state(vid, 'suspend')
         self.assertTrue(result, 'dut=%s' % dut)
         config = dut.run_commands('show vlan')
         self.assertEqual('suspended', config[0]['vlans'][vid]['status'],
                          'dut=%s' % dut)
Esempio n. 12
0
 def test_set_state_suspend(self):
     for dut in self.duts:
         vid = str(random_int(2, 4095))
         dut.config(['no vlan %s' % vid, 'vlan %s' % vid, 'state active'])
         result = dut.api('vlans').set_state(vid, 'suspend')
         self.assertTrue(result, 'dut=%s' % dut)
         config = dut.run_commands('show vlan')
         self.assertEqual('suspended', config[0]['vlans'][vid]['status'],
                          'dut=%s' % dut)
Esempio n. 13
0
 def test_set_name(self):
     for dut in self.duts:
         name = random_string(maxchar=20)
         vid = str(random_int(2, 4095))
         dut.config(['no vlan %s' % vid, 'vlan %s' % vid])
         result = dut.api('vlans').set_name(vid, name)
         self.assertTrue(result, 'dut=%s' % dut)
         config = dut.run_commands('show vlan')
         self.assertEqual(name, config[0]['vlans'][vid]['name'],
                          'dut=%s' % dut)
Esempio n. 14
0
 def test_add_trunk_group(self):
     for dut in self.duts:
         tg = random_string(maxchar=32)
         vid = str(random_int(2, 4095))
         dut.config(['no vlan %s' % vid, 'vlan %s' % vid, 'no trunk group'])
         result = dut.api('vlans').add_trunk_group(vid, tg)
         self.assertTrue(result, 'dut=%s' % dut)
         config = dut.run_commands('show vlan trunk group')
         self.assertIn(tg, config[0]['trunkGroups'][vid]['names'],
                       'dut=%s' % dut)
Esempio n. 15
0
 def test_set_name(self):
     for dut in self.duts:
         name = random_string(maxchar=20)
         vid = str(random_int(2, 4095))
         dut.config(['no vlan %s' % vid, 'vlan %s' % vid])
         result = dut.api('vlans').set_name(vid, name)
         self.assertTrue(result, 'dut=%s' % dut)
         config = dut.run_commands('show vlan')
         self.assertEqual(name, config[0]['vlans'][vid]['name'],
                          'dut=%s' % dut)
Esempio n. 16
0
 def test_default(self):
     for dut in self.duts:
         vid = str(random_int(2, 4095))
         name = random_string(maxchar=20)
         dut.config(['no vlan %s' % vid, 'vlan %s' % vid,
                     'vlan %s' % vid, 'name %s' % name])
         result = dut.api('vlans').default(vid)
         self.assertTrue(result, 'dut=%s' % dut)
         config = dut.run_commands('show vlan')
         self.assertNotIn(vid, config[0]['vlans'], 'dut=%s' % dut)
Esempio n. 17
0
 def test_add_trunk_group(self):
     for dut in self.duts:
         tg = random_string(maxchar=32)
         vid = str(random_int(2, 4095))
         dut.config(['no vlan %s' % vid, 'vlan %s' % vid, 'no trunk group'])
         result = dut.api('vlans').add_trunk_group(vid, tg)
         self.assertTrue(result, 'dut=%s' % dut)
         config = dut.run_commands('show vlan trunk group')
         self.assertIn(tg, config[0]['trunkGroups'][vid]['names'],
                       'dut=%s' % dut)
Esempio n. 18
0
 def test_set_trunk_groups_default(self):
     for dut in self.duts:
         vid = str(random_int(2, 4094))
         tg = random_string()
         dut.config(['no vlan %s' % vid, 'vlan %s' % vid,
                     'trunk group %s' % tg])
         result = dut.api('vlans').set_trunk_groups(vid, default=True)
         self.assertTrue(result, 'dut=%s' % dut)
         cmd = 'show running-config section vlan %s' % vid
         config = dut.run_commands(cmd, 'text')
         self.assertNotIn('trunk group', config[0]['output'])
Esempio n. 19
0
    def test_create(self):
        # Test passing in a full set of parameters to 'create'
        # Some parameters may be not set: None
        for ip_dest in IP_DESTS:
            # Get the parameters for the call
            (next_hop, next_hop_ip) = choice(NEXT_HOPS)
            distance = choice(DISTANCES)
            if distance:
                distance = random_int(0, 255)
            tag = choice(TAGS)
            if tag:
                tag = random_int(0, 255)
            route_name = choice(ROUTE_NAMES)
            if route_name:
                route_name = random_string(minchar=4, maxchar=10)

            func = function('create',
                            ip_dest,
                            next_hop,
                            next_hop_ip=next_hop_ip,
                            distance=distance,
                            tag=tag,
                            route_name=route_name)

            # Build the expected string for comparison
            # A value of None will default to an empty string, and
            # add the tag or name keywords where appropriate
            cmd_next_hop_ip = cmd_distance = cmd_tag = cmd_route_name = ''
            if next_hop_ip is not None:
                cmd_next_hop_ip = " %s" % next_hop_ip
            if distance is not None:
                cmd_distance = " %d" % distance
            if tag is not None:
                cmd_tag = " tag %d" % tag
            if route_name is not None:
                cmd_route_name = " name %s" % route_name
            cmds = "ip route %s %s%s%s%s%s" % \
                   (ip_dest, next_hop, cmd_next_hop_ip, cmd_distance,
                    cmd_tag, cmd_route_name)

            self.eapi_positive_config_test(func, cmds)
Esempio n. 20
0
 def test_minimum_links_valid(self):
     for dut in self.duts:
         minlinks = random_int(1, 16)
         dut.config(['no interface Port-Channel1',
                     'interface Port-Channel1'])
         result = dut.api('interfaces').set_minimum_links('Port-Channel1',
                                                          minlinks)
         self.assertTrue(result, 'dut=%s' % dut)
         commands = 'show running-config interfaces Port-Channel1'
         config = dut.run_commands(commands, 'text')
         self.assertIn('port-channel min-links %s' % minlinks,
                       config[0]['output'], 'dut=%s' % dut)
Esempio n. 21
0
 def test_minimum_links_valid(self):
     for dut in self.duts:
         minlinks = random_int(1, 16)
         dut.config(
             ['no interface Port-Channel1', 'interface Port-Channel1'])
         result = dut.api('interfaces').set_minimum_links(
             'Port-Channel1', minlinks)
         self.assertTrue(result, 'dut=%s' % dut)
         commands = 'show running-config interfaces Port-Channel1'
         config = dut.run_commands(commands, 'text')
         self.assertIn('port-channel min-links %s' % minlinks,
                       config[0]['output'], 'dut=%s' % dut)
Esempio n. 22
0
 def test_set_trunk_groups(self):
     for dut in self.duts:
         vid = str(random_int(2, 4094))
         tg1 = random_string(maxchar=10)
         tg2 = random_string(maxchar=10)
         tg3 = random_string(maxchar=10)
         dut.config(['no vlan %s' % vid, 'vlan %s' % vid,
                     'trunk group %s' % tg1, 'trunk group %s' % tg2])
         result = dut.api('vlans').set_trunk_groups(vid, [tg1, tg3])
         self.assertTrue(result, 'dut=%s' % dut)
         config = dut.run_commands('show vlan %s trunk group' % vid)
         config = sorted(config[0]['trunkGroups'][vid]['names'])
         self.assertEqual(sorted([tg1, tg3]), config)
    def test_create(self):
        # Test passing in a full set of parameters to 'create'
        # Some parameters may be not set: None
        for ip_dest in IP_DESTS:
            # Get the parameters for the call
            (next_hop, next_hop_ip) = choice(NEXT_HOPS)
            distance = choice(DISTANCES)
            if distance:
                distance = random_int(0, 255)
            tag = choice(TAGS)
            if tag:
                tag = random_int(0, 255)
            route_name = choice(ROUTE_NAMES)
            if route_name:
                route_name = random_string(minchar=4, maxchar=10)

            func = function('create', ip_dest, next_hop,
                            next_hop_ip=next_hop_ip,
                            distance=distance,
                            tag=tag,
                            route_name=route_name)

            # Build the expected string for comparison
            # A value of None will default to an empty string, and
            # add the tag or name keywords where appropriate
            cmd_next_hop_ip = cmd_distance = cmd_tag = cmd_route_name = ''
            if next_hop_ip is not None:
                cmd_next_hop_ip = " %s" % next_hop_ip
            if distance is not None:
                cmd_distance = " %d" % distance
            if tag is not None:
                cmd_tag = " tag %d" % tag
            if route_name is not None:
                cmd_route_name = " name %s" % route_name
            cmds = "ip route %s %s%s%s%s%s" % \
                   (ip_dest, next_hop, cmd_next_hop_ip, cmd_distance,
                    cmd_tag, cmd_route_name)

            self.eapi_positive_config_test(func, cmds)
Esempio n. 24
0
    def test_enable_with_multiple_commands(self):
        commands = list()
        for i in range(0, random_int(2, 5)):
            commands.append(random_string())

        def execute_response(cmds, *args):
            return {'result': [x for x in cmds]}

        self.connection.execute.side_effect = execute_response

        responses = self.node.enable(commands)

        self.assertEqual(self.connection.execute.call_count, len(commands))

        expected_calls = [call(['enable', cmd], 'json') for cmd in commands]
        self.assertEqual(self.connection.execute.mock_calls, expected_calls)

        for index, response in enumerate(responses):
            self.assertEqual(commands[index], response['result'])
Esempio n. 25
0
    def test_enable_with_multiple_commands(self):
        commands = list()
        for i in range(0, random_int(2, 5)):
            commands.append(random_string())

        def execute_response(cmds, *args):
            return {'result': [x for x in cmds]}

        self.connection.execute.side_effect = execute_response

        responses = self.node.enable(commands)

        self.assertEqual(self.connection.execute.call_count, len(commands))

        expected_calls = [call(['enable', cmd], 'json') for cmd in commands]
        self.assertEqual(self.connection.execute.mock_calls, expected_calls)

        for index, response in enumerate(responses):
            self.assertEqual(commands[index], response['result'])
Esempio n. 26
0
 def test_set_minimum_links_with_value(self):
     minlinks = random_int(1, 16)
     cmds = ['interface Port-Channel1',
             'port-channel min-links %s' % minlinks]
     func = function('set_minimum_links', 'Port-Channel1', minlinks)
     self.eapi_positive_config_test(func, cmds)
Esempio n. 27
0
 def test_multiple_requests(self):
     for dut in self.duts:
         for i in range(1, random_int(10, 200)):
             result = dut.run_commands('show version')
             self.assertIsInstance(result, list, 'dut=%s' % dut)
             self.assertEqual(len(result), 1, 'dut=%s' % dut)
Esempio n. 28
0
def _ip_addr():
    ip1 = random_int(0, 223)
    ip2 = random_int(0, 255)
    ip3 = random_int(0, 255)
    return "%s.%s.%s.0/24" % (ip1, ip2, ip3)
Esempio n. 29
0
def _distance():
    return random_int(1, 255)
Esempio n. 30
0
 def test_set_mtu_with_values(self):
     for intf in self.INTERFACES:
         for value in [68, 65535, random_int(68, 65535)]:
             cmds = ['interface %s' % intf, 'mtu %s' % value]
             func = function('set_mtu', intf, value)
             self.eapi_positive_config_test(func, cmds)
Esempio n. 31
0
 def test_set_mtu_with_values(self):
     for intf in self.INTERFACES:
         for value in [68, 65535, random_int(68, 65535)]:
             cmds = ['interface %s' % intf, 'mtu %s' % value]
             func = function('set_mtu', intf, value)
             self.eapi_positive_config_test(func, cmds)
Esempio n. 32
0
 def test_minimum_links_invalid_value(self):
     for dut in self.duts:
         minlinks = random_int(17, 128)
         result = dut.api('interfaces').set_minimum_links('Port-Channel1',
                                                          minlinks)
         self.assertFalse(result)
Esempio n. 33
0
def _tag():
    return random_int(0, 255)
Esempio n. 34
0
 def test_minimum_links_invalid_value(self):
     for dut in self.duts:
         minlinks = random_int(17, 128)
         result = dut.api('interfaces').set_minimum_links(
             'Port-Channel1', minlinks)
         self.assertFalse(result)
Esempio n. 35
0
 def test_multiple_requests(self):
     for dut in self.duts:
         for i in range(1, random_int(10, 200)):
             result = dut.run_commands('show version')
             self.assertIsInstance(result, list, 'dut=%s' % dut)
             self.assertEqual(len(result), 1, 'dut=%s' % dut)
Esempio n. 36
0
 def test_set_lacp_timeout_with_value(self):
     timeout = random_int(1, 16)
     cmds = ['interface Port-Channel1', 'port-channel lacp fallback timeout %s' % timeout]
     func = function('set_lacp_timeout', 'Port-Channel1', timeout)
     self.eapi_positive_config_test(func, cmds)