if !@object
return render_not_found
end
- @object.ping({ ip: params[:local_ipv4] || request.env['REMOTE_ADDR'],
- ping_secret: params[:ping_secret],
- ec2_instance_id: params[:instance_id] })
+ ping_data = {
+ ip: params[:local_ipv4] || request.env['REMOTE_ADDR'],
+ ec2_instance_id: params[:instance_id]
+ }
+ [:ping_secret, :total_cpu_cores, :total_ram_mb, :total_scratch_mb]
+ .each do |key|
+ ping_data[key] = params[key] if params[key]
+ end
+ @object.ping(ping_data)
if @object.info['ping_secret'] == params[:ping_secret]
render json: @object.as_api_response(:superuser)
else
end
end
+ # Record other basic stats
+ ['total_cpu_cores', 'total_ram_mb', 'total_scratch_mb'].each do |key|
+ if value = (o[key] or o[key.to_sym])
+ self.info[key] = value
+ else
+ self.info.delete(key)
+ end
+ end
+
save!
end
info:
:ping_secret: "69udawxvn3zzj45hs8bumvndricrha4lcpi23pd69e44soanc0"
:slurm_state: "idle"
+ total_cpu_cores: 16
assert_not_nil json_response['info']['ping_secret']
end
+ test "ping adds node stats to info" do
+ node = nodes(:idle)
+ post :ping, {
+ id: node.uuid,
+ ping_secret: node.info['ping_secret'],
+ total_cpu_cores: 32,
+ total_ram_mb: 1024,
+ total_scratch_mb: 2048
+ }
+ assert_response :success
+ info = JSON.parse(@response.body)['info']
+ assert_equal(node.info['ping_secret'], info['ping_secret'])
+ assert_equal(32, info['total_cpu_cores'].to_i)
+ assert_equal(1024, info['total_ram_mb'].to_i)
+ assert_equal(2048, info['total_scratch_mb'].to_i)
+ end
end
require 'test_helper'
class NodeTest < ActiveSupport::TestCase
- # test "the truth" do
- # assert true
- # end
+ def ping_node(node_name, ping_data)
+ set_user_from_auth :admin
+ node = nodes(node_name)
+ node.ping({ping_secret: node.info['ping_secret'],
+ ip: node.ip_address}.merge(ping_data))
+ node
+ end
+
+ test "pinging a node can add and update stats" do
+ node = ping_node(:idle, {total_cpu_cores: '12', total_ram_mb: '512'})
+ assert_equal(12, node.info['total_cpu_cores'].to_i)
+ assert_equal(512, node.info['total_ram_mb'].to_i)
+ end
+
+ test "stats disappear if not in a ping" do
+ node = ping_node(:idle, {total_ram_mb: '256'})
+ refute_includes(node.info, 'total_cpu_cores')
+ assert_equal(256, node.info['total_ram_mb'].to_i)
+ end
end