Skip to content

Commit a568ae9

Browse files
committed
script: add config-diff tool
Signed-off-by: Naveen Naidu <[email protected]>
1 parent ecf4a71 commit a568ae9

File tree

3 files changed

+784
-0
lines changed

3 files changed

+784
-0
lines changed

src/script/config-diff/README.md

Lines changed: 158 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,158 @@
1+
# Ceph Config Diff Tool
2+
3+
This program is a Python-based tool designed to compare the configuration options of Ceph by cloning the repository and analyzing the files present in the `src/common/options` directory. It supports three modes of operation: `diff-branch`, `diff-tag`, and `diff-branch-remote-repo`.
4+
5+
Note: This tool **does not** compare the configuration changes occuring on a running Ceph cluster.
6+
7+
## Features
8+
9+
- **Compare Branches**: Compare configuration options between two branches in the same repository.
10+
- **Compare Tags**: Compare configuration options between two tags in the same repository.
11+
- **Compare Branches Across Repositories**: Compare configuration options between branches in different repositories.
12+
13+
## Usage
14+
15+
Run the program using the following command:
16+
17+
```bash
18+
python3 config_diff.py <mode> [options]
19+
```
20+
21+
### Modes
22+
23+
1. **`diff-branch`**: Compare configuration options between two branches in the same Ceph repository.
24+
```bash
25+
python3 config_diff.py diff-branch --ref-branch <branch1> --cmp-branch <branch2> [--ref-repo <repo-url>] [--skip-clone] [--format <output-format>]
26+
```
27+
28+
- `--ref-branch`: The reference branch to compare against.
29+
- `--cmp-branch`: The branch to compare.
30+
- `--ref-repo`: (Optional) The repository URL. Defaults to the Ceph upstream repository.
31+
- `--skip-clone`: (Optional) Skips cloning repositories for diff. **Note**: When using this flag, the script must be run from a valid Ceph upstream repository or a forked repository that has access to the branches present in the upstream repository or already contains those branches.
32+
- `--format`: (Optional) Specify the output format for the configuration diff. Options are `json` or `posix-diff`. Default is `json`.
33+
34+
35+
2. **`diff-tag`**: Compare configuration options between two tags in the same Ceph repository.
36+
```bash
37+
python3 config_diff.py diff-tag --ref-tag <tag1> --cmp-tag <tag2> [--ref-repo <repo-url>] [--posix-diff]
38+
```
39+
40+
- `--ref-tag`: The reference tag to compare against.
41+
- `--cmp-tag`: The tag to compare.
42+
- `--ref-repo`: (Optional) The repository URL. Defaults to the Ceph upstream repository.
43+
- `--skip-clone`: (Optional) Skips cloning repositories for diff. **Note**: When using this flag, the script must be run from a valid Ceph upstream repository or a forked repository that has access to the branches present in the upstream repository or already contains those branches.
44+
- `--format`: (Optional) Specify the output format for the configuration diff. Options are `json` or `posix-diff`. Default is `json`.
45+
46+
3. **`diff-branch-remote-repo`**: Compare configuration options between branches in different repositories.
47+
```bash
48+
python3 config_diff.py diff-branch-remote-repo --ref-branch <branch1> --cmp-branch <branch2> --remote-repo <repo-url> [--ref-repo <repo-url>] [--posix-diff]
49+
```
50+
51+
- `--ref-branch`: The reference branch to compare against.
52+
- `--cmp-branch`: The branch to compare.
53+
- `--remote-repo`: The remote repository URL for the branch to compare.
54+
- `--ref-repo`: (Optional) The repository URL for the reference branch. Defaults to the Ceph upstream repository.
55+
- `--skip-clone`: (Optional) Skips cloning repositories for diff. **Note**: When using this flag, the script must be run from a valid Ceph upstream repository or a forked repository that has access to the branches present in the upstream repository or already contains those branches.
56+
- `--format`: (Optional) Specify the output format for the configuration diff. Options are `json` or `posix-diff`. Default is `json`.
57+
58+
### Example Commands
59+
60+
1. Compare two branches in the same repository:
61+
```bash
62+
python3 config_diff.py diff-branch --ref-branch main --cmp-branch feature-branch
63+
```
64+
65+
The above command checks how the configuration options present in the branch
66+
`feature-branch` has changed from the `main` branch
67+
68+
2. Compare two tags in the same repository:
69+
```bash
70+
python3 config_diff.py diff-tag --ref-tag v1.0.0 --cmp-tag v1.1.0
71+
```
72+
The above command checks how the configuration options present in the tag
73+
`v1.1.0` has changed from the `v1.0.0` branch
74+
75+
3. Compare branches across repositories:
76+
```bash
77+
python3 config_diff.py diff-branch-remote-repo --ref-branch main --cmp-branch feature-branch --remote-repo https://github.com/username/ceph
78+
```
79+
80+
81+
The above command checks how the configuration options present in the
82+
`feature-branch` of the remote repository `https://github.com/username/ceph`
83+
has changed from the `main` branch of the ceph upstream repo. This command is
84+
used by the `diff-ceph-config.yml` GitHub Action to check for any
85+
configuration changes on the any PR's that are raised.
86+
87+
### Important Notes for `--skip-clone` Flag
88+
89+
- When using the `--skip-clone` flag, the script assumes it is being run from a valid Ceph upstream repository or a forked repository.
90+
- If using a forked repository, ensure that the forked repository has access to the branches present in the upstream repository or already contains those branches.
91+
92+
93+
## Output
94+
95+
The program generates a JSON output containing the following structure:
96+
97+
```json
98+
{
99+
"added": {
100+
"daemon1": ["config1", "config2"]
101+
},
102+
"deleted": {
103+
"daemon2": ["config3"]
104+
},
105+
"modified": {
106+
"daemon3": {
107+
"config4": {
108+
"key1": {
109+
"before": "old_value",
110+
"after": "new_value"
111+
}
112+
}
113+
}
114+
}
115+
}
116+
```
117+
118+
- **`added`**: Configuration options added in the comparing version.
119+
- **`deleted`**: Configuration options removed in the comparing version.
120+
- **`modified`**: Configuration options modified between the two versions.
121+
122+
## Example:
123+
124+
### diff in JSON
125+
126+
```json
127+
{
128+
"added": {
129+
"mgr.yaml.in": [
130+
"mgr_client_bytes_test"
131+
]
132+
},
133+
"deleted": {
134+
"osd.yaml.in": [
135+
"osd_scrub_load_threshold"
136+
]
137+
},
138+
"modified": {
139+
"global.yaml.in": {
140+
"mon_debug_no_require_tentacle": {
141+
"default": {
142+
"before": false,
143+
"after": true
144+
}
145+
}
146+
}
147+
}
148+
}
149+
```
150+
151+
### POSIX like diff:
152+
153+
```diff
154+
+ added: bluefs_wal_envelope_mode
155+
- removed: rgw_d4n_l1_write_open_flags
156+
! changed: mon_nvmeofgw_skip_failovers_interval: old: 16
157+
! changed: mon_nvmeofgw_skip_failovers_interval: new: 32
158+
```

0 commit comments

Comments
 (0)