From 268a7f547e25a38cf6086659c912145d5e36620f Mon Sep 17 00:00:00 2001 From: John Date: Thu, 12 Aug 2021 11:19:27 +0100 Subject: [PATCH 1/3] Add additional logging to s3 storage. Signed-off-by: John --- scripts/build/TestImpactAnalysis/tiaf_persistent_storage.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/scripts/build/TestImpactAnalysis/tiaf_persistent_storage.py b/scripts/build/TestImpactAnalysis/tiaf_persistent_storage.py index 18ea25091f..ec646ee484 100644 --- a/scripts/build/TestImpactAnalysis/tiaf_persistent_storage.py +++ b/scripts/build/TestImpactAnalysis/tiaf_persistent_storage.py @@ -49,6 +49,7 @@ class PersistentStorage(ABC): try: historic_data = json.loads(historic_data_json) self._last_commit_hash = historic_data["last_commit_hash"] + logger.info(f"Last commit hash '{self._last_commit_hash}' found.") # Create the active workspace directory where the coverage data file will be placed and unpack the coverage data so # it is accessible by the runtime @@ -105,7 +106,10 @@ class PersistentStorage(ABC): historic_data_json = self._pack_historic_data(last_commit_hash) if historic_data_json: + logger.info(f"Attempting to store historic data with new last commit hash '{self._last_commit_hash}'...") self._store_historic_data(historic_data_json) + logger.info("The historic data was successfully stored.") + else: logger.info("The historic data could not be successfully stored.") From 9601db55aa96a9185943d81e49a43135bf557e32 Mon Sep 17 00:00:00 2001 From: John Date: Thu, 12 Aug 2021 11:19:48 +0100 Subject: [PATCH 2/3] Add sanity checking to last commit hash. Signed-off-by: John --- scripts/build/TestImpactAnalysis/tiaf.py | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/scripts/build/TestImpactAnalysis/tiaf.py b/scripts/build/TestImpactAnalysis/tiaf.py index 255a34759a..a06a01cf38 100644 --- a/scripts/build/TestImpactAnalysis/tiaf.py +++ b/scripts/build/TestImpactAnalysis/tiaf.py @@ -61,17 +61,13 @@ class TestImpact: logger.error(f"The config does not contain the key {str(e)}.") return - def _attempt_to_generate_change_list(self, last_commit_hash, instance_id: str): + def _attempt_to_generate_change_list(self): """ Attempts to determine the change list bewteen now and the last tiaf run (if any). - - @param last_commit_hash: The commit hash of the last TIAF run. - @param instance_id: The unique id to derive the change list file name from. """ self._has_change_list = False self._change_list_path = None - self._src_commit = last_commit_hash # Check whether or not a previous commit hash exists (no hash is not a failure) if self._src_commit: @@ -92,7 +88,7 @@ class TestImpact: try: # Attempt to generate a diff between the src and dst commits logger.error(f"Source '{self._src_commit}' and destination '{self._dst_commit}' will be diff'd.") - diff_path = pathlib.Path(pathlib.PurePath(self._temp_workspace).joinpath(f"changelist.{instance_id}.diff")) + diff_path = pathlib.Path(pathlib.PurePath(self._temp_workspace).joinpath(f"changelist.{self._instance_id}.diff")) self._repo.create_diff_file(self._src_commit, self._dst_commit, diff_path, multi_branch) except RuntimeError as e: logger.error(e) @@ -124,7 +120,7 @@ class TestImpact: # Serialize the change list to the JSON format the test impact analysis runtime expects change_list_json = json.dumps(self._change_list, indent = 4) - change_list_path = pathlib.PurePath(self._temp_workspace).joinpath(f"changelist.{instance_id}.json") + change_list_path = pathlib.PurePath(self._temp_workspace).joinpath(f"changelist.{self._instance_id}.json") f = open(change_list_path, "w") f.write(change_list_json) f.close() @@ -215,7 +211,7 @@ class TestImpact: self._commit_distance = None # Generate a unique ID to be used as part of the file name for required runtime dynamic artifacts. - instance_id = uuid.uuid4().hex + self._instance_id = uuid.uuid4().hex if self._use_test_impact_analysis: logger.info("Test impact analysis is enabled.") @@ -232,7 +228,14 @@ class TestImpact: if persistent_storage: if persistent_storage.has_historic_data: logger.info("Historic data found.") - self._attempt_to_generate_change_list(persistent_storage.last_commit_hash, instance_id) + self._src_commit = persistent_storage.last_commit_hash + + # Perform some basic sanity checks on the commit hashes to ensure confidence in the integrity of of the environment + if self._src_commit == self._dst_commit: + logger.error(f"Source commit '{self._src_commit}' and destination commit '{self._dst_commit}', implying the integrity of the historic data is compromised.") + persistent_storage = None + else: + self._attempt_to_generate_change_list(self._instance_id) else: logger.info("No historic data found.") @@ -283,7 +286,7 @@ class TestImpact: logger.info(f"Test failure policy is set to '{test_failure_policy}'.") # Sequence report - report_file = pathlib.PurePath(self._temp_workspace).joinpath(f"report.{instance_id}.json") + report_file = pathlib.PurePath(self._temp_workspace).joinpath(f"report.{self._instance_id}.json") args.append(f"--report={report_file}") logger.info(f"Sequence report file is set to '{report_file}'.") From 199273b880a9266af7a5eeb1e93c76beb8bbf2c9 Mon Sep 17 00:00:00 2001 From: John Date: Thu, 12 Aug 2021 12:00:51 +0100 Subject: [PATCH 3/3] Remove positional argument from change list generaiton. Signed-off-by: John --- scripts/build/TestImpactAnalysis/tiaf.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/build/TestImpactAnalysis/tiaf.py b/scripts/build/TestImpactAnalysis/tiaf.py index a06a01cf38..11ca24f830 100644 --- a/scripts/build/TestImpactAnalysis/tiaf.py +++ b/scripts/build/TestImpactAnalysis/tiaf.py @@ -235,7 +235,7 @@ class TestImpact: logger.error(f"Source commit '{self._src_commit}' and destination commit '{self._dst_commit}', implying the integrity of the historic data is compromised.") persistent_storage = None else: - self._attempt_to_generate_change_list(self._instance_id) + self._attempt_to_generate_change_list() else: logger.info("No historic data found.")