a8f280f24d
Fix service file for openSUSE:Factory OBS-URL: https://build.opensuse.org/request/show/541865 OBS-URL: https://build.opensuse.org/package/show/systemsmanagement:saltstack/salt?expand=0&rev=99
60 lines
1.5 KiB
Python
60 lines
1.5 KiB
Python
#!/usr/bin/python3
|
|
#
|
|
# Copyright (c) 2016 SUSE Linux LLC
|
|
# All Rights Reserved.
|
|
#
|
|
# Author: Bo Maryniuk <bo@suse.de>
|
|
|
|
import sys
|
|
import os
|
|
import hashlib
|
|
|
|
from zypp_plugin import Plugin
|
|
|
|
|
|
class DriftDetector(Plugin):
|
|
"""
|
|
Return diff of the installed packages outside the Salt.
|
|
"""
|
|
def __init__(self):
|
|
Plugin.__init__(self)
|
|
self.ck_path = "/var/cache/salt/minion/rpmdb.cookie"
|
|
self.rpm_path = "/var/lib/rpm/Packages"
|
|
|
|
def _get_mtime(self):
|
|
'''
|
|
Get the modified time of the RPM Database.
|
|
Returns:
|
|
Unix ticks
|
|
'''
|
|
return os.path.exists(self.rpm_path) and int(os.path.getmtime(self.rpm_path)) or 0
|
|
|
|
def _get_checksum(self):
|
|
'''
|
|
Get the checksum of the RPM Database.
|
|
Returns:
|
|
hexdigest
|
|
'''
|
|
digest = hashlib.md5()
|
|
with open(self.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 PLUGINEND(self, headers, body):
|
|
"""
|
|
Hook when plugin closes Zypper's transaction.
|
|
"""
|
|
if 'SALT_RUNNING' not in os.environ:
|
|
with open(self.ck_path, 'w') as ck_fh:
|
|
ck_fh.write('{chksum} {mtime}\n'.format(chksum=self._get_checksum(), mtime=self._get_mtime()))
|
|
|
|
self.ack()
|
|
|
|
|
|
DriftDetector().main()
|