From af341538fc218ecbb5b2c288d49f20ef0e7c7c25 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miha=20Ple=C5=A1ko?= Date: Mon, 27 May 2019 14:24:42 +0200 Subject: [PATCH] Support firmware update MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit With this commit we expose neccessary operations for UI to be able to render a functional "Firmware Update" modal. User has to pick a firmware binary from the drop-down to apply it to selected server(s). Eventually, when she submits the modal, a new Request of type PhysicalServerFirmwareUpdateRequest is created by means of POSTing to `/api/request`. Signed-off-by: Miha Pleško --- .../api/physical_servers_controller.rb | 4 +++ config/api.yml | 14 ++++++++ spec/requests/physical_servers_spec.rb | 35 +++++++++++++++++++ 3 files changed, 53 insertions(+) diff --git a/app/controllers/api/physical_servers_controller.rb b/app/controllers/api/physical_servers_controller.rb index 109dfe9cd1..dc6ce9aa5c 100644 --- a/app/controllers/api/physical_servers_controller.rb +++ b/app/controllers/api/physical_servers_controller.rb @@ -65,6 +65,10 @@ def apply_config_pattern_resource(type, id, data) action_result(false, err.to_s) end + def firmware_binaries_query_resource(object) + object.compatible_firmware_binaries + end + private def change_resource_state(state, type, id, data = []) diff --git a/config/api.yml b/config/api.yml index 0a9a4e3581..c71143402c 100644 --- a/config/api.yml +++ b/config/api.yml @@ -1225,6 +1225,16 @@ :post: - :name: assign - :name: unassign + :firmware_binaries: + :description: Firmware Binaries + :options: + - :subcollection + :verbs: *g + :klass: FirmwareBinary + :subcollection_actions: + :get: + - :name: read + :identifier: firmware :firmwares: :description: Firmwares :options: @@ -1244,6 +1254,7 @@ :get: - :name: read :identifier: firmware_show + :flavors: :description: Flavors :identifier: flavor @@ -1931,6 +1942,7 @@ :klass: PhysicalServer :subcollections: - :event_streams + - :firmware_binaries :collection_actions: :get: - :name: read @@ -2647,6 +2659,8 @@ :identifier: vm_retire - :klass: PhysicalServerProvisionRequest :identifier: physical_server_provision + - :klass: PhysicalServerFirmwareUpdateRequest + :identifier: firmware - :name: edit :identifier: miq_request_edit - :name: approve diff --git a/spec/requests/physical_servers_spec.rb b/spec/requests/physical_servers_spec.rb index 84e4fc7b49..e0e3f82344 100644 --- a/spec/requests/physical_servers_spec.rb +++ b/spec/requests/physical_servers_spec.rb @@ -622,5 +622,40 @@ end end end + + describe 'FirmwareBinaries subcollection' do + let(:physical_server) { FactoryBot.create(:physical_server, :with_asset_detail) } + let(:firmware_binary) { FactoryBot.create(:firmware_binary) } + let!(:firmware_target) do + FactoryBot.create( + :firmware_target, + :manufacturer => physical_server.asset_detail.manufacturer, + :model => physical_server.asset_detail.model, + :firmware_binaries => [firmware_binary] + ) + end + + describe 'GET /api/physical_servers/:id/firmware_binaries' do + let(:url) { api_physical_server_firmware_binaries_url(nil, physical_server) } + + it 'returns the firmware_binaries with an appropriate role' do + api_basic_authorize subcollection_action_identifier(:physical_servers, :firmware_binaries, :read, :get) + get(url) + expect_result_resources_to_include_hrefs( + 'resources', + [ + api_physical_server_firmware_binary_url(nil, physical_server, firmware_binary) + ] + ) + expect(response).to have_http_status(:ok) + end + + it 'does not return the event_streams without an appropriate role' do + api_basic_authorize + get(url) + expect(response).to have_http_status(:forbidden) + end + end + end end end