Skip to content
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

Closed
wants to merge 48 commits into from
Closed

Move some systemd modules to real classes #758

wants to merge 48 commits into from

Conversation

dgdavid
Copy link
Member

@dgdavid dgdavid commented Jul 4, 2018

Listed "class modules" below has been moved to their owns real classes

  • SystemdServiceClass -> SystemdService
  • SystemdSocketClass -> SystemdSocket
  • SystemdTargetClass -> SystemdTarget

@@ -0,0 +1,187 @@
require "yast2/systemd_unit"

module Yast
Copy link
Contributor

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]
Copy link
Contributor

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]
Copy link
Contributor

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]
Copy link
Contributor

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)
Copy link
Contributor

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

Copy link
Member Author

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
Copy link
Contributor

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
Copy link
Contributor

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
Copy link
Contributor

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 @@

Copy link
Contributor

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(
Copy link
Contributor

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"))
Copy link
Contributor

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(
Copy link
Contributor

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")
Copy link
Contributor

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")
Copy link
Contributor

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")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

NP: not needed Yast2

@coveralls
Copy link

Coverage Status

Coverage decreased (-0.01%) to 29.268% when pulling 5aa2e71 on dgdavid:feature/move-module-to-real-classes into 6be7ec7 on yast:socket_feature_branch.

@dgdavid dgdavid changed the base branch from socket_feature_branch to master August 14, 2018 08:53
@dgdavid dgdavid changed the base branch from master to SLE-15-GA August 14, 2018 09:37
@dgdavid
Copy link
Member Author

dgdavid commented Aug 14, 2018

This PR is too outdated, so I am closing it in favor of a new one.

See #799

@dgdavid dgdavid closed this Aug 14, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants