fix some error message suppression in node#ping
authorTom Clegg <tom@clinicalfuture.com>
Thu, 10 Jan 2013 22:26:55 +0000 (14:26 -0800)
committerTom Clegg <tom@clinicalfuture.com>
Thu, 10 Jan 2013 22:26:55 +0000 (14:26 -0800)
app/models/node.rb

index ab971ac3af533f85a163019448412998b0f9f92e..026865e9575cff26b229ff8c5cfcc5917774b7fd 100644 (file)
@@ -43,8 +43,12 @@ class Node < ActiveRecord::Base
       try_slot = 0
       begin
         self.slot_number = try_slot
-        try_slot += 1
-        break if self.save rescue nil
+        begin
+          self.save!
+          break
+        rescue ActiveRecord::RecordNotUnique
+          try_slot += 1
+        end
         raise "No available node slots" if try_slot == MAX_SLOTS
       end while true
       self.hostname = self.class.hostname_for_slot(self.slot_number)
@@ -79,7 +83,9 @@ class Node < ActiveRecord::Base
 
   def dnsmasq_update
     if self.hostname_changed? or self.ip_address_changed?
-      self.class.dnsmasq_update(self.hostname, self.ip_address)
+      if self.hostname and self.ip_address
+        self.class.dnsmasq_update(self.hostname, self.ip_address)
+      end
     end
   end