summaryrefslogtreecommitdiffstats
path: root/src/software/openlmi/software/core/AffectedSoftwareJobElement.py
diff options
context:
space:
mode:
Diffstat (limited to 'src/software/openlmi/software/core/AffectedSoftwareJobElement.py')
-rw-r--r--src/software/openlmi/software/core/AffectedSoftwareJobElement.py79
1 files changed, 69 insertions, 10 deletions
diff --git a/src/software/openlmi/software/core/AffectedSoftwareJobElement.py b/src/software/openlmi/software/core/AffectedSoftwareJobElement.py
index 2530104..34c5078 100644
--- a/src/software/openlmi/software/core/AffectedSoftwareJobElement.py
+++ b/src/software/openlmi/software/core/AffectedSoftwareJobElement.py
@@ -26,7 +26,8 @@ from openlmi.common import cmpi_logging
from openlmi.software import util
from openlmi.software.core import ComputerSystem
from openlmi.software.core import Identity
-from openlmi.software.core import InstallationJob
+from openlmi.software.core import IdentityFileCheck
+from openlmi.software.core import Job
from openlmi.software.core import SystemCollection
from openlmi.software.yumdb import jobs
from openlmi.software.yumdb import PackageInfo
@@ -52,14 +53,15 @@ class Values(object):
def check_path(env, op):
"""
Checks, whether object path is valid.
- @return affected object path
+
+ Return internal object representing job and object path of affected element
+ as a pair: ``(job, affected)``.
"""
if not isinstance(op, pywbem.CIMInstanceName):
raise TypeError("op must be a CIMInstanceName")
ch = env.get_cimom_handle()
- job = op['AffectingElement'] = InstallationJob.object_path2job(
- op['AffectingElement'])
+ job = op['AffectingElement'] = Job.object_path2job(op['AffectingElement'])
affected = op['AffectedElement']
if ch.is_subclass(affected.namespace, sub=affected.classname,
super='LMI_SoftwareIdentity'):
@@ -82,7 +84,7 @@ def check_path(env, op):
if job.state == job.COMPLETED:
affected = Identity.pkg2model(job.result_data)
else:
- # TODO: this should be somehow obtained from from downloaded
+ # TODO: this should be somehow obtained from downloaded
# package before installation
raise pywbem.CIMError(pywbem.CIM_ERR_NOT_FOUND,
"No SoftwareIdentity is associated to given job.")
@@ -98,6 +100,25 @@ def check_path(env, op):
super='Linux_ComputerSystem'):
ComputerSystem.check_path(env, affected, "AffectedElement")
affected = ComputerSystem.get_path()
+ elif ch.is_subclass(affected.namespace, sub=affected.classname,
+ super='LMI_SoftwareIdentityFileCheck'):
+ if not isinstance(job, jobs.YumCheckPackage):
+ raise pywbem.CIMError(pywbem.CIM_ERR_NOT_FOUND,
+ "Job must point to verification job, not to: \"%s\"" % job)
+ if job.state != job.COMPLETED:
+ raise pywbem.CIMError(pywbem.CIM_ERR_NOT_FOUND,
+ "Associations to failed file checks for verification job"
+ " \"%s\" are not yet known, since job has not completed"
+ " yet." % op["AffectingElement"]["InstanceID"])
+ pkg_info, _ = job.result_data
+ file_check = IdentityFileCheck.object_path2file_check(affected)
+ if file_check.pkg_info.nevra != pkg_info.nevra:
+ raise pywbem.CIMError(pywbem.CIM_ERR_NOT_FOUND,
+ "Affected element associated to job for another package:"
+ " \"%s\" != \"%s\"." % (file_check.pkg_info, pkg_info))
+ if IdentityFileCheck.file_check_passed(file_check):
+ raise pywbem.CIMError(pywbem.CIM_ERR_NOT_FOUND,
+ "Given file check reference passed the verification.")
else:
raise pywbem.CIMError(pywbem.CIM_ERR_INVALID_PARAMETER,
"Expected an instance of LMI_SoftwareIdentity,"
@@ -114,7 +135,11 @@ def job2affected_software_identity(job):
descriptions = []
if isinstance(job, jobs.YumSpecificPackageJob):
if job.state == job.COMPLETED and job.result_data:
- affected = Identity.pkg2model(job.result_data)
+ if isinstance(job, jobs.YumCheckPackage):
+ # get the first item out of (pkg_info, pkg_check)
+ affected = Identity.pkg2model(job.result_data[0])
+ else:
+ affected = Identity.pkg2model(job.result_data)
else:
affected = Identity.pkg2model(job.pkg)
if isinstance(job, jobs.YumInstallPackage):
@@ -125,7 +150,7 @@ def job2affected_software_identity(job):
(jobs.YumUpdatePackage, jobs.YumUpdateToPackage)):
descriptions.append("Updating")
elif isinstance(job, jobs.YumCheckPackage):
- descriptions.append("Checking")
+ descriptions.append("Verifying")
else:
descriptions.append("Modifying")
cmpi_logging.logger.error("Unhandled job: %s", job)
@@ -177,6 +202,36 @@ def fill_model_system_collection(model, keys_only=True):
return model
@cmpi_logging.trace_function
+def fill_model_failed_check(model, failed_check, keys_only=True):
+ """
+ Fills model's AffectedElement and all non-key properties.
+
+ :param failed_check: (``CIMInstanceName``) Is on object path of failed
+ file check.
+ """
+ if not isinstance(failed_check, pywbem.CIMInstanceName):
+ raise TypeError("failed_check must be a CIMInstanceName")
+ model["AffectedElement"] = failed_check
+ if not keys_only:
+ model["ElementEffects"] = [Values.ElementEffects.Other]
+ model["OtherElementEffectsDescriptions"] = [
+ "File did not pass the verification."
+ ]
+ return model
+
+@cmpi_logging.trace_function
+def generate_failed_checks(model, job, keys_only=True):
+ """
+ Generates associations between LMI_SoftwareVerificationJob and
+ LMI_SoftwareIdentityFileCheck for files that did not pass the check.
+ """
+ out_params = Job.get_verification_out_params(job)
+ if not "Failed" in out_params:
+ return
+ for failed in out_params["Failed"].value:
+ yield fill_model_failed_check(model, failed, keys_only)
+
+@cmpi_logging.trace_function
def generate_models_from_job(job, keys_only=True, model=None):
"""
Generates all associations between job and affected elements.
@@ -189,7 +244,7 @@ def generate_models_from_job(job, keys_only=True, model=None):
if not keys_only:
model = pywbem.CIMInstance("LMI_AffectedSoftwareJobElement",
path=model)
- model["AffectingElement"] = InstallationJob.job2model(job)
+ model["AffectingElement"] = Job.job2model(job)
(si, element_effects, element_effects_descriptions) = \
job2affected_software_identity(job)
model["AffectedElement"] = si
@@ -198,8 +253,12 @@ def generate_models_from_job(job, keys_only=True, model=None):
model["OtherElementEffectsDescriptions"] = \
element_effects_descriptions
yield model
- fill_model_system_collection(model, keys_only=keys_only)
- yield model
+ if not isinstance(job, jobs.YumCheckPackage):
+ fill_model_system_collection(model, keys_only=keys_only)
+ yield model
+ else: # package verification - associate to failed file checks
+ for model in generate_failed_checks(model, job, keys_only=keys_only):
+ yield model
fill_model_computer_system(model, job, keys_only=keys_only)
yield model