Verification Method - Rpm Module

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hi, I create a method to verify the installed packages for the rpms module.

I checked python api and there isn't any build in method I could use, but I checked yum api and I found something interesting,

The output with the external command was:

S.?.....    /usr/sbin/groupmod
prelink: /usr/sbin/useradd: at least one of file's dependencies has changed since prelinking
S.?.....    /usr/sbin/useradd
prelink: /usr/sbin/userdel: at least one of file's dependencies has changed since prelinking
S.?.....    /usr/sbin/userdel
prelink: /usr/sbin/usermod: at least one of file's dependencies has changed since prelinking
S.?.....    /usr/sbin/usermod

While the output with the yum api is:

/usr/sbin/userdel - checksum does not match
/usr/sbin/userdel - size does not match
/usr/sbin/groupdel - checksum does not match
/usr/sbin/groupdel - size does not match
/etc/login.defs - mtime does not match
/etc/login.defs - checksum does not match
/etc/login.defs - size does not match
/usr/bin/newgrp - checksum does not match

Alikins: I would like your opinion for witch approach do I have to take, use the built in yum api or the external command ?

I intend to work now to allow the verification for only one package each time adding support for rpms.glob(). When its done the plan is to merge the yum module (hi guy[Varinder] from yum module, I hope your module will be ready soon) with the rpm module and create a new module called "packages".

My current code is:
http://func.pastebin.com/m523b93ac

   def verify(self, flatten=True):
   """
   Returns information of the verification of all installed packages.
   """
   import yum
   ts = rpm.TransactionSet()
   mi = ts.dbMatch()
   results = []
   for hdr in mi:
       name = hdr['name']
if flatten: yb = yum.YumBase()
       pkgs = yb.rpmdb.searchNevra(name)
       for pkg in pkgs:
           errors = pkg.verify()
           for fn in errors.keys():
           for prob in errors[fn]:
               results.append('%s %s %s' % (name, fn, prob.message))
   else:
       results.append("%s-%s-%s.%s" % (name, version, release, arch))
   return results



Feel free to give me some ideas or comments, thanks.




>
> A unified diff against git head is usually easier for me to deal with, or a url to a git repo with the changes > and a copy of the diff in the email is even better. Just makes reviewing things a little easier, and makes
> merging even easier.
>
>    comments inline
>>>
>>> ----------------------
>>>    def verify(self, flatten=True):
> I would add support for specifying a package name, or even better, a package glob. See the rpms.glob()
> method as an example.
>
>>>
>>>        """
>>> Returns information of the verification of all installed packages. """
>>>        import subprocess
>>>        ts = rpm.TransactionSet()
>>>        mi = ts.dbMatch()
>>>        results = []
>>>        for hdr in mi:
>>>            name = hdr['name']
>>>            if flatten:
>>>                   results.append("%s" % (name))
>>> proc = subprocess.Popen(['/bin/rpm -V '+ name], shell=True, stdout=subprocess.PIPE) > In this particular implementation, there isn't really any difference between the code above and just > shelling out to `rpm -Va`. That said, if you add the glob support, your approach is better.
>>>





>>>                   stdout_value = proc.communicate()[0]
>>>                   results.append("%s\n" % (stdout_value))
>>>            else:
>>>                   results.append([name])
> Not sure yet, but I think you may be losing data here in cases where multiple versions of the same package > is installed (say, a kernel, or just about any package on a x86_64 machine with i386 packages installed). > May be better to key the dict on something more unique (name-version-release.arch, for example)
>
> I'd also check to see if the rpm python api supports package verification directly now. I know it didn't > for a long time, but it may now. Though, it may not be very backwards compatible.
>
> Adrian
>


--




--------
Milton Paiva Neto
milton.paiva@xxxxxxxxx
mpaivaneto@xxxxxxxxxxxxxxxxxxx
http://miltonpaiva.wordpress.com/


diff --git a/func/func/minion/modules/rpms.py b/rpms.py
old mode 100644
new mode 100755
index 746b9b8..99cdd6d
--- a/func/func/minion/modules/rpms.py
+++ b/rpms.py
@@ -9,6 +9,7 @@
 # Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 
 import func_module
+import rpm
 
 class RpmModule(func_module.FuncModule):
 
