-
Notifications
You must be signed in to change notification settings - Fork 4
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
Conversation
@click.version_option(version=__version__) | ||
def main(experiments_path): | ||
def main(experiments_path, ssh_host_key): |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
disruption_generator/cli.py
Outdated
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 |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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 = [ |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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" |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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( |
There was a problem hiding this comment.
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][ |
There was a problem hiding this comment.
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
.
There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
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.
disruption_generator/cli.py
Outdated
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 |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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" |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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( |
There was a problem hiding this comment.
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
@jan-zmeskal @StLuke Please review additional changes based on your comments. |
No description provided.