Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 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
11 changes: 11 additions & 0 deletions engines/instance_verification/lib/instance_verification/engine.rb
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,16 @@ def find_subscription(base_product, logger, request)
)
end

def add_extension_product_class(base_product, product)
# SLES identifier has 2 product classes 7261 and SLES-ARM64, for each arch
# using identifier to include both cases
payg_sles = @system.payg? && base_product.identifier.casecmp?('sles') && base_product.version.start_with?('15')
if payg_sles && product.product_class.casecmp?('sle-lp') && base_product.arch == product.arch && base_product.version == product.version
return [product.product_class]
end
[]
end

def verify_product_activation
product = find_product

Expand Down Expand Up @@ -249,6 +259,7 @@ def verify_payg_extension_activation!(product)

allowed_product_classes = subscription.product_classes.pluck(:product_class)

allowed_product_classes += add_extension_product_class(base_product, product)
unless allowed_product_classes.include?(product.product_class)
raise InstanceVerification::Exception.new(
'The product is not available for this instance'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -562,6 +562,63 @@
expect(response.body).to eq(serialized_service_json)
end
end

context 'when the extension is Live-Patching for SLES' do
let(:payload_no_token) do
{
identifier: product.identifier,
version: product.version,
arch: product.arch,
instance_data: 'dummy_instance_data',
proxy_byos_mode: system.proxy_byos_mode,
hwinfo:
{
hostname: 'test',
cpus: '1',
sockets: '1',
hypervisor: 'Xen',
arch: 'x86_64',
uuid: 'ec235f7d-b435-e27d-86c6-c8fef3180a01',
cloud_provider: 'amazon'
}
}
end

let(:base_product) { FactoryBot.create(:product, :product_sles, :with_mirrored_repositories) }
let(:product) do
FactoryBot.create(
:product, :product_live_patch, :with_mirrored_repositories, base_products: [base_product]
)
end
let(:product_classes) { [base_product.product_class] }
let(:fake_subscription) { instance_double(Subscription, id: 1, products: [base_product]) }
let(:fake_subscription_prod_class) { FactoryBot.create(:subscription_product_class) }

before do
allow(InstanceVerification::Providers::Example).to receive(:new).and_return(plugin_double)
allow(plugin_double).to receive(:instance_identifier).and_return('foo')
allow(plugin_double).to receive(:parse_instance_data).and_return({ InstanceId: 'foo' })
allow(plugin_double).to receive(:allowed_extension?).and_return(true)
allow(plugin_double).to receive(:add_on).and_return(nil)
allow_any_instance_of(described_class).to receive(:find_subscription).and_return(fake_subscription)
allow(fake_subscription).to receive(:product_classes).and_return([{ product_class: 'foo' }])
# stub the fake announcement call PAYG has to do to SCC
# to create the system before activate product (and skip validation)
stub_request(:post, 'https://scc.suse.com/connect/subscriptions/systems')
.to_return(status: 201, body: scc_response_body, headers: {})

headers['X-Instance-Data'] = Base64.strict_encode64(instance_data)
post url, params: payload_no_token, headers: headers
end

it 'allow the extension' do
expect(response.body).to eq(serialized_service_json)
data = JSON.parse(response.body)
expected_name = data['name'].include?('Live_Patch')
expect(expected_name).to be(true)
expect(data['product']['product_class']).to eq('SLE-LP')
end
end
end
end

Expand Down
17 changes: 17 additions & 0 deletions spec/factories/products.rb
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,23 @@
friendly_version { '15 SP6' }
end

trait :product_live_patch do
identifier { 'SLE-LP' }
name { 'SUSE Linux Enterprise Live Patching' }
description { 'Liva Patcha offers a comprehensive suite of products...' }
shortname { 'SLES-LP' }
former_identifier { 'SLE-LP' }
product_type { :extension }
product_class { 'SLE-LP' }
release_type { nil }
release_stage { 'released' }
version { '15.3' } # must match SLES product version
arch { 'x86_64' } # must match SLES product arch
free { false }
cpe { 'cpe:/o:suse:sle_live_paching:15:sp3' }
friendly_version { 'Live Patching' }
end

trait :extension do
product_type { 'extension' }
end
Expand Down