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 assert_equal 0, json_response['items'].size
21 assert_equal 0, json_response['items_available']
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 assert_operator 0, :<, json_response['items_available']
30 node_items = json_response['items']
31 assert_operator 0, :<, node_items.size
32 found_busy_node = false
33 node_items.each do |node|
34 assert_nil node['info'].andand['ping_secret']
35 assert_not_nil node['crunch_worker_state']
36 if node['uuid'] == nodes(:busy).uuid
37 found_busy_node = true
38 assert_equal 'busy', node['crunch_worker_state']
41 assert_equal true, found_busy_node
44 test "node should ping with ping_secret and no token" do
46 id: 'zzzzz-7ekkf-2z3mc76g2q73aio',
47 instance_id: 'i-0000000',
48 local_ipv4: '172.17.2.174',
49 ping_secret: '69udawxvn3zzj45hs8bumvndricrha4lcpi23pd69e44soanc0'
51 assert_response :success
52 response = JSON.parse(@response.body)
53 assert_equal 'zzzzz-7ekkf-2z3mc76g2q73aio', response['uuid']
54 # Ensure we are getting the "superuser" attributes, too
55 assert_not_nil response['first_ping_at'], '"first_ping_at" attr missing'
56 assert_not_nil response['info'], '"info" attr missing'
57 assert_not_nil response['nameservers'], '"nameservers" attr missing'
60 test "node should fail ping with invalid ping_secret" do
62 id: 'zzzzz-7ekkf-2z3mc76g2q73aio',
63 instance_id: 'i-0000000',
64 local_ipv4: '172.17.2.174',
65 ping_secret: 'dricrha4lcpi23pd69e44soanc069udawxvn3zzj45hs8bumvn'
72 post :create, {node: {}}
73 assert_response :success
74 assert_not_nil json_response['uuid']
75 assert_not_nil json_response['info'].is_a? Hash
76 assert_not_nil json_response['info']['ping_secret']
79 test "ping adds node stats to info" do
84 ping_secret: node.info['ping_secret'],
87 total_scratch_mb: 2048
89 assert_response :success
90 info = JSON.parse(@response.body)['info']
91 properties = JSON.parse(@response.body)['properties']
92 assert_equal(node.info['ping_secret'], info['ping_secret'])
93 assert_equal(32, properties['total_cpu_cores'].to_i)
94 assert_equal(1024, properties['total_ram_mb'].to_i)
95 assert_equal(2048, properties['total_scratch_mb'].to_i)
98 test "active user can see their assigned job" do
99 authorize_with :active
100 get :show, {id: nodes(:busy).uuid}
101 assert_response :success
102 assert_equal(jobs(:nearly_finished_job).uuid, json_response["job_uuid"])
105 test "user without job read permission can't see job" do
106 authorize_with :spectator
107 get :show, {id: nodes(:busy).uuid}
108 assert_response :success
109 assert_nil(json_response["job"], "spectator can see node's assigned job")
112 [:admin, :spectator].each do |user|
113 test "select param does not break node list for #{user}" do
115 get :index, {select: ['domain']}
116 assert_response :success
117 assert_operator 0, :<, json_response['items_available']
121 test "admin can associate a job with a node" do
122 changed_node = nodes(:idle)
123 assigned_job = jobs(:queued)
124 authorize_with :admin
126 id: changed_node.uuid,
127 node: {job_uuid: assigned_job.uuid},
129 assert_response :success
130 assert_equal(changed_node.hostname, json_response["hostname"],
131 "hostname mismatch after defining job")
132 assert_equal(assigned_job.uuid, json_response["job_uuid"],
133 "mismatch in node's assigned job UUID")
136 test "non-admin can't associate a job with a node" do
137 authorize_with :active
139 id: nodes(:idle).uuid,
140 node: {job_uuid: jobs(:queued).uuid},
145 test "admin can unassign a job from a node" do
146 changed_node = nodes(:busy)
147 authorize_with :admin
149 id: changed_node.uuid,
150 node: {job_uuid: nil},
152 assert_response :success
153 assert_equal(changed_node.hostname, json_response["hostname"],
154 "hostname mismatch after defining job")
155 assert_nil(json_response["job_uuid"],
156 "node still has job assignment after update")
159 test "non-admin can't unassign a job from a node" do
160 authorize_with :project_viewer
162 id: nodes(:busy).uuid,
163 node: {job_uuid: nil},
168 test "job readable after updating other attributes" do
169 authorize_with :admin
171 id: nodes(:busy).uuid,
172 node: {last_ping_at: 1.second.ago},
174 assert_response :success
175 assert_equal(jobs(:nearly_finished_job).uuid, json_response["job_uuid"],
176 "mismatched job UUID after ping update")
179 test "node should fail ping with invalid hostname config format" do
180 Rails.configuration.assign_node_hostname = 'compute%<slot_number>04' # should end with "04d"
182 id: nodes(:new_with_no_hostname).uuid,
183 ping_secret: nodes(:new_with_no_hostname).info['ping_secret'],
188 test "first ping should set ip addr using local_ipv4 when provided" do
190 id: 'zzzzz-7ekkf-nodenoipaddryet',
191 instance_id: 'i-0000000',
192 local_ipv4: '172.17.2.172',
193 ping_secret: 'abcdyefg4lb5q4gzqqtrnq30oyj08r8dtdimmanbqw49z1anz2'
195 assert_response :success
196 response = JSON.parse(@response.body)
197 assert_equal 'zzzzz-7ekkf-nodenoipaddryet', response['uuid']
198 assert_equal '172.17.2.172', response['ip_address']
201 test "first ping should set ip addr using remote_ip when local_ipv4 is not provided" do
203 id: 'zzzzz-7ekkf-nodenoipaddryet',
204 instance_id: 'i-0000000',
205 ping_secret: 'abcdyefg4lb5q4gzqqtrnq30oyj08r8dtdimmanbqw49z1anz2'
207 assert_response :success
208 response = JSON.parse(@response.body)
209 assert_equal 'zzzzz-7ekkf-nodenoipaddryet', response['uuid']
210 assert_equal request.remote_ip, response['ip_address']
213 test "future pings should not change previous ip address" do
215 id: 'zzzzz-7ekkf-2z3mc76g2q73aio',
216 instance_id: 'i-0000000',
217 local_ipv4: '172.17.2.175',
218 ping_secret: '69udawxvn3zzj45hs8bumvndricrha4lcpi23pd69e44soanc0'
220 assert_response :success
221 response = JSON.parse(@response.body)
222 assert_equal 'zzzzz-7ekkf-2z3mc76g2q73aio', response['uuid']
223 assert_equal '172.17.2.174', response['ip_address'] # original ip address is not overwritten