Skip to content

Commit

Permalink
Prevent deactivation of base product
Browse files Browse the repository at this point in the history
  • Loading branch information
Andrei Shaidurov committed Apr 19, 2017
1 parent d118d65 commit 72bf0f0
Show file tree
Hide file tree
Showing 6 changed files with 12 additions and 4 deletions.
3 changes: 3 additions & 0 deletions .rubocop.yml
@@ -1,3 +1,6 @@
ClassLength:
Max: 128

HashSyntax:
Enabled: false

Expand Down
5 changes: 4 additions & 1 deletion lib/suse/connect/cli.rb
Expand Up @@ -75,11 +75,14 @@ def execute! # rubocop:disable MethodLength, CyclomaticComplexity
# Zypper errors are in the range 1-7 and 100-105 (which connect will not cause)
log.fatal "Error: zypper returned (#{e.exitstatus}) with '#{e.output}'"
exit e.exitstatus
rescue SystemNotRegisteredError => e
rescue SystemNotRegisteredError
log.fatal 'Deregistration failed. Check if the system has been '\
'registered using the --status-text option or use the '\
'--regcode parameter to register it.'
exit 69
rescue BaseProductDeactivationError
log.fatal 'Can not deregister base product. Use SUSEConnect -d to deactivate the whole system.'
exit 70
end

private
Expand Down
1 change: 1 addition & 0 deletions lib/suse/connect/client.rb
Expand Up @@ -37,6 +37,7 @@ def register!
def deregister!
raise SystemNotRegisteredError unless registered?
if @config.product
raise BaseProductDeactivationError if @config.product == Zypper.base_product
service = deactivate_product @config.product
System.remove_service service
Zypper.remove_release_package @config.product.identifier
Expand Down
1 change: 1 addition & 0 deletions lib/suse/connect/errors.rb
Expand Up @@ -11,6 +11,7 @@ class SystemCallError < StandardError; end
class UnsupportedStatusFormat < StandardError; end
class NetworkError < StandardError; end
class SystemNotRegisteredError < StandardError; end
class BaseProductDeactivationError < StandardError; end

# Basic error for API interactions. Collects HTTP response (which includes
# status code and response body) for future showing to user via {Cli}
Expand Down
4 changes: 2 additions & 2 deletions lib/suse/connect/status.rb
Expand Up @@ -69,8 +69,8 @@ def extract_extensions(product)
activation_code: build_product_activation_code(extension),
name: extension.friendly_name,
free: extension.free,
installed: installed_products.any? {|p| p.to_params == extension.to_params },
activated: activated_products.any? {|p| p.to_params == extension.to_params },
installed: installed_products.any? {|p| p == extension },
activated: activated_products.any? {|p| p == extension },
extensions: extract_extensions(extension)
}
end if product.extensions
Expand Down
2 changes: 1 addition & 1 deletion lib/suse/connect/zypper.rb
Expand Up @@ -152,7 +152,7 @@ def install_release_package(identifier)
end

def remove_release_package(identifier)
call("--no-refresh --non-interactive remove --no-recommends -t product #{identifier}") if identifier
call("--no-refresh --non-interactive remove -t product #{identifier}") if identifier
end

# rubocop:disable AccessorMethodName
Expand Down

0 comments on commit 72bf0f0

Please sign in to comment.