Skip to content

Commit

Permalink
Merge pull request #112 from r0h4n/master
Browse files Browse the repository at this point in the history
tendrl-bug-id: #110
  • Loading branch information
r0h4n committed Jan 16, 2017
2 parents 805e11a + 0de9a4f commit 73f19a6
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 11 deletions.
18 changes: 9 additions & 9 deletions tendrl/commons/tests/test_service_status.py
Expand Up @@ -6,7 +6,7 @@

class TestServiceStatus(object):
def test_service_status_constructor(self, monkeypatch):
service = ServiceStatus("tendrl-node-agent")
service = ServiceStatus("tendrl-node-agent", '/tmp/')
assert service.name == "tendrl-node-agent"

def test_service_exists_true(self, monkeypatch):
Expand All @@ -18,15 +18,15 @@ def mock_command_constructor(obj, command):
monkeypatch.setattr(Command, '__init__',
mock_command_constructor)

def mock_command_run(obj):
def mock_command_run(obj, exec_path):
stdout = "LoadState=loaded"
stderr = ""
rc = 0
return stdout, stderr, rc

monkeypatch.setattr(Command, 'run', mock_command_run)

service = ServiceStatus("tendrl-node-agent")
service = ServiceStatus("tendrl-node-agent", '/tmp/')
exists = service.exists()
assert exists

Expand All @@ -39,15 +39,15 @@ def mock_command_constructor(obj, command):
monkeypatch.setattr(Command, '__init__',
mock_command_constructor)

def mock_command_run(obj):
def mock_command_run(obj, exec_path):
stdout = ""
stderr = ""
rc = 1
return stdout, stderr, rc

monkeypatch.setattr(Command, 'run', mock_command_run)

service = ServiceStatus("tendrl-node-agent")
service = ServiceStatus("tendrl-node-agent", '/tmp/')
exists = service.exists()
assert not exists

Expand All @@ -60,7 +60,7 @@ def mock_command_constructor(obj, command):
monkeypatch.setattr(Command, '__init__',
mock_command_constructor)

def mock_command_run(obj):
def mock_command_run(obj, exec_path):
stdout = "tendrl-node-agent.service - A python agent local to" + \
" every managed storage node in the sds cluster " + \
" Loaded: loaded (/usr/lib/systemd/system/tendrl" + \
Expand All @@ -74,7 +74,7 @@ def mock_command_run(obj):

monkeypatch.setattr(Command, 'run', mock_command_run)

service = ServiceStatus("tendrl-node-agent")
service = ServiceStatus("tendrl-node-agent", '/tmp/')
status = service.status()
assert status

Expand All @@ -87,14 +87,14 @@ def mock_command_constructor(obj, command):
monkeypatch.setattr(Command, '__init__',
mock_command_constructor)

def mock_command_run(obj):
def mock_command_run(obj, exec_path):
stdout = ""
stderr = ""
rc = 1
return stdout, stderr, rc

monkeypatch.setattr(Command, 'run', mock_command_run)

service = ServiceStatus("tendrl-node-agent")
service = ServiceStatus("tendrl-node-agent", '/tmp/')
status = service.status()
assert not status
5 changes: 3 additions & 2 deletions tendrl/commons/utils/service_status.py
Expand Up @@ -4,16 +4,17 @@
class ServiceStatus(object):
"""systemd services provider."""

def __init__(self, name):
def __init__(self, name, exec_path):
self.name = name
self.exec_path = exec_path

def _execute_service_command(self, argument):
service_cmd = "systemctl "
service_cmd += " ".join(argument) if isinstance(
argument, tuple) else argument
service_cmd += " %s.service" % self.name
command = cmd_util.Command(service_cmd)
return command.run()
return command.run(self.exec_path)

def exists(self):
stdout, stderr, rc = self._execute_service_command(
Expand Down

0 comments on commit 73f19a6

Please sign in to comment.