New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Move some systemd modules to real classes #758
Move some systemd modules to real classes #758
Conversation
@@ -0,0 +1,187 @@ | |||
require "yast2/systemd_unit" | |||
|
|||
module Yast |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess we should start to use Yast2
namespace for this class.
def initialize(service) | ||
@service = service | ||
end | ||
|
||
# Returns socket associated with service or nil if there is no such socket | ||
# | ||
# @return [Yast::SystemdSocketClass::Socket] | ||
# @return [Yast::Systemd::Socket] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yast2::Systemd::Socket
@@ -31,7 +31,7 @@ module Yast2 | |||
class SystemService | |||
extend Forwardable | |||
|
|||
# @return [Yast::SystemdService] | |||
# @return [Yast2::Systemd::Service] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not necessary Yast2 here because we are already under Yast2 namespace.
end | ||
end | ||
|
||
# @param service [Yast::SystemdServiceClass::Service] | ||
# @param service [Yast2::Systemd::Service] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not needed Yast2.
@@ -76,7 +76,7 @@ def socket | |||
socket_name = socket_name[/\S+\.socket/] | |||
return unless socket_name # triggered by non-socket | |||
|
|||
@socket = Yast::SystemdSocket.find(socket_name) | |||
@socket = Yast::Systemd::Socket.find(socket_name) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does it work? It should be @socket = Systemd::Socket.find(socket_name
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oops 💩! Good catch!
require "yast2/systemd_unit" | ||
|
||
module Yast2 | ||
module Systemd |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To be compliant with ruby standards, the name space hierarchy should match the directories structure, so this file should be placed in yast2/systemd/service.rb
. I would also create a new file yast2/systemd.rb
with a content as follows:
require "yast2/systemd/unit"
require "yast2/systemd/target"
require "yast2/systemd/service"
require "yast2/systemd/socket"
module Systemd; end
require "yast2/systemd_unit" | ||
|
||
module Yast2 | ||
module Systemd |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same comment as before, it should be placed at yast2/systemd/socket.rb
.
require "yast2/systemd_unit" | ||
|
||
module Yast2 | ||
module Systemd |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
And again the same, yast2/systemd/target.rb
@@ -2,309 +2,311 @@ | |||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
and here the last one. Please, move it to yast2/systemd/unit.rb
@@ -23,7 +22,7 @@ def stub_systemctl(unit) | |||
end | |||
|
|||
def stub_execute(success: true) | |||
allow(Yast::Systemctl).to receive(:execute).and_return( | |||
allow(Yast2::Systemctl).to receive(:execute).and_return( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Reading this I have the doubt if Systemctl
should also be under Systemd
namespace. @jreidinger @imobachgs ?
@@ -48,36 +46,36 @@ module Yast | |||
let(:apparmor_double) { double("Service", name: "apparmor") } | |||
let(:cups_double) { double("Service", name: "cups") } | |||
let(:systemctl_stdout) do | |||
File.read(File.join(__dir__, "data", "apparmor_and_cups_properties")) | |||
File.read(File.join(File.expand_path("..", __dir__), "data", "apparmor_and_cups_properties")) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For this I think it is better to define a data path in test_helper.rb
and then use it here.
In test_helper.rb
:
DATA_PATH = File.expand_path("../data", __FILE__)
In test:
File.read(File.join(DATA_PATH, "apparmor_and_cups_properties")
@@ -63,70 +61,70 @@ module Yast | |||
|
|||
describe ".get_default" do | |||
it "returns the unit object of the currently set default target" do | |||
allow(Systemctl).to receive(:execute).with("get-default").and_return( | |||
allow(Yast2::Systemctl).to receive(:execute).with("get-default").and_return( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
NP: not needed Yast2
expect(target.unit_name).to eq("graphical") | ||
end | ||
end | ||
|
||
describe ".set_default" do | ||
it "returns true if the default target has been has for the parameter successfully" do | ||
expect(Systemctl).to receive(:execute).with("set-default --force graphical.target") | ||
expect(Yast2::Systemctl).to receive(:execute).with("set-default --force graphical.target") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
NP: not needed Yast2
end | ||
end | ||
|
||
describe "#set_default" do | ||
it "it returns true if the target unit object has been set as default target" do | ||
expect(Systemctl).to receive(:execute).with("set-default --force graphical.target") | ||
expect(Yast2::Systemctl).to receive(:execute).with("set-default --force graphical.target") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
NP: not needed Yast2
expect(target.set_default).to eq(false) | ||
end | ||
|
||
context "when target properties cannot be found out (e.g. in chroot)" do | ||
it "it returns true if the target unit object has been set as default target" do | ||
expect(Systemctl).to receive(:execute).with("set-default --force multi-user-in-installation.target") | ||
expect(Yast2::Systemctl).to receive(:execute).with("set-default --force multi-user-in-installation.target") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
NP: not needed Yast2
- SystemService#active_state - SystemService#sub_state
* Relocate systemd classes to `lib/yast2/systemd/`, matching directories with with name space hierarchy * Fix wrong `Yast::` prefix * Remove not necessaries `Yast2::` prefixes * Improve data path in test
This PR is too outdated, so I am closing it in favor of a new one. See #799 |
Listed "class modules" below has been moved to their owns real classes