Project

General

Profile

Revision ef3feba4

Added by Daniel Lobato Garcia over 6 years ago

Fixes #9752 - Pass Docker errors to controller

View differences:

app/models/service/containers.rb
38 38
        container.send(:"#{taxonomy}=", wizard_state.preliminary.send(:"#{taxonomy}"))
39 39
      end
40 40

  
41
      unless container.valid?
42
        @errors = container.errors
43
        fail ActiveRecord::Rollback
44
      end
41
      pull_image(container)
42
      start_container(container)
43
      errors << container.errors unless container.valid?
45 44

  
46
      fail ActiveRecord::Rollback unless pull_image(container) && start_container(container)
45
      fail ActiveRecord::Rollback if @errors.present?
47 46

  
48 47
      container.name = container.in_fog.name[1..-1] unless container.name.present?
49 48

  
......
51 50
    end
52 51

  
53 52
    def pull_image(container)
54
      container.compute_resource.create_image(:fromImage => container.repository_pull_url)
53
      success = container.compute_resource.
54
        create_image(:fromImage => container.repository_pull_url)
55
      errors << container.compute_resource.errors[:base] unless success
55 56
    end
56 57

  
57 58
    def start_container(container)
test/units/containers_service_test.rb
24 24
    Fog.unmock!
25 25
    assert_equal DockerContainerWizardState.where(:id => @state.id).count, 0
26 26
  end
27

  
28
  test 'passes errors from compute resource' do
29
    # Since the compute resource will be unreachable, this test will always
30
    # fail at the 'pull_image' step
31
    containers_service = Service::Containers.new
32
    assert_raises(ActiveRecord::Rollback) do
33
      containers_service.create_container_object(@state)
34
    end
35
    assert containers_service.errors.present?
36
  end
37

  
27 38
end

Also available in: Unified diff