@@ -26,7 +27,6 @@ class RpmModule(func_module.FuncModule):
         """
         # I have not been able to get flatten=False to work if there 
         # is more than 491 entries in the dict -- ashcrow
-	import rpm
         ts = rpm.TransactionSet()
         mi = ts.dbMatch()
         results = []
@@ -43,11 +43,32 @@ class RpmModule(func_module.FuncModule):
                 results.append([name, epoch, version, release, arch])
         return results
 
+    def verify(self, flatten=True):
+	"""
+	Returns information of the verification of all installed packages.
+	"""
+	import yum
+	ts = rpm.TransactionSet()
+	mi = ts.dbMatch()
+	results = []
+	for hdr in mi:
+	    name = hdr['name']
+	    if flatten:	    
+		yb = yum.YumBase()
+		pkgs = yb.rpmdb.searchNevra(name)
+		for pkg in pkgs:
+		    errors = pkg.verify()
+		    for fn in errors.keys():
+			for prob in errors[fn]:
+			    results.append('%s %s %s' % (name, fn, prob.message))
+	else:
+	    results.append("%s-%s-%s.%s" % (name, version, release, arch))
+	return results
+
     def glob(self, pattern, flatten=True):
         """
         Return a list of installed packages that match a pattern
         """
-	import rpm
         ts = rpm.TransactionSet()
         mi = ts.dbMatch()
         results = []
@@ -86,6 +107,17 @@ class RpmModule(func_module.FuncModule):
                         },
                     'description':"Returns information on all installed packages"
                     },
+		'verify':{
+                    'args':{
+                        'flatten':{
+                            'type':'boolean',
+                            'optional':True,
+                            'default':True,
+                            'description':"Print clean in difss"
+                            }
+                        },
+                    'description':"Returns information of the verification on all installed packages"
+                    },
                 'glob':{
                     'args':{
                         'pattern':{
# Copyright 2007, Red Hat, Inc
# Michael DeHaan <mdehaan@xxxxxxxxxx>
#
# This software may be freely redistributed under the terms of the GNU
# general public license.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.

import func_module
import rpm

class RpmModule(func_module.FuncModule):

    version = "0.0.1"
    api_version = "0.0.1"
    description = "RPM related commands."

    def inventory(self, flatten=True):
        """
        Returns information on all installed packages.
        By default, 'flatten' is passed in as True, which makes printouts very
        clean in diffs for use by func-inventory.  If you are writting another
        software application, using flatten=False will prevent the need to 
        parse the returns.
        """
        # I have not been able to get flatten=False to work if there 
        # is more than 491 entries in the dict -- ashcrow
        ts = rpm.TransactionSet()
        mi = ts.dbMatch()
        results = []
        for hdr in mi:
            name = hdr['name']
            epoch = (hdr['epoch'] or 0)
            version = hdr['version']
            release = hdr['release']
            arch = hdr['arch']
            if flatten:
                results.append("%s %s %s %s %s" % (name, epoch, version, 
                                                   release, arch))
            else:
                results.append([name, epoch, version, release, arch])
        return results

    def verify(self, flatten=True):
	"""
	Returns information of the verification of all installed packages.
	"""
	import yum
	ts = rpm.TransactionSet()
	mi = ts.dbMatch()
	results = []
	for hdr in mi:
	    name = hdr['name']
	    if flatten:	    
		yb = yum.YumBase()
		pkgs = yb.rpmdb.searchNevra(name)
		for pkg in pkgs:
		    errors = pkg.verify()
		    for fn in errors.keys():
			for prob in errors[fn]:
			    results.append('%s %s %s' % (name, fn, prob.message))
	else:
	    results.append("%s-%s-%s.%s" % (name, 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

    def register_method_args(self):
        """
        Implementing the method argument getter
        """

        return {
                'inventory':{
                    'args':{
                        'flatten':{
                            'type':'boolean',
                            'optional':True,
                            'default':True,
                            'description':"Print clean in difss"
                            }
                        },
                    'description':"Returns information on all installed packages"
                    },
		'verify':{
                    'args':{
                        'flatten':{
                            'type':'boolean',
                            'optional':True,
                            'default':True,
                            'description':"Print clean in difss"
                            }
                        },
                    'description':"Returns information of the verification on all installed packages"
                    },
                'glob':{
                    'args':{
                        'pattern':{
                            'type':'string',
                            'optional':False,
                            'description':"The glob packet pattern"
                            },
                        'flatten':{
                            'type':'boolean',
                            'optional':True,
                            'default':True,
                            'description':"Print clean in difss"
                                }
                        },
                    'description':"Return a list of installed packages that match a pattern"
                    }
                }
_______________________________________________
Func-list mailing list
Func-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/func-list

[Index of Archives]     [Fedora Users]     [Linux Networking]     [Fedora Legacy List]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]

  Powered by Linux