Skip to content

Commit

Permalink
monitor: Skip repo errors involving CDROM/file source
Browse files Browse the repository at this point in the history
When using the rhsm command anaconda first tries the cdrom, and when it
fails then tries the CDN. This causes lorax-composer to see the repo
failure and exit too early, preventing it from working with rhsm.

This should never show up during normal lmc usage, so it's safe to skip.
Includes new tests in LogMonitorTest

(cherry picked from commit df6cdfd)

Resolves: RHEL-4658
  • Loading branch information
bcl committed Jul 18, 2024
1 parent 37af69f commit 1b73b53
Show file tree
Hide file tree
Showing 2 changed files with 71 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/pylorax/monitor.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,8 @@ class LogRequestHandler(socketserver.BaseRequestHandler):
]

re_tests = [
r"packaging: base repo .* not valid",
r"Process [0-9]+ \(anaconda\) of user [0-9]+ dumped core",
r"packaging: base repo (?!\(CDROM/file).* not valid",
r"packaging: .* requires .*"
]

Expand Down
69 changes: 69 additions & 0 deletions tests/pylorax/test_monitor.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
import socket
import time
import unittest

from pylorax.monitor import LogMonitor

class LogMonitorTest(unittest.TestCase):
def test_monitor(self):
monitor = LogMonitor(timeout=1)
try:
with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as s:
s.connect((monitor.host, monitor.port))
s.sendall("Just a test string\nwith two and a half\nlines in it".encode("utf8"))
time.sleep(1)
self.assertFalse(monitor.server.log_check())
s.sendall("\nAnother line\nTraceback (Not a real traceback)\n".encode("utf8"))
time.sleep(1)
self.assertTrue(monitor.server.log_check())
self.assertEqual(monitor.server.error_line, "Traceback (Not a real traceback)")
finally:
monitor.shutdown()

def test_monitor_repo(self):
monitor = LogMonitor(timeout=1)
try:
with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as s:
s.connect((monitor.host, monitor.port))
# Test a base repo cdrom failure
# This does NOT cause an error, it can happen when using rhsm in the kickstart
s.sendall("18:10:59,811 ERR anaconda:packaging: base repo (CDROM/file:///run/install/sources/mount-0000-cdrom) not valid -- removing it\n".encode("utf8"))
time.sleep(1)
self.assertFalse(monitor.server.log_check())

# Test a base repo failure message
s.sendall("18:10:59,811 ERR anaconda:packaging: base repo (https://foo.bar) not valid -- removing it\n".encode("utf8"))
time.sleep(1)
self.assertTrue(monitor.server.log_check())
finally:
monitor.shutdown()

def test_monitor_IGNORED(self):
monitor = LogMonitor(timeout=1)
try:
with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as s:
s.connect((monitor.host, monitor.port))
s.sendall("Just a test string\nwith two and a half\nlines in it".encode("utf8"))
time.sleep(1)
self.assertFalse(monitor.server.log_check())
s.sendall("\nAnother line\nIGNORED: Traceback (Not a real traceback)\n".encode("utf8"))
time.sleep(1)
self.assertFalse(monitor.server.log_check())
self.assertEqual(monitor.server.error_line, "")
finally:
monitor.shutdown()

def test_monitor_timeout(self):
# Timeout is in minutes so to shorten the test we pass 0.1
monitor = LogMonitor(timeout=0.1)
try:
with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as s:
s.connect((monitor.host, monitor.port))
s.sendall("Just a test string\nwith two and a half\nlines in it".encode("utf8"))
time.sleep(1)
self.assertFalse(monitor.server.log_check())
time.sleep(7)
self.assertTrue(monitor.server.log_check())
self.assertEqual(monitor.server.error_line, "")
finally:
monitor.shutdown()

0 comments on commit 1b73b53

Please sign in to comment.