Add YUM plugin

* Add plugin for Yum-Salt integration
* Add configuration for the yumnotify plugin
* Fixes wrong 'enabled' opts for yumnotify plugin
This commit is contained in:
Bo Maryniuk 2016-09-29 17:00:14 +02:00 committed by Pablo Suárez Hernández
parent 22d884f478
commit a27415c4cc
3 changed files with 77 additions and 0 deletions

View file

@ -0,0 +1,20 @@
## What it is
Plugin which provides a notification mechanism to Salt, if Yum is
used outside of it.
## Installation
Configuration files are going to:
`/etc/yum/pluginconf.d/[name].conf`
Plugin itself goes to:
`/usr/share/yum-plugins/[name].conf`
## Permissions
User: root
Group: root
Mode: 644

View file

@ -0,0 +1,2 @@
[main]
enabled=1

View file

@ -0,0 +1,55 @@
# Copyright (c) 2016 SUSE Linux LLC
# All Rights Reserved.
#
# Author: Bo Maryniuk <bo@suse.de>
from yum.plugins import TYPE_CORE
from yum import config
import os
import hashlib
CK_PATH = "/var/cache/salt/minion/rpmdb.cookie"
RPM_PATH = "/var/lib/rpm/Packages"
requires_api_version = '2.5'
plugin_type = TYPE_CORE
def _get_mtime():
"""
Get the modified time of the RPM Database.
Returns:
Unix ticks
"""
return os.path.exists(RPM_PATH) and int(os.path.getmtime(RPM_PATH)) or 0
def _get_checksum():
"""
Get the checksum of the RPM Database.
Returns:
hexdigest
"""
digest = hashlib.md5()
with open(RPM_PATH, "rb") as rpm_db_fh:
while True:
buff = rpm_db_fh.read(0x1000)
if not buff:
break
digest.update(buff)
return digest.hexdigest()
def posttrans_hook(conduit):
"""
Hook after the package installation transaction.
:param conduit:
:return:
"""
# Integrate Yum with Salt
if 'SALT_RUNNING' not in os.environ:
with open(CK_PATH, 'w') as ck_fh:
ck_fh.write('{chksum} {mtime}\n'.format(chksum=_get_checksum(), mtime=_get_mtime()))