Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add system token for PAYG systems #1206

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,53 @@
describe Api::Connect::V3::Subscriptions::SystemsController, type: :request do
describe '#announce_system' do
let(:instance_data) { '<instance_data/>' }
let(:params) do
{
hostname: 'test',
instance_data: instance_data,
hwinfo:
{
hostname: 'test',
cpus: '1',
sockets: '1',
hypervisor: 'Xen',
arch: 'x86_64',
uuid: 'ec235f7d-b435-e27d-86c6-c8fef3180a01',
cloud_provider: 'amazon'
}
}
end
let(:iid) do
{
accountId: '1234',
architecture: 'some-arch',
availabilityZone: 'some-zone',
billingProducts: [ 'billing-info' ],
devpayProductCodes: nil,
marketplaceProductCodes: nil,
imageId: 'ami-1234',
instanceId: 'i-1234',
instanceType: 'instance-type',
kernelId: nil,
pendingTime: 'yyyy-mm-ddThh:mm:ssZ',
privateIp: 'some-ip',
ramdiskId: nil,
region: 'some-region',
version: '2017-09-30'
}.to_json
end
let(:plugin_double) { instance_double('InstanceVerification::Providers::Example') }

context 'using RMT generated credentials' do
it 'saves instance data' do
post '/connect/subscriptions/systems', params: { hostname: 'test', instance_data: instance_data }
allow(InstanceVerification::Providers::Example).to receive(:new)
.with(nil, nil, nil, instance_data).and_return(plugin_double)
allow(plugin_double).to receive(:parse_instance_data).and_return(JSON.parse(iid))
post '/connect/subscriptions/systems', params: params
data = JSON.parse(response.body)
system = System.find_by(login: data['login'])
expect(system.instance_data).to eq(instance_data)
expect(system.system_token).to eq('i-1234')
end
end
end
Expand Down
9 changes: 7 additions & 2 deletions engines/scc_proxy/lib/scc_proxy/engine.rb
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ def get_instance_id(params)
nil,
nil,
params['instance_data']
)
)
instance_id_key = INSTANCE_ID_KEYS[params['hwinfo']['cloud_provider'].downcase.to_sym]
iid = verification_provider.parse_instance_data
iid[instance_id_key]
Expand Down Expand Up @@ -264,7 +264,12 @@ def announce_system
if has_no_regcode?(auth_header)
# no token sent to check with SCC
# standard announce case
@system = System.create!(hostname: params[:hostname], system_information: system_information, proxy_byos_mode: :payg)
@system = System.create!(
hostname: params[:hostname],
system_information: system_information,
proxy_byos_mode: :payg,
system_token: SccProxy.get_instance_id(request.request_parameters)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see that get_instance_id makes some assumptions that are specific to our implementation of the verification plugin and that are probably not documented. This goes hand in hand with #1207 and should first be discussed with PM as to what the behavior should be and then we should do the implementation based on business needs/agreements rather than more or less randomly implement changes where there is a good chance that we do not fully understand the implications.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

will convert both PRs into drafts until a decision has been made then

)
else
request.request_parameters['proxy_byos_mode'] = 'byos'
response = SccProxy.announce_system_scc(auth_header, request.request_parameters)
Expand Down