Exemple #1
0
    def test_parse_simple_kv(self, exec_mock):
        exec_mock.return_value = [
            """driver: r8169
version: 2.3LK-NAPI
firmware-version: rtl_nic/rtl8168e-2.fw
bus-info: 0000:06:00.0
supports-statistics: yes
supports-test: no
supports-eeprom-access: no
supports-register-dump: yes

"""
        ]

        expected = {
            'driver': 'r8169',
            'version': '2.3LK-NAPI',
            'firmware-version': 'rtl_nic/rtl8168e-2.fw',
            'bus-info': '0000:06:00.0',
            'supports-statistics': 'yes',
            'supports-test': 'no',
            'supports-eeprom-access': 'no',
            'supports-register-dump': 'yes'
        }

        self.assertEqual(expected, hu.parse_simple_kv('fake', 'cmd'))
        exec_mock.assert_called_once_with('fake', 'cmd')
Exemple #2
0
def shrink_sparse_file(filename):
    """Shrinks file to its size of actual data. Only ext fs are supported."""
    utils.execute('e2fsck', '-y', '-f', filename)
    utils.execute('resize2fs', '-M', filename)
    data = hu.parse_simple_kv('dumpe2fs', filename)
    block_count = int(data['block count'])
    block_size = int(data['block size'])
    with open(filename, 'rwb+') as f:
        f.truncate(block_count * block_size)
Exemple #3
0
def shrink_sparse_file(filename):
    """Shrinks file to its size of actual data. Only ext fs are supported."""
    utils.execute('e2fsck', '-y', '-f', filename)
    utils.execute('resize2fs', '-M', filename)
    data = hu.parse_simple_kv('dumpe2fs', filename)
    block_count = int(data['block count'])
    block_size = int(data['block size'])
    with open(filename, 'rwb+') as f:
        f.truncate(block_count * block_size)
    def test_parse_simple_kv(self, exec_mock):
        exec_mock.return_value = ["""driver: r8169
version: 2.3LK-NAPI
firmware-version: rtl_nic/rtl8168e-2.fw
bus-info: 0000:06:00.0
supports-statistics: yes
supports-test: no
supports-eeprom-access: no
supports-register-dump: yes

"""]

        expected = {'driver': 'r8169',
                    'version': '2.3LK-NAPI',
                    'firmware-version': 'rtl_nic/rtl8168e-2.fw',
                    'bus-info': '0000:06:00.0',
                    'supports-statistics': 'yes',
                    'supports-test': 'no',
                    'supports-eeprom-access': 'no',
                    'supports-register-dump': 'yes'}

        self.assertEqual(expected, hu.parse_simple_kv('fake', 'cmd'))
        exec_mock.assert_called_once_with('fake', 'cmd')