Skip to content

Commit

Permalink
Improve tracer upload
Browse files Browse the repository at this point in the history
  • Loading branch information
sbernhard committed Jul 28, 2021
1 parent 3a6c91b commit 5168be0
Show file tree
Hide file tree
Showing 5 changed files with 70 additions and 40 deletions.
19 changes: 2 additions & 17 deletions src/apt_plugins/tracer_upload.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,29 +12,14 @@
from os import path, environ
import logging
from katello.tracer import upload_tracer_profile
from katello.apt_tracer import collect_apps


# The file is created by /etc/kernel/postinst.d/unattended-upgrades (part of unattended-upgrades pkg)
REBOOT_NEEDED_FLAG = "/var/run/reboot-required"

class TracerApp:
pass

class TracerUpload:
def collect_apps(self, _plugin):
apps = []
if path.isfile(REBOOT_NEEDED_FLAG):
app = TracerApp()
app.name = "kernel"
app.helper = "You will have to reboot your computer"
app.type = "static"
apps.append(app)
return apps

def send(self):
logging.info("Uploading Tracer Profile")
try:
upload_tracer_profile(self.collect_apps)
upload_tracer_profile(collect_apps)
except:
logging.error("Unable to upload Tracer Profile")

Expand Down
20 changes: 20 additions & 0 deletions src/katello/apt_tracer.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
from __future__ import absolute_import
from os import path

# The file is created by /etc/kernel/postinst.d/unattended-upgrades (part of unattended-upgrades pkg)
REBOOT_NEEDED_FLAG = "/var/run/reboot-required"


class AptTracerApp:
pass


def collect_apps(plugin=None):
apps = []
if path.isfile(REBOOT_NEEDED_FLAG):
app = AptTracerApp()
app.name = "kernel"
app.helper = "You will have to reboot your computer"
app.type = "static"
apps.append(app)
return apps
32 changes: 26 additions & 6 deletions src/katello/tracer.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,28 @@
from __future__ import absolute_import

from katello.uep import get_uep, lookup_consumer_id
import sys

from katello.uep import get_uep, lookup_consumer_id
try:
import apt
from katello.apt_tracer import collect_apps
except ImportError as e:
apt = None

try:
from tracer.query import Query
import dnf
except ImportError:
pass
dnf = None

try:
import yum
except ImportError:
yum = None

try:
import zypp
from katello.zypper_tracer import collect_apps
except ImportError:
zypp = None


def upload_tracer_profile(queryfunc, plugin=None):
Expand All @@ -22,8 +37,13 @@ def upload_tracer_profile(queryfunc, plugin=None):


def query_affected_apps(plugin=None):
query = Query()
return query.affected_applications().get()
if yum or dnf:
query = Query()
return query.affected_applications().get()
elif zypp or apt:
return collect_apps()
else:
raise Exception("Couldn't detect package manager. Failed to query affected apps!")


def get_apps(queryfunc, plugin=None):
Expand Down
20 changes: 20 additions & 0 deletions src/katello/zypper_tracer.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
from __future__ import absolute_import
from os import path

# The path is defined in zypper, see https://github.com/openSUSE/libzypp/blob/master/zypp/target/TargetImpl.cc
REBOOT_NEEDED_FLAG = "/var/run/reboot-needed"


class ZypperTracerApp:
pass


def collect_apps(plugin=None):
apps = []
if path.isfile(REBOOT_NEEDED_FLAG):
app = ZypperTracerApp()
app.name = "kernel"
app.helper = "You will have to reboot your computer"
app.type = "static"
apps.append(app)
return apps
19 changes: 2 additions & 17 deletions src/zypper_plugins/tracer_upload.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,32 +12,17 @@
from os import path, environ
import logging
from katello.tracer import upload_tracer_profile
from katello.zypper_tracer import collect_apps
from zypp_plugin import Plugin


# The path is defined in zypper, see https://github.com/openSUSE/libzypp/blob/master/zypp/target/TargetImpl.cc
REBOOT_NEEDED_FLAG = "/var/run/reboot-needed"

class ZypperTracerApp:
pass

class TracerUploadPlugin(Plugin):
def collect_apps(self, _plugin):
apps = []
if path.isfile(REBOOT_NEEDED_FLAG):
app = ZypperTracerApp()
app.name = "kernel"
app.helper = "You will have to reboot your computer"
app.type = "static"
apps.append(app)
return apps

def PLUGINEND(self, headers, body):
logging.info("PLUGINEND")

logging.info("Uploading Tracer Profile")
try:
upload_tracer_profile(self.collect_apps)
upload_tracer_profile(collect_apps)
except:
logging.error("Unable to upload Tracer Profile")

Expand Down

0 comments on commit 5168be0

Please sign in to comment.