Skip to content

Commit

Permalink
Merge pull request #793 from yast/backport-from-master
Browse files Browse the repository at this point in the history
Backport from master
  • Loading branch information
imobachgs committed Aug 8, 2018
2 parents 3c8a84b + 8c16b39 commit 75b27db
Show file tree
Hide file tree
Showing 10 changed files with 121 additions and 62 deletions.
4 changes: 2 additions & 2 deletions doc/examples/ask_resize_windows_partition.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@
# Example when to use a headline:
#
# There is lengthy text that advanced users might have read several times
# before, so we give him a concise headline that identifies that dialog so he
# can keep on working without having to read everything again.
# before, so we give the users a concise headline that identifies that dialogue
# so they can keep on working without having to read everything again.
module Yast
class AskResizeWindowsPartitionClient < Client
def main
Expand Down
22 changes: 11 additions & 11 deletions doc/examples/popups2.rb
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ def main
"Really delete world?",
"You in your infinite wisdom have chosen to delete this only world of ours.\n" \
"This will mean the end to all of mankind and all life in the only known planet\n" \
"known to habitate intelligent or other life in the entire universe.\n" \
"known to be inhabited by intelligent or other life in the entire universe.\n" \
"\n" \
"Even though it is well known that mankind and human character are far from perfect,\n" \
"we urgently request you to reconsider that decision.\n" \
Expand All @@ -72,17 +72,17 @@ def main
"\n" \
"\n" \
"\n" \
"If make the wrong decision, creatures from outer space may decide\n" \
"If you make the wrong decision, creatures from outer space may choose\n" \
"\n" \
"to get rid of that planet of ours to make room for some interstellar\n" \
"to get rid of this planet of ours to make room for some interstellar\n" \
"\n" \
"hyper expressway.\n" \
"\n" \
"\n" \
"\n" \
"So: Do you fail to be aware to recognize the lack of not being able\n" \
"\n" \
"to face this kind of indecision may kill all of mankind?",
"So: Do you fail to recognize that your inability to confront\n" \
"\n" \
"this kind of indecision may destroy all of mankind?",
"&Everything you say",
"I'll &buy one of it",
:focus_no
Expand All @@ -94,17 +94,17 @@ def main
"\n" \
"\n" \
"\n" \
"If make the wrong decision, creatures from outer space may decide\n" \
"If you make the wrong decision, creatures from outer space may choose\n" \
"\n" \
"to get rid of that planet of ours to make room for some interstellar\n" \
"to get rid of this planet of ours to make room for some interstellar\n" \
"\n" \
"hyper expressway.\n" \
"\n" \
"\n" \
"\n" \
"So: Do you fail to be aware to recognize the lack of not being able\n" \
"\n" \
"to face this kind of indecision may kill all of mankind?",
"So: Do you fail to recognize that your inability to confront\n" \
"\n" \
"this kind of indecision may destroy all of mankind?",
"&Everything you say",
"I'll &buy one of it",
"But I don't have a &car",
Expand Down
26 changes: 13 additions & 13 deletions library/network/src/lib/network/susefirewall2.rb
Original file line number Diff line number Diff line change
Expand Up @@ -278,12 +278,12 @@ def ReportOnlyOnce(what_to_report)

# Function returns whether the feature 'any' network interface is supported in the
# firewall configuration. The string 'any' must be in the 'EXT' zone.
# Updated: Currently returns only 'true' as every unasigned interface is
# Updated: Currently returns only 'true' as every unassigned interface is
# automatically assigned to the EXT zone by SuSEfirewall2.
#
# @return [Boolean] is_supported whether the feature is supported or not
def IsAnyNetworkInterfaceSupported
# Currently unasigned interfaces belong to the EXT zone by dafault
# Currently unassigned interfaces belong to the EXT zone by dafault
true
end

Expand Down Expand Up @@ -360,7 +360,7 @@ def ReadSysconfigSuSEFirewall(variables)
nil
end

# Local function for reseting list of sysconfig variables in internal variables.
# Local function for resetting list of sysconfig variables in internal variables.
#
# @param [Array<String>] variables of sysconfig variables
def ResetSysconfigSuSEFirewall(variables)
Expand Down Expand Up @@ -492,7 +492,7 @@ def SetBroadcastConfiguration(zone, broadcast_configuration)
nil
end

