Exemplo n.º 1
0
    def test_get_vlan_list(self, mock_symlink, mock_os_path, mock_oneline,
                           mock_os_listdir):
        mock_subint = MagicMock()
        mock_subint.return_value = ['bond0.11', 'bond0.20', 'bond0.30']
        self.iface.get_sub_interfaces = mock_subint
        # bridgemember is trunk port
        values = {
            '/sys/class/net/bond0/brport': True,
            '/sys/class/net/bond0.11/brport': True,
            '/sys/class/net/bond0.20/brport': False,
            '/sys/class/net/bond0.30/brport': True,
        }
        values2 = {
            '/sys/class/net/bond0/brport/state': '3',
            '/sys/class/net/bond0/brport/bridge/bridge/root_port': 'aaa',
            '/sys/class/net/bond0/brport/port_id': 'aaa',
            '/sys/class/net/bond0.11/brport/state': '0',
            '/sys/class/net/bond0.11/brport/bridge/bridge/stp_state': '1',
            '/sys/class/net/bond0.11/brport/bridge/bridge/root_port': 'aaa',
            '/sys/class/net/bond0.11/brport/port_id': 'aaa',
            '/sys/class/net/bond0.30/brport/state': '0',
            '/sys/class/net/bond0.30/brport/bridge/bridge/stp_state': '0'
        }
        values3 = {
            '/sys/class/net/bond0/brport/bridge': 'br10',
            '/sys/class/net/bond0.11/brport/bridge': 'br11',
            '/sys/class/net/bond0.20/brport/bridge': None,
            '/sys/class/net/bond0.30/brport/bridge': 'br30'
        }
        values4 = {
            '/sys/class/net/br30/brif': ['bond0.30'],
            '/sys/class/net/br11/brif': ['bond0.11'],
            '/sys/class/net/br10/brif': ['bond0']
        }

        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
        assert_equals(vlanlist, {
            'br30': ['30'],
            'br10': ['0'],
            'br11': ['11']
        })
Exemplo n.º 2
0
 def test_state_trunk_port(self, mock_symlink, mock_os_path, mock_oneline):
     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/bridge/bridge/stp_state': True,
         '/sys/class/net/eth1.11/brport/bridge/bridge/stp_state': True,
         '/sys/class/net/eth1.20/brport/bridge/bridge/stp_state': True,
         '/sys/class/net/eth1.30/brport/bridge/bridge/stp_state': True,
         '/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/bridge/bridge/stp_state': '1',
         '/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'
     }
     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
     assert_equals(
         self.stp.state, {
             'disabled': [br11],
             'blocking': [],
             'forwarding': [br10],
             'root': [br10],
             'stp_disabled': [br30],
             'intransition': []
         })
    def test_trunk_summary(self, mock_symlink, mock_os_path, mock_oneline,
                           mock_os_listdir, mock_is_trunk):
        mock_is_trunk.return_value = True
        mock_subint = mock.MagicMock()
        mock_subint.return_value = ['eth22.11', 'eth22.20', 'eth22.30']
        self.piface.iface = linux_bridge.BridgeMember('eth22')
        self.piface.iface.get_sub_interfaces = mock_subint
        # bridgemember is trunk port
        values = {
            '/sys/class/net/eth22/brport': True,
            '/sys/class/net/eth22.11/brport': True,
            '/sys/class/net/eth22.20/brport': False,
            '/sys/class/net/eth22.30/brport': True,
        }
        values2 = {
            '/sys/class/net/eth22/brport/state': '3',
            '/sys/class/net/eth22/brport/bridge/bridge/root_port': 'aaa',
            '/sys/class/net/eth22/brport/port_id': 'aaa',
            '/sys/class/net/eth22.11/brport/state': '0',
            '/sys/class/net/eth22.11/brport/bridge/bridge/stp_state': '1',
            '/sys/class/net/eth22.11/brport/bridge/bridge/root_port': 'aaa',
            '/sys/class/net/eth22.11/brport/port_id': 'aaa',
            '/sys/class/net/eth22.30/brport/state': '0',
            '/sys/class/net/eth22.30/brport/bridge/bridge/stp_state': '0'
        }
        values3 = {
            '/sys/class/net/eth22/brport/bridge': 'br10',
            '/sys/class/net/eth22.11/brport/bridge': 'br11',
            '/sys/class/net/eth22.20/brport/bridge': None,
            '/sys/class/net/eth22.30/brport/bridge': 'br30'
        }
        values4 = {
            '/sys/class/net/br30/brif': ['eth22.30'],
            '/sys/class/net/br11/brif': ['eth22.11'],
            '/sys/class/net/br10/brif': ['eth22']
        }

        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
        _output = self.piface.trunk_summary()
        assert_equals(_output[1], 'tagged: br11(11), br30(30)')
        assert_equals(_output[2], 'untagged: br10')
Exemplo n.º 4
0
 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': []
         })
