Skip to content

Limits the number of network interfaces per instance - #816

Merged
bnaecker merged 1 commit into
mainfrom
limit-nics
Mar 28, 2022
Merged

bnaecker merged 1 commit into
mainfrom
limit-nics

Conversation

@bnaecker

Copy link
Copy Markdown
Collaborator
  • Limits interfaces to 8 inline with RFD 135
  • Adds check against this limit in instance create saga
  • Adds subquery to the interface creation query that checks this limit
    too. This works by assigning each NIC a slot on the device, and
    assigns the lowest available slot, up to the limit.
  • Add test against the total per-instance limit

@bnaecker
bnaecker requested a review from jmpesp March 27, 2022 15:05
@bnaecker

Copy link
Copy Markdown
Collaborator Author

This will address #810 when merged.

This adds a subquery to the interface-creation query that assigns the lowest available slot, or fails a table check constraint otherwise. I've added a test that exercises this limit check, but there's another aspect that is actually difficult to test with the current code: testing that we assign the lowest available slot.

To do that, I:

  • Created an instance. This has one NIC in slot 0.
  • Added two custom NICs, in slots 1 and 2.
  • Deleted the first custom NIC, in slot 1.
  • Added a new NIC. It should have slot 1, which I've verified it does.

I had to resurrect the oxapi_demo script, since the CLI doesn't currently support adding or deleting new interfaces for an instance. But below is the DB state at each stage:

Create an instance:

[email protected]:32221/omicron> select slot from network_interface where time_deleted is null;
  slot
--------
     0
(1 row)

Add two interfaces:

[email protected]:32221/omicron> select slot from network_interface where time_deleted is null;
  slot
--------
     0
     1
(2 rows)

Time: 0ms total (execution 0ms / network 0ms)

[email protected]:32221/omicron> select slot from network_interface where time_deleted is null;
  slot
--------
     2
     0
     1
(3 rows)

Delete the middle interface:

[email protected]:32221/omicron> select slot from network_interface where time_deleted is null;
  slot
--------
     2
     0
(2 rows)

Time: 1ms total (execution 1ms / network 0ms)

And add one back, seeing that it takes slot 1.

[email protected]:32221/omicron> select slot from network_interface where time_deleted is null;
  slot
--------
     2
     0
     1
(3 rows)

Time: 1ms total (execution 0ms / network 0ms)

@bnaecker

Copy link
Copy Markdown
Collaborator Author

Actually, this might be a more useful view of the table in the final state:

[email protected]:32221/omicron> select time_created, time_deleted, slot from network_interface;
          time_created          |         time_deleted          | slot
--------------------------------+-------------------------------+-------
  2022-03-27 15:00:29.160602+00 | NULL                          |    2
  2022-03-27 14:47:53.917718+00 | NULL                          |    0
  2022-03-27 14:58:39.365886+00 | 2022-03-27 15:00:44.085588+00 |    1
  2022-03-27 15:02:12.182115+00 | NULL                          |    1
(4 rows)

Time: 1ms total (execution 1ms / network 0ms)

@jmpesp jmpesp left a comment

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.

🚢

Comment thread nexus/src/db/subnet_allocation.rs Resolved
- Limits interfaces to 8 inline with RFD 135
- Adds check against this limit in instance create saga
- Adds subquery to the interface creation query that checks this limit
  too. This works by assigning each NIC a slot on the device, and
  assigns the lowest available slot, up to the limit.
- Add test against the total per-instance limit
@bnaecker
bnaecker enabled auto-merge (squash) March 28, 2022 18:32
@bnaecker
bnaecker merged commit 4c575f4 into main Mar 28, 2022
@bnaecker
bnaecker deleted the limit-nics branch March 28, 2022 19:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants