11308: Remove obsolete test setup steps.
[arvados.git] / services / api / test / unit / container_request_test.rb
1 require 'test_helper'
2 require 'helpers/docker_migration_helper'
3
4 class ContainerRequestTest < ActiveSupport::TestCase
5   include DockerMigrationHelper
6
7   def create_minimal_req! attrs={}
8     defaults = {
9       command: ["echo", "foo"],
10       container_image: links(:docker_image_collection_tag).name,
11       cwd: "/tmp",
12       environment: {},
13       mounts: {"/out" => {"kind" => "tmp", "capacity" => 1000000}},
14       output_path: "/out",
15       runtime_constraints: {"vcpus" => 1, "ram" => 2},
16       name: "foo",
17       description: "bar",
18     }
19     cr = ContainerRequest.create!(defaults.merge(attrs))
20     cr.reload
21     return cr
22   end
23
24   def check_bogus_states cr
25     [nil, "Flubber"].each do |state|
26       assert_raises(ActiveRecord::RecordInvalid) do
27         cr.state = state
28         cr.save!
29       end
30       cr.reload
31     end
32   end
33
34   test "Container request create" do
35     set_user_from_auth :active
36     cr = create_minimal_req!
37
38     assert_nil cr.container_uuid
39     assert_nil cr.priority
40
41     check_bogus_states cr
42
43     # Ensure we can modify all attributes
44     cr.command = ["echo", "foo3"]
45     cr.container_image = "img3"
46     cr.cwd = "/tmp3"
47     cr.environment = {"BUP" => "BOP"}
48     cr.mounts = {"BAR" => "BAZ"}
49     cr.output_path = "/tmp4"
50     cr.priority = 2
51     cr.runtime_constraints = {"vcpus" => 4}
52     cr.name = "foo3"
53     cr.description = "bar3"
54     cr.save!
55
56     assert_nil cr.container_uuid
57   end
58
59   [
60     {"vcpus" => 1},
61     {"vcpus" => 1, "ram" => nil},
62     {"vcpus" => 0, "ram" => 123},
63     {"vcpus" => "1", "ram" => "123"}
64   ].each do |invalid_constraints|
65     test "Create with #{invalid_constraints}" do
66       set_user_from_auth :active
67       assert_raises(ActiveRecord::RecordInvalid) do
68         cr = create_minimal_req!(state: "Committed",
69                                  priority: 1,
70                                  runtime_constraints: invalid_constraints)
71         cr.save!
72       end
73     end
74
75     test "Update with #{invalid_constraints}" do
76       set_user_from_auth :active
77       cr = create_minimal_req!(state: "Uncommitted", priority: 1)
78       cr.save!
79       assert_raises(ActiveRecord::RecordInvalid) do
80         cr = ContainerRequest.find_by_uuid cr.uuid
81         cr.update_attributes!(state: "Committed",
82                               runtime_constraints: invalid_constraints)
83       end
84     end
85   end
86
87   test "Update from fixture" do
88     set_user_from_auth :active
89     cr = ContainerRequest.find_by_uuid(container_requests(:running).uuid)
90     cr.update_attributes!(description: "New description")
91     assert_equal "New description", cr.description
92   end
93
94   test "Update with valid runtime constraints" do
95       set_user_from_auth :active
96       cr = create_minimal_req!(state: "Uncommitted", priority: 1)
97       cr.save!
98       cr = ContainerRequest.find_by_uuid cr.uuid
99       cr.update_attributes!(state: "Committed",
100                             runtime_constraints: {"vcpus" => 1, "ram" => 23})
101       assert_not_nil cr.container_uuid
102   end
103
104   test "Container request priority must be non-nil" do
105     set_user_from_auth :active
106     cr = create_minimal_req!(priority: nil)
107     cr.state = "Committed"
108     assert_raises(ActiveRecord::RecordInvalid) do
109       cr.save!
110     end
111   end
112
113   test "Container request commit" do
114     set_user_from_auth :active
115     cr = create_minimal_req!(runtime_constraints: {"vcpus" => 2, "ram" => 30})
116
117     assert_nil cr.container_uuid
118
119     cr.reload
120     cr.state = "Committed"
121     cr.priority = 1
122     cr.save!
123
124     cr.reload
125
126     assert_equal({"vcpus" => 2, "ram" => 30}, cr.runtime_constraints)
127
128     assert_not_nil cr.container_uuid
129     c = Container.find_by_uuid cr.container_uuid
130     assert_not_nil c
131     assert_equal ["echo", "foo"], c.command
132     assert_equal collections(:docker_image).portable_data_hash, c.container_image
133     assert_equal "/tmp", c.cwd
134     assert_equal({}, c.environment)
135     assert_equal({"/out" => {"kind"=>"tmp", "capacity"=>1000000}}, c.mounts)
136     assert_equal "/out", c.output_path
137     assert_equal({"keep_cache_ram"=>268435456, "vcpus" => 2, "ram" => 30}, c.runtime_constraints)
138     assert_equal 1, c.priority
139
140     assert_raises(ActiveRecord::RecordInvalid) do
141       cr.priority = nil
142       cr.save!
143     end
144
145     cr.priority = 0
146     cr.save!
147
148     cr.reload
149     c.reload
150     assert_equal 0, cr.priority
151     assert_equal 0, c.priority
152   end
153
154
155   test "Container request max priority" do
156     set_user_from_auth :active
157     cr = create_minimal_req!(priority: 5, state: "Committed")
158
159     c = Container.find_by_uuid cr.container_uuid
160     assert_equal 5, c.priority
161
162     cr2 = create_minimal_req!
163     cr2.priority = 10
164     cr2.state = "Committed"
165     cr2.container_uuid = cr.container_uuid
166     act_as_system_user do
167       cr2.save!
168     end
169
170     # cr and cr2 have priority 5 and 10, and are being satisfied by
171     # the same container c, so c's priority should be
172     # max(priority)=10.
173     c.reload
174     assert_equal 10, c.priority
175
176     cr2.update_attributes!(priority: 0)
177
178     c.reload
179     assert_equal 5, c.priority
180
181     cr.update_attributes!(priority: 0)
182
183     c.reload
184     assert_equal 0, c.priority
185   end
186
187
188   test "Independent container requests" do
189     set_user_from_auth :active
190     cr1 = create_minimal_req!(command: ["foo", "1"], priority: 5, state: "Committed")
191     cr2 = create_minimal_req!(command: ["foo", "2"], priority: 10, state: "Committed")
192
193     c1 = Container.find_by_uuid cr1.container_uuid
194     assert_equal 5, c1.priority
195
196     c2 = Container.find_by_uuid cr2.container_uuid
197     assert_equal 10, c2.priority
198
199     cr1.update_attributes!(priority: 0)
200
201     c1.reload
202     assert_equal 0, c1.priority
203
204     c2.reload
205     assert_equal 10, c2.priority
206   end
207
208   test "Request is finalized when its container is cancelled" do
209     set_user_from_auth :active
210     cr = create_minimal_req!(priority: 1, state: "Committed", container_count_max: 1)
211
212     act_as_system_user do
213       Container.find_by_uuid(cr.container_uuid).
214         update_attributes!(state: Container::Cancelled)
215     end
216
217     cr.reload
218     assert_equal "Final", cr.state
219   end
220
221   test "Request is finalized when its container is completed" do
222     set_user_from_auth :active
223     project = groups(:private)
224     cr = create_minimal_req!(owner_uuid: project.uuid,
225                              priority: 1,
226                              state: "Committed")
227
228     c = act_as_system_user do
229       c = Container.find_by_uuid(cr.container_uuid)
230       c.update_attributes!(state: Container::Locked)
231       c.update_attributes!(state: Container::Running)
232       c
233     end
234
235     cr.reload
236     assert_equal "Committed", cr.state
237
238     output_pdh = '1f4b0bc7583c2a7f9102c395f4ffc5e3+45'
239     log_pdh = 'fa7aeb5140e2848d39b416daeef4ffc5+45'
240     act_as_system_user do
241       c.update_attributes!(state: Container::Complete,
242                            output: output_pdh,
243                            log: log_pdh)
244     end
245
246     cr.reload
247     assert_equal "Final", cr.state
248     ['output', 'log'].each do |out_type|
249       pdh = Container.find_by_uuid(cr.container_uuid).send(out_type)
250       assert_equal(1, Collection.where(portable_data_hash: pdh,
251                                        owner_uuid: project.uuid).count,
252                    "Container #{out_type} should be copied to #{project.uuid}")
253     end
254     assert_not_nil cr.output_uuid
255     assert_not_nil cr.log_uuid
256     output = Collection.find_by_uuid cr.output_uuid
257     assert_equal output_pdh, output.portable_data_hash
258     log = Collection.find_by_uuid cr.log_uuid
259     assert_equal log_pdh, log.portable_data_hash
260   end
261
262   test "Container makes container request, then is cancelled" do
263     set_user_from_auth :active
264     cr = create_minimal_req!(priority: 5, state: "Committed", container_count_max: 1)
265
266     c = Container.find_by_uuid cr.container_uuid
267     assert_equal 5, c.priority
268
269     cr2 = create_minimal_req!
270     cr2.update_attributes!(priority: 10, state: "Committed", requesting_container_uuid: c.uuid, command: ["echo", "foo2"], container_count_max: 1)
271     cr2.reload
272
273     c2 = Container.find_by_uuid cr2.container_uuid
274     assert_equal 10, c2.priority
275
276     act_as_system_user do
277       c.state = "Cancelled"
278       c.save!
279     end
280
281     cr.reload
282     assert_equal "Final", cr.state
283
284     cr2.reload
285     assert_equal 0, cr2.priority
286
287     c2.reload
288     assert_equal 0, c2.priority
289   end
290
291   [
292     ['running_container_auth', 'zzzzz-dz642-runningcontainr'],
293     ['active_no_prefs', nil],
294   ].each do |token, expected|
295     test "create as #{token} and expect requesting_container_uuid to be #{expected}" do
296       set_user_from_auth token
297       cr = ContainerRequest.create(container_image: "img", output_path: "/tmp", command: ["echo", "foo"])
298       assert_not_nil cr.uuid, 'uuid should be set for newly created container_request'
299       assert_equal expected, cr.requesting_container_uuid
300     end
301   end
302
303   [[{"vcpus" => [2, nil]},
304     lambda { |resolved| resolved["vcpus"] == 2 }],
305    [{"vcpus" => [3, 7]},
306     lambda { |resolved| resolved["vcpus"] == 3 }],
307    [{"vcpus" => 4},
308     lambda { |resolved| resolved["vcpus"] == 4 }],
309    [{"ram" => [1000000000, 2000000000]},
310     lambda { |resolved| resolved["ram"] == 1000000000 }],
311    [{"ram" => [1234234234]},
312     lambda { |resolved| resolved["ram"] == 1234234234 }],
313   ].each do |rc, okfunc|
314     test "resolve runtime constraint range #{rc} to values" do
315       resolved = Container.resolve_runtime_constraints(rc)
316       assert(okfunc.call(resolved),
317              "container runtime_constraints was #{resolved.inspect}")
318     end
319   end
320
321   [[{"/out" => {
322         "kind" => "collection",
323         "uuid" => "zzzzz-4zz18-znfnqtbbv4spc3w",
324         "path" => "/foo"}},
325     lambda do |resolved|
326       resolved["/out"] == {
327         "portable_data_hash" => "1f4b0bc7583c2a7f9102c395f4ffc5e3+45",
328         "kind" => "collection",
329         "path" => "/foo",
330       }
331     end],
332    [{"/out" => {
333         "kind" => "collection",
334         "uuid" => "zzzzz-4zz18-znfnqtbbv4spc3w",
335         "portable_data_hash" => "1f4b0bc7583c2a7f9102c395f4ffc5e3+45",
336         "path" => "/foo"}},
337     lambda do |resolved|
338       resolved["/out"] == {
339         "portable_data_hash" => "1f4b0bc7583c2a7f9102c395f4ffc5e3+45",
340         "kind" => "collection",
341         "path" => "/foo",
342       }
343     end],
344   ].each do |mounts, okfunc|
345     test "resolve mounts #{mounts.inspect} to values" do
346       set_user_from_auth :active
347       resolved = Container.resolve_mounts(mounts)
348       assert(okfunc.call(resolved),
349              "Container.resolve_mounts returned #{resolved.inspect}")
350     end
351   end
352
353   test 'mount unreadable collection' do
354     set_user_from_auth :spectator
355     m = {
356       "/foo" => {
357         "kind" => "collection",
358         "uuid" => "zzzzz-4zz18-znfnqtbbv4spc3w",
359         "path" => "/foo",
360       },
361     }
362     assert_raises(ArvadosModel::UnresolvableContainerError) do
363       Container.resolve_mounts(m)
364     end
365   end
366
367   test 'mount collection with mismatched UUID and PDH' do
368     set_user_from_auth :active
369     m = {
370       "/foo" => {
371         "kind" => "collection",
372         "uuid" => "zzzzz-4zz18-znfnqtbbv4spc3w",
373         "portable_data_hash" => "fa7aeb5140e2848d39b416daeef4ffc5+45",
374         "path" => "/foo",
375       },
376     }
377     assert_raises(ArgumentError) do
378       Container.resolve_mounts(m)
379     end
380   end
381
382   ['arvados/apitestfixture:latest',
383    'arvados/apitestfixture',
384    'd8309758b8fe2c81034ffc8a10c36460b77db7bc5e7b448c4e5b684f9d95a678',
385   ].each do |tag|
386     test "Container.resolve_container_image(#{tag.inspect})" do
387       set_user_from_auth :active
388       resolved = Container.resolve_container_image(tag)
389       assert_equal resolved, collections(:docker_image).portable_data_hash
390     end
391   end
392
393   test "Container.resolve_container_image(pdh)" do
394     set_user_from_auth :active
395     [[:docker_image, 'v1'], [:docker_image_1_12, 'v2']].each do |coll, ver|
396       Rails.configuration.docker_image_formats = [ver]
397       pdh = collections(coll).portable_data_hash
398       resolved = Container.resolve_container_image(pdh)
399       assert_equal resolved, pdh
400     end
401   end
402
403   ['acbd18db4cc2f85cedef654fccc4a4d8+3',
404    'ENOEXIST',
405    'arvados/apitestfixture:ENOEXIST',
406   ].each do |img|
407     test "container_image_for_container(#{img.inspect}) => 422" do
408       set_user_from_auth :active
409       assert_raises(ArvadosModel::UnresolvableContainerError) do
410         Container.resolve_container_image(img)
411       end
412     end
413   end
414
415   test "migrated docker image" do
416     Rails.configuration.docker_image_formats = ['v2']
417     add_docker19_migration_link
418
419     # Test that it returns only v2 images even though request is for v1 image.
420
421     set_user_from_auth :active
422     cr = create_minimal_req!(command: ["true", "1"],
423                              container_image: collections(:docker_image).portable_data_hash)
424     assert_equal(Container.resolve_container_image(cr.container_image),
425                  collections(:docker_image_1_12).portable_data_hash)
426
427     cr = create_minimal_req!(command: ["true", "2"],
428                              container_image: links(:docker_image_collection_tag).name)
429     assert_equal(Container.resolve_container_image(cr.container_image),
430                  collections(:docker_image_1_12).portable_data_hash)
431   end
432
433   test "use unmigrated docker image" do
434     Rails.configuration.docker_image_formats = ['v1']
435     add_docker19_migration_link
436
437     # Test that it returns only supported v1 images even though there is a
438     # migration link.
439
440     set_user_from_auth :active
441     cr = create_minimal_req!(command: ["true", "1"],
442                              container_image: collections(:docker_image).portable_data_hash)
443     assert_equal(Container.resolve_container_image(cr.container_image),
444                  collections(:docker_image).portable_data_hash)
445
446     cr = create_minimal_req!(command: ["true", "2"],
447                              container_image: links(:docker_image_collection_tag).name)
448     assert_equal(Container.resolve_container_image(cr.container_image),
449                  collections(:docker_image).portable_data_hash)
450   end
451
452   test "incompatible docker image v1" do
453     Rails.configuration.docker_image_formats = ['v1']
454     add_docker19_migration_link
455
456     # Don't return unsupported v2 image even if we ask for it directly.
457     set_user_from_auth :active
458     cr = create_minimal_req!(command: ["true", "1"],
459                              container_image: collections(:docker_image_1_12).portable_data_hash)
460     assert_raises(ArvadosModel::UnresolvableContainerError) do
461       Container.resolve_container_image(cr.container_image)
462     end
463   end
464
465   test "incompatible docker image v2" do
466     Rails.configuration.docker_image_formats = ['v2']
467     # No migration link, don't return unsupported v1 image,
468
469     set_user_from_auth :active
470     cr = create_minimal_req!(command: ["true", "1"],
471                              container_image: collections(:docker_image).portable_data_hash)
472     assert_raises(ArvadosModel::UnresolvableContainerError) do
473       Container.resolve_container_image(cr.container_image)
474     end
475     cr = create_minimal_req!(command: ["true", "2"],
476                              container_image: links(:docker_image_collection_tag).name)
477     assert_raises(ArvadosModel::UnresolvableContainerError) do
478       Container.resolve_container_image(cr.container_image)
479     end
480   end
481
482   test "requestor can retrieve container owned by dispatch" do
483     assert_not_empty Container.readable_by(users(:admin)).where(uuid: containers(:running).uuid)
484     assert_not_empty Container.readable_by(users(:active)).where(uuid: containers(:running).uuid)
485     assert_empty Container.readable_by(users(:spectator)).where(uuid: containers(:running).uuid)
486   end
487
488   [
489     [{"var" => "value1"}, {"var" => "value1"}, nil],
490     [{"var" => "value1"}, {"var" => "value1"}, true],
491     [{"var" => "value1"}, {"var" => "value1"}, false],
492     [{"var" => "value1"}, {"var" => "value2"}, nil],
493   ].each do |env1, env2, use_existing|
494     test "Container request #{((env1 == env2) and (use_existing.nil? or use_existing == true)) ? 'does' : 'does not'} reuse container when committed#{use_existing.nil? ? '' : use_existing ? ' and use_existing == true' : ' and use_existing == false'}" do
495       common_attrs = {cwd: "test",
496                       priority: 1,
497                       command: ["echo", "hello"],
498                       output_path: "test",
499                       runtime_constraints: {"vcpus" => 4,
500                                             "ram" => 12000000000},
501                       mounts: {"test" => {"kind" => "json"}}}
502       set_user_from_auth :active
503       cr1 = create_minimal_req!(common_attrs.merge({state: ContainerRequest::Committed,
504                                                     environment: env1}))
505       if use_existing.nil?
506         # Testing with use_existing default value
507         cr2 = create_minimal_req!(common_attrs.merge({state: ContainerRequest::Uncommitted,
508                                                       environment: env2}))
509       else
510
511         cr2 = create_minimal_req!(common_attrs.merge({state: ContainerRequest::Uncommitted,
512                                                       environment: env2,
513                                                       use_existing: use_existing}))
514       end
515       assert_not_nil cr1.container_uuid
516       assert_nil cr2.container_uuid
517
518       # Update cr2 to commited state and check for container equality on different cases:
519       # * When env1 and env2 are equal and use_existing is true, the same container
520       #   should be assigned.
521       # * When use_existing is false, a different container should be assigned.
522       # * When env1 and env2 are different, a different container should be assigned.
523       cr2.update_attributes!({state: ContainerRequest::Committed})
524       assert_equal (cr2.use_existing == true and (env1 == env2)),
525                    (cr1.container_uuid == cr2.container_uuid)
526     end
527   end
528
529   test "requesting_container_uuid at create is not allowed" do
530     set_user_from_auth :active
531     assert_raises(ActiveRecord::RecordNotSaved) do
532       create_minimal_req!(state: "Uncommitted", priority: 1, requesting_container_uuid: 'youcantdothat')
533     end
534   end
535
536   test "Retry on container cancelled" do
537     set_user_from_auth :active
538     cr = create_minimal_req!(priority: 1, state: "Committed", container_count_max: 2)
539     cr2 = create_minimal_req!(priority: 1, state: "Committed", container_count_max: 2, command: ["echo", "baz"])
540     prev_container_uuid = cr.container_uuid
541
542     c = act_as_system_user do
543       c = Container.find_by_uuid(cr.container_uuid)
544       c.update_attributes!(state: Container::Locked)
545       c.update_attributes!(state: Container::Running)
546       c
547     end
548
549     cr.reload
550     cr2.reload
551     assert_equal "Committed", cr.state
552     assert_equal prev_container_uuid, cr.container_uuid
553     assert_not_equal cr2.container_uuid, cr.container_uuid
554     prev_container_uuid = cr.container_uuid
555
556     act_as_system_user do
557       c.update_attributes!(state: Container::Cancelled)
558     end
559
560     cr.reload
561     cr2.reload
562     assert_equal "Committed", cr.state
563     assert_not_equal prev_container_uuid, cr.container_uuid
564     assert_not_equal cr2.container_uuid, cr.container_uuid
565     prev_container_uuid = cr.container_uuid
566
567     c = act_as_system_user do
568       c = Container.find_by_uuid(cr.container_uuid)
569       c.update_attributes!(state: Container::Cancelled)
570       c
571     end
572
573     cr.reload
574     cr2.reload
575     assert_equal "Final", cr.state
576     assert_equal prev_container_uuid, cr.container_uuid
577     assert_not_equal cr2.container_uuid, cr.container_uuid
578   end
579
580   test "Output collection name setting using output_name with name collision resolution" do
581     set_user_from_auth :active
582     output_name = collections(:foo_file).name
583
584     cr = create_minimal_req!(priority: 1,
585                              state: ContainerRequest::Committed,
586                              output_name: output_name)
587     act_as_system_user do
588       c = Container.find_by_uuid(cr.container_uuid)
589       c.update_attributes!(state: Container::Locked)
590       c.update_attributes!(state: Container::Running)
591       c.update_attributes!(state: Container::Complete,
592                            exit_code: 0,
593                            output: '1f4b0bc7583c2a7f9102c395f4ffc5e3+45',
594                            log: 'fa7aeb5140e2848d39b416daeef4ffc5+45')
595     end
596     cr.save
597     assert_equal ContainerRequest::Final, cr.state
598     output_coll = Collection.find_by_uuid(cr.output_uuid)
599     # Make sure the resulting output collection name include the original name
600     # plus the date
601     assert_not_equal output_name, output_coll.name,
602                      "It shouldn't exist more than one collection with the same owner and name '${output_name}'"
603     assert output_coll.name.include?(output_name),
604            "New name should include original name"
605     assert_match /\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}\.\d+Z/, output_coll.name,
606                  "New name should include ISO8601 date"
607   end
608
609   test "Finalize committed request when reusing a finished container" do
610     set_user_from_auth :active
611     cr = create_minimal_req!(priority: 1, state: ContainerRequest::Committed)
612     cr.reload
613     assert_equal ContainerRequest::Committed, cr.state
614     act_as_system_user do
615       c = Container.find_by_uuid(cr.container_uuid)
616       c.update_attributes!(state: Container::Locked)
617       c.update_attributes!(state: Container::Running)
618       c.update_attributes!(state: Container::Complete,
619                            exit_code: 0,
620                            output: '1f4b0bc7583c2a7f9102c395f4ffc5e3+45',
621                            log: 'fa7aeb5140e2848d39b416daeef4ffc5+45')
622     end
623     cr.reload
624     assert_equal ContainerRequest::Final, cr.state
625
626     cr2 = create_minimal_req!(priority: 1, state: ContainerRequest::Committed)
627     assert_equal cr.container_uuid, cr2.container_uuid
628     assert_equal ContainerRequest::Final, cr2.state
629
630     cr3 = create_minimal_req!(priority: 1, state: ContainerRequest::Uncommitted)
631     assert_equal ContainerRequest::Uncommitted, cr3.state
632     cr3.update_attributes!(state: ContainerRequest::Committed)
633     assert_equal cr.container_uuid, cr3.container_uuid
634     assert_equal ContainerRequest::Final, cr3.state
635   end
636
637   [
638     [{"partitions" => ["fastcpu","vfastcpu", 100]}, ContainerRequest::Committed, ActiveRecord::RecordInvalid],
639     [{"partitions" => ["fastcpu","vfastcpu", 100]}, ContainerRequest::Uncommitted],
640     [{"partitions" => "fastcpu"}, ContainerRequest::Committed, ActiveRecord::RecordInvalid],
641     [{"partitions" => "fastcpu"}, ContainerRequest::Uncommitted],
642     [{"partitions" => ["fastcpu","vfastcpu"]}, ContainerRequest::Committed],
643   ].each do |sp, state, expected|
644     test "create container request with scheduling_parameters #{sp} in state #{state} and verify #{expected}" do
645       common_attrs = {cwd: "test",
646                       priority: 1,
647                       command: ["echo", "hello"],
648                       output_path: "test",
649                       scheduling_parameters: sp,
650                       mounts: {"test" => {"kind" => "json"}}}
651       set_user_from_auth :active
652
653       if expected == ActiveRecord::RecordInvalid
654         assert_raises(ActiveRecord::RecordInvalid) do
655           create_minimal_req!(common_attrs.merge({state: state}))
656         end
657       else
658         cr = create_minimal_req!(common_attrs.merge({state: state}))
659         assert_equal sp, cr.scheduling_parameters
660
661         if state == ContainerRequest::Committed
662           c = Container.find_by_uuid(cr.container_uuid)
663           assert_equal sp, c.scheduling_parameters
664         end
665       end
666     end
667   end
668 end