Skip to content

Commit

Permalink
storage/lvm: force default locale for lvm command cont.
Browse files Browse the repository at this point in the history
Few more places where lvm commands are called.

Fixes QubesOS/qubes-issues#3753
  • Loading branch information
marmarek committed Mar 29, 2018
1 parent faca898 commit 2c13ba9
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
4 changes: 3 additions & 1 deletion qubes/storage/lvm.py
Expand Up @@ -170,8 +170,10 @@ def init_cache(log=logging.getLogger('qubes.storage.lvm')):
'--units', 'b', '--separator', ';']
if os.getuid() != 0:
cmd.insert(0, 'sudo')
environ = os.environ.copy()
environ['LC_ALL'] = 'C.utf8'
p = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE,
close_fds=True)
close_fds=True, env=environ)
out, err = p.communicate()
return_code = p.returncode
if return_code == 0 and err:
Expand Down
10 changes: 8 additions & 2 deletions qubes/tests/storage_lvm.py
Expand Up @@ -164,17 +164,23 @@ def test_003_read_write_volume(self):
def test_004_size(self):
with self.assertNotRaises(NotImplementedError):
size = self.pool.size
environ = os.environ.copy()
environ['LC_ALL'] = 'C.utf8'
pool_size = subprocess.check_output(['sudo', 'lvs', '--noheadings',
'-o', 'lv_size',
'--units', 'b', self.pool.volume_group + '/' + self.pool.thin_pool])
'--units', 'b', self.pool.volume_group + '/' + self.pool.thin_pool],
env=environ)
self.assertEqual(size, int(pool_size.strip()[:-1]))

def test_005_usage(self):
with self.assertNotRaises(NotImplementedError):
usage = self.pool.usage
environ = os.environ.copy()
environ['LC_ALL'] = 'C.utf8'
pool_info = subprocess.check_output(['sudo', 'lvs', '--noheadings',
'-o', 'lv_size,data_percent',
'--units', 'b', self.pool.volume_group + '/' + self.pool.thin_pool])
'--units', 'b', self.pool.volume_group + '/' + self.pool.thin_pool],
env=environ)
pool_size, pool_usage = pool_info.strip().split()
pool_size = int(pool_size[:-1])
pool_usage = float(pool_usage)
Expand Down

0 comments on commit 2c13ba9

Please sign in to comment.