From bbac2c35fa6c361dfd54af949f4d38a11e72a323 Mon Sep 17 00:00:00 2001 From: Pino Toscano Date: Wed, 17 Apr 2024 15:30:49 +0200 Subject: [PATCH] test: break insights-client in a different way The sequence of events in the test is the following: 1) register with insights-client, a new machine-id is generated 2) the test moves away the machine-id file 3) a new data upload is triggered by starting the systemd service 4) insights-client eagerly generates a new machine-id file to check whether it is registered even if it is not the case (that's another issue, much harder to fix) 5) the newly generated machine-id has nothing associated to it 6) a proper warning is shown as expected 7) the original machine-id is restored 8) everything else continues as usual This worked fine until recent times, as the new machine-id always had a new UUID. After recent changes in insights-core [1], now the default machine-id generated by insights-client when the system is registered with subscription-manager is the subscription-manager UUID. Thus, the machine-id file generated during step (4) is now always the same, which then allows insights-client to query for its own details as if nothing happened. To break insights-client again, the changes are in the following step of the above sequence: 4) a new random UUID is written as machine-id file This new "wrong" machine-id file makes insights-client think that the status is not correct, and thus the test can keep going as expected. [1] https://github.com/RedHatInsights/insights-core/pull/4057 --- test/check-subscriptions | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/test/check-subscriptions b/test/check-subscriptions index deb8a4c..7442ac4 100755 --- a/test/check-subscriptions +++ b/test/check-subscriptions @@ -19,6 +19,7 @@ import os import sys import unittest +import uuid # import Cockpit's machinery for test VMs and its browser test API TEST_DIR = os.path.dirname(__file__) @@ -444,8 +445,10 @@ class TestSubscriptions(SubscriptionsCase): b.wait_visible("button:contains('Connected to Insights')") - # Break the next upload and expect the warning triangle to tell us about it - m.execute(["mv", "/etc/insights-client/machine-id", "/etc/insights-client/machine-id.lost"]) + # Break the next upload and expect the warning triangle to tell us about it; + # write over the original file so its SELinux attributes are preserved. + m.execute(["cp", "/etc/insights-client/machine-id", "/etc/insights-client/machine-id.orig"]) + m.write("/etc/insights-client/machine-id", str(uuid.uuid4())) m.execute(["systemctl", "start", "insights-client"]) with b.wait_timeout(60): @@ -456,7 +459,7 @@ class TestSubscriptions(SubscriptionsCase): b.click("button.cancel") # Unbreak it and retry. - m.execute(["mv", "/etc/insights-client/machine-id.lost", "/etc/insights-client/machine-id"]) + m.execute(["mv", "/etc/insights-client/machine-id.orig", "/etc/insights-client/machine-id"]) m.execute( "systemctl start insights-client; " "while systemctl --quiet is-active insights-client; do sleep 1; done",