Skip to content

Commit 5a5a00a

Browse files
committed
contest: hw: count and display reservation time
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
1 parent 698d494 commit 5a5a00a

4 files changed

Lines changed: 11 additions & 2 deletions

File tree

contest/hw/hwksft.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,8 @@ def test(binfo, rinfo, cbarg): # pylint: disable=unused-argument
7777

7878
tree_path = config.get('local', 'tree_path')
7979
mc_url = config.get('hw', 'machine_control_url')
80+
executor_name = config.get('executor', 'name')
81+
mc = MCClient(mc_url, caller=executor_name)
8082
nic_vendor = config.get('hw', 'nic_vendor')
8183
nic_model = config.get('hw', 'nic_model')
8284
mc = MCClient(mc_url)

contest/hw/lib/reservations.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,7 @@ def reserve(self, caller, machine_ids, timeout=None):
9292
self.active[reservation_id] = {
9393
'caller': caller,
9494
'machine_ids': machine_ids,
95+
'reserved_at': now,
9596
'last_refresh': now,
9697
'timeout': timeout,
9798
}

contest/hw/machine_control.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,7 @@ def _recover_reservations(pool, mgr):
114114
mgr.active[rid] = {
115115
'caller': info['caller'],
116116
'machine_ids': info['machine_ids'],
117+
'reserved_at': now,
117118
'last_refresh': now,
118119
'timeout': mgr.default_timeout,
119120
}
@@ -165,6 +166,9 @@ def get_machine_info():
165166
if mid in rinfo['machine_ids']:
166167
info['reservation_id'] = rid
167168
info['reserved_by'] = rinfo['caller']
169+
elapsed = (datetime.datetime.now(datetime.UTC) -
170+
rinfo['reserved_at']).total_seconds()
171+
info['reserved_secs'] = int(elapsed)
168172
break
169173
result.append(info)
170174
return jsonify(result)

ui/status.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1081,8 +1081,10 @@ function hw_machines_loaded(data)
10811081
$.each(data, function(i, m) {
10821082
var cell = row.insertCell();
10831083
var state = m.state;
1084-
if (m.reserved_by)
1085-
state += " (" + m.reserved_by + ")";
1084+
if (m.reserved_by) {
1085+
var mins = Math.round(m.reserved_secs / 60);
1086+
state += " (" + m.reserved_by + ", " + mins + "m)";
1087+
}
10861088
cell.innerText = state;
10871089
});
10881090
}

0 commit comments

Comments
 (0)