def _check_device_size(self): self._messenger.info('Checking size of "%s"...' % self._abs_target_path) blockdev_output = self._executor.check_output([ COMMAND_BLOCKDEV, '--getsize64', self._abs_target_path, ]) size_bytes_found = int(blockdev_output) size_bytes_needed = self._distro.get_minimum_size_bytes() if size_bytes_found < size_bytes_needed: raise OSError(errno.ENOSPC, 'Device "%s" is %s in size, %s or more needed.' % ( self._abs_target_path, format_byte_size(size_bytes_found), format_byte_size(size_bytes_needed), ))
def test_some(self): for size_bytes, expected in ( (0, '0 byte'), (1, '1 byte'), (2, '2 byte'), (511, '511 byte'), (512, '0.5 KiB'), (513, '0.501 KiB'), (1023, '0.999 KiB'), (1024, '1 KiB'), (1025, '1.001 KiB'), (1024 * 1024 - 1, '1 MiB'), (1024 * 1024, '1 MiB'), (1024 * 1024 + 1, '1 MiB'), (1024**3, '1 GiB'), (1024**4, '1 TiB'), ): received = format_byte_size(size_bytes) self.assertEqual(received, expected)
def test_some(self): for size_bytes, expected in ( (0, '0 byte'), (1, '1 byte'), (2, '2 byte'), (511, '511 byte'), (512, '0.5 KiB'), (513, '0.501 KiB'), (1023, '0.999 KiB'), (1024, '1 KiB'), (1025, '1.001 KiB'), (1024 * 1024 - 1, '1 MiB'), (1024 * 1024, '1 MiB'), (1024 * 1024 + 1, '1 MiB'), (1024**3, '1 GiB'), (1024**4, '1 TiB'), ): received = format_byte_size(size_bytes) self.assertEquals(received, expected)