Module: Yast::RSpec::SCR
- Defined in:
- src/ruby/yast/rspec/scr.rb
Overview
RSpec extension to handle several agent operations.
Instance Method Summary collapse
-
#change_scr_root(directory) ⇒ Object
Encapsulates SCR calls into a chroot.
-
#reset_scr_root ⇒ Object
Resets the SCR calls to prior behaviour, closing the SCR instance open by the call to #change_scr_root.
Instance Method Details
#change_scr_root(directory) ⇒ Object
Encapsulates SCR calls into a chroot.
If a block if given, the SCR calls in the block are executed in the chroot and the corresponding SCR instance is automatically closed when the block ends (or if an exception is raised by the block).
If a block is not given, the chroot must be explicitly closed calling reset_root_path.
Nesting of chroots is forbidden and the method will raise an exception if is called without closing a previous chroot.
46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 |
# File 'src/ruby/yast/rspec/scr.rb', line 46 def change_scr_root(directory) if @scr_handle raise "There is already an open chrooted SCR instance, "\ "a call to reset_scr_root was expected" end if !File.directory?(directory) raise "#{directory} is not a valid directory" end @scr_original_handle = Yast::WFM.SCRGetDefault check_version = false @scr_handle = Yast::WFM.SCROpen("chroot=#{directory}:scr", check_version) if @scr_handle < 0 @scr_handle = nil @scr_original_handle = nil raise "Error creating the chrooted SCR instance" end Yast::WFM.SCRSetDefault(@scr_handle) return unless block_given? begin yield ensure reset_scr_root end end |
#reset_scr_root ⇒ Object
Resets the SCR calls to prior behaviour, closing the SCR instance open by the call to #change_scr_root.
Raises an exception if #change_scr_root has not been called before or if the corresponding instance has already been closed.
82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 |
# File 'src/ruby/yast/rspec/scr.rb', line 82 def reset_scr_root if @scr_handle.nil? raise "Unable to find a chrooted SCR instance to close" end default_handle = Yast::WFM.SCRGetDefault if default_handle != @scr_handle raise "Error closing the chrooted SCR instance, "\ "it's not the current default one" end Yast::WFM.SCRClose(default_handle) Yast::WFM.SCRSetDefault(@scr_original_handle) ensure @scr_handle = nil @scr_original_handle = nil end |