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

remote/client: support token with template RemotePlace #1208

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
5 changes: 4 additions & 1 deletion labgrid/remote/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -1342,13 +1342,16 @@ def make(*args, **kwargs):
return session[0]

def find_role_by_place(config, place):
token_role = None
for role, role_config in config.items():
resources, _ = target_factory.normalize_config(role_config)
remote_places = resources.get('RemotePlace', {})
remote_place = remote_places.get(place)
if remote_place:
return role
return None
if any(remote_place.startswith('+') for remote_place in remote_places.keys()):
token_role = role
return token_role

def find_any_role_with_place(config):
for role, role_config in config.items():
Expand Down
46 changes: 46 additions & 0 deletions tests/test_crossbar.py
Original file line number Diff line number Diff line change
Expand Up @@ -465,6 +465,52 @@ def test_reservation_custom_config(place, exporter, tmpdir):
spawn.close()
assert spawn.exitstatus == 0, spawn.before.strip()

def test_reservation_custom_config_template(place, exporter, tmpdir):
p = tmpdir.join("config.yaml")
p.write(
"""
targets:
test1:
role: foo
resources:
RemotePlace:
name: !template $LG_PLACE
drivers:
- ManualPowerDriver: {}
"""
)
env = os.environ.copy()
env['LG_PLACE'] = '+'
with pexpect.spawn(f'python -m labgrid.remote.client -c {p} reserve --wait --shell board=bar name=test', env=env) as spawn:
spawn.expect(pexpect.EOF)
spawn.close()
assert spawn.exitstatus == 0, spawn.before.strip()
m = re.search(rb"^export LG_TOKEN=(\S+)$", spawn.before.replace(b'\r\n', b'\n'), re.MULTILINE)
s = re.search(rb"^Selected role$", spawn.before.replace(b'\r\n', b'\n'), re.MULTILINE)
assert m is not None, spawn.before.strip()
assert s is None, spawn.before.strip()
token = m.group(1)

env['LG_TOKEN'] = token.decode('ASCII')

with pexpect.spawn(f'python -m labgrid.remote.client -c {p} lock', env=env) as spawn:
spawn.expect("acquired place test")
spawn.expect(pexpect.EOF)
spawn.close()
assert spawn.exitstatus == 0, spawn.before.strip()

with pexpect.spawn(f'python -m labgrid.remote.client -c {p} power get', env=env) as spawn:
spawn.expect("Selected role test1 from configuration file")
spawn.expect(pexpect.EOF)
spawn.close()
assert spawn.exitstatus == 2, spawn.before.strip()

with pexpect.spawn(f'python -m labgrid.remote.client -c {p} release', env=env) as spawn:
spawn.expect("released place test")
spawn.expect(pexpect.EOF)
spawn.close()
assert spawn.exitstatus == 0, spawn.before.strip()

def test_same_name_resources(place, exporter, tmpdir):
with pexpect.spawn('python -m labgrid.remote.client -p test add-named-match "testhost/Many/NetworkService" "samename"') as spawn:
spawn.expect(pexpect.EOF)
Expand Down