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

Commit

Permalink
Fix cleanup in vmdk_ops_test.py
Browse files Browse the repository at this point in the history
  • Loading branch information
ashahi1 committed Jun 26, 2017
1 parent 4196f1f commit d68050d
Show file tree
Hide file tree
Showing 2 changed files with 107 additions and 28 deletions.
6 changes: 3 additions & 3 deletions esx_service/vmdk_ops_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -728,7 +728,7 @@ def cleanup(self):
# cleanup existing volume under DEFAULT tenant
logging.info("VMDKTenantTest cleanup")
if self.datastore_path:
default_tenant_path = os.path.join(self.datastore_path, auth_data_const.DEFAULT_TENANT)
default_tenant_path = os.path.join(self.datastore_path, auth_data_const.DEFAULT_TENANT_UUID)
for vol in self.default_tenant_vols:
vmdk_path = vmdk_utils.get_vmdk_path(default_tenant_path, vol)
response = vmdk_ops.getVMDK(vmdk_path, vol, self.datastore_name)
Expand Down Expand Up @@ -1408,7 +1408,7 @@ def cleanup(self):
# cleanup existing volume under DEFAULT tenant
logging.info("VmdkTenantPolicyUsageTestCase cleanup")
if self.datastore_path:
default_tenant_path = os.path.join(self.datastore_path, auth_data_const.DEFAULT_TENANT)
default_tenant_path = os.path.join(self.datastore_path, auth_data_const.DEFAULT_TENANT_UUID)
for vol in self.default_tenant_vols:
vmdk_path = vmdk_utils.get_vmdk_path(default_tenant_path, vol)
response = vmdk_ops.getVMDK(vmdk_path, vol, self.datastore_name)
Expand Down Expand Up @@ -1565,7 +1565,7 @@ def cleanup(self):
# cleanup existing volume under DEFAULT tenant
logging.info("VMListenerTest cleanup")
if self.datastore_path:
default_tenant_path = os.path.join(self.datastore_path, auth_data_const.DEFAULT_TENANT)
default_tenant_path = os.path.join(self.datastore_path, auth_data_const.DEFAULT_TENANT_UUID)
vol = self.default_tenant_vol1_name
vmdk_path = vmdk_utils.get_vmdk_path(default_tenant_path, vol)
response = vmdk_ops.getVMDK(vmdk_path, vol, self.datastore_name)
Expand Down
129 changes: 104 additions & 25 deletions tests/e2e/defaultvmgroup_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,83 +12,162 @@
// See the License for the specific language governing permissions and
// limitations under the License.

// This test suite tries to add, remove and replace vm to the _DEFAULT vmgroup
// Expected behavior is that add/rm/replace vm for _DEFAULT vmgroup should fail
// This test suite contains tests to verify behavior of default vmgroup

// +build runonce

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."
)

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)
defaultVG := "defaultVGTest"
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))

// 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(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))

// 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(&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 succeed
// 8. Verify volume from esx and docker host

func (s *DefaultVMGroupTestSuite) TestDeleteDefaultVmgroup(c *C) {
misc.LogTestStart(c.TestName())
nullVmgroup := "N/A"
noVgErrorMsg := "VolumeDriver.Create: VM " + s.config.DockerHostNames[0] + " does not belong to any vmgroup"

// Verify default vmgroup is present
isVmgroupAvailable := admincli.IsVmgroupPresent(s.config.EsxHost, admincliconst.DefaultVMgroup)
c.Assert(isVmgroupAvailable, Equals, true, Commentf(" Vmgroup %s does not exist", admincliconst.DefaultVMgroup))

// Create a volume
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 default vmgroup
isVolInVmgroup := admincli.IsVolumeExistInVmgroup(s.config.EsxHost, admincliconst.DefaultVMgroup, s.volumeNames[0])
c.Assert(isVolInVmgroup, Equals, true, Commentf("Volume [%s] does not belong to vmgroup [%s]", admincliconst.DefaultVMgroup, s.volumeNames[0]))

// Delete default vmgroup and verify it does not exist
admincli.DeleteVMgroup(s.config.EsxHost, admincliconst.DefaultVMgroup)

isVmgroupAvailable = admincli.IsVmgroupPresent(s.config.EsxHost, admincliconst.DefaultVMgroup)
c.Assert(isVmgroupAvailable, Equals, false, Commentf("Failed 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))
c.Assert(strings.Contains(out, noVgErrorMsg), Equals, true, Commentf(out))

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

isVmgroupAvailable = admincli.CreateDefaultVmgroup(s.config.EsxHost)
c.Assert(isVmgroupAvailable, Equals, true, Commentf("Failed to create vmgroup %s .", admincliconst.DefaultVMgroup))

// Create a volume - operation should succeed as default vmgroup exists now
out, err = dockercli.CreateVolume(s.config.DockerHosts[0], s.volumeNames[1])
c.Assert(err, IsNil, Commentf(out))

// 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]))

// Check volumes now again belong to default vmgroup
isVolInVmgroup = admincli.IsVolumeListExistInVmgroup(s.config.EsxHost, admincliconst.DefaultVMgroup, s.volumeNames)
c.Assert(isVolInVmgroup, Equals, true, Commentf("All volumes [%s] do not belong to vmgroup [%s]", s.volumeNames, 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())
}

0 comments on commit d68050d

Please sign in to comment.