Skip to content

Commit

Permalink
Export engine adjustments
Browse files Browse the repository at this point in the history
- Provide a description for use of the data export engine and how to use it
- Rename the update_info interface of the export engine to export_rmt_data
  • Loading branch information
rjschwei authored and jesusbv committed Jan 20, 2025
1 parent 71a3e86 commit c5076cb
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 17 deletions.
10 changes: 8 additions & 2 deletions engines/data_export/README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# DataExport
Short description and motivation.
The data export engine supports exporting of data from RMT whenever a
client visits the RMT server to received updates or an initial registration
is performed.

With this implementation the implementer can decide to forward all client
data or specific data to some external service for data analysis for example.

## Usage
How to use my plugin.
Place you implementation into /usr/share/rmt/engines/data_export/lib/data_export/handlers/ and implement the export_rmt_data function. The function takes no
arguments. Data to be exported is extracted from the RMT data base.
12 changes: 6 additions & 6 deletions engines/data_export/lib/data_export/engine.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ class Engine < ::Rails::Engine
config.after_initialize do
# replaces RMT registration for SCC registration
Api::Connect::V3::Subscriptions::SystemsController.class_eval do
after_action :update_info, only: %i[announce_system], if: -> { response.successful? }
after_action :export_rmt_data, only: %i[announce_system], if: -> { response.successful? }

def update_info
def export_rmt_data
# no need to check if system is nil
# as the response is successful
return if @system.byos?
Expand All @@ -17,7 +17,7 @@ def update_info
params,
logger
)
data_export_handler.update_info
data_export_handler.export_rmt_data
logger.info "System #{@system.login} info updated by data export handler after announcing the system"
rescue StandardError => e
logger.error('Unexpected data export error has occurred:')
Expand All @@ -29,16 +29,16 @@ def update_info
end

Api::Connect::V3::Systems::SystemsController.class_eval do
after_action :update_info, only: %i[update], if: -> { response.successful? }
after_action :export_rmt_data, only: %i[update], if: -> { response.successful? }

def update_info
def export_rmt_data
data_export_handler = DataExport.handler.new(
@system,
request,
params,
logger
)
data_export_handler.update_info
data_export_handler.export_rmt_data
logger.info "System #{@system.login} info updated by data export handler after updating the system"
rescue StandardError => e
logger.error('Unexpected data export error has occurred:')
Expand Down
2 changes: 1 addition & 1 deletion engines/data_export/lib/data_export/handlers/example.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
class DataExport::Handlers::Example < DataExport::HandlerBase
def update_info
def export_rmt_data
true
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@

before do
allow(DataExport::Handlers::Example).to receive(:new).and_return(plugin_double)
allow(plugin_double).to receive(:update_info)
allow(plugin_double).to receive(:export_rmt_data)
stub_request(:post, scc_register_system_url)
.to_return(
status: 201,
Expand All @@ -48,7 +48,7 @@
end

it 'saves the data' do
expect(plugin_double).to receive(:update_info)
expect(plugin_double).to receive(:export_rmt_data)
post '/connect/subscriptions/systems', params: params, headers: { HTTP_AUTHORIZATION: 'Token token=' }
end

Expand All @@ -57,7 +57,7 @@

before do
allow(DataExport::Handlers::Example).to receive(:new).and_return(plugin_double)
allow(plugin_double).to receive(:update_info).and_raise('foo')
allow(plugin_double).to receive(:export_rmt_data).and_raise('foo')
allow(Rails.logger).to receive(:error)
stub_request(:post, scc_register_system_url)
.to_return(
Expand All @@ -68,7 +68,7 @@
end

it 'does not save the data and log error' do
expect(plugin_double).to receive(:update_info)
expect(plugin_double).to receive(:export_rmt_data)
expect(Rails.logger).to receive(:error)
post '/connect/subscriptions/systems', params: params, headers: { HTTP_AUTHORIZATION: 'Token token=' }
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,22 +30,22 @@
before { allow(DataExport::Handlers::Example).to receive(:new).and_return(plugin_double) }

context 'when data export success' do
before { allow(plugin_double).to receive(:update_info) }
before { allow(plugin_double).to receive(:export_rmt_data) }

it do
expect(plugin_double).to receive(:update_info)
expect(plugin_double).to receive(:export_rmt_data)
expect { update_action }.to change { system.reload.hostname }.from('initial').to(payload[:hostname])
end
end

context 'when data export fails' do
before do
allow(plugin_double).to receive(:update_info).and_raise('foo')
allow(plugin_double).to receive(:export_rmt_data).and_raise('foo')
allow(Rails.logger).to receive(:error)
end

it do
expect(plugin_double).to receive(:update_info)
expect(plugin_double).to receive(:export_rmt_data)
expect(Rails.logger).to receive(:error)
update_action
end
Expand Down

0 comments on commit c5076cb

Please sign in to comment.