Skip to content

Commit

Permalink
Merge pull request #538 from openlawlibrary/ndusan/notice-level-updat…
Browse files Browse the repository at this point in the history
…e-status

feat: add notice level logging
  • Loading branch information
renatav authored Sep 28, 2024
2 parents 5f61e58 + 322de17 commit 3b6fefc
Show file tree
Hide file tree
Showing 6 changed files with 46 additions and 7 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ and this project adheres to [Semantic Versioning][semver].

### Changed

- Default verbosity to 0 (NOTICE) level; add notice level update outcome logging ([538])
- Raise a more descriptive error if `pygit2` repository cannot be instantiated ([485], [489])
- Enhanced commit_and_push for better error logging and update the last validated commit ([469])
- Generate public key from private key if .pub file is missing ([462])
Expand All @@ -51,6 +52,7 @@ and this project adheres to [Semantic Versioning][semver].
- Fix setup role when specifying public keys in keys-description ([511])
- `check_if_repositories_clean` error now returns a list of repositories which aren't clean, instead of a single repository ([525])

[538]: https://github.com/openlawlibrary/taf/pull/538
[535]: https://github.com/openlawlibrary/taf/pull/535
[532]: https://github.com/openlawlibrary/taf/pull/532
[529]: https://github.com/openlawlibrary/taf/pull/529
Expand Down
2 changes: 1 addition & 1 deletion taf/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ def __init__(
message = ""
dirty_repo_list = ", ".join(dirty_index_repos)
if len(dirty_index_repos) >= 1:
message += f"Repositories {dirty_repo_list} have uncommitted changes. Commit and push or revert the changes and run the command again."
message += f"Repositories {dirty_repo_list} have uncommitted changes. Commit and push or use --force to revert and run the command again."
unpushed_repo_branches = ", ".join(
[
f"{repo}: ({branch})"
Expand Down
2 changes: 1 addition & 1 deletion taf/tests/test_updater/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@
NO_INFO_JSON = "Update of repository failed due to error: Error during info.json parse. If the authentication repository's path is not specified, info.json metadata is expected to be in targets/protected"
UNCOMMITTED_CHANGES = r"Update of (\w+\/\w+) failed due to error: Repository (\w+\/\w+) should contain only committed changes\. \nPlease update the repository at (.+) manually and try again\."
UPDATE_ERROR_PATTERN = r"Update of (\w+\/\w+) failed due to error: Validation of authentication repository (\w+\/\w+) failed at revision ([0-9a-f]+) due to error: .*"
FORCED_UPDATE_PATTERN = r"Update of (\w+\/\w+) failed due to error: Repositories ([\w/,\s-]+) have uncommitted changes. Commit and push or revert the changes and run the command again."
FORCED_UPDATE_PATTERN = r"Update of (\w+\/\w+) failed due to error: Repositories ([\w/,\s-]+) have uncommitted changes. Commit and push or use --force to revert and run the command again."
REMOVED_COMMITS_PATTERN = r"Update of (\w+/\w+) failed due to error: Last validated commit ([0-9a-f]{40}) is not in the remote repository."
INVALID_TIMESTAMP_PATTERN = r"^Update of (\w+\/\w+) failed due to error: Update of (\w+\/\w+) failed. One or more referenced authentication repositories could not be validated:\n Validation of authentication repository (\w+\/\w+) failed at revision ([0-9a-f]{40}) due to error: timestamp was signed by (\d+)\/(\d+) keys$"
CANNOT_CLONE_TARGET_PATTERN = r"^Update of (\w+/\w+) failed due to error: Update of (\w+/\w+) failed. One or more referenced authentication repositories could not be validated:\n Cannot clone (\w+/\w+) from any of the following URLs: \['.*'\]$"
Expand Down
2 changes: 1 addition & 1 deletion taf/updater/lifecycle_handlers.py
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,7 @@ def prepare_data_repo(
):
conf_data = get_config(auth_repo.library_dir)
if not conf_data:
taf_logger.info(
taf_logger.debug(
f"WARNING: No config data at {Path(library_dir, CONFIG_NAME)}. Scripts might not be executed successfully"
)
return {
Expand Down
41 changes: 39 additions & 2 deletions taf/updater/updater.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@
from cattr import unstructure
import concurrent.futures
from concurrent.futures import ThreadPoolExecutor
from taf.updater.types.update import Update

disable_tuf_console_logging()

Expand Down Expand Up @@ -362,7 +363,7 @@ def _update_or_clone_repository(config: UpdateConfig):
f"Update of {auth_repo_name or 'repository'} failed due to error: {e}"
)

update_data = {}
update_data = Update()
if not config.excluded_target_globs:
# after all repositories have been updated
# update information is in repos_update_data
Expand All @@ -388,7 +389,7 @@ def _update_or_clone_repository(config: UpdateConfig):
errors,
root_auth_repo,
)

log_repo_updates(update_data)
if root_error:
raise root_error
return unstructure(update_data)
Expand Down Expand Up @@ -529,6 +530,42 @@ def _process_repo_update(
repositoriesdb.clear_repositories_db()


def log_repo_updates(update_data: Update):
"""
Log the status of the repositories after updating them.
"""
update_output_dict = {
repo_name: {
"changed": repo_info["changed"],
"event": repo_info["event"],
**({"error": repo_info["error_msg"]} if repo_info["error_msg"] else {}),
}
for repo_name, repo_info in update_data.auth_repos.items()
}
changes_or_errors = False

for repo_name, details in update_output_dict.items():
changed = details.get("changed", False)
event_operation = details["event"]
error_message = details.get("error")

if changed or error_message:
changes_or_errors = True
message = f"Repository: {repo_name}\n"
message += f" Change status: {'changed' if changed else 'no changes'}\n"
message += f" Event: {event_operation}"

if error_message:
message += f"\n Error: {error_message}\n"

taf_logger.log("NOTICE", message)

if not changes_or_errors:
taf_logger.log(
"NOTICE", "All repositories are up-to-date with no changes or errors."
)


def _update_dependencies(update_config, child_auth_repos):

# for now, just take the newest commit and do not worry about updated definitions
Expand Down
4 changes: 2 additions & 2 deletions taf/updater/updater_pipeline.py
Original file line number Diff line number Diff line change
Expand Up @@ -1686,8 +1686,8 @@ def _update_tuf_current_revision(git_fetcher, updater, auth_repo_name):
f"Validation of authentication repository {auth_repo_name or ''}"
f" failed at revision {current_commit} due to error: {e}"
)
taf_logger.warning(
f"WARNING: Could not validate authentication repository {auth_repo_name} at revision {current_commit} due to error: {e}"
taf_logger.debug(
f"WARNING: Could not validate {auth_repo_name} at revision {current_commit} due to error: {e}"
)


Expand Down

0 comments on commit 3b6fefc

Please sign in to comment.