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

[WIP]Common: Added generic utils to common #79

Merged
merged 6 commits into from
Jan 5, 2017

Conversation

nnDarshan
Copy link
Contributor

This patch adds generic utils like command-executor,
package-installer, service-manager to common as utility.

Signed-off-by: nnDarshan darshan.n.2024@gmail.com

@coveralls
Copy link

Coverage Status

Coverage decreased (-8.4%) to 29.389% when pulling 250f00a on nnDarshan:AddGenericUtilities into d30c66f on Tendrl:master.

@nnDarshan
Copy link
Contributor Author

@r0h4n @nthomas-redhat @shtripat @brainfunked Its initial WIP patch for adding general utilities.

@shtripat Can you please help me by providing an issue for this, when you create one for the re factoring specification.

@coveralls
Copy link

Coverage Status

Coverage decreased (-9.4%) to 28.407% when pulling c86f74e on nnDarshan:AddGenericUtilities into d30c66f on Tendrl:master.

@nnDarshan
Copy link
Contributor Author

@r0h4n @nthomas-redhat @shtripat Please review.

@coveralls
Copy link

Coverage Status

Coverage increased (+14.006%) to 51.823% when pulling d4909a7 on nnDarshan:AddGenericUtilities into d30c66f on Tendrl:master.

@nnDarshan
Copy link
Contributor Author

@shtripat If you find it easy to use these utils as part of your re-factoring, please go ahead. If you find it would make your re-factoring patch huge , I will send a separate PR afterwards to do that. In any case, please provide your thoughts

@shtripat
Copy link
Member

shtripat commented Dec 13, 2016

@nnDarshan I feel doing this as part of different PR is good as refactoring PR is already huge and I am targetting more of cleanup, movement to common module and proper class hierarchies etc as part of my PR.

@r0h4n @brainfunked @nthomas-redhat thoughts??

@nnDarshan also add spec and issues link in commit message

@nnDarshan
Copy link
Contributor Author

tendrl-spec: Tendrl/specifications#31
tendrl-bug-id: #80

def restart(self):
attr = self.attributes
attr.update({"state": "restarted"})
return self.__run_module(attr)
Copy link
Member

Choose a reason for hiding this comment

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

Is it possible to add a status() function as well. Few modules need that I feel.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The ansible module which we are using to manage the service has only 4 types of operations namely start, stop, restart and reload(http://docs.ansible.com/ansible/service_module.html refer state under options). So its not possible with this approach.
I feel when we monitor systemd dbus signals we will be able to obtain the service states

Copy link
Member

Choose a reason for hiding this comment

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

ok

Copy link
Contributor

Choose a reason for hiding this comment

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

start and stop are idempotent actions that will not run commands unless necessary, so you can rely on these itself and you get the status in return. Can we take that approach?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

But using this approach we can't just read the status without changing it right ? If we already know that we want the state to be either started or stopped we can directly use the start/stopped method. I am not getting the advantage of using a status that way. Could you please elaborate ?

@@ -7,13 +7,15 @@ Source0: %{name}-%{version}.tar.gz
License: LGPLv2+
URL: https://github.com/Tendrl/common

BuildRequires: ansible
Copy link
Member

Choose a reason for hiding this comment

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

I remember on rhel by default ansible 2.2 was not getting downloaded. We should explicitly mention > 2.2 here if you use any ansible 2.2 specific feature.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

import AnsibleRunner


class Test_ansible_runner_constructor(object):
Copy link
Member

Choose a reason for hiding this comment

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

Better use CamelCase for all the class names

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

@@ -0,0 +1,38 @@
from ansible_module_runner import AnsibleExecutableGenerationFailed
Copy link
Member

Choose a reason for hiding this comment

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

I feel source could be named as package_installer.py

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

def restart(self):
attr = self.attributes
attr.update({"state": "restarted"})
return self.__run_module(attr)
Copy link
Member

Choose a reason for hiding this comment

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

ok

Copy link
Member

@shtripat shtripat left a comment

Choose a reason for hiding this comment

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

LGTM


class Command(object):
def __init__(self, command):
self.attributes = {"_raw_params": command}
Copy link
Contributor

Choose a reason for hiding this comment

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

This needs a whitelist of good commands we use or some sorta security check

This patch adds generic utils like command-executor,
package-installer, service-manager to common as utility.

tendrl-spec: Tendrl/specifications#31
tendrl-bug-id: Tendrl#80

Signed-off-by: nnDarshan <darshan.n.2024@gmail.com>
This commit adds the unit tests for the general purpose
utils namely installer, command executor and service
manager.

tendrl-spec: Tendrl/specifications#31
tendrl-bug-id: Tendrl#80

Signed-off-by: nnDarshan <darshan.n.2024@gmail.com>
Addressed some review comments

tendrl-spec:refactor_common_code_and_move
tendrl-bug-id: Tendrl#80

Signed-off-by: nnDarshan <darshan.n.2024@gmail.com>
Added a list of safe commands, only these safe
commands can be executed by the util.

tendrl-spec:add_utils_to_common
tendrl-bug-id: Tendrl#80

Signed-off-by: nnDarshan <darshan.n.2024@gmail.com>
@coveralls
Copy link

Coverage Status

Coverage increased (+15.9%) to 53.48% when pulling 01c156f on nnDarshan:AddGenericUtilities into e1aa599 on Tendrl:master.

@nnDarshan
Copy link
Contributor Author

@r0h4n @nthomas-redhat @brainfunked Please Review. Have addressed the commets

@@ -5,9 +5,25 @@
ANSIBLE_MODULE_PATH = "core/commands/command.py"
LOG = logging.getLogger(__name__)

SAFE_COMMAND_LIST = [
Copy link
Member

Choose a reason for hiding this comment

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

Should we externalize these command in tendrl owned yaml file? Just a thought, but if we are very strict on list of commands supported, then it ok to keep inside code. My only point is just for a new command we would need a code change later.

Comment??

Copy link
Contributor Author

Choose a reason for hiding this comment

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

My opinion is having it in code is better, keeping the security in mind.
@nthomas-redhat @r0h4n @brainfunked Please provide your thoughts

Copy link
Member

Choose a reason for hiding this comment

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

ok

Copy link
Member

@shtripat shtripat left a comment

Choose a reason for hiding this comment

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

Looks good to me

from ansible_module_runner import AnsibleRunner
import logging

ANSIBLE_MODULE_PATH = "core/system/systemd.py"
Copy link
Contributor

Choose a reason for hiding this comment

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

This supports only systemd services only right?
If we want to support old versions of LINUX where systemd is not available(ex;RHEL6), this would not be enough. I think the service module(https://github.com/ansible/ansible-modules-core/blob/devel/system/service.py) has support for different init modules including systemd and BSD init. Have considered that?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

def restart(self):
attr = self.attributes
attr.update({"state": "restarted"})
return self.__run_module(attr)
Copy link
Contributor

Choose a reason for hiding this comment

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

start and stop are idempotent actions that will not run commands unless necessary, so you can rely on these itself and you get the status in return. Can we take that approach?

Using service module for service management as it is
more generic. Also provided configurable util execution
path.

tendrl-spec:add_utils_to_common
tendrl-bug-id: Tendrl#80

Signed-off-by: nnDarshan <darshan.n.2024@gmail.com>
@coveralls
Copy link

Coverage Status

Coverage increased (+15.8%) to 53.333% when pulling 7a4de9d on nnDarshan:AddGenericUtilities into e1aa599 on Tendrl:master.

@coveralls
Copy link

Coverage Status

Coverage increased (+8.4%) to 56.48% when pulling 0fa1912 on nnDarshan:AddGenericUtilities into 3b96011 on Tendrl:master.

@r0h4n r0h4n merged commit 01fe6c6 into Tendrl:master Jan 5, 2017
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