Browse Source

make sure we get the output from the setup script..

main
John-Mark Gurney 4 years ago
parent
commit
f5f9966430
1 changed files with 13 additions and 6 deletions
  1. +13
    -6
      bitelab/__init__.py

+ 13
- 6
bitelab/__init__.py View File

@@ -50,6 +50,7 @@ import orm
import os
import socket
import sqlite3
import subprocess
import sys
import tempfile
import unittest
@@ -316,7 +317,8 @@ async def reserve_board(board_id_or_class, user: str = Depends(lookup_user),
# Initialize board
try:
sub = await asyncio.create_subprocess_exec(
settings.setup_script, 'reserve', brd.name, user)
settings.setup_script, 'reserve', brd.name, user,
stdout=subprocess.PIPE, stderr=subprocess.PIPE)
stdout, stderr = await sub.communicate()
if sub.returncode:
raise RuntimeError(sub.returncode, stderr)
@@ -360,11 +362,13 @@ async def release_board(board_id, user: str = Depends(lookup_user),
except orm.exceptions.NoMatch:
raise BITEError(
status_code=HTTP_400_BAD_REQUEST,
errobj=Error(error='Board not reserved.', board=Board.from_orm(brd)),
errobj=Error(error='Board not reserved.',
board=Board.from_orm(brd)),
)

sub = await asyncio.create_subprocess_exec(
settings.setup_script, 'release', brd.name, user)
settings.setup_script, 'release', brd.name, user,
stdout=subprocess.PIPE, stderr=subprocess.PIPE)
stdout, stderr = await sub.communicate()
if sub.returncode:
raise RuntimeError(sub.returncode, stderr)
@@ -621,7 +625,8 @@ class TestBiteLab(unittest.IsolatedAsyncioTestCase):
self.assertEqual(res.json(), info)

# and that it called the start script
cse.assert_called_with(self.settings.setup_script, 'reserve', 'cora-1', 'foo')
cse.assert_called_with(self.settings.setup_script, 'reserve',
'cora-1', 'foo', stdout=subprocess.PIPE, stderr=subprocess.PIPE)

# that when the setup script returns
self._wrap_subprocess_exec(cse, json.dumps(dict(ip='192.0.2.10')))
@@ -644,7 +649,8 @@ class TestBiteLab(unittest.IsolatedAsyncioTestCase):
self.assertEqual(res.json(), brdinfo)

# and that it called the start script
cse.assert_called_with(self.settings.setup_script, 'reserve', 'cora-1', 'foo')
cse.assert_called_with(self.settings.setup_script, 'reserve',
'cora-1', 'foo', stdout=subprocess.PIPE, stderr=subprocess.PIPE)

# that another user reserving the board
res = await self.client.post('/board/cora-1/reserve',
@@ -691,7 +697,8 @@ class TestBiteLab(unittest.IsolatedAsyncioTestCase):
self.assertEqual(res.json(), info)

# and that it called the release script
cse.assert_called_with(self.settings.setup_script, 'release', 'cora-1', 'foo')
cse.assert_called_with(self.settings.setup_script, 'release',
'cora-1', 'foo', stdout=subprocess.PIPE, stderr=subprocess.PIPE)

# that it can be reserved by a different user
res = await self.client.post('/board/cora-1/reserve',


Loading…
Cancel
Save