Skip to content
Snippets Groups Projects
Commit 2b9b4369 authored by Manuel Kieweg's avatar Manuel Kieweg
Browse files

Merge branch 99-commit-confirm-mechanic-for-ond-changes with...

Merge branch 99-commit-confirm-mechanic-for-ond-changes with refs/heads/develop into refs/merge-requests/147/train
parents 5e53f43f 78e57d25
No related branches found
No related tags found
No related merge requests found
Pipeline #69000 passed with warnings
...@@ -27,22 +27,23 @@ integration-test: ...@@ -27,22 +27,23 @@ integration-test:
allow_failure: true allow_failure: true
variables: variables:
GOSDN_LOG: "nolog" GOSDN_LOG: "nolog"
GOSDN_CHANGE_TIMEOUT: "100ms"
rules: rules:
- if: $CI_PIPELINE_SOURCE == "merge_request_event" && $CI_MERGE_REQUEST_TARGET_BRANCH_NAME == $CI_DEFAULT_BRANCH - if: $CI_PIPELINE_SOURCE == "merge_request_event" && $CI_MERGE_REQUEST_TARGET_BRANCH_NAME == $CI_DEFAULT_BRANCH
- if: $CI_NIGHTLY - if: $CI_NIGHTLY
- if: $CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH - if: $CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH
- if: $CI_COMMIT_BRANCH != $CI_DEFAULT_BRANCH - if: $CI_COMMIT_BRANCH != $CI_DEFAULT_BRANCH
allow_failure: true allow_failure: true
after_script:
- go tool cover -func=coverage.out
unit-test: unit-test:
script: script:
- go test -short -race $(go list ./... | grep -v /forks/ | grep -v /api/ | grep -v /mocks ) -v -coverprofile=coverage.out - go test -short -race $(go list ./... | grep -v /forks/ | grep -v /api/ | grep -v /mocks ) -v -coverprofile=coverage.out
after_script:
- go tool cover -func=coverage.out
<<: *test <<: *test
http-api-test: controller-test:
script: script:
- cd ./nucleus - cd ./nucleus
- go test -race -v -run Test_httpApi -coverprofile=coverage.out - go test -race -v -run TestRun
<<: *test <<: *test
\ No newline at end of file
...@@ -3,11 +3,12 @@ package cli ...@@ -3,11 +3,12 @@ package cli
import ( import (
"errors" "errors"
"fmt" "fmt"
log "github.com/sirupsen/logrus"
"github.com/spf13/viper"
"io/ioutil" "io/ioutil"
"net/http" "net/http"
"strings" "strings"
log "github.com/sirupsen/logrus"
"github.com/spf13/viper"
) )
const apiRoot = "?" const apiRoot = "?"
...@@ -26,6 +27,7 @@ func HTTPGet(apiEndpoint, f string, args ...string) error { ...@@ -26,6 +27,7 @@ func HTTPGet(apiEndpoint, f string, args ...string) error {
} }
resp, err := http.Get(apiEndpoint + apiRoot + "q=" + f + builder.String()) resp, err := http.Get(apiEndpoint + apiRoot + "q=" + f + builder.String())
if err != nil { if err != nil {
log.Info(fmt.Sprintf("Err: %s", err))
return err return err
} }
builder.Reset() builder.Reset()
...@@ -38,8 +40,8 @@ func HTTPGet(apiEndpoint, f string, args ...string) error { ...@@ -38,8 +40,8 @@ func HTTPGet(apiEndpoint, f string, args ...string) error {
} }
switch f { switch f {
case "init": case "init":
pnd := string(bytes[:36]) pnd := string(bytes[9:45])
sbi := string(bytes[36:]) sbi := string(bytes[55:91])
viper.Set("CLI_PND", pnd) viper.Set("CLI_PND", pnd)
viper.Set("CLI_SBI", sbi) viper.Set("CLI_SBI", sbi)
err := viper.WriteConfig() err := viper.WriteConfig()
...@@ -49,6 +51,7 @@ func HTTPGet(apiEndpoint, f string, args ...string) error { ...@@ -49,6 +51,7 @@ func HTTPGet(apiEndpoint, f string, args ...string) error {
default: default:
fmt.Println(string(bytes)) fmt.Println(string(bytes))
} }
case http.StatusCreated: case http.StatusCreated:
defer resp.Body.Close() defer resp.Body.Close()
bytes, err := ioutil.ReadAll(resp.Body) bytes, err := ioutil.ReadAll(resp.Body)
...@@ -58,6 +61,8 @@ func HTTPGet(apiEndpoint, f string, args ...string) error { ...@@ -58,6 +61,8 @@ func HTTPGet(apiEndpoint, f string, args ...string) error {
uuid := string(bytes[19:55]) uuid := string(bytes[19:55])
viper.Set("LAST_DEVICE_UUID", uuid) viper.Set("LAST_DEVICE_UUID", uuid)
fmt.Println(string(bytes)) fmt.Println(string(bytes))
case http.StatusAccepted:
default: default:
log.WithFields(log.Fields{ log.WithFields(log.Fields{
"status code": resp.StatusCode, "status code": resp.StatusCode,
......
...@@ -3,10 +3,7 @@ package cli ...@@ -3,10 +3,7 @@ package cli
import ( import (
"code.fbi.h-da.de/cocsn/gosdn/forks/goarista/gnmi" "code.fbi.h-da.de/cocsn/gosdn/forks/goarista/gnmi"
"code.fbi.h-da.de/cocsn/gosdn/nucleus" "code.fbi.h-da.de/cocsn/gosdn/nucleus"
"code.fbi.h-da.de/cocsn/gosdn/nucleus/util/proto"
"context" "context"
pb "google.golang.org/protobuf/proto"
"os"
) )
// Set sends a gNMI Set request to the specified target. Only one // Set sends a gNMI Set request to the specified target. Only one
...@@ -23,28 +20,5 @@ func Set(a, u, p, typ string, args ...string) error { ...@@ -23,28 +20,5 @@ func Set(a, u, p, typ string, args ...string) error {
if err != nil { if err != nil {
return err return err
} }
return t.Set(context.Background(), args)
path := gnmi.SplitPath(args[0])
req := []interface{}{
&gnmi.Operation{
Type: typ,
Origin: "",
Target: "",
Path: path,
Val: args[1],
},
}
resp, err := t.Set(context.Background(), req...)
if err != nil {
return err
}
_, tap := os.LookupEnv("GOSDN_TAP")
if tap {
if err := proto.Write(resp.(pb.Message), "resp-set-system-config-hostname"); err != nil {
return err
}
}
return nil
} }
/*
Copyright © 2021 da/net research group <danet.fbi.h-da.de>
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice,
this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
3. Neither the name of the copyright holder nor the names of its contributors
may be used to endorse or promote products derived from this software
without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
POSSIBILITY OF SUCH DAMAGE.
*/
package cmd
import (
"github.com/spf13/cobra"
)
// changeCmd represents the change command
var changeCmd = &cobra.Command{
Use: "change",
Short: "manage changes of the specified pnd",
Long: `use "change list" or "change list-pending" to list changes
use "change commit" or "change confirm" respectively`,
}
func init() {
cliCmd.AddCommand(changeCmd)
}
...@@ -41,12 +41,14 @@ var cliSetCmd = &cobra.Command{ ...@@ -41,12 +41,14 @@ var cliSetCmd = &cobra.Command{
Use: "set", Use: "set",
Args: cobra.ExactArgs(2), Args: cobra.ExactArgs(2),
Short: "set a value on a device", Short: "set a value on a device",
Long: `Set a path value for a given device. Only one path and Long: `Update a path value for a given device. Only one path and
only one value supported for now`, only one value supported for now.
Use "set replace" or "set delete" respectively`,
RunE: func(cmd *cobra.Command, args []string) error { RunE: func(cmd *cobra.Command, args []string) error {
return cli.HTTPGet( return cli.HTTPGet(
apiEndpoint, apiEndpoint,
"set", "update",
"uuid="+uuid, "uuid="+uuid,
"cliSbi="+cliSbi, "cliSbi="+cliSbi,
"cliPnd="+cliPnd, "cliPnd="+cliPnd,
...@@ -60,5 +62,5 @@ only one value supported for now`, ...@@ -60,5 +62,5 @@ only one value supported for now`,
func init() { func init() {
cliCmd.AddCommand(cliSetCmd) cliCmd.AddCommand(cliSetCmd)
cliSetCmd.Flags().StringVar(&uuid, "uuid", "", "uuid of the requested device") cliSetCmd.PersistentFlags().StringVar(&uuid, "uuid", "", "uuid of the target device")
} }
/*
Copyright © 2021 da/net research group <danet.fbi.h-da.de>
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice,
this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
3. Neither the name of the copyright holder nor the names of its contributors
may be used to endorse or promote products derived from this software
without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
POSSIBILITY OF SUCH DAMAGE.
*/
package cmd
import (
"code.fbi.h-da.de/cocsn/gosdn/cli"
"github.com/spf13/cobra"
)
// commitCmd represents the commit command
var commitCmd = &cobra.Command{
Use: "commit",
Args: cobra.ExactArgs(1),
Short: "Commit the given change for the active PND",
Long: ``,
RunE: func(cmd *cobra.Command, args []string) error {
return cli.HTTPGet(
apiEndpoint,
"change-commit",
"pnd="+cliPnd,
"cuid="+args[0],
)
},
}
func init() {
changeCmd.AddCommand(commitCmd)
}
/*
Copyright © 2021 da/net research group <danet.fbi.h-da.de>
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice,
this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
3. Neither the name of the copyright holder nor the names of its contributors
may be used to endorse or promote products derived from this software
without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
POSSIBILITY OF SUCH DAMAGE.
*/
package cmd
import (
"code.fbi.h-da.de/cocsn/gosdn/cli"
"github.com/spf13/cobra"
)
// confirmCmd represents the confirm command
var confirmCmd = &cobra.Command{
Use: "confirm",
Args: cobra.ExactArgs(1),
Short: "Confirms the given change for the active PND",
Long: ``,
RunE: func(cmd *cobra.Command, args []string) error {
return cli.HTTPGet(
apiEndpoint,
"change-confirm",
"pnd="+cliPnd,
"cuid="+args[0],
)
},
}
func init() {
changeCmd.AddCommand(confirmCmd)
}
/*
Copyright © 2021 da/net research group <danet.fbi.h-da.de>
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice,
this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
3. Neither the name of the copyright holder nor the names of its contributors
may be used to endorse or promote products derived from this software
without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
POSSIBILITY OF SUCH DAMAGE.
*/
package cmd
import (
"code.fbi.h-da.de/cocsn/gosdn/cli"
"github.com/spf13/cobra"
)
// deleteCmd represents the delete command
var deleteCmd = &cobra.Command{
Use: "delete",
Args: cobra.ExactArgs(1),
Short: "set a value on a device",
Long: `Set a path value for a given device. Only one path and
only one value supported for now`,
RunE: func(cmd *cobra.Command, args []string) error {
return cli.HTTPGet(
apiEndpoint,
"delete",
"uuid="+uuid,
"cliSbi="+cliSbi,
"cliPnd="+cliPnd,
"path="+args[0],
"address="+address,
)
},
}
func init() {
cliSetCmd.AddCommand(deleteCmd)
// Here you will define your flags and configuration settings.
// Cobra supports Persistent Flags which will work for this command
// and all subcommands, e.g.:
// deleteCmd.PersistentFlags().String("foo", "", "A help for foo")
// Cobra supports local flags which will only run when this command
// is called directly, e.g.:
// deleteCmd.Flags().BoolP("toggle", "t", false, "Help message for toggle")
}
/*
Copyright © 2021 da/net research group <danet.fbi.h-da.de>
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice,
this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
3. Neither the name of the copyright holder nor the names of its contributors
may be used to endorse or promote products derived from this software
without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
POSSIBILITY OF SUCH DAMAGE.
*/
package cmd
import (
"code.fbi.h-da.de/cocsn/gosdn/cli"
"github.com/spf13/cobra"
)
// listCmd represents the list command
var listCmd = &cobra.Command{
Use: "list",
Short: "Lists all committed changes",
Long: ``,
RunE: func(cmd *cobra.Command, args []string) error {
return cli.HTTPGet(
apiEndpoint,
"change-list",
"pnd="+cliPnd,
)
},
}
func init() {
changeCmd.AddCommand(listCmd)
}
/*
Copyright © 2021 da/net research group <danet.fbi.h-da.de>
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice,
this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
3. Neither the name of the copyright holder nor the names of its contributors
may be used to endorse or promote products derived from this software
without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
POSSIBILITY OF SUCH DAMAGE.
*/
package cmd
import (
"code.fbi.h-da.de/cocsn/gosdn/cli"
"github.com/spf13/cobra"
)
// listPendingCmd represents the listPending command
var listPendingCmd = &cobra.Command{
Use: "listPending",
Short: "Lists all committed changes",
Long: ``,
RunE: func(cmd *cobra.Command, args []string) error {
return cli.HTTPGet(
apiEndpoint,
"change-list-pending",
"pnd="+cliPnd,
)
},
}
func init() {
changeCmd.AddCommand(listPendingCmd)
}
/*
Copyright © 2021 da/net research group <danet.fbi.h-da.de>
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice,
this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
3. Neither the name of the copyright holder nor the names of its contributors
may be used to endorse or promote products derived from this software
without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
POSSIBILITY OF SUCH DAMAGE.
*/
package cmd
import (
"code.fbi.h-da.de/cocsn/gosdn/cli"
"github.com/spf13/cobra"
)
// replaceCmd represents the replace command
var replaceCmd = &cobra.Command{
Use: "replace",
Args: cobra.ExactArgs(2),
Short: "set a value on a device",
Long: `Set a path value for a given device. Only one path and
only one value supported for now`,
RunE: func(cmd *cobra.Command, args []string) error {
return cli.HTTPGet(
apiEndpoint,
"replace",
"uuid="+uuid,
"cliSbi="+cliSbi,
"cliPnd="+cliPnd,
"path="+args[0],
"address="+address,
"value="+args[1],
)
},
}
func init() {
cliSetCmd.AddCommand(replaceCmd)
}
/*
Copyright © 2021 da/net research group <danet.fbi.h-da.de>
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice,
this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
3. Neither the name of the copyright holder nor the names of its contributors
may be used to endorse or promote products derived from this software
without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
POSSIBILITY OF SUCH DAMAGE.
*/
package cmd
import (
"code.fbi.h-da.de/cocsn/gosdn/cli"
"github.com/spf13/cobra"
)
// updateCmd represents the update command
var updateCmd = &cobra.Command{
Use: "update",
Args: cobra.ExactArgs(2),
Short: "update a value on a device",
Long: `Update a path value for a given device. Only one path and
only one value supported for now`,
RunE: func(cmd *cobra.Command, args []string) error {
return cli.HTTPGet(
apiEndpoint,
"update",
"uuid="+uuid,
"cliSbi="+cliSbi,
"cliPnd="+cliPnd,
"path="+args[0],
"address="+address,
"value="+args[1],
)
},
}
func init() {
cliSetCmd.AddCommand(updateCmd)
}
...@@ -118,7 +118,7 @@ func DialContext(ctx context.Context, cfg *Config) (pb.GNMIClient, error) { ...@@ -118,7 +118,7 @@ func DialContext(ctx context.Context, cfg *Config) (pb.GNMIClient, error) {
if cfg.TLS || cfg.CAFile != "" || cfg.CertFile != "" || cfg.Token != "" { if cfg.TLS || cfg.CAFile != "" || cfg.CertFile != "" || cfg.Token != "" {
tlsConfig := &tls.Config{ tlsConfig := &tls.Config{
MinVersion: tls.VersionTLS12, MinVersion: tls.VersionTLS12,
} }
if cfg.CAFile != "" { if cfg.CAFile != "" {
b, err := ioutil.ReadFile(cfg.CAFile) b, err := ioutil.ReadFile(cfg.CAFile)
......
...@@ -9,17 +9,17 @@ require ( ...@@ -9,17 +9,17 @@ require (
github.com/google/gnxi v0.0.0-20201221102247-c26672548161 github.com/google/gnxi v0.0.0-20201221102247-c26672548161
github.com/google/uuid v1.1.2 github.com/google/uuid v1.1.2
github.com/neo4j/neo4j-go-driver v1.8.3 github.com/neo4j/neo4j-go-driver v1.8.3
github.com/openconfig/gnmi v0.0.0-20200617225440-d2b4e6a45802 github.com/openconfig/gnmi v0.0.0-20210428141518-ae4d850000ab
github.com/openconfig/goyang v0.2.3 github.com/openconfig/goyang v0.2.4
github.com/openconfig/ygot v0.10.0 github.com/openconfig/ygot v0.10.5
github.com/sirupsen/logrus v1.7.0 github.com/sirupsen/logrus v1.8.1
github.com/spf13/cobra v1.1.1 github.com/spf13/cobra v1.1.3
github.com/spf13/viper v1.7.1 github.com/spf13/viper v1.7.1
github.com/stretchr/testify v1.6.1 github.com/stretchr/testify v1.7.0
golang.org/x/net v0.0.0-20201216054612-986b41b23924 golang.org/x/net v0.0.0-20210428140749-89ef3d95e781
google.golang.org/grpc v1.34.0 google.golang.org/grpc v1.37.0
google.golang.org/protobuf v1.26.0 google.golang.org/protobuf v1.26.0
k8s.io/api v0.20.5 k8s.io/api v0.21.0
k8s.io/apimachinery v0.20.5 k8s.io/apimachinery v0.21.0
k8s.io/client-go v0.20.5 k8s.io/client-go v0.21.0
) )
This diff is collapsed.
// Code generated by mockery v2.6.0. DO NOT EDIT. // Code generated by mockery 2.7.4. DO NOT EDIT.
package mocks package mocks
...@@ -6,6 +6,8 @@ import ( ...@@ -6,6 +6,8 @@ import (
mock "github.com/stretchr/testify/mock" mock "github.com/stretchr/testify/mock"
uuid "github.com/google/uuid" uuid "github.com/google/uuid"
ygot "github.com/openconfig/ygot/ygot"
) )
// PrincipalNetworkDomain is an autogenerated mock type for the PrincipalNetworkDomain type // PrincipalNetworkDomain is an autogenerated mock type for the PrincipalNetworkDomain type
...@@ -41,6 +43,71 @@ func (_m *PrincipalNetworkDomain) AddSbi(_a0 interface{}) error { ...@@ -41,6 +43,71 @@ func (_m *PrincipalNetworkDomain) AddSbi(_a0 interface{}) error {
return r0 return r0
} }
// ChangeOND provides a mock function with given fields: _a0, operation, path, value
func (_m *PrincipalNetworkDomain) ChangeOND(_a0 uuid.UUID, operation interface{}, path string, value ...string) error {
_va := make([]interface{}, len(value))
for _i := range value {
_va[_i] = value[_i]
}
var _ca []interface{}
_ca = append(_ca, _a0, operation, path)
_ca = append(_ca, _va...)
ret := _m.Called(_ca...)
var r0 error
if rf, ok := ret.Get(0).(func(uuid.UUID, interface{}, string, ...string) error); ok {
r0 = rf(_a0, operation, path, value...)
} else {
r0 = ret.Error(0)
}
return r0
}
// Commit provides a mock function with given fields: _a0
func (_m *PrincipalNetworkDomain) Commit(_a0 uuid.UUID) error {
ret := _m.Called(_a0)
var r0 error
if rf, ok := ret.Get(0).(func(uuid.UUID) error); ok {
r0 = rf(_a0)
} else {
r0 = ret.Error(0)
}
return r0
}
// Committed provides a mock function with given fields:
func (_m *PrincipalNetworkDomain) Committed() []uuid.UUID {
ret := _m.Called()
var r0 []uuid.UUID
if rf, ok := ret.Get(0).(func() []uuid.UUID); ok {
r0 = rf()
} else {
if ret.Get(0) != nil {
r0 = ret.Get(0).([]uuid.UUID)
}
}
return r0
}
// Confirm provides a mock function with given fields: _a0
func (_m *PrincipalNetworkDomain) Confirm(_a0 uuid.UUID) error {
ret := _m.Called(_a0)
var r0 error
if rf, ok := ret.Get(0).(func(uuid.UUID) error); ok {
r0 = rf(_a0)
} else {
r0 = ret.Error(0)
}
return r0
}
// ContainsDevice provides a mock function with given fields: _a0 // ContainsDevice provides a mock function with given fields: _a0
func (_m *PrincipalNetworkDomain) ContainsDevice(_a0 uuid.UUID) bool { func (_m *PrincipalNetworkDomain) ContainsDevice(_a0 uuid.UUID) bool {
ret := _m.Called(_a0) ret := _m.Called(_a0)
...@@ -69,6 +136,22 @@ func (_m *PrincipalNetworkDomain) Destroy() error { ...@@ -69,6 +136,22 @@ func (_m *PrincipalNetworkDomain) Destroy() error {
return r0 return r0
} }
// Devices provides a mock function with given fields:
func (_m *PrincipalNetworkDomain) Devices() []uuid.UUID {
ret := _m.Called()
var r0 []uuid.UUID
if rf, ok := ret.Get(0).(func() []uuid.UUID); ok {
r0 = rf()
} else {
if ret.Get(0) != nil {
r0 = ret.Get(0).([]uuid.UUID)
}
}
return r0
}
// GetDescription provides a mock function with given fields: // GetDescription provides a mock function with given fields:
func (_m *PrincipalNetworkDomain) GetDescription() string { func (_m *PrincipalNetworkDomain) GetDescription() string {
ret := _m.Called() ret := _m.Called()
...@@ -83,6 +166,29 @@ func (_m *PrincipalNetworkDomain) GetDescription() string { ...@@ -83,6 +166,29 @@ func (_m *PrincipalNetworkDomain) GetDescription() string {
return r0 return r0
} }
// GetDevice provides a mock function with given fields: _a0
func (_m *PrincipalNetworkDomain) GetDevice(_a0 uuid.UUID) (ygot.GoStruct, error) {
ret := _m.Called(_a0)
var r0 ygot.GoStruct
if rf, ok := ret.Get(0).(func(uuid.UUID) ygot.GoStruct); ok {
r0 = rf(_a0)
} else {
if ret.Get(0) != nil {
r0 = ret.Get(0).(ygot.GoStruct)
}
}
var r1 error
if rf, ok := ret.Get(1).(func(uuid.UUID) error); ok {
r1 = rf(_a0)
} else {
r1 = ret.Error(1)
}
return r0, r1
}
// GetName provides a mock function with given fields: // GetName provides a mock function with given fields:
func (_m *PrincipalNetworkDomain) GetName() string { func (_m *PrincipalNetworkDomain) GetName() string {
ret := _m.Called() ret := _m.Called()
...@@ -113,7 +219,7 @@ func (_m *PrincipalNetworkDomain) GetSBIs() interface{} { ...@@ -113,7 +219,7 @@ func (_m *PrincipalNetworkDomain) GetSBIs() interface{} {
return r0 return r0
} }
// Id provides a mock function with given fields: // ID provides a mock function with given fields:
func (_m *PrincipalNetworkDomain) ID() uuid.UUID { func (_m *PrincipalNetworkDomain) ID() uuid.UUID {
ret := _m.Called() ret := _m.Called()
...@@ -150,6 +256,22 @@ func (_m *PrincipalNetworkDomain) MarshalDevice(_a0 uuid.UUID) (string, error) { ...@@ -150,6 +256,22 @@ func (_m *PrincipalNetworkDomain) MarshalDevice(_a0 uuid.UUID) (string, error) {
return r0, r1 return r0, r1
} }
// Pending provides a mock function with given fields:
func (_m *PrincipalNetworkDomain) Pending() []uuid.UUID {
ret := _m.Called()
var r0 []uuid.UUID
if rf, ok := ret.Get(0).(func() []uuid.UUID); ok {
r0 = rf()
} else {
if ret.Get(0) != nil {
r0 = ret.Get(0).([]uuid.UUID)
}
}
return r0
}
// RemoveDevice provides a mock function with given fields: _a0 // RemoveDevice provides a mock function with given fields: _a0
func (_m *PrincipalNetworkDomain) RemoveDevice(_a0 uuid.UUID) error { func (_m *PrincipalNetworkDomain) RemoveDevice(_a0 uuid.UUID) error {
ret := _m.Called(_a0) ret := _m.Called(_a0)
......
// Code generated by mockery v2.6.0. DO NOT EDIT. // Code generated by mockery 2.7.4. DO NOT EDIT.
package mocks package mocks
...@@ -18,7 +18,7 @@ type SouthboundInterface struct { ...@@ -18,7 +18,7 @@ type SouthboundInterface struct {
mock.Mock mock.Mock
} }
// Id provides a mock function with given fields: // ID provides a mock function with given fields:
func (_m *SouthboundInterface) ID() uuid.UUID { func (_m *SouthboundInterface) ID() uuid.UUID {
ret := _m.Called() ret := _m.Called()
......
// Code generated by mockery v2.6.0. DO NOT EDIT. // Code generated by mockery 2.7.4. DO NOT EDIT.
package mocks package mocks
...@@ -13,7 +13,7 @@ type Storable struct { ...@@ -13,7 +13,7 @@ type Storable struct {
mock.Mock mock.Mock
} }
// Id provides a mock function with given fields: // ID provides a mock function with given fields:
func (_m *Storable) ID() uuid.UUID { func (_m *Storable) ID() uuid.UUID {
ret := _m.Called() ret := _m.Called()
......
// Code generated by mockery v2.6.0. DO NOT EDIT. // Code generated by mockery 2.7.4. DO NOT EDIT.
package mocks package mocks
...@@ -76,29 +76,20 @@ func (_m *Transport) ProcessResponse(resp interface{}, root interface{}, models ...@@ -76,29 +76,20 @@ func (_m *Transport) ProcessResponse(resp interface{}, root interface{}, models
} }
// Set provides a mock function with given fields: ctx, params // Set provides a mock function with given fields: ctx, params
func (_m *Transport) Set(ctx context.Context, params ...interface{}) (interface{}, error) { func (_m *Transport) Set(ctx context.Context, params ...interface{}) error {
var _ca []interface{} var _ca []interface{}
_ca = append(_ca, ctx) _ca = append(_ca, ctx)
_ca = append(_ca, params...) _ca = append(_ca, params...)
ret := _m.Called(_ca...) ret := _m.Called(_ca...)
var r0 interface{} var r0 error
if rf, ok := ret.Get(0).(func(context.Context, ...interface{}) interface{}); ok { if rf, ok := ret.Get(0).(func(context.Context, ...interface{}) error); ok {
r0 = rf(ctx, params...) r0 = rf(ctx, params...)
} else { } else {
if ret.Get(0) != nil { r0 = ret.Error(0)
r0 = ret.Get(0).(interface{})
}
}
var r1 error
if rf, ok := ret.Get(1).(func(context.Context, ...interface{}) error); ok {
r1 = rf(ctx, params...)
} else {
r1 = ret.Error(1)
} }
return r0, r1 return r0
} }
// Subscribe provides a mock function with given fields: ctx, params // Subscribe provides a mock function with given fields: ctx, params
......
// Code generated by mockery v2.6.0. DO NOT EDIT. // Code generated by mockery 2.7.4. DO NOT EDIT.
package mocks package mocks
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment