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

Mocked CAF::FileWriter attempts to create directories #139

Closed
jouvin opened this issue Mar 3, 2017 · 10 comments · Fixed by #160
Closed

Mocked CAF::FileWriter attempts to create directories #139

jouvin opened this issue Mar 3, 2017 · 10 comments · Fixed by #160
Assignees
Milestone

Comments

@jouvin
Copy link
Contributor

jouvin commented Mar 3, 2017

I tried to remove CAF::Object::NoAction=1 in a few unit tests, like write_grub2_config.t in AII aii-pxelinux. This results in the following exception:

Uncaught exception!!! Calling stack is:
  LC::Exception::throw_error called at /usr/lib/perl/LC/Fatal.pm line 261
  LC::Fatal::mkdir called at /usr/lib/perl/LC/File.pm line 529
  LC::File::makedir called at /usr/lib/perl/LC/File.pm line 524
  LC::File::makedir called at /usr/lib/perl/LC/Check.pm line 231
  LC::Check::directory called at /usr/lib/perl/LC/Check.pm line 262
  LC::Check::parent_directory called at /usr/lib/perl/LC/Check.pm line 913
  LC::Check::file called at /usr/lib/perl/CAF/FileWriter.pm line 237
  CAF::FileWriter::close called at /exp/si/jouvin/GitRepositories/Quattor/aii/aii-pxelinux/target/dependency/build-scripts/Test/Quattor.pm line 385
  Test::Quattor::new_filewriter_close called at /exp/si/jouvin/GitRepositories/Quattor/aii/aii-pxelinux/target/lib/perl/NCM/Component/pxelinux.pm line 520
  NCM::Component::pxelinux::_write_grub2_config called at src/test/perl/write_grub2_config.t line 33
  main::check_config called at src/test/perl/write_grub2_config.t line 63
*** mkdir(/grub, 0755): Permission denied
# Tests were run but no plan was declared and done_testing() was not seen.
Uncaught exception!!! Calling stack is:
  LC::Exception::throw_error called at /usr/lib/perl/LC/Fatal.pm line 261
  LC::Fatal::mkdir called at /usr/lib/perl/LC/File.pm line 529
  LC::File::makedir called at /usr/lib/perl/LC/File.pm line 524
  LC::File::makedir called at /usr/lib/perl/LC/Check.pm line 231
  LC::Check::directory called at /usr/lib/perl/LC/Check.pm line 262
  LC::Check::parent_directory called at /usr/lib/perl/LC/Check.pm line 913
  LC::Check::file called at /usr/lib/perl/CAF/FileWriter.pm line 237
  CAF::FileWriter::close called at /exp/si/jouvin/GitRepositories/Quattor/aii/aii-pxelinux/target/dependency/build-scripts/Test/Quattor.pm line 385
  Test::Quattor::new_filewriter_close called at /exp/si/jouvin/GitRepositories/Quattor/aii/aii-pxelinux/target/lib/perl/NCM/Component/pxelinux.pm line 520
  NCM::Component::pxelinux::_write_grub2_config called at src/test/perl/write_grub2_config.t line 33
  main::check_config called at src/test/perl/write_grub2_config.t line 67
*** mkdir(/grub, 0755): Permission denied
src/test/perl/write_grub2_config.t .. 

This seems unexpected as CAF::FileWriter is supposed to be mocked...

@stdweird
Copy link
Member

stdweird commented Mar 5, 2017

quattor/CAF#202 should fix this. we should retest once that PR is tested and merged.

@jouvin
Copy link
Contributor Author

jouvin commented Mar 20, 2017

quattor/CAF#202 may fix it but I checked the Test/Quattor.pm test and I don't understand why it fails as LC_Check is supposed to be mocked... Something strange to me: Test/Quattor.pm has an exported function make_directory but there is also a make_directory in simple_caf used by tests... Logic not clear to me...

@jouvin
Copy link
Contributor Author

jouvin commented Mar 21, 2017

I manage to find the culprit... This is the mocked CAF::FileWriter::close(). It calls the original CAF::FileWriter::close() which seems a little bit odd as there is no point to mock it if we call it (well it is not completely true as the mocked version updates the %desired_file_contentshash)... Removing this call, I have been able to check that maven tools build-scripts can be built successfully and that it does fix the problem in aii-pxelinux. But it remove of the diff handling and the reporting about the differences: I don't know if this may be a problem in other contexts. Another approach could be not to execute the LC::Check::file call if noaction is set (which is the case as it is set by the mocked constructor).

