Skip to content

Commit

Permalink
consts: now not doing implicit dynamic root, instead providing the dy…
Browse files Browse the repository at this point in the history
…namic_root method
  • Loading branch information
Bodong-Yang committed Oct 11, 2024
1 parent 7f9853a commit 1cf975c
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 37 deletions.
3 changes: 2 additions & 1 deletion src/otaclient/configs/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
ConfigurableSettings,
set_configs,
)
from otaclient.configs._cfg_consts import Consts
from otaclient.configs._cfg_consts import Consts, dynamic_root
from otaclient.configs._ecu_info import BootloaderType, ECUContact, ECUInfo
from otaclient.configs._proxy_info import ProxyInfo

Expand All @@ -31,4 +31,5 @@
"ECUInfo",
"ProxyInfo",
"set_configs",
"dynamic_root",
]
46 changes: 10 additions & 36 deletions src/otaclient/configs/_cfg_consts.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,12 @@
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
"""otaclient internal uses consts."""
"""otaclient internal uses consts, should not be changed from external."""


from __future__ import annotations

from enum import Enum
from typing import Any

from otaclient_common import replace_root

Expand All @@ -30,35 +29,15 @@ class CreateStandbyMechanism(str, Enum):
IN_PLACE = "IN_PLACE" # not yet implemented


_dynamic_loaded_paths = set(
[
"OPT_OTA_DPATH",
"OTACLIENT_INSTALLATION",
"CERT_DPATH",
"IMAGE_META_DPATH",
"BOOT_DPATH",
"OTA_DPATH",
"ECU_INFO_FPATH",
"PROXY_INFO_FPATH",
"ETC_DPATH",
"PASSWD_FPATH",
"GROUP_FPATH",
"FSTAB_FPATH",
]
)


class Consts:

@property
def ACTIVE_ROOT(self) -> str: # NOSONAR
return self._ACTIVE_ROOT

#
# ------ fixed paths ------ #
# ------ paths ------ #
#
"""Paths that is fixed with dynamic root."""

RUN_DIR = "/run/otaclient"
OTACLIENT_PID_FILE = "/run/otaclient.pid"

Expand All @@ -72,9 +51,6 @@ def ACTIVE_ROOT(self) -> str: # NOSONAR
OTA_TMP_STORE = "/.ota-tmp"
"""tmp store for local copy, located at standby slot."""

#
# ------ dynamic paths ------ #
#
OPT_OTA_DPATH = "/opt/ota"
OTACLIENT_INSTALLATION = "/opt/ota/client"
CERT_DPATH = "/opt/ota/client/certs"
Expand All @@ -101,20 +77,18 @@ def ACTIVE_ROOT(self) -> str: # NOSONAR
OTA_API_SERVER_PORT = 50051
OTAPROXY_LISTEN_PORT = 8082

def __getattribute__(self, name: str) -> Any:
try:
attr = object.__getattribute__(self, name)
except KeyError:
raise AttributeError(f"{name} not found in {__name__}") from None

if name == "ACTIVE_ROOT" or name not in _dynamic_loaded_paths:
return attr
return replace_root(attr, CANONICAL_ROOT, self.ACTIVE_ROOT)

def __init__(self) -> None:
"""For future updating the ACTIVE_ROOT."""

# TODO: detect rootfs here
self._ACTIVE_ROOT = CANONICAL_ROOT


cfg_consts = Consts()


def dynamic_root(canonical_path: str) -> str:
"""Re-root the input path with the actual ACTIVE_ROOT."""
if cfg_consts.ACTIVE_ROOT == CANONICAL_ROOT:
return canonical_path
return replace_root(canonical_path, CANONICAL_ROOT, cfg_consts.ACTIVE_ROOT)

0 comments on commit 1cf975c

Please sign in to comment.