-
Notifications
You must be signed in to change notification settings - Fork 44
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
Fix log copy #252
Fix log copy #252
Changes from 7 commits
015db2a
7c098f8
78588b7
522e70c
dd87e2d
444db60
3e13c0f
4c3465e
48183d0
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,142 +1,3 @@ | ||
# encoding: utf-8 | ||
require "installation/copy_logs_finish" | ||
|
||
# ------------------------------------------------------------------------------ | ||
# Copyright (c) 2006-2012 Novell, Inc. All Rights Reserved. | ||
# | ||
# | ||
# This program is free software; you can redistribute it and/or modify it under | ||
# the terms of version 2 of the GNU General Public License as published by the | ||
# Free Software Foundation. | ||
# | ||
# This program is distributed in the hope that it will be useful, but WITHOUT | ||
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS | ||
# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. | ||
# | ||
# You should have received a copy of the GNU General Public License along with | ||
# this program; if not, contact Novell, Inc. | ||
# | ||
# To contact Novell about this file by physical or electronic mail, you may find | ||
# current contact information at www.novell.com. | ||
# ------------------------------------------------------------------------------ | ||
|
||
# File: | ||
# copy_logs_finish.ycp | ||
# | ||
# Module: | ||
# Step of base installation finish | ||
# | ||
# Authors: | ||
# Jiri Srain <jsrain@suse.cz> | ||
# | ||
# $Id$ | ||
# | ||
module Yast | ||
class CopyLogsFinishClient < Client | ||
include Yast::Logger | ||
|
||
def main | ||
Yast.import "UI" | ||
|
||
textdomain "installation" | ||
|
||
Yast.import "Directory" | ||
Yast.include self, "installation/misc.rb" | ||
|
||
@ret = nil | ||
@func = "" | ||
@param = {} | ||
|
||
# Check arguments | ||
if Ops.greater_than(Builtins.size(WFM.Args), 0) && | ||
Ops.is_string?(WFM.Args(0)) | ||
@func = Convert.to_string(WFM.Args(0)) | ||
if Ops.greater_than(Builtins.size(WFM.Args), 1) && | ||
Ops.is_map?(WFM.Args(1)) | ||
@param = Convert.to_map(WFM.Args(1)) | ||
end | ||
end | ||
|
||
log.info "starting copy_logs_finish" | ||
log.debug "func=#{@func}" | ||
log.debug "param=#{@param}" | ||
|
||
if @func == "Info" | ||
return { | ||
"steps" => 1, | ||
# progress step title | ||
"title" => _( | ||
"Copying log files to installed system..." | ||
), | ||
"when" => [:installation, :live_installation, :update, :autoinst] | ||
} | ||
elsif @func == "Write" | ||
@log_files = Convert.convert( | ||
WFM.Read(path(".local.dir"), Directory.logdir), | ||
:from => "any", | ||
:to => "list <string>" | ||
) | ||
|
||
Builtins.foreach(@log_files) do |file| | ||
log.debug "Processing file #{file}" | ||
|
||
if file == "y2log" || Builtins.regexpmatch(file, "^y2log-[0-9]+$") | ||
# Prepare y2log, y2log-* for log rotation | ||
|
||
target_no = 1 | ||
|
||
if Ops.greater_than(Builtins.size(file), Builtins.size("y2log-")) | ||
target_no = Ops.add( | ||
1, | ||
Builtins.tointeger( | ||
Builtins.substring(file, Builtins.size("y2log-"), 5) | ||
) | ||
) | ||
end | ||
|
||
target_basename = Builtins.sformat("y2log-%1", target_no) | ||
InjectRenamedFile(Directory.logdir, file, target_basename) | ||
|
||
compress_cmd = Builtins.sformat( | ||
"gzip %1/%2/%3", | ||
Installation.destdir, | ||
Directory.logdir, | ||
target_basename | ||
) | ||
log.debug "Compress command: #{compress_cmd}" | ||
WFM.Execute(path(".local.bash"), compress_cmd) | ||
elsif Builtins.regexpmatch(file, "^y2log-[0-9]+\\.gz$") | ||
target_no = Ops.add( | ||
1, | ||
Builtins.tointeger( | ||
Builtins.regexpsub(file, "y2log-([0-9]+)\\.gz", "\\1") | ||
) | ||
) | ||
InjectRenamedFile( | ||
Directory.logdir, | ||
file, | ||
Builtins.sformat("y2log-%1.gz", target_no) | ||
) | ||
elsif file == "zypp.log" | ||
# Save zypp.log from the inst-sys | ||
InjectRenamedFile(Directory.logdir, file, "zypp.log-1") # not y2log, y2log-* | ||
else | ||
InjectFile(Ops.add(Ops.add(Directory.logdir, "/"), file)) | ||
end | ||
end | ||
|
||
copy_cmd = "/bin/cp /var/log/pbl.log '#{Installation.destdir}/#{Directory.logdir}/pbl-instsys.log'" | ||
log.debug "Copy command: #{copy_cmd}" | ||
WFM.Execute(path(".local.bash"), copy_cmd) | ||
else | ||
log.error "unknown function: #{@func}" | ||
@ret = nil | ||
end | ||
|
||
log.debug "ret=#{@ret}" | ||
log.info "copy_logs_finish finished" | ||
deep_copy(@ret) | ||
end | ||
end | ||
end | ||
|
||
Yast::CopyLogsFinishClient.new.main | ||
::Installation::CopyLogsFinish.run |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,107 @@ | ||
# ------------------------------------------------------------------------------ | ||
# Copyright (c) 2006-2015 Novell, Inc. All Rights Reserved. | ||
# | ||
# | ||
# This program is free software; you can redistribute it and/or modify it under | ||
# the terms of version 2 of the GNU General Public License as published by the | ||
# Free Software Foundation. | ||
# | ||
# This program is distributed in the hope that it will be useful, but WITHOUT | ||
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS | ||
# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. | ||
# | ||
# You should have received a copy of the GNU General Public License along with | ||
# this program; if not, contact Novell, Inc. | ||
# | ||
# To contact Novell about this file by physical or electronic mail, you may find | ||
# current contact information at www.novell.com. | ||
# ------------------------------------------------------------------------------ | ||
|
||
require "yast" | ||
|
||
require "installation/finish_client" | ||
|
||
module Installation | ||
class CopyLogsFinish < ::Installation::FinishClient | ||
include Yast::I18n | ||
|
||
LOCAL_BASH = Yast::Path.new(".local.bash") | ||
|
||
def initialize | ||
textdomain "installation" | ||
|
||
Yast.import "Directory" | ||
Yast.import "Installation" | ||
end | ||
|
||
def steps | ||
1 | ||
end | ||
|
||
def title | ||
_("Copying log files to installed system...") | ||
end | ||
|
||
def modes | ||
[:installation, :live_installation, :update, :autoinst] | ||
end | ||
|
||
def write | ||
log_files = Yast::WFM.Read(Yast::Path.new(".local.dir"), Yast::Directory.logdir) | ||
|
||
log_files.each do |file| | ||
log.debug "Processing file #{file}" | ||
|
||
case file | ||
when "y2log", /\Ay2log-\d+\z/ | ||
# Prepare y2log, y2log-* for log rotation | ||
target_no = 1 | ||
|
||
if file != "y2log" | ||
prefix_size = "y2log-".size | ||
target_no = file[prefix_size..-1].to_i + 1 | ||
end | ||
|
||
target_basename = "y2log-#{target_no}" | ||
copy_log_to_target(file, target_basename) | ||
|
||
target_path = ::File.join( | ||
Yast::Installation.destdir, | ||
Yast::Directory.logdir, | ||
target_basename | ||
) | ||
compress_cmd = "gzip -f #{target_path}" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe a comment here to justify the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. good idea 👍 |
||
log.debug "Compress command: #{compress_cmd}" | ||
Yast::WFM.Execute(LOCAL_BASH, compress_cmd) | ||
when /\Ay2log-\d+\.gz\z/ | ||
target_no = file[/y2log-(\d+)/, 1].to_i + 1 | ||
copy_log_to_target(file, "y2log-#{target_no}.gz") | ||
when "zypp.log" | ||
# Save zypp.log from the inst-sys | ||
copy_log_to_target(file, "zypp.log-1") # not y2log, y2log-* | ||
else | ||
copy_log_to_target(file) | ||
end | ||
end | ||
|
||
copy_cmd = "/bin/cp /var/log/pbl.log '#{Yast::Installation.destdir}/#{Yast::Directory.logdir}/pbl-instsys.log'" | ||
log.debug "Copy command: #{copy_cmd}" | ||
Yast::WFM.Execute(LOCAL_BASH, copy_cmd) | ||
|
||
nil | ||
end | ||
|
||
private | ||
|
||
def copy_log_to_target(src_file, dst_file = src_file) | ||
dir = Yast::Directory.logdir | ||
src_path = "#{dir}/#{src_file}" | ||
dst_path = "#{Yast::Installation.destdir}/#{dir}/#{dst_file}" | ||
command = "/bin/cp #{src_path} #{dst_path}" | ||
|
||
log.info "copy log with '#{command}'" | ||
|
||
Yast::WFM.Execute(LOCAL_BASH, command) | ||
end | ||
end | ||
end |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
#! /usr/bin/env rspec | ||
|
||
require_relative "./test_helper" | ||
|
||
require "installation/copy_logs_finish" | ||
|
||
describe ::Installation::CopyLogsFinish do | ||
describe "#write" do | ||
before do | ||
allow(Yast::WFM).to receive(:Execute) | ||
end | ||
|
||
it "copies logs from instalation to target system" do | ||
allow(Yast::WFM).to receive(:Read).and_return(["y2start.log"]) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Without reading the implementation code, the purpose of this What about using There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I am also considering it and if you get same idea I will do it. |
||
|
||
expect(Yast::WFM).to receive(:Execute).with(anything(), /cp/).at_least(:once) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The y2start.log returned by the previous call is not used in the expectation. Feels strange. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. fair comment. I will add it. |
||
|
||
subject.write | ||
end | ||
|
||
it "rotate y2log" do | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. rotates :-) |
||
allow(Yast::WFM).to receive(:Read).and_return(["y2log-1.gz"]) | ||
|
||
expect(Yast::WFM).to receive(:Execute).with(anything(), /cp .*y2log-1.gz .*y2log-2.gz/) | ||
|
||
subject.write | ||
end | ||
|
||
it "compress y2log if not already done" do | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. "compresses"... and "does" (in the next one) and "rotates" (last one). |
||
allow(Yast::WFM).to receive(:Read).and_return(["y2log-1"]) | ||
|
||
expect(Yast::WFM).to receive(:Execute).with(anything(), /gzip .*y2log-2/) #-2 due to rotation | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. yep, maybe time to finally find time to have generic rspec helper for SCR in yast2 or ruby bindings |
||
|
||
subject.write | ||
end | ||
|
||
it "do not stuck during compress if file already exists (bnc#897091)" do | ||
allow(Yast::WFM).to receive(:Read).and_return(["y2log-1"]) | ||
|
||
expect(Yast::WFM).to receive(:Execute).with(anything(), /gzip -f/) | ||
|
||
subject.write | ||
end | ||
|
||
it "rotate zypp.log" do | ||
allow(Yast::WFM).to receive(:Read).and_return(["zypp.log"]) | ||
|
||
expect(Yast::WFM).to receive(:Execute).with(anything(), /cp .*zypp.log .*zypp.log-1/) | ||
|
||
subject.write | ||
end | ||
end | ||
end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just asking. Do we have any convention on naming all these clients living under
lib/installation
? Like always usingWhateverFinish
for clients inheriting fromFinishClient
?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
actually no convention...in bootloader it is simple
Bootloader/FinishClient
but here it can create collisions so I name it this way.CopyLogs
without finish can confuse reader as it can be seen as common class to copy logs from one place to another.