Skip to content

Commit

Permalink
Use network backing info for debug network (vmware#1181)
Browse files Browse the repository at this point in the history
* Remove network argument to portlayer

This removes the network argument from the portlayer. It is replaced with
direct access to the extraconfig data. This is specifically to add a debug
network to support our debug NIC. It should be removed anyway eventually,
however the other arguments also need this migration so it was a useful
testbed.

* Update vm test to use generated VM name

One of our tests was using deadbeef for a VM name that gets created on a
datastore. That's caused issues with concurrent testing so is updated to
use the UUID of the guest running the test.
Will likely error if the runner isn't a VM.

Fixes: 1180
  • Loading branch information
hickeng committed Jun 23, 2016
1 parent a5df76a commit c27db78
Show file tree
Hide file tree
Showing 13 changed files with 56 additions and 22 deletions.
1 change: 1 addition & 0 deletions .gitignore
@@ -1,4 +1,5 @@
.vagrant/
.vscode/
.cover/
bin/
binary/
Expand Down
1 change: 0 additions & 1 deletion lib/apiservers/portlayer/restapi/configure_port_layer.go
Expand Up @@ -75,7 +75,6 @@ func configureAPI(api *operations.PortLayerAPI) http.Handler {
ClusterPath: options.PortLayerOptions.ClusterPath,
PoolPath: options.PortLayerOptions.PoolPath,
DatastorePath: options.PortLayerOptions.DatastorePath,
NetworkPath: options.PortLayerOptions.NetworkPath,
}

sess, err := session.NewSession(sessionconfig).Create(ctx)
Expand Down
Expand Up @@ -62,7 +62,6 @@ func (i *InteractionHandlersImpl) Configure(api *operations.PortLayerAPI, _ *Han
ClusterPath: options.PortLayerOptions.ClusterPath,
PoolPath: options.PortLayerOptions.PoolPath,
DatastorePath: options.PortLayerOptions.DatastorePath,
NetworkPath: options.PortLayerOptions.NetworkPath,
}

interactionSession, err = session.NewSession(sessionconfig).Create(ctx)
Expand Down
Expand Up @@ -57,7 +57,6 @@ func (handler *StorageHandlersImpl) Configure(api *operations.PortLayerAPI, hand
ClusterPath: options.PortLayerOptions.ClusterPath,
PoolPath: options.PortLayerOptions.PoolPath,
DatastorePath: options.PortLayerOptions.DatastorePath,
NetworkPath: options.PortLayerOptions.NetworkPath,
}

storageSession, err = session.NewSession(sessionconfig).Create(ctx)
Expand Down
1 change: 0 additions & 1 deletion lib/apiservers/portlayer/restapi/options/options.go
Expand Up @@ -27,7 +27,6 @@ type PortLayerOptionsType struct {
ClusterPath string `long:"cluster" default:"" description:"Cluster path" env:"CS_PATH" required:"true"`
PoolPath string `long:"pool" default:"" description:"Resource pool path" env:"POOL_PATH" required:"true"`
DatastorePath string `long:"datastore" default:"/ha-datacenter/datastore/*" description:"Datastore path" env:"DS_PATH" required:"true"`
NetworkPath string `long:"network" default:"/ha-datacenter/network/*" description:"Network path" env:"NET_PATH" required:"true"`

VCHName string `long:"vch" default:"" description:"VCH name" env:"VCH_NAME" required:"true"`

Expand Down
3 changes: 0 additions & 3 deletions lib/install/management/appliance.go
Expand Up @@ -17,7 +17,6 @@ package management
import (
"fmt"
"strconv"
"strings"
"time"

log "github.com/Sirupsen/logrus"
Expand Down Expand Up @@ -416,7 +415,6 @@ func (d *Dispatcher) createAppliance(conf *metadata.VirtualContainerHostConfigSp
},
)

netname := strings.Split(conf.Networks["client"].Network.ID, "-")[1]
conf.AddComponent("port-layer", &metadata.SessionConfig{
Cmd: metadata.Cmd{
Path: "/sbin/port-layer-server",
Expand All @@ -431,7 +429,6 @@ func (d *Dispatcher) createAppliance(conf *metadata.VirtualContainerHostConfigSp
"--cluster=" + settings.ClusterPath,
"--pool=" + settings.ResourcePoolPath,
"--datastore=" + conf.ImageStores[0].Host,
"--network=" + fmt.Sprintf("/%s/network/%s", settings.DatacenterName, netname),
"--vch=" + conf.ExecutorConfig.Name,
},
},
Expand Down
4 changes: 4 additions & 0 deletions lib/portlayer/exec/config.go
Expand Up @@ -46,4 +46,8 @@ type Configuration struct {

// Allow custom naming convention for containerVMs
ContainerNameConvention string

// FIXME: temporary work around for injecting network path of debug nic
Networks map[string]*metadata.NetworkEndpoint `vic:"0.1" scope:"read-only" key:"init/networks"`
DebugNetwork object.NetworkReference
}
11 changes: 9 additions & 2 deletions lib/portlayer/exec/handle.go
Expand Up @@ -17,9 +17,9 @@ package exec
import (
"crypto/rand"
"encoding/hex"
"errors"
"fmt"
"net"
"strings"
"sync"
"time"

Expand Down Expand Up @@ -196,6 +196,13 @@ func (h *Handle) Create(ctx context.Context, sess *session.Session, config *Cont

URI := fmt.Sprintf("tcp://%s:%d", ips[0], serialOverLANPort)

//FIXME: remove debug network
backing, err := Config.DebugNetwork.EthernetCardBackingInfo(ctx)
if err != nil {
detail := fmt.Sprintf("unable to generate backing info for debug network - this code can be removed once network mapping/dhcp client are available: %s", err)
log.Error(detail)
return errors.New(detail)
}
specconfig := &spec.VirtualMachineConfigSpecConfig{
// FIXME: hardcoded values
NumCPUs: 2,
Expand All @@ -211,7 +218,7 @@ func (h *Handle) Create(ctx context.Context, sess *session.Session, config *Cont
// FIXME: hardcoded value
BootMediaPath: sess.Datastore.Path(fmt.Sprintf("%s/bootstrap.iso", config.VCHName)),
VMPathName: fmt.Sprintf("[%s]", sess.Datastore.Name()),
NetworkName: strings.Split(sess.Network.Reference().Value, "-")[1],
DebugNetwork: backing,

ImageStoreName: config.ImageStoreName,

Expand Down
16 changes: 16 additions & 0 deletions lib/portlayer/portlayer.go
Expand Up @@ -59,6 +59,22 @@ func Init(ctx context.Context, sess *session.Session) error {
return err
}
exec.Config.ResourcePool = r.(*object.ResourcePool)
//FIXME: temporary injection of debug network for debug nic
ne := exec.Config.Networks["client"]
if ne == nil {
detail := fmt.Sprintf("could not get client network reference for debug nic - this code can be removed once network mapping/dhcp client is present")
log.Errorf(detail)
return err
}
nr := new(types.ManagedObjectReference)
nr.FromString(ne.Network.ID)
r, err = f.ObjectReference(ctx, *nr)
if err != nil {
detail := fmt.Sprintf("could not get client network reference from %s: %s", nr.String(), err)
log.Errorf(detail)
return err
}
exec.Config.DebugNetwork = r.(object.NetworkReference)

extraconfig.Decode(source, &network.Config)
log.Debugf("Decoded VCH config for network: %#v", network.Config)
Expand Down
6 changes: 1 addition & 5 deletions lib/spec/network.go
Expand Up @@ -62,11 +62,7 @@ func NewVirtualE1000() *types.VirtualE1000 {
func (s *VirtualMachineConfigSpec) addVirtualNIC(device types.BaseVirtualDevice) *VirtualMachineConfigSpec {
device.GetVirtualDevice().Key = s.generateNextKey()

device.GetVirtualDevice().Backing = &types.VirtualEthernetCardNetworkBackingInfo{
VirtualDeviceDeviceBackingInfo: types.VirtualDeviceDeviceBackingInfo{
DeviceName: s.NetworkName(),
},
}
device.GetVirtualDevice().Backing = s.DebugNetwork()
return s.AddVirtualDevice(device)
}

Expand Down
8 changes: 4 additions & 4 deletions lib/spec/spec.go
Expand Up @@ -63,8 +63,8 @@ type VirtualMachineConfigSpecConfig struct {
// URI of the network serial port
ConnectorURI string

// Name of the network
NetworkName string
// Network backing info
DebugNetwork types.BaseVirtualDeviceBackingInfo

// Name of the image store
ImageStoreName string
Expand Down Expand Up @@ -231,10 +231,10 @@ func (s *VirtualMachineConfigSpec) VMPathName() string {
}

// NetworkName returns the network name
func (s *VirtualMachineConfigSpec) NetworkName() string {
func (s *VirtualMachineConfigSpec) DebugNetwork() types.BaseVirtualDeviceBackingInfo {
defer trace.End(trace.Begin(s.config.ID))

return s.config.NetworkName
return s.config.DebugNetwork
}

// ConnectorURI returns the connector URI
Expand Down
18 changes: 15 additions & 3 deletions pkg/vsphere/test/test.go
Expand Up @@ -17,11 +17,12 @@ package test
import (
"fmt"
"math/rand"
"strings"
"testing"
"time"

log "github.com/Sirupsen/logrus"
"github.com/vmware/govmomi/object"
"github.com/vmware/vic/lib/guest"
"github.com/vmware/vic/lib/spec"
"github.com/vmware/vic/pkg/vsphere/session"
"github.com/vmware/vic/pkg/vsphere/test/env"
Expand Down Expand Up @@ -52,18 +53,29 @@ func Session(ctx context.Context, t *testing.T) *session.Session {

// SpecConfig returns a spec.VirtualMachineConfigSpecConfig struct
func SpecConfig(session *session.Session) *spec.VirtualMachineConfigSpecConfig {
backing, err := session.Network.EthernetCardBackingInfo(context.TODO())
if err != nil {
log.Errorf("unable to get backing info for test network: %s", err)
return nil
}

uuid, err := guest.UUID()
if err != nil {
log.Errorf("unable to get UUID for guest - used for VM name: %s", err)
return nil
}
return &spec.VirtualMachineConfigSpecConfig{
NumCPUs: 2,
MemoryMB: 2048,
VMForkEnabled: true,

ConnectorURI: "tcp://1.2.3.4:9876",

ID: "deadbeef",
ID: uuid,
Name: "zombie_attack",
BootMediaPath: session.Datastore.Path("brainz.iso"),
VMPathName: fmt.Sprintf("[%s]", session.Datastore.Name()),
NetworkName: strings.Split(session.Network.Reference().Value, "-")[1],
DebugNetwork: backing,
}
}

Expand Down
7 changes: 6 additions & 1 deletion pkg/vsphere/vm/vm_test.go
Expand Up @@ -140,10 +140,15 @@ func TestVMAttributes(t *testing.T) {
// Wrap the result with our version of VirtualMachine
vm := NewVirtualMachine(ctx, session, *moref)

uuid, err := guest.UUID()
if err != nil {
t.Fatalf("unable to get UUID for guest - used for VM name: %s", err)
}

if folder, err := vm.FolderName(ctx); err != nil {
t.Fatalf("ERROR: %s", err)
} else {
assert.Equal(t, "deadbeef", folder)
assert.Equal(t, uuid, folder)
}

_, err = tasks.WaitForResult(ctx, func(ctx context.Context) (tasks.ResultWaiter, error) {
Expand Down

0 comments on commit c27db78

Please sign in to comment.