diff options
author | Michal Minar <miminar@redhat.com> | 2012-10-10 17:55:12 +0200 |
---|---|---|
committer | Michal Minar <miminar@redhat.com> | 2012-10-10 17:55:12 +0200 |
commit | 2aa4f8635b13e1849763a1964eb45032ee30948c (patch) | |
tree | 3563082116a1a3464a365668505a4db68d55a20a /src/software/test/common.py | |
parent | 167c13bdf07c2a86ff7043b4b874073556858e69 (diff) | |
download | openlmi-providers-2aa4f8635b13e1849763a1964eb45032ee30948c.tar.gz openlmi-providers-2aa4f8635b13e1849763a1964eb45032ee30948c.tar.xz openlmi-providers-2aa4f8635b13e1849763a1964eb45032ee30948c.zip |
renamed yum package providers to software
renamed LMI_Yum* to LMI_Software*
removed attributes GroupString and LicenseString from LMI_SoftwarePackage
modified attributes Group, Architecture and License of
LMI_SoftwarePackage to return string instead of Uints
- because values and valuemaps would need frequent updates
Diffstat (limited to 'src/software/test/common.py')
-rw-r--r-- | src/software/test/common.py | 109 |
1 files changed, 109 insertions, 0 deletions
diff --git a/src/software/test/common.py b/src/software/test/common.py new file mode 100644 index 0000000..d88b2bb --- /dev/null +++ b/src/software/test/common.py @@ -0,0 +1,109 @@ +from collections import namedtuple +import os +import pywbem +import re +import subprocess +import unittest + +SCHEMA="http" +HOSTNAME="localhost" +PORT=5988 +USER='' +PASSWORD='' + +Package = namedtuple("Package", + "name, epoch, ver, rel, arch, " + "updatable, up_epoch, up_ver, up_rel") +# This is a database of packages used in tests. If you modify this, please +# ensure, that all corresponding rpm packages are present in test directory. +packages = [ Package(*args) for args in + ( ( "python-xlib-doc", "0", "0.15", "0.6.rc1.fc17", "noarch", False + , None, None, None) + , ( "slv2", "0", "0.6.6", "8.fc17", "x86_64", True + , "0", "0.6.6", "9.fc17") + ) ] + +pkg_files = ( + ( "bash-completion-1:2.0-1.fc17.noarch", + ( "/usr/share/bash-completion/completions/vgs" # symlink + , "/usr/share/doc/bash-completion-2.0/README" # file + , "/usr/share/doc/bash-completion-2.0" # directory + ) + , ) + , ) + +re_nevra = re.compile(r'^(?P<name>.+)-(?P<evra>(?P<epoch>\d+):(?P<ver>[^-]+)' + r'-(?P<rel>.+)\.(?P<arch>[^.]+))$') + +def make_nevra(name, epoch, ver, rel, arch, with_epoch='NOT_ZERO'): + """ + @param with_epoch may be one of: + "NOT_ZERO" - include epoch only if it's not zero + "ALWAYS" - include epoch always + "NEVER" - do not include epoch at all + """ + estr = '' + if with_epoch.lower() == "always": + estr = epoch + elif with_epoch.lower() == "not_zero": + if epoch != "0": + estr = epoch + if len(estr): estr += ":" + return "%s-%s%s-%s.%s" % (name, estr, ver, rel, arch) + +def remove_pkg(name, *args): + subprocess.call(["rpm", "--quiet"] + list(args) + ["-e", name]) + +def install_pkg(*args, **kwargs): + if len(args) > 1 or len(kwargs) > 0: + if kwargs.has_key('nevra'): + m = re_nevra.match(kwargs['nevra']) + args = [ m.group(k) for k in ( + 'name', 'epoch', 'ver', 'rel', 'arch') ] + nevra = make_nevra(*args, with_epoch="NEVER") + rpm_name = nevra + ".rpm" + if os.path.exists(rpm_name): + subprocess.call(["rpm", "--quiet", "-i", rpm_name]) + return + subprocess.call(["yum", "-q", "-y", "install", args[0]]) + +def is_installed(*args, **kwargs): + if len(args) == 1: + return subprocess.call(["rpm", "--quiet", "-q", args[0]]) == 0 + else: + if kwargs.has_key("nevra"): + nevra = kwargs["nevra"] + name = re_nevra.match(nevra).group('name') + else: + nevra = make_nevra(*args) + name = args[0] + try: + out = subprocess.check_output( + ["rpm", "-q", "--qf", "%{NEVRA}", name]) + return out == nevra + except subprocess.CalledProcessError: + return False + +def verify_pkg(name): + return subprocess.call(["rpm", "--quiet", "-Va", name]) == 0 + +class SoftwareBaseTestCase(unittest.TestCase): + + def setUp(self): + unittest.TestCase.setUp(self) + self.url = "%s://%s:%d" % (SCHEMA, HOSTNAME, PORT) + self.conn = pywbem.WBEMConnection(self.url, (USER, PASSWORD)) + self.op = pywbem.CIMInstanceName( + namespace="root/cimv2", classname=self.CLASS_NAME) + + def tearDown(self): + del self.conn + + def assertIsSubclass(self, cls, base_cls): + if not isinstance(cls, basestring): + raise TypeError("cls must be a string") + if not isinstance(base_cls, basestring): + raise TypeError("base_cls must be a string") + return self.assertTrue(pywbem.is_subclass(self.conn, + "root/cimv2", base_cls, cls)) + |