Skip to content

Commit

Permalink
Merge pull request #694 from shundhammer/huha-dump-yaml
Browse files Browse the repository at this point in the history
Copy storage-ng XML / YAML devicegraph dump files to installation target system
  • Loading branch information
shundhammer committed May 3, 2018
2 parents 81bb0d4 + f666200 commit a5e1c8c
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 19 deletions.
7 changes: 7 additions & 0 deletions package/yast2-installation.changes
@@ -1,3 +1,10 @@
-------------------------------------------------------------------
Wed May 2 15:44:18 UTC 2018 - shundhammer@suse.com

- Copy new /var/log/YaST2/storage-inst/ subdir to target at the
end of the installation (part of fate #318196)
- 4.0.56

-------------------------------------------------------------------
Fri Apr 27 15:07:15 UTC 2018 - igonzalezsosa@suse.com

Expand Down
2 changes: 1 addition & 1 deletion package/yast2-installation.spec
Expand Up @@ -16,7 +16,7 @@
#

Name: yast2-installation
Version: 4.0.55
Version: 4.0.56
Release: 0

BuildRoot: %{_tmppath}/%{name}-%{version}-build
Expand Down
40 changes: 26 additions & 14 deletions src/lib/installation/copy_logs_finish.rb
Expand Up @@ -47,6 +47,8 @@ def modes
end

PREFIX_SIZE = "y2log-".size
STORAGE_DUMP_DIR = "storage-inst".freeze

def write
log_files = Yast::WFM.Read(Yast::Path.new(".local.dir"), Yast::Directory.logdir)

Expand All @@ -70,38 +72,48 @@ def write
)
# call gzip with -f to avoid stuck during race condition when log
# rotator also gzip file and gzip then wait for input (bnc#897091)
compress_cmd = "gzip -f #{target_path}"
log.debug "Compress command: #{compress_cmd}"
Yast::WFM.Execute(LOCAL_BASH, compress_cmd)
shell_cmd("/usr/bin/gzip -f '#{target_path}'")
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-*
when "pbl.log"
copy_log_to_target("pbl.log", "pbl-instsys.log")
when STORAGE_DUMP_DIR
copy_storage_inst_subdir
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}"
def copy_log_to_target(src_file, dest_file = src_file)
shell_cmd("/bin/cp '#{src_dir}/#{src_file}' '#{dest_dir}/#{dest_file}'")
end

def copy_storage_inst_subdir
return if dest_dir == "/"
shell_cmd("/bin/rm -rf '#{dest_dir}/#{STORAGE_DUMP_DIR}'")
shell_cmd("/bin/cp -r '#{src_dir}/#{STORAGE_DUMP_DIR}' '#{dest_dir}/#{STORAGE_DUMP_DIR}'")
end

def src_dir
Yast::Directory.logdir
end

log.info "copy log with '#{command}'"
def dest_dir
File.join(Yast::Installation.destdir, Yast::Directory.logdir)
end

Yast::WFM.Execute(LOCAL_BASH, command)
def shell_cmd(cmd)
log.info("Executing #{cmd}")
Yast::WFM.Execute(LOCAL_BASH, cmd)
end
end
end
19 changes: 15 additions & 4 deletions test/copy_logs_finish_test.rb
Expand Up @@ -8,6 +8,8 @@
describe "#write" do
before do
allow(Yast::WFM).to receive(:Execute)
# Set the target dir to /mnt
allow(Yast::WFM).to receive(:Args).and_return("initial")
end

def mock_log_dir(files)
Expand All @@ -21,15 +23,15 @@ def expect_to_run(cmd)
it "copies logs from instalation to target system" do
mock_log_dir(["y2start.log"])

expect_to_run(/cp .*y2start.log .*y2start.log/)
expect_to_run(/cp .*y2start.log.*y2start.log/)

subject.write
end

it "rotates y2log" do
mock_log_dir(["y2log-1.gz"])

expect_to_run(/cp .*y2log-1.gz .*y2log-2.gz/)
expect_to_run(/cp .*y2log-1.gz.*y2log-2.gz/)

subject.write
end
Expand All @@ -42,7 +44,7 @@ def expect_to_run(cmd)
subject.write
end

it "does not stuck during compress if file already exists (bnc#897091)" do
it "does not get stuck during compress if file already exists (bnc#897091)" do
mock_log_dir(["y2log-1"])

expect_to_run(/gzip -f/)
Expand All @@ -53,7 +55,16 @@ def expect_to_run(cmd)
it "rotates zypp.log" do
mock_log_dir(["zypp.log"])

expect_to_run(/cp .*zypp.log .*zypp.log-1/)
expect_to_run(/cp .*zypp.log.*zypp.log-1/)

subject.write
end

it "copies the storage-inst subdir" do
mock_log_dir(["storage-inst"])

expect_to_run(/rm -rf .*storage-inst/)
expect_to_run(/cp -r .*storage-inst/)

subject.write
end
Expand Down

0 comments on commit a5e1c8c

Please sign in to comment.