Project

General

Profile

Revision b2f2c848

Added by Shlomi Zadok about 6 years ago

Refs #14570 - Destroy Container db object
When deleting with container uuid params, the container object should be destroyed as well

View differences:

app/controllers/containers_controller.rb
102 102
    if params[:compute_resource_id].present?
103 103
      compute_resource_id = params[:compute_resource_id]
104 104
      container_uuid      = params[:id]
105
      @container ||= Container.authorized("#{action_permission}_#{controller_name}".to_sym).find_by_uuid(container_uuid)
105 106
    else
106 107
      find_container
107 108
      compute_resource_id = @container.compute_resource_id
test/functionals/containers_controller_test.rb
59 59
        flash[:notice]
60 60
    end
61 61

  
62
    test 'deleting with container params deletes container object' do
63
      managed_container = FactoryGirl.create(
64
        :container,
65
        :compute_resource => @container_resource)
66
      managed_container.update(:uuid => @container.id)
67
      ComputeResource.any_instance.expects(:destroy_vm).
68
        with(@container.id).returns(true)
69
      Container.any_instance.expects(:destroy)
70
      delete :destroy, { :compute_resource_id => @container_resource.id,
71
                         :id                  => @container.id }, set_session_user
72
      assert_redirected_to containers_path
73
      assert_equal "Container #{managed_container.uuid} is being deleted.",
74
        flash[:notice]
75
    end
76

  
62 77
    test 'failed deletion of managed container keeps container in Foreman' do
63 78
      ComputeResource.any_instance.stubs(:destroy_vm).
64 79
        raises(::Foreman::Exception.new('Could not destroy Docker container'))

Also available in: Unified diff