Skip to content

Commit d2d3356

Browse files
authored
Accept empty list of whitelisted_users when updating reservations. (#2950)
* Check that whitelisted_users is actually None to skip updates so that we can update empty lists ([]). * Fix formatting and test. * Update comments.
1 parent b67ef87 commit d2d3356

File tree

2 files changed

+28
-1
lines changed

2 files changed

+28
-1
lines changed

cirq/google/engine/engine_client.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -754,6 +754,8 @@ def update_reservation(self,
754754
start: the new starting time of the reservation as a datetime object
755755
end: the new ending time of the reservation as a datetime object
756756
whitelisted_users: a list of emails that can use the reservation.
757+
The empty list, [], will clear the whitelisted_users while None
758+
will leave the value unchanged.
757759
"""
758760
name = self._reservation_name_from_ids(
759761
project_id, processor_id, reservation_id) if reservation_id else ''
@@ -766,7 +768,7 @@ def update_reservation(self,
766768
if end:
767769
reservation.end_time.seconds = int(end.timestamp())
768770
paths.append('end_time')
769-
if whitelisted_users:
771+
if whitelisted_users != None:
770772
reservation.whitelisted_users.extend(whitelisted_users)
771773
paths.append('whitelisted_users')
772774

cirq/google/engine/engine_client_test.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -847,6 +847,31 @@ def test_update_reservation(client_constructor):
847847
}
848848

849849

850+
@mock.patch.object(quantum, 'QuantumEngineServiceClient', autospec=True)
851+
def test_update_reservation_remove_all_users(client_constructor):
852+
grpc_client = setup_mock_(client_constructor)
853+
name = 'projects/proj/processors/processor0/reservations/papar-party-44'
854+
result = qtypes.QuantumReservation(
855+
name=name,
856+
whitelisted_users=[],
857+
)
858+
grpc_client.update_quantum_reservation.return_value = result
859+
860+
client = EngineClient()
861+
assert (client.update_reservation(
862+
'proj',
863+
'processor0',
864+
'papar-party-44',
865+
whitelisted_users=[],
866+
) == result)
867+
kwargs = grpc_client.update_quantum_reservation.call_args[1]
868+
assert kwargs == {
869+
'name': name,
870+
'quantum_reservation': result,
871+
'update_mask': FieldMask(paths=['whitelisted_users'])
872+
}
873+
874+
850875
@mock.patch.object(quantum, 'QuantumEngineServiceClient', autospec=True)
851876
def test_list_time_slots(client_constructor):
852877
grpc_client = setup_mock_(client_constructor)

0 commit comments

Comments
 (0)