From 1f630443252840ff8fc6e1b590b50723688a79e8 Mon Sep 17 00:00:00 2001 From: Adrian Likins Date: Thu, 26 Jun 2008 12:42:06 -0400 Subject: add "glob" method to rpm minion module, and add test cases patch from Pradeep Kilambi (with a small change to handle arch being "None" for gpg-pubkey packages) --- func/minion/modules/rpms.py | 25 +++++++++++++++++++++++++ test/unittest/test_client.py | 32 +++++++++++++++++++++++++++++++- 2 files changed, 56 insertions(+), 1 deletion(-) diff --git a/func/minion/modules/rpms.py b/func/minion/modules/rpms.py index ae26cb4..66d9129 100644 --- a/func/minion/modules/rpms.py +++ b/func/minion/modules/rpms.py @@ -42,3 +42,28 @@ class RpmModule(func_module.FuncModule): else: results.append([name, epoch, version, release, arch]) return results + + def glob(self, pattern, flatten=True): + """ + Return a list of installed packages that match a pattern + """ + ts = rpm.TransactionSet() + mi = ts.dbMatch() + results = [] + if not mi: + return + mi.pattern('name', rpm.RPMMIRE_GLOB, pattern) + for hdr in mi: + name = hdr['name'] + epoch = (hdr['epoch'] or 0) + version = hdr['version'] + release = hdr['release'] + # gpg-pubkeys have no arch + arch = (hdr['arch'] or "") + + if flatten: + results.append("%s %s %s %s %s" % (name, epoch, version, + release, arch)) + else: + results.append([name, epoch, version, release, arch]) + return results diff --git a/test/unittest/test_client.py b/test/unittest/test_client.py index 1a3f7cd..eae7746 100644 --- a/test/unittest/test_client.py +++ b/test/unittest/test_client.py @@ -49,7 +49,6 @@ class BaseTest: def test_module_get_method_args(self): mod = getattr(self.overlord,self.module) arg_result=mod.get_method_args() - print arg_result self.assert_on_fault(arg_result) def test_module_inventory(self): @@ -312,6 +311,37 @@ class TestRpm(BaseTest): result = self.overlord.rpms.inventory() self.assert_on_fault(result) + def test_glob(self): + # if func is running, there should at least be python installed ;-> + result = self.overlord.rpms.glob("python*", False) + self.assert_on_fault(result) + + def test_glob_flatten(self): + result = self.overlord.rpms.glob("python*", True) + self.assert_on_fault(result) + + def test_glob_nomatch(self): + # shouldn't be any rpms called "-" ;-> + result = self.overlord.rpms.glob("-*") + self.assert_on_fault(result) + + def test_glob_gpg_pubkey(self): + # gpg-pubkey packages are weird rpm virtual packages, and tend to do + # weird things, so try that too + result = self.overlord.rpms.glob("gpg-pubkey*") + self.assert_on_fault(result) + + def test_glob_gpg_pubkey_no_flat(self): + # gpg-pubkey packages are weird rpm virtual packages, and tend to do + # weird things, so try that too + result = self.overlord.rpms.glob("gpg-pubkey*", False) + self.assert_on_fault(result) + + def test_glob_match_all(self): + result = self.overlord.rpms.glob("*", False) + self.assert_on_fault(result) + + class TestSmart(BaseTest): module = "smart" -- cgit