def _check_required_patches_are_applied(self, patches=None): """Validates that each patch provided is applied on the system""" if patches is None: patches = [] try: system = self._dbapi.isystem_get_one() response = patch_api.patch_query( token=None, timeout=constants.PATCH_DEFAULT_TIMEOUT_IN_SECS, region_name=system.region_name) except Exception as e: LOG.error(e) raise exception.SysinvException( _("Error while querying sw-patch-controller for the " "state of the patch(es).")) query_patches = response['pd'] applied_patches = [] for patch_key in query_patches: patch = query_patches[patch_key] patchstate = patch.get('patchstate', None) if patchstate == patch_constants.APPLIED or \ patchstate == patch_constants.COMMITTED: applied_patches.append(patch_key) missing_patches = [] for required_patch in patches: if required_patch not in applied_patches: missing_patches.append(required_patch) success = not missing_patches return success, missing_patches
def _check_patching_operation(self): try: system = self._dbapi.isystem_get_one() response = patch_api.patch_query( token=None, timeout=constants.PATCH_DEFAULT_TIMEOUT_IN_SECS, region_name=system.region_name) query_patches = response['pd'] except Exception as e: # Assume that a patching operation is underway, raise an exception. LOG.error(_("No response from patch api: %s" % e)) raise for patch in query_patches: patch_state = query_patches[patch].get('patchstate', None) if (patch_state == patch_constants.PARTIAL_APPLY or patch_state == patch_constants.PARTIAL_REMOVE): raise exception.SysinvException( _("Patching operation is in progress."))
def _check_required_patches(self, patch_list): """Validates that each patch provided is applied on the system""" system = self._dbapi.isystem_get_one() response = patch_api.patch_query(token=None, timeout=60, region_name=system.region_name) query_patches = response['pd'] applied_patches = [] for patch_key in query_patches: patch = query_patches[patch_key] patchstate = patch.get('patchstate', None) if patchstate == patch_constants.APPLIED or \ patchstate == patch_constants.COMMITTED: applied_patches.append(patch_key) missing_patches = [] for required_patch in patch_list: if required_patch not in applied_patches: missing_patches.append(required_patch) success = not missing_patches return success, missing_patches