Skip to content

Commit d5bef81

Browse files
authored
Merge pull request #1379 from SUSE/allow-live-patching-sles15
Add Live-Patching extension access for SLES 15.X
2 parents 2e0e66b + 61fb499 commit d5bef81

3 files changed

Lines changed: 84 additions & 0 deletions

File tree

engines/instance_verification/lib/instance_verification/engine.rb

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -213,6 +213,16 @@ def find_subscription(base_product, logger, request)
213213
)
214214
end
215215

216+
def add_extension_product_class(base_product, product)
217+
# SLES identifier has 2 product classes 7261 and SLES-ARM64, for each arch
218+
# using identifier to include both cases
219+
payg_sles = @system.payg? && base_product.identifier.casecmp?('sles') && base_product.version.start_with?('15')
220+
if payg_sles && product.product_class.casecmp?('sle-lp') && base_product.arch == product.arch && base_product.version == product.version
221+
return [product.product_class]
222+
end
223+
[]
224+
end
225+
216226
def verify_product_activation
217227
product = find_product
218228

@@ -249,6 +259,7 @@ def verify_payg_extension_activation!(product)
249259

250260
allowed_product_classes = subscription.product_classes.pluck(:product_class)
251261

262+
allowed_product_classes += add_extension_product_class(base_product, product)
252263
unless allowed_product_classes.include?(product.product_class)
253264
raise InstanceVerification::Exception.new(
254265
'The product is not available for this instance'

engines/instance_verification/spec/requests/api/connect/v3/systems/products_controller_spec.rb

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -562,6 +562,62 @@
562562
expect(response.body).to eq(serialized_service_json)
563563
end
564564
end
565+
566+
context 'when the extension is Live-Patching for SLES' do
567+
let(:payload_no_token) do
568+
{
569+
identifier: product.identifier,
570+
version: product.version,
571+
arch: product.arch,
572+
instance_data: 'dummy_instance_data',
573+
proxy_byos_mode: system.proxy_byos_mode,
574+
hwinfo:
575+
{
576+
hostname: 'test',
577+
cpus: '1',
578+
sockets: '1',
579+
hypervisor: 'Xen',
580+
arch: 'x86_64',
581+
uuid: 'ec235f7d-b435-e27d-86c6-c8fef3180a01',
582+
cloud_provider: 'amazon'
583+
}
584+
}
585+
end
586+
587+
let(:base_product) { FactoryBot.create(:product, :product_sles, :with_mirrored_repositories) }
588+
let(:product) do
589+
FactoryBot.create(
590+
:product, :product_live_patch, :with_mirrored_repositories, base_products: [base_product]
591+
)
592+
end
593+
let(:product_classes) { [base_product.product_class] }
594+
let(:fake_subscription) { instance_double(Subscription, id: 1, products: [base_product]) }
595+
let(:fake_subscription_prod_class) { FactoryBot.create(:subscription_product_class) }
596+
597+
before do
598+
allow(InstanceVerification::Providers::Example).to receive(:new).and_return(plugin_double)
599+
allow(plugin_double).to receive(:instance_identifier).and_return('foo')
600+
allow(plugin_double).to receive(:parse_instance_data).and_return({ InstanceId: 'foo' })
601+
allow(plugin_double).to receive(:allowed_extension?).and_return(true)
602+
allow(plugin_double).to receive(:add_on).and_return(nil)
603+
allow_any_instance_of(described_class).to receive(:find_subscription).and_return(fake_subscription)
604+
allow(fake_subscription).to receive(:product_classes).and_return([{ product_class: 'foo' }])
605+
# stub the fake announcement call PAYG has to do to SCC
606+
# to create the system before activate product (and skip validation)
607+
stub_request(:post, 'https://scc.suse.com/connect/subscriptions/systems')
608+
.to_return(status: 201, body: scc_response_body, headers: {})
609+
610+
headers['X-Instance-Data'] = Base64.strict_encode64(instance_data)
611+
post url, params: payload_no_token, headers: headers
612+
end
613+
614+
it 'allow the extension' do
615+
expect(response.body).to eq(serialized_service_json)
616+
data = JSON.parse(response.body)
617+
expect(data['name']).to include('Live_Patch')
618+
expect(data['product']['product_class']).to eq('SLE-LP')
619+
end
620+
end
565621
end
566622
end
567623

spec/factories/products.rb

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,23 @@
106106
friendly_version { '15 SP6' }
107107
end
108108

109+
trait :product_live_patch do
110+
identifier { 'SLE-LP' }
111+
name { 'SUSE Linux Enterprise Live Patching' }
112+
description { 'Liva Patcha offers a comprehensive suite of products...' }
113+
shortname { 'SLES-LP' }
114+
former_identifier { 'SLE-LP' }
115+
product_type { :extension }
116+
product_class { 'SLE-LP' }
117+
release_type { nil }
118+
release_stage { 'released' }
119+
version { '15.3' } # must match SLES product version
120+
arch { 'x86_64' } # must match SLES product arch
121+
free { false }
122+
cpe { 'cpe:/o:suse:sle_live_paching:15:sp3' }
123+
friendly_version { 'Live Patching' }
124+
end
125+
109126
trait :extension do
110127
product_type { 'extension' }
111128
end

0 commit comments

Comments
 (0)