# Local function return map of allowed ports (without aliases).
# Local function returns map of allowed ports (without aliases).
# If any list for zone is defined but empty, all allowed
# UDP ports for this zone also accept broadcast packets.
# This function returns only ports that are mentioned in configuration,
Expand Down Expand Up @@ -526,7 +526,7 @@ def GetBroadcastAllowedPorts
# BNC #694782: "yes" is automatically translated by SuSEfirewall2
elsif broadcast == "yes"
Ops.set(allowed_ports, zone, ["yes"])
# only listed ports allows broadcast
# only listed ports allow broadcast
else
Ops.set(allowed_ports, zone, Builtins.splitstring(broadcast, " "))
Ops.set(
Expand Down Expand Up @@ -1761,15 +1761,15 @@ def WriteConfiguration
true
end

# Helper function for the backward compatibility.
# Helper function for backward compatibility.
# See WriteConfiguration(). Remove from code ASAP.
#
# @return [Boolean] if succesful
def WriteOnly
WriteConfiguration()
end

# Function for writing and enabling configuration it is an union of
# Function for writing and enabling configuration, it is a union of
# WriteConfiguration() and ActivateConfiguration().
#
# @return [Boolean] if succesfull
Expand All @@ -1789,7 +1789,7 @@ def Write
# This powerful function returns list of services/ports which are
# not assigned to any fully-supported known-services.
# This function doesn't check for services defined by packages.
# They are listed by a different way.
# They are listed by a different method.
#
# @return [Array<String>] of additional (unassigned) services
#
Expand Down Expand Up @@ -1939,7 +1939,7 @@ def RemoveSpecialInterfaceFromZone(interface, zone)
nil
end

# Functions adds special string into defined zone.
# Function adds special string into defined zone.
#
# @param [String] interface
# @param [String] zone
Expand Down Expand Up @@ -1985,7 +1985,7 @@ def SetMasquerade(enable, _zone = nil)

Ops.set(@SETTINGS, "FW_MASQUERADE", enable ? "yes" : "no")

# routing is needed for masquerading, but we can't swithc it off when disabling masquerading
# routing is needed for masquerading, but we can't switch it off when disabling masquerading
Ops.set(@SETTINGS, "FW_ROUTE", "yes") if enable

nil
Expand Down Expand Up @@ -2223,7 +2223,7 @@ def SetLoggingSettings(rule, state)
nil
end

# Function returns yes/no - ingoring broadcast for zone
# Function returns yes/no - ignoring broadcast for zone
#
# @param [String] zone
# @return [String] "yes" or "no"
Expand All @@ -2240,7 +2240,7 @@ def GetIgnoreLoggingBroadcast(zone)
Ops.get_string(@SETTINGS, Ops.add("FW_IGNORE_FW_BROADCAST_", zone), "no")
end

# Function sets yes/no - ingoring broadcast for zone
# Function sets yes/no - ignoring broadcast for zone
#
# @param [String] zone
# @param [String] bcast ignore 'yes' or 'no'
Expand All @@ -2261,7 +2261,7 @@ def SetIgnoreLoggingBroadcast(zone, bcast)
nil
end

# Firewall Expert Rulezz
# Firewall Expert Rules

# Returns list of rules describing protocols and ports that are allowed
# to be accessed from listed hosts. All is returned as a single string.
Expand Down
14 changes: 13 additions & 1 deletion 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 Expand Up @@ -425,7 +437,7 @@ def save_start_mode
when :on_boot
service.enable && (socket ? socket.disable : true)
when :on_demand
service.disable && (socket ? socket.enable : true)
service.disable && (socket ? socket.enable : false)
when :manual
service.disable && (socket ? socket.disable : true)
end
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
18 changes: 6 additions & 12 deletions library/systemd/src/modules/systemd_service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -190,19 +190,13 @@ def restart

# Returns socket associated with service or nil if there is no such socket
#
# @return [Yast::SystemdSocketClass::Socket]
# @note The current implementation is too simplistic. At this point, checking the
# 'Triggers' property of each socket would be a better way. However, it won't work
# during installation as 'systemctl show' is not available.
#
# @return [Yast::SystemdSocketClass::Socket,nil]
def socket
return @socket if @socket

# not triggered
socket_name = properties.triggered_by
return unless socket_name

# this may be a space separated list
socket_name = socket_name[/\S+\.socket/]
return unless socket_name # triggered by non-socket

@socket = Yast::SystemdSocket.find(socket_name)
@socket ||= Yast::SystemdSocket.find(name)
end

# Determines whether the service has an associated socket
Expand Down
26 changes: 15 additions & 11 deletions library/systemd/test/systemd_service_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -179,20 +179,22 @@ module Yast

describe "#socket" do
subject(:service) { SystemdService.find(service_name) }
let(:service_name) { "sshd" }

before { stub_services(service: service_name) }
before do
allow(SystemdSocket).to receive(:find).with(service_name).and_return(socket)
end

context "when the service is triggered by a socket" do
let(:service_name) { "cups" }
context "when a socket named after the service exists" do
let(:socket) { instance_double(SystemdSocketClass::Socket) }

it "returns the socket" do
expect(service.socket).to be_a(Yast::SystemdSocketClass::Socket)
expect(service.socket.unit_name).to eq("iscsid")
expect(service.socket).to eq(socket)
end
end

context "when the service is not triggered by a socket" do
let(:service_name) { "sshd" }
context "when no socket named after the service exists" do
let(:socket) { nil }

it "returns nil" do
expect(service.socket).to be_nil
Expand All @@ -201,20 +203,22 @@ module Yast
end

describe "#socket?" do
subject(:service) { SystemdService.find(service_name) }
subject(:service) { SystemdService.find("sshd") }

before { stub_services(service: service_name) }
before do
allow(service).to receive(:socket).and_return(socket)
end

context "when there is an associated socket" do
let(:service_name) { "cups" }
let(:socket) { instance_double(SystemdSocketClass::Socket) }

it "returns true" do
expect(service.socket?).to eq(true)
end
end

context "when there is no associated socket" do
let(:service_name) { "sshd" }
let(:socket) { nil }

it "returns false" do
expect(service.socket?).to eq(false)
Expand Down
48 changes: 44 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 @@ -609,6 +620,17 @@

system_service.save
end

context "but there is not associated socket (possible during 1st stage)" do
before do
allow(system_service).to receive(:socket).and_return(nil)
end

it "registers an error" do
system_service.save
expect(system_service.errors).to include(start_mode: :on_demand)
end
end
end

context "and the new start mode is :manual" do
Expand Down Expand Up @@ -1093,4 +1115,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
Loading

0 comments on commit 75b27db

Please sign in to comment.