diff --git a/doc/configuration.rst b/doc/configuration.rst index a956386fd..93e55ab43 100644 --- a/doc/configuration.rst +++ b/doc/configuration.rst @@ -1289,10 +1289,12 @@ A :any:`TFTPProvider` resource describes a TFTP server. TFTPProvider: internal: '/srv/tftp/board-23/' external: 'board-23/' + external_ip: '192.168.1.100' # optional Arguments: - internal (str): path prefix to the local directory accessible by the target - external (str): corresponding path prefix for use by the target + - external_ip (str, optional): IP address that the target should use to access the TFTP server. If not specified, defaults to empty string. Used by: - `TFTPProviderDriver`_ @@ -1339,11 +1341,13 @@ a remote computer. host: 'tftphost' internal: '/srv/tftp/board-23/' external: 'board-23/' + external_ip: '10.0.0.50' # optional Arguments: - host (str): hostname of the remote host - internal (str): path prefix to the TFTP root directory on ``host`` - external (str): corresponding path prefix for use by the target + - external_ip (str, optional): IP address that the target should use to access the TFTP server. If not specified, defaults to empty string. Used by: - `TFTPProviderDriver`_ diff --git a/labgrid/driver/provider.py b/labgrid/driver/provider.py index 9c8fda70f..c7dbf652c 100644 --- a/labgrid/driver/provider.py +++ b/labgrid/driver/provider.py @@ -16,6 +16,7 @@ def get_export_vars(self): "host": self.provider.host, "internal": self.provider.internal, "external": self.provider.external, + "external_ip": self.provider.external_ip, } @Driver.check_active diff --git a/labgrid/remote/exporter.py b/labgrid/remote/exporter.py index d3b406503..28bec93ea 100755 --- a/labgrid/remote/exporter.py +++ b/labgrid/remote/exporter.py @@ -590,6 +590,7 @@ def _get_params(self): "host": self.host, "internal": self.local.internal, "external": self.local.external, + "external_ip": self.local.external_ip, } diff --git a/labgrid/resource/provider.py b/labgrid/resource/provider.py index 3b8f723ab..030c8dd37 100644 --- a/labgrid/resource/provider.py +++ b/labgrid/resource/provider.py @@ -8,6 +8,7 @@ class BaseProvider(Resource): internal = attr.ib(validator=attr.validators.instance_of(str)) external = attr.ib(validator=attr.validators.instance_of(str)) + external_ip = attr.ib(default="", validator=attr.validators.instance_of(str)) def __attrs_post_init__(self): self.host = "localhost" diff --git a/labgrid/resource/remote.py b/labgrid/resource/remote.py index a29e58ee8..2daa75a89 100644 --- a/labgrid/resource/remote.py +++ b/labgrid/resource/remote.py @@ -396,6 +396,7 @@ class RemoteNetworkInterface(NetworkResource, ManagedResource): class RemoteBaseProvider(NetworkResource): internal = attr.ib(validator=attr.validators.instance_of(str)) external = attr.ib(validator=attr.validators.instance_of(str)) + external_ip = attr.ib(default="", validator=attr.validators.instance_of(str)) @target_factory.reg_resource diff --git a/tests/test_export.py b/tests/test_export.py index f977322a8..5ea368328 100644 --- a/tests/test_export.py +++ b/tests/test_export.py @@ -97,6 +97,7 @@ def test_export_tftp_provider(target): 'LG__TFTP_HOST': 'localhost', 'LG__TFTP_INTERNAL': '/srv/tftp/testboard/', 'LG__TFTP_EXTERNAL': 'testboard/', + 'LG__TFTP_EXTERNAL_IP': '', } @@ -109,4 +110,31 @@ def test_export_remote_tftp_provider(target): 'LG__TFTP_HOST': 'testhost', 'LG__TFTP_INTERNAL': '/srv/tftp/testboard/', 'LG__TFTP_EXTERNAL': 'testboard/', + 'LG__TFTP_EXTERNAL_IP': '', + } + + +def test_export_tftp_provider_with_external_ip(target): + TFTPProvider(target, None, internal='/srv/tftp/testboard/', external='testboard/', external_ip='192.168.1.100') + TFTPProviderDriver(target, "tftp") + + exported = target.export() + assert exported == { + 'LG__TFTP_HOST': 'localhost', + 'LG__TFTP_INTERNAL': '/srv/tftp/testboard/', + 'LG__TFTP_EXTERNAL': 'testboard/', + 'LG__TFTP_EXTERNAL_IP': '192.168.1.100', + } + + +def test_export_remote_tftp_provider_with_external_ip(target): + RemoteTFTPProvider(target, None, host='testhost', internal='/srv/tftp/testboard/', external='testboard/', external_ip='10.0.0.50') + TFTPProviderDriver(target, "tftp") + + exported = target.export() + assert exported == { + 'LG__TFTP_HOST': 'testhost', + 'LG__TFTP_INTERNAL': '/srv/tftp/testboard/', + 'LG__TFTP_EXTERNAL': 'testboard/', + 'LG__TFTP_EXTERNAL_IP': '10.0.0.50', }