Skip to content

Commit

Permalink
[metalos][host_configs] refactor test data to a builder
Browse files Browse the repository at this point in the history
Summary:
We currently copy the template and modify it in many places. This
makes it very hard to understand what changed and also duplicates a lot of
code. The refactor provides a starlark API that can be customized piece by
piece and generate the final host config for consumption.

The goal is to keep all relevant data manipulation in starlark outside provider
so anyone understanding python can craft a structure they want, without the
need to know host_config provider internals. Meanwhile, we utilize the rust
binary that generates the final json in provider to ensure the data is a valid
thrift object.

The API should also make it very obvious what changes each host config is
making on top of the base config. The parameters in builder API is flexible and
should capture common customizations. For uncommon ones, they can manipulate
the data for each section after calling the builder API.

Note: There are data changes that can be cleaned up in this diff, but it's
intentionally kept same for comparison purpose. Some of the deviations are
likely because of data copying. See next diff for clean up for anything marked
as TODO.

Test Plan:
Compare all touched targets to make sure their before/after
artifacts are exactly the same.
```
$ cat ~/bin/D48610337.sh | pastry
P812815820: https://www.internalfb.com/intern/paste/P812815820/
$ D48610337.sh 2>&1 | pastry
P812816172: https://www.internalfb.com/intern/paste/P812816172/
```

Reviewed By: pzmarzly

Differential Revision: D48610337

fbshipit-source-id: c8e7ba908ea1087214a8cd1e19a9156bbf1b388d
  • Loading branch information
wujj123456 authored and facebook-github-bot committed Aug 24, 2023
1 parent e03ecaf commit 0660063
Showing 1 changed file with 6 additions and 113 deletions.
119 changes: 6 additions & 113 deletions antlir/vm/bzl/disk.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -6,123 +6,16 @@
load("//antlir/bzl:image.bzl", "image")
load("//antlir/bzl/image/feature:defs.bzl", "feature")
load("//antlir/bzl/image/package:btrfs.bzl", "btrfs")
load("//metalos/host_configs/tests/bzl:builder.bzl", "builders")
load("//metalos/host_configs/tests/bzl:defs.bzl", "host_config")
load(":kernel.bzl", "normalize_kernel")

def _host_config(kernel_version):
return {
"boot_config": {
"bootloader": {
"cmdline": "console=ttyS0,57600 systemd.unified_cgroup_hierarchy=1 selinux=0 cgroup_no_v1=all root=LABEL=/ macaddress=00:00:00:00:00:01",
"pkg": {
"format": 2,
"id": {"uuid": "deadbeefdeadbeefdeadbeefdeadbeef"},
"kind": 8,
"name": "metalos.bootloader",
},
},
"deployment_specific": {"metalos": {}},
"initrd": {
"format": 2,
"id": {"uuid": "deadbeefdeadbeefdeadbeefdeadbeef"},
"kind": 3,
"name": "metalos.initrd",
},
"kernel": {
"cmdline": "console=ttyS0,57600 systemd.unified_cgroup_hierarchy=1 selinux=0 cgroup_no_v1=all root=LABEL=/ macaddress=00:00:00:00:00:01",
"pkg": {
"format": 1,
# deadbeef is always used as the version, but the package name is changed
"id": {"uuid": "deadbeefdeadbeefdeadbeefdeadbeef"},
"kind": 2,
"name": "kernel." + kernel_version,
},
},
"rootfs": {
"format": 1,
"id": {"uuid": "deadbeefdeadbeefdeadbeefdeadbeef"},
"kind": 1,
"name": "metalos",
},
},
"provisioning_config": {
"deployment_specific": {"metalos": {}},
"event_backend": {
"base_uri": "http://vmtest-host:8000/send-event",
"source": {
"asset_id": 1,
},
},
"gpt_root_disk": {
"format": 2,
"id": {"uuid": "deadbeefdeadbeefdeadbeefdeadbeef"},
"kind": 7,
"name": "metalos.gpt-root-disk",
},
"identity": {
"hostname": "vm00.abc00.facebook.com",
"id": "1",
"network": {
"dns": {
"search_domains": [
"example.com",
"subdomain.example.com",
],
"servers": [
"beef::cafe:1",
"beef::cafe:2",
],
},
"interfaces": [
{
"addrs": ["fd00:{0}::2".format(i)],
"essential": True if i == 0 else False,
"interface_type": 0,
"mac": "00:00:00:00:00:0{0}".format(i + 1),
"name": "eth{0}".format(i),
"structured_addrs": [
{
"addr": "fd00:{0}::2".format(i),
"mode": 0,
"prefix_length": 64,
},
],
}
for i in range(4)
],
"primary_interface": {
"addrs": ["fd00::2"],
"essential": True,
"interface_type": 0,
"mac": "00:00:00:00:00:01",
"name": "eth0",
"structured_addrs": [
{
"addr": "fd00::2",
"mode": 0,
"prefix_length": 64,
},
],
},
},
},
"imaging_initrd": {
"format": 2,
"id": {"uuid": "deadbeefdeadbeefdeadbeefdeadbeef"},
"kind": 4,
"name": "metalos.imaging-initrd",
},
"root_disk_config": {
"single_serial": {
"config": {},
"serial": "ROOT_DISK_SERIAL",
},
},
},
"runtime_config": {
"deployment_specific": {"metalos": {}},
},
}
return builders.build_host_config(
boot_config = builders.build_boot_config(uname = kernel_version),
provisioning_config = builders.build_provisioning_config(num_nics = 4),
runtime_config = builders.build_runtime_config(),
)

def _control_layer(
name,
Expand Down

0 comments on commit 0660063

Please sign in to comment.