17004: Allow output_properties to override the default metadata
authorPeter Amstutz <peter.amstutz@curii.com>
Tue, 10 May 2022 15:26:44 +0000 (11:26 -0400)
committerPeter Amstutz <peter.amstutz@curii.com>
Fri, 13 May 2022 20:44:43 +0000 (16:44 -0400)
Arvados-DCO-1.1-Signed-off-by: Peter Amstutz <peter.amstutz@curii.com>

services/api/app/models/container_request.rb
services/api/test/unit/container_request_test.rb

index 605b376cf55c917848f08f07df7e3c3c2e1ddd99..911603590586a6e1cbaddb8a2f575940ff0d8cd3 100644 (file)
@@ -237,17 +237,20 @@ class ContainerRequest < ArvadosModel
       end
 
       merged_properties = {}
-      if out_type == "output"
-        merged_properties.update(container.output_properties)
-        merged_properties.update(self.output_properties)
-      end
+      merged_properties['container_request'] = uuid
 
       if out_type == 'output' and !requesting_container_uuid.nil?
-          merged_properties['type'] = 'intermediate'
+        # output of a child process, give it "intermediate" type by
+        # default.
+        merged_properties['type'] = 'intermediate'
       else
         merged_properties['type'] = out_type
       end
-      merged_properties['container_request'] = uuid
+
+      if out_type == "output"
+        merged_properties.update(container.output_properties)
+        merged_properties.update(self.output_properties)
+      end
 
       coll.assign_attributes(
         portable_data_hash: Digest::MD5.hexdigest(manifest) + '+' + manifest.bytesize.to_s,
index 5a75fb5fa2835ee8199301c3eb8bd3cea19a88c9..e5c0085184ec5b0f4690b11decfadd1fb82be5b3 100644 (file)
@@ -469,13 +469,34 @@ class ContainerRequestTest < ActiveSupport::TestCase
   ].each do |token, expected, expected_priority|
     test "create as #{token} and expect requesting_container_uuid to be #{expected}" do
       set_user_from_auth token
-      cr = ContainerRequest.create(container_image: "img", output_path: "/tmp", command: ["echo", "foo"])
+      cr = create_minimal_req!
       assert_not_nil cr.uuid, 'uuid should be set for newly created container_request'
       assert_equal expected, cr.requesting_container_uuid
       assert_equal expected_priority, cr.priority
     end
   end
 
+  [
+    ['running_container_auth', 'zzzzz-dz642-runningcontainr', 501],
+  ].each do |token, expected, expected_priority|
+    test "create as #{token} with requesting_container_uuid set and expect output to be intermediate" do
+      set_user_from_auth token
+      cr = create_minimal_req!
+      assert_not_nil cr.uuid, 'uuid should be set for newly created container_request'
+      assert_equal expected, cr.requesting_container_uuid
+      assert_equal expected_priority, cr.priority
+
+      cr.state = ContainerRequest::Committed
+      cr.save!
+
+      run_container(cr)
+      cr.reload
+      output = Collection.find_by_uuid(cr.output_uuid)
+      props = {"type": "intermediate", "container_request": cr.uuid}
+      assert_equal props.symbolize_keys, output.properties.symbolize_keys
+    end
+  end
+
   test "create as container_runtime_token and expect requesting_container_uuid to be zzzzz-dz642-20isqbkl8xwnsao" do
     set_user_from_auth :container_runtime_token
     Thread.current[:token] = "#{Thread.current[:token]}/zzzzz-dz642-20isqbkl8xwnsao"
@@ -1455,7 +1476,7 @@ class ContainerRequestTest < ActiveSupport::TestCase
     [{},               {"a1": "b1"}, {"type": "output", "a1": "b1"}],
     [{"a1": "b1"},     {"a1": "c1"}, {"type": "output", "a1": "b1"}],
     [{"a1": "b1"},     {"a2": "c2"}, {"type": "output", "a1": "b1", "a2": "c2"}],
-    [{"type": "blah"}, {},           {"type": "output"}],
+    [{"type": "blah"}, {},           {"type": "blah"}],
   ].each do |cr_prop, container_prop, expect_prop|
     test "setting output_properties #{cr_prop} #{container_prop} on current container" do
       act_as_user users(:active) do