def verify_package(ns, package): """ Returns the instances of ``LMI_SoftwareIdentityFileCheck`` representing files, that did not pass the verification. :param package: Instance or instance name of ``LMI_SoftwareIdentity`` representing package to verify. :type package: :py:class:`lmi.shell.LMIInstance` or :py:class:`lmi.shell.LMIInstanceName` :returns: List of instances of ``LMI_SoftwareIdentityFileCheck`` with non-empty ``FailedFlags`` property. :rtype: list """ if not isinstance(package, (LMIInstance, LMIInstanceName)): raise TypeError("package must be an LMIInstance or LMIInstanceName") # we can not use synchronous invocation because the reference to a job is # needed - for enumerating of affected software identities service = ns.LMI_SoftwareInstallationService.first_instance() results = service.VerifyInstalledIdentity( Source=package.path if isinstance(package, LMIInstance) else package, Target=get_computer_system(ns).path) nevra = get_package_nevra(package) if results.rval != 4096: msg = 'Failed to verify package "%s (rval=%d)".' % (nevra, results.rval) if results.errorstr: msg += ': ' + results.errorstr raise LmiFailed(msg) job = results.rparams['Job'].to_instance() _wait_for_job_finished(job) if not LMIJob.lmi_is_job_completed(job): msg = 'Failed to verify package "%s".' % nevra if job.ErrorDescription: msg += ': ' + job.ErrorDescription raise LmiFailed(msg) LOG().debug('Verified package "%s" on remote host "%s".', nevra, ns.connection.uri) failed = job.associators( Role='AffectingElement', ResultRole='AffectedElement', AssocClass="LMI_AffectedSoftwareJobElement", ResultClass='LMI_SoftwareIdentityFileCheck') LOG().debug('Verified package "%s" on remote host "%s" with %d failures.', nevra, ns.connection.uri, len(failed)) return failed
def verify_package(ns, package): """ Returns the instances of ``LMI_SoftwareIdentityFileCheck`` representing files, that did not pass the verification. :param package: Instance or instance name of ``LMI_SoftwareIdentity`` representing package to verify. :type package: :py:class:`lmi.shell.LMIInstance` or :py:class:`lmi.shell.LMIInstanceName` :returns: List of instances of ``LMI_SoftwareIdentityFileCheck`` with non-empty ``FailedFlags`` property. :rtype: list """ if not isinstance(package, (LMIInstance, LMIInstanceName)): raise TypeError("package must be an LMIInstance or LMIInstanceName") # we can not use synchronous invocation because the reference to a job is # needed - for enumerating of affected software identities service = ns.LMI_SoftwareInstallationService.first_instance() results = service.VerifyInstalledIdentity( Source=package.path if isinstance(package, LMIInstance) else package, Target=get_computer_system(ns).path) nevra = get_package_nevra(package) if results.rval != 4096: msg = 'Failed to verify package "%s (rval=%d)".' % (nevra, results.rval) if results.errorstr: msg += ': ' + results.errorstr raise LmiFailed(msg) job = results.rparams['Job'].to_instance() _wait_for_job_finished(job) if not LMIJob.lmi_is_job_completed(job): msg = 'Failed to verify package "%s".' % nevra if job.ErrorDescription: msg += ': ' + job.ErrorDescription raise LmiFailed(msg) LOG().debug('Verified package "%s" on remote host "%s".', nevra, ns.connection.uri) failed = job.associators(Role='AffectingElement', ResultRole='AffectedElement', AssocClass="LMI_AffectedSoftwareJobElement", ResultClass='LMI_SoftwareIdentityFileCheck') LOG().debug('Verified package "%s" on remote host "%s" with %d failures.', nevra, ns.connection.uri, len(failed)) return failed
def install_package(ns, package, force=False, update=False): """ Install package on system. :param package: Instance or instance name of ``LMI_SoftwareIdentity`` representing package to install. :type package: :py:class:`lmi.shell.LMIInstance` or :py:class:`lmi.shell.LMIInstanceName` :param boolean force: Whether the installation shall be done even if installing the same (reinstalling) or older version than already installed. :param boolean update: Whether this is an update. Update fails if package is not already installed on system. :returns: Software identity installed on remote system. It's an instance ``LMI_SoftwareIdentity``. :rtype: :py:class:`lmi.shell.LMIInstance` """ if not isinstance(package, (LMIInstance, LMIInstanceName)): raise TypeError("package must be an LMIInstance or LMIInstanceName") service = ns.LMI_SoftwareInstallationService.first_instance() options = [4 if not update else 5] # Install (4) or Update (5) if force: options.append(3) # Force Installation # we can not use synchronous invocation because the reference to a job is # needed results = service.InstallFromSoftwareIdentity( Source=package.path if isinstance(package, LMIInstance) else package, Collection=ns.LMI_SystemSoftwareCollection.first_instance_name(), InstallOptions=options) nevra = get_package_nevra(package) if results.rval != 4096: msg = 'Failed to %s package "%s" (rval=%d).' % ( 'update' if update else 'install', nevra, results.rval) if results.errorstr: msg += ': ' + results.errorstr raise LmiFailed(msg) job = results.rparams['Job'].to_instance() _wait_for_job_finished(job) if not LMIJob.lmi_is_job_completed(job): if not update: if not isinstance(package, LMIInstance): try: package = package.to_instance() except wbem.CIMError: pass if getattr(package, 'InstallDate', None) is not None: LOG().info('Package "%s" is already installed.' % nevra) return msg = 'Failed to %s package "%s".' % ('update' if update else 'install', nevra) if job.ErrorDescription: msg += ': ' + job.ErrorDescription raise LmiFailed(msg) else: LOG().info('Installed package "%s".', nevra, ns.connection.uri) installed = job.associators(Role='AffectingElement', ResultRole='AffectedElement', AssocClass="LMI_AffectedSoftwareJobElement", ResultClass='LMI_SoftwareIdentity') if len(installed) < 1: raise LmiFailed('Failed to find installed package "%s".' % nevra) if len(installed) > 1: LOG().warn('Expected just one affected software identity, got: %s', {get_package_nevra(p) for p in installed}) return installed[-1]
def install_package(ns, package, force=False, update=False): """ Install package on system. :param package: Instance or instance name of ``LMI_SoftwareIdentity`` representing package to install. :type package: :py:class:`lmi.shell.LMIInstance` or :py:class:`lmi.shell.LMIInstanceName` :param boolean force: Whether the installation shall be done even if installing the same (reinstalling) or older version than already installed. :param boolean update: Whether this is an update. Update fails if package is not already installed on system. :returns: Software identity installed on remote system. It's an instance ``LMI_SoftwareIdentity``. :rtype: :py:class:`lmi.shell.LMIInstance` """ if not isinstance(package, (LMIInstance, LMIInstanceName)): raise TypeError("package must be an LMIInstance or LMIInstanceName") service = ns.LMI_SoftwareInstallationService.first_instance() options = [4 if not update else 5] # Install (4) or Update (5) if force: options.append(3) # Force Installation # we can not use synchronous invocation because the reference to a job is # needed results = service.InstallFromSoftwareIdentity( Source=package.path if isinstance(package, LMIInstance) else package, Collection=ns.LMI_SystemSoftwareCollection.first_instance_name(), InstallOptions=options) nevra = get_package_nevra(package) if results.rval != 4096: msg = 'Failed to %s package "%s" (rval=%d).' % ( 'update' if update else 'install', nevra, results.rval) if results.errorstr: msg += ': ' + results.errorstr raise LmiFailed(msg) job = results.rparams['Job'].to_instance() _wait_for_job_finished(job) if not LMIJob.lmi_is_job_completed(job): if not update: if not isinstance(package, LMIInstance): try: package = package.to_instance() except pywbem.CIMError: pass if getattr(package, 'InstallDate', None) is not None: raise LmiFailed('Package "%s" is already installed!' % nevra) msg = 'Failed to %s package "%s".' % ( 'update' if update else 'install', nevra) if job.ErrorDescription: msg += ': ' + job.ErrorDescription raise LmiFailed(msg) else: LOG().info('Installed package "%s" on remote host "%s".', nevra, ns.connection.uri) installed = job.associators( Role='AffectingElement', ResultRole='AffectedElement', AssocClass="LMI_AffectedSoftwareJobElement", ResultClass='LMI_SoftwareIdentity') if len(installed) < 1: raise LmiFailed('Failed to find installed package "%s".' % nevra) if len(installed) > 1: LOG().warn('Expected just one affected software identity, got: %s', {get_package_nevra(p) for p in installed}) return installed[-1]