summaryrefslogtreecommitdiffstats
path: root/src/yum/test/common.py
diff options
context:
space:
mode:
Diffstat (limited to 'src/yum/test/common.py')
-rw-r--r--src/yum/test/common.py109
1 files changed, 109 insertions, 0 deletions
diff --git a/src/yum/test/common.py b/src/yum/test/common.py
new file mode 100644
index 0000000..0da5695
--- /dev/null
+++ b/src/yum/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 YumBaseTestCase(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))
+