Documentation
¶
Overview ¶
Package remotessh provides host connectivity in go for system/integration testing in a multi host environment. It supports two testbed environments viz. baremetal and vagrant
Use this library to do remote testing with baremetal or vagrant nodes.
For example, To setup a baremetal setup with a host node with ssh reachability '1.2.3.4' and port '22' for user 'foo', you can initialize the setup as:
hosts := []HostInfo{ { Name: "mynode", SSHAddr: "1.2.3.4", SSHPort: "22" User: "foo", PrivKey: "path/to/foo's/privkey/file", Env: []string{}, }, } tb := &Baremetal{} tb.Setup(hosts)
Or to auto connect to a vagrant based setup you can initialize the setup as:
tb := &Vagrant{} tb.Setup(false, "", 3) // 3 node cluster, do not run `vagrant up`.
Once you have your favorite setup initialized, this will select the "mynode" node and run "ls" on it.
out, err := tb.GetNode("mynode").RunCommandWithOutput("ls") if err != nil { // exit status != 0 panic(err) } fmt.Println(out) // already a string
If you want to walk nodes, you have a few options:
Sequentially:
for _, node := range tb.GetNodes() { node.RunCommand("something") }
In Parallel:
err := tb.IterateNodes(func (node remotessh.TestbedNode) error { return node.RunCommand("docker ps -aq | xargs docker rm") }) if err != nil { // one or more nodes failed panic(err) }
Copyright 2014 Cisco Systems Inc. All rights reserved.
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
Index ¶
- Variables
- type Baremetal
- func (b *Baremetal) GetNode(name string) TestbedNode
- func (b *Baremetal) GetNodes() []TestbedNode
- func (b *Baremetal) IterateNodes(fn func(TestbedNode) error) error
- func (b *Baremetal) SSHExecAllNodes(cmd string) error
- func (b *Baremetal) Setup(args ...interface{}) error
- func (b *Baremetal) Teardown()
- type HostInfo
- type SSHNode
- type TestCommand
- type Testbed
- type TestbedNode
- type Vagrant
- type VagrantCommand
Constants ¶
This section is empty.
Variables ¶
var MaxSSHRetries = 3
MaxSSHRetries is the number of times we'll retry SSH connection
var SSHRetryDelay = time.Second
SSHRetryDelay is the delay between SSH connection retries
Functions ¶
This section is empty.
Types ¶
type Baremetal ¶
type Baremetal struct {
// contains filtered or unexported fields
}
Baremetal implements a host based testbed
func (*Baremetal) GetNode ¶
func (b *Baremetal) GetNode(name string) TestbedNode
GetNode obtains a node by name. The name is the name of the host provided at the time of testbed Setup.
func (*Baremetal) GetNodes ¶
func (b *Baremetal) GetNodes() []TestbedNode
GetNodes returns the nodes in a baremetal setup, returned sequentially.
func (*Baremetal) IterateNodes ¶
func (b *Baremetal) IterateNodes(fn func(TestbedNode) error) error
IterateNodes walks each host and executes the function supplied. On error, it waits for all hosts to complete before returning the error, if any.
func (*Baremetal) SSHExecAllNodes ¶
SSHExecAllNodes will ssh into each host and run the specified command.
type HostInfo ¶
type HostInfo struct { Name string SSHAddr string SSHPort string User string PrivKeyFile string Env []string }
HostInfo contains host specific connectivity info for setting up testbed node
type SSHNode ¶
type SSHNode struct { Name string // contains filtered or unexported fields }
SSHNode implements a node with ssh connectivity in a testbed
func NewSSHNode ¶
func NewSSHNode(name, user string, env []string, sshAddr, sshPort, privKeyFile string) (*SSHNode, error)
NewSSHNode intializes a ssh-client based node in a testbed
func (*SSHNode) RunCommand ¶
RunCommand runs a shell command in a vagrant node and returns it's exit status
func (*SSHNode) RunCommandBackground ¶
RunCommandBackground runs a background command in a vagrant node.
type TestCommand ¶
TestCommand is a command that is run on a test node
func (*TestCommand) Run ¶
func (c *TestCommand) Run(cmd string, args ...string) error
Run runs a command and return it's exit status
func (*TestCommand) RunWithOutput ¶
func (c *TestCommand) RunWithOutput(cmd string, args ...string) ([]byte, error)
RunWithOutput runs a command and return it's exit status and output
type Testbed ¶
type Testbed interface { Setup(args ...interface{}) error Teardown() GetNodes() []TestbedNode GetNode(name string) TestbedNode IterateNodes(fn func(TestbedNode) error) error }
Testbed is a collection of test nodes
type TestbedNode ¶
type TestbedNode interface { RunCommand(cmd string) (err error) RunCommandWithOutput(cmd string) (output string, err error) RunCommandBackground(cmd string) (err error) GetName() string }
TestbedNode is a node under test
type Vagrant ¶
type Vagrant struct {
// contains filtered or unexported fields
}
Vagrant implements a vagrant based testbed
func (*Vagrant) GetNode ¶
func (v *Vagrant) GetNode(name string) TestbedNode
GetNode obtains a node by name. The name is the name of the VM provided at `config.vm.define` time in Vagrantfiles. It is *not* the hostname of the machine, which is `vagrant` for all VMs by default.
func (*Vagrant) GetNodes ¶
func (v *Vagrant) GetNodes() []TestbedNode
GetNodes returns the nodes in a vagrant setup, returned sequentially.
func (*Vagrant) IterateNodes ¶
func (v *Vagrant) IterateNodes(fn func(TestbedNode) error) error
IterateNodes walks each host and executes the function supplied. On error, it waits for all hosts to complete before returning the error, if any.
func (*Vagrant) SSHExecAllNodes ¶
SSHExecAllNodes will ssh into each host and run the specified command.
func (*Vagrant) Teardown ¶
func (v *Vagrant) Teardown()
Teardown cleans up a vagrant testbed. It performs `vagrant destroy -f` to tear down the environment. While this method can be useful, the notion of VMs that clean up after themselves (with an appropriate Makefile to control vm availability) will be considerably faster than a method that uses this in a suite teardown.
type VagrantCommand ¶
VagrantCommand is a command that is run on a vagrant node
func (*VagrantCommand) Run ¶
func (c *VagrantCommand) Run(cmd string, args ...string) error
Run runs a command and return its exit status
func (*VagrantCommand) RunWithOutput ¶
func (c *VagrantCommand) RunWithOutput(cmd string, args ...string) ([]byte, error)
RunWithOutput runs a command and return its exit status and output