Skip to content

tftp: add external_ip setting #1678

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

Open
wants to merge 1 commit 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
4 changes: 4 additions & 0 deletions doc/configuration.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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`_
Expand Down Expand Up @@ -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`_
Expand Down
1 change: 1 addition & 0 deletions labgrid/driver/provider.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions labgrid/remote/exporter.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}


Expand Down
1 change: 1 addition & 0 deletions labgrid/resource/provider.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
1 change: 1 addition & 0 deletions labgrid/resource/remote.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
28 changes: 28 additions & 0 deletions tests/test_export.py
Original file line number Diff line number Diff line change
Expand Up @@ -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': '',
}


Expand All @@ -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',
}