-
Notifications
You must be signed in to change notification settings - Fork 157
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
autoinstall: Don't use snap env when invoking early and late commands
- Loading branch information
1 parent
926bfeb
commit b482e23
Showing
4 changed files
with
103 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
# Copyright 2023 Canonical, Ltd. | ||
# | ||
# This program is free software: you can redistribute it and/or modify | ||
# it under the terms of the GNU Affero General Public License as | ||
# published by the Free Software Foundation, either version 3 of the | ||
# License, or (at your option) any later version. | ||
# | ||
# This program is distributed in the hope that it will be useful, | ||
# but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
# GNU Affero General Public License for more details. | ||
# | ||
# You should have received a copy of the GNU Affero General Public License | ||
# along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
|
||
from unittest import IsolatedAsyncioTestCase, mock | ||
|
||
from subiquity.server.controllers import cmdlist | ||
from subiquity.server.controllers.cmdlist import ( | ||
CmdListController, | ||
Command, | ||
EarlyController, | ||
LateController, | ||
) | ||
from subiquitycore.tests.mocks import make_app | ||
from subiquitycore.utils import orig_environ | ||
|
||
|
||
class TestCmdListController(IsolatedAsyncioTestCase): | ||
controller_type = CmdListController | ||
|
||
def setUp(self): | ||
self.controller = self.controller_type(make_app()) | ||
self.controller.cmds = [Command(args="some-command", check=False)] | ||
|
||
self.mocked_arun = mock.patch.object(cmdlist, "arun_command") | ||
self.mocked_orig_environ = mock.patch.object( | ||
cmdlist, "orig_environ", side_effect=orig_environ | ||
) | ||
snap_env_vars = { | ||
"LD_LIBRARY_PATH": "/var/lib/snapd/lib/gl", | ||
} | ||
self.mocked_os_environ = mock.patch.dict("os.environ", snap_env_vars) | ||
|
||
@mock.patch("shutil.which", return_value="/usr/bin/path/to/bin") | ||
async def test_no_snap_env_on_call(self, mocked_shutil): | ||
with self.mocked_arun as faked_process_call, self.mocked_os_environ, self.mocked_orig_environ as mocked_orig_environ: | ||
await self.controller.run() | ||
_, kwargs = faked_process_call.call_args | ||
call_env = kwargs["env"] | ||
|
||
mocked_orig_environ.assert_called() | ||
assert "LD_LIBRARY_PATH" not in call_env | ||
|
||
@mock.patch("shutil.which", return_value="/snap/path/to/bin") | ||
async def test_with_snap_env_on_call(self, mocked_shutil): | ||
with self.mocked_arun as faked_process_call, self.mocked_os_environ, self.mocked_orig_environ as mocked_orig_environ: | ||
await self.controller.run() | ||
_, kwargs = faked_process_call.call_args | ||
call_env = kwargs["env"] | ||
|
||
mocked_orig_environ.assert_not_called() | ||
assert "LD_LIBRARY_PATH" in call_env | ||
|
||
|
||
class TestEarlyController(TestCmdListController): | ||
controller_type = EarlyController | ||
|
||
def setUp(self): | ||
super().setUp() | ||
|
||
|
||
class TestLateController(TestCmdListController): | ||
controller_type = LateController | ||
|
||
def setUp(self): | ||
super().setUp() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters