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

[RFR] Added ssh credentials handling #30

Merged
merged 4 commits into from
Jul 22, 2018
Merged

[RFR] Added ssh credentials handling #30

merged 4 commits into from
Jul 22, 2018

Conversation

grafuls
Copy link
Owner

@grafuls grafuls commented Jun 29, 2018

No description provided.

@grafuls grafuls added the enhancement New feature or request label Jun 29, 2018
@grafuls grafuls added this to the POC milestone Jun 29, 2018
@grafuls grafuls self-assigned this Jun 29, 2018
@grafuls
Copy link
Owner Author

grafuls commented Jun 29, 2018

#20

@click.version_option(version=__version__)
def main(experiments_path):
def main(experiments_path, ssh_host_key):
Copy link
Collaborator

Choose a reason for hiding this comment

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

Maybe I am missing something there. But main here is defined with two args that have no default value. However, in the end of the program it is called with no args provided.

Copy link
Owner Author

Choose a reason for hiding this comment

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

These values are being taken from the click decorator which does state the default values for those.

except (OSError, asyncssh.Error) as exc:
sys.exit("SSH connection failed: " + str(exc))


async def execute(experiments_path):
async def execute(experiments_path, ssh_host_key):
ssh_host_key = [ssh_host_key] if ssh_host_key else ssh_host_key
Copy link
Collaborator

Choose a reason for hiding this comment

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

I cannot wrap my head around this construction. ssh_host_key has no default value, there you cannot really call execute without specifying it. I suppose you could specify False as ssh_host_key value but that's probably not how it's supposed to work. Given that, it seems that else clause should never happen.

Copy link
Collaborator

Choose a reason for hiding this comment

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

ssh_host_key = ssh_host_key or [ssh_host_key]

_files = []
for (dirpath, dirnames, filenames) in walk(experiments_path):
for _file in filenames:
_files.append(path.join(dirpath, _file))
_files = [
Copy link
Collaborator

Choose a reason for hiding this comment

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

Here we could maybe log files that are excluded (do not end with .yml/.yaml) as warning.

Copy link
Owner Author

Choose a reason for hiding this comment

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

+1

@@ -60,11 +78,14 @@ def main(experiments_path):

if result:
click.echo("Triggering: %s" % action.name)
trigger = Trigger(action)
_username = action.username if action.username else "root"
Copy link
Collaborator

Choose a reason for hiding this comment

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

This behavior (using root if no username is specifie) should be exposed at some higher level.

logger.debug("Connected to %s", self.hostname)
stdin, stdout, stderr = await conn.open_session("tail -F %s" % filepath)
stdin, stdout, stderr = await conn.open_session(
"tail -F %s" % filepath
Copy link
Collaborator

Choose a reason for hiding this comment

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

Let's please stick with new-style string formatting: "tail -F {}".format(filepath).

return _listener
except KeyError as ex:
raise ParserException(
"Missing %s definition from listener section", ex
Copy link
Collaborator

Choose a reason for hiding this comment

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

Pls new-style string formatting.

wait = trigger[key][config.WAIT_KEY]
timeout = trigger[key][config.TIMEOUT_KEY]

trigger = Action(
Copy link
Collaborator

Choose a reason for hiding this comment

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

Why not call it action? This naming seems kind of confusing since trigger (at least according to example.yaml) is higher-category term than action.

@@ -89,15 +115,23 @@ def _init_actions(element_trigger):

_scenarios = []
for disrupt_action in doc:
name = disrupt_action[config.DISRUPT_ACTION_STR][0][config.NAME_STR]
name = disrupt_action[config.DISRUPT_ACTION_KEY][0][
Copy link
Collaborator

Choose a reason for hiding this comment

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

Why is there [0] index? In example.yaml, name key is directly under disrupt_action.

Copy link
Owner Author

Choose a reason for hiding this comment

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

Cause it bring a 1 element list

ALL_ACTIONS
attr_err_msg = (
"Unexpected disruptive action other than %s"
% ", ".join(ALL_ACTIONS)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Please use new-style string formatting.

except (OSError, asyncssh.Error) as exc:
sys.exit("SSH connection failed: " + str(exc))


async def execute(experiments_path):
async def execute(experiments_path, ssh_host_key):
ssh_host_key = [ssh_host_key] if ssh_host_key else ssh_host_key
Copy link
Collaborator

Choose a reason for hiding this comment

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

ssh_host_key = ssh_host_key or [ssh_host_key]

try:
disruption = getattr(trigger, action.name)
except AssertionError as err:
logger.info(err)
logger.error(err)
return 1
Copy link
Collaborator

Choose a reason for hiding this comment

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

would be nice to have return values documented somewhere in config file

NAME_STR = "name"
LISTENER_STR = "listener"
TRIGGER_STR = "trigger"
ACTION_KEY = "action"
Copy link
Collaborator

Choose a reason for hiding this comment

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

I dont get the _KEY

Copy link
Collaborator

Choose a reason for hiding this comment

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

This is what parses should be looking for in experiment definition file, e.g. this one: https://github.com/grafuls/disruption_generator/blob/master/disruption_generator/experiments/example.yaml

Copy link
Owner Author

Choose a reason for hiding this comment

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

_KEY as in dictionary for key, value.

host = element_listener[config.HOST_KEY]
username = element_listener[config.USERNAME_KEY]
password = element_listener[config.PASSWORD_KEY]
_listener = Listener(
Copy link
Collaborator

Choose a reason for hiding this comment

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

shouldnt this be after except branch? dont think you are testing for KeyError there

@grafuls grafuls changed the title Added ssh credentials handling [RFR] Added ssh credentials handling Jul 13, 2018
@grafuls
Copy link
Owner Author

grafuls commented Jul 17, 2018

@jan-zmeskal @StLuke Please review additional changes based on your comments.

@grafuls grafuls merged commit 66a67c0 into master Jul 22, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants