From c164decb8e7f99e4e0a7856a2c85fe7c48fe5b32 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Iv=C3=A1n=20L=C3=B3pez=20Gonz=C3=A1lez?= Date: Fri, 5 Jun 2020 15:35:29 +0100 Subject: [PATCH 1/3] Always try to stop and start the service --- .../systemd/src/lib/yast2/system_service.rb | 44 +++++++------------ 1 file changed, 16 insertions(+), 28 deletions(-) diff --git a/library/systemd/src/lib/yast2/system_service.rb b/library/systemd/src/lib/yast2/system_service.rb index b57d6748c..e1419e103 100644 --- a/library/systemd/src/lib/yast2/system_service.rb +++ b/library/systemd/src/lib/yast2/system_service.rb @@ -1,6 +1,4 @@ -# encoding: utf-8 - -# Copyright (c) [2018] SUSE LLC +# Copyright (c) [2018-2020] SUSE LLC # # All Rights Reserved. # @@ -181,7 +179,7 @@ def found? # # @return [String] all possible active_state values of systemd def state - return socket.active_state if socket_active? && !service.active? + return socket.active_state if socket? && socket.active? && !service.active? service.active_state end @@ -192,7 +190,7 @@ def state # # @return [String] all possible sub_state values of systemd def substate - return socket.sub_state if socket_active? && !service.active? + return socket.sub_state if socket? && socket.active? && !service.active? service.sub_state end @@ -220,7 +218,7 @@ def current_start_mode # # @return [Boolean] def currently_active? - service.active? || socket_active? + service.active? || (socket? && socket.active?) end # Returns the list of supported start modes for this service (if a socket @@ -476,15 +474,7 @@ def perform_action # # @return [Boolean] true if the service was correctly started def perform_start - result = true - - if socket && start_mode == :on_demand - result &&= socket.start unless socket_active? - else - result &&= service.start unless service.active? - end - - result + (socket? && start_mode == :on_demand) ? socket.start : service.start end # Stops the service in the underlying system @@ -495,8 +485,8 @@ def perform_start def perform_stop result = true - result &&= service.stop if service.active? - result &&= socket.stop if socket_active? + result &&= socket.stop if socket? + result &&= service.stop result end @@ -522,7 +512,7 @@ def perform_reload result = true - result &&= socket.stop if socket_active? && start_mode != :on_demand + result &&= socket.stop if socket? && start_mode != :on_demand result &&= service.active? ? service.reload : perform_start result @@ -542,20 +532,18 @@ def clear_errors @errors.clear end - # Returns the associated socket + # Whether there is a socket associated to the service # - # @return [Yast2::Systemd::Socket] - def socket - service && service.socket + # @return [Boolean] + def socket? + !socket.nil? end - # Whether the associated socket (if any) is actived + # Returns the associated socket # - # @return [Boolean] - def socket_active? - return false unless socket - - socket.active? + # @return [Yast2::Systemd::Socket, nil] + def socket + service.socket end # Registers change for a given key From 27ad3cfe189274594e8f448e76e25d8842892b35 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Iv=C3=A1n=20L=C3=B3pez=20Gonz=C3=A1lez?= Date: Fri, 5 Jun 2020 15:36:21 +0100 Subject: [PATCH 2/3] Adapt unit tests --- .../systemd/test/yast2/system_service_test.rb | 125 ++++++------------ 1 file changed, 42 insertions(+), 83 deletions(-) diff --git a/library/systemd/test/yast2/system_service_test.rb b/library/systemd/test/yast2/system_service_test.rb index c73655a5f..6d8ad8d10 100755 --- a/library/systemd/test/yast2/system_service_test.rb +++ b/library/systemd/test/yast2/system_service_test.rb @@ -1,7 +1,5 @@ #!/usr/bin/env rspec -# encoding: utf-8 - -# Copyright (c) [2018] SUSE LLC +# Copyright (c) [2018-2020] SUSE LLC # # All Rights Reserved. # @@ -744,64 +742,35 @@ context "and the action is start" do let(:action) { :start } - context "and neither the service nor the socket are active" do - let(:service_active) { false } - let(:socket_active) { false } - - context "and the start mode is set to :on_demand" do - let(:start_mode) { :on_demand } - - it "tries to start the socket" do - expect(socket).to receive(:start).and_return(true) - - system_service.save - end + context "and the start mode is set to :on_demand" do + let(:start_mode) { :on_demand } - it "does not try to start the service" do - allow(socket).to receive(:start).and_return(true) - expect(service).to_not receive(:start) + it "tries to start the socket" do + expect(socket).to receive(:start).and_return(true) - system_service.save - end + system_service.save end - context "and the start mode is set to :on_boot or :manual" do - let(:start_mode) { :manual } - - it "tries to start the service" do - expect(service).to receive(:start).and_return(true) - - system_service.save - end - - it "does not try to start the socket" do - allow(service).to receive(:start).and_return(true) - expect(socket).to_not receive(:start) + it "does not try to start the service" do + allow(socket).to receive(:start).and_return(true) + expect(service).to_not receive(:start) - system_service.save - end + system_service.save end end - context "and the service is active" do - let(:service_active) { true } - let(:socket_active) { false } + context "and the start mode is set to :on_boot or :manual" do + let(:start_mode) { :manual } - it "does not try to start neither the socket nor the service" do - expect(socket).to_not receive(:start) - expect(service).to_not receive(:start) + it "tries to start the service" do + expect(service).to receive(:start).and_return(true) system_service.save end - end - - context "and the socket is active" do - let(:socket_active) { true } - let(:service_active) { true } - it "does not try to start neither the socket nor the service" do + it "does not try to start the socket" do + allow(service).to receive(:start).and_return(true) expect(socket).to_not receive(:start) - expect(service).to_not receive(:start) system_service.save end @@ -816,61 +785,51 @@ allow(socket).to receive(:stop).and_return(true) end - context "and the service is active" do - let(:service_active) { true } - - it "tries to stop the service" do - expect(service).to receive(:stop).and_return(true) + it "tries to stop the service" do + expect(service).to receive(:stop).and_return(true) - system_service.save - end + system_service.save end - context "and the socket is active" do - let(:socket_active) { true } - - it "tries to stop the socket" do - expect(socket).to receive(:stop).and_return(true) + it "tries to stop the socket" do + expect(socket).to receive(:stop).and_return(true) - system_service.save - end + system_service.save end + end - context "and the service is not active" do - let(:service_active) { false } - - it "does not try to stop the service again" do - expect(service).to_not receive(:stop) - system_service.save - end - end + context "and the action is restart" do + let(:action) { :restart } - context "and the socket is not active" do - let(:socket_active) { false } + before do + allow(system_service).to receive(:perform_stop).and_return(stop_success) - it "does not try to stop the socket again" do - expect(socket).to_not receive(:stop) - system_service.save - end + allow(system_service).to receive(:perform_start).and_return(true) end - end - context "and the action is restart" do - let(:action) { :restart } + let(:stop_success) { true } it "performs the stop action (see above)" do - expect(system_service).to receive(:perform_stop).and_return(true) + expect(system_service).to receive(:perform_stop) system_service.save end context "and the system service is correctly stopped" do - before do - allow(system_service).to receive(:perform_stop).and_return(true) - end + let(:stop_success) { true } it "performs the start action (see above)" do - expect(system_service).to receive(:perform_start).and_return(true) + expect(system_service).to receive(:perform_start) + + system_service.save + end + end + + context "and the system service is not correctly stopped" do + let(:stop_success) { false } + + it "does not try to perform the start action" do + expect(system_service).to_not receive(:perform_start) system_service.save end From 1d538e29644a096edf14aa630de17015e05aa537 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Iv=C3=A1n=20L=C3=B3pez=20Gonz=C3=A1lez?= Date: Fri, 5 Jun 2020 16:15:16 +0100 Subject: [PATCH 3/3] Update version and changelog --- package/yast2.changes | 7 +++++++ package/yast2.spec | 2 +- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/package/yast2.changes b/package/yast2.changes index a59261c01..9a7bb0fbb 100644 --- a/package/yast2.changes +++ b/package/yast2.changes @@ -1,3 +1,10 @@ +------------------------------------------------------------------- +Fri Jun 5 15:13:42 UTC 2020 - José Iván López González + +- Improve actions to stop and start a system service. +- Related to bsc#1162514. +- 4.1.78 + ------------------------------------------------------------------- Mon Apr 13 12:36:58 UTC 2020 - Knut Anderssen diff --git a/package/yast2.spec b/package/yast2.spec index 98bc7e4f1..5cbfb115d 100644 --- a/package/yast2.spec +++ b/package/yast2.spec @@ -17,7 +17,7 @@ Name: yast2 -Version: 4.1.77 +Version: 4.1.78 Release: 0 Summary: YaST2 - Main Package