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

[NEXMANAGE-899] Fix dispatcher not recording state file and causing snapshot failure #583

Merged
merged 6 commits into from
Oct 24, 2024
Merged
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
7 changes: 5 additions & 2 deletions inbm/Changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,16 @@ 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
- (NEXMANAGE-837) Fix schema validation issue on failed UDM request sent from
dispatcher to cloudadapter
### Added
- (NEXMANAGE-900) Add UpdateFirmware to the common proto file
-
### Changed
- (NEXMANAGE-906) Truncate the granular log instead of removing it

### Fixed
- (NEXMANAGE-837) Fix schema validation issue on failed UDM request sent from
dispatcher to cloudadapter
- (NEXMANAGE-899) Fix dispatcher not recording state file and causing snapshot failure

## 4.2.6.1 - 2024-10-18
### Added
Expand Down
13 changes: 7 additions & 6 deletions inbm/dispatcher-agent/dispatcher/common/dispatcher_state.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,12 +65,12 @@ def is_dispatcher_state_file_exists() -> bool:
}, total=False)


def consume_dispatcher_state_file(read: bool = False) -> DispatcherState | None:
def consume_dispatcher_state_file(readonly: bool = False) -> DispatcherState | None:
"""Read dispatcher state file and return state object, clearing state file on success

Try old location first, then new location.

@param read: Set to True to read file info without removing the file
@param readonly: Set to True to read file info without removing the file
@return: State object from state file; None on error
"""
logger.debug("Starting consume_dispatcher_state_file")
Expand All @@ -92,17 +92,18 @@ def consume_dispatcher_state_file(read: bool = False) -> DispatcherState | None:
logger.exception(f"Exception while extracting dispatcher state from {state_file}: {e}")
state = None # Ensure state is None if this attempt fails

# If there is no state, the dispatcher will record the restart_reason and snapshot_num.
if state is None:
logger.error("Failed to extract dispatcher state from all state files.")
raise DispatcherException("Exception while extracting dispatcher state from disk")
logger.error("Failed to extract dispatcher state from all state files.")

if not read:

if not readonly:
try:
logger.debug("Clearing dispatcher state files")
clear_dispatcher_state()
except Exception as e:
logger.exception(f"Failed to clear dispatcher state files: {e}")
# Depending on requirements, you might want to raise or handle this differently
# Nothing more can be done if clearing the state file fails

return state

Expand Down
2 changes: 1 addition & 1 deletion inbm/dispatcher-agent/dispatcher/dispatcher_class.py
Original file line number Diff line number Diff line change
Expand Up @@ -757,7 +757,7 @@ def check_dispatcher_state_info(self) -> None:
"""

if dispatcher_state.is_dispatcher_state_file_exists():
state = dispatcher_state.consume_dispatcher_state_file(read=True)
state = dispatcher_state.consume_dispatcher_state_file(readonly=True)
if state is None:
raise DispatcherException("Unable to get dispatcher state file")
logger.debug(str(state))
Expand Down
6 changes: 3 additions & 3 deletions inbm/dispatcher-agent/dispatcher/sota/snapshot.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ def take_snapshot(self) -> None:
restart_reason = None

state: dispatcher_state.DispatcherState | None = dispatcher_state.consume_dispatcher_state_file(
read=True)
readonly=True)
if state:
restart_reason = state.get('restart_reason')
if restart_reason:
Expand Down Expand Up @@ -357,7 +357,7 @@ def take_snapshot(self) -> None:
content = read_current_mender_version()
state: dispatcher_state.DispatcherState
if dispatcher_state.is_dispatcher_state_file_exists():
consumed_state = dispatcher_state.consume_dispatcher_state_file(read=True)
consumed_state = dispatcher_state.consume_dispatcher_state_file(readonly=True)
restart_reason = None
if consumed_state:
restart_reason = consumed_state.get('restart_reason', None)
Expand Down Expand Up @@ -473,7 +473,7 @@ def take_snapshot(self) -> None:
raise SotaError("Failed to get os version.")
state: dispatcher_state.DispatcherState
if dispatcher_state.is_dispatcher_state_file_exists():
consumed_state = dispatcher_state.consume_dispatcher_state_file(read=True)
consumed_state = dispatcher_state.consume_dispatcher_state_file(readonly=True)
restart_reason = None
if consumed_state:
restart_reason = consumed_state.get('restart_reason', None)
Expand Down