Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[NEX-14264] Download file to /opt dir in TiberOS #584

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions inbm-lib/inbm_lib/path_prefixes.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
INTEL_MANAGEABILITY_CACHE_PATH_PREFIX = INBM_PATH / 'cache'
INTEL_MANAGEABILITY_BINARY_SEARCH_PATHS = [
C_COLON / 'Windows' / 'System32' / 'wbem'] # wmic tool
INTEL_MANAGEABILITY_OPT = INBM_PATH / 'opt'
LOG_PATH = INTEL_MANAGEABILITY_VAR_PATH_PREFIX / 'log'
else:
ROOT = Path('/')
Expand All @@ -32,4 +33,5 @@
ROOT / 'usr' / 'sbin',
ROOT / 'usr' / 'bin',
ROOT / 'sbin']
INTEL_MANAGEABILITY_OPT = ROOT / 'opt'
LOG_PATH = ROOT / 'var' / 'log'
2 changes: 2 additions & 0 deletions inbm/Changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/).

## NEXT - YYYY-MM-DD
### Changed
- (NEX-14264) Download file to /opt directory in TiberOS

## 4.2.6.1 - 2024-10-18
### Added
Expand Down
4 changes: 3 additions & 1 deletion inbm/dispatcher-agent/dispatcher/sota/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
SPDX-License-Identifier: Apache-2.0
"""

from inbm_lib.path_prefixes import INTEL_MANAGEABILITY_CACHE_PATH_PREFIX
from inbm_lib.path_prefixes import INTEL_MANAGEABILITY_CACHE_PATH_PREFIX, INTEL_MANAGEABILITY_OPT
from inbm_common_lib.utility import get_canonical_representation_of_path

# Mender file path
Expand All @@ -32,6 +32,8 @@
# Device local cache for SOTA
SOTA_CACHE = str(INTEL_MANAGEABILITY_CACHE_PATH_PREFIX / 'repository-tool' / 'sota')

# Download folder for SOTA in TiberOS
SOTA_OPT_PATH = str(INTEL_MANAGEABILITY_OPT/ 'sota')

FAILED = "Failed"
SUCCESS = "Success"
Expand Down
4 changes: 2 additions & 2 deletions inbm/dispatcher-agent/dispatcher/sota/os_updater.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
from inbm_lib.constants import DOCKER_CHROOT_PREFIX, CHROOT_PREFIX

from .command_list import CommandList
from .constants import MENDER_FILE_PATH, SOTA_CACHE
from .constants import MENDER_FILE_PATH, SOTA_OPT_PATH
from .converter import size_to_bytes
from .sota_error import SotaError
from ..common import uri_utilities
Expand Down Expand Up @@ -436,7 +436,7 @@ def download_only(self) -> list[str]:
parsed_uri = urlparse(self._uri)
filename = os.path.basename(parsed_uri.path)
if filename:
file_path = os.path.join(SOTA_CACHE, filename)
file_path = os.path.join(SOTA_OPT_PATH, filename)

cmds = [update_tool_write_command(self._signature, file_path)]
return CommandList(cmds).cmd_list
44 changes: 31 additions & 13 deletions inbm/dispatcher-agent/dispatcher/sota/sota.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@

from dispatcher.dispatcher_exception import DispatcherException
from .command_handler import run_commands, print_execution_summary, get_command_status
from .constants import SUCCESS, SOTA_STATE, SOTA_CACHE, PROCEED_WITHOUT_ROLLBACK_DEFAULT
from .constants import SUCCESS, SOTA_STATE, SOTA_CACHE, PROCEED_WITHOUT_ROLLBACK_DEFAULT, SOTA_OPT_PATH
from .downloader import Downloader
from .log_helper import get_log_destination
from .os_factory import ISotaOs, SotaOsFactory
Expand Down Expand Up @@ -223,18 +223,36 @@ def execute(self, proceed_without_rollback: bool, skip_sleeps: bool = False) ->
if self.sota_cmd is None:
raise SotaError('sota_cmd is None')
release_date = self._parsed_manifest['release_date']
if not os.path.exists(SOTA_CACHE):
try:
os.mkdir(SOTA_CACHE)
except OSError as e:
logger.debug(f"SOTA cache directory {SOTA_CACHE} cannot be created: {e}")
raise SotaError("SOTA cache directory cannot be created") from e
elif not os.path.isdir(SOTA_CACHE):
logger.debug(
f"SOTA cache directory {SOTA_CACHE} already exists and is not a directory")
raise SotaError(
"SOTA cache directory already exists and is not a directory")
sota_cache_repo = DirectoryRepo(SOTA_CACHE)

# In TiberOS, we use different path to download the file
# TODO: Remove Mariner when confirmed that TiberOS is in use
os_type = detect_os()
if os_type == LinuxDistType.tiber.name or os_type == LinuxDistType.Mariner.name:
if not os.path.exists(SOTA_OPT_PATH):
try:
os.mkdir(SOTA_OPT_PATH)
except OSError as e:
logger.debug(f"SOTA cache directory {SOTA_OPT_PATH} cannot be created: {e}")
raise SotaError("SOTA cache directory cannot be created") from e
elif not os.path.isdir(SOTA_OPT_PATH):
logger.debug(
f"SOTA cache directory {SOTA_OPT_PATH} already exists and is not a directory")
raise SotaError(
"SOTA cache directory already exists and is not a directory")
sota_cache_repo = DirectoryRepo(SOTA_OPT_PATH)
else:
if not os.path.exists(SOTA_CACHE):
try:
os.mkdir(SOTA_CACHE)
except OSError as e:
logger.debug(f"SOTA cache directory {SOTA_CACHE} cannot be created: {e}")
raise SotaError("SOTA cache directory cannot be created") from e
elif not os.path.isdir(SOTA_CACHE):
logger.debug(
f"SOTA cache directory {SOTA_CACHE} already exists and is not a directory")
raise SotaError(
"SOTA cache directory already exists and is not a directory")
sota_cache_repo = DirectoryRepo(SOTA_CACHE)

time_to_wait_before_reboot = 2 if not skip_sleeps else 0

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@
/etc/task_list.yaml r,
/etc/trtl.conf w,
/opt/afulnx/afulnx_64 rUx,
/opt/sota rw,
/usr/bin/afulnx_64 rUx,
/proc/1/comm r,
/proc/device-tree/firmware/bios/** r,
Expand Down
3 changes: 2 additions & 1 deletion inbm/dispatcher-agent/tests/unit/sota/test_sota.py
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,8 @@ def test_run_raises(self, mock_reboot, mock_rollback_and_delete_snap, mock_print
@patch("dispatcher.sota.sota.print_execution_summary")
@patch("dispatcher.sota.snapshot.DebianBasedSnapshot._rollback_and_delete_snap")
@patch('inbm_common_lib.shell_runner.PseudoShellRunner.run', return_value=('200', "", 0))
def test_run_pass(self, mock_run, mock_rollback_and_delete_snap, mock_print,
@patch("dispatcher.sota.sota.detect_os", return_value='Ubuntu')
def test_run_pass(self, mock_os, mock_run, mock_rollback_and_delete_snap, mock_print,
mock_detect_os) -> None:
mock_detect_os.return_value = 'Ubuntu'
parsed_manifest = {'log_to_file': 'Y', 'sota_cmd': 'update',
Expand Down
Loading