Skip to content

Commit eefca07

Browse files
committed
Add support for testing/stopping servers from cli.
Includes documentation in README. Implements #15.
1 parent 1a16381 commit eefca07

File tree

2 files changed

+65
-3
lines changed

2 files changed

+65
-3
lines changed

README.rst

Lines changed: 32 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -87,14 +87,43 @@ Example:
8787
RobotRemoteServer(MyLibrary(), host='10.0.0.42', port=0,
8888
port_file='/tmp/remote-port.txt', allow_stop=False)
8989

90+
Testing is server running
91+
-------------------------
92+
93+
Starting from version 1.0.1 , ``robotremoteserver`` module supports testing is
94+
a remote server running. This can be accomplished by running the module as
95+
a script with ``test`` argument and an optional URI:
96+
97+
.. sourcecode:: bash
98+
99+
$ python -m robotremoteserver test
100+
Remote server running at http://127.0.0.1:8270.
101+
$ python -m robotremoteserver test http://10.0.0.42:57347
102+
No remote server running at http://10.0.0.42:57347.
103+
104+
.. tip:: As discussed below, using ``stop`` instead of ``test`` allows stopping
105+
the server. Both testing and stopping works also against other Robot
106+
Framework remote server implementations.
107+
90108
Stopping
91109
--------
92110

93111
The remote server can be gracefully stopped using three different methods:
94112

95-
- Hitting ``Ctrl-C`` on the console where the server is running.
96-
- Sending the process ``SIGINT``, ``SIGTERM``, or ``SIGHUP`` signal.
97-
- Using ``Stop Remote Server`` keyword (unless explicitly disabled).
113+
- Hitting ``Ctrl-C`` on the console where the server is running. Starting from
114+
version 1.0.1 this ought to work regardless the operating system and Python
115+
interpreter.
116+
117+
- Sending the process ``SIGINT``, ``SIGTERM``, or ``SIGHUP`` signal. Does not
118+
work on Windows. Notice that with Jython you need to send the signal to the
119+
started Java process, not to the shell typically started by ``jython`` command.
120+
121+
- Using ``Stop Remote Server`` keyword. This can be disabled by using
122+
``allow_stop=False`` when starting the server.
123+
124+
- Running ``python -m robotremoteserver stop [uri]`` similarly as when testing
125+
is the server running. Also this can be disabled using ``allow_stop=False``.
126+
New in version 1.0.1.
98127

99128
Example
100129
-------

src/robotremoteserver.py

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -289,3 +289,36 @@ def _log(self, msg, level=None):
289289
def _write_to_stream(self, msg, stream):
290290
stream.write(msg + '\n')
291291
stream.flush()
292+
293+
294+
if __name__ == '__main__':
295+
import xmlrpclib
296+
297+
def stop(uri):
298+
server = test(uri, log_success=False)
299+
if server is not None:
300+
print 'Stopping remote server at %s.' % uri
301+
server.stop_remote_server()
302+
303+
def test(uri, log_success=True):
304+
server = xmlrpclib.ServerProxy(uri)
305+
try:
306+
server.get_keyword_names()
307+
except:
308+
print 'No remote server running at %s.' % uri
309+
return None
310+
if log_success:
311+
print 'Remote server running at %s.' % uri
312+
return server
313+
314+
def parse_args(args):
315+
actions = {'stop': stop, 'test': test}
316+
if not args or len(args) > 2 or args[0] not in actions:
317+
sys.exit('Usage: python -m robotremoteserver test|stop [uri]')
318+
uri = args[1] if len(args) == 2 else 'http://127.0.0.1:8270'
319+
if '://' not in uri:
320+
uri = 'http://' + uri
321+
return actions[args[0]], uri
322+
323+
action, uri = parse_args(sys.argv[1:])
324+
action(uri)

0 commit comments

Comments
 (0)