Skip to content

[Nexthop][fboss2-dev] Save the config commands to CLI metadata and in session commit.#809

Closed
benoit-nexthop wants to merge 2 commits into
facebook:mainfrom
nexthop-ai:fboss2-cli-prototype_part14
Closed

[Nexthop][fboss2-dev] Save the config commands to CLI metadata and in session commit.#809
benoit-nexthop wants to merge 2 commits into
facebook:mainfrom
nexthop-ai:fboss2-cli-prototype_part14

Conversation

@benoit-nexthop

@benoit-nexthop benoit-nexthop commented Jan 13, 2026

Copy link
Copy Markdown
Contributor

Pre-submission checklist

  • I've ran the linters locally and fixed lint errors related to the files I modified in this PR. You can install the linters by running pip install -r requirements-dev.txt && pre-commit install
  • pre-commit run

Summary

Now every config command is saved in the CLI session metadata so we can
easily tell what commands were used in a given session. The metadata is
now also saved along the config when we commit the session. A future
commit will make rollback also rely on this metadata to decide whether
or not to restart the agent.

Note: this change is part of a series, the previous one is #805, the next one is #825.

Test Plan

New unit tests added.

Sample usage

[admin@fboss101 ~]$ ~/benoit/fboss2-dev config interface eth1/1/1 description this is a test.
Successfully set description for interface(s) eth1/1/1
[admin@fboss101 ~]$ ~/benoit/fboss2-dev config interface eth1/1/1 mtu 1500
Successfully set MTU for interface(s) eth1/1/1 to 1500
[admin@fboss101 ~]$ ls -l ~/.fboss2/
total 216
-rw-r--r-- 1 admin admin 213174 Jan 13 13:00 agent.conf
-rw-r--r-- 1 admin admin    141 Jan 13 13:00 conf_metadata.json
[admin@fboss101 ~]$ cat ~/.fboss2/conf_metadata.json 
{
  "action": {},
  "commands": [
    "config interface eth1/1/1 description this is a test.",
    "config interface eth1/1/1 mtu 1500"
  ]
}
[admin@fboss101 ~]$ ~/benoit/fboss2-dev config session commit
Config session committed successfully as r6 and config reloaded.
[admin@fboss101 ~]$ ls -l /etc/coop/cli/
total 1292
-rw-r--r-- 1 root  root  213185 Jan 13 12:52 agent-r1.conf
-rw-r--r-- 1 admin admin 213194 Jan 13 12:56 agent-r2.conf
-rw-r--r-- 1 admin admin    108 Jan 13 12:56 agent-r2.metadata.json
-rw-r--r-- 1 admin admin 213185 Jan 13 12:56 agent-r3.conf
-rw-r--r-- 1 admin admin     99 Jan 13 12:56 agent-r3.metadata.json
-rw-r--r-- 1 admin admin 213185 Jan 13 12:58 agent-r4.conf
-rw-r--r-- 1 admin admin     80 Jan 13 12:58 agent-r4.metadata.json
-rw-r--r-- 1 admin admin 213185 Jan 13 12:58 agent-r5.conf
-rw-r--r-- 1 admin admin     80 Jan 13 12:58 agent-r5.metadata.json
-rw-r--r-- 1 admin admin 213174 Jan 13 13:00 agent-r6.conf
-rw-r--r-- 1 admin admin    141 Jan 13 13:00 agent-r6.metadata.json
[admin@fboss101 ~]$ cat /etc/coop/cli/agent-r6.metadata.json 
{
  "action": {},
  "commands": [
    "config interface eth1/1/1 description this is a test.",
    "config interface eth1/1/1 mtu 1500"
  ]
}
@meta-cla meta-cla Bot added the CLA Signed label Jan 13, 2026
@benoit-nexthop benoit-nexthop force-pushed the fboss2-cli-prototype_part14 branch 3 times, most recently from 42fe595 to 58cf5a1 Compare January 19, 2026 21:06
@benoit-nexthop benoit-nexthop force-pushed the fboss2-cli-prototype_part14 branch 4 times, most recently from e88c524 to 0304b7c Compare January 28, 2026 17:19
@benoit-nexthop benoit-nexthop force-pushed the fboss2-cli-prototype_part14 branch from 0304b7c to 31eb904 Compare January 28, 2026 18:48
meta-codesync Bot pushed a commit that referenced this pull request Feb 18, 2026
Summary:
**Pre-submission checklist**
- [x] I've ran the linters locally and fixed lint errors related to the files I modified in this PR. You can install the linters by running `pip install -r requirements-dev.txt && pre-commit install`
- [x] `pre-commit run`

