Skip to content

Commit

Permalink
Refresh zypper service when deactivating product on SMT
Browse files Browse the repository at this point in the history
  • Loading branch information
ikapelyukhin committed Oct 16, 2017
1 parent f2f679e commit f77e9a5
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 3 deletions.
12 changes: 11 additions & 1 deletion lib/suse/connect/client.rb
Expand Up @@ -39,7 +39,7 @@ def deregister!
if @config.product
raise BaseProductDeactivationError if @config.product == Zypper.base_product
service = deactivate_product @config.product
System.remove_service service
remove_or_refresh_service(service)
Zypper.remove_release_package @config.product.identifier
print_success_message @config.product, action: 'Deregistered'
else
Expand Down Expand Up @@ -178,6 +178,16 @@ def registered?
System.credentials?
end

# SMT provides one service for all products, removing it would remove all repositories.
# Refreshing the service instead to remove the repos of deregistered product.
def remove_or_refresh_service(service)
if service.name == 'SMT_DUMMY_NOREMOVE_SERVICE'
Zypper.refresh_all_services
else
System.remove_service service
end
end

def print_success_message(product, action: 'Registered')
log.info "#{action} #{product.identifier} #{product.version} #{product.arch}"
log.info "Rooted at: #{@config.filesystem_root}" if @config.filesystem_root
Expand Down
5 changes: 5 additions & 0 deletions lib/suse/connect/zypper.rb
Expand Up @@ -4,6 +4,7 @@
require 'suse/connect/rexml_refinement'
require 'suse/toolkit/system_calls'

# rubocop:disable Metrics/ModuleLength
module SUSE
module Connect

Expand Down Expand Up @@ -109,6 +110,10 @@ def refresh_service(service_name)
call("--non-interactive refs #{Shellwords.escape(service_name)}")
end

def refresh_all_services
call('--non-interactive refs')
end

# @param product identifier [String]
# Returns an array of hashes of all solvable products
def find_products(identifier)
Expand Down
5 changes: 5 additions & 0 deletions package_obs/SUSEConnect.changes
@@ -1,3 +1,8 @@
-------------------------------------------------------------------
Mon Oct 16 15:23:33 UTC 2017 - ikapelyukhin@suse.com

- Properly refresh zypper services when deactivating a product on SMT (bsc#1047153)

-------------------------------------------------------------------
Mon Jun 26 10:20:22 UTC 2017 - kpimenov@suse.com

Expand Down
15 changes: 13 additions & 2 deletions spec/connect/client_spec.rb
Expand Up @@ -456,13 +456,24 @@
stub_request(:delete, 'https://scc.suse.com/connect/systems/products').to_return(body: '{"product":{}}')
end

it 'removes service and release package' do
expect(client_instance).to receive :deactivate_product
it 'removes SCC service and release package' do
expect(client_instance).to receive(:deactivate_product) do
SUSE::Connect::Remote::Service.new({ 'name' => 'dummy', 'product' => {} })
end
expect(System).to receive :remove_service
expect(Zypper).to receive :remove_release_package
subject
end

it 'refreshes SMT service and removes release package' do
expect(client_instance).to receive(:deactivate_product) do
SUSE::Connect::Remote::Service.new({ 'name' => 'SMT_DUMMY_NOREMOVE_SERVICE', 'product' => {} })
end
expect(Zypper).to receive :refresh_all_services
expect(Zypper).to receive :remove_release_package
subject
end

it 'logs success' do
allow(System).to receive :remove_service
allow(Zypper).to receive :remove_release_package
Expand Down
7 changes: 7 additions & 0 deletions spec/connect/zypper_spec.rb
Expand Up @@ -194,6 +194,13 @@
end
end

describe '.refresh_all_services' do
it 'calls zypper with proper arguments' do
expect(Open3).to receive(:capture3).with(shared_env_hash, 'zypper --non-interactive refs').and_return(['', '', status])
subject.refresh_all_services
end
end

describe '.find_products' do
let(:zypper_sles_product_search) { File.read('spec/fixtures/zypper_sles_product_search.xml') }
let(:zypper_sles_product_search_not_found) { File.read('spec/fixtures/zypper_sles_product_search_not_found.xml') }
Expand Down

0 comments on commit f77e9a5

Please sign in to comment.