Skip to content
This repository has been archived by the owner on Mar 5, 2020. It is now read-only.

Commit

Permalink
New domain form and controller actions support master/slave now [#48]
Browse files Browse the repository at this point in the history
  • Loading branch information
kennethkalmer committed Feb 15, 2009
1 parent 68ae720 commit e83c358
Show file tree
Hide file tree
Showing 5 changed files with 71 additions and 12 deletions.
20 changes: 12 additions & 8 deletions app/controllers/domains_controller.rb
Expand Up @@ -31,17 +31,21 @@ def new
end

def create
@zone_template = ZoneTemplate.find(params[:domain][:zone_template_id]) unless params[:domain][:zone_template_id].blank?
@zone_template ||= ZoneTemplate.find_by_name(params[:domain][:zone_template_name]) unless params[:domain][:zone_template_name].blank?

@domain = Domain.new( params[:domain] )
unless @zone_template.nil?
begin
@domain = @zone_template.build( params[:domain][:name] )
rescue ActiveRecord::RecordInvalid => e
@domain.attach_errors(e)

unless @domain.slave?
@zone_template = ZoneTemplate.find(params[:domain][:zone_template_id]) unless params[:domain][:zone_template_id].blank?
@zone_template ||= ZoneTemplate.find_by_name(params[:domain][:zone_template_name]) unless params[:domain][:zone_template_name].blank?

unless @zone_template.nil?
begin
@domain = @zone_template.build( params[:domain][:name] )
rescue ActiveRecord::RecordInvalid => e
@domain.attach_errors(e)
end
end
end

@domain.user = current_user unless current_user.has_role?( 'admin' )

respond_to do |format|
Expand Down
2 changes: 2 additions & 0 deletions app/models/domain.rb
Expand Up @@ -87,6 +87,8 @@ def after_validation_on_create #:nodoc:

# Setup an SOA if we have the requirements
def after_create #:nodoc:
return if self.slave?

soa = SOA.new( :domain => self )
SOA_FIELDS.each do |f|
soa.send( "#{f}=", send( f ) )
Expand Down
18 changes: 18 additions & 0 deletions app/views/domains/_new.html.haml
Expand Up @@ -27,6 +27,14 @@
caching time - the time a NAME ERROR = NXDOMAIN record is cached. The
maximum value allowed by BIND 9 for this parameter is 3 hours (10800
seconds).
#help-type
PowerDNS supports NATIVE, MASTER and SLAVE domain types. NATIVE domains will
cause PowerDNS to keep quiet on changes, MASTER will have PowerDNS notify the
slaves when changes are made to the records, and SLAVE will create a
read-only domain where PowerDNS will pull changes from the specified master
server.
#help-master
The IP address of the authorative (or master) DNS server for this domain.

%p
Create a new domain by entering the Start of Authority (SOA) information below:
Expand All @@ -40,6 +48,16 @@
%td= f.text_field :name
%td= prototip_help_icon('help-domain')
%tr
%td Type
%td
= f.select :type, ['NATIVE','MASTER','SLAVE']
= observe_field :domain_type, :function => "if(value == \"SLAVE\") { $('master-address').show(); $('zone-templates').hide(); $('no-template-input').hide(); } else { $('master-address').hide(); $('zone-templates').show(); $('no-template-input').show(); }"
%td= prototip_help_icon('help-type')
%tr#master-address{ :style => 'display: none' }
%td Master Address
%td= f.text_field :master
%td= prototip_help_icon('help-master')
%tr#zone-templates
%td Zone Template
%td
- if @zone_templates.size > 0
Expand Down
21 changes: 18 additions & 3 deletions spec/controllers/domains_controller_spec.rb
Expand Up @@ -51,10 +51,9 @@
end

it "should build from a zone template if selected" do
@zone_template = zone_templates(:east_coast_dc)
ZoneTemplate.stubs(:find).with('1').returns(@zone_template)
zone_template = zone_templates(:east_coast_dc)

post 'create', :domain => { :name => 'example.org', :zone_template_id => "1" }
post 'create', :domain => { :name => 'example.org', :zone_template_id => zone_template.id }

assigns[:domain].should_not be_nil
response.should be_redirect
Expand All @@ -71,6 +70,22 @@
response.should redirect_to( domain_path( assigns[:domain] ) )
flash[:info].should_not be_nil
end

it "should ignore the zone template if a slave is created" do
zone_template = zone_templates(:east_coast_dc)

post 'create', :domain => {
:name => 'example.org',
:type => 'SLAVE',
:master => '127.0.0.1',
:zone_template_id => zone_template.id
}

assigns[:domain].should be_slave
assigns[:domain].soa_record.should be_nil

response.should be_redirect
end

end

Expand Down
22 changes: 21 additions & 1 deletion spec/models/domain_spec.rb
Expand Up @@ -50,6 +50,10 @@
@domain.master = '127.0.0.1'
@domain.should have(:no).errors_on(:master)
end

it "should not bail out on missing SOA fields" do
@domain.should have(:no).errors_on( :primary_ns )
end
end

describe Domain, "when loaded" do
Expand Down Expand Up @@ -137,7 +141,7 @@
end
end

describe Domain, "when created" do
describe "NATIVE/MASTER", Domain, "when created" do
fixtures :all

before(:each) do
Expand All @@ -159,6 +163,22 @@
end
end

describe "SLAVE", Domain, "when created" do
fixtures :all

before(:each) do
@domain = Domain.new( :type => 'SLAVE' )
end

it "should create with SOA requirements or SOA record" do
@domain.name = 'example.org'
@domain.master = '127.0.0.1'

@domain.save.should be_true
@domain.soa_record.should be_nil
end
end

describe Domain, "when deleting" do
fixtures :all

Expand Down

0 comments on commit e83c358

Please sign in to comment.