Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support more than 99 nodes in NixOS tests & export toHex and toBase #85635

Merged
merged 4 commits into from Jul 20, 2020

Conversation

basvandijk
Copy link
Member

@basvandijk basvandijk commented Apr 20, 2020

Motivation for this change

The current zeroPad function, which determines the MAC address of each QEMU VM in NixOS tests, returns a MAC address component in decimal notation while it should return it in hexadecimal. This means that you get inconsistent MAC addresses once you have 10 nodes or more. Worse: when you have 100 or more nodes the MAC address will look like 52:54:00:12:01:100 which is invalid.

Things done

This PR fixes the zeroPad function to return a proper hexadecimal component which means we can now have up to 254 nodes.

The implementation needed the toHex and toBase functions which have been added to the lib and come with unit tests.

Finally the dhcpSimple NixOS test from the networking test suite has been modified to give out fixed IP addresses (instead of a range) based on the MAC address.

  • Tested using sandboxing (nix.useSandbox on NixOS, or option sandbox in nix.conf on non-NixOS linux)
  • Built on platform(s)
    • NixOS
    • macOS
    • other Linux distributions
  • Tested via one or more NixOS test(s) if existing and applicable for the change (look inside nixos/tests)
  • Tested compilation of all pkgs that depend on this change using nix-shell -p nixpkgs-review --run "nixpkgs-review wip"
  • Tested execution of all binary files (usually in ./result/bin/)
  • Determined the impact on package closure size (by running nix path-info -S before and after)
  • Ensured that relevant documentation is up to date
  • Fits CONTRIBUTING.md.

@basvandijk
Copy link
Member Author

@GrahamcOfBorg test networking

@basvandijk
Copy link
Member Author

@GrahamcOfBorg test networking.dhcpSimple

@basvandijk
Copy link
Member Author

@GrahamcOfBorg test networking.networkd
@GrahamcOfBorg test networking.scripted

`toHex` converts the given positive integer to a string of the hexadecimal
representation of that integer. For example:

```
toHex 0 => "0"

toHex 16 => "10"

toHex 250 => "FA"
```

`toBase base i` converts the positive integer `i` to a list of it
digits in the given `base`. For example:

```
toBase 10 123 => [ 1 2 3 ]

toBase 2 6 => [ 1 1 0 ]

toBase 16 250 => [ 15 10 ]
```
This modifies the `router` to not give out a range of IP addresses but
only give out a fixed address based on the MAC address using the
`services.dhcpd4.machines` option.

To get access to the MAC address the `qemuNicMac` function is defined
and exported from `qemu-flags.nix`.
This makes the type of these functions more apparent from the name.
@basvandijk
Copy link
Member Author

@GrahamcOfBorg test networking.networkd
@GrahamcOfBorg test networking.scripted

@basvandijk
Copy link
Member Author

@GrahamcOfBorg test networking.networkd.dhcpSimple
@GrahamcOfBorg test networking.scripted.dhcpSimple
@GrahamcOfBorg test networking.networkd.dhcpOneIf
@GrahamcOfBorg test networking.scripted.dhcpOneIf

@basvandijk basvandijk merged commit 27296cc into NixOS:master Jul 20, 2020
@edolstra
Copy link
Member

Maybe it's better to assert that there aren't more than 99 nodes? If you have that many nodes you have a big problem, since it's going to be superslow and take a huge amount of memory.

@arianvp
Copy link
Member

arianvp commented Jul 20, 2020

No. as Bas already noted this starts breaking at 10 nodes; not 100 without this fix. Adding an assertion < 100 will not be enough.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants