本文整理汇总了Python中asserts.mod_args_generator函数的典型用法代码示例。如果您正苦于以下问题:Python mod_args_generator函数的具体用法?Python mod_args_generator怎么用?Python mod_args_generator使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了mod_args_generator函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_is_bridgemem_port_type
def test_is_bridgemem_port_type(self, mock_path_exists,
mock_get_subints):
# port is not a l2 port
values = {'/sys/class/net/eth1/brport': False}
mock_path_exists.side_effect = mod_args_generator(values)
mock_get_subints.return_value = []
assert_equals(self.iface.get_bridgemem_port_type(), 0)
# port is not a l2 port but has subints that are l2 ports
values = {'/sys/class/net/eth1/brport': False,
'/sys/class/net/eth1.100/brport': True}
mock_get_subints.return_value = ['eth1.100']
mock_path_exists.side_effect = mod_args_generator(values)
assert_equals(self.iface.get_bridgemem_port_type(), 2)
# port is an access
mock_get_subints.return_value = []
values = {'/sys/class/net/eth1/brport': True}
mock_path_exists.side_effect = mod_args_generator(values)
assert_equals(self.iface.get_bridgemem_port_type(), 1)
# if port has native port that is in bridge and subints in bridge
mock_get_subints.return_value = ['eth1.100']
values = {'/sys/class/net/eth1/brport': True,
'/sys/class/net/eth1.100/brport': True}
mock_path_exists.side_effect = mod_args_generator(values)
assert_equals(self.iface.get_bridgemem_port_type(), 2)
示例2: test_read_link_state
def test_read_link_state(self, mock_read_oneline):
""" test get link state """
# port is admin down
values = {
'/sys/class/net/eth1/carrier': None,
'/sys/class/net/eth1/operstate': 'down'
}
mock_read_oneline.side_effect = mod_args_generator(values)
assert_equals(self.iface.linkstate, 0)
# port is down
values = {
'/sys/class/net/eth1/carrier': '0',
'/sys/class/net/eth1/operstate': 'down'
}
mock_read_oneline.side_effect = mod_args_generator(values)
assert_equals(self.iface.linkstate, 1)
# clear link_state
self.iface._linkstate = None
# port is up
values = {
'/sys/class/net/eth1/carrier': '1',
'/sys/class/net/eth1/operstate': 'up'
}
mock_read_oneline.side_effect = mod_args_generator(values)
self.iface._linkstate = None
assert_equals(self.iface.linkstate, 2)
# port is dormant
values = {
'/sys/class/net/eth1/carrier': '1',
'/sys/class/net/eth1/operstate': 'dormant'
}
mock_read_oneline.side_effect = mod_args_generator(values)
self.iface._linkstate = None
assert_equals(self.iface.linkstate, 3)
示例3: test_stp_state
def test_stp_state(self, mock_read_from_sys, mock_exists, mock_subints):
# test if iface is in stp bridge
values = {
'/sys/class/net/eth1/brport/bridge/bridge/stp_state': True
}
values2 = {
'brport/bridge/bridge/stp_state': '2'
}
mock_exists.side_effect = mod_args_generator(values)
mock_read_from_sys.side_effect = mod_args_generator(values2)
_output = self.iface.stp_state()
assert_equals(_output, '2')
# test if subint is in stp bridge
# assumption here is that only one type of stp bridge is running. either its
# kernel or mstpd. even though in reality both I believe can coexist.
values = {
'/sys/class/net/eth1/brport/bridge/bridge/stp_state': False,
'/sys/class/net/eth1.100/brport/bridge/bridge/stp_state': True
}
values2 = {
'brport/bridge/bridge/stp_state': '2'
}
mock_exists.side_effect = mod_args_generator(values)
mock_read_from_sys.side_effect = mod_args_generator(values2)
mock_subints.return_value = ['eth1.100', 'eth1.101', 'eth1.110']
_output = self.iface.stp_state()
assert_equals(_output, '2')
示例4: test_bondstate
def test_bondstate(self, mock_read_from_sys):
values = {"carrier": "0", "operstate": "down", "bonding/mode": "active-backup 2"}
mock_read_from_sys.side_effect = mod_args_generator(values)
# mock_read_from_sys.return_value = 'active-backup 2'
# if lacp is not set and linkstate is not up
assert_equals(self.iface.bondstate, 0)
# if lacp is not set and linkstate is up
values = {"carrier": "1", "operstate": "up", "bonding/mode": "active-backup 2"}
mock_read_from_sys.side_effect = mod_args_generator(values)
assert_equals(self.iface.bondstate, 1)
# if lacp is set and agg_id is same
values = {"carrier": "1", "operstate": "up", "bonding/mode": "802.3ad 4"}
mock_read_from_sys.side_effect = mod_args_generator(values)
bondingfile = io.open("tests/test_netshowlib/proc_net_bonding_agg_id_match.txt")
with mock.patch("io.open") as mock_open:
mock_open.return_value = bondingfile
assert_equals(self.iface.bondstate, 1)
# if lacp is set and agg_id is different
bondingfile = io.open("tests/test_netshowlib/proc_net_bonding_agg_id_no_match.txt")
with mock.patch("io.open") as mock_open:
mock_open.return_value = bondingfile
assert_equals(self.iface.bondstate, 0)
示例5: test_vlan_filtering
def test_vlan_filtering(self, mock_read_from_sys):
values = {('bridge/vlan_filtering', 'br0'): '1'}
mock_read_from_sys.side_effect = mod_args_generator(values)
assert_equals(self.iface.vlan_filtering, 1)
values = {('bridge/vlan_filtering', 'br0'): None}
mock_read_from_sys.side_effect = mod_args_generator(values)
assert_equals(self.iface.vlan_filtering, 0)
示例6: test_stp_details
def test_stp_details(self, mock_read_from_sys, mock_exec,
mock_os_listdir):
mock_exec.return_value = io.open(
'tests/test_netshowlib/mstpctl_showall').read()
values = {('bridge/vlan_filtering', 'br1'): None,
('bridge/stp_state', 'br1', True): '2'}
mock_read_from_sys.side_effect = mod_args_generator(values)
values4 = {
('/sys/class/net/br1/brif',): ['swp3.1', 'swp4.1']
}
mock_os_listdir.side_effect = mod_args_generator(values4)
_output = self.piface.stp_details()
assert_equals(re.split(r'\s{3,}', _output.split('\n')[2]),
['stp_mode:', 'RSTP / per vlan instance'])
assert_equals(re.split(r'\s{3,}', _output.split('\n')[3]),
['root_port:', 'root_switch'])
assert_equals(re.split(r'\s{3,}', _output.split('\n')[4]),
['ports_in_designated_role: swp3-4'])
assert_equals(re.split(r'\s{3,}', _output.split('\n')[5]),
['ports_in_alternate_role:', 'none'])
assert_equals(re.split(r'\s{3,}', _output.split('\n')[6]),
['root_priority:', '32768'])
assert_equals(re.split(r'\s{3,}', _output.split('\n')[7]),
['bridge_priority:', '32768'])
assert_equals(re.split(r'\s{3,}', _output.split('\n')[8]),
['last_tcn:', 'swp4.1 (15 days, 20:34:24)'])
assert_equals(re.split(r'\s{3,}', _output.split('\n')[9]),
['802.1q_tag:', '1'])
示例7: test_stp_details
def test_stp_details(self, mock_read_sys, mock_listdir,
mock_file_oneline, mock_is_root):
mock_is_root.return_value = False
mock_listdir.return_value = ['eth1', 'eth2']
values1 = {
'bridge/stp_state': '1',
'bridge/root_id': '4000.fe54007e7eeb',
'bridge/bridge_id': '8000.fe54007e7111'}
values2 = {
'/sys/class/net/eth1/brport/state': '3',
'/sys/class/net/eth1/brport/bridge/bridge/root_port': '1',
'/sys/class/net/eth1/brport/port_id': '1',
'/sys/class/net/eth2/brport/state': '0',
'/sys/class/net/eth2/brport/bridge/bridge/stp_state': '1',
'/sys/class/net/eth2/brport/bridge/bridge/root_port': '1',
'/sys/class/net/eth2/brport/port_id': '2',
}
mock_read_sys.side_effect = mod_args_generator(values1)
mock_file_oneline.side_effect = mod_args_generator(values2)
_output = self.piface.stp_details()
_outputtable = _output.split('\n')
assert_equals(re.split(r'\s{2,}', _outputtable[2]),
['stp_mode:', '802.1d / per bridge instance'])
assert_equals(_outputtable[3].split(),
['root_port:', 'eth1'])
assert_equals(_outputtable[4].split(),
['root_priority:', '16384'])
assert_equals(_outputtable[5].split(), ['bridge_priority:', '32768'])
assert_equals(_outputtable[6].split(), ['802.1q_tag', 'untagged'])
示例8: test_bondmem_details
def test_bondmem_details(self, mock_read_from_sys, mock_file_oneline,
mock_lldp):
values1 = {'carrier': '1', 'operstate': 'up',
'bonding/mode': '802.3ad 4',
'bonding/slaves': 'eth22 eth23',
'bonding/xmit_hash_policy': 'layer3+4 1',
'bonding/min_links': '2'}
values2 = {'/sys/class/net/bond0/bonding/ad_sys_priority': '65535',
'/sys/class/net/bond0/bonding/lacp_rate': 'slow 0'}
values = [{'adj_port': 'eth2',
'adj_hostname': 'switch1'},
{'adj_port': 'eth10',
'adj_hostname': 'switch2'}]
mock_lldp.return_value = values
mock_read_from_sys.side_effect = mod_args_generator(values1)
mock_file_oneline.side_effect = mod_args_generator(values2)
_output = self.piface.bondmem_details()
_outputtable = _output.split('\n')
assert_equals(len(_outputtable), 13)
assert_equals(_outputtable[0].split(r'\s{3,}'), ['bond_details'])
assert_equals(re.split(r'\s{3,}', _outputtable[2]), ['master_bond:', 'bond0'])
assert_equals(re.split(r'\s{3,}', _outputtable[3]), ['state_in_bond:',
'port_not_in_bond'])
assert_equals(re.split(r'\s{3,}', _outputtable[4]), ['link_failures:', '0'])
assert_equals(re.split(r'\s{3,}', _outputtable[5]), ['bond_members:',
'eth22, eth23'])
assert_equals(re.split(r'\s{3,}', _outputtable[6]), ['bond_mode:', 'lacp'])
assert_equals(re.split(r'\s{3,}', _outputtable[7]), ['load_balancing:',
'layer3+4'])
assert_equals(re.split(r'\s{3,}', _outputtable[8]), ['minimum_links:', '2'])
assert_equals(re.split(r'\s{2,}', _outputtable[9]),
['lacp_sys_priority:', '65535'])
assert_equals(re.split(r'\s{3,}', _outputtable[10]), ['lacp_rate:', 'slow_lacp'])
示例9: test_stp_summary
def test_stp_summary(self, mock_is_root, mock_read_from_sys,
mock_listdir, mock_oneline):
# if stp is disabled
mock_read_from_sys.return_value = '0'
assert_equals(self.piface.stp_summary().split(), ['stp:', 'disabled'])
# if stp is root
values = {
'bridge/stp_state': '1',
'bridge/root_id': '4000.fe54007e7eeb',
'bridge/bridge_id': '4000.fe54007e7eeb'}
mock_read_from_sys.side_effect = mod_args_generator(values)
mock_is_root.return_value = True
assert_equals(self.piface.stp_summary().split(), ['stp:', 'rootswitch(16384)'])
# if stp is not root
values = {
'bridge/stp_state': '1',
'bridge/root_id': '4000.fe54007e7eeb',
'bridge/bridge_id': '8000.fe54007e7111'}
values2 = {
'/sys/class/net/eth1/brport/state': '3',
'/sys/class/net/eth1/brport/bridge/bridge/root_port': '1',
'/sys/class/net/eth1/brport/port_id': '1',
'/sys/class/net/eth2/brport/state': '0',
'/sys/class/net/eth2/brport/bridge/bridge/stp_state': '1',
'/sys/class/net/eth2/brport/bridge/bridge/root_port': '1',
'/sys/class/net/eth2/brport/port_id': '2',
}
mock_oneline.side_effect = mod_args_generator(values2)
mock_read_from_sys.side_effect = mod_args_generator(values)
mock_is_root.return_value = False
mock_listdir.return_value = ['eth1', 'eth2']
assert_equals(self.piface.stp_summary().split(),
['stp:', 'eth1(root)', '16384(root_priority)'])
示例10: test_iface_discovery
def test_iface_discovery(mock_import, mock_provider_check):
""" test iface discovery """
# provider_check is none
mock_provider_check.return_value = 'debian'
mock_debian_iface = MagicMock()
mock_debian_iface.iface.return_value = 'its a debian bridge'
values = {'netshowlib.debian.iface': mock_debian_iface}
mock_import.side_effect = mod_args_generator(values)
assert_equals(nn.iface('eth1'), 'its a debian bridge')
# if provider_check is not none
mock_debian_iface = MagicMock()
mock_debian_iface.iface.return_value = 'its a debian bridge'
values['netshowlib.debian.iface'] = mock_debian_iface
assert_equals(nn.iface('eth1', providername='debian'), 'its a debian bridge')
# if cache is set provider_check is none
mock_debian_iface.reset_mock()
mock_debian_iface = MagicMock()
mock_debian_iface.iface.return_value = 'its a debian bridge'
mock_debian_cache = MagicMock()
values = {'netshowlib.debian.iface': mock_debian_iface,
'netshowlib.debian.cache': mock_debian_cache}
mock_import.side_effect = mod_args_generator(values)
all_cache = nn.feature_cache()
assert_equals(nn.iface('eth1', cache=all_cache),
'its a debian bridge')
# confirm syntax for iface_type accepts cache
mock_debian_iface.iface.assert_called_with('eth1', cache=all_cache)
示例11: test_bridgemem_details_classic_driver
def test_bridgemem_details_classic_driver(self,
mock_stp_state,
mock_is_bridgemem,
mock_symlink,
mock_exec,
mock_listdir,
mock_file,
mock_read_oneline):
values4 = {('/sys/class/net',): ['swp3', 'swp3.1', 'swp3.2'],
('/sys/class/net/br0/brif',): ['swp3'],
('/sys/class/net/br1/brif',): ['swp3.1'],
('/sys/class/net/br2/brif',): ['swp3.2']
}
mock_is_bridgemem.return_value = True
mock_stp_state.return_value = '2'
mock_listdir.side_effect = mod_args_generator(values4)
mock_exec.return_value = io.open(
'tests/test_netshowlib/mstpctl_showall').read()
values = {('bridge/stp_state',): '2',
('brport/vlans',): None,
('/sys/class/net/swp3/brport/vlans',): None}
mock_read_oneline.side_effect = mod_args_generator(values)
values5 = {
('/sys/class/net/swp3/brport/bridge',): 'br0',
('/sys/class/net/swp3.1/brport/bridge',): 'br1',
('/sys/class/net/swp3.2/brport/bridge',): 'br2'
}
mock_symlink.side_effect = mod_args_generator(values5)
self.piface.iface = cumulus_bridge.BridgeMember('swp3')
_output = self.piface.bridgemem_details()
_outputtable = _output.split('\n')
示例12: test_cli_output
def test_cli_output(self, mock_read_from_sys, mock_exec,
mock_os_listdir):
values10 = {('/sbin/mstpctl showall',):
io.open('tests/test_netshowlib/mstpctl_showall').read()}
mock_exec.side_effect = mod_args_generator(values10)
values = {('bridge/vlan_filtering', 'br1'): None,
('bridge/stp_state', 'br1', True): '2',
('carrier', 'br1', True): '1',
('operstate', 'br1', True): 'up',
('address', 'br1', True): '11:22:33:44:55:66',
('speed', 'br1', True): '10000',
('ifalias', 'br1', True): None,
('operstate', 'br1', True): 'up',
('mtu', 'br1', True): '1500'}
mock_read_from_sys.side_effect = mod_args_generator(values)
values4 = {
('/sys/class/net/br1/brif',): ['swp3.1', 'swp4.1']
}
mock_os_listdir.side_effect = mod_args_generator(values4)
_output = self.piface.cli_output()
_outputtable = _output.split('\n')
# checks to make sure stp details is there
assert_equals(re.split(r'\s{3,}', _outputtable[10]),
['root_priority:', '32768'])
assert_equals(_outputtable[17], 'ports in Forwarding state')
assert_equals(_outputtable[19], 'swp3-4')
示例13: test_state_access_port
def test_state_access_port(self, mock_symlink, mock_os_path,
mock_oneline):
mock_subint = MagicMock()
self.iface.get_sub_interfaces = mock_subint
# bridgemember is access port
mock_subint = []
mock_symlink.return_value = 'br10'
values = {
'/sys/class/net/eth1/brport': True,
'/sys/class/net/eth1/brport/bridge/bridge/stp_state': '1'
}
values2 = {
'/sys/class/net/eth1/brport/state': '3',
'/sys/class/net/eth1/brport/bridge/bridge/root_port': 'aaa',
'/sys/class/net/eth1/brport/bridge/bridge/stp_state': '1',
'/sys/class/net/eth1/brport/port_id': 'aaa'
}
mock_oneline.side_effect = mod_args_generator(values2)
mock_os_path.side_effect = mod_args_generator(values)
briface = linux_bridge.Bridge('br10')
linux_bridge.BRIDGE_CACHE['br10'] = briface
assert_equals(self.stp.state, {
'disabled': [],
'blocking': [],
'forwarding': [briface],
'root': [briface],
'intransition': [],
'stp_disabled': []
})
示例14: test_bond_details
def test_bond_details(self, mock_read_from_sys, mock_file_oneline):
# with lacp
values1 = {'bonding/mode': '802.3ad 4',
'bonding/xmit_hash_policy': 'layer3+4 2',
'bonding/min_links': '2'}
values2 = {
'/sys/class/net/bond0/bonding/ad_sys_priority': '65535',
'/sys/class/net/bond0/bonding/lacp_rate': 'fast 1'
}
mock_read_from_sys.side_effect = mod_args_generator(values1)
mock_file_oneline.side_effect = mod_args_generator(values2)
_output = self.piface.bond_details()
_outputtable = _output.split('\n')
assert_equals(_outputtable[0], 'bond_details')
assert_equals(_outputtable[2].split(), ['bond_mode:', 'lacp'])
assert_equals(_outputtable[3].split(), ['load_balancing:', 'layer2+3'])
assert_equals(_outputtable[4].split(), ['minimum_links:', '2'])
assert_equals(_outputtable[5].split(), ['lacp_sys_priority:', '65535'])
assert_equals(_outputtable[6].split(), ['lacp_rate:', 'fast_lacp'])
assert_equals(len(_output.split('\n')), 9)
# without lacp
values1 = {'bonding/mode': 'something_else 2',
'bonding/xmit_hash_policy': 'layer3+4 2',
'bonding/min_links': '2'}
mock_read_from_sys.side_effect = mod_args_generator(values1)
_output = self.piface.bond_details()
assert_equals(len(_output.split('\n')), 7)
示例15: test_is_vlan_aware_bridge
def test_is_vlan_aware_bridge(self, mock_read_from_sys):
values = {('bridge/vlan_filtering', 'br1'): '1'}
mock_read_from_sys.side_effect = mod_args_generator(values)
assert_equals(self.piface.is_vlan_aware_bridge(), 'vlan_aware_bridge')
values = {('bridge/vlan_filtering', 'br1'): None}
mock_read_from_sys.side_effect = mod_args_generator(values)
assert_equals(self.piface.is_vlan_aware_bridge(), '')