本文整理汇总了Python中testlib.function函数的典型用法代码示例。如果您正苦于以下问题:Python function函数的具体用法?Python function怎么用?Python function使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了function函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_set_description
def test_set_description(self):
for state in ['config', 'negate', 'default']:
value = 'this is a test'
name = 'test'
cmd = 'neighbor {} description'.format(name)
if state == 'config':
cmds = ['router bgp 65000', '{} {}'.format(cmd, value)]
func = function('set_description', name, value=value)
elif state == 'negate':
cmds = ['router bgp 65000', 'no {}'.format(cmd)]
func = function('set_description', name, disable=True)
elif state == 'default':
cmds = ['router bgp 65000', 'default {}'.format(cmd)]
func = function('set_description', name, value=value,
default=True)
self.eapi_positive_config_test(func, cmds)
# func = function('set_description', name, value=None, default=False,
# disable=False)
# self.eapi_exception_config_test(func, ValueError)
# If command_builder fails because value is None, uncomment
# above lines and remove below lines.
cmds = ['router bgp 65000', 'no neighbor test description']
func = function('set_description', 'test', None)
self.eapi_positive_config_test(func, cmds)
示例2: test_set_route_map_out
def test_set_route_map_out(self):
for state in ['config', 'negate', 'default']:
route_map = 'TEST_RM'
name = 'test'
cmd = 'neighbor {} route-map'.format(name)
if state == 'config':
cmds = ['router bgp 65000', '{} {} out'.format(cmd, route_map)]
func = function('set_route_map_out', name, value=route_map)
elif state == 'negate':
cmds = ['router bgp 65000', 'no {} out'.format(cmd)]
func = function('set_route_map_out', name, disable=True)
elif state == 'default':
cmds = ['router bgp 65000', 'default {} out'.format(cmd)]
func = function('set_route_map_out', name, value=route_map,
default=True)
self.eapi_positive_config_test(func, cmds)
# func = function('set_route_map_out', name, value=None, default=False,
# disable=False)
# self.eapi_exception_config_test(func, ValueError)
# If command_builder fails because value is None, uncomment
# above lines and remove below lines.
cmds = ['router bgp 65000', 'no neighbor test route-map out']
func = function('set_route_map_out', 'test', None)
self.eapi_positive_config_test(func, cmds)
示例3: test_set_primary_ip
def test_set_primary_ip(self):
# vrrp 10 ip 10.10.4.10
# Test set_primary_ip gives properly formatted commands
ip1 = '10.10.4.110'
ipcurr = '10.10.4.10'
cases = [
(ip1, None, None, 'vrrp %d ip %s' % (upd_vrid, ip1)),
(ip1, True, None, 'no vrrp %d ip %s' % (upd_vrid, ipcurr)),
(ip1, None, True, 'default vrrp %d ip %s' % (upd_vrid, ipcurr)),
(ip1, True, True, 'default vrrp %d ip %s' % (upd_vrid, ipcurr)),
]
for (primary_ip, disable, default, cmd) in cases:
func = function('set_primary_ip', upd_intf, upd_vrid,
value=primary_ip, disable=disable, default=default)
exp_cmds = [upd_cmd] + [cmd]
self.eapi_positive_config_test(func, exp_cmds)
# Test raising ValueError from invalid parameters
cases = ['abc', 500, '101.101']
for primary_ip in cases:
func = function('set_primary_ip', upd_intf, upd_vrid,
value=primary_ip)
self.eapi_exception_config_test(func, ValueError)
示例4: test_set_mac_addr_adv_interval
def test_set_mac_addr_adv_interval(self):
# vrrp 10 mac-address advertisement-interval 30
# Test set_timers_advertise gives properly formatted commands
maadvint = 'mac-address advertisement-interval'
cases = [
(50, None, None, 'vrrp %d %s 50' % (upd_vrid, maadvint)),
(None, None, True, 'default vrrp %d %s' % (upd_vrid, maadvint)),
(None, True, True, 'default vrrp %d %s' % (upd_vrid, maadvint)),
(None, True, None, 'no vrrp %d %s' % (upd_vrid, maadvint)),
]
for (mac_addr_adv_interval, disable, default, cmd) in cases:
func = function('set_mac_addr_adv_interval', upd_intf, upd_vrid,
value=mac_addr_adv_interval, disable=disable,
default=default)
exp_cmds = [upd_cmd] + [cmd]
self.eapi_positive_config_test(func, exp_cmds)
# Test raising ValueError by entering invalid parameters
cases = ['a', 10000]
for mac_addr_adv_interval in cases:
func = function('set_mac_addr_adv_interval', upd_intf, upd_vrid,
value=mac_addr_adv_interval)
self.eapi_exception_config_test(func, ValueError)
示例5: test_set_timers_advertise
def test_set_timers_advertise(self):
# vrrp 10 timers advertise 3
# Test set_timers_advertise gives properly formatted commands
cases = [
(50, None, None, 'vrrp %d timers advertise 50' % upd_vrid),
(None, None, True, 'default vrrp %d timers advertise' % upd_vrid),
(None, True, True, 'default vrrp %d timers advertise' % upd_vrid),
(None, True, None, 'no vrrp %d timers advertise' % upd_vrid),
]
for (timers_advertise, disable, default, cmd) in cases:
func = function('set_timers_advertise', upd_intf, upd_vrid,
value=timers_advertise, disable=disable,
default=default)
exp_cmds = [upd_cmd] + [cmd]
self.eapi_positive_config_test(func, exp_cmds)
# Test raising ValueError by entering invalid parameters
cases = [256, 0, 'a']
for timers_advertise in cases:
func = function('set_timers_advertise', upd_intf, upd_vrid,
value=timers_advertise)
self.eapi_exception_config_test(func, ValueError)
示例6: test_set_preempt
def test_set_preempt(self):
# vrrp 10 preempt
# Test set_description gives properly formatted commands
cases = [
(False, None, None, 'no vrrp %d preempt' % upd_vrid),
(True, None, None, 'vrrp %d preempt' % upd_vrid),
(None, None, True, 'default vrrp %d preempt' % upd_vrid),
(None, True, True, 'default vrrp %d preempt' % upd_vrid),
(None, True, None, 'no vrrp %d preempt' % upd_vrid),
]
for (preempt, disable, default, cmd) in cases:
func = function('set_preempt', upd_intf, upd_vrid,
value=preempt, disable=disable, default=default)
exp_cmds = [upd_cmd] + [cmd]
self.eapi_positive_config_test(func, exp_cmds)
# Test raising ValueError by entering invalid parameters
cases = ['a', 5]
for preempt in cases:
func = function('set_preempt', upd_intf, upd_vrid,
value=preempt)
self.eapi_exception_config_test(func, ValueError)
示例7: test_set_preempt_delay_min
def test_set_preempt_delay_min(self):
# vrrp 10 preempt delay minimum 0
# Test set_preempt_delay_min gives properly formatted commands
cases = [
(2500, None, None,
'vrrp %d preempt delay minimum 2500' % upd_vrid),
(None, None, True,
'default vrrp %d preempt delay minimum' % upd_vrid),
(None, True, True,
'default vrrp %d preempt delay minimum' % upd_vrid),
(None, True, None, 'no vrrp %d preempt delay minimum' % upd_vrid),
]
for (preempt_delay_min, disable, default, cmd) in cases:
func = function('set_preempt_delay_min', upd_intf, upd_vrid,
value=preempt_delay_min, disable=disable,
default=default)
exp_cmds = [upd_cmd] + [cmd]
self.eapi_positive_config_test(func, exp_cmds)
# Test raising ValueError by entering invalid parameters
cases = ['a', 3601]
for preempt_delay_min in cases:
func = function('set_preempt_delay_min', upd_intf, upd_vrid,
value=preempt_delay_min)
self.eapi_exception_config_test(func, ValueError)
示例8: test_set_delay_reload
def test_set_delay_reload(self):
# vrrp 10 delay reload 0
# Test set_delay_min gives properly formatted commands
cases = [
(1750, None, None, 'vrrp %d delay reload 1750' % upd_vrid),
(None, None, True, 'default vrrp %d delay reload' % upd_vrid),
(None, True, True, 'default vrrp %d delay reload' % upd_vrid),
(None, True, None, 'no vrrp %d delay reload' % upd_vrid),
]
for (delay_reload, disable, default, cmd) in cases:
func = function('set_delay_reload', upd_intf, upd_vrid,
value=delay_reload, disable=disable,
default=default)
exp_cmds = [upd_cmd] + [cmd]
self.eapi_positive_config_test(func, exp_cmds)
# Test raising ValueError by entering invalid parameters
cases = ['a', 3601]
for delay_reload in cases:
func = function('set_delay_reload', upd_intf, upd_vrid,
value=delay_reload)
self.eapi_exception_config_test(func, ValueError)
示例9: test_set_peer_group
def test_set_peer_group(self):
for state in ['config', 'negate', 'default']:
peer_group = 'test'
name = '172.16.10.1'
cmd = 'neighbor {} peer-group'.format(name)
if state == 'config':
cmds = ['router bgp 65000', '{} {}'.format(cmd, peer_group)]
func = function('set_peer_group', name, peer_group)
elif state == 'negate':
cmds = ['router bgp 65000', 'no {}'.format(cmd)]
func = function('set_peer_group', name, disable=True)
elif state == 'default':
cmds = ['router bgp 65000', 'default {}'.format(cmd)]
func = function('set_peer_group', name, peer_group,
default=True)
self.eapi_positive_config_test(func, cmds)
# func = function('set_peer_group', name, value=None, default=False,
# disable=False)
# self.eapi_exception_config_test(func, ValueError)
# If command_builder fails because value is None, uncomment
# above lines and remove below lines.
cmds = ['router bgp 65000', 'no neighbor 172.16.10.1 peer-group']
func = function('set_peer_group', '172.16.10.1', None)
self.eapi_positive_config_test(func, cmds)
示例10: test_set_bfd_ip
def test_set_bfd_ip(self):
# no vrrp 10 bfd ip
bfd_addr = '10.10.4.101'
# Test bfd_ip gives properly formatted commands
cases = [
(bfd_addr, None, None, 'vrrp %d bfd ip %s' % (upd_vrid, bfd_addr)),
(None, True, None, 'no vrrp %d bfd ip' % upd_vrid),
(None, None, True, 'default vrrp %d bfd ip' % upd_vrid),
(None, True, True, 'default vrrp %d bfd ip' % upd_vrid),
]
for (bfd_ip, disable, default, cmd) in cases:
func = function('set_bfd_ip', upd_intf, upd_vrid,
value=bfd_ip, disable=disable, default=default)
exp_cmds = [upd_cmd] + [cmd]
self.eapi_positive_config_test(func, exp_cmds)
# Test raising ValueError from invalid parameters
cases = ['abc', 500, '101.101']
for bfd_ip in cases:
func = function('set_bfd_ip', upd_intf, upd_vrid,
value=bfd_ip)
self.eapi_exception_config_test(func, ValueError)
示例11: test_set_banner_default_disable
def test_set_banner_default_disable(self):
func = function('set_banner', banner_type='motd',
value=None, default=True)
cmds = 'default banner motd'
self.eapi_positive_config_test(func, cmds)
func = function('set_banner', banner_type='motd',
value=None, disable=True)
cmds = 'no banner motd'
self.eapi_positive_config_test(func, cmds)
示例12: test_remove_network
def test_remove_network(self):
func = function('remove_network', '172.16.10.1', '24', 'test')
cmds = ['router bgp 65000', 'no network 172.16.10.1/24 route-map test']
self.eapi_positive_config_test(func, cmds)
func = function('remove_network', '', '24', 'test')
self.eapi_exception_config_test(func, ValueError)
func = function('remove_network', '172.16.10.1', '', 'test')
self.eapi_exception_config_test(func, ValueError)
示例13: test_set_mtu_invalid_value_raises_value_error
def test_set_mtu_invalid_value_raises_value_error(self):
for intf in self.INTERFACES:
for value in [67, 65536, random_string()]:
func = function('set_mtu', intf, value)
self.eapi_exception_config_test(func, ValueError)
for value in [None]:
# If command_builder fails because value is None, put None
# in the first loop to check for value error, and remove
# this second loop
cmds = ['interface %s' % intf, 'no mtu']
func = function('set_mtu', intf, value)
self.eapi_positive_config_test(func, cmds)
示例14: test_set_shutdown
def test_set_shutdown(self):
for state in ['config', 'negate', 'default']:
if state == 'config':
cmds = ['router bgp 65000', 'shutdown']
func = function('set_shutdown', default=False, disable=False)
elif state == 'negate':
cmds = ['router bgp 65000', 'no shutdown']
func = function('set_shutdown', disable=True)
elif state == 'default':
cmds = ['router bgp 65000', 'default shutdown']
func = function('set_shutdown', default=True)
self.eapi_positive_config_test(func, cmds)
示例15: test_set_iprouting
def test_set_iprouting(self):
for state in ['config', 'negate', 'default']:
if state == 'config':
cmds = 'ip routing'
func = function('set_iprouting', True)
elif state == 'negate':
cmds = 'no ip routing'
func = function('set_iprouting', disable=True)
elif state == 'default':
cmds = 'default ip routing'
func = function('set_iprouting', default=True)
self.eapi_positive_config_test(func, cmds)