PD migrator: handle deactivated users in PD when migrating schedules (#1407)
# What this PR does Handle deactivated users in PD when migrating schedules using PD migrator. ## Checklist - [x] Tests updated
This commit is contained in:
parent
52ea445f6c
commit
e2392988c8
2 changed files with 43 additions and 7 deletions
|
|
@ -132,6 +132,16 @@ class Schedule:
|
|||
shifts = []
|
||||
errors = []
|
||||
for layer in self.layers:
|
||||
# Check if all users in the layer exist in PD
|
||||
deactivated_user_ids = [
|
||||
user_id for user_id in layer.user_ids if user_id not in user_id_map
|
||||
]
|
||||
if deactivated_user_ids:
|
||||
errors.append(
|
||||
f"{layer.name}: User IDs {deactivated_user_ids} not found. The users probably have been deactivated in PagerDuty."
|
||||
)
|
||||
continue
|
||||
|
||||
# A single PagerDuty layer can result in multiple OnCall shifts
|
||||
layer_shifts, error = layer.to_oncall_shifts(user_id_map)
|
||||
|
||||
|
|
|
|||
|
|
@ -2,13 +2,11 @@ import datetime
|
|||
|
||||
from migrator.resources.schedules import Restriction, Schedule
|
||||
|
||||
|
||||
class IdentityMap(dict):
|
||||
def __missing__(self, key):
|
||||
return key
|
||||
|
||||
|
||||
user_id_map = IdentityMap()
|
||||
user_id_map = {
|
||||
"USER_ID_1": "USER_ID_1",
|
||||
"USER_ID_2": "USER_ID_2",
|
||||
"USER_ID_3": "USER_ID_3",
|
||||
}
|
||||
|
||||
|
||||
def test_merge_restrictions():
|
||||
|
|
@ -177,6 +175,34 @@ def test_current_or_next_restriction():
|
|||
)
|
||||
|
||||
|
||||
def test_deactivated_users():
|
||||
pd_schedule = {
|
||||
"name": "No restrictions",
|
||||
"time_zone": "Europe/London",
|
||||
"schedule_layers": [
|
||||
{
|
||||
"name": "Layer 1",
|
||||
"start": "2023-02-19T19:25:55+00:00",
|
||||
"end": None,
|
||||
"rotation_virtual_start": "2023-02-07T19:00:00+00:00",
|
||||
"rotation_turn_length_seconds": 1209600,
|
||||
"restrictions": [],
|
||||
"users": [
|
||||
{"user": {"id": "USER_ID_1"}},
|
||||
{"user": {"id": "USER_ID_DEACTIVATED"}},
|
||||
],
|
||||
},
|
||||
],
|
||||
}
|
||||
|
||||
oncall_schedule, errors = Schedule.from_dict(pd_schedule).to_oncall_schedule(
|
||||
user_id_map
|
||||
)
|
||||
assert errors == [
|
||||
"Layer 1: User IDs ['USER_ID_DEACTIVATED'] not found. The users probably have been deactivated in PagerDuty."
|
||||
]
|
||||
|
||||
|
||||
def test_no_restrictions():
|
||||
pd_schedule = {
|
||||
"name": "No restrictions",
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue