Override subprocess environment for dpkg

Whenever we subprocess out from the charm, it is most likely because
we are running tools provided by the payload to mange it.

We should take care to set an appropriate environment whenever there
is a chance for external python tools to be directly or indirectly
involved.

Change-Id: Icce4e4a8475b6ad3dc9bf60e59ff2a8ee60d9d1c
Closes-Bug: #1840257
This commit is contained in:
Frode Nordahl 2019-08-16 12:22:27 +02:00
parent 5503c63ffe
commit 88480fdae0
No known key found for this signature in database
GPG Key ID: 6A5D59A3BA48373F
2 changed files with 6 additions and 2 deletions

View File

@ -139,7 +139,8 @@ class OpenStackCharm(BaseOpenStackCharm,
"""
# No attempt is made to deal with dependancies. These should be
# handled by the charms 'packages' list.
subprocess.check_call(['dpkg', '-i', deb])
subprocess.check_call(['dpkg', '-i', deb],
env=fetch.get_apt_dpkg_env())
def install_resources(self):
"""Install Juju application resources

View File

@ -211,8 +211,11 @@ class TestOpenStackCharm(BaseOpenStackCharmTest):
def test_install_deb(self):
self.patch_object(chm.subprocess, 'check_call')
self.patch_object(chm.fetch, 'get_apt_dpkg_env', return_value={})
self.target.install_deb('mydeb')
self.check_call.assert_called_once_with(['dpkg', '-i', 'mydeb'])
self.check_call.assert_called_once_with(
['dpkg', '-i', 'mydeb'],
env={})
def test_install_resources(self):
self.patch_target('install_deb')