| @@ -387,8 +387,11 @@ async def release_board(board_id, user: str = Depends(lookup_user), | |||
| board=Board.from_orm(brd)), | |||
| ) | |||
| env = os.environ.copy() | |||
| env.update({ k: v for k, v in brd.attrs.items() if k in { 'iface', 'ip', 'devfsrule' } }) | |||
| sub = await asyncio.create_subprocess_exec( | |||
| settings.setup_script, 'release', brd.name, user, | |||
| settings.setup_script, 'release', brd.name, user, env=env, | |||
| stdout=subprocess.PIPE, stderr=subprocess.PIPE) | |||
| stdout, stderr = await sub.communicate() | |||
| retcode = sub.returncode | |||
| @@ -568,10 +571,12 @@ class TestBiteLab(unittest.IsolatedAsyncioTestCase): | |||
| # that the cora-1 board is reserved | |||
| data = self.data | |||
| brd = self.brdmgr.boards['cora-1'] | |||
| attrs = dict(iface='a', ip='b', devfsrule='c') | |||
| async with brd.lock: | |||
| await brd.reserve() | |||
| obrdreq = await data.BoardStatus.objects.create( | |||
| board='cora-1', user='foo') | |||
| brd.attrcache.update(attrs) | |||
| # that when the correct user releases the board | |||
| res = await self.client.post('/board/cora-1/release', | |||
| @@ -585,13 +590,17 @@ class TestBiteLab(unittest.IsolatedAsyncioTestCase): | |||
| board=Board(name='cora-1', | |||
| brdclass='cora-z7s', | |||
| reserved=True, | |||
| attrs=attrs, | |||
| ), | |||
| ).dict() | |||
| self.assertEqual(res.json(), info) | |||
| # and that it called the release script | |||
| cse.assert_called_with(self.settings.setup_script, 'release', | |||
| 'cora-1', 'foo', stdout=subprocess.PIPE, stderr=subprocess.PIPE) | |||
| env = os.environ.copy() | |||
| env.update(attrs) | |||
| cse.assert_called_with(self.settings.setup_script, | |||
| 'release', 'cora-1', 'foo', env=env, | |||
| stdout=subprocess.PIPE, stderr=subprocess.PIPE) | |||
| # and that the error got logged | |||
| le.assert_called_with('release script failure: board: \'cora-1\', ret: 1, stderr: b\'error\'') | |||
| @@ -635,7 +644,10 @@ class TestBiteLab(unittest.IsolatedAsyncioTestCase): | |||
| # that when the setup script returns | |||
| wrap_subprocess_exec(cse, | |||
| json.dumps(dict(ip='192.0.2.10')).encode('utf-8')) | |||
| json.dumps(dict(ip='192.0.2.10', | |||
| iface='epair0b', | |||
| devfsrule='14', | |||
| )).encode('utf-8')) | |||
| # that reserving the board | |||
| res = await self.client.post('/board/cora-1/reserve', | |||
| @@ -650,6 +662,8 @@ class TestBiteLab(unittest.IsolatedAsyncioTestCase): | |||
| reserved=True, | |||
| attrs=dict(power=False, | |||
| ip='192.0.2.10', | |||
| iface='epair0b', | |||
| devfsrule='14', | |||
| ), | |||
| ).dict() | |||
| self.assertEqual(res.json(), brdinfo) | |||
| @@ -702,9 +716,15 @@ class TestBiteLab(unittest.IsolatedAsyncioTestCase): | |||
| } | |||
| self.assertEqual(res.json(), info) | |||
| env = os.environ.copy() | |||
| env['ip'] = brdinfo['attrs']['ip'] | |||
| env['iface'] = brdinfo['attrs']['iface'] | |||
| env['devfsrule'] = brdinfo['attrs']['devfsrule'] | |||
| # and that it called the release script | |||
| cse.assert_called_with(self.settings.setup_script, 'release', | |||
| 'cora-1', 'foo', stdout=subprocess.PIPE, stderr=subprocess.PIPE) | |||
| 'cora-1', 'foo', env=env, | |||
| stdout=subprocess.PIPE, stderr=subprocess.PIPE) | |||
| # that it can be reserved by a different user | |||
| res = await self.client.post('/board/cora-1/reserve', | |||