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

Commit

Permalink
Adding vmgroup tests
Browse files Browse the repository at this point in the history
  • Loading branch information
ashahi1 committed Jun 24, 2017
1 parent 8607f2e commit c10d75e
Show file tree
Hide file tree
Showing 6 changed files with 453 additions and 14 deletions.
19 changes: 17 additions & 2 deletions tests/constants/admincli/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,14 +56,17 @@ 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"

// AllDatastore access to all datastore for vms in vmgroup
AllDatastore = "_ALL_DS"

// InitLocalConfigDb referring to Initialize (local) Single Node Config DB
InitLocalConfigDb = vmdkopsAdmin + "config init --local"

Expand All @@ -82,4 +85,16 @@ 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="

// AddDatastoreAccess adds datastore to vmgroup
AddDatastoreAccess = vmdkopsAdmin + "vmgroup access add --name="

// GetDBMode get current DB config
GetDBMode = vmdkopsAdmin + "config status"
)
6 changes: 6 additions & 0 deletions tests/constants/admincli/vmdkops.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,10 @@ const (

// StartService starts vmdkops service
StartService = vmdkopsd + "start"

// DBNotConfigured - DB mode not configured
DBNotConfigured = "NotConfigured"

// DBSingleNode - DB mode SingleNode
DBSingleNode = "SingleNode"
)
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 @@ -173,7 +173,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
269 changes: 269 additions & 0 deletions tests/e2e/vmgroupmisc_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,269 @@
// 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.

// This test suite contains miscellaneous tests to verify behavior of non-default vmgroup

// +build unstable

package e2e

import (
"log"

admincliconst "github.com/vmware/docker-volume-vsphere/tests/constants/admincli"
"github.com/vmware/docker-volume-vsphere/tests/constants/properties"
"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/esx"
"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"
)

const (
vmGroupName = "vg_basictest"
)

type vgBasicSuite struct {
config *inputparams.TestConfig
volumeNames []string
}

func (s *vgBasicSuite) SetUpSuite(c *C) {
basicVG := "basicVGTest"
s.config = inputparams.GetTestConfig()
if s.config == nil {
c.Skip("Unable to retrieve test config, skipping vmgroupbasic tests.")
}
admincli.ConfigInit(s.config.EsxHost)

// Verify DB successfully initialized
c.Assert(admincli.GetDBmode(s.config.EsxHost), Equals, admincliconst.DBSingleNode, Commentf("Failed to init the DB mode on ESX - .", s.config.EsxHost))
s.volumeNames = []string{inputparams.GetUniqueVolumeName(basicVG), inputparams.GetUniqueVolumeName(basicVG)}
}

func (s *vgBasicSuite) SetUpTest(c *C) {
// Creating non-default vmgroup only if it does not exists
if admincli.IsVmgroupPresent(s.config.EsxHost, vmGroupName) {
return
}
admincli.CreateVMgroup(s.config.EsxHost, vmGroupName, s.config.DockerHostNames[0], s.config.Datastores[0])

// Verify if vmgroup exists
isVmgroupAvailable := admincli.IsVmgroupPresent(s.config.EsxHost, vmGroupName)
c.Assert(isVmgroupAvailable, Equals, true, Commentf("vmgroup ls command does not lists the vmgroup %s .", vmGroupName))

// Verify vm belongs to vmgroup
isVMPartofVg := admincli.IsVMInVmgroup(s.config.EsxHost, s.config.DockerHostNames[0], vmGroupName)
c.Assert(isVMPartofVg, Equals, true, Commentf("VM %s does not belong to vmgroup %s .", s.config.DockerHostNames[0], vmGroupName))
}

