-
Notifications
You must be signed in to change notification settings - Fork 112
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
Update zone-serial only on changing zone-records (sed version) #45
Conversation
# A real zone file will be updated only at change of the stage file, thanks to this serial is updated only in case of need | ||
$zone_serial = inline_template('<%= Time.now.to_i %>') | ||
exec { "real-${zone}": | ||
command => "sed '8s/_SERIAL_/${zone_serial}/' ${zone_file_stage} > ${zone_file}", |
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 change only line num 8 (sed '8s/...'). It is safe, but demands care with a zone_file.erb template.
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.
That seems ok to me.
I think we are getting close to a solid PR. The next thing I would like to talk about it is tests. Have you ever written a Puppet rspec test before? |
The first most basic test is lint. Now, this module hasn't had lint tests against it historically, so there are lots of previous errors. But can you fix the ones that pertain to the file you have edited? (zone.pp) Start by installing the necissary gems to run the test:
Then run the lint test, and only look at the errors that are related to your change:
(In the root of the module directory. Requires ruby and rubygems to be installed) |
I never wrote tests for Puppet. I can try this, but it will take time. |
# A real zone file will be updated only at change of the stage file, thanks to this serial is updated only in case of need | ||
$zone_serial = inline_template('<%= Time.now.to_i %>') | ||
exec { "bump-${zone}-serial": | ||
command => "sed '8s/_SERIAL_/${zone_serial}/' ${zone_file_stage} > ${zone_file}", |
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 checked code by lint and corrected all warnings except this line (correct version not committed now). Warning for this line:
manifests/zone.pp:56:80chars:WARNING:line has more than 80 characters
There is a need to correct this warning?
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.
Eh, its ok.
Linting is good. Feel free to run Next is rspec tests. They are currently failing. https://travis-ci.org/ajjahn/puppet-dns/jobs/22713442 Run the tests yourselves on your own code:
You will see test cases that are defined in the spec folder. Check them out, see why some are failing, etc. Try to get it to come out green. |
My local puppet was broken (after "bundle install") therefore, I couldn't check operability of the last patch. I will try verify code tomorrow, but i think that everything is good. |
Hmm, depending on whether you installed puppet via a Gem or system package, there might be a conflict. The puppet "binary" should always prefer the Gem install. If you wanted to you could uninstall the gem version, set a local GEM_HOME=~/.gem/ and install gems locally to prevent them from conflicting. |
Getting the existing tests to pass is a good first step, but we need tests on the new code in order to be accepted. Here is another PR with some tests in progress for some examples: https://github.com/ajjahn/puppet-dns/pull/46/files There are also existing tests to look at. For your purposes, you will be working with For this, PR I would like to see tests for:
You can't test that the actual zone file serial gets bumped for real in unit tests, however :( But testing that those 3 things exist in the catalog is good enough for me, and assures me that if something changes in the future that breaks the functionality you just wrote, we will know because the tests will fail! |
Sorry I've been largely absent from this discussion, and maybe this is beyond the scope, but do you guys think this functionality could be better accomplished with a type/provider? Just a thought. |
Hmmm. Interesting idea. On the one hand, yes, a bind provider could handle the updating of the serial number "on flush". But in the end, the bind configuration syntax is not standard, and certainly not something machine readable like json. The provider would have a really hard time extracting the current state of the configuration files. You basically would end up writing a zone file parser in ruby. It would be cool, but would put this module outside the scope of most puppet module writers skillsets (including mine). :( Erb+concat really does get us most of the way there, and it can be understood by most people (sysadmins). The only special thing about zone files is that serial bump, so I think using sed is a good middle-ground-hack. (Too bad bind couldn't just handle bumping serials internally automatically some how) |
@kubashin-a can you merge master (has changed recently) ? |
I merged maser. |
Cool. I look forward to this being merged. If not by you then I will pick it up and complete it. |
@@ -4,7 +4,7 @@ | |||
let(:title) { 'test.com' } | |||
|
|||
context 'passing something other than an array' do | |||
let :facts do { :concat_basedir => '/dne', } end | |||
let :facts do { :osfamily => 'Debian', :concat_basedir => '/dne' } 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.
include dns::server::params in zone.pp require fact osfamily
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.
That is fine.
} | ||
|
||
it { should contain_concat__fragment('db.test.com.soa'). | ||
with_content(/_SERIAL_/) |
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 is a method to check only the 8th line for pattern?
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.
Not that I know of, but I'm pretty happy with this part.
If someone breaks the method of bumping serials, this test will complain.
There are still merge conflicts on master. Can you merge upstream master and correct them so, and then travis should run?
|
I executed these commands, now:
|
Hmm. And were you on your sed branch at the time of the merge? |
Here is I get when I try to merge your branch master from your branch: https://pastee.org/2qcyg |
Yes, i have the same picture. I go to read about the merge conflicts :) |
Conflicts: manifests/zone.pp spec/defines/dns_zone_spec.rb
In the current master an error in zone.pp used variable: $dns::options::forwarder, but whould be $dns::server::options::forwarder. |
You should be able to correct it, commit it, and push again. |
It work on Ubuntu 14.04, do you need additional testing? |
This looks good to me. I'm was mostly concerned about unit tests. (and Travis now sees them as passing) @danzilio or @ajjahn do you have any objections? I vote merge. This solves the non-convergence issue that we've had since the beginning. (and I don't like non-converging puppet runs) |
Update zone-serial only on changing zone-records (sed version)
@kubashin-a Thank you again for iterating over this PR for so long to refine it. In the end I think it is pretty solid. |
Big thanks for your work and patience. |
Sed version of PR #42.
I tested it only on Ubuntu 14.04 (Puppet 3.4.3).