Skip to content

Commit

Permalink
Ensure volatile keys are preserved, when saving a network (#1036)
Browse files Browse the repository at this point in the history
## Done

- Ensure volatile keys are preserved, when saving a network

Fixes canonical/lxd#14531

## QA

1. Run the LXD-UI:
- On the demo server via the link posted by @webteam-app below. This is
only available for PRs created by collaborators of the repo. Ask
@mas-who or @edlerd for access.
- With a local copy of this branch, [build and run as described in the
docs](../CONTRIBUTING.md#setting-up-for-development).
2. Perform the following QA steps:
    - edit a network, that has settings under config.volatile.*
- modify the network in the UI, ensure the save call contains all
config.volatile keys in the payload
  • Loading branch information
edlerd authored Dec 18, 2024
2 parents b6832ba + 9e9c0d9 commit 69a9617
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 3 deletions.
4 changes: 1 addition & 3 deletions src/pages/networks/forms/NetworkForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -99,9 +99,7 @@ export const toNetwork = (values: NetworkFormValues): Partial<LxdNetwork> => {
const excludeConfigKeys = getHandledNetworkConfigKeys();
const missingConfigFields = Object.fromEntries(
Object.entries(values.bareNetwork?.config ?? {}).filter(
(e) =>
!excludeConfigKeys.has(e[0] as keyof LxdNetworkConfig) &&
!e[0].startsWith("volatile"),
(e) => !excludeConfigKeys.has(e[0] as keyof LxdNetworkConfig),
),
);

Expand Down
1 change: 1 addition & 0 deletions src/types/network.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ export interface LxdNetworkConfig {
network?: string;
parent?: string;
[key: `user.${string}`]: string;
[key: `volatile.${string}`]: string;
}

export interface LxdNetwork {
Expand Down
15 changes: 15 additions & 0 deletions src/util/networkForm.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,19 @@ describe("conversion to form values and back with toNetworkFormValues and toNetw

expect(payload.config?.["user.key"]).toBe("custom-config-value");
});

it("preserves volatile keys in network config", () => {
const network = {
devices: {},
config: {
"user.key": "custom-config-value",
"volatile.network.ipv4.address": "1.2.3.4",
},
} as unknown as LxdNetwork;

const formValues = toNetworkFormValues(network);
const payload = toNetwork(formValues);

expect(payload.config?.["volatile.network.ipv4.address"]).toBe("1.2.3.4");
});
});

0 comments on commit 69a9617

Please sign in to comment.