| 1 |
import os |
| 2 |
import re |
| 3 |
import time |
| 4 |
|
| 5 |
import pytest |
| 6 |
import pexpect |
| 7 |
|
| 8 |
def test_startup(coordinator): |
| 9 |
pass |
| 10 |
|
| 11 |
@pytest.fixture(scope='function') |
| 12 |
def place(create_place): |
| 13 |
create_place('test') |
| 14 |
|
| 15 |
@pytest.fixture(scope='function') |
| 16 |
def create_place(coordinator): |
| 17 |
place_names = [] |
| 18 |
|
| 19 |
def _create_place(place_name): |
| 20 |
with pexpect.spawn(f'python -m labgrid.remote.client -p {place_name} create') as spawn: |
| 21 |
spawn.expect(pexpect.EOF) |
| 22 |
assert spawn.exitstatus == 0, spawn.before.strip() |
| 23 |
|
| 24 |
place_names.append(place_name) |
| 25 |
|
| 26 |
with pexpect.spawn(f'python -m labgrid.remote.client -p {place_name} set-tags board=123board') as spawn: |
| 27 |
spawn.expect(pexpect.EOF) |
| 28 |
assert spawn.exitstatus == 0, spawn.before.strip() |
| 29 |
|
| 30 |
yield _create_place |
| 31 |
|
| 32 |
for place_name in place_names: |
| 33 |
|
| 34 |
with pexpect.spawn(f'python -m labgrid.remote.client -p {place_name} release') as spawn: |
| 35 |
spawn.expect(pexpect.EOF) |
| 36 |
|
| 37 |
with pexpect.spawn(f'python -m labgrid.remote.client -p {place_name} delete') as spawn: |
| 38 |
spawn.expect(pexpect.EOF) |
| 39 |
assert spawn.exitstatus == 0, spawn.before.strip() |
| 40 |
|
| 41 |
@pytest.fixture(scope='function') |
| 42 |
def place_acquire(place, exporter): |
| 43 |
with pexpect.spawn('python -m labgrid.remote.client -p test add-match "*/Testport/*"') as spawn: |
| 44 |
spawn.expect(pexpect.EOF) |
| 45 |
spawn.close() |
| 46 |
assert spawn.exitstatus == 0, spawn.before.strip() |
| 47 |
|
| 48 |
with pexpect.spawn('python -m labgrid.remote.client -p test acquire') as spawn: |
| 49 |
spawn.expect(pexpect.EOF) |
| 50 |
spawn.close() |
| 51 |
assert spawn.exitstatus == 0, spawn.before.strip() |
| 52 |
|
| 53 |
yield |
| 54 |
|
| 55 |
with pexpect.spawn('python -m labgrid.remote.client -p test release') as spawn: |
| 56 |
spawn.expect(pexpect.EOF) |
| 57 |
spawn.close() |
| 58 |
assert spawn.exitstatus == 0, spawn.before.strip() |
| 59 |
|
| 60 |
def test_connect_error(): |
| 61 |
with pexpect.spawn('python -m labgrid.remote.client -x 127.0.0.1:20409 places') as spawn: |
| 62 |
spawn.expect("Could not connect to coordinator") |
| 63 |
spawn.expect(pexpect.EOF) |
| 64 |
spawn.close() |
| 65 |
assert spawn.exitstatus == 1, spawn.before.strip() |
| 66 |
|
| 67 |
def test_connect_timeout(coordinator): |
| 68 |
coordinator.suspend_tree() |
| 69 |
try: |
| 70 |
with pexpect.spawn('python -m labgrid.remote.client places') as spawn: |
| 71 |
spawn.expect("connection attempt timed out before receiving SETTINGS frame") |
| 72 |
spawn.expect(pexpect.EOF) |
| 73 |
spawn.close() |
| 74 |
assert spawn.exitstatus == 1, spawn.before.strip() |
| 75 |
finally: |
| 76 |
coordinator.resume_tree() |
| 77 |
pass |
| 78 |
|
| 79 |
def test_place_show(place): |
| 80 |
with pexpect.spawn('python -m labgrid.remote.client -p test show') as spawn: |
| 81 |
spawn.expect("Place 'test':") |
| 82 |
spawn.expect(pexpect.EOF) |
| 83 |
spawn.close() |
| 84 |
assert spawn.exitstatus == 0, spawn.before.strip() |
| 85 |
|
| 86 |
def test_place_alias(place): |
| 87 |
with pexpect.spawn('python -m labgrid.remote.client -p test add-alias foo') as spawn: |
| 88 |
spawn.expect(pexpect.EOF) |
| 89 |
spawn.close() |
| 90 |
assert spawn.exitstatus == 0, spawn.before.strip() |
| 91 |
|
| 92 |
with pexpect.spawn('python -m labgrid.remote.client -p foo del-alias foo') as spawn: |
| 93 |
spawn.expect(pexpect.EOF) |
| 94 |
spawn.close() |
| 95 |
assert spawn.exitstatus == 0, spawn.before.strip() |
| 96 |
|
| 97 |
def test_place_comment(place): |
| 98 |
with pexpect.spawn('python -m labgrid.remote.client -p test set-comment my comment') as spawn: |
| 99 |
spawn.expect(pexpect.EOF) |
| 100 |
spawn.close() |
| 101 |
assert spawn.exitstatus == 0, spawn.before.strip() |
| 102 |
|
| 103 |
with pexpect.spawn('python -m labgrid.remote.client -p test show') as spawn: |
| 104 |
spawn.expect("Place 'test':") |
| 105 |
spawn.expect(" comment: my comment") |
| 106 |
spawn.expect(pexpect.EOF) |
| 107 |
spawn.close() |
| 108 |
assert spawn.exitstatus == 0, spawn.before.strip() |
| 109 |
|
| 110 |
def test_place_match(place): |
| 111 |
with pexpect.spawn('python -m labgrid.remote.client -p test add-match "e1/g1/r1" "e2/g2/*"') as spawn: |
| 112 |
spawn.expect(pexpect.EOF) |
| 113 |
spawn.close() |
| 114 |
assert spawn.exitstatus == 0, spawn.before.strip() |
| 115 |
|
| 116 |
with pexpect.spawn('python -m labgrid.remote.client -p test del-match "e1/g1/r1"') as spawn: |
| 117 |
spawn.expect(pexpect.EOF) |
| 118 |
spawn.close() |
| 119 |
assert spawn.exitstatus == 0, spawn.before.strip() |
| 120 |
|
| 121 |
with pexpect.spawn('python -m labgrid.remote.client -p test show') as spawn: |
| 122 |
spawn.expect(" matches:") |
| 123 |
spawn.expect(" e2/g2/*") |
| 124 |
spawn.expect(pexpect.EOF) |
| 125 |
spawn.close() |
| 126 |
assert spawn.exitstatus == 0, spawn.before.strip() |
| 127 |
|
| 128 |
def test_place_match_duplicates(place): |
| 129 |
|
| 130 |
matches = ( |
| 131 |
("e1/g1/r1", "e1/g1/r1"), |
| 132 |
("e1/g1/r1/n1", "e1/g1/r1/n1"), |
| 133 |
("e1/g1/r1/n1", "e1/g1/r1"), |
| 134 |
("e1/g1/r1", "e1/g1/r1/n1"), |
| 135 |
) |
| 136 |
for match in matches: |
| 137 |
with pexpect.spawn(f'python -m labgrid.remote.client -p test add-match "{match[0]}" "{match[1]}"') as spawn: |
| 138 |
spawn.expect(f"pattern '{match[1]}' exists, skipping") |
| 139 |
spawn.expect(pexpect.EOF) |
| 140 |
spawn.close() |
| 141 |
assert spawn.exitstatus == 0, spawn.before.strip() |
| 142 |
|
| 143 |
with pexpect.spawn(f'python -m labgrid.remote.client -p test del-match "{match[0]}"') as spawn: |
| 144 |
spawn.expect(pexpect.EOF) |
| 145 |
spawn.close() |
| 146 |
assert spawn.exitstatus == 0, spawn.before.strip() |
| 147 |
|
| 148 |
def test_place_acquire(place): |
| 149 |
with pexpect.spawn('python -m labgrid.remote.client -p test acquire') as spawn: |
| 150 |
spawn.expect(pexpect.EOF) |
| 151 |
spawn.close() |
| 152 |
assert spawn.exitstatus == 0, spawn.before.strip() |
| 153 |
|
| 154 |
with pexpect.spawn('python -m labgrid.remote.client who') as spawn: |
| 155 |
spawn.expect(".*test.*") |
| 156 |
spawn.expect(pexpect.EOF) |
| 157 |
spawn.close() |
| 158 |
assert spawn.exitstatus == 0, spawn.before.strip() |
| 159 |
|
| 160 |
with pexpect.spawn('python -m labgrid.remote.client -p test release') as spawn: |
| 161 |
spawn.expect(pexpect.EOF) |
| 162 |
spawn.close() |
| 163 |
assert spawn.exitstatus == 0, spawn.before.strip() |
| 164 |
|
| 165 |
def test_place_acquire_multiple(create_place, tmpdir): |
| 166 |
|
| 167 |
place_names = ['test1', 'test2'] |
| 168 |
for place_name in place_names: |
| 169 |
create_place(place_name) |
| 170 |
|
| 171 |
|
| 172 |
p = tmpdir.join('config.yaml') |
| 173 |
p.write('targets:') |
| 174 |
for place_name in place_names: |
| 175 |
p.write( |
| 176 |
f""" |
| 177 |
{place_name}: |
| 178 |
resources: |
| 179 |
RemotePlace: |
| 180 |
name: {place_name} |
| 181 |
""", |
| 182 |
mode='a', |
| 183 |
) |
| 184 |
|
| 185 |
|
| 186 |
with pexpect.spawn(f'python -m labgrid.remote.client -c {p} acquire') as spawn: |
| 187 |
spawn.expect(pexpect.EOF) |
| 188 |
assert spawn.exitstatus == 0, spawn.before.strip() |
| 189 |
|
| 190 |
|
| 191 |
with pexpect.spawn('python -m labgrid.remote.client who') as spawn: |
| 192 |
spawn.expect(pexpect.EOF) |
| 193 |
for place_name in place_names: |
| 194 |
assert place_name.encode('utf-8') in spawn.before |
| 195 |
|
| 196 |
assert spawn.exitstatus == 0, spawn.before.strip() |
| 197 |
|
| 198 |
|
| 199 |
with pexpect.spawn(f'python -m labgrid.remote.client -c {p} release') as spawn: |
| 200 |
spawn.expect(pexpect.EOF) |
| 201 |
assert spawn.exitstatus == 0, spawn.before.strip() |
| 202 |
|
| 203 |
|
| 204 |
with pexpect.spawn('python -m labgrid.remote.client who') as spawn: |
| 205 |
spawn.expect('User.*Host.*Place.*Changed\r\n') |
| 206 |
assert not spawn.before, spawn.before |
| 207 |
|
| 208 |
def test_place_acquire_enforce(place): |
| 209 |
with pexpect.spawn('python -m labgrid.remote.client -p test add-match does/not/exist') as spawn: |
| 210 |
spawn.expect(pexpect.EOF) |
| 211 |
spawn.close() |
| 212 |
assert spawn.exitstatus == 0, spawn.before.strip() |
| 213 |
|
| 214 |
with pexpect.spawn('python -m labgrid.remote.client -p test acquire') as spawn: |
| 215 |
spawn.expect("Match does/not/exist has no matching remote resource") |
| 216 |
spawn.expect(pexpect.EOF) |
| 217 |
spawn.close() |
| 218 |
assert spawn.exitstatus != 0, spawn.before.strip() |
| 219 |
|
| 220 |
with pexpect.spawn('python -m labgrid.remote.client -p test acquire --allow-unmatched') as spawn: |
| 221 |
spawn.expect("acquired place test") |
| 222 |
spawn.expect(pexpect.EOF) |
| 223 |
spawn.close() |
| 224 |
assert spawn.exitstatus == 0, spawn.before.strip() |
| 225 |
|
| 226 |
with pexpect.spawn('python -m labgrid.remote.client -p test release') as spawn: |
| 227 |
spawn.expect(pexpect.EOF) |
| 228 |
spawn.close() |
| 229 |
assert spawn.exitstatus == 0, spawn.before.strip() |
| 230 |
|
| 231 |
def test_place_acquire_broken(place, exporter): |
| 232 |
with pexpect.spawn('python -m labgrid.remote.client -p test add-match "*/Broken/*"') as spawn: |
| 233 |
spawn.expect(pexpect.EOF) |
| 234 |
spawn.close() |
| 235 |
assert spawn.exitstatus == 0, spawn.before.strip() |
| 236 |
|
| 237 |
with pexpect.spawn('python -m labgrid.remote.client -p test acquire') as spawn: |
| 238 |
spawn.expect('Failed to acquire resources for place test') |
| 239 |
spawn.expect(pexpect.EOF) |
| 240 |
spawn.close() |
| 241 |
assert spawn.exitstatus == 1, spawn.before.strip() |
| 242 |
|
| 243 |
with pexpect.spawn('python -m labgrid.remote.client -p test show') as spawn: |
| 244 |
spawn.expect("'broken': 'start failed'") |
| 245 |
spawn.expect(pexpect.EOF) |
| 246 |
spawn.close() |
| 247 |
print(spawn.before.decode()) |
| 248 |
assert spawn.exitstatus == 0, spawn.before.strip() |
| 249 |
|
| 250 |
def test_place_release_from(monkeypatch, place, exporter): |
| 251 |
user = "test-user" |
| 252 |
host = "test-host" |
| 253 |
monkeypatch.setenv("LG_USERNAME", user) |
| 254 |
monkeypatch.setenv("LG_HOSTNAME", host) |
| 255 |
|
| 256 |
|
| 257 |
with pexpect.spawn('python -m labgrid.remote.client -p test acquire') as spawn: |
| 258 |
spawn.expect(pexpect.EOF) |
| 259 |
spawn.close() |
| 260 |
assert spawn.exitstatus == 0, spawn.before.strip() |
| 261 |
|
| 262 |
|
| 263 |
with pexpect.spawn('python -m labgrid.remote.client who') as spawn: |
| 264 |
spawn.expect(f"{user}\\s+{host}\\s+test") |
| 265 |
spawn.expect(pexpect.EOF) |
| 266 |
spawn.close() |
| 267 |
assert spawn.exitstatus == 0, spawn.before.strip() |
| 268 |
|
| 269 |
|
| 270 |
with pexpect.spawn('python -m labgrid.remote.client -p test release-from foo/bar') as spawn: |
| 271 |
spawn.expect(pexpect.EOF) |
| 272 |
spawn.close() |
| 273 |
assert spawn.exitstatus == 0, spawn.before.strip() |
| 274 |
|
| 275 |
|
| 276 |
with pexpect.spawn('python -m labgrid.remote.client who') as spawn: |
| 277 |
spawn.expect(f"{user}\\s+{host}\\s+test") |
| 278 |
spawn.expect(pexpect.EOF) |
| 279 |
spawn.close() |
| 280 |
assert spawn.exitstatus == 0, spawn.before.strip() |
| 281 |
|
| 282 |
|
| 283 |
with pexpect.spawn(f'python -m labgrid.remote.client -p test release-from {host}/{user}') as spawn: |
| 284 |
spawn.expect(pexpect.EOF) |
| 285 |
spawn.close() |
| 286 |
assert spawn.exitstatus == 0, spawn.before.strip() |
| 287 |
|
| 288 |
|
| 289 |
with pexpect.spawn('python -m labgrid.remote.client who') as spawn: |
| 290 |
spawn.expect(pexpect.EOF) |
| 291 |
spawn.close() |
| 292 |
assert spawn.exitstatus == 0, spawn.before.strip() |
| 293 |
before = spawn.before.decode("utf-8").strip() |
| 294 |
assert user not in before and not host in before, before |
| 295 |
|
| 296 |
def test_place_add_no_name(coordinator): |
| 297 |
with pexpect.spawn('python -m labgrid.remote.client create') as spawn: |
| 298 |
spawn.expect("missing place name") |
| 299 |
spawn.expect(pexpect.EOF) |
| 300 |
spawn.close() |
| 301 |
assert spawn.exitstatus != 0, spawn.before.strip() |
| 302 |
|
| 303 |
def test_place_del_no_name(coordinator): |
| 304 |
with pexpect.spawn('python -m labgrid.remote.client delete') as spawn: |
| 305 |
spawn.expect("place pattern not specified") |
| 306 |
spawn.expect(pexpect.EOF) |
| 307 |
spawn.close() |
| 308 |
assert spawn.exitstatus != 0, spawn.before.strip() |
| 309 |
|
| 310 |
def test_remoteplace_target(place_acquire, tmpdir): |
| 311 |
from labgrid.environment import Environment |
| 312 |
p = tmpdir.join("config.yaml") |
| 313 |
p.write( |
| 314 |
""" |
| 315 |
targets: |
| 316 |
test1: |
| 317 |
role: foo |
| 318 |
resources: |
| 319 |
RemotePlace: |
| 320 |
name: test |
| 321 |
""" |
| 322 |
) |
| 323 |
e = Environment(str(p)) |
| 324 |
t = e.get_target("test1") |
| 325 |
t.await_resources(t.resources) |
| 326 |
|
| 327 |
remote_place = t.get_resource("RemotePlace") |
| 328 |
assert remote_place.tags == {"board": "123board"} |
| 329 |
|
| 330 |
def test_remoteplace_target_without_env(request, place_acquire): |
| 331 |
from labgrid import Target |
| 332 |
from labgrid.resource import RemotePlace |
| 333 |
|
| 334 |
t = Target(request.node.name) |
| 335 |
remote_place = RemotePlace(t, name="test") |
| 336 |
assert remote_place.tags == {"board": "123board"} |
| 337 |
|
| 338 |
def test_resource_conflict(place_acquire, tmpdir): |
| 339 |
with pexpect.spawn('python -m labgrid.remote.client -p test2 create') as spawn: |
| 340 |
spawn.expect(pexpect.EOF) |
| 341 |
spawn.close() |
| 342 |
assert spawn.exitstatus == 0, spawn.before.strip() |
| 343 |
|
| 344 |
with pexpect.spawn('python -m labgrid.remote.client -p test2 add-match "*/Testport/*"') as spawn: |
| 345 |
spawn.expect(pexpect.EOF) |
| 346 |
spawn.close() |
| 347 |
assert spawn.exitstatus == 0, spawn.before.strip() |
| 348 |
|
| 349 |
with pexpect.spawn('python -m labgrid.remote.client -p test2 acquire') as spawn: |
| 350 |
spawn.expect(pexpect.EOF) |
| 351 |
spawn.close() |
| 352 |
assert spawn.exitstatus != 0, spawn.before.strip() |
| 353 |
|
| 354 |
with pexpect.spawn('python -m labgrid.remote.client -p test2 delete') as spawn: |
| 355 |
spawn.expect(pexpect.EOF) |
| 356 |
spawn.close() |
| 357 |
assert spawn.exitstatus == 0, spawn.before.strip() |
| 358 |
|
| 359 |
def test_reservation(place_acquire, tmpdir): |
| 360 |
with pexpect.spawn('python -m labgrid.remote.client reserve --shell board=123board name=test') as spawn: |
| 361 |
spawn.expect(pexpect.EOF) |
| 362 |
spawn.close() |
| 363 |
assert spawn.exitstatus == 0, spawn.before.strip() |
| 364 |
m = re.search(rb"^export LG_TOKEN=(\S+)$", spawn.before.replace(b'\r\n', b'\n'), re.MULTILINE) |
| 365 |
assert m is not None, spawn.before.strip() |
| 366 |
token = m.group(1) |
| 367 |
|
| 368 |
env = os.environ.copy() |
| 369 |
env['LG_TOKEN'] = token.decode('ASCII') |
| 370 |
|
| 371 |
with pexpect.spawn('python -m labgrid.remote.client reservations') as spawn: |
| 372 |
spawn.expect(pexpect.EOF) |
| 373 |
spawn.close() |
| 374 |
assert spawn.exitstatus == 0, spawn.before.strip() |
| 375 |
assert b'waiting' in spawn.before, spawn.before.strip() |
| 376 |
assert token in spawn.before, spawn.before.strip() |
| 377 |
|
| 378 |
with pexpect.spawn('python -m labgrid.remote.client -p test release') as spawn: |
| 379 |
spawn.expect(pexpect.EOF) |
| 380 |
spawn.close() |
| 381 |
assert spawn.exitstatus == 0, spawn.before.strip() |
| 382 |
|
| 383 |
with pexpect.spawn('python -m labgrid.remote.client reservations') as spawn: |
| 384 |
spawn.expect(pexpect.EOF) |
| 385 |
spawn.close() |
| 386 |
assert spawn.exitstatus == 0, spawn.before.strip() |
| 387 |
assert b'allocated' in spawn.before, spawn.before.strip() |
| 388 |
assert token in spawn.before, spawn.before.strip() |
| 389 |
|
| 390 |
with pexpect.spawn('python -m labgrid.remote.client reservations') as spawn: |
| 391 |
spawn.expect(pexpect.EOF) |
| 392 |
spawn.close() |
| 393 |
assert spawn.exitstatus == 0, spawn.before.strip() |
| 394 |
assert b'allocated' in spawn.before, spawn.before.strip() |
| 395 |
assert token in spawn.before, spawn.before.strip() |
| 396 |
|
| 397 |
with pexpect.spawn('python -m labgrid.remote.client -p + acquire', env=env) as spawn: |
| 398 |
spawn.expect(pexpect.EOF) |
| 399 |
spawn.close() |
| 400 |
assert spawn.exitstatus == 0, spawn.before.strip() |
| 401 |
|
| 402 |
with pexpect.spawn('python -m labgrid.remote.client -p + show', env=env) as spawn: |
| 403 |
spawn.expect(pexpect.EOF) |
| 404 |
spawn.close() |
| 405 |
assert token in spawn.before, spawn.before.strip() |
| 406 |
assert spawn.exitstatus == 0, spawn.before.strip() |
| 407 |
|
| 408 |
with pexpect.spawn('python -m labgrid.remote.client -p + release', env=env) as spawn: |
| 409 |
spawn.expect(pexpect.EOF) |
| 410 |
spawn.close() |
| 411 |
assert spawn.exitstatus == 0, spawn.before.strip() |
| 412 |
|
| 413 |
with pexpect.spawn('python -m labgrid.remote.client reservations') as spawn: |
| 414 |
spawn.expect(pexpect.EOF) |
| 415 |
spawn.close() |
| 416 |
assert spawn.exitstatus == 0, spawn.before.strip() |
| 417 |
assert b'allocated' in spawn.before, spawn.before.strip() |
| 418 |
assert token in spawn.before, spawn.before.strip() |
| 419 |
|
| 420 |
with pexpect.spawn('python -m labgrid.remote.client cancel-reservation', env=env) as spawn: |
| 421 |
spawn.expect(pexpect.EOF) |
| 422 |
spawn.close() |
| 423 |
assert spawn.exitstatus == 0, spawn.before.strip() |
| 424 |
|
| 425 |
with pexpect.spawn('python -m labgrid.remote.client reservations') as spawn: |
| 426 |
spawn.expect(pexpect.EOF) |
| 427 |
spawn.close() |
| 428 |
assert spawn.exitstatus == 0, spawn.before.strip() |
| 429 |
assert token not in spawn.before, spawn.before.strip() |
| 430 |
|
| 431 |
with pexpect.spawn('python -m labgrid.remote.client -p test acquire') as spawn: |
| 432 |
spawn.expect(pexpect.EOF) |
| 433 |
spawn.close() |
| 434 |
assert spawn.exitstatus == 0, spawn.before.strip() |
| 435 |
|
| 436 |
def test_resource_acquired_state_on_exporter_restart(monkeypatch, place, exporter): |
| 437 |
user = "test-user" |
| 438 |
host = "test-host" |
| 439 |
monkeypatch.setenv("LG_USERNAME", user) |
| 440 |
monkeypatch.setenv("LG_HOSTNAME", host) |
| 441 |
|
| 442 |
|
| 443 |
with pexpect.spawn('python -m labgrid.remote.client -p test add-match testhost/Testport/NetworkSerialPort') as spawn: |
| 444 |
spawn.expect(pexpect.EOF) |
| 445 |
spawn.close() |
| 446 |
assert spawn.exitstatus == 0, spawn.before.strip() |
| 447 |
|
| 448 |
|
| 449 |
with pexpect.spawn('python -m labgrid.remote.client -p test show') as spawn: |
| 450 |
spawn.expect(pexpect.EOF) |
| 451 |
spawn.close() |
| 452 |
assert spawn.exitstatus == 0, spawn.before.strip() |
| 453 |
assert b"acquired: None" in spawn.before |
| 454 |
assert b"Matching resource 'NetworkSerialPort' (testhost/Testport/NetworkSerialPort/NetworkSerialPort)" in spawn.before |
| 455 |
|
| 456 |
with pexpect.spawn('python -m labgrid.remote.client -p test -v resources') as spawn: |
| 457 |
spawn.expect(pexpect.EOF) |
| 458 |
spawn.close() |
| 459 |
assert spawn.exitstatus == 0, spawn.before.strip() |
| 460 |
assert b"Resource 'NetworkSerialPort' (testhost/Testport/NetworkSerialPort[/NetworkSerialPort]):\r\n {'acquired': None," in spawn.before |
| 461 |
|
| 462 |
|
| 463 |
with pexpect.spawn('python -m labgrid.remote.client -p test acquire') as spawn: |
| 464 |
spawn.expect(pexpect.EOF) |
| 465 |
spawn.close() |
| 466 |
assert spawn.exitstatus == 0, spawn.before.strip() |
| 467 |
|
| 468 |
with pexpect.spawn('python -m labgrid.remote.client -p test -v resources') as spawn: |
| 469 |
spawn.expect(pexpect.EOF) |
| 470 |
spawn.close() |
| 471 |
assert spawn.exitstatus == 0, spawn.before.strip() |
| 472 |
assert b"Resource 'NetworkSerialPort' (testhost/Testport/NetworkSerialPort[/NetworkSerialPort]):\r\n {'acquired': 'test'," in spawn.before |
| 473 |
|
| 474 |
|
| 475 |
exporter.stop() |
| 476 |
exporter.start() |
| 477 |
|
| 478 |
|
| 479 |
with pexpect.spawn('python -m labgrid.remote.client -p test show') as spawn: |
| 480 |
spawn.expect(pexpect.EOF) |
| 481 |
spawn.close() |
| 482 |
assert spawn.exitstatus == 0, spawn.before.strip() |
| 483 |
assert f"acquired: {host}/{user}" in spawn.before.decode("utf-8") |
| 484 |
assert b"Acquired resource 'NetworkSerialPort' (testhost/Testport/NetworkSerialPort/NetworkSerialPort)" in spawn.before |
| 485 |
|
| 486 |
|
| 487 |
with pexpect.spawn('python -m labgrid.remote.client -p test release') as spawn: |
| 488 |
spawn.expect(pexpect.EOF) |
| 489 |
spawn.close() |
| 490 |
assert spawn.exitstatus == 0, spawn.before.strip() |
| 491 |
|
| 492 |
with pexpect.spawn('python -m labgrid.remote.client -p test -v resources') as spawn: |
| 493 |
spawn.expect(pexpect.EOF) |
| 494 |
spawn.close() |
| 495 |
assert spawn.exitstatus == 0, spawn.before.strip() |
| 496 |
assert b"Resource 'NetworkSerialPort' (testhost/Testport/NetworkSerialPort[/NetworkSerialPort]):\r\n {'acquired': None," in spawn.before |
| 497 |
|
| 498 |
|
| 499 |
with pexpect.spawn('python -m labgrid.remote.client -p test show') as spawn: |
| 500 |
spawn.expect(pexpect.EOF) |
| 501 |
spawn.close() |
| 502 |
assert spawn.exitstatus == 0, spawn.before.strip() |
| 503 |
assert b"acquired: None" in spawn.before |
| 504 |
assert b"Matching resource 'NetworkSerialPort' (testhost/Testport/NetworkSerialPort/NetworkSerialPort)" in spawn.before |
| 505 |
|
| 506 |
|
| 507 |
with pexpect.spawn('python -m labgrid.remote.client -p test acquire') as spawn: |
| 508 |
spawn.expect(pexpect.EOF) |
| 509 |
spawn.close() |
| 510 |
assert spawn.exitstatus == 0, spawn.before.strip() |
| 511 |
|
| 512 |
with pexpect.spawn('python -m labgrid.remote.client -p test release') as spawn: |
| 513 |
spawn.expect(pexpect.EOF) |
| 514 |
spawn.close() |
| 515 |
assert spawn.exitstatus == 0, spawn.before.strip() |
| 516 |
|
| 517 |
|
| 518 |
def test_exporter_timeout(place, exporter): |
| 519 |
with pexpect.spawn('python -m labgrid.remote.client resources') as spawn: |
| 520 |
spawn.expect(pexpect.EOF) |
| 521 |
spawn.close() |
| 522 |
assert spawn.exitstatus == 0, spawn.before.strip() |
| 523 |
assert b'/Testport/NetworkSerialPort' in spawn.before |
| 524 |
|
| 525 |
|
| 526 |
with pexpect.spawn('python -m labgrid.remote.client -p test acquire') as spawn: |
| 527 |
spawn.expect(pexpect.EOF) |
| 528 |
spawn.close() |
| 529 |
assert spawn.exitstatus == 0, spawn.before.strip() |
| 530 |
|
| 531 |
exporter.suspend_tree() |
| 532 |
try: |
| 533 |
time.sleep(30) |
| 534 |
|
| 535 |
|
| 536 |
with pexpect.spawn('python -m labgrid.remote.client resources') as spawn: |
| 537 |
spawn.expect(pexpect.EOF) |
| 538 |
spawn.close() |
| 539 |
assert spawn.exitstatus == 0, spawn.before.strip() |
| 540 |
assert b'/Testport/NetworkSerialPort' not in spawn.before |
| 541 |
finally: |
| 542 |
exporter.resume_tree() |
| 543 |
|
| 544 |
|
| 545 |
time.sleep(5) |
| 546 |
|
| 547 |
assert not exporter.isalive() |
| 548 |
assert exporter.exitstatus == 100 |
| 549 |
|
| 550 |
with pexpect.spawn('python -m labgrid.remote.client -p test release') as spawn: |
| 551 |
spawn.expect(pexpect.EOF) |
| 552 |
spawn.close() |
| 553 |
assert spawn.exitstatus == 0, spawn.before.strip() |
| 554 |
|
| 555 |
def test_reservation_custom_config(place, exporter, tmpdir): |
| 556 |
p = tmpdir.join("config.yaml") |
| 557 |
p.write( |
| 558 |
""" |
| 559 |
targets: |
| 560 |
test1: |
| 561 |
role: foo |
| 562 |
resources: |
| 563 |
RemotePlace: |
| 564 |
name: test |
| 565 |
""" |
| 566 |
) |
| 567 |
with pexpect.spawn(f'python -m labgrid.remote.client -c {p} reserve --wait --shell board=123board name=test') as spawn: |
| 568 |
spawn.expect(pexpect.EOF) |
| 569 |
spawn.close() |
| 570 |
assert spawn.exitstatus == 0, spawn.before.strip() |
| 571 |
m = re.search(rb"^export LG_TOKEN=(\S+)$", spawn.before.replace(b'\r\n', b'\n'), re.MULTILINE) |
| 572 |
s = re.search(rb"^Selected role$", spawn.before.replace(b'\r\n', b'\n'), re.MULTILINE) |
| 573 |
assert m is not None, spawn.before.strip() |
| 574 |
assert s is None, spawn.before.strip() |
| 575 |
token = m.group(1) |
| 576 |
|
| 577 |
env = os.environ.copy() |
| 578 |
env['LG_TOKEN'] = token.decode('ASCII') |
| 579 |
|
| 580 |
with pexpect.spawn(f'python -m labgrid.remote.client -c {p} -p + lock', env=env) as spawn: |
| 581 |
spawn.expect("acquired place test") |
| 582 |
spawn.expect(pexpect.EOF) |
| 583 |
spawn.close() |
| 584 |
assert spawn.exitstatus == 0, spawn.before.strip() |
| 585 |
|
| 586 |
with pexpect.spawn(f'python -m labgrid.remote.client -c {p} -p + release', env=env) as spawn: |
| 587 |
spawn.expect("released place test") |
| 588 |
spawn.expect(pexpect.EOF) |
| 589 |
spawn.close() |
| 590 |
assert spawn.exitstatus == 0, spawn.before.strip() |
| 591 |
|
| 592 |
def test_same_name_resources(place, exporter, tmpdir): |
| 593 |
with pexpect.spawn('python -m labgrid.remote.client -p test add-named-match "testhost/Many/NetworkService" "samename"') as spawn: |
| 594 |
spawn.expect(pexpect.EOF) |
| 595 |
spawn.close() |
| 596 |
assert spawn.exitstatus == 0, spawn.before.strip() |
| 597 |
|
| 598 |
with pexpect.spawn('python -m labgrid.remote.client -p test add-named-match "testhost/Many/NetworkSerialPort" "samename"') as spawn: |
| 599 |
spawn.expect(pexpect.EOF) |
| 600 |
spawn.close() |
| 601 |
assert spawn.exitstatus == 0, spawn.before.strip() |
| 602 |
|
| 603 |
with pexpect.spawn('python -m labgrid.remote.client -p test acquire') as spawn: |
| 604 |
spawn.expect(pexpect.EOF) |
| 605 |
spawn.close() |
| 606 |
assert spawn.exitstatus == 0, spawn.before.strip() |
| 607 |
|
| 608 |
with pexpect.spawn('python -m labgrid.remote.client -p test env') as spawn: |
| 609 |
spawn.expect(pexpect.EOF) |
| 610 |
spawn.close() |
| 611 |
assert spawn.exitstatus == 0, spawn.before.strip() |
| 612 |
assert "NetworkService".encode("utf-8") in spawn.before.replace(b'\r\n', b'\n'), spawn.before.strip() |
| 613 |
assert "NetworkSerialPort".encode("utf-8") in spawn.before.replace(b'\r\n', b'\n'), spawn.before.strip() |
| 614 |
|
| 615 |
with pexpect.spawn('python -m labgrid.remote.client -p test release') as spawn: |
| 616 |
spawn.expect(pexpect.EOF) |
| 617 |
spawn.close() |
| 618 |
assert spawn.exitstatus == 0, spawn.before.strip() |