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

Commit

Permalink
Refactor existing tests to use c.TestName() consistently
Browse files Browse the repository at this point in the history
  • Loading branch information
Shaomin Chen committed Jun 8, 2017
1 parent 0d0ee43 commit df76303
Show file tree
Hide file tree
Showing 7 changed files with 50 additions and 51 deletions.
15 changes: 9 additions & 6 deletions tests/e2e/basic_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,9 @@ func (s *BasicTestSuite) SetUpSuite(c *C) {
s.vm2 = s.config.DockerHosts[1]
s.vm1Name = s.config.DockerHostNames[0]
s.vm2Name = s.config.DockerHostNames[1]
}

func (s *BasicTestSuite) SetUpTest(c *C) {
s.volName1 = inputparams.GetUniqueVolumeName(c.TestName())
s.volName2 = inputparams.GetUniqueVolumeName(c.TestName())
s.containerName = inputparams.GetContainerNameWithTimeStamp(c.TestName())
Expand All @@ -74,7 +77,7 @@ var _ = Suite(&BasicTestSuite{})
// 7. Remove the volume
// 8. Verify the volume is unavailable
func (s *BasicTestSuite) TestVolumeLifecycle(c *C) {
misc.LogTestStart(c.TestName(), "TestVolumeLifecycle")
misc.LogTestStart(c.TestName())

for _, host := range s.config.DockerHosts {
out, err := dockercli.CreateVolume(host, s.volName1)
Expand Down Expand Up @@ -102,7 +105,7 @@ func (s *BasicTestSuite) TestVolumeLifecycle(c *C) {
c.Assert(accessible, Equals, false, Commentf("Volume %s is still available", s.volName1))
}

misc.LogTestEnd(c.TestName(), "TestVolumeLifecycle")
misc.LogTestEnd(c.TestName())
}

// Test volume isolation between VMs backed by different datastores:
Expand All @@ -117,7 +120,7 @@ func (s *BasicTestSuite) TestVolumeLifecycle(c *C) {
// 3. Verify the volume is unavailable from VM2
// 4. Remove the volume
func (s *BasicTestSuite) TestBasicVolumeIsolation(c *C) {
misc.LogTestStart(c.TestName(), "TestBasicVolumeIsolation")
misc.LogTestStart(c.TestName())

out, err := dockercli.CreateVolume(s.vm1, s.volName1)
c.Assert(err, IsNil, Commentf(out))
Expand All @@ -132,7 +135,7 @@ func (s *BasicTestSuite) TestBasicVolumeIsolation(c *C) {
out, err = dockercli.DeleteVolume(s.vm1, s.volName1)
c.Assert(err, IsNil, Commentf(out))

misc.LogTestEnd(c.TestName(), "TestBasicVolumeIsolation")
misc.LogTestEnd(c.TestName())
}

// Test volume isolation between _DEFAULT and user defined vmgroups:
Expand All @@ -150,7 +153,7 @@ func (s *BasicTestSuite) TestBasicVolumeIsolation(c *C) {
// 8. Remove the volumes
// 9. Remove Config DB
func (s *BasicTestSuite) TestVmGroupVolumeIsolation(c *C) {
misc.LogTestStart(c.TestName(), "TestVmGroupVolumeIsolation")
misc.LogTestStart(c.TestName())

// Initialize Config DB
admincli.ConfigInit(s.esx)
Expand Down Expand Up @@ -193,5 +196,5 @@ func (s *BasicTestSuite) TestVmGroupVolumeIsolation(c *C) {
// Remove Config DB
admincli.ConfigRemove(s.esx)

misc.LogTestEnd(c.TestName(), "TestVmGroupVolumeIsolation")
misc.LogTestEnd(c.TestName())
}
39 changes: 20 additions & 19 deletions tests/e2e/vmgroups_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ import (
)

const (
vmgroupsTest = "vmgroup"
vgTestVMgroup1 = "vmgroup_test1"
vgTestVMgroup2 = "vmgroup_test2"
vgTestContainer = "vmgroupContainer"
Expand Down Expand Up @@ -83,16 +82,18 @@ func (vg *VmGroupTest) SetUpSuite(c *C) {
out, err = ssh.InvokeCommand(vg.config.EsxHost, cmd)
c.Assert(err, IsNil, Commentf(out))

// Create volume names used for the test
vg.vmgroupGetVolName(c)

cmd = adminconst.ListVMgroups
out, err = ssh.InvokeCommand(vg.config.EsxHost, cmd)
log.Printf(out)

log.Printf("Done creating vmgroups test config.")
}

func (vg *VmGroupTest) SetUpTest(c *C) {
// Create volume names used for the test
vg.vmgroupGetVolName(c)
}

func (vg *VmGroupTest) TearDownSuite(c *C) {
// A failed test may leave the VM in either of these groups
adminutils.RemoveVMFromVMgroup(vg.config.EsxHost, vgTestVMgroup1, vg.config.DockerHostNames[0])
Expand All @@ -118,9 +119,9 @@ func (vg *VmGroupTest) TearDownSuite(c *C) {
}

func (vg *VmGroupTest) vmgroupGetVolName(c *C) {
vg.volName1 = inputparams.GetUniqueVolumeName(vmgroupsTest)
vg.volName2 = inputparams.GetUniqueVolumeName(vmgroupsTest)
vg.volName3 = inputparams.GetUniqueVolumeName(vmgroupsTest)
vg.volName1 = inputparams.GetUniqueVolumeName(c.TestName())
vg.volName2 = inputparams.GetUniqueVolumeName(c.TestName())
vg.volName3 = inputparams.GetUniqueVolumeName(c.TestName())
}

// Tests to validate behavior with the __DEFAULT_ vmgroup.
Expand All @@ -143,7 +144,7 @@ func (vg *VmGroupTest) createVolumes(c *C, name string) {
// 2. Verify the VM is able to attach and run a container with the volume
// 3. Delete the volume
func (vg *VmGroupTest) TestVmGroupVolumeCreate(c *C) {
misc.LogTestStart(vmgroupsTest, "TestVmGroupVolumeCreate")
misc.LogTestStart(c.TestName())

// Create a volume in the default group
vg.createVolumes(c, vg.volName1)
Expand All @@ -160,7 +161,7 @@ func (vg *VmGroupTest) TestVmGroupVolumeCreate(c *C) {
c.Assert(err, IsNil, Commentf(out))
c.Logf("Passed - Volume create and attach on default vmgroup")

misc.LogTestEnd(vmgroupsTest, "TestVmGroupVolumeCreate")
misc.LogTestEnd(c.TestName())
}

// TestVmGroupVolumeAccessAcrossVmGroups - Verify volumes can be accessed only
Expand All @@ -173,7 +174,7 @@ func (vg *VmGroupTest) TestVmGroupVolumeCreate(c *C) {
// 5. Try deleting the volume in th default group from VM2
// 6. Remove the newly created vmgroup
func (vg *VmGroupTest) TestVmGroupVolumeAccessAcrossVmGroups(c *C) {
misc.LogTestStart(vmgroupsTest, "TestVmGroupVolumeAccessAcrossVmGroups")
misc.LogTestStart(c.TestName())

// 1. Create a volume in the default group
vg.createVolumes(c, vg.volName1)
Expand Down Expand Up @@ -206,7 +207,7 @@ func (vg *VmGroupTest) TestVmGroupVolumeAccessAcrossVmGroups(c *C) {
c.Assert(err, IsNil, Commentf(out))

c.Logf("Passed - Volume access across vmgroups")
misc.LogTestEnd(vmgroupsTest, "TestVmGroupVolumeAccessAcrossVmGroups")
misc.LogTestEnd(c.TestName())
}

// TestVmGroupCreateAccessPrivilege - Verify volumes can be
Expand All @@ -220,7 +221,7 @@ func (vg *VmGroupTest) TestVmGroupVolumeAccessAcrossVmGroups(c *C) {
// 5. Restore create privilege on default vmgroup
// 6. Remove volume created in (1).
func (vg *VmGroupTest) TestVmGroupCreateAccessPrivilege(c *C) {
misc.LogTestStart(vmgroupsTest, "TestVmGroupCreateAccessPrivilege")
misc.LogTestStart(c.TestName())

// 1. Create a volume in the default vmgroup
vg.createVolumes(c, vg.volName1)
Expand Down Expand Up @@ -255,7 +256,7 @@ func (vg *VmGroupTest) TestVmGroupCreateAccessPrivilege(c *C) {
c.Assert(err, IsNil, Commentf(out))

c.Logf("Passed - create privilege on default vmgroup")
misc.LogTestEnd(vmgroupsTest, "TestVmGroupCreateAccessPrivilege")
misc.LogTestEnd(c.TestName())
}

// TestVmGroupVolumeCreateOnVg - Verify basic volume create/attach/delete
Expand All @@ -266,7 +267,7 @@ func (vg *VmGroupTest) TestVmGroupCreateAccessPrivilege(c *C) {
// 4. Delete volume created in (2)
// 5. Destroy the VM group
func (vg *VmGroupTest) TestVmGroupVolumeCreateOnVg(c *C) {
misc.LogTestStart(vmgroupsTest, "TestVmGroupVolumeCreateOnVg")
misc.LogTestStart(c.TestName())

// 1. Remove VM from test group 1 and add to test group 2
out, err := adminutils.RemoveVMFromVMgroup(vg.config.EsxHost, vgTestVMgroup1, vg.config.DockerHostNames[0])
Expand Down Expand Up @@ -298,7 +299,7 @@ func (vg *VmGroupTest) TestVmGroupVolumeCreateOnVg(c *C) {
c.Assert(err, IsNil, Commentf(out))

c.Logf("Passed - create and attach volumes on a non-default vmgroup")
misc.LogTestEnd(vmgroupsTest, "TestVmGroupVolumeCreateOnVg")
misc.LogTestEnd(c.TestName())
}

// TestVmGroupVerifyMaxFileSizeOnVg - Verify that enough volumes can be created
Expand All @@ -311,7 +312,7 @@ func (vg *VmGroupTest) TestVmGroupVolumeCreateOnVg(c *C) {
// 5. Retry step (4) - expect success this time
// 6. Remove both volumes
func (vg *VmGroupTest) TestVmGroupVerifyMaxFileSizeOnVg(c *C) {
misc.LogTestStart(vmgroupsTest, "TestVmGroupVerifyMaxFileSizeOnVg")
misc.LogTestStart(c.TestName())

// 1. Ensure the max file size and total size is set to 1G each.
out, err := adminutils.SetVolumeSizeForVMgroup(vg.config.EsxHost, vgTestVMgroup1, vg.config.Datastores[0], "1gb", "1gb")
Expand Down Expand Up @@ -359,7 +360,7 @@ func (vg *VmGroupTest) TestVmGroupVerifyMaxFileSizeOnVg(c *C) {
dockercli.DeleteVolume(vg.config.DockerHosts[0], vg.volName2)

c.Logf("Passed - verified volumes can be created to match total size assigned to a vmgroup")
misc.LogTestEnd(vmgroupsTest, "TestVmGroupVerifyMaxFileSizeOnVg")
misc.LogTestEnd(c.TestName())
}

// TestVmGroupVolumeMobility - verify a VM with a volume
Expand All @@ -370,7 +371,7 @@ func (vg *VmGroupTest) TestVmGroupVerifyMaxFileSizeOnVg(c *C) {
// 3. Attempt removing the VM from vmgroup (to default) (should fail)
// 4. Delete container and attempt 3 (should pass)
func (vg *VmGroupTest) TestVmGroupVolumeMobility(c *C) {
misc.LogTestStart(vmgroupsTest, "TestVmGroupVolumeMobility")
misc.LogTestStart(c.TestName())

// 1. Create a volume in the default group
vg.createVolumes(c, vg.volName1)
Expand Down Expand Up @@ -398,5 +399,5 @@ func (vg *VmGroupTest) TestVmGroupVolumeMobility(c *C) {
c.Assert(err, IsNil, Commentf(out))

c.Logf("Passed - VM removal from vmgroups, with volume attached")
misc.LogTestEnd(vmgroupsTest, "TestVmGroupVolumeAccessAcrossVmGroups")
misc.LogTestEnd(c.TestName())
}
9 changes: 4 additions & 5 deletions tests/e2e/volume_access_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ import (
)

const (
volAccessTest = "vol_access"
errorWriteVolume = "Read-only file system"
)

Expand Down Expand Up @@ -90,7 +89,7 @@ func (s *VolumeAccessTestSuite) newCName(i int) string {
// 11. Write from host2 should succeed
// 12. Read from host1 to verify the content is same
func (s *VolumeAccessTestSuite) TestAccessUpdate(c *C) {
misc.LogTestStart(volAccessTest, "TestAccessUpdate")
misc.LogTestStart(c.TestName())

data1 := "message_by_host1"
data2 := "message_by_host2"
Expand Down Expand Up @@ -140,7 +139,7 @@ func (s *VolumeAccessTestSuite) TestAccessUpdate(c *C) {
c.Assert(err, IsNil, Commentf(out))
c.Assert(out, Equals, data2)

misc.LogTestEnd(volAccessTest, "TestAccessUpdate")
misc.LogTestEnd(c.TestName())
}

// Verify read, write is possible after volume access update
Expand All @@ -153,7 +152,7 @@ func (s *VolumeAccessTestSuite) TestAccessUpdate(c *C) {
// 7. Write from host2 should succeed
// 8. Read from host1 to verify the content is same
func (s *VolumeAccessTestSuite) TestAccessUpdate_R_RW(c *C) {
misc.LogTestStart(volAccessTest, "TestAccessUpdate_R_RW")
misc.LogTestStart(c.TestName())

data1 := "message_by_host1"
data2 := "message_by_host2"
Expand Down Expand Up @@ -186,5 +185,5 @@ func (s *VolumeAccessTestSuite) TestAccessUpdate_R_RW(c *C) {
c.Assert(err, IsNil, Commentf(out))
c.Assert(out, Equals, data2)

misc.LogTestEnd(volAccessTest, "TestAccessUpdate_R_RW")
misc.LogTestEnd(c.TestName())
}
17 changes: 8 additions & 9 deletions tests/e2e/volumecreate_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ import (
)

const (
volCreateTest = "vol_create"
ErrorVolumeCreate = "Error response from daemon: create"
)

Expand Down Expand Up @@ -129,7 +128,7 @@ func (s *VolumeCreateTestSuite) accessCheck(hostIP string, volList []string, c *
// 7. contains unicode character
// 8. contains space
func (s *VolumeCreateTestSuite) TestValidName(c *C) {
misc.LogTestStart(volCreateTest, "TestValidName")
misc.LogTestStart(c.TestName())

volNameList := []string{
inputparams.GetVolumeNameOfSize(100),
Expand All @@ -145,15 +144,15 @@ func (s *VolumeCreateTestSuite) TestValidName(c *C) {
s.parallelCreateByName(volNameList, true, c)
s.accessCheck(s.config.DockerHosts[0], s.volumeList, c)

misc.LogTestEnd(volCreateTest, "TestValidName")
misc.LogTestEnd(c.TestName())
}

// Invalid volume names test
// 1. having more than 100 chars
// 2. ending -NNNNNN (6Ns)
// 3. contains @invalid datastore name
func (s *VolumeCreateTestSuite) TestInvalidName(c *C) {
misc.LogTestStart(volCreateTest, "TestInvalidName")
misc.LogTestStart(c.TestName())

invalidVolList := []string{
inputparams.GetVolumeNameOfSize(101),
Expand All @@ -163,7 +162,7 @@ func (s *VolumeCreateTestSuite) TestInvalidName(c *C) {

s.parallelCreateByName(invalidVolList, false, c)

misc.LogTestEnd(volCreateTest, "TestInvalidName")
misc.LogTestEnd(c.TestName())
}

// Valid volume creation options
Expand All @@ -175,7 +174,7 @@ func (s *VolumeCreateTestSuite) TestInvalidName(c *C) {
// 6. clone-from valid volume
// 7. fstype xfs
func (s *VolumeCreateTestSuite) TestValidOptions(c *C) {
misc.LogTestStart(volCreateTest, "TestValidOptions")
misc.LogTestStart(c.TestName())

// Need a valid volume source to test clone-from option
cloneSrcVol := inputparams.GetUniqueVolumeName("clone_src")
Expand Down Expand Up @@ -206,7 +205,7 @@ func (s *VolumeCreateTestSuite) TestValidOptions(c *C) {

s.accessCheck(s.config.DockerHosts[0], s.volumeList, c)

misc.LogTestEnd(volCreateTest, "TestValidOptions")
misc.LogTestEnd(c.TestName())
}

// Invalid volume create operations
Expand All @@ -216,7 +215,7 @@ func (s *VolumeCreateTestSuite) TestValidOptions(c *C) {
// 4. Wrong access types
// 5. Unavailable clone source
func (s *VolumeCreateTestSuite) TestInvalidOptions(c *C) {
misc.LogTestStart(volCreateTest, "TestInvalidOptions")
misc.LogTestStart(c.TestName())

invalidVolOpts := []string{
" -o diskformat=zeroedthickk",
Expand All @@ -233,5 +232,5 @@ func (s *VolumeCreateTestSuite) TestInvalidOptions(c *C) {

s.parallelCreateByOption(invalidVolOpts, false, c)

misc.LogTestEnd(volCreateTest, "TestInvalidOptions")
misc.LogTestEnd(c.TestName())
}
8 changes: 3 additions & 5 deletions tests/e2e/volumeproperty_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,6 @@ import (
)

const (
testName = "TestVolumeProperties"
testgroup = "volumeproperty_group"
size = "100MB"
diskFormatOption = " -o diskformat="
)
Expand Down Expand Up @@ -69,7 +67,7 @@ func (s *VolumePropertyTestSuite) SetUpSuite(c *C) {
}

func (s *VolumePropertyTestSuite) SetUpTest(c *C) {
s.containerName = inputparams.GetContainerNameWithTimeStamp(testName)
s.containerName = inputparams.GetContainerNameWithTimeStamp(c.TestName())
s.formatTypes = []string{"thin", "zeroedthick", "eagerzeroedthick"}
s.volumeStatus = properties.DetachedStatus
}
Expand Down Expand Up @@ -98,7 +96,7 @@ NOTE: Do steps 5 ,6 and 7 only for volume of 'thin' disk format type.
*/

func (s *VolumePropertyTestSuite) TestVolumeProperties(c *C) {
misc.LogTestStart(testgroup, testName)
misc.LogTestStart(c.TestName())

// create volumes of all three disk formats
s.createVolumes(c)
Expand All @@ -121,7 +119,7 @@ func (s *VolumePropertyTestSuite) TestVolumeProperties(c *C) {

// Verify if docker and ESX properties of volumes are same and as expected.
s.verifyProperties(c)
misc.LogTestEnd(testgroup, testName)
misc.LogTestEnd(c.TestName())
}

// createVolumes - creates volumes of each format type
Expand Down
5 changes: 2 additions & 3 deletions tests/e2e/vsan_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ import (
)

const (
vsanVolumeTest = "vsan_vol"
vsanPolicyFlag = "vsan-policy-name"
)

Expand Down Expand Up @@ -74,7 +73,7 @@ var _ = Suite(&VsanTestSuite{})
// 5. Volume creation with non existing policy should fail
// 6. Volume creation with invalid policy should fail
func (s *VsanTestSuite) TestVSANPolicy(c *C) {
misc.LogTestStart(volCreateTest, "TestVSANPolicy")
misc.LogTestStart(c.TestName())

policyName := "validPolicy"
out, err := admincli.CreatePolicy(s.config.EsxHost, policyName, "'((\"proportionalCapacity\" i50)''(\"hostFailuresToTolerate\" i0))'")
Expand All @@ -99,5 +98,5 @@ func (s *VsanTestSuite) TestVSANPolicy(c *C) {
c.Assert(strings.HasPrefix(out, ErrorVolumeCreate), Equals, true)
}

misc.LogTestStart(volCreateTest, "TestVSANPolicy")
misc.LogTestStart(c.TestName())
}
Loading

0 comments on commit df76303

Please sign in to comment.