Skip to content

Conversation

pmarkee
Copy link
Contributor

@pmarkee pmarkee commented Aug 29, 2018

JSRemoteTest-DCO-1.0-Signed-off-by: Peter Marki marpeter@inf.u-szeged.hu

@pmarkee
Copy link
Contributor Author

pmarkee commented Aug 29, 2018

This patch has the same purpose as #185 , but for ssh devices (currently rpi2 and artik530) instead of serial devices.

@pmarkee pmarkee changed the title [WIP] Create an ssh server using MockSSH to emulate ssh connection Create an ssh server using MockSSH to emulate ssh connection Sep 20, 2018
@@ -14,7 +14,7 @@

from jstest.builder.builder import Builder
from jstest.common import console, paths, symbol_resolver, utils
from jstest.emulate import pseudo_terminal
from jstest.emulate import pseudo_terminal, mockssh_server
Copy link
Contributor

Choose a reason for hiding this comment

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

Please fix the order of the modules.

@@ -193,12 +203,15 @@ def main():
testresult.append(env.options.id, env.paths.builddir)
# Upload all the results to the Firebase database.
testresult.upload()
exitcode = 0
Copy link
Contributor

Choose a reason for hiding this comment

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

Does the exitcode variable really needed? If the Python script ends normally, the return value is 0. If error happens, it's enough to use the sys.exit(1) to stop the program.


except (Exception, KeyboardInterrupt) as e:
jstest.resources.patch_modules(env, revert=True)
jstest.console.error('[%s] %s' % (type(e).__name__, str(e)))

sys.exit(1)
exitcode = 1
Copy link
Contributor

Choose a reason for hiding this comment

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

Ditto.


class ThreadPrinter(object):
'''
#Class to redirect stdout from non-main threads into /dev/null.
Copy link
Contributor

Choose a reason for hiding this comment

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

This is a multi-line comment, no need # character.

#Class to redirect stdout from non-main threads into /dev/null.
'''
def __init__(self):
pass
Copy link
Contributor

Choose a reason for hiding this comment

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

Unnecessary constructor definition.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Pylint was giving a warning when the constructor was missing. Should I disable that warning in pylintrc or should we keep this constructor?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Nevermind, I just tried it, it's no longer giving a warning. I will delete the constructor.

.gitignore Outdated
@@ -5,3 +5,6 @@
build/*
deps/*
results/*

# Skip ssh key files.
*.key
Copy link
Contributor

Choose a reason for hiding this comment

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

Is there any .key file in the projects?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, the mockssh server needs them, so they shouldn't even be in .gitignore, I just realized it.

@@ -82,12 +82,19 @@ def parse_options():
action='store_true', default=False,
help='display less verbose output')

parser.add_argument('--emulate',
default=False, action='store_true',
help='Emulate the connection.')
Copy link
Contributor

Choose a reason for hiding this comment

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

Emulate the connection. -> emulate the connection

group = parser.add_argument_group("Secure Shell communication")

group.add_argument('--username',
metavar='USER',
help='specify the username to login to the device.')

group.add_argument('--password',
help='specify the password to login to the device.')
Copy link
Contributor

Choose a reason for hiding this comment

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

There is no need a dot at the end of the text. Could you please modify the help of the --username option as well?

break

self.writeln(ret)
self.exit()
Copy link
Contributor

@rtakacs rtakacs Sep 20, 2018

Choose a reason for hiding this comment

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

Just a shorter solution:

import re

iotjs_build_info = re.compile('.*iotjs_build_info.js')

if filter(iotjs_build_info.match, self.args):
    self.writeln('{ "builtins": {}, "features": {}, "stability": "stable" }')

self.exit()

@pmarkee pmarkee changed the title Create an ssh server using MockSSH to emulate ssh connection Create an ssh server to emulate ssh connection Sep 24, 2018
self.ssh.connect(hostname=self.ip, port=self.port, username=self.username,
password=self.password, look_for_keys=False)
else:
self.ssh.connect(hostname=self.ip, port=self.port, username=self.username)
Copy link
Contributor

Choose a reason for hiding this comment

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

Just a shorter solution:

look_for_keys=True

if self.password:
    look_for_keys=False

self.ssh.connect(hostname=self.ip, port=self.port, username=self.username, password=self.password, look_for_keys=look_for_keys)

Copy link
Contributor

Choose a reason for hiding this comment

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

Or more simply:

self.ssh.connect(hostname=self.ip, port=self.port, username=self.username, password=self.password, look_for_keys=bool(self.password))

self.ip = device_info['ip']
self.port = device_info['port']
self.timeout = device_info['timeout']
self._no_exec_command = device_info['_no_exec_command']
Copy link
Contributor

Choose a reason for hiding this comment

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

It would be nice if this variable could have a comment about its purpose. For example: FIXME: the exec_command of Paramico SSH library can't be used with the emulated SSH server. (or something else).

self.ip = device_info['ip']
self.port = device_info['port']
self.timeout = device_info['timeout']
# FIXME the exec_command method of paramiko.client.SSHClient cannot be used with the
Copy link
Contributor

Choose a reason for hiding this comment

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

FIXME -> FIXME:

exitcode = 1 if 'run_fail' in cmd else 0
self.write('{"output": "",'
' "memstat": {"heap-system": "n/a", "heap-jerry": "n/a", "stack": "n/a"},'
' "exitcode": %d}\r\n' % exitcode)
Copy link
Contributor

Choose a reason for hiding this comment

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

exitcode can be replaced with int('fail' in cmd). Please note that JerryScript uses fail folder name for the expected failure tests.

Copy link
Contributor

Choose a reason for hiding this comment

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

A better solution to format JSON string is to create an object and use json.dumps:

if 'iotjs_build_info' in cmd:
    result = {
        'builtins': {},
        'features': {}
        'stability': 'stable'
    }

else:
    result = {
        'output': 'Hello from emulated device.',
        'memstat': {
            'heap-system': 'n/a',
            'heap-jerry': 'n/a',
            'stack': 'n/a'
        },
        'exitcode': int('fail' in cmd)
    }

self.write(json.dumps(result) + '\r\n')

options.password = 'jerry'
options.ip = '127.0.0.1'
options.port = 2022
options.remote_workdir = 'emulated_workdir'
Copy link
Contributor

Choose a reason for hiding this comment

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

Unnecessary overwrite.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

If we don't overwrite remote_workdir, we will get an error message:
[SystemError] Please use --remote-workdir for the device.
This error message comes from the SSHDevice class, which should not distinguish if we are using an emulated device or a real device, so overwriting remote_workdir is necessary.

JSRemoteTest-DCO-1.0-Signed-off-by: Peter Marki marpeter@inf.u-szeged.hu
Copy link
Contributor

@rtakacs rtakacs left a comment

Choose a reason for hiding this comment

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

LGTM

Copy link
Contributor

@robertsipka robertsipka left a comment

Choose a reason for hiding this comment

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

LGTM

@robertsipka robertsipka merged commit 2ffd5ba into jerryscript-project:master Sep 25, 2018
@pmarkee pmarkee deleted the mockssh_server branch February 1, 2019 07:41
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.

3 participants