-
Notifications
You must be signed in to change notification settings - Fork 4
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
refine(v3.7.x): refactor proxy_info.yaml and ecu_info.yaml config files parsing #286
Merged
Merged
Changes from 17 commits
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
c1e0954
backport_v3.6.x: backport PR#270
Bodong-Yang b037ee4
integrate new ecu_info into boot_control module
Bodong-Yang 2e36f56
WIP: integrate into otaclient package
Bodong-Yang 3fae358
WIP: integrate into otaclient_service and otaclient_stub
Bodong-Yang bd9196a
WIP: integrate into otaclient
Bodong-Yang 508791a
otaclient.boot_control: cleanup selector
Bodong-Yang 9b4ad0d
fix lint
Bodong-Yang b7ca9c3
fix more lint
Bodong-Yang facb0bf
otaclient, otaclient_stub: not initialize with ecu_info
Bodong-Yang d3a8132
ecu_proxy_info: typing refinement
Bodong-Yang d5932dc
cleanup unused code
Bodong-Yang 16170cb
log_setting, otaclient_stub: minor updates
Bodong-Yang c08fb46
fix up tests
Bodong-Yang e2d0d2a
minor update
Bodong-Yang 17301d3
minor fix
Bodong-Yang 6c9d655
ecu_info: fix deprecation warning over default value
Bodong-Yang 57cce6f
minor fix
Bodong-Yang 1222869
allow logging_server field to be null in proxy_info.yaml
Bodong-Yang File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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,48 @@ | ||
# Copyright 2022 TIER IV, INC. All rights reserved. | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# 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. | ||
|
||
|
||
from __future__ import annotations | ||
from pathlib import Path | ||
from typing import Any, Callable, TypeVar, Union | ||
from typing_extensions import Annotated, ParamSpec | ||
|
||
from pydantic import Field | ||
|
||
P = ParamSpec("P") | ||
T = TypeVar("T") | ||
RT = TypeVar("RT") | ||
|
||
StrOrPath = Union[str, Path] | ||
|
||
# pydantic helpers | ||
|
||
NetworkPort = Annotated[int, Field(ge=1, le=65535)] | ||
|
||
|
||
def gen_strenum_validator(enum_type: type[T]) -> Callable[[T | str | Any], T]: | ||
"""A before validator generator that converts input value into enum | ||
before passing it to pydantic validator. | ||
|
||
NOTE(20240129): as upto pydantic v2.5.3, (str, Enum) field cannot | ||
pass strict validation if input is str. | ||
""" | ||
|
||
def _inner(value: T | str | Any) -> T: | ||
assert isinstance( | ||
value, (enum_type, str) | ||
), f"{value=} should be {enum_type} or str type" | ||
return enum_type(value) | ||
|
||
return _inner |
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
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
This file was deleted.
Oops, something went wrong.
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 |
---|---|---|
|
@@ -17,26 +17,13 @@ | |
|
||
import atexit | ||
import logging | ||
import os | ||
import yaml | ||
import requests | ||
from queue import Queue | ||
from threading import Event, Thread | ||
from urllib.parse import urljoin | ||
|
||
import requests | ||
|
||
import otaclient | ||
from .configs import config as cfg | ||
|
||
|
||
# NOTE: EcuInfo imports this log_setting so independent get_ecu_id are required. | ||
def get_ecu_id(): | ||
try: | ||
with open(cfg.ECU_INFO_FILE) as f: | ||
ecu_info = yaml.load(f, Loader=yaml.SafeLoader) | ||
return ecu_info["ecu_id"] | ||
except Exception: | ||
return "autoware" | ||
from .configs import config as cfg, ecu_info, proxy_info | ||
|
||
|
||
class _LogTeeHandler(logging.Handler): | ||
|
@@ -99,25 +86,15 @@ def configure_logging(): | |
_logger = logging.getLogger(_module_name) | ||
_logger.setLevel(_log_level) | ||
|
||
# NOTE(20240306): for only god knows reason, although in proxy_info.yaml, | ||
# the logging_server field is assigned with an URL, and otaclient | ||
# expects an URL, the run.sh from autoware_ecu_system_setup pass in | ||
# HTTP_LOGGING_SERVER with URL schema being removed!? | ||
# NOTE: I will do a quick fix here as I don't want to touch autoware_ecu_system_setup | ||
# for now, leave it in the future. | ||
if iot_logger_url := os.environ.get("HTTP_LOGGING_SERVER"): | ||
# special treatment for not-a-URL passed in by run.sh | ||
# note that we only support http, the proxy_info.yaml should be properly setup. | ||
if not (iot_logger_url.startswith("http") or iot_logger_url.startswith("HTTP")): | ||
iot_logger_url = f"http://{iot_logger_url.strip('/')}" | ||
if iot_logger_url := str(proxy_info.logging_server): | ||
iot_logger_url = f"{iot_logger_url.strip('/')}/" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Note: after we directly parse the |
||
|
||
ch = _LogTeeHandler() | ||
fmt = logging.Formatter(fmt=cfg.LOG_FORMAT) | ||
ch.setFormatter(fmt) | ||
|
||
# star the logging thread | ||
log_upload_endpoint = urljoin(iot_logger_url, get_ecu_id()) | ||
log_upload_endpoint = urljoin(iot_logger_url, ecu_info.ecu_id) | ||
ch.start_upload_thread(log_upload_endpoint) | ||
|
||
# NOTE: "otaclient" logger will be the root logger for all loggers name | ||
|
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Note:
BootloaderType.UNSPECIFIC
is renamed toAUTO_DETECT
for better understanding. ButAUTO_DETECT
is deprecated and should not be used in the future.