Skip to content

Commit

Permalink
Revert "Merge pull request canonical#1811 from Chris-Peterson444/lp-2…
Browse files Browse the repository at this point in the history
…032961-clean-environment-commands"

This reverts commit 85af88e, reversing
changes made to 143d8e3.
  • Loading branch information
Chris-Peterson444 committed Oct 25, 2023
1 parent a6708aa commit e49c99d
Show file tree
Hide file tree
Showing 8 changed files with 19 additions and 109 deletions.
12 changes: 1 addition & 11 deletions subiquity/server/controllers/cmdlist.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
import asyncio
import os
import shlex
import shutil
from typing import List, Sequence, Union

import attr
Expand All @@ -26,7 +25,7 @@
from subiquity.server.controller import NonInteractiveController
from subiquitycore.async_helpers import run_bg_task
from subiquitycore.context import with_context
from subiquitycore.utils import arun_command, orig_environ
from subiquitycore.utils import arun_command


@attr.s(auto_attribs=True)
Expand Down Expand Up @@ -79,15 +78,6 @@ async def run(self, context):
env = self.env()
for i, cmd in enumerate(tuple(self.builtin_cmds) + tuple(self.cmds)):
desc = cmd.desc()

# If the path to the command isn't found on the snap we should
# drop the snap specific environment variables.
command = shlex.split(desc)[0]
path = shutil.which(command)
if path is not None:
if not path.startswith("/snap"):
env = orig_environ(env)

with context.child("command_{}".format(i), desc):
args = cmd.as_args_list()
if self.syslog_id:
Expand Down
84 changes: 0 additions & 84 deletions subiquity/server/controllers/tests/test_cmdlist.py

This file was deleted.

4 changes: 4 additions & 0 deletions subiquity/server/controllers/tests/test_filesystem.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,8 @@ def setUp(self):
self.app = make_app()
self.app.opts.bootloader = "UEFI"
self.app.command_runner = mock.AsyncMock()
self.app.report_start_event = mock.Mock()
self.app.report_finish_event = mock.Mock()
self.app.prober = mock.Mock()
self.app.prober.get_storage = mock.AsyncMock()
self.app.block_log_dir = "/inexistent"
Expand Down Expand Up @@ -1205,6 +1207,8 @@ def setUp(self):
self.app = make_app()
self.app.command_runner = mock.AsyncMock()
self.app.opts.bootloader = "UEFI"
self.app.report_start_event = mock.Mock()
self.app.report_finish_event = mock.Mock()
self.app.prober = mock.Mock()
self.app.prober.get_storage = mock.AsyncMock()
self.app.snapdapi = snapdapi.make_api_client(AsyncSnapd(get_fake_connection()))
Expand Down
4 changes: 4 additions & 0 deletions subiquity/server/controllers/tests/test_install.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ def setUp(self):
self.controller = InstallController(make_app())
self.controller.write_config = unittest.mock.Mock()
self.controller.app.note_file_for_apport = Mock()
self.controller.app.report_start_event = Mock()
self.controller.app.report_finish_event = Mock()

self.controller.model.target = "/target"

Expand Down Expand Up @@ -197,6 +199,8 @@ def test_generic_config(self):
class TestInstallController(unittest.IsolatedAsyncioTestCase):
def setUp(self):
self.controller = InstallController(make_app())
self.controller.app.report_start_event = Mock()
self.controller.app.report_finish_event = Mock()
self.controller.model.target = tempfile.mkdtemp()
os.makedirs(os.path.join(self.controller.model.target, "etc/grub.d"))
self.addCleanup(shutil.rmtree, self.controller.model.target)
Expand Down
2 changes: 2 additions & 0 deletions subiquity/server/controllers/tests/test_refresh.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@
class TestRefreshController(SubiTestCase):
def setUp(self):
self.app = make_app()
self.app.report_start_event = mock.Mock()
self.app.report_finish_event = mock.Mock()
self.app.note_data_for_apport = mock.Mock()
self.app.prober = mock.Mock()
self.app.snapdapi = snapdapi.make_api_client(AsyncSnapd(get_fake_connection()))
Expand Down
4 changes: 3 additions & 1 deletion subiquity/server/controllers/tests/test_snaplist.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>.

import unittest
from unittest.mock import AsyncMock
from unittest.mock import AsyncMock, Mock

import requests

Expand All @@ -31,6 +31,8 @@ def setUp(self):
self.model = SnapListModel()
self.app = make_app()
self.app.snapd = AsyncMock()
self.app.report_start_event = Mock()
self.app.report_finish_event = Mock()

self.loader = SnapdSnapInfoLoader(
self.model, self.app.snapd, "server", self.app.context
Expand Down
5 changes: 0 additions & 5 deletions subiquitycore/tests/mocks.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,4 @@ def make_app(model=None):
app.opts = mock.Mock()
app.opts.dry_run = True
app.scale_factor = 1000
app.echo_syslog_id = None
app.log_syslog_id = None
app.report_start_event = mock.Mock()
app.report_finish_event = mock.Mock()

return app
13 changes: 5 additions & 8 deletions subiquitycore/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
import os
import random
import subprocess
from typing import Any, Dict, List, Optional, Sequence
from typing import Any, Dict, List, Sequence

log = logging.getLogger("subiquitycore.utils")

Expand All @@ -35,18 +35,15 @@ def _clean_env(env, *, locale=True):
return env


def orig_environ(env: Optional[Dict[str, str]]) -> Dict[str, str]:
def orig_environ(env):
"""Generate an environment dict that is suitable for use for running
programs that live outside the snap."""

if env is None:
env: Dict[str, str] = os.environ

ret: Dict[str, str] = env.copy()

env = os.environ
ret = env.copy()
for key, val in env.items():
if key.endswith("_ORIG"):
key_to_restore: str = key[: -len("_ORIG")]
key_to_restore = key[: -len("_ORIG")]
if val:
ret[key_to_restore] = val
else:
Expand Down

0 comments on commit e49c99d

Please sign in to comment.