Exemplo n.º 5
0
 def test_get_bridge_masters(self, mock_symlink, mock_os_path,
                             mock_oneline):
     mock_subint = MagicMock()
     mock_subint.return_value = ['bond0.11', 'bond0.20', 'bond0.30']
     self.iface.get_sub_interfaces = mock_subint
     # bridgemember is trunk port
     values = {
         '/sys/class/net/bond0/brport': True,
         '/sys/class/net/bond0.11/brport': True,
         '/sys/class/net/bond0.20/brport': False,
         '/sys/class/net/bond0.30/brport': True,
     }
     values2 = {
         '/sys/class/net/bond0/brport/state': '3',
         '/sys/class/net/bond0/brport/bridge/bridge/root_port': 'aaa',
         '/sys/class/net/bond0/brport/port_id': 'aaa',
         '/sys/class/net/bond0.11/brport/state': '0',
         '/sys/class/net/bond0.11/brport/bridge/bridge/stp_state': '1',
         '/sys/class/net/bond0.11/brport/bridge/bridge/root_port': 'aaa',
         '/sys/class/net/bond0.11/brport/port_id': 'aaa',
         '/sys/class/net/bond0.30/brport/state': '0',
         '/sys/class/net/bond0.30/brport/bridge/bridge/stp_state': '0'
     }
     values3 = {
         '/sys/class/net/bond0/brport/bridge': 'br10',
         '/sys/class/net/bond0.11/brport/bridge': 'br11',
         '/sys/class/net/bond0.20/brport/bridge': None,
         '/sys/class/net/bond0.30/brport/bridge': 'br30'
     }
     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
     assert_equals(sorted(list(self.iface.bridge_masters.keys())),
                   ['br10', 'br11', 'br30'])
 def test_access_summary(self, mock_symlink, mock_os_path, mock_oneline):
     self.piface.iface = linux_bridge.BridgeMember('eth22')
     mock_subint = mock.MagicMock()
     mock_subint.return_value = []
     self.piface.iface.get_sub_interfaces = mock_subint
     # bridgemember is trunk port
     values = {
         '/sys/class/net/eth22/brport': True,
     }
     values2 = {
         '/sys/class/net/eth22/brport/state': '3',
     }
     values3 = {
         '/sys/class/net/eth22/brport/bridge': 'br10',
     }
     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')
     linux_bridge.BRIDGE_CACHE['br10'] = br10
     _output = self.piface.access_summary()
     # Untagged: br0
     assert_equals(_output, ['untagged: br10'])
 def test_bridgemem_details(self, mock_symlink, mock_os_path, mock_oneline,
                            mock_os_listdir):
     mock_subint = mock.MagicMock()
     mock_subint.return_value = [
         'eth22.11', 'eth22.20', 'eth22.40', 'eth22.30'
     ]
     self.piface.iface.get_sub_interfaces = mock_subint
     values22 = {
         '/sys/class/net/br10/brif': ['eth22', 'eth33', 'eth44'],
         '/sys/class/net/br30/brif': ['eth22.30', 'eth1.30', 'eth2'],
         '/sys/class/net/br11/brif': ['eth22.11', 'eth1.11', 'eth4'],
         '/sys/class/net/br40/brif': ['eth22.40', 'eth1.40', 'eth12']
     }
     mock_os_listdir.side_effect = mod_args_generator(values22)
     self.piface.iface.get_sub_interfaces = mock_subint
     # bridgemember is trunk port
     values = {
         '/sys/class/net/eth22/brport/bridge/bridge/stp_state': True,
         '/sys/class/net/eth22.11/brport/bridge/bridge/stp_state': True,
         '/sys/class/net/eth22.30/brport/bridge/bridge/stp_state': True,
         '/sys/class/net/eth22.40/brport/bridge/bridge/stp_state': True,
         '/sys/class/net/eth22/brport': True,
         '/sys/class/net/eth22.11/brport': True,
         '/sys/class/net/eth22.20/brport': False,
         '/sys/class/net/eth22.30/brport': True,
         '/sys/class/net/eth22.40/brport': True,
     }
     values2 = {
         '/sys/class/net/eth22/brport/state': '3',
         '/sys/class/net/eth22/brport/bridge/bridge/root_port': 'aaa',
         '/sys/class/net/eth22/brport/port_id': 'aaa',
         '/sys/class/net/eth22/brport/bridge/bridge/stp_state': '1',
         '/sys/class/net/eth22.11/brport/state': '4',
         '/sys/class/net/eth22.11/brport/bridge/bridge/stp_state': '1',
         '/sys/class/net/eth22.11/brport/bridge/bridge/root_port': 'aaa',
         '/sys/class/net/eth22.11/brport/port_id': '12',
         '/sys/class/net/eth22.30/brport/state': '0',
         '/sys/class/net/eth22.30/brport/bridge/bridge/stp_state': '0',
         '/sys/class/net/eth22.40/brport/bridge/bridge/root_port': 'aaa',
         '/sys/class/net/eth22.40/brport/state': '3',
         '/sys/class/net/eth22.40/brport/port_id': '10',
         '/sys/class/net/eth22.40/brport/bridge/bridge/stp_state': '1'
     }
     values3 = {
         '/sys/class/net/eth22/brport/bridge': 'br10',
         '/sys/class/net/eth22.11/brport/bridge': 'br11',
         '/sys/class/net/eth22.20/brport/bridge': None,
         '/sys/class/net/eth22.30/brport/bridge': 'br30',
         '/sys/class/net/eth22.40/brport/bridge': 'br40'
     }
     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
     _output = self.piface.bridgemem_details()
     _outputtable = _output.split('\n')
     assert_equals(_outputtable[0], 'vlans in Root state')
     assert_equals(_outputtable[2], 'br10')
     assert_equals(_outputtable[4], 'vlans in Forwarding state')
     assert_equals(_outputtable[6], 'br10, br40(40)')
     assert_equals(_outputtable[8], 'vlans in Blocking state')
     assert_equals(_outputtable[10], 'br11(11)')
     assert_equals(_outputtable[12], 'vlans in Stp Disabled state')
     assert_equals(_outputtable[14], 'br30(30)')
 def setup(self):
     iface = linux_bridge.Bridge('br0')
     self.piface = print_bridge.PrintBridge(iface)
Exemplo n.º 9
0
 def setup(self):
     """ setup function """
     self.iface = linux_bridge.Bridge('br0')
Exemplo n.º 10
0
 def setup(self):
     br0 = linux_bridge.Bridge('br0')
     self.stp = linux_bridge.KernelStpBridge(br0)