Skip to content

Commit

Permalink
Do a cleanup of the profile being merged with
Browse files Browse the repository at this point in the history
  • Loading branch information
teclator committed Oct 11, 2018
1 parent 269ceaf commit 53134af
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 19 deletions.
31 changes: 16 additions & 15 deletions src/modules/AutoInstallRules.rb
Expand Up @@ -912,25 +912,26 @@ def merge_profiles(base_profile, with, to)
def Merge(result_profile)
base_profile = File.join(AutoinstConfig.tmpDir, "base_profile.xml")
merge_profile = File.join(AutoinstConfig.tmpDir, "result.xml")
cleaned_profile = File.join(AutoinstConfig.tmpDir, "current.xml")
ok = true
skip = false
error = false
@tomerge.each do |file|
@tomerge.each_with_index do |file, iter|
log.info("Working on file: #{file}")
current_profile = File.join(AutoinstConfig.local_rules_location, file)
if !skip
if !XML_cleanup(current_profile, base_profile)
log.error("Error reading XML file")
message = _(
"The XML parser reported an error while parsing the autoyast profile. The error message is:\n"
)
message += XML.XMLError
Yast2::Popup.show(message, headline: :error)
error = true
end
skip = true
elsif !error
xsltret = merge_profiles(base_profile, current_profile, merge_profile)
dest_profile = iter == 0 ? base_profile : cleaned_profile
if !XML_cleanup(current_profile, dest_profile)
log.error("Error reading XML file")
message = _(
"The XML parser reported an error while parsing the autoyast profile. The error message is:\n"
)
message += XML.XMLError
Yast2::Popup.show(message, headline: :error)
error = true
end

unless error
next if iter == 0
xsltret = merge_profiles(base_profile, cleaned_profile, merge_profile)

log.info("Merge result: #{xsltret}")
if xsltret["exit"] != 0 || xsltret.fetch("stderr", "") != ""
Expand Down
23 changes: 19 additions & 4 deletions test/AutoInstallRules_test.rb
Expand Up @@ -283,8 +283,10 @@
describe '#Merge' do
let(:tmp_dir) { File.join(root_path, 'tmp') }
let(:result_path) { File.join(tmp_dir, 'result.xml') }
let(:first_path) { File.join(tmp_dir, 'first.xml') }
let(:second_path) { File.join(tmp_dir, 'second.xml') }
let(:base_profile_path) { File.join(tmp_dir, 'base_profile.xml') }
let(:cleaned_profile_path) { File.join(tmp_dir, 'current.xml') }

around(:each) do |example|
FileUtils.rm_rf(tmp_dir) if Dir.exist?(tmp_dir)
Expand Down Expand Up @@ -317,12 +319,25 @@
end

context 'when two XML profiles are given' do
it 'merges two XML profiles' do
before do
subject.CreateFile("first.xml")
subject.CreateFile("second.xml")
expect(subject).to receive(:XML_cleanup).at_least(:once).and_return(true)
expect(subject).to receive(:merge_profiles).with(base_profile_path,
second_path, result_path).and_return({ 'exit' => 0, 'stderr' => '', 'stdout' => '' })
allow(subject).to receive(:XML_cleanup).and_return(true)
end

it 'cleans up each profile before merging them' do
expect(subject).to receive(:XML_cleanup).with(first_path, base_profile_path)
.and_return(true)
expect(subject).to receive(:XML_cleanup).with(second_path, cleaned_profile_path)
.and_return(true)

subject.Merge(result_path)
end

it 'merges two XML profiles' do
expect(subject).to receive(:merge_profiles)
.with(base_profile_path, cleaned_profile_path, result_path)
.and_return({ 'exit' => 0, 'stderr' => '', 'stdout' => '' })
expect(subject.Merge(result_path)).to eq(true)
end
end
Expand Down

0 comments on commit 53134af

Please sign in to comment.