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

Simpleipv6 #64

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 24 additions & 1 deletion README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ accepts the following configuration parameters when it is initialized:
Argument Default Explanation
===================== ================= ========================================
``library`` Test library instance or module to host. Mandatory argument.
``host`` ``'127.0.0.1'`` Address to listen. Use ``'0.0.0.0'`` to listen to all available interfaces.
``host`` ``'127.0.0.1'`` Address to listen. Use ``'0.0.0.0'`` to listen to all available IPv4 addresses.
``port`` ``8270`` Port to listen. Use ``0`` to select a free port automatically. Can be given as an integer or as a string. The default port ``8270`` is `registered by IANA`__ for remote server usage.
``port_file`` ``None`` File to write the port that is used. ``None`` (default) means no such file is written.
``allow_stop`` ``'DEPRECATED'`` Deprecated since version 1.1. Use ``allow_remote_stop`` instead.
Expand Down Expand Up @@ -243,6 +243,29 @@ using ``stop`` argument on the command line or by using the
``stop_remote_server`` function programmatically. Testing and stopping should
work also with other Robot Framework remote server implementations.

Simple IPv6 Support
-------------------

RobotRemoteServer instances can bind to IPv6 addresses as well as IPv4 addresses;
both specific addresses and the 'any available address' equivalent to IPv4's
'0.0.0.0': '::'.

To use IPv6 addresses, it is necessary to set the class variable `TCPServer.address_family`
*before* the `import` of `RobotRemoteServer`, as shown in the example below.

.. sourcecode:: python

import socketserver
import socket

socketserver.TCPServer.address_family = socket.AF_INET6

from robotremoteserver import RobotRemoteServer
from mylibrary import MyLibrary

RobotRemoteServer (MyLibrary (), host = "::")


Listing keywords and viewing documentation
------------------------------------------

Expand Down
26 changes: 26 additions & 0 deletions example/exipv6.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#!/usr/bin/env python
# example of how to get RobotRemtoteServer working with IPv6: set up socketserver.TTCPServer.addresse_family
# class variable before importing RobotRemoteServer. Then use IPv6 notation, rather than IPv4

import sys

import socketserver
import socket

socketserver.TCPServer.address_family = socket.AF_INET6

from robotremoteserver import RobotRemoteServer

from examplelibrary import ExampleLibrary

if __name__ == '__main__':
# listen on any IPv6 address, including all IPv4 addresses on the host
#RobotRemoteServer(ExampleLibrary(), host="::", *sys.argv[1:])
# listen on local loopback interface
#RobotRemoteServer(ExampleLibrary(), host="::1", *sys.argv[1:])
# example encoding of IPv4 RFC1918 address as IPv6 address
#RobotRemoteServer(ExampleLibrary(), host="::ffff:192.168.194.81", *sys.argv[1:])
# IPv4 notation will fail
#RobotRemoteServer(ExampleLibrary(), host="192.168.194.81", *sys.argv[1:])
# listen on any IPv4 address
RobotRemoteServer(ExampleLibrary(), host="::ffff:0.0.0.0", *sys.argv[1:])
8 changes: 7 additions & 1 deletion example/tests.robot
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,13 @@
Library Remote http://${ADDRESS}:${PORT}

*** Variables ***
${ADDRESS} 127.0.0.1
# localhost may be a suitable alias for the local IP stack loopback address
${ADDRESS} localhost
# alternatively, use a protocol specific loopback address
# IPv6 loopback address
#${ADDRESS} ::1
# IPv4 loopback address
#${ADDRESS} 127.0.0.1
${PORT} 8270

*** Test Cases ***
Expand Down
13 changes: 10 additions & 3 deletions src/robotremoteserver.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,12 @@
import threading
import traceback

import socketserver
import socket

socketserver.TCPServer.address_family = socket.AF_INET6


if sys.version_info < (3,):
from SimpleXMLRPCServer import SimpleXMLRPCServer
from StringIO import StringIO
Expand All @@ -49,13 +55,14 @@

class RobotRemoteServer(object):

def __init__(self, library, host='127.0.0.1', port=8270, port_file=None,
def __init__(self, library, host='::1', port=8270, port_file=None,
allow_stop='DEPRECATED', serve=True, allow_remote_stop=True):
"""Configure and start-up remote server.

:param library: Test library instance or module to host.
:param host: Address to listen. Use ``'0.0.0.0'`` to listen
to all available interfaces.
to all available interfaces that have an IPv4
address.
:param port: Port to listen. Use ``0`` to select a free port
automatically. Can be given as an integer or as
a string.
Expand Down Expand Up @@ -149,7 +156,7 @@ def _announce_stop(self, log, port_file):

def _log(self, action, log=True, warn=False):
if log:
address = '%s:%s' % self.server_address
address = '%s:%s' % self.server_address [:2]
if warn:
print('*WARN*', end=' ')
print('Robot Framework remote server at %s %s.' % (address, action))
Expand Down