Skip to content

Commit

Permalink
policy: Fix capture full state with simple line
Browse files Browse the repository at this point in the history
For capture like `default-gw: override me with the cache`, nmstate
should store the full state to `default-gw`.

Example file created and will be used for unit tests.

Signed-off-by: Gris Ge <[email protected]>
  • Loading branch information
cathay4t committed Sep 25, 2024
1 parent 245fcb1 commit 58389ee
Show file tree
Hide file tree
Showing 4 changed files with 71 additions and 1 deletion.
21 changes: 21 additions & 0 deletions examples/policy/capture_all/current.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
---
routes:
running:
- destination: 0.0.0.0/0
next-hop-interface: eth1
next-hop-address: 192.0.2.1
config:
- destination: 0.0.0.0/0
next-hop-interface: eth1
next-hop-address: 192.0.2.1
interfaces:
- name: eth1
type: ethernet
state: up
mac-address: 1c:c1:0c:32:3b:ff
ipv4:
enabled: true
dhcp: false
address:
- ip: 192.0.2.251
prefix-length: 24
23 changes: 23 additions & 0 deletions examples/policy/capture_all/expected.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
---
routes:
config:
- destination: 0.0.0.0/0
next-hop-interface: br1
next-hop-address: 192.0.2.1
interfaces:
- name: br1
description: Linux bridge with base interface as a port
type: linux-bridge
state: up
ipv4:
enabled: true
dhcp: false
address:
- ip: 192.0.2.251
prefix-length: 24
bridge:
options:
stp:
enabled: false
port:
- name: eth1
25 changes: 25 additions & 0 deletions examples/policy/capture_all/policy.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
---
capture:
default-gw: override me with the cache
base-iface: >-
interfaces.name == capture.default-gw.routes.running.0.next-hop-interface
base-iface-routes: >-
routes.running.next-hop-interface ==
capture.default-gw.routes.running.0.next-hop-interface
bridge-routes: >-
capture.base-iface-routes | routes.running.next-hop-interface:="br1"
desiredState:
interfaces:
- bridge:
options:
stp:
enabled: false
port:
- name: "{{ capture.base-iface.interfaces.0.name }}"
description: Linux bridge with base interface as a port
ipv4: "{{ capture.base-iface.interfaces.0.ipv4 }}"
name: br1
state: up
type: linux-bridge
routes:
config: "{{ capture.bridge-routes.routes.running }}"
3 changes: 2 additions & 1 deletion rust/src/lib/policy/capture.rs
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,8 @@ impl NetworkCaptureCommand {
)
});
} else {
return Ok(NetworkState::new());
// User just want to store full state to a new name
return Ok(input);
}
}

Expand Down

0 comments on commit 58389ee

Please sign in to comment.