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'
71 post :create, {node: {}}
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 [:admin, :spectator].each do |user|
112 test "select param does not break node list for #{user}" do
114 get :index, {select: ['domain']}
115 assert_response :success
119 test "admin can associate a job with a node" do
120 changed_node = nodes(:idle)
121 assigned_job = jobs(:queued)
122 authorize_with :admin
124 id: changed_node.uuid,
125 node: {job_uuid: assigned_job.uuid},
127 assert_response :success
128 assert_equal(changed_node.hostname, json_response["hostname"],
129 "hostname mismatch after defining job")
130 assert_equal(assigned_job.uuid, json_response["job_uuid"],
131 "mismatch in node's assigned job UUID")
134 test "non-admin can't associate a job with a node" do
135 authorize_with :active
137 id: nodes(:idle).uuid,
138 node: {job_uuid: jobs(:queued).uuid},
143 test "admin can unassign a job from a node" do
144 changed_node = nodes(:busy)
145 authorize_with :admin
147 id: changed_node.uuid,
148 node: {job_uuid: nil},
150 assert_response :success
151 assert_equal(changed_node.hostname, json_response["hostname"],
152 "hostname mismatch after defining job")
153 assert_nil(json_response["job_uuid"],
154 "node still has job assignment after update")
157 test "non-admin can't unassign a job from a node" do
158 authorize_with :project_viewer
160 id: nodes(:busy).uuid,
161 node: {job_uuid: nil},
166 test "job readable after updating other attributes" do
167 authorize_with :admin
169 id: nodes(:busy).uuid,
170 node: {last_ping_at: 1.second.ago},
172 assert_response :success
173 assert_equal(jobs(:nearly_finished_job).uuid, json_response["job_uuid"],
174 "mismatched job UUID after ping update")
177 test "node should fail ping with invalid hostname config format" do
178 Rails.configuration.assign_node_hostname = 'compute%<slot_number>04' # should end with "04d"
180 id: nodes(:new_with_no_hostname).uuid,
181 ping_secret: nodes(:new_with_no_hostname).info['ping_secret'],
186 test "first ping should set ip addr using local_ipv4 when provided" do
188 id: 'zzzzz-7ekkf-nodenoipaddryet',
189 instance_id: 'i-0000000',
190 local_ipv4: '172.17.2.172',
191 ping_secret: 'abcdyefg4lb5q4gzqqtrnq30oyj08r8dtdimmanbqw49z1anz2'
193 assert_response :success
194 response = JSON.parse(@response.body)
195 assert_equal 'zzzzz-7ekkf-nodenoipaddryet', response['uuid']
196 assert_equal '172.17.2.172', response['ip_address']
199 test "first ping should set ip addr using remote_ip when local_ipv4 is not provided" do
201 id: 'zzzzz-7ekkf-nodenoipaddryet',
202 instance_id: 'i-0000000',
203 ping_secret: 'abcdyefg4lb5q4gzqqtrnq30oyj08r8dtdimmanbqw49z1anz2'
205 assert_response :success
206 response = JSON.parse(@response.body)
207 assert_equal 'zzzzz-7ekkf-nodenoipaddryet', response['uuid']
208 assert_equal request.remote_ip, response['ip_address']
211 test "future pings should not change previous ip address" do
213 id: 'zzzzz-7ekkf-2z3mc76g2q73aio',
214 instance_id: 'i-0000000',
215 local_ipv4: '172.17.2.175',
216 ping_secret: '69udawxvn3zzj45hs8bumvndricrha4lcpi23pd69e44soanc0'
218 assert_response :success
219 response = JSON.parse(@response.body)
220 assert_equal 'zzzzz-7ekkf-2z3mc76g2q73aio', response['uuid']
221 assert_equal '172.17.2.174', response['ip_address'] # original ip address is not overwritten