+require 'tempfile'
+
class Node < ArvadosModel
include HasUuid
include KindAndEtag
begin
begin
template = IO.read(Rails.configuration.dns_server_conf_template)
- rescue => e
+ rescue IOError, SystemCallError => e
logger.error "Reading #{Rails.configuration.dns_server_conf_template}: #{e.message}"
raise
end
hostfile = File.join Rails.configuration.dns_server_conf_dir, "#{hostname}.conf"
- File.open hostfile+'.tmp', 'w' do |f|
+ tmpfile = Tempfile.open(["#{hostname}", ".conf.tmp"],
+ Rails.configuration.dns_server_conf_dir) do |f|
f.puts template % template_vars
+ f.path
end
- File.rename hostfile+'.tmp', hostfile
- rescue => e
+ File.rename tmpfile, hostfile
+ rescue IOError, SystemCallError => e
logger.error "Writing #{hostfile}: #{e.message}"
ok = false
end
# Typically, this is used to trigger a dns server restart
f.puts Rails.configuration.dns_server_reload_command
end
- rescue => e
+ rescue IOError, SystemCallError => e
logger.error "Unable to write #{restartfile}: #{e.message}"
ok = false
end
assert Node.dns_server_update 'compute65535', '127.0.0.127'
end
+ test "dns update with dir configured but no command configured" do
+ Rails.configuration.dns_server_update_command = false
+ Rails.configuration.dns_server_conf_dir = Rails.root.join 'tmp'
+ conffile = Rails.root.join 'tmp', 'compute65535.conf'
+ assert Node.dns_server_update 'compute65535', '127.0.0.127'
+ refute File.exist? conffile
+ end
+
test "ping new node with no hostname and default config" do
node = ping_node(:new_with_no_hostname, {})
slot_number = node.slot_number