本文整理汇总了Golang中github.com/contiv/systemtests-utils.TestbedNode.RunCommandWithOutput方法的典型用法代码示例。如果您正苦于以下问题:Golang TestbedNode.RunCommandWithOutput方法的具体用法?Golang TestbedNode.RunCommandWithOutput怎么用?Golang TestbedNode.RunCommandWithOutput使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/contiv/systemtests-utils.TestbedNode
的用法示例。
在下文中一共展示了TestbedNode.RunCommandWithOutput方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: DumpNetpluginLogs
// DumpNetpluginLogs prints netplugin logs from the specified testbed node
func DumpNetpluginLogs(node stu.TestbedNode) {
cmdStr := fmt.Sprintf("sudo cat /tmp/netplugin.log")
output, err := node.RunCommandWithOutput(cmdStr)
if err == nil {
log.Debugf("logs on node %s: \n%s\n", node.GetName(), output)
}
}
示例2: StartClientWithEnvAndArgs
// StartClientWithEnvAndArgs starts a client container with specified env-variables.
// It expects ping to server container to succeed
func StartClientWithEnvAndArgs(t *testing.T, node stu.TestbedNode, contName, ipAddress string,
env, dockerArgs []string) {
cmdStr := "sudo %s docker run %s --name=" + contName +
" ubuntu /bin/bash -c \"ping -c5 " + ipAddress + "\""
cmdStr = fmt.Sprintf(cmdStr, strings.Join(env, " "),
strings.Join(dockerArgs, " "))
output, err := node.RunCommandWithOutput(cmdStr)
if err != nil {
OvsDumpInfo(node)
t.Fatalf("Error '%s' launching container '%s', Output: \n%s\n",
err, contName, output)
}
cmdStr = fmt.Sprintf("sudo docker logs %s", contName)
output, err = node.RunCommandWithOutput(cmdStr)
if err != nil {
t.Fatalf("Error '%s' fetching container '%s' logs, Output: \n%s\n",
err, contName, output)
}
//verify that the output indicates <100% loss (some loss is expected due to
// timing of interface creation and starting ping)
if strings.Contains(string(output), ", 100% packet loss,") {
OvsDumpInfo(node)
t.Fatalf("Ping test failed for container '%s', Output: \n%s\n",
contName, output)
}
}
示例3: GetIPAddress
// GetIPAddress returns IP-address information for specified endpoint
func GetIPAddress(t *testing.T, node stu.TestbedNode, ep, stateStore string) string {
cmdStr := "netdcli -oper get -construct endpoint " + ep + " 2>&1"
if stateStore != "" {
cmdStr = "netdcli -oper get -state-store " + stateStore + " -construct endpoint " + ep + " 2>&1"
}
output, err := node.RunCommandWithOutput(cmdStr)
if err != nil || string(output) == "" {
time.Sleep(2 * time.Second)
output, err = node.RunCommandWithOutput(cmdStr)
if err != nil || output == "" {
t.Fatalf("Error getting ip for ep %s. Error: %s, Cmdstr: %s, Output: \n%s\n",
err, ep, cmdStr, output)
}
}
output = strings.Trim(string(output), "[]")
epStruct := drivers.OvsOperEndpointState{}
if err := json.Unmarshal([]byte(output), &epStruct); err != nil {
t.Fatalf("Error getting ip for ep %s. Error: %s, Cmdstr: %s, Output: \n%s\n",
err, ep, cmdStr, output)
}
return epStruct.IPAddress
}
示例4: getContainerUUID
func getContainerUUID(node stu.TestbedNode, contName string) (string, error) {
cmdStr := "sudo docker inspect --format='{{.Id}}' " + contName
output, err := node.RunCommandWithOutput(cmdStr)
if err != nil {
output = ""
}
return strings.TrimSpace(output), err
}
示例5: StartServerWithEnvAndArgs
// StartServerWithEnvAndArgs starts a server container with specified env-variables
func StartServerWithEnvAndArgs(t *testing.T, node stu.TestbedNode, contName string,
env, dockerArgs []string) {
cmdStr := "sudo %s docker run -d %s --name=" + contName +
" ubuntu /bin/bash -c \"mkfifo foo && < foo\""
cmdStr = fmt.Sprintf(cmdStr, strings.Join(env, " "),
strings.Join(dockerArgs, " "))
output, err := node.RunCommandWithOutput(cmdStr)
if err != nil {
OvsDumpInfo(node)
t.Fatalf("Error '%s' launching container '%s', Output: \n%s\n",
err, contName, output)
}
}
示例6: NetworkStateExists
// NetworkStateExists tests if state for specified network exists
func NetworkStateExists(node stu.TestbedNode, network, stateStore string) error {
cmdStr := "netdcli -oper get -construct network " + network + " 2>&1"
if stateStore != "" {
cmdStr = "netdcli -state-store " + stateStore + "-oper get -construct network " + network + " 2>&1"
}
output, err := node.RunCommandWithOutput(cmdStr)
if err != nil {
return err
}
if string(output) == "" {
return core.Errorf("got null output")
}
return nil
}
示例7: StartClientFailureWithEnvAndArgs
// StartClientFailureWithEnvAndArgs starts a client container with specified env-variables.
// It expects ping to server container to failure
func StartClientFailureWithEnvAndArgs(t *testing.T, node stu.TestbedNode, contName, ipAddress string,
env, dockerArgs []string) {
cmdStr := "sudo %s docker run %s --name=" + contName +
" ubuntu /bin/bash -c \"ping -c5 " + ipAddress + "\""
cmdStr = fmt.Sprintf(cmdStr, strings.Join(env, " "),
strings.Join(dockerArgs, " "))
output, err := node.RunCommandWithOutput(cmdStr)
if err == nil {
t.Fatalf("Ping did not fail as expected, err '%s' container '%s', "+
"Output: \n%s\n", err, contName, output)
}
cmdStr = fmt.Sprintf("sudo docker logs %s", contName)
output, err = node.RunCommandWithOutput(cmdStr)
if err != nil || !strings.Contains(string(output), ", 100% packet loss,") {
t.Fatalf("Ping did not fail as expected, err '%s' container '%s', "+
"Output: \n%s\n", err, contName, output)
}
}
示例8: applyConfig
func applyConfig(t *testing.T, cfgType, jsonCfg string, node stu.TestbedNode, stateStore string) {
// replace newlines with space and "(quote) with \"(escaped quote) for
// echo to consume and produce desired json config
jsonCfg = getEchoCompatibleStr(jsonCfg)
cmdStr := fmt.Sprintf("echo \"%s\" > /tmp/netdcli.cfg", jsonCfg)
output, err := node.RunCommandWithOutput(cmdStr)
if err != nil {
t.Fatalf("Error '%s' creating config file\nCmd: %q\n Output : %s \n",
err, cmdStr, output)
}
cmdStr = "netdcli -" + cfgType + " /tmp/netdcli.cfg 2>&1"
if stateStore != "" {
cmdStr = "netdcli -state-store " + stateStore + " -" + cfgType + " /tmp/netdcli.cfg 2>&1"
}
output, err = node.RunCommandWithOutput(cmdStr)
if err != nil {
t.Fatalf("Failed to apply config. Error: %s\nCmd: %q\n Output : %s\n",
err, cmdStr, output)
}
}
示例9: OvsDumpInfo
// OvsDumpInfo dumps the ovs state on the specified testbed node
func OvsDumpInfo(node stu.TestbedNode) {
cmdStr := "sudo ovs-vsctl show"
output, _ := node.RunCommandWithOutput(cmdStr)
log.Debugf("ovs-vsctl on node %s: \n%s\n", node.GetName(), output)
}