Skip to content

Commit

Permalink
SystemService#start_modes returns known modes when service is not found
Browse files Browse the repository at this point in the history
* It does not have enough information to infer which are the supported
  modes.
* This feature is used during first stage.
  • Loading branch information
imobachgs committed Aug 7, 2018
1 parent 3fc8121 commit 6ae6341
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 5 deletions.
12 changes: 12 additions & 0 deletions library/systemd/src/lib/yast2/system_service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,13 @@ def initialize(service)
@errors = {}
end

# Determines whether the service exists in the underlying system
#
# @return [Boolean] true if it exists; false otherwise.
def found?
!service.not_found?
end

# State of the service
#
# In case the service is not active but socket is, the socket state is considered
Expand Down Expand Up @@ -228,8 +235,13 @@ def currently_active?
# * :on_demand: The service will be started on demand.
# * :manual: The service is disabled and it will be started manually.
#
# @note When the service does not exist in the underlying system (for instance,
# during 1st stage) all possible start modes are returned, as there is no way
# to find out which of them are supported.
#
# @return [Array<Symbol>] List of supported modes.
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 << :on_demand if socket
Expand Down
3 changes: 2 additions & 1 deletion library/systemd/src/lib/yast2/systemd_unit.rb
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,8 @@ class PropMap < Hash
:loaded?,
:active_state,
:sub_state,
:can_reload?
:can_reload?,
:not_found?
].freeze

private_constant :FORWARDED_METHODS
Expand Down
37 changes: 33 additions & 4 deletions library/systemd/test/yast2/system_service_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,16 @@

let(:service) do
instance_double(Yast::SystemdServiceClass::Service,
name: "cups",
enabled?: service_enabled,
active?: service_active,
refresh!: true)
name: "cups",
enabled?: service_enabled,
active?: service_active,
not_found?: !service_found,
refresh!: true)
end

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

let(:service_socket) do
instance_double(Yast::SystemdSocketClass::Socket,
Expand Down Expand Up @@ -311,6 +313,15 @@
expect(system_service.start_modes).to contain_exactly(:on_boot, :manual)
end
end

context "when the service is not found" do
let(:socket) { nil }
let(:service_found) { false }

it "returns all available start modes" do
expect(system_service.start_modes).to contain_exactly(:on_boot, :manual, :on_demand)
end
end
end

describe "#start_mode" do
Expand Down Expand Up @@ -1093,4 +1104,22 @@
end
end
end

describe "#found" do
context "when the service is found" do
let(:service_found) { true }

it "returns true" do
expect(system_service.found?).to eq(true)
end
end

context "when the service is not found" do
let(:service_found) { false }

it "returns false" do
expect(system_service.found?).to eq(false)
end
end
end
end

0 comments on commit 6ae6341

Please sign in to comment.