def test_check():
    # Found cumulus OS
    # test with encoded string like in Python3 to ensure it gets decoded
    # properly
    values = {("/etc/lsb-release", "r"): open("tests/test_netshowlib/lsb-release.example")}
    with mock.patch(mock_open_str()) as mock_open:
        mock_open.side_effect = mod_args_generator(values)
        assert_equals(provider_discovery.check(), "cumulus")
def test_cacheinfo_ports_not_initialized(mock_exec):
    mock_exec.return_value = open(
        'tests/test_netshowlib/lspci_output.txt', 'rb').read()

    with mock.patch(mock_open_str()) as mock_open:
        mock_open.side_effect = IOError
        _output = asic.cacheinfo()
        assert_equals(_output,  {'name': 'broadcom', 'asicports': {}, 'kernelports': {}})
 def test_checking_if_dhcp_is_used(self):
     dhcpfile = open('tests/test_netshowlib/dhclient.eth0.leases')
     # some fancy mocking to bypass ip address checking
     self.iface._ip_address = mock.MagicMock()
     self.iface.ip_address.allentries = ['192.168.122.64/24']
     # -----
     with mock.patch(mock_open_str()) as mock_open:
         mock_open.return_value = dhcpfile
         assert_equals(self.iface.ip_addr_assign, 1)
 def test_checking_if_dhcp_is_used(self):
     dhcpfile = open('tests/test_netshowlib/dhclient.eth0.leases')
     # some fancy mocking to bypass ip address checking
     self.iface._ip_address = mock.MagicMock()
     self.iface.ip_address.allentries = ['192.168.122.64/24']
     # -----
     with mock.patch(mock_open_str()) as mock_open:
         mock_open.return_value = dhcpfile
         assert_equals(self.iface.ip_addr_assign, 1)
Esempio n. 5
0
def test_check():
    # Found cumulus OS
    # test with encoded string like in Python3 to ensure it gets decoded
    # properly
    values = {
        ('/etc/lsb-release', 'r'):
        open('tests/test_netshowlib/lsb-release.example')
    }
    with mock.patch(mock_open_str()) as mock_open:
        mock_open.side_effect = mod_args_generator(values)
        assert_equals(provider_discovery.check(), 'cumulus')
Esempio n. 6
0
def test_cacheinfo_ports_not_initialized(mock_exec):
    mock_exec.return_value = open('tests/test_netshowlib/lspci_output.txt',
                                  'rb').read()

    with mock.patch(mock_open_str()) as mock_open:
        mock_open.side_effect = IOError
        _output = asic.cacheinfo()
        assert_equals(_output, {
            'name': 'broadcom',
            'asicports': {},
            'kernelports': {}
        })
    def test_bondmem_details(self, mock_symlink, mock_read_from_sys, mock_file_oneline,
                             mock_exec):
        values3 = {
            ('/sbin/ethtool -S swp2',): io.open('tests/test_netshowlib/ethtool_swp.txt').read(),
            ('/sbin/ethtool -S swp3',): io.open('tests/test_netshowlib/ethtool_swp.txt').read(),
            ('lspci -nn',): io.open('tests/test_netshowlib/lspci_output.txt', 'rb').read()
        }

        mock_exec.side_effect = mod_args_generator(values3)
        values10 = {
            ('/proc/net/bonding/bond0',): io.open('tests/test_netshow/proc_net_bonding.txt'),
            ('/var/lib/cumulus/porttab',): io.open('tests/test_netshowlib/xe_porttab'),
            ('/etc/bcm.d/config.bcm',): io.open('tests/test_netshowlib/config_xe.bcm')
        }

        values = {
        }
        values1 = {('carrier',): '1',
                   ('operstate',): 'up',
                   ('speed',): '1000',
                   ('bonding/mode',): '802.3ad 4',
                   ('bonding/slaves',): 'swp2 swp3',
                   ('bonding/xmit_hash_policy',): 'layer3+4 1',
                   ('bonding/min_links',): '2',
                   ('ifalias',): None}
        values2 = {'/sys/class/net/bond0/bonding/ad_sys_priority': '65535',
                   '/sys/class/net/bond0/bonding/lacp_rate': 'slow 0'}
        values5 = {('master',): 'bond0'}
        mock_symlink.side_effect = mod_args_generator(values5)
        mock_read_from_sys.side_effect = mod_args_generator(values1)
        mock_file_oneline.side_effect = mod_args_generator(values2)

        with mock.patch(mock_open_str()) as mock_open:
            with mock.patch('io.open') as mock_open2:
                mock_open2.side_effect = mod_args_generator(values10)
                mock_open.side_effect = mod_args_generator(values)
                _output = self.piface.bondmem_details()
                outputtable = _output.split('\n')
                assert_equals(outputtable[0].split(),
                              ['port', 'speed', 'tx', 'rx', 'err',
                               'link_failures'])
                assert_equals(outputtable[2].split(),
                              ['up', 'swp2(P)', '1G(sfp)', '1500',
                               '600', '30', '11'])
                assert_equals(outputtable[3].split(),
                              ['up', 'swp3(N)', '1G', '1500', '600', '30', '0'])
 def test_if_dhcp_file_is_empty(self):
     touch('/tmp/empty_file')
     dhcpfile = open('/tmp/empty_file')
     with mock.patch(mock_open_str()) as mock_open:
         mock_open.return_value = dhcpfile
         assert_equals(self.iface.ip_addr_assign, 0)
 def test_if_dhcp_file_is_empty(self):
     touch('/tmp/empty_file')
     dhcpfile = open('/tmp/empty_file')
     with mock.patch(mock_open_str()) as mock_open:
         mock_open.return_value = dhcpfile
         assert_equals(self.iface.ip_addr_assign, 0)