-
Notifications
You must be signed in to change notification settings - Fork 217
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
Fixes #12633 - Pxegrub2 variant and multiple configs #414
Conversation
logger.info "TFTP: entry for #{mac} created successfully" | ||
pxeconfig_file(mac).each do |file| | ||
File.open(file, 'w') {|f| f.write(config) } | ||
logger.info "TFTP: #{file} created successfully" |
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.
Can you change "info"-level logging with "debug" one (here and below)?
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.
Can you change "info"-level logging with "debug" one (here and below)?
Changed all three then.
Later,
Lukas #lzap Zapletal
Rebased and added those instantiation tests which I believe are useless. |
Failed because of the bundler issue. |
It looks like JSON responses of the API changed, I need to add asserts for that and compare with develop. |
Added, it looks like previously the API was handing over return values of |
end | ||
|
||
def test_set | ||
FileUtils.stubs(:mkdir_p).returns(true) |
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.
If you want to use mocks for these tests, can you extract file-related operations into methods in Proxy::TFTP::Server
class? For example, around https://github.com/lzap/smart-proxy/blob/pxegrub2/modules/tftp/server.rb#L10 would become something like:
def write_config_for_mac(dir, file, config)
FileUtils.mkdir_p dir
File.open(File.join(dir, file), 'w') {|f| f.write(config) }
end
etc.
Such a refactor would both improve readability (both code and tests) and reduce the fragility of mocks...
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.
Such a refactor would both improve readability (both code and tests) and reduce the fragility of mocks...
Excellent idea.
Later,
Lukas #lzap Zapletal
Fixed tests, it's now much more simple with the two little helper methods! |
|
||
def test_api_can_fetch_boot_file | ||
Proxy::Util::CommandTask.stubs(:new).returns(true) | ||
FileUtils.stubs(:mkdir_p).returns(true) |
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.
these two stubs aren't needed anymore.
[test] |
Amended both comments.
Well, I added those to actually avoid testing of the File.open and read Later, |
Kinda -- mocks and stubs should ideally be as close as possible to the class that is being tested (to improve readability and reduce brittleness of tests). Having said that, the logic that you extracted into dedicated method should be tested too -- you verified interfaces to read_file, etc, but not if they actually work. To test those extracted methods you can verify changes they do to the file system, or mock lower-level calls. Personally I would prefer the former approach. Mocking of lower-level calls should be ok in this case though, as while it is more brittle (chances are these tests will have to updated every time read_file, write_file, or delete_file change), there is going to be only one test (I think) per method, which contains the amount of pain these mocks can cause. |
Done the filesystem path. Later, |
end | ||
end | ||
|
||
class HelersServerTest < Test::Unit::TestCase |
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.
Spelling?
@lzap: please take a look, tests are failing under 1.8.7. |
All fixed. |
@lzap: there's also a couple of rubocop failures. |
Holy, no my day. Refactored. Later, |
Foreman Proxy must be enhanced with new PXE variant "Pxegrub2" to allow
deploying configuration files in "grub2/" folder. In addition to that, Pxegrub
(version 1) must deploy two configuration files instead of one now to support
both BIOS and UEFI naming conventions (grub/menu.lst vs grub/efidefault and
grub/menu.lst.01aabbccddeeff vs grub/01-AA-BB-CC-DD-EE-FF). Also, Pxegrub
variant will use new base directory "grub/" instead of "boot/grub/" for
consistency with "grub2" and "pxelinux.cfg/".
More details at:
http://projects.theforeman.org/projects/foreman/wiki/PXE_Booting_UEFI