Skip to content

MAC Address values format update#9149

Merged
polmichel merged 16 commits into
stablefrom
pmi-20260504-mac-address-values
May 8, 2026
Merged

MAC Address values format update#9149
polmichel merged 16 commits into
stablefrom
pmi-20260504-mac-address-values

Conversation

@polmichel

@polmichel polmichel commented May 6, 2026

Copy link
Copy Markdown
Contributor

Why

MAC address values are standardized to the following form: 01-23-45-67-89-AB.
Expected standardized form is 01:23:45:67:89:AB.

Closes #9015 and IFC-2494

What

This PR updates the standardization method against MAC address values, and adds a migration to update any existing MAC address attributes or existing display labels/HFID that would reference such attribute. It also introduces the _normalize_value() framework hook on BaseAttribute (no-op by default), overridden in MacAddress to canonicalize input directly to colon-uppercase EUI-48 form.

Stack ordering

PR #8904 (IPHost/IPNetwork normalization + HFID/display-label recompute migration) is now stacked on top of this PR. m070 (this PR) normalizes MAC values; m071 (PR #8904) recomputes IP HFIDs/display labels and benefits from MAC values being already in colon form.

Note on history

This branch was originally PR #9134, but GitHub auto-marked that PR as "merged" when the previous force-push made the head reachable from its old base branch. This PR recreates it; it carries the same head branch (pmi-20260504-mac-address-values) with one rebuilt commit on top of stable.

…8 form (closes #9015)

Adds an input-time `_normalize_value()` hook on `BaseAttribute` (no-op default), overridden in `MacAddress` to emit colon-uppercase form (`AA:BB:CC:DD:EE:FF`). Adds m070 migration that rewrites stored MAC values + dependent HFIDs / display labels in the DB.

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
@polmichel polmichel requested review from a team as code owners May 6, 2026 08:22
@github-actions github-actions Bot added type/documentation Improvements or additions to documentation group/backend Issue related to the backend (API Server, Git Agent) labels May 6, 2026
@codspeed-hq

codspeed-hq Bot commented May 6, 2026

Copy link
Copy Markdown

Merging this PR will not alter performance

✅ 12 untouched benchmarks


Comparing pmi-20260504-mac-address-values (d5369a3) with stable (045500f)

Open in CodSpeed

form (`AA:BB:CC:DD:EE:FF`) per issue #9015.

Pre-existing values may be in any form accepted by ``netaddr.EUI`` — on
`stable`, ``serialize_value`` produces dash-uppercase form, but

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

stable or other branches in the repo shouldn't be referenced in here. unless I am misunderstanding what "stable" means in this context

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have missed it, thanks I think the bot added this one because I mentioned some dependencies with other PR and default stable branch behavior. My bad

if node_schema_name in SCHEMA_KINDS_TO_SKIP:
continue
schema = schema_branch.get_node(name=node_schema_name, duplicate=False)
if schema.branch not in branch_filter:

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it's possible for an attribute to be branch-aware on a branch-agnostic/local schema. so perhaps this filter should move down a layer

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch thanks

AND e1.status = "active"
AND e2.branch IN $branch_names
AND e2.to IS NULL
AND e2.status = "active"

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can you add AND n.uuid <> peer.uuid here to prevent paths that loop back to the same Node?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added there and in two other locations 76ed870

set_display_label: str | None = None,
) -> Node:
"""Create a node, then rewrite MAC + (optional) HFID + display_label so the DB matches the
legacy on-stable storage form: MacAddress stored as EUI-48 dash form."""

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

stable again

Comment on lines +187 to +200
default_branch.update_schema_hash()
gql_params = await prepare_graphql_params(db=db, branch=default_branch)
pre_result = await graphql(
schema=gql_params.schema,
source=INTERFACE_BY_ID_QUERY,
context_value=gql_params.context,
root_value=None,
variable_values={"ids": [node.id]},
)
assert pre_result.errors is None, pre_result.errors
assert pre_result.data is not None
pre_edge = pre_result.data["TestingInterface"]["edges"][0]["node"]
assert pre_edge["hfid"] == [LEGACY_DASH_MAC]
assert pre_edge["display_label"] == legacy_display_label

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we usually don't do graphql layer testing in migration tests. verifying the database should be enough

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That makes sense

return node


class TestMigration070(TestInfrahubApp):

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can you add a call to verify_graph from db_validation.py to the end of each of these test cases to ensure nothing is getting duplicated or orphaned please?

await node.new(db=db, name=node_name, mac=LEGACY_DASH_MAC)
await node.save(db=db)

# Mimic legacy on-stable state on the branch: dash-form MAC stored on disk plus dash-form HFID + display_label.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

stable

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it's worth considering consolidating these test cases into a single test case that I think would save some time. something like this

  • load data for default and user branches, including single object with different values on both
  • run migration on default
  • rebase user branch
  • run migration on user branch
  • verify data
  • run the migrations again to check idempotency
  • verify data again
  • verify_graph()

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok let's do this, I will do the same in the PR containing the migration 71

@polmichel polmichel marked this pull request as draft May 7, 2026 10:01
@@ -0,0 +1,406 @@
from __future__ import annotations

@polmichel polmichel May 7, 2026

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

With the inversion of both PRs, this code is currently duplicated, but will be removed from original class in the next PR

@polmichel polmichel marked this pull request as ready for review May 7, 2026 13:28
@polmichel polmichel requested a review from ajtmccarty May 7, 2026 13:28
- `Dropdown`: A list of choices, each choice can have a color and description
- `Email`: Email address
- `Password`: A Text String that should be obfuscated but which can be read with enough right in the UI
- `HashedPassword`: Similar to Password but it will not be shown in the UI and can't be re-read.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll just push the removal of this documentation change regarding product work on documentation

@github-actions github-actions Bot removed the type/documentation Improvements or additions to documentation label May 7, 2026
branch=default_branch,
at=migration_input.at,
branch_filter=(BranchSupportType.AWARE,),
)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should have thought of this before, but I think that the branch-filtering will exclude any branch-agnostic MAC address attributes

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

AGNOSTIC tackled on default_branch process, AWARE & LOCAL on both

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also applied on M071

db=migration_input.db,
branch=default_branch,
at=migration_input.at,
branch_filter=(BranchSupportType.AWARE,),

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this looks like it skips branch-local MAC attributes on the default branch

@polmichel polmichel requested a review from ajtmccarty May 8, 2026 08:33
@polmichel polmichel merged commit 324a6f7 into stable May 8, 2026
55 checks passed
@polmichel polmichel deleted the pmi-20260504-mac-address-values branch May 8, 2026 16:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

group/backend Issue related to the backend (API Server, Git Agent)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

task: Improve how a mac address is displayed

3 participants