diff --git a/software/software/software_controller.py b/software/software/software_controller.py index 66975fbf..01469995 100644 --- a/software/software/software_controller.py +++ b/software/software/software_controller.py @@ -72,6 +72,7 @@ from software.software_functions import audit_log_info from software.software_functions import repo_root_dir from software.software_functions import is_deploy_state_in_sync from software.software_functions import is_deployment_in_progress +from software.software_functions import get_release_from_patch from software.release_state import ReleaseState from software.deploy_host_state import DeployHostState from software.deploy_state import DeployState @@ -1342,11 +1343,9 @@ class PatchController(PatchService): base_patch_filename = os.path.basename(patch_file) - # NOTE(bqian) does it make sense to link the release_id to name of the patch? - # Get the release_id from the filename + # Get the release_id from the patch's metadata # and check to see if it's already uploaded - # todo(abailey) We should not require the ID as part of the file - (release_id, _) = os.path.splitext(base_patch_filename) + release_id = get_release_from_patch(patch_file,'id') release = self.release_collection.get_release_by_id(release_id) diff --git a/software/software/software_functions.py b/software/software/software_functions.py index 350c147e..190e1349 100644 --- a/software/software/software_functions.py +++ b/software/software/software_functions.py @@ -160,19 +160,19 @@ def write_xml_file(top, outfile.write(minidom.parseString(rough_xml).toprettyxml(indent=" ")) -def get_release_from_patch(patchfile): +def get_release_from_patch(patchfile, key="sw_version"): rel = "" try: metadata_str = subprocess.check_output(['tar', '--to-command=tar -xO', '-xf', patchfile, 'metadata.tar']) root = ElementTree.fromstring(metadata_str) # Extract release version - rel = root.findtext('sw_version') + rel = root.findtext(key) except subprocess.CalledProcessError as e: LOG.error("Failed to run tar command") LOG.error("Command output: %s", e.output) raise e except Exception as e: - print("Failed to parse patch software version") + print("Failed to parse patch %s" % key) raise e return rel