summaryrefslogtreecommitdiffstats
path: root/src/yum/providers/util/common.py
diff options
context:
space:
mode:
Diffstat (limited to 'src/yum/providers/util/common.py')
-rw-r--r--src/yum/providers/util/common.py60
1 files changed, 55 insertions, 5 deletions
diff --git a/src/yum/providers/util/common.py b/src/yum/providers/util/common.py
index 00f702f..16c10ff 100644
--- a/src/yum/providers/util/common.py
+++ b/src/yum/providers/util/common.py
@@ -28,6 +28,7 @@ import os
import platform
import pwd
import re
+import rpm
import socket
import stat
import pywbem
@@ -89,6 +90,7 @@ class YumDB(singletonmixin.Singleton):
self.update_db()
return getattr(self._yum, name)
+
def _get_distname():
if hasattr(platform, 'linux_distribution'):
return platform.linux_distribution(
@@ -132,6 +134,14 @@ def get_target_operating_system():
else:
return (0, 'Unknown')
+def get_computer_system_op():
+ return pywbem.CIMInstanceName(
+ classname='CIM_ComputerSystem',
+ keybindings={
+ "CreationClassName": "CIM_ComputerSystem"
+ , "Name" : socket.gethostname() },
+ namespace="root/cimv2")
+
def check_target_operating_system(system):
"""
@return if param system matches current target operating system
@@ -153,6 +163,37 @@ def check_target_operating_system(system):
return True
return False
+def check_computer_system_op(env, system):
+ if not isinstance(system, pywbem.CIMInstanceName):
+ raise pywbem.CIMError(pywbem.CIM_ERR_NOT_FOUND,
+ "\"System\" must be a CIMInstanceName")
+ our_system = get_computer_system_op()
+ if system.namespace != our_system.namespace:
+ raise pywbem.CIMError(pywbem.CIM_ERR_NOT_FOUND,
+ "\"System\" has wrong namespace")
+ ch = env.get_cimom_handle()
+ if not ch.is_subclass(system.namespace,
+ sub=system.classname,
+ super=our_system.classname):
+ raise pywbem.CIMError(pywbem.CIM_ERR_NOT_FOUND,
+ "Class of \"System\" must be a sublass of %s" %
+ our_system.classname)
+ if not 'CreationClassName' in system or not 'Name' in system:
+ raise pywbem.CIMError(pywbem.CIM_ERR_NOT_FOUND,
+ "\"System\" is missing one of keys")
+ if not ch.is_subclass(system.namespace,
+ sub=system['CreationClassName'],
+ super=our_system.classname):
+ raise pywbem.CIMError(pywbem.CIM_ERR_NOT_FOUND,
+ "CreationClassName of \"System\" must be a sublass of %s" %
+ our_system.classname)
+ if system['Name'] != our_system['Name']:
+ raise pywbem.CIMError(pywbem.CIM_ERR_NOT_FOUND,
+ "Name of \"System\" does not match \"%s\"" %
+ our_system['Name'])
+ return True
+
+
def match_pkg(pkg, **kwargs):
"""
all not Null and not empty arguments will be matched against pkg
@@ -668,6 +709,15 @@ class YumFileCheck:
yum.constants.RPM_CHECKSUM_TYPES.items())
@staticmethod
+ def pkg_checksum_type( pkg):
+ if not isinstance(pkg, yum.packages.YumAvailablePackage):
+ raise TypeError("pkg must be an instance of YumAvailablePackage")
+ if isinstance(pkg, yum.rpmsack.RPMInstalledPackage):
+ return pkg.hdr[rpm.RPMTAG_FILEDIGESTALGO]
+ with self: # ensure, that _yum is inited
+ return pkg.yumdb_info.checksum_type
+
+ @staticmethod
def checksumtype_num2hash(csumt):
return getattr(hashlib, yum.constants.RPM_CHECKSUM_TYPES[csumt])
@@ -818,8 +868,8 @@ class YumFileCheck:
"No matching package installed")
fi = pkg.hdr.fiFromHeader()
- vpkg = yum.packages._RPMVerifyPackage(
- pkg, fi, pkg.yumdb_info.checksum_type, [], True)
+ vpkg = yum.packages._RPMVerifyPackage(pkg, fi,
+ YumFileCheck.pkg_checksum_type(pkg), [], True)
if not op['Name'] in vpkg:
raise pywbem.CIMError(pywbem.CIM_ERR_NOT_FOUND,
"File not found in RPM package")
@@ -909,7 +959,8 @@ class YumFileCheck:
flags.append(v)
return flags
- def filecheck2model(vpkg, fn, env, keys_only=True, model=None, fc=None):
+ def filecheck2model(vpkg, fn, env, keys_only=True,
+ model=None, fc=None):
if not isinstance(vpkg, yum.packages._RPMVerifyPackage):
raise TypeError(
"vpkg must be an instance of _RPMVerifyPackage")
@@ -943,8 +994,7 @@ class YumFileCheck:
#model['InstanceID'] = '' # TODO
model['FileName'] = os.path.basename(vpf.filename)
model['ChecksumType'] = csumt = \
- YumFileCheck.checksumtype_str2pywbem(
- pkg.yumdb_info.checksum_type)
+ pywbem.Uint16(YumFileCheck.pkg_checksum_type(pkg))
if fc is None:
fc = YumFileCheck.test_file(env, csumt, vpf)
for mattr, fattr in (