-
Notifications
You must be signed in to change notification settings - Fork 286
nfs: add ApplyExportInfo function #1261
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
nixpanic
wants to merge
3
commits into
ceph:master
Choose a base branch
from
nixpanic:nfs/export-update
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,56 @@ | ||
| //go:build !(nautilus || octopus || pacific || quincy) && ceph_preview | ||
|
|
||
| package nfs | ||
|
|
||
| import ( | ||
| "encoding/json" | ||
| "errors" | ||
| "fmt" | ||
|
|
||
| "github.com/ceph/go-ceph/internal/commands" | ||
| ) | ||
|
|
||
| var errUnknownApplyState = errors.New("apply returned unknown state") | ||
|
|
||
| // applyRes is used to parse the result from "nfs export apply" which can | ||
| // modify multiple exports with a single call. Each export that was (attempted | ||
| // to be) modified has JSON resonse with "pseudo" and "state" in it. | ||
| // ApplyExportInfo() modifies only a single export, but the returned response | ||
| // is still formatted in a JSON list. | ||
| type applyRes []*struct { | ||
| Pseudo string `json:"pseudo"` | ||
| State string `json:"state"` | ||
| } | ||
|
|
||
| func parseApplyResults(res commands.Response) error { | ||
| results := applyRes{} | ||
| if err := res.NoStatus().Unmarshal(&results).End(); err != nil { | ||
| return err | ||
| } | ||
| for _, ar := range results { | ||
| if ar.State == "added" || ar.State == "updated" { | ||
| // succes, nothing to do for this ar | ||
| continue | ||
| } | ||
| return fmt.Errorf("%w %s for pseudo %s", errUnknownApplyState, ar.State, ar.Pseudo) | ||
| } | ||
| return nil | ||
| } | ||
|
|
||
| // ApplyExportInfo will create or update an existing NFS export. | ||
| // | ||
| // Similar To: | ||
| // | ||
| // ceph nfs export apply | ||
| func (nfsa *Admin) ApplyExportInfo(clusterID string, info ExportInfo) error { | ||
| buf, err := json.Marshal(info) | ||
| if err != nil { | ||
| return err | ||
| } | ||
| m := map[string]string{ | ||
| "prefix": "nfs export apply", | ||
| "format": "json", | ||
| "cluster_id": clusterID, | ||
| } | ||
| return parseApplyResults(commands.MarshalMgrCommandWithBuffer(nfsa.conn, m, buf)) | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,57 @@ | ||
| //go:build !(nautilus || octopus || pacific || quincy) && ceph_preview | ||
|
|
||
| package nfs | ||
|
|
||
| func (suite *NFSAdminSuite) TestApplyExportInfo() { | ||
| require := suite.Require() | ||
| ra := radosConnector.Get(suite.T()) | ||
| nfsa := NewFromConn(ra) | ||
|
|
||
| // Create initial export with ClientAddr | ||
| res, err := nfsa.CreateCephFSExport(CephFSExportSpec{ | ||
| FileSystemName: suite.fileSystemName, | ||
| ClusterID: suite.clusterID, | ||
| PseudoPath: "/applytest", | ||
| Path: "/january", | ||
| ClientAddr: []string{"192.168.1.0/24"}, | ||
| }) | ||
| require.NoError(err) | ||
| require.Equal("/applytest", res.Bind) | ||
|
|
||
| defer func() { | ||
| err = nfsa.RemoveExport(suite.clusterID, "/applytest") | ||
| require.NoError(err) | ||
| }() | ||
|
|
||
| // Get initial export info | ||
| info, err := nfsa.ExportInfo(suite.clusterID, "/applytest") | ||
| require.NoError(err) | ||
| require.Equal("/applytest", info.PseudoPath) | ||
| require.Equal("/january", info.Path) | ||
| require.Len(info.Clients, 1) | ||
| require.Contains(info.Clients[0].Addresses, "192.168.1.0/24") | ||
|
|
||
| // Modify the export info and apply it | ||
| // Several attributes cause an NFS-server restart, this doesn't work in | ||
| // the CI as there is no orchestrator handling it. | ||
| // This test should not modify user_id, fs_name, path or pseudo. | ||
| info.Clients = []ClientInfo{ | ||
| { | ||
| Addresses: []string{"10.0.0.0/8", "172.16.0.0/12"}, | ||
| AccessType: "RW", | ||
| Squash: "none", | ||
| }, | ||
| } | ||
| err = nfsa.ApplyExportInfo(suite.clusterID, info) | ||
| require.NoError(err) | ||
|
|
||
| // Verify the update by getting export info | ||
| updatedInfo, err := nfsa.ExportInfo(suite.clusterID, "/applytest") | ||
| require.NoError(err) | ||
| require.Equal("/applytest", updatedInfo.PseudoPath) | ||
| require.Equal("/january", updatedInfo.Path) | ||
| require.Len(updatedInfo.Clients, 1) | ||
| require.Len(updatedInfo.Clients[0].Addresses, 2) | ||
| require.Contains(updatedInfo.Clients[0].Addresses, "10.0.0.0/8") | ||
| require.Contains(updatedInfo.Clients[0].Addresses, "172.16.0.0/12") | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.