Skip to content
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

feat(rdma): add e2e agent capability to enable and disable network interface #85

Merged
merged 1 commit into from
Oct 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 52 additions & 0 deletions common/e2e_agent/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,10 @@ type Rdma struct {
InterfaceName string `json:"interfaceName"`
}

type NetworkInterface struct {
NetworkInterface string `json:"networkInterface"`
}

func sendRequest(reqType, url string, data interface{}) error {
_, err := sendRequestGetResponse(reqType, url, data, true)
return err
Expand Down Expand Up @@ -1219,3 +1223,51 @@ func DeleteRdmaDevice(serverAddr string, deeviceName string) (string, error) {
logf.Log.Info("DeleteRdmaDevice succeeded", "output", out)
return out, err
}

// EnableNetworkInterface enable network interface
func EnableNetworkInterface(serverAddr string, interfaceName string) (string, error) {
data := NetworkInterface{
NetworkInterface: interfaceName,
}
logf.Log.Info("Executing EnableNetworkInterface", "addr", serverAddr, "data", data)
url := "http://" + getAgentAddress(serverAddr) + "/enablenetworkinterface"
encodedresult, err := sendRequestGetResponse("POST", url, data, false)
if err != nil {
logf.Log.Info("sendRequestGetResponse", "encodedresult", encodedresult, "error", err.Error())
return encodedresult, err
}
out, e2eagenterrcode, err := UnwrapResult(encodedresult)
if err != nil {
logf.Log.Info("unwrap failed", "encodedresult", encodedresult, "error", err.Error())
return encodedresult, err
}
if e2eagenterrcode != ErrNone {
return out, fmt.Errorf("failed to enable network interface, errcode %d", e2eagenterrcode)
}
logf.Log.Info("EnableNetworkInterface succeeded", "output", out)
return out, err
}

// DisableNetworkInterface disable network interface
func DisableNetworkInterface(serverAddr string, interfaceName string) (string, error) {
data := NetworkInterface{
NetworkInterface: interfaceName,
}
logf.Log.Info("Executing DisableNetworkInterface", "addr", serverAddr, "data", data)
url := "http://" + getAgentAddress(serverAddr) + "/disablenetworkinterface"
encodedresult, err := sendRequestGetResponse("POST", url, data, false)
if err != nil {
logf.Log.Info("sendRequestGetResponse", "encodedresult", encodedresult, "error", err.Error())
return encodedresult, err
}
out, e2eagenterrcode, err := UnwrapResult(encodedresult)
if err != nil {
logf.Log.Info("unwrap failed", "encodedresult", encodedresult, "error", err.Error())
return encodedresult, err
}
if e2eagenterrcode != ErrNone {
return out, fmt.Errorf("failed to disable network interface, errcode %d", e2eagenterrcode)
}
logf.Log.Info("DeleteRdmaDevice succeeded", "output", out)
return out, err
}
36 changes: 36 additions & 0 deletions common/k8stest/util_node.go
Original file line number Diff line number Diff line change
Expand Up @@ -493,3 +493,39 @@ func CheckCsiNodeTopologyKeysPresent(nodeName string, driverName string, key []s
}
return true, nil
}

// enable network interface on node
func EnableNetworkInterfaceOnNode(node string) error {
nodeIp, err := GetNodeIPAddress(node)
if err != nil {
return fmt.Errorf("failed to get node %s ip, error: %v", node, err)
}

// get interface name
iface := e2e_config.GetConfig().NetworkInterface
// enable network interface
out, err := e2e_agent.EnableNetworkInterface(*nodeIp, iface)
if err != nil {
return err
}
logf.Log.Info("Enable network interface", "node", node, "output", out, "interface", iface)
return nil
}

// disable network interface on node
func DisableNetworkInterfaceOnNode(node string) error {
nodeIp, err := GetNodeIPAddress(node)
if err != nil {
return fmt.Errorf("failed to get node %s ip, error: %v", node, err)
}

// get interface name
iface := e2e_config.GetConfig().NetworkInterface
// enable network interface
out, err := e2e_agent.DisableNetworkInterface(*nodeIp, iface)
if err != nil {
return err
}
logf.Log.Info("Disable network interface", "node", node, "output", out, "interface", iface)
return nil
}
2 changes: 1 addition & 1 deletion tools/e2e-agent/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
# as long as we do not make breaking changes.
set -e
IMAGE="openebs/e2e-agent"
TAG="v3.0.5"
TAG="v3.0.6"
registry=""
tag_as_latest=""

