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

Fixes #12633 - Pxegrub2 variant and multiple configs #414

Closed
wants to merge 1 commit into from

Conversation

lzap
Copy link
Member

@lzap lzap commented May 5, 2016

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

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"
Copy link
Member

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)?

Copy link
Member Author

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

@lzap
Copy link
Member Author

lzap commented May 6, 2016

Rebased and added those instantiation tests which I believe are useless.

@lzap
Copy link
Member Author

lzap commented May 6, 2016

Failed because of the bundler issue.

@lzap
Copy link
Member Author

lzap commented May 6, 2016

It looks like JSON responses of the API changed, I need to add asserts for that and compare with develop.

@lzap
Copy link
Member Author

lzap commented May 6, 2016

Added, it looks like previously the API was handing over return values of logger calls, I changed this to be always empty.

end

def test_set
FileUtils.stubs(:mkdir_p).returns(true)
Copy link
Member

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...

Copy link
Member Author

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

@lzap
Copy link
Member Author

lzap commented May 24, 2016

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)
Copy link
Member

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.

@dmitri-d
Copy link
Member

[test]

@lzap
Copy link
Member Author

lzap commented May 31, 2016

Amended both comments.

Looks good. It would be useful to add tests that verify that Proxy::TFTP::Server#read_file, Proxy::TFTP::Server#write_file, and Proxy::TFTP::Server#delete_file methods do what we expect them to.

Well, I added those to actually avoid testing of the File.open and read
stuff.

Later,
Lukas #lzap Zapletal

@dmitri-d
Copy link
Member

Well, I added those to actually avoid testing of the File.open and read stuff.

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.

@lzap
Copy link
Member Author

lzap commented May 31, 2016

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,
Lukas #lzap Zapletal

end
end

class HelersServerTest < Test::Unit::TestCase
Copy link
Member

Choose a reason for hiding this comment

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

Spelling?

@dmitri-d
Copy link
Member

dmitri-d commented Jun 1, 2016

@lzap: please take a look, tests are failing under 1.8.7.

@lzap
Copy link
Member Author

lzap commented Jun 1, 2016

All fixed.

@dmitri-d
Copy link
Member

dmitri-d commented Jun 1, 2016

@lzap: there's also a couple of rubocop failures.

@lzap
Copy link
Member Author

lzap commented Jun 1, 2016

@lzap: there's also a couple of rubocop failures.

Holy, no my day. Refactored.

Later,
Lukas #lzap Zapletal

@dmitri-d
Copy link
Member

dmitri-d commented Jun 2, 2016

Merged as b1cec0e. Thanks, @lzap.

@dmitri-d dmitri-d closed this Jun 2, 2016
@lzap lzap deleted the pxegrub2 branch May 23, 2017 14:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
3 participants