func (s *vgBasicSuite) TearDownSuite(c *C) {
admincli.RemoveVMFromVMgroup(s.config.EsxHost, vmGroupName, s.config.DockerHostNames[0])

// Verify vm does not belongs to vmgroup
isVMPartofVg := admincli.IsVMInVmgroup(s.config.EsxHost, s.config.DockerHostNames[0], vmGroupName)
c.Assert(isVMPartofVg, Equals, false, Commentf("Unexpected Behavior: VM %s belong to vmgroup %s .", s.config.DockerHostNames[0], vmGroupName))

admincli.DeleteVMgroup(s.config.EsxHost, vmGroupName)
// Verify vmgroup does not exist
isVmgroupAvailable := admincli.IsVmgroupPresent(s.config.EsxHost, vmGroupName)
c.Assert(isVmgroupAvailable, Equals, false, Commentf("Failed to delete the vmgroup [%s] .", vmGroupName))

// Removing the DB at the end of suite
admincli.ConfigRemove(s.config.EsxHost)

// Verifying DB successfully removed
c.Assert(admincli.GetDBmode(s.config.EsxHost), Equals, admincliconst.DBNotConfigured, Commentf("Failed to remove the DB mode on ESX - .", s.config.EsxHost))
}

var _ = Suite(&vgBasicSuite{})

/*
//TO DO: Please reenable or remove this test based on the conclusion of the Issue # 1469
// Verify vmgroup for orphaned volumes is specified as N/A
// 1. Create a vmgroup and add vm to it.
// 2. Verify vmgroup was successfully created.
// 3. Create a volume from vm-2.
// 4. Verify volumes vmgroup from esx.
// 5. Remove vm-2 from vmgroup.
// 6. Verify volume is not visible from vm-2.
// 7. Delete the tenant.
// 8. Again verify volumes vmgroup is listed as N/A.
func (s *vgBasicSuite) TestVGNameForOrphanedVolumes(c *C) {
misc.LogTestStart(c.TestName())
nullVmgroup := "N/A"
// Create a volume from vmgroup's vm
out, err := dockercli.CreateVolume(s.config.DockerHosts[0], s.volumeNames[0])
c.Assert(err, IsNil, Commentf(out))
// 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 vmgroup
isVolInVmgroup := admincli.IsVolumeExistInVmgroup(s.config.EsxHost, vmGroupName, s.volumeNames[0])
c.Assert(isVolInVmgroup, Equals, true, Commentf("Volume [%s] does not belong to vmgroup [%s]", s.volumeNames[0], vmGroupName))
admincli.RemoveVMFromVMgroup(s.config.EsxHost, vmGroupName, s.config.DockerHostNames[0])
// Check if volume was not visible from vm since it does not belong to vmgroup
isAvailable = verification.CheckVolumeAvailability(s.config.DockerHosts[0], s.volumeNames[0])
c.Assert(isAvailable, Equals, false, Commentf("Unexpected Behavior: Volume %s belonging to "+
"vmgroup [%s] is visible from host [%s] which does not belong to the same vmgroup", s.volumeNames[0], vmGroupName, s.config.DockerHosts[0]))
// Now delete the vmgroup
admincli.DeleteVMgroup(s.config.EsxHost, vmGroupName)
// Verify vmgroup does not exist
isVmgroupAvailable := admincli.IsVmgroupPresent(s.config.EsxHost, vmGroupName)
c.Assert(isVmgroupAvailable, Equals, false, Commentf("Failed to delete the vmgroup [%s] .", vmGroupName))
// Verify vmgroup for volume is N/A
isVolInVmgroup = admincli.IsVolumeExistInVmgroup(s.config.EsxHost, nullVmgroup, s.volumeNames[0])
c.Assert(isVolInVmgroup, Equals, true, Commentf("Unexpected Behavior: Vmgroup [%s] for volume [%s] is not N/A. ", s.volumeNames[0], vmGroupName))
// verify orpahned volume is not visible from host
isAvailable = verification.CheckVolumeAvailability(s.config.DockerHosts[0], s.volumeNames[0])
c.Assert(isAvailable, Equals, false, Commentf("Unexpected Behavior: Orphaned volume %s "+
"is visible from host [%s] ", s.volumeNames[0], s.config.DockerHosts[0]))
misc.LogTestEnd(c.TestName())
}
*/

// TestUserVGDatastoreAccessPrivilege - Verify volumes can be
// created by a VM as long as the non-default vmgroup has "allow_create" right given
// 1. Create vmgroup VG1 and add vm VM2 to it
// 2. Add datastore to VG1 - By default no "allow_create" right is given
// 3. Create volume in VG1 and expect error as allow-create is false
// 4. Create volume creation from VM1 (In _DEFAULT vmgroup) and expects successful volume creation
// 5. Change allow-create access to true
// 6. Repeat step-3 and this time volume creation should succeed
// 7. Update datastore access for VG1 (remove --allow-create rule)
// 8. Repeat step#5 and this time expect the error
func (s *vgBasicSuite) TestDSAccessPrivilegeForUserVG(c *C) {
misc.LogTestStart(c.TestName())

// Add another datastore to vmgroup
admincli.AddDatastoreToVmgroup(s.config.EsxHost, vmGroupName, s.config.Datastores[1])

// Verify if vmgroup does not have access-rights for DS
isDatastoreAccessible := admincli.IsDSAccessibleForVMgroup(s.config.EsxHost, vmGroupName, s.config.Datastores[1])
c.Assert(isDatastoreAccessible, Equals, false, Commentf("Unexpected Behavior: Datastore %s is accessible for vmgroup %s .", s.config.Datastores[1], vmGroupName))

// Create a volume from _DEFAULT vmgroup's vm - operation should succeed
out, err := dockercli.CreateVolume(s.config.DockerHosts[1], s.volumeNames[1])
c.Assert(err, IsNil, Commentf(out))

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

// This volume create will fail because of trying to create volume on the non-default DS.
out, err = dockercli.CreateVolume(s.config.DockerHosts[0], s.volumeNames[0]+"@"+s.config.Datastores[1])
c.Assert(err, Not(IsNil), Commentf(out))

// Check volume was not created
isAvailable = verification.CheckVolumeAvailability(s.config.DockerHosts[0], s.volumeNames[0]+"@"+s.config.Datastores[1])
c.Assert(isAvailable, Equals, false, Commentf("Unexpected behavior: Volume %s is successfully created "+
" even though vmgroup [%s] does not have access rights for the datastore %s", s.volumeNames[1], vmGroupName, s.config.Datastores[1]))

// Set the create privilege on the vmgroup for specified datastore
out, _ = admincli.AddCreateAccessForVMgroup(s.config.EsxHost, vmGroupName, s.config.Datastores[1])
isDatastoreAccessible = admincli.IsDSAccessibleForVMgroup(s.config.EsxHost, vmGroupName, s.config.Datastores[1])
c.Assert(isDatastoreAccessible, Equals, true, Commentf("Datstore %s is not accessible for vmgroup %s .", s.config.Datastores[1], vmGroupName))

// Create a volume from non-default vmgroup's vm - operation should succeed this time
// as access-rights have been changed to True
out, err = dockercli.CreateVolume(s.config.DockerHosts[0], s.volumeNames[0]+"@"+s.config.Datastores[1])
c.Assert(err, IsNil, Commentf(out))

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

// verify able to delete volume
out, err = dockercli.DeleteVolume(s.config.DockerHosts[0], s.volumeNames[0]+"@"+s.config.Datastores[1])
c.Assert(err, IsNil, Commentf(out))

// Check if volume was successfully deleted
isAvailable = verification.CheckVolumeAvailability(s.config.DockerHosts[0], s.volumeNames[0]+"@"+s.config.Datastores[1])
c.Assert(isAvailable, Equals, false, Commentf("Failed to delete volume %s", s.volumeNames[0]))

// Remove the create privilege on the non-default vmgroup for specified datastore
admincli.RemoveCreateAccessForVMgroup(s.config.EsxHost, vmGroupName, s.config.Datastores[1])

// Verify if vmgroup does not have access-rights for DS
isDatastoreAccessible = admincli.IsDSAccessibleForVMgroup(s.config.EsxHost, vmGroupName, s.config.Datastores[1])
c.Assert(isDatastoreAccessible, Equals, false, Commentf("Datastore %s is accessible for vmgroup %s .", s.config.Datastores[1], vmGroupName))

// This volume create will fail because of trying to create volume on ds with no create privilege.
volumeName := inputparams.GetUniqueVolumeName(vmGroupName)
out, err = dockercli.CreateVolume(s.config.DockerHostNames[0], volumeName+"@"+s.config.Datastores[1])
c.Assert(err, Not(IsNil), Commentf(out))

// Check if volume was not created
isAvailable = verification.CheckVolumeAvailability(s.config.DockerHosts[0], volumeName+"@"+s.config.Datastores[1])
c.Assert(isAvailable, Equals, false, Commentf("Unexpected behavior: Volume %s is successfully created "+
" even though vmgroup [%s] does not have access rights for the datastore %s ", s.volumeNames[1], vmGroupName, s.config.Datastores[1]))

out, err = dockercli.DeleteVolume(s.config.DockerHosts[1], s.volumeNames[1])
c.Assert(err, IsNil, Commentf(out))

misc.LogTestEnd(c.TestName())
}

// Test steps:
// 1. Create a vmgroup and associate a vm to it.
// 2. Execute vmgroup ls command.
// 3. Kill the vm that was added to the tenant.
// 4. Again execute vmgroup ls command to verify command works fine.
func (s *vgBasicSuite) TestVmgroupLsPostVMKill(c *C) {
misc.LogTestStart(c.TestName())

powerState := esx.GetVMPowerState(s.config.DockerHostNames[0])
log.Printf("VM[%s]'s current power state is [%s]", s.config.DockerHostNames[0], properties.PowerOnState)
c.Assert(powerState, Equals, properties.PowerOnState, Commentf("VM [%s] should be powered on state", s.config.DockerHostNames[0]))

vmProcessID := esx.GetVMProcessID(s.config.EsxHost, s.config.DockerHostNames[0])
log.Printf("VM's process ID is: %s", vmProcessID)

// Kill the VM
isVMKilled := esx.KillVM(s.config.EsxHost, vmProcessID)
c.Assert(isVMKilled, Equals, true, Commentf("Unable to kill VM %s ...", s.config.DockerHostNames[0]))

isStatusChanged := esx.WaitForExpectedState(esx.GetVMPowerState, s.config.DockerHostNames[0], properties.PowerOffState)
c.Assert(isStatusChanged, Equals, true, Commentf("VM [%s] should be powered off state", s.config.DockerHostNames[0]))

// Check vmgroup ls
isVmgroupAvailable := admincli.IsVmgroupPresent(s.config.EsxHost, vmGroupName)
c.Assert(isVmgroupAvailable, Equals, true, Commentf("vmgroup ls command does not lists the vmgroup %s .", vmGroupName))

// Power-on the VM
esx.PowerOnVM(s.config.DockerHostNames[0])

isStatusChanged = esx.WaitForExpectedState(esx.GetVMPowerState, s.config.DockerHostNames[0], properties.PowerOnState)
c.Assert(isStatusChanged, Equals, true, Commentf("Failed to power-on the VM [%s]", s.config.DockerHostNames[0]))

// Verify vDVS successfully started
isVDVSRunning := verification.IsVDVSIsRunning(s.config.DockerHosts[0])
c.Assert(isVDVSRunning, Equals, true, Commentf("Failed to start docker volume vsphere on the VM [%s]", s.config.DockerHostNames[0]))

misc.LogTestEnd(c.TestName())
}
Loading

0 comments on commit c10d75e

Please sign in to comment.