A recent merge introduced a duplicate command by mistake (bad merge on my part) and this escaped because of lack of test coverage.

Also make sure we keep `cmake/CliFboss2Test.cmake` sorted.

Note: this change is part of a series, the previous one is #791, the next one is #809.

Pull Request resolved: #805

Test Plan: New regression unit test.

Reviewed By: AarjunC

Differential Revision: D93523408

Pulled By: joseph5wu

fbshipit-source-id: 87c4920c1fa1730631eafbf0a31e8c179145dc0d
@travisb-nexthop travisb-nexthop force-pushed the fboss2-cli-prototype_part14 branch from d3095ec to aaed4ff Compare February 18, 2026 23:30
@meta-codesync

meta-codesync Bot commented Feb 18, 2026

Copy link
Copy Markdown
Contributor

@joseph5wu has imported this pull request. If you are a Meta employee, you can view this in D93669865.

@joseph5wu joseph5wu 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.

Please address the unit test failure from the github action
https://github.com/facebook/fboss/actions/runs/22161929622/job/64082894482

fs::create_directories(sessionDir);
std::ofstream metaFile(metadataFile);
metaFile << R"({
"action": {"WEDGE_AGENT": "HITLESS"},

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.

"WEDGE_AGENT" -> "AGENT"

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.

Updated.


// Setup mock agent server
setupMockedAgentServer();
EXPECT_CALL(getMockAgent(), reloadConfig()).Times(1);

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.

Our internal run failed on this unit test:

❯❯❯ buck test //fboss/cli/fboss2/test:cmd_test
File changed: fbcode//fboss/cli/fboss2/test/CmdConfigSessionTest.cpp
✗ Fail: fbcode//fboss/cli/fboss2/test:cmd_test - ConfigSessionTestFixture.commitOnNewlyInitializedSession (3.9s)
Note: Google Test filter = ConfigSessionTestFixture.commitOnNewlyInitializedSession
[==========] Running 1 test from 1 test suite.
[----------] Global test environment set-up.
[----------] 1 test from ConfigSessionTestFixture
[ RUN      ] ConfigSessionTestFixture.commitOnNewlyInitializedSession
fbcode/fboss/cli/fboss2/test/CmdConfigSessionTest.cpp:284: Failure
Actual function call count doesn't match EXPECT_CALL(getMockAgent(), reloadConfig())...
         Expected: to be called once
           Actual: never called - unsatisfied and active

[  FAILED  ] ConfigSessionTestFixture.commitOnNewlyInitializedSession (3921 ms)

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.

Addressed.

benoit-nexthop and others added 2 commits February 18, 2026 23:02
Now every config command is saved in the CLI session metadata so we can
easily tell what commands were used in a given session. The metadata is
now also saved along the config when we commit the session. A future
commit will make rollback also rely on this metadata to decide whether
or not to restart the agent.
@manoharan-nexthop manoharan-nexthop force-pushed the fboss2-cli-prototype_part14 branch from aaed4ff to 17e16c5 Compare February 19, 2026 12:01
@facebook-github-bot

Copy link
Copy Markdown
Contributor

@benoit-nexthop has updated the pull request. You must reimport the pull request before landing.

@meta-codesync

meta-codesync Bot commented Feb 20, 2026

Copy link
Copy Markdown
Contributor

@joseph5wu merged this pull request in 9816430.

@benoit-nexthop benoit-nexthop deleted the fboss2-cli-prototype_part14 branch February 25, 2026 15:41
meta-codesync Bot pushed a commit that referenced this pull request Mar 3, 2026
Summary:
**Pre-submission checklist**
- [x] I've ran the linters locally and fixed lint errors related to the files I modified in this PR. You can install the linters by running `pip install -r requirements-dev.txt && pre-commit install`
- [x] `pre-commit run`

Replace the basic file-based configuration versioning mechanism with Git-based versioning for the CLI config session.

Key changes:

