Skip to content

Commit

Permalink
Merge pull request #113 from r0h4n/master
Browse files Browse the repository at this point in the history
- Adds config, etcd_server etc for atoms
  • Loading branch information
r0h4n committed Jan 17, 2017
2 parents 73f19a6 + 4661917 commit 3f61eee
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 31 deletions.
9 changes: 7 additions & 2 deletions tendrl/commons/atoms/base_atom.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,22 @@ def __init__(
help,
inputs,
outputs,
uuid
uuid,
parameters
):
self.name = name
self.enabled = enabled
self.inputs = inputs
self.help = help
self.outputs = outputs
self.uuid = uuid
self.parameters = parameters
self.etcd_server = self.parameters['etcd_server']
self.config = self.parameters['config']
self.manager = self.parameters['manager']

@abc.abstractmethod
def run(self, parameters):
def run(self):
raise AtomNotImplementedError(
'define the function run to use this class'
)
5 changes: 3 additions & 2 deletions tendrl/commons/flows/base_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -223,8 +223,9 @@ def execute_atom(self, mod):
help,
inputs,
outputs,
uuid
).run(self.parameters)
uuid,
self.parameters
).run()
except AtomExecutionFailedError:
return False

Expand Down
26 changes: 11 additions & 15 deletions tendrl/commons/tests/test_command.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,8 @@

sys.modules['tendrl.commons.config'] = MagicMock()

from tendrl.commons.utils.ansible_module_runner \
import AnsibleExecutableGenerationFailed
from tendrl.commons.utils.ansible_module_runner \
import AnsibleRunner
from tendrl.commons.utils.command \
import Command
from tendrl.commons.utils.command \
import UnsupportedCommandException
from tendrl.commons.utils import ansible_module_runner
from tendrl.commons.utils import cmd_utils

del sys.modules['tendrl.commons.config']

Expand Down Expand Up @@ -42,9 +36,10 @@ def mock_runner_run(obj):
}
return result, ""

monkeypatch.setattr(AnsibleRunner, 'run', mock_runner_run)
monkeypatch.setattr(ansible_module_runner.AnsibleRunner, 'run',
mock_runner_run)

c = Command("cat /asdf.txt")
c = cmd_utils.Command("cat /asdf.txt")
stdout, stderr, rc = c.run('/tmp/')

assert stdout == "Hello world"
Expand All @@ -53,14 +48,15 @@ def mock_runner_run(obj):

def test_command_error(self, monkeypatch):
def mock_runner_run(obj):
raise AnsibleExecutableGenerationFailed(
raise ansible_module_runner.AnsibleExecutableGenerationFailed(
"module_path", "arg",
"err message"
)

monkeypatch.setattr(AnsibleRunner, 'run', mock_runner_run)
monkeypatch.setattr(ansible_module_runner.AnsibleRunner, 'run',
mock_runner_run)

c = Command("cat /asdf")
c = cmd_utils.Command("cat /asdf")
stdout, stderr, rc = c.run('/tmp/')

assert stdout == ""
Expand All @@ -71,7 +67,7 @@ def mock_runner_run(obj):

def test_command_unsafe_command(self, monkeypatch):
pytest.raises(
UnsupportedCommandException,
Command,
cmd_utils.UnsupportedCommandException,
cmd_utils.Command,
"rm -f /sadf"
)
19 changes: 9 additions & 10 deletions tendrl/commons/tests/test_service_status.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
from tendrl.commons.utils.command \
import Command
from tendrl.commons.utils import cmd_utils
from tendrl.commons.utils.service_status \
import ServiceStatus

Expand All @@ -15,7 +14,7 @@ def mock_command_constructor(obj, command):
" tendrl-node-agent.service"
return

monkeypatch.setattr(Command, '__init__',
monkeypatch.setattr(cmd_utils.Command, '__init__',
mock_command_constructor)

def mock_command_run(obj, exec_path):
Expand All @@ -24,7 +23,7 @@ def mock_command_run(obj, exec_path):
rc = 0
return stdout, stderr, rc

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

service = ServiceStatus("tendrl-node-agent", '/tmp/')
exists = service.exists()
Expand All @@ -36,7 +35,7 @@ def mock_command_constructor(obj, command):
"tendrl-node-agent.service"
return

monkeypatch.setattr(Command, '__init__',
monkeypatch.setattr(cmd_utils.Command, '__init__',
mock_command_constructor)

def mock_command_run(obj, exec_path):
Expand All @@ -45,7 +44,7 @@ def mock_command_run(obj, exec_path):
rc = 1
return stdout, stderr, rc

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

service = ServiceStatus("tendrl-node-agent", '/tmp/')
exists = service.exists()
Expand All @@ -57,7 +56,7 @@ def mock_command_constructor(obj, command):
"tendrl-node-agent.service"
return

monkeypatch.setattr(Command, '__init__',
monkeypatch.setattr(cmd_utils.Command, '__init__',
mock_command_constructor)

def mock_command_run(obj, exec_path):
Expand All @@ -72,7 +71,7 @@ def mock_command_run(obj, exec_path):
rc = 0
return stdout, stderr, rc

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

service = ServiceStatus("tendrl-node-agent", '/tmp/')
status = service.status()
Expand All @@ -84,7 +83,7 @@ def mock_command_constructor(obj, command):
"tendrl-node-agent.service"
return

monkeypatch.setattr(Command, '__init__',
monkeypatch.setattr(cmd_utils.Command, '__init__',
mock_command_constructor)

def mock_command_run(obj, exec_path):
Expand All @@ -93,7 +92,7 @@ def mock_command_run(obj, exec_path):
rc = 1
return stdout, stderr, rc

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

service = ServiceStatus("tendrl-node-agent", '/tmp/')
status = service.status()
Expand Down
File renamed without changes.
4 changes: 2 additions & 2 deletions tendrl/commons/utils/service_status.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from tendrl.commons.utils import command as cmd_util
from tendrl.commons.utils import cmd_utils


class ServiceStatus(object):
Expand All @@ -13,7 +13,7 @@ def _execute_service_command(self, argument):
service_cmd += " ".join(argument) if isinstance(
argument, tuple) else argument
service_cmd += " %s.service" % self.name
command = cmd_util.Command(service_cmd)
command = cmd_utils.Command(service_cmd)
return command.run(self.exec_path)

def exists(self):
Expand Down

0 comments on commit 3f61eee

Please sign in to comment.