Skip to content

Commit

Permalink
Merge pull request #800 from yast/static-services-support
Browse files Browse the repository at this point in the history
Add support for on-demand only services
  • Loading branch information
imobachgs committed Aug 16, 2018
2 parents 093772c + 857116d commit 7a57294
Show file tree
Hide file tree
Showing 6 changed files with 55 additions and 8 deletions.
17 changes: 14 additions & 3 deletions library/systemd/src/lib/yast2/system_service.rb
Expand Up @@ -239,7 +239,8 @@ def currently_active?
def start_modes
@start_modes = [:on_boot, :manual, :on_demand] unless found?
return @start_modes if @start_modes
@start_modes = [:on_boot, :manual]
@start_modes = [:manual]
@start_modes << :on_boot unless service.static?
@start_modes << :on_demand if socket
@start_modes
end
Expand Down Expand Up @@ -433,9 +434,9 @@ def save_start_mode
when :on_boot
service.enable && (socket ? socket.disable : true)
when :on_demand
service.disable && (socket ? socket.enable : false)
disable_service && (socket ? socket.enable : false)
when :manual
service.disable && (socket ? socket.disable : true)
disable_service && (socket ? socket.disable : true)
end

register_error(:start_mode) unless result
Expand Down Expand Up @@ -594,5 +595,15 @@ def changed_value?(key)
def any_change?
CURRENT_VALUE_METHODS.keys.any? { |k| changed_value?(k) }
end

# Disable the service unless it is static
#
# @note It does not try to disable the service when it is an static one.
#
# @return [Boolean] false if the operation failed
def disable_service
return true if service.static?
service.disable
end
end
end
8 changes: 4 additions & 4 deletions library/systemd/src/lib/yast2/systemd_unit.rb
Expand Up @@ -254,10 +254,10 @@ def initialize(systemd_unit, property_text)

extract_properties
self[:active?] = ACTIVE_STATES.include?(active_state)
self[:running?] = sub_state == "running"
self[:loaded?] = load_state == "loaded"
self[:not_found?] = load_state == "not-found"
self[:static?] = load_state == "static"
self[:running?] = sub_state == "running"
self[:loaded?] = load_state == "loaded"
self[:not_found?] = load_state == "not-found"
self[:static?] = unit_file_state == "static"
self[:enabled?] = read_enabled_state
self[:supported?] = SUPPORTED_STATES.include?(unit_file_state)
self[:can_reload?] = can_reload == "yes"
Expand Down
1 change: 1 addition & 0 deletions library/systemd/test/systemd_unit_test.rb
Expand Up @@ -83,6 +83,7 @@ def trigger_reloading_properties(command)
expect(unit.properties[:loaded?]).not_to be_nil
expect(unit.properties[:supported?]).not_to be_nil
expect(unit.properties[:not_found?]).not_to be_nil
expect(unit.properties[:static?]).not_to be_nil
expect(unit.properties[:path]).not_to be_nil
expect(unit.properties[:error]).not_to be_nil
expect(unit.properties[:raw]).not_to be_nil
Expand Down
28 changes: 28 additions & 0 deletions library/systemd/test/yast2/system_service_test.rb
Expand Up @@ -32,12 +32,14 @@
enabled?: service_enabled,
active?: service_active,
not_found?: !service_found,
static?: service_static,
refresh!: true)
end

let(:service_enabled) { true }
let(:service_active) { true }
let(:service_found) { true }
let(:service_static) { false }

let(:service_socket) do
instance_double(Yast::SystemdSocketClass::Socket,
Expand Down Expand Up @@ -302,6 +304,14 @@
end
end

context "when the service is static" do
let(:service_static) { true }

it "returns :on_demand and :manual" do
expect(system_service.start_modes).to contain_exactly(:on_demand, :manual)
end
end

context "when the service is not found" do
let(:socket) { nil }
let(:service_found) { false }
Expand Down Expand Up @@ -619,6 +629,15 @@
expect(system_service.errors).to include(start_mode: :on_demand)
end
end

context "and the service is static" do
let(:service_static) { true }

it "does not try to disable the service" do
expect(service).to_not receive(:disable)
system_service.save
end
end
end

context "and the new start mode is :manual" do
Expand All @@ -645,6 +664,15 @@
system_service.save
end
end

context "and the service is static" do
let(:service_static) { true }

it "does not try to disable the service" do
expect(service).to_not receive(:disable)
system_service.save
end
end
end

context "and there is a problem when trying to set the new start mode" do
Expand Down
7 changes: 7 additions & 0 deletions package/yast2.changes
@@ -1,3 +1,10 @@
-------------------------------------------------------------------
Tue Aug 14 17:32:02 UTC 2018 - igonzalezsosa@suse.com

- Add support for systemd services that can only be started
on-demand (fate#319428 and bsc#1104568).
- 4.0.85

-------------------------------------------------------------------
Thu Aug 9 13:02:38 UTC 2018 - igonzalezsosa@suse.com

Expand Down
2 changes: 1 addition & 1 deletion package/yast2.spec
Expand Up @@ -17,7 +17,7 @@


Name: yast2
Version: 4.0.84
Version: 4.0.85
Release: 0
Summary: YaST2 - Main Package
License: GPL-2.0-only
Expand Down

0 comments on commit 7a57294

Please sign in to comment.