Skip to content

Commit

Permalink
Ensure we extend memberships where necessary
Browse files Browse the repository at this point in the history
  • Loading branch information
andy-isoc committed Oct 9, 2024
1 parent 4cab026 commit 34e5c77
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 11 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
# Changelog

## 0.6
- extend a membership if created date for imported record is before end date of previous record

## 0.5
- fix membership starting after it ended
- fix import for AS being a member of an IX for multiple prefixes
Expand Down
20 changes: 11 additions & 9 deletions ixp_tracker/importers.py
Original file line number Diff line number Diff line change
Expand Up @@ -212,15 +212,17 @@ def do_process_member_data(all_member_data):
# Avoid re-adding a member for the same start_date
continue
if membership.end_date > created_date:
logger.warning("We might have overlapping memberships", extra=log_data)
# Most recent membership has ended so create a new membership record
membership = IXPMembershipRecord(
member=member,
start_date=created_date,
is_rs_peer=member_data["is_rs_peer"],
speed=member_data["speed"]
)
logger.debug("Created new membership as previous one ended", extra=log_data)
logger.debug("Extending membership", extra=log_data)
membership.end_date = None
else:
# Most recent membership has ended so create a new membership record
membership = IXPMembershipRecord(
member=member,
start_date=created_date,
is_rs_peer=member_data["is_rs_peer"],
speed=member_data["speed"]
)
logger.debug("Created new membership as previous one ended", extra=log_data)
membership.save()

logger.debug("Imported IXP member record", extra=log_data)
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[project]
name = "django-ixp-tracker"
version = "0.5"
version = "0.6"
description = "Library to retrieve and manipulate data about IXPs"
readme = "README.md"
requires-python = ">=3.8"
Expand Down
35 changes: 34 additions & 1 deletion tests/test_members_import.py
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,37 @@ def test_adds_new_membership_for_existing_member_marked_as_left():
assert current_membership.first().end_date is None


def test_extends_membership_for_member_marked_as_left_if_created_before_date_left():
asn = create_asn_fixture(dummy_member_data["asn"])
ixp = create_ixp_fixture(dummy_member_data["ix_id"])
member = IXPMember(
ixp=ixp,
asn=asn,
last_updated=dummy_member_data["updated"],
last_active=datetime(year=2023, month=7, day=13)
)
member.save()
membership = IXPMembershipRecord(
member=member,
start_date=datetime(year=2018, month=1, day=3).date(),
end_date=datetime(year=2018, month=7, day=13),
is_rs_peer=False,
speed=500
)
membership.save()

member_data_with_created_date_before_date_left = dict(dummy_member_data)
member_data_with_created_date_before_date_left["created"] = "2018-06-24T14:15:22Z"
processor = importers.process_member_data(date_now, TestLookup())
processor([member_data_with_created_date_before_date_left])

members = IXPMember.objects.all()
assert len(members) == 1
current_membership = IXPMembershipRecord.objects.filter(member=member).order_by("-start_date")
assert len(current_membership) == 1
assert current_membership.first().end_date is None


def test_marks_member_as_left_that_is_no_longer_active():
asn = create_asn_fixture(dummy_member_data["asn"])
ixp = create_ixp_fixture(dummy_member_data["ix_id"])
Expand Down Expand Up @@ -311,8 +342,10 @@ def test_ensure_multiple_member_entries_does_not_trigger_multiple_new_membership
)
membership.save()

member_data_with_created_date_after_date_left = dict(dummy_member_data)
member_data_with_created_date_after_date_left["created"] = "2023-09-24T14:15:22Z"
processor = importers.process_member_data(date_now, TestLookup())
processor([dummy_member_data, dummy_member_data])
processor([member_data_with_created_date_after_date_left, member_data_with_created_date_after_date_left])

memberships = IXPMembershipRecord.objects.filter(member=member)
assert len(memberships) == 2
Expand Down

0 comments on commit 34e5c77

Please sign in to comment.