Skip to content
This repository has been archived by the owner on Nov 9, 2020. It is now read-only.

Commit

Permalink
Addressed review comments
Browse files Browse the repository at this point in the history
  • Loading branch information
ashahi1 committed Jun 17, 2017
1 parent 6289773 commit 0602bc6
Show file tree
Hide file tree
Showing 8 changed files with 453 additions and 40 deletions.
13 changes: 11 additions & 2 deletions tests/constants/admincli/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,10 +56,10 @@ const (
GetAccessForVMgroup = vmdkopsAdmin + "vmgroup access ls --name "

// ListVMgroups list vm groups
ListVMgroups = vmdkopsAdmin + "vmgroup ls"
ListVMgroups = vmdkopsAdmin + "vmgroup ls "

// DefaultVMgroup referring name of default vmgroup
DefaultVMgroup = "_DEFAULT "
DefaultVMgroup = "_DEFAULT"

// VMHomeDatastore referring datastore where the docker host vm is created
VMHomeDatastore = "_VM_DS"
Expand All @@ -82,4 +82,13 @@ const (

// ReadWriteAccess read-write rights for the volume
ReadWriteAccess = "read-write"

// ListVmgroupVMs referring to vmdkops_admin vmgroups vm ls
ListVmgroupVMs = vmdkopsAdmin + "vmgroup vm ls --name="

// VMlist VM of the vmgroup
VMlist = " --vm-list="

// AddDatastoreToVMgroup adds datastore to vmgroup
AddDatastoreToVMgroup = vmdkopsAdmin + "vmgroup access add --name="
)
25 changes: 25 additions & 0 deletions tests/constants/properties/vmproperties.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
// Copyright 2017 VMware, 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.

// A home to hold test constants related to vm

package properties

const (
//PoweredOffState - vm powered-off
PoweredOffState = "poweredOff"

//PoweredOnState - vm powered-on
PoweredOnState = "poweredOn"
)
6 changes: 3 additions & 3 deletions tests/e2e/basic_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,13 @@
package e2e

import (
. "gopkg.in/check.v1"

admincliconst "github.com/vmware/docker-volume-vsphere/tests/constants/admincli"
"github.com/vmware/docker-volume-vsphere/tests/utils/admincli"
"github.com/vmware/docker-volume-vsphere/tests/utils/dockercli"
"github.com/vmware/docker-volume-vsphere/tests/utils/inputparams"
"github.com/vmware/docker-volume-vsphere/tests/utils/misc"
"github.com/vmware/docker-volume-vsphere/tests/utils/verification"
. "gopkg.in/check.v1"
)

type BasicTestSuite struct {
Expand Down Expand Up @@ -168,7 +168,7 @@ func (s *BasicTestSuite) TestVmGroupVolumeIsolation(c *C) {
c.Assert(accessible, Equals, true, Commentf("Volume %s is not available on [%s]", s.volName1, s.vm2))

const vmgroup = "T1"
out, err = admincli.CreateVMgroup(s.esx, vmgroup, s.vm1Name)
out, err = admincli.CreateVMgroup(s.esx, vmgroup, s.vm1Name, admincliconst.VMHomeDatastore)
c.Assert(err, IsNil, Commentf(out))

accessible = verification.CheckVolumeAvailability(s.vm1, s.volName1)
Expand Down
125 changes: 103 additions & 22 deletions tests/e2e/defaultvmgroup_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,34 +21,42 @@ package e2e

import (
"log"
"os"
"strings"

con "github.com/vmware/docker-volume-vsphere/tests/constants/admincli"
admincliconst "github.com/vmware/docker-volume-vsphere/tests/constants/admincli"
dockerconst "github.com/vmware/docker-volume-vsphere/tests/constants/dockercli"
"github.com/vmware/docker-volume-vsphere/tests/utils/admincli"
"github.com/vmware/docker-volume-vsphere/tests/utils/esx"
"github.com/vmware/docker-volume-vsphere/tests/utils/dockercli"
"github.com/vmware/docker-volume-vsphere/tests/utils/inputparams"
"github.com/vmware/docker-volume-vsphere/tests/utils/misc"
"github.com/vmware/docker-volume-vsphere/tests/utils/ssh"
"github.com/vmware/docker-volume-vsphere/tests/utils/verification"
. "gopkg.in/check.v1"
)

const (
ErrorMsg = "This feature is not supported for vmgroup _DEFAULT."
vgErrorMsg = "This feature is not supported for vmgroup _DEFAULT."
NotAvailable = "N/A"
defaultVG = "defaultVGTest"
)

type DefaultVMGroupTestSuite struct {
esxIP string
hostName string
config *inputparams.TestConfig
volumeNames []string
}

func (s *DefaultVMGroupTestSuite) SetUpSuite(c *C) {
s.hostName = esx.RetrieveVMNameFromIP(os.Getenv("VM2"))
s.esxIP = inputparams.GetEsxIP()
out, err := admincli.ConfigInit(s.esxIP)
s.config = inputparams.GetTestConfig()
if s.config == nil {
c.Skip("Unable to retrieve test config, skipping vmgroupbasic tests.")
}
out, err := admincli.ConfigInit(s.config.EsxHost)
c.Assert(err, IsNil, Commentf(out))
s.volumeNames = []string{inputparams.GetUniqueVolumeName(defaultVG), inputparams.GetUniqueVolumeName(defaultVG)}
}

func (s *DefaultVMGroupTestSuite) TearDownSuite(c *C) {
out, err := admincli.ConfigRemove(s.esxIP)
out, err := admincli.ConfigRemove(s.config.EsxHost)
c.Assert(err, IsNil, Commentf(out))
}

Expand All @@ -57,38 +65,111 @@ var _ = Suite(&DefaultVMGroupTestSuite{})
// Test step:
// Add a vm to the _DEFAULT Vmgroup
func (s *DefaultVMGroupTestSuite) TestAddVMToDefaultTenant(c *C) {
log.Printf("START: defaultvmgroup.TestAddVMToDefaultTenant")
misc.LogTestStart(c.TestName())

out, err := admincli.AddVMToVMgroup(s.esxIP, con.DefaultVMgroup, s.hostName)
out, err := admincli.AddVMToVMgroup(s.config.EsxHost, admincliconst.DefaultVMgroup, s.config.DockerHostNames[1])
c.Assert(err, IsNil, Commentf(out))
c.Assert(strings.TrimRight(string(out), "\n"), Equals, ErrorMsg, Commentf("Unexpected Behavior: "+
c.Assert(strings.TrimRight(string(out), "\n"), Equals, vgErrorMsg, Commentf("Unexpected Behavior: "+
"We are able to add vm to the _DEFAULT tenant which is NOT allowed as per current spec."))

log.Printf("END: defaultvmgroup.TestAddVMToDefaultTenant")
misc.LogTestEnd(c.TestName())
}

// Test step:
// Remove a vm from the _DEFAULT Vmgroup
func (s *DefaultVMGroupTestSuite) TestRemoveDefaultTenantVMs(c *C) {
log.Printf("START: defaultvmgroup.TestRemoveDefaultTenantVMs")
misc.LogTestStart(c.TestName())

out, err := admincli.RemoveVMFromVMgroup(s.esxIP, con.DefaultVMgroup, s.hostName)
out, err := admincli.RemoveVMFromVMgroup(s.config.EsxHost, admincliconst.DefaultVMgroup, s.config.DockerHostNames[1])
c.Assert(err, IsNil, Commentf(out))
c.Assert(strings.TrimRight(string(out), "\n"), Equals, ErrorMsg, Commentf("Unexpected Behavior: "+
c.Assert(strings.TrimRight(string(out), "\n"), Equals, vgErrorMsg, Commentf("Unexpected Behavior: "+
"We are able to remove vm from the _DEFAULT tenant which is NOT allowed as per current spec."))

log.Printf("END: defaultvmgroup.TestRemoveDefaultTenantVMs")
misc.LogTestEnd(c.TestName())
}

// Test step:
// Replace a vm from the _DEFAULT Vmgroup
func (s *DefaultVMGroupTestSuite) TestReplaceDefaultTenantVMs(c *C) {
log.Printf("START: defaultvmgroup.TestReplaceDefaultTenantVMs")
misc.LogTestStart(c.TestName())

out, err := admincli.ReplaceVMFromVMgroup(s.esxIP, con.DefaultVMgroup, s.hostName)
out, err := admincli.ReplaceVMFromVMgroup(s.config.EsxHost, admincliconst.DefaultVMgroup, s.config.DockerHostNames[1])
c.Assert(err, IsNil, Commentf(out))
c.Assert(strings.TrimRight(string(out), "\n"), Equals, ErrorMsg, Commentf("Unexpected Behavior: "+
c.Assert(strings.TrimRight(string(out), "\n"), Equals, vgErrorMsg, Commentf("Unexpected Behavior: "+
"We are able to replace vm from the _DEFAULT tenant which is NOT allowed as per current spec."))

log.Printf("END: defaultvmgroup.TestReplaceDefaultTenantVMs")
misc.LogTestEnd(c.TestName())
}

// Verify volume creation after deleting _DEFAULT tenant
// 1. Create a volume
// 2. Verify volume from docker host and esx
// 2. Delete default tenant
// 3. Verify not able to create volume from docker host - Error: VM does not belong to any vmgroup
// 4. Verify docker volume ls does not show any volumes
// 5. Verify admin cli shows volume with VMGroup set as N/A
// 6. Create _DEFAULT vmgroup with —default-datastore=_VM_DS
// 7. Again create new volume - operation should succedd
// 8. Verify volume from esx and docker host
func (s *DefaultVMGroupTestSuite) TestDeleteDefaultVmgroupAndVerify(c *C) {
misc.LogTestStart(c.TestName())
// Create a volume
s.createVolume(c, s.config.DockerHosts[0], s.volumeNames[0])

// Check if volume was successfully created
isAvailable := verification.CheckVolumeAvailability(s.config.DockerHosts[0], s.volumeNames[0])
c.Assert(isAvailable, Equals, true, Commentf("Volume %s is not available after creation", s.volumeNames[0]))

// Verify if volume exists in default vmgroup
isVolInVmgroup := admincli.CheckVolumeExistInVmgroup(s.config.EsxHost, s.volumeNames[0], admincliconst.DefaultVMgroup)
c.Assert(isVolInVmgroup, Equals, true, Commentf("Volume [%s] does not belong to vmgroup [%s]", s.volumeNames[0], admincliconst.DefaultVMgroup))

// Delete default vmgroup and verify it does not exist
admincli.DeleteVMgroup(s.config.EsxHost, admincliconst.DefaultVMgroup)
isVmgroupAvailable := admincli.CheckVmgroupAvailability(s.config.EsxHost, admincliconst.DefaultVMgroup)
c.Assert(isVmgroupAvailable, Equals, false, Commentf("Falied to delete vmgroup %s .", admincliconst.DefaultVMgroup))

// Create a volume - operation should fail as default vmgroup no longer exist
out, err := dockercli.CreateVolume(s.config.DockerHosts[0], s.volumeNames[1])
c.Assert(err, Not(IsNil), Commentf(out))

// Verify existing volume - volumeName1 does not belong to any vmgroup (N/A)
isVolInVmgroup = admincli.CheckVolumeExistInVmgroup(s.config.EsxHost, s.volumeNames[0], NotAvailable)
c.Assert(isVolInVmgroup, Equals, true, Commentf("Unexpected Behavior: Vmgroup for volume [%s] is not N/A. ", s.volumeNames[0]))

s.createDefaultVmgroup(c)

// Create a volume - operation should succeed as default vmgroup exists now
s.createVolume(c, s.config.DockerHosts[0], s.volumeNames[1])

// Check if volume was successfully created
isAvailable = verification.CheckVolumeAvailability(s.config.DockerHosts[0], s.volumeNames[1])
c.Assert(isAvailable, Equals, true, Commentf("Volume %s is not available after creation", s.volumeNames[1]))

// Verify if volume exists in default vmgroup
isVolInVmgroup = admincli.CheckVolumeExistInVmgroup(s.config.EsxHost, s.volumeNames[1], admincliconst.DefaultVMgroup)
c.Assert(isVolInVmgroup, Equals, true, Commentf("Volume [%s] does not belong to vmgroup [%s]", s.volumeNames[1], admincliconst.DefaultVMgroup))

out, err = ssh.InvokeCommand(s.config.DockerHosts[0], dockerconst.RemoveVolume+strings.Join(s.volumeNames, " "))
c.Assert(err, IsNil, Commentf(out))

misc.LogTestEnd(c.TestName())
}

// Create the default Vmgroup
func (s *DefaultVMGroupTestSuite) createDefaultVmgroup(c *C) {
cmd := admincliconst.CreateVMgroup + admincliconst.DefaultVMgroup + " --default-datastore " + admincliconst.VMHomeDatastore
log.Printf("Creating default vmgroup %s", admincliconst.DefaultVMgroup)
ssh.InvokeCommand(s.config.EsxHost, cmd)
ssh.InvokeCommand(s.config.EsxHost, admincliconst.AddDatastoreToVMgroup+admincliconst.DefaultVMgroup+" --datastore=_ALL_DS --allow-create ")

// Verify default vmgroup exists
isVmgroupAvailable := admincli.CheckVmgroupAvailability(s.config.EsxHost, admincliconst.DefaultVMgroup)
c.Assert(isVmgroupAvailable, Equals, true, Commentf("Falied to create vmgroup %s .", admincliconst.DefaultVMgroup))
}

// Create volumes
func (s *DefaultVMGroupTestSuite) createVolume(c *C, hostIp, volumeName string) {
out, err := dockercli.CreateVolume(hostIp, volumeName)
c.Assert(err, IsNil, Commentf(out))
}
Loading

0 comments on commit 0602bc6

Please sign in to comment.