Skip to content

Commit acaa06d

Browse files
committed
Use exported constants for netconf commit-datastore values
Signed-off-by: Markus Vahlenkamp <markus.vahlenkamp@nokia.com>
1 parent 38c2036 commit acaa06d

4 files changed

Lines changed: 12 additions & 12 deletions

File tree

‎pkg/config/datastore.go‎

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,8 @@ const (
3232
sbiNETCONF = "netconf"
3333
sbiGNMI = "gnmi"
3434

35-
ncCommitDatastoreRunning = "running"
36-
ncCommitDatastoreCandidate = "candidate"
35+
NcCommitDatastoreRunning = "running"
36+
NcCommitDatastoreCandidate = "candidate"
3737
)
3838

3939
type DatastoreConfig struct {
@@ -189,12 +189,12 @@ func (s *SBI) validateSetDefaults() error {
189189
case sbiNETCONF:
190190
switch s.NetconfOptions.CommitDatastore {
191191
case "":
192-
s.NetconfOptions.CommitDatastore = ncCommitDatastoreCandidate
193-
case ncCommitDatastoreRunning:
194-
case ncCommitDatastoreCandidate:
192+
s.NetconfOptions.CommitDatastore = NcCommitDatastoreCandidate
193+
case NcCommitDatastoreRunning:
194+
case NcCommitDatastoreCandidate:
195195
default:
196196
return fmt.Errorf("unknown commit-datastore: %s. Must be one of %s, %s",
197-
s.NetconfOptions.CommitDatastore, ncCommitDatastoreCandidate, ncCommitDatastoreRunning)
197+
s.NetconfOptions.CommitDatastore, NcCommitDatastoreCandidate, NcCommitDatastoreRunning)
198198
}
199199
case sbiGNMI:
200200
if s.GnmiOptions.Encoding == "" {

‎pkg/core/datastore.go‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ func targetFromSBI(s *config.SBI) api.Target {
129129
}
130130
if o := s.NetconfOptions; o != nil {
131131
commit := api.CommitCandidateCandidate
132-
if o.CommitDatastore == "running" {
132+
if o.CommitDatastore == config.NcCommitDatastoreRunning {
133133
commit = api.CommitCandidateRunning
134134
}
135135
t.ProtocolOptions.Netconf = &api.NetconfOptions{

‎pkg/datastore/target/netconf/nc.go‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@ func (t *ncTarget) Set(ctx context.Context, source types.TargetSource) (*sdcpb.S
165165
}
166166

167167
switch t.sbiConfig.NetconfOptions.CommitDatastore {
168-
case "running", "candidate":
168+
case config.NcCommitDatastoreRunning, config.NcCommitDatastoreCandidate:
169169
return t.setToDevice(ctx, t.sbiConfig.NetconfOptions.CommitDatastore, source)
170170
}
171171
// should not get here if the config validation happened.
@@ -274,7 +274,7 @@ func (t *ncTarget) setToDevice(ctx context.Context, commitDatastore string, sour
274274
}
275275

276276
// candidate should discard on error
277-
if commitDatastore == "candidate" {
277+
if commitDatastore == config.NcCommitDatastoreCandidate {
278278
err2 := t.driver.Discard()
279279
if err2 != nil {
280280
// log failed discard
@@ -289,7 +289,7 @@ func (t *ncTarget) setToDevice(ctx context.Context, commitDatastore string, sour
289289
}
290290

291291
// candidate stores need to commit the changes to running
292-
if commitDatastore == "candidate" {
292+
if commitDatastore == config.NcCommitDatastoreCandidate {
293293
log.Info("committing changes on target")
294294
// commit the config
295295
err = t.driver.Commit()

‎pkg/server/datastore.go‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -108,11 +108,11 @@ func (s *Server) CreateDataStore(ctx context.Context, req *sdcpb.CreateDataStore
108108
switch strings.ToLower(reqTarget.GetType()) {
109109
case "netconf":
110110
netconfOpts := reqTarget.GetNetconfOpts()
111-
commitDatastore := "candidate"
111+
commitDatastore := config.NcCommitDatastoreCandidate
112112
switch netconfOpts.GetCommitCandidate() {
113113
case sdcpb.CommitCandidate_COMMIT_CANDIDATE:
114114
case sdcpb.CommitCandidate_COMMIT_RUNNING:
115-
commitDatastore = "running"
115+
commitDatastore = config.NcCommitDatastoreRunning
116116
default:
117117
log.Error(nil, "unknown commitDatastore", "datastore", netconfOpts.GetCommitCandidate())
118118
return nil, fmt.Errorf("unknown commitDatastore: %v", netconfOpts.GetCommitCandidate())

0 commit comments

Comments
 (0)