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

Fix restoring SCR root (bsc#1207968) #1324

Merged
merged 3 commits into from Feb 10, 2023
Merged

Fix restoring SCR root (bsc#1207968) #1324

merged 3 commits into from Feb 10, 2023

Conversation

jreidinger
Copy link
Member

Problem

The issue is that bootloader ( yeah, not network ) crash with calling method on nil. Reason why it gets nil is that it failed to find /etc/sysconfig/bootloader. In logs I see several other failed reads e.g. to /etc/sysconfig/kdump. When manually reproduce it I notice that files are there. So only idea is switched SCR. So I check when it was last changed and it was in save_network to local one, but not back. So problem is that network switch SCR to '/' and do not restore it back.

Solution

Quickly from logs it is obvious that issue is at return from block at https://github.com/yast/yast-network/blob/master/src/lib/network/clients/save_network.rb#L98 where I though that return is from method and replace with break will fix it. But to be sure I write also test program. Another part is issue is that on_local method is not robust enough and e.g. if exception is returned it also do not get restore SCR chroot at https://github.com/yast/yast-network/blob/master/src/lib/network/clients/save_network.rb#L74 .

So to verify this ruby behavior I create testing program:

def test(&block)
  puts "pre block"

  block.call

  puts "post block"
ensure
  puts "ensured block"
end

def a
  test do
    puts "in block"
    return
  end
end

def b
  test do
    puts "in block"
    break
  end
end

def c
  test do
    puts "in block"
  end
end

puts "method a"
a
puts
puts "method b"
b
puts
puts "method c"
c

and get following output ( on both ruby 2.5 and ruby 3.1.2 ):

method a
pre block
in block
ensured block

method b
pre block
in block
ensured block

method c
pre block
in block
post block
ensured block

So conclusion for me is that replacing return with break does not help with skipping calls after block.call which really surprise me ( feel free to enlighten me why ). So only correct solution ( that is correct also to handle properly exceptions ) is to enclose restore of SCR to ensure block.

Testing

  • Added a new unit test sadly save_network unit test is so messy and overmocked that I failed to test new behavior
  • Tested manually (thanks lada for yupdate, test was easy with using this branch )

@coveralls
Copy link

coveralls commented Feb 9, 2023

Coverage Status

Coverage: 80.438%. Remained the same when pulling b2d8292 on fix_closing_scr into 6c667c3 on master.

Copy link
Contributor

@ancorgs ancorgs left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. ensure is definitely the right thing to do.

@jreidinger jreidinger merged commit e707387 into master Feb 10, 2023
@jreidinger jreidinger deleted the fix_closing_scr branch February 10, 2023 12:30
@yast-bot
Copy link
Contributor

✔️ Public Jenkins job #321 successfully finished
✔️ Created OBS submit request #1064238

@yast-bot
Copy link
Contributor

✔️ Internal Jenkins job #216 successfully finished
✔️ Created IBS submit request #289752

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants