def alternate_ports(self): if self.iface.stp: portlist = self.iface.stp.member_state.get('alternate') portnames = [x.name for x in portlist] if portlist: return linux_common.group_ports(portnames) return [_('none')]
def alternate_ports(self): if self.iface.stp: portlist = self.iface.stp.member_state.get("alternate") portnames = [x.name for x in portlist] if portlist: return linux_common.group_ports(portnames) return [_("none")]
def print_list_in_chunks(self, listofstuff, _title, _result, place_in_list=False, break_into_list=False, shorten_to=4): """ take a long array of bridge names and break it up into smaller groups of arrays based on shorten_to variable Reference: http://stackoverflow.com/questions/312443/how-do-you-split-a-list-into-evenly-sized-chunks-in-python Args: listofstuff (list): list of things that in are in a long list that you want to break up into chunks _title (str): heading of the list of stuff you want cut up in chunks _result (list): The list where the chunks will be stored. place_in_list (boolean): Some data needs to be returned as a list in a list. Others do not. Setting to this true means that you want the _result returned to be a list of list Example ['1.1.1.1/24'] becomes ["ip: 1.1.1.1/24"] Default: False break_into_list (boolean): When printing detailed IP info, print out each entry as a list. for example [1.1.1.1/24] becomes ["ip:", "1.1.1.1/24"] Default: False shorten_to (int): How many elements are to be placed in each chunk. Default: 4 """ if listofstuff: listofstuff = sorted(common.group_ports(listofstuff)) listofstuff = [ listofstuff[_x:_x + shorten_to] for _x in range(0, len(listofstuff), shorten_to) ] for _idx, _arrlist in enumerate(listofstuff): joined_arrlist = ', '.join(_arrlist) if _idx == 0 and _title: if break_into_list: entry = [_title + ':', joined_arrlist] else: entry = _title + ': ' + joined_arrlist if place_in_list: arr_entry = [entry] else: arr_entry = entry _result.append(arr_entry) else: if break_into_list: entry = ['', joined_arrlist] else: entry = ' ' + joined_arrlist if place_in_list: arr_entry = [entry] else: arr_entry = entry _result.append(arr_entry)
def test_group_port_with_subiface(): a = ['swp1', 'swp2', 'swp3', 'swp4', 'bond0.100', 'bond1.100', 'bond3.100', 'swp33.100', 'swp34.100', 'swp40.100', 'swp10', 'swp11', 'swp12', 'swp20'] assert_equals(common.group_ports(a), ['bond0-1.100', 'bond3.100', 'swp33-34.100', 'swp40.100', 'swp1-4', 'swp10-12', 'swp20'])
def update_vlan_aware_bridge_config(self): """ runs function to add/remove vlan from bridge vlan list then sends appropriate module and module arguments to ansible to make the config change """ self.update_bridge_vlan_list() modname = 'cl_bridge' modargs_str = 'name=%s ports=%s vids=%s' % ( self.vlan_aware_bridge.name, ','.join(group_ports(self.bridge_ports)), ','.join(self.bridge_vids)) return update_config_via_ansible(modname, modargs_str)
def test_get_vlan_list(self, mock_symlink, mock_os_path, mock_oneline, mock_os_listdir): mock_subint = MagicMock() mock_subint.return_value = ['eth1.11', 'eth1.20', 'eth1.30'] self.iface.get_sub_interfaces = mock_subint # bridgemember is trunk port values = { '/sys/class/net/eth1/brport': True, '/sys/class/net/eth1.11/brport': True, '/sys/class/net/eth1.20/brport': False, '/sys/class/net/eth1.30/brport': True, } values2 = { '/sys/class/net/eth1/brport/state': '3', '/sys/class/net/eth1/brport/bridge/bridge/root_port': 'aaa', '/sys/class/net/eth1/brport/port_id': 'aaa', '/sys/class/net/eth1.11/brport/state': '0', '/sys/class/net/eth1.11/brport/bridge/bridge/stp_state': '1', '/sys/class/net/eth1.11/brport/bridge/bridge/root_port': 'aaa', '/sys/class/net/eth1.11/brport/port_id': 'aaa', '/sys/class/net/eth1.30/brport/state': '0', '/sys/class/net/eth1.30/brport/bridge/bridge/stp_state': '0' } values3 = { '/sys/class/net/eth1/brport/bridge': 'br10', '/sys/class/net/eth1.11/brport/bridge': 'br11', '/sys/class/net/eth1.20/brport/bridge': None, '/sys/class/net/eth1.30/brport/bridge': 'br30' } values4 = { '/sys/class/net/br30/brif': ['eth1.30'], '/sys/class/net/br11/brif': ['eth1.11'], '/sys/class/net/br10/brif': [] } mock_os_listdir.side_effect = mod_args_generator(values4) mock_symlink.side_effect = mod_args_generator(values3) mock_oneline.side_effect = mod_args_generator(values2) mock_os_path.side_effect = mod_args_generator(values) br10 = linux_bridge.Bridge('br10') br11 = linux_bridge.Bridge('br11') br30 = linux_bridge.Bridge('br30') linux_bridge.BRIDGE_CACHE['br10'] = br10 linux_bridge.BRIDGE_CACHE['br11'] = br11 linux_bridge.BRIDGE_CACHE['br30'] = br30 vlanlist = self.iface.vlan_list vlanlist = common.group_ports(vlanlist.keys()) assert_equals(vlanlist, ['br10-11', 'br30'])
def test_group_ports_where_one_does_not_have_number(): a = ['downlink', 'downlink2', 'swp1', 'swp2', 'swp3'] assert_equals(common.group_ports(a), ['downlink', 'downlink2', 'swp1-3'])
def test_group_port_no_subiface(): a = ['swp1', 'swp2', 'swp3', 'swp4', 'swp10', 'swp11', 'swp12', 'swp20'] assert_equals(common.group_ports(a), ['swp1-4', 'swp10-12', 'swp20'])