@stdweird any opinion?

@jouvin
Copy link
Contributor Author

jouvin commented Mar 21, 2017

I had a look as the second solution (set noaction option before calling the original close() and not calling LC::Check::file in this case). It looks to me the right way to do it but in this case we also need to force noAction in the mocked context which is not currently the case conversely to what I said... Comments welcome!

@stdweird
Copy link
Member

how can i repoduce this issue? and have you tried the new filewriter? i have never had an issue with the original code; but we probably run NoAction=1 everywhere where we shouldn't.
best way to deal with this is proabably shipping a dummy LC or Atomic module with maven-tools, similar to the CAF uses in its unittests and also the components.

@jouvin
Copy link
Contributor Author

jouvin commented Mar 22, 2017

@stdweird I found this issue after your remark that we were abusing NoAction=1 in the unit tests and that it was not necessary now that CAF was mocked in maven tools... You can easily reproduce the problem by running write_pxelinux_config.t in UEFI PR after removing NoAction=1.

After thinking more at this problem, I think that what is wrong is to execute the original method in the mocked one. I've the feeling that the right approach is what I did with links: have a mocked version that is implementing the feature of the original one (like reporting diffs for example).

An alternative could be to set noaction option (at least by default) before calling the original close() but I don't know if if may break some tests in other Quattor components...

@stdweird
Copy link
Member

ok, i see.
yes, Noaction is not used properly in most unittests and this issue would indeed prevent people from doing so.
however, i'm not convinced we should reinplement the CAF code here, shipping a dummy LC or Atomic module will do the same trick with a lot less work.

but there are also cases where the mocking cannot be done, eg during the test profile CCM part. that needs fully functional FileWriter. it's also not a big issue as long as all compilation is triggered via the import hack.

@jouvin
Copy link
Contributor Author

jouvin commented Mar 22, 2017

@stdweird your CCM use case is a reason I was proposing to set noaction option of the FW instance to 1 by default in the constructor or in close(). This would allow to define CAF::Object:NoAction=0 when this is needed (and in this case noaction option will be set to 0 too).

jouvin added a commit to jouvin/maven-tools that referenced this issue Mar 22, 2017
- Default can be overriden with $CAF::Object::NoAction=0

Fixes quattor#139
@jouvin
Copy link
Contributor Author

jouvin commented Mar 22, 2017

I just pushed a commit implement the noaction idea to make it more clear! I tested that it does fix the aii-pxelinux issue when NoAction=1 is removed from unit tests and that CAF unit tests work properly too. I could not verify CCM as I fail to run successfully the tests on the master without the modified build tools... @stdweird as you have a cleaner dev environment than me, may be you could validate the impact and if it is enough to define $CAF::Object::NoAction=0 to fix problems if any?

jouvin added a commit to jouvin/maven-tools that referenced this issue Mar 23, 2017
- Default can be overriden with $Test::Quattor::NoAction=0
- Do not set noaction in CAF::FE::new() as it calls CAF::FW::new()

Fixes quattor#139
jouvin added a commit to jouvin/maven-tools that referenced this issue Mar 29, 2017
- Default can be overriden with $Test::Quattor::NoAction=0
- Do not set noaction in CAF::FE::new() as it calls CAF::FW::new()

Fixes quattor#139
jouvin added a commit to jouvin/maven-tools that referenced this issue Mar 29, 2017
- Default can be overriden with $Test::Quattor::NoAction=0
- Do not set noaction in CAF::FE::new() as it calls CAF::FW::new()
- Ensure that $Test::Quattor::NoAction=0 in Test::Quattor:ProfileCache

Fixes quattor#139
@jouvin jouvin self-assigned this Mar 30, 2017
@jrha jrha added this to the 17.4 milestone Mar 30, 2017
@jrha jrha modified the milestones: 17.3, 17.7 Jul 26, 2017
@jrha
Copy link
Member

jrha commented Jul 26, 2017

I believe this was closed by #160.

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

Successfully merging a pull request may close this issue.

3 participants