Expand Down
2 changes: 1 addition & 1 deletion tools/e2e-agent/e2e-agent.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ spec:
securityContext:
privileged: true
allowPrivilegeEscalation: true
image: openebs/e2e-agent:v3.0.5
image: openebs/e2e-agent:v3.0.6
imagePullPolicy: Always
volumeMounts:
- name: host-root
Expand Down
67 changes: 67 additions & 0 deletions tools/e2e-agent/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,10 @@ type CmpPaths struct {
Path2 string `json:"path2"`
}

type NetworkInterface struct {
NetworkInterface string `json:"networkInterface"`
}

func homePage(w http.ResponseWriter, r *http.Request) {
fmt.Fprint(w, "Welcome home!\n")
}
Expand Down Expand Up @@ -180,6 +184,8 @@ func handleRequests() {
router.HandleFunc("/listrdmadevice", ListRdmaDevice).Methods("POST")
router.HandleFunc("/createrdmadevice", CreateRdmaDevice).Methods("POST")
router.HandleFunc("/deleterdmadevice", DeleteRdmaDevice).Methods("POST")
router.HandleFunc("/enablenetworkinterface", EnableNetworkInterface).Methods("POST")
router.HandleFunc("/disablenetworkinterface", DisableNetworkInterface).Methods("POST")
log.Fatal(http.ListenAndServe(podIP+":"+restPort, router))
}

Expand Down Expand Up @@ -1188,3 +1194,64 @@ func Cmp(w http.ResponseWriter, r *http.Request) {
klog.Info(string(output))
WrapResult(b64out, errCode, w)
}

// EnableNetworkInterface enable network interface
func EnableNetworkInterface(w http.ResponseWriter, r *http.Request) {
var msg string
var iface NetworkInterface
d := json.NewDecoder(r.Body)
if err := d.Decode(&iface); err != nil {
msg = fmt.Sprintf("failed to read JSON encoded data, Error: %s", err.Error())
klog.Error(msg)
WrapResult(msg, ErrJsonDecode, w)
return
}

if iface.NetworkInterface == "" {
msg = "no network interface name passed"
klog.Error(msg)
WrapResult(msg, UnprocessableEntityErrorCode, w)
return
}
klog.Info("enable network interface, data: %v", iface)

iFaceUpCommand := fmt.Sprintf("ifconfig %s up", iface.NetworkInterface)
output, err := bashLocal(iFaceUpCommand)
if err != nil {
msg = fmt.Sprintf("cannot enable network interface, Error %s", err.Error())
klog.Error(msg)
WrapResult(msg, ErrExecFailed, w)
return
}
WrapResult(string(output), ErrNone, w)
}

// DisableNetworkInterface disable network interface
func DisableNetworkInterface(w http.ResponseWriter, r *http.Request) {
var msg string
var iface NetworkInterface
d := json.NewDecoder(r.Body)
if err := d.Decode(&iface); err != nil {
msg = fmt.Sprintf("failed to read JSON encoded data, Error: %s", err.Error())
klog.Error(msg)
WrapResult(msg, ErrJsonDecode, w)
return
}
if iface.NetworkInterface == "" {
msg = "no interface name passed"
klog.Error(msg)
WrapResult(msg, UnprocessableEntityErrorCode, w)
return
}
klog.Info("disable network interface, data: %v", iface)

iFaceDownCommand := fmt.Sprintf("ifconfig %s down", iface.NetworkInterface)
output, err := bashLocal(iFaceDownCommand)
if err != nil {
msg = fmt.Sprintf("cannot disable network interface, Error %s", err.Error())
klog.Error(msg)
WrapResult(msg, ErrExecFailed, w)
return
}
WrapResult(string(output), ErrNone, w)
}