Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Autosave logs at the end of installation #887

Merged
merged 17 commits into from
Dec 4, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions rust/agama-cli/src/logs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ const DEFAULT_PATHS: [&str; 14] = [
"/linuxrc.config",
];

const DEFAULT_RESULT: &str = "/tmp/agama_logs";
const DEFAULT_RESULT: &str = "/tmp/agama-logs";
// what compression is used by default:
// (<compression as distinguished by tar>, <an extension for resulting archive>)
const DEFAULT_COMPRESSION: (&str, &str) = ("bzip2", "tar.bz2");
Expand Down Expand Up @@ -398,7 +398,11 @@ fn store(options: LogOptions) -> Result<(), io::Error> {
showln(verbose, "\t- proceeding output of commands");

// store it
showln(true, format!("Storing result in: \"{}\"", result).as_str());
if verbose {
showln(true, format!("Storing result in: \"{}\"", result).as_str());
} else {
showln(true, result.as_str());
}

for log in log_sources.iter() {
show(
Expand Down
2 changes: 1 addition & 1 deletion service/Gemfile.lock
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -73,4 +73,4 @@ DEPENDENCIES
yard (~> 0.9.0)

BUNDLED WITH
2.3.26
2.4.22
6 changes: 3 additions & 3 deletions service/lib/agama/dbus/manager.rb
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ def initialize(backend, logger)
dbus_method(:Probe, "") { config_phase }
dbus_method(:Commit, "") { install_phase }
dbus_method(:CanInstall, "out result:b") { can_install? }
dbus_method(:CollectLogs, "out tarball_filesystem_path:s, in user:s") { |u| collect_logs(u) }
dbus_method(:CollectLogs, "out tarball_filesystem_path:s") { collect_logs }
dbus_method(:Finish, "") { finish_phase }
dbus_reader :installation_phases, "aa{sv}"
dbus_reader :current_installation_phase, "u"
Expand Down Expand Up @@ -92,8 +92,8 @@ def can_install?
end

# Collects the YaST logs
def collect_logs(user)
backend.collect_logs(user)
def collect_logs
backend.collect_logs
end

# Last action for the installer
Expand Down
15 changes: 9 additions & 6 deletions service/lib/agama/manager.rb
Original file line number Diff line number Diff line change
Expand Up @@ -205,18 +205,21 @@ def valid?

# Collects the logs and stores them into an archive
#
# @param user [String] local username who will own archive
# @param path [String] directory where to store logs
#
# @return [String] path to created archive
def collect_logs(user)
output = Yast::Execute.locally!("save_y2logs", stderr: :capture)
path = output[/^.* (\/tmp\/y2log-\S*)/, 1]
Yast::Execute.locally!("chown", "#{user}:", path)
def collect_logs(path: nil)
opt = "-d #{path}" unless path.nil? || path.empty?

path
`agama logs store #{opt}`.strip
end

# Whatever has to be done at the end of installation
def finish_installation
logs = collect_logs(path: "/tmp/var/logs/")

logger.info("Installation logs stored in #{logs}")

cmd = if iguana?
"/usr/bin/agamactl -k"
else
Expand Down
11 changes: 5 additions & 6 deletions service/test/agama/manager_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -214,13 +214,12 @@

describe "#collect_logs" do
it "collects the logs and returns the path to the archive" do
expect(Yast::Execute).to receive(:locally!)
.with("save_y2logs", stderr: :capture)
.and_return("Saving YaST logs to /tmp/y2log-hWBn95.tar.xz")
expect(Yast::Execute).to receive(:locally!)
.with("chown", "ytm:", /y2log-hWBn95/)
# %x returns the command output including trailing \n
expect(subject).to receive(:`)
.with("agama logs store ")
.and_return("/tmp/y2log-hWBn95.tar.xz\n")

path = subject.collect_logs("ytm")
path = subject.collect_logs
expect(path).to eq("/tmp/y2log-hWBn95.tar.xz")
end
end
Expand Down
5 changes: 4 additions & 1 deletion setup-service.sh
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,9 @@ $SUDO zypper --non-interactive --gpg-auto-import-keys install gcc gcc-c++ make o
# only install cargo if it is not available (avoid conflicts with rustup)
which cargo || $SUDO zypper --non-interactive install cargo

# if agama is already running -> stop it
$SUDO systemctl stop agama.service

# - Install service rubygem dependencies
(
cd $MYDIR/service
Expand All @@ -70,7 +73,7 @@ $SUDO cp -v $MYDIR/service/share/dbus.conf /usr/share/dbus-1/agama.conf
# cleanup previous installation
[[ -d $DBUSDIR ]] && $SUDO rm -r $DBUSDIR

# create services
# create services
$SUDO mkdir -p $DBUSDIR
for SVC in org.opensuse.Agama*.service; do
sudosed "s@\(Exec\)=/usr/bin/@\1=$MYDIR/service/bin/@" $SVC $DBUSDIR/$SVC
Expand Down
7 changes: 6 additions & 1 deletion setup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,12 @@ fi

# Backend setup

$MYDIR/setup-service.sh
if ! $MYDIR/setup-service.sh; then
echo "Backend setup failed."
echo "Agama service is NOT running."

exit 2
fi;

# Install Frontend dependencies

Expand Down
2 changes: 1 addition & 1 deletion web/src/client/manager.js
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ class ManagerBaseClient {
*/
async fetchLogs() {
const proxy = await this.client.proxy(MANAGER_IFACE);
const path = await proxy.CollectLogs("root");
const path = await proxy.CollectLogs();
const file = cockpit.file(path, { binary: true });
return file.read();
}
Expand Down
2 changes: 1 addition & 1 deletion web/src/components/core/LogsButton.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import { Alert, Button } from "@patternfly/react-core";
import { Icon } from "~/components/layout";
import { _ } from "~/i18n";

const FILENAME = "y2logs.tar.xz";
const FILENAME = "agama-installation-logs.tar.bzip2";
const FILETYPE = "application/x-xz";

/**
Expand Down
2 changes: 1 addition & 1 deletion web/src/components/core/LogsButton.test.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ describe("LogsButton", () => {
// And test what we're looking for
expect(document.createElement).toHaveBeenCalledWith('a');
expect(anchorMock).toHaveAttribute("href", "fake-blob-url");
expect(anchorMock).toHaveAttribute("download", expect.stringMatching(/y2logs/));
expect(anchorMock).toHaveAttribute("download", expect.stringMatching(/agama-installation-logs/));
expect(anchorMock.click).toHaveBeenCalled();

// Be polite and restore document.createElement function,
Expand Down