- Add new `Git` class providing a simple interface for Git operations: init, commit, log, show, etc
- Use `folly::Subprocess` with full path `/usr/bin/git` for all Git commands
- Replace revision files (`agent-rN.conf` + symlink) with atomic writes to agent.conf tracked in a local Git repository
- Use Git commit SHAs as revision identifiers instead of rN format
- Update RevisionList validation to accept Git SHAs (7+ hex chars)

Repository initialization:
- Automatically initialize Git repo if it doesn't exist
- Automatically create initial commit if repo has no commits but config file exists
- Use `--shared=group` flag and umask 0002 to ensure `.git` directory is group-writable when `/etc/coop` is group-writable

Commands updated:
- config history: Shows Git commit log with SHA, author, timestamp, message
- config session diff: Uses git show to compare commits
- config session commit: Creates Git commits with username as author
- config rollback: Reads config from Git history and creates new commit

Note: this change is part of a series, the previous one is #809, the next one is #832.

Pull Request resolved: #825

Test Plan:
Test updates:
- Update all CLI config tests to use Git-based setup
- Initialize Git repo and create initial commit in test fixtures
- Added new unit tests for the Git layer

## Sample usage

Simple change and session commit:
```
[admin@fboss101 benoit]$ ./fboss2-dev show interface eth1/1/1
+-----------+--------+-------+------+------+------------------------------+-------------+
| Interface | Status | Speed | VLAN | MTU  | Addresses                    | Description |
-----------------------------------------------------------------------------------------
| eth1/1/1  | down   | 800G  | 2001 | 9000 | 10.0.0.0/24                  | demo        |
|           |        |       |      |      | 2400::/64                    |             |
|           |        |       |      |      | fe80::b4db:91ff:fe95:ff07/64 |             |
-----------------------------------------------------------------------------------------
[admin@fboss101 benoit]$ ./fboss2-dev config interface eth1/1/1 description hello
Successfully set description for interface(s) eth1/1/1
[admin@fboss101 benoit]$ ./fboss2-dev config session diff
 --- current live config
+++ session config
@@ -2200,7 +2200,7 @@
     "ports": [
       {
         "conditionalEntropyRehash": false,
-        "description": "demo",
+        "description": "hello",
         "drainState": 0,
         "expectedLLDPValues": {
           "2": "eth1/5/1"
[admin@fboss101 benoit]$ ./fboss2-dev config session commit
Config session committed successfully as b8245b4 and config reloaded.
[admin@fboss101 benoit]$ ./fboss2-dev config history | head
 Commit    Author  Commit Time              Message
------------------------------------------------------------------------
 b8245b40  admin   2026-01-21 11:13:57  Config commit by admin
 7241abad  admin   2026-01-21 11:12:51  Config commit by admin
 02fe511c  admin   2026-01-21 10:51:36  Config commit by admin
 e5650a98  admin   2026-01-21 10:51:35  Config commit by admin
 ad07138f  admin   2026-01-21 10:51:35  Config commit by admin
 1845e710  admin   2026-01-21 10:51:35  Config commit by admin
 ede5a527  admin   2026-01-20 14:28:10  Config commit by admin
 e900ef88  admin   2026-01-20 14:23:25  Config commit by admin
[admin@fboss101 benoit]$ cd /etc/coop
[admin@fboss101 coop]$ git -c safe.directory=/etc/coop show
commit b8245b40b2b3c8797cbeed2fb91161e5440b7fd9 (HEAD -> main)
Author: admin <fboss-cli@localhost>
Date:   Wed Jan 21 11:13:57 2026 -0800

    Config commit by admin

 diff --git a/cli/agent.conf b/cli/agent.conf
index 406b341..f61516f 100644
 --- a/cli/agent.conf
+++ b/cli/agent.conf
@@ -2200,7 +2200,7 @@
     "ports": [
       {
         "conditionalEntropyRehash": false,
-        "description": "demo",
+        "description": "hello",
         "drainState": 0,
         "expectedLLDPValues": {
           "2": "eth1/5/1"
 diff --git a/cli/cli_metadata.json b/cli/cli_metadata.json
index 68f340a..6c6a925 100644
 --- a/cli/cli_metadata.json
+++ b/cli/cli_metadata.json
@@ -1,6 +1,6 @@
 {
   "action": {},
   "commands": [
-    "config interface eth1/1/1 description demo"
+    "config interface eth1/1/1 description hello"
   ]
 }
\ No newline at end of file
```
Rollback flow:
```
[admin@fboss101 benoit]$ ./fboss2-dev config interface eth1/1/1 description hello2
Successfully set description for interface(s) eth1/1/1
[admin@fboss101 benoit]$ ./fboss2-dev config session commit
Config session committed successfully as 476f9ee and config reloaded.
[admin@fboss101 benoit]$ ./fboss2-dev config history | head
 Commit    Author  Commit Time              Message
------------------------------------------------------------------------
 476f9ee4  admin   2026-01-21 11:15:23  Config commit by admin
 b8245b40  admin   2026-01-21 11:13:57  Config commit by admin
 7241abad  admin   2026-01-21 11:12:51  Config commit by admin      <-- we're going to rollback to here
 02fe511c  admin   2026-01-21 10:51:36  Config commit by admin
 e5650a98  admin   2026-01-21 10:51:35  Config commit by admin
 ad07138f  admin   2026-01-21 10:51:35  Config commit by admin
 1845e710  admin   2026-01-21 10:51:35  Config commit by admin
 ede5a527  admin   2026-01-20 14:28:10  Config commit by admin
[admin@fboss101 benoit]$ ./fboss2-dev config rollback 7241abad
Successfully rolled back. New commit: 8be163e7. Config reloaded.
[admin@fboss101 benoit]$ ./fboss2-dev show interface eth1/1/1
+-----------+--------+-------+------+------+------------------------------+-------------+
| Interface | Status | Speed | VLAN | MTU  | Addresses                    | Description |
-----------------------------------------------------------------------------------------
| eth1/1/1  | down   | 800G  | 2001 | 9000 | 10.0.0.0/24                  | demo        |
|           |        |       |      |      | 2400::/64                    |             |
|           |        |       |      |      | fe80::b4db:91ff:fe95:ff07/64 |             |
-----------------------------------------------------------------------------------------
[admin@fboss101 benoit]$ ./fboss2-dev config history | head
 Commit    Author  Commit Time          Message
---------------------------------------------------------------------------
 8be163e7  admin   2026-01-21 11:17:26  Rollback to 7241abad by admin
 476f9ee4  admin   2026-01-21 11:15:23  Config commit by admin
 b8245b40  admin   2026-01-21 11:13:57  Config commit by admin
 7241abad  admin   2026-01-21 11:12:51  Config commit by admin
 02fe511c  admin   2026-01-21 10:51:36  Config commit by admin
 e5650a98  admin   2026-01-21 10:51:35  Config commit by admin
 ad07138f  admin   2026-01-21 10:51:35  Config commit by admin
 1845e710  admin   2026-01-21 10:51:35  Config commit by admin
[admin@fboss101 benoit]$ cd /etc/coop
[admin@fboss101 coop]$ git -c safe.directory=/etc/coop show
commit 8be163e7cd60574278dc7201b157e4238fa55380 (HEAD -> main)
Author: admin <fboss-cli@localhost>
Date:   Wed Jan 21 11:17:26 2026 -0800

    Rollback to 7241abad by admin

 diff --git a/cli/agent.conf b/cli/agent.conf
index d918bae..406b341 100644
 --- a/cli/agent.conf
+++ b/cli/agent.conf
@@ -2200,7 +2200,7 @@
     "ports": [
       {
         "conditionalEntropyRehash": false,
-        "description": "hello2",
+        "description": "demo",
         "drainState": 0,
         "expectedLLDPValues": {
           "2": "eth1/5/1"
 diff --git a/cli/cli_metadata.json b/cli/cli_metadata.json
index 5435c54..68f340a 100644
 --- a/cli/cli_metadata.json
+++ b/cli/cli_metadata.json
@@ -1,6 +1,6 @@
 {
   "action": {},
   "commands": [
-    "config interface eth1/1/1 description hello2"
+    "config interface eth1/1/1 description demo"
   ]
 }
\ No newline at end of file
```

Reviewed By: srikrishnagopu

Differential Revision: D94975358

Pulled By: joseph5wu

fbshipit-source-id: 197bc68feed6f5fe9443ad91d24999546ebbb0e7
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

4 participants