File kdump-nfs-directory.patch of Package cockpit

From 674f2fa74dbc7f5b98ea4977500bc9d21a1db6d8 Mon Sep 17 00:00:00 2001
From: Martin Pitt <mpitt@redhat.com>
Date: Thu, 23 Sep 2021 10:05:34 +0200
Subject: [PATCH] kdump: Show "Directory" field for NFS mounts

kdump.conf's `path=` option is relevant for NFS target as well: the
dump will be written to <nfs mount>/<path>. Thus, show the "Directory"
input for NFS as well. Fortunately the config writing logic is already
generic enough that everything else just works.

The full integration test TestNFS uncovers a bug in the service
handling: After trying to start the service with a broken configuration,
the service will fail. But it will not be restarted automatically after
changing (and potentially fixing) the configuration. Manually start it
in the test for now to work around this.

Add as similar test to TestKdump.testConfiguration() which can run in
downstream gating. Make the assertNotIn()s in this test stricter and
simpler.

https://bugzilla.redhat.com/show_bug.cgi?id=2004041
---
 pkg/kdump/kdump-view.jsx | 18 ++++++++++----
 test/verify/check-kdump  | 54 +++++++++++++++++++++++++++++++++++-----
 2 files changed, 61 insertions(+), 11 deletions(-)

diff --git a/pkg/kdump/kdump-view.jsx b/pkg/kdump/kdump-view.jsx
index 564c99ad17f..1a36adb0274 100644
--- a/pkg/kdump/kdump-view.jsx
+++ b/pkg/kdump/kdump-view.jsx
@@ -94,11 +94,19 @@ class KdumpTargetBody extends React.Component {
             if (this.props.settings && "nfs" in this.props.settings)
                 nfs = this.props.settings.nfs.value;
             detailRows = (
-                <FormGroup fieldId="kdump-settings-nfs-mount" label={_("Mount")}>
-                    <TextInput id="kdump-settings-nfs-mount" key="mount"
-                               placeholder="penguin.example.com:/export/cores" value={nfs}
-                               onChange={value => this.props.onChange("nfs", value)} />
-                </FormGroup>
+                <>
+                    <FormGroup fieldId="kdump-settings-nfs-mount" label={_("Mount")}>
+                        <TextInput id="kdump-settings-nfs-mount" key="mount"
+                                placeholder="penguin.example.com:/export/cores" value={nfs}
+                                onChange={value => this.props.onChange("nfs", value)} />
+                    </FormGroup>
+                    <FormGroup fieldId="kdump-settings-nfs-directory" label={_("Directory")}>
+                        <TextInput id="kdump-settings-nfs-directory" key="directory"
+                                placeholder="/var/crash" value={directory}
+                                data-stored={directory}
+                                onChange={value => this.props.onChange("path", value)} />
+                    </FormGroup>
+                </>
             );
         } else if (this.state.storeDest == "ssh") {
             var ssh = "";
diff --git a/test/verify/check-kdump b/test/verify/check-kdump
index 151941545d0..1468a9d25ff 100755
--- a/test/verify/check-kdump
+++ b/test/verify/check-kdump
@@ -202,14 +202,24 @@ class TestKdump(KdumpHelpers):
         b.click("#kdump-change-target")
         b.wait_visible("#kdump-settings-dialog")
         b.set_val("#kdump-settings-location", "nfs")
-        b.set_input_text("#kdump-settings-nfs-mount", "localhost:/var/tmp/crash")
+        b.set_input_text("#kdump-settings-nfs-mount", "someserver:/srv")
         b.click("button:contains('Apply')")
         b.wait_not_present("#kdump-settings-dialog")
         conf = m.execute("cat /etc/kdump.conf")
-        self.assertIn("nfs localhost:/var/tmp/crash", conf)
-        self.assertNotIn("path /var/tmp/crash", conf)
-        self.assertNotIn("ssh admin@localhost", conf)
-        self.assertNotIn("sshkey /home/admin/.ssh/id_rsa", conf)
+        self.assertIn("nfs someserver:/srv", conf)
+        # directory unspecified, using default path
+        self.assertNotIn("\npath ", conf)
+        self.assertNotIn("\nssh ", conf)
+
+        # NFS with custom path
+        b.click("#kdump-change-target")
+        b.wait_visible("#kdump-settings-dialog")
+        b.set_input_text("#kdump-settings-nfs-directory", "dumps")
+        b.click("button:contains('Apply')")
+        b.wait_not_present("#kdump-settings-dialog")
+        conf = m.execute("cat /etc/kdump.conf")
+        self.assertIn("nfs someserver:/srv", conf)
+        self.assertIn("\npath dumps", conf)
 
         # Check local location
         b.click("#kdump-change-target")
@@ -220,7 +230,7 @@ class TestKdump(KdumpHelpers):
         b.wait_not_present("#kdump-settings-dialog")
         conf = m.execute("cat /etc/kdump.conf")
         self.assertIn("path /var/tmp", conf)
-        self.assertNotIn("nfs localhost:/var/tmp/crash", conf)
+        self.assertNotIn("\nnfs ", conf)
 
         # Check compression
         current = m.execute("grep '^core_collector' /etc/kdump.conf").strip()
openSUSE Build Service is sponsored by