-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
[Modules 4746] Creates class for managing Apache mod_jk connector #1630
Conversation
|
@EmersonPrado is there anything specifically we can help with on this PR? |
|
@eputnam Yes: with the tests. I have way too little knowledge on rspec-puppet, so I'm getting lost. I'd really appreciate some help making decent tests which pass. |
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.
the inheritance should fix the broken test. as for the tests, they look fine. one thing to add might be a debian scenario just because things can change across platforms for mods. other than that, i think you're fine.
| # Mount file content | ||
| # See comments in template mod/jk/uriworkermap.properties.erb | ||
| $mount_file_content = {}, | ||
| ){ |
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.
there's not really a great pattern to open up access to the vars you reference in the parameters here, so i'll take a page from many of the other mods and say use inheritance here.
) inherits apache {then you can remove the include ::apache below as well.
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.
Does that mean that, by using inheritance in the class, the external variables (from ::apache) will be available in the spec test?
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.
it's going to work just like the include but with a guaranteed parse order. i'm not actually sure what you're looking for, did you have something specific in mind?
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.
What I exactly need is the mod/jk spec test to access the variables from ::apache class. If I understood you correctly, inheritance would make sure the variables get included before needed in the spec test. Is that correct?
I'm avoiding inheritance here because it's considered an anti-pattern by Puppet itself - see block "Aside: When to Inherit" here.
An alternative would be to declare the parameter as undef in the class signature, then assingn values depending on such parameter, like I did with workers_file and mount_file. So, by assigning something in the test in :parameters section, maybe the required variables will be there. Doesn't seem much clear (I'm in a hurry now), but feel free to ask.
Thanks!
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.
i commented above, i think the undef pattern you mention would work best, then we can avoid inheritance altogether. as for mocking apache params, you can use "pre_conditions" in a compile block for one:
puppetlabs-apache/spec/classes/mod/auth_kerb_spec.rb
Lines 77 to 105 in 40c1ad4
| context "overriding mod_packages" do | |
| context "on a RedHat OS", :compile do | |
| let :facts do | |
| { | |
| :id => 'root', | |
| :kernel => 'Linux', | |
| :osfamily => 'RedHat', | |
| :operatingsystem => 'RedHat', | |
| :operatingsystemrelease => '6', | |
| :path => '/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin', | |
| :concat_basedir => '/dne', | |
| :is_pe => false, | |
| } | |
| end | |
| let :pre_condition do | |
| <<-EOS | |
| include apache::params | |
| class { 'apache': | |
| mod_packages => merge($::apache::params::mod_packages, { | |
| 'auth_kerb' => 'httpd24-mod_auth_kerb', | |
| }) | |
| } | |
| EOS | |
| end | |
| it { is_expected.to contain_apache__mod("auth_kerb") } | |
| it { is_expected.to contain_package("httpd24-mod_auth_kerb") } | |
| it { is_expected.to_not contain_package("mod_auth_kerb") } | |
| end | |
| end |
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.
OK. I used the undef pattern for ::apache::logroot only, including a new parameter for it in mod::jk class. Then I changed the file parameters to only the name, as you suggested (so the user can override either filename or diretory at will). Finally, added the logroot parameter in the :params section in the spec test. Let's hope it works!
As for pre_conditions section, I still don't get quite well how it works. I'll try something later. But thanks for the hint!
spec/classes/mod/jk_spec.rb
Outdated
|
|
||
| context "with only required facts and no parameters" do | ||
|
|
||
| let :facts do |
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.
parens here for :facts
manifests/mod/jk.pp
Outdated
| class apache::mod::jk ( | ||
| $workers_file = undef, | ||
| $worker_property = {}, | ||
| $shm_file = "${::apache::logroot}/jk-runtime-status", |
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.
in the case of these logroot dependencies, you could just set these to the file's name and then prepend the logroot path below. this would be a more predictable pattern for those who are wanting to override anyway.
|
for logroot, you don't need a $logroot parameter in your class, you should just be able to get it from ::apache, and it will never be so:
$shm_path = "${::apache::logroot}/${shm_file}"
$log_path = "${::apache::logroot}/${log_file}"and for future reference, :params in the spec test expects a hash, so it might look like this instead: let (:params) do
{ :logroot => '/var/log/httpd' }
endwas any of that helpful? |
This reverts commit cea6bbf. Setting default value from other class (::apache) breaks spec test, which does not parse the other class
|
@eputnam Yes, I'm including the possibility for the user to override logroot directory. I don't know how much this will be used - the user would probably be safer overriding this in ::apache class instead - but I'm leaving this here for pickiness. Maybe it's something to think twice. Your correction about spec :params section nailed it. With last commits, all spec tests pass. I included a Debian context too. So I guess we're all set now. Thanks a lot! |
|
@EmersonPrado thanks this is great. |
[Modules 4746] Creates class for managing Apache mod_jk connector
Current state: includes
mod_jkmodule, creates jk.load, jk.conf and worker properties files and adds some description in the README file.Lacks (as far as my creativity goes): parameter validation, proper parsing of some parameters, worker map file management and tests.