3 class Arvados::V1::NodesControllerTest < ActionController::TestCase
5 test "should get index with ping_secret" do
8 assert_response :success
9 assert_not_nil assigns(:objects)
10 node_items = JSON.parse(@response.body)['items']
11 assert_not_equal 0, node_items.size
12 assert_not_nil node_items[0]['info'].andand['ping_secret']
15 # inactive user does not see any nodes
16 test "inactive user should get empty index" do
17 authorize_with :inactive
19 assert_response :success
20 node_items = JSON.parse(@response.body)['items']
21 assert_equal 0, node_items.size
24 # active user sees non-secret attributes of up and recently-up nodes
25 test "active user should get non-empty index with no ping_secret" do
26 authorize_with :active
28 assert_response :success
29 node_items = JSON.parse(@response.body)['items']
30 assert_not_equal 0, node_items.size
31 found_busy_node = false
32 node_items.each do |node|
33 assert_nil node['info'].andand['ping_secret']
34 assert_not_nil node['crunch_worker_state']
35 if node['uuid'] == nodes(:busy).uuid
36 found_busy_node = true
37 assert_equal 'busy', node['crunch_worker_state']
40 assert_equal true, found_busy_node
43 test "node should ping with ping_secret and no token" do
45 id: 'zzzzz-7ekkf-2z3mc76g2q73aio',
46 instance_id: 'i-0000000',
47 local_ipv4: '172.17.2.174',
48 ping_secret: '69udawxvn3zzj45hs8bumvndricrha4lcpi23pd69e44soanc0'
50 assert_response :success
51 response = JSON.parse(@response.body)
52 assert_equal 'zzzzz-7ekkf-2z3mc76g2q73aio', response['uuid']
53 # Ensure we are getting the "superuser" attributes, too
54 assert_not_nil response['first_ping_at'], '"first_ping_at" attr missing'
55 assert_not_nil response['info'], '"info" attr missing'
56 assert_not_nil response['nameservers'], '"nameservers" attr missing'
59 test "node should fail ping with invalid ping_secret" do
61 id: 'zzzzz-7ekkf-2z3mc76g2q73aio',
62 instance_id: 'i-0000000',
63 local_ipv4: '172.17.2.174',
64 ping_secret: 'dricrha4lcpi23pd69e44soanc069udawxvn3zzj45hs8bumvn'
72 assert_response :success
73 assert_not_nil json_response['uuid']
74 assert_not_nil json_response['info'].is_a? Hash
75 assert_not_nil json_response['info']['ping_secret']
78 test "ping adds node stats to info" do
83 ping_secret: node.info['ping_secret'],
86 total_scratch_mb: 2048
88 assert_response :success
89 info = JSON.parse(@response.body)['info']
90 properties = JSON.parse(@response.body)['properties']
91 assert_equal(node.info['ping_secret'], info['ping_secret'])
92 assert_equal(32, properties['total_cpu_cores'].to_i)
93 assert_equal(1024, properties['total_ram_mb'].to_i)
94 assert_equal(2048, properties['total_scratch_mb'].to_i)
97 test "active user can see their assigned job" do
98 authorize_with :active
99 get :show, {id: nodes(:busy).uuid}
100 assert_response :success
101 assert_equal(jobs(:nearly_finished_job).uuid, json_response["job_uuid"])
104 test "user without job read permission can't see job" do
105 authorize_with :spectator
106 get :show, {id: nodes(:busy).uuid}
107 assert_response :success
108 assert_nil(json_response["job"], "spectator can see node's assigned job")
111 test "admin can associate a job with a node" do
112 changed_node = nodes(:idle)
113 assigned_job = jobs(:queued)
114 authorize_with :admin
116 id: changed_node.uuid,
117 node: {job_uuid: assigned_job.uuid},
119 assert_response :success
120 assert_equal(changed_node.hostname, json_response["hostname"],
121 "hostname mismatch after defining job")
122 assert_equal(assigned_job.uuid, json_response["job_uuid"],
123 "mismatch in node's assigned job UUID")
126 test "non-admin can't associate a job with a node" do
127 authorize_with :active
129 id: nodes(:idle).uuid,
130 node: {job_uuid: jobs(:queued).uuid},
135 test "admin can unassign a job from a node" do
136 changed_node = nodes(:busy)
137 authorize_with :admin
139 id: changed_node.uuid,
140 node: {job_uuid: nil},
142 assert_response :success
143 assert_equal(changed_node.hostname, json_response["hostname"],
144 "hostname mismatch after defining job")
145 assert_nil(json_response["job_uuid"],
146 "node still has job assignment after update")
149 test "non-admin can't unassign a job from a node" do
150 authorize_with :project_viewer
152 id: nodes(:busy).uuid,
153 node: {job_uuid: nil},
158 test "job readable after updating other attributes" do
159 authorize_with :admin
161 id: nodes(:busy).uuid,
162 node: {last_ping_at: 1.second.ago},
164 assert_response :success
165 assert_equal(jobs(:nearly_finished_job).uuid, json_response["job_uuid"],
166 "mismatched job UUID after ping update")