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

Automate vsan policy test case #1361

Merged
merged 9 commits into from
Jun 10, 2017
Merged

Automate vsan policy test case #1361

merged 9 commits into from
Jun 10, 2017

Conversation

lipingxue
Copy link
Contributor

Fixed #1264.
I was not able to run the whole e2e-test locally due to issue #1284, so I run only my newly added test locally. Please refer the following result:

GO15VENDOREXPERIMENT=1 go test github.com/vmware/docker-volume-vsphere/tests/e2e -v -timeout 30m -check.f VsanPolicyTestSuite
=== RUN   Test
2017/06/06 22:07:43 Initializing the SingleNode Config DB on esx [10.160.52.65] 
2017/06/06 22:07:44 START: VsanPolicyTest.TestDeleteVsanPolicyAlreadyInUse
2017/06/06 22:07:44 Creating a vsanPolicy [some-policy] on esx [10.160.52.65]
2017/06/06 22:07:46 Verify vsanPolicy [some-policy] on esx [10.160.52.65] has active as Unused
2017/06/06 22:07:47 policy ls output for vsanPolicy [some-policy] is some-policy  (("proportionalCapacity" i50)("hostFailuresToTolerate" i0))  Unused:
2017/06/06 22:07:47 Creating volume [vsanVol@vsanDatastore] on VM [10.160.51.216]
2017/06/06 22:07:51 Verify vsanPolicy [some-policy] on esx [10.160.52.65] has active as In use by 1 volumes
2017/06/06 22:07:52 policy ls output for vsanPolicy [some-policy] is some-policy  (("proportionalCapacity" i50)("hostFailuresT..  In use by 1 volumes:
2017/06/06 22:07:52 Removing a vsanPolicy [some-policy] on esx [10.160.52.65]
2017/06/06 22:07:54 Remove vsanPolicy "some-policy" returns with Error: Cannot remove. Policy is in use by {'volume': 'vsanVol.vmdk', 'path': '/vmfs/volumes/vsanDatastore/dockvols/11111111-1111-1111-1111-111111111111', 'policy': 'some-policy'}
2017/06/06 22:07:54 END: VsanPolicyTest.TestDeleteVsanPolicyAlreadyInUse
2017/06/06 22:07:54 Removing the SingleNode Config DB on esx [10.160.52.65] 
OK: 1 passed
--- PASS: Test (11.26s)


// CreateVsanPolicy referring to create vsanPolicy
// where --name will be name of the vsanPolicy
CreateVsanPolicy = vmdkopsAdmin + "policy create --name="
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we already have a constant to create policy in the same file. Not sure if this is needed.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't use that. I think in the current code, no use for "CreatePolicy". I will remove it.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is being used. we had a separate PR to introduce a common utils. The change that I merged yesterday had a test to create volume with vsan policy. That uses CreatePolicy

PolicyContent = "'((\"proportionalCapacity\" i50)''(\"hostFailuresToTolerate\" i0))'"

// vsanDatastore is the name of vsanDatastore which will be used in test
vsanDatastore = "vsanDatastore"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

use util govc.GetDatastoreByType to get the name of vsan datastore. This name might be different in different setups.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

vsanDatastore = "vsanDatastore"

// VsanVol1 is the name of volume to be created on vsanDatastore
VsanVol1 = "vsanVol1@" + vsanDatastore
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

use util to get the unique volume name and then append vsan datastore name

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

Copy link
Contributor

@pshahzeb pshahzeb left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Test is good.
I have a few comments about using the latest utils introduced in recent PRs

}

func (s *VsanPolicyTestSuite) SetUpSuite(c *C) {
s.hostIP = os.Getenv("VM1")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

henceforth, we plan to use the common test config introduced in #1286 . You can refer vmgroup tests to see how it that config is consumed.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

res := admincli.VerifyActiveFromVsanPolicyListOutput(s.esxIP, con.PolicyName, "Unused")
c.Assert(res, Equals, true, Commentf("vsanPolicy should be \"Unused\""))

out, err = dockercli.CreateVolumeWithVsanPolicy(s.hostIP, con.VsanVol1, con.PolicyName)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do we need this extra util since using a vsan policy for policy is just a matter of specifying option? we have a util to create volume by options.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

// 6. run "vmdkops_admin policy rm" to remove the policy, which should fail since the volume is still
// use the vsan policy
func (s *VsanPolicyTestSuite) TestDeleteVsanPolicyAlreadyInUse(c *C) {
log.Printf("START: VsanPolicyTest.TestDeleteVsanPolicyAlreadyInUse")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

minor: use the misc util to log start and end of test.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

@@ -172,3 +172,13 @@ func VerifyDetachedStatus(name, hostName, esxName string) bool {
log.Printf("Timed out to poll status\n")
return false
}

// GetVsanPolicyNameVOlumeUsed returns the vsan policy name used by the volume using docker cli
func GetVsanPolicyNameVolumeUsedDockerCli(volName string, hostname string) string {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

quite a big name. I would suggest GetPolicyNameforVol

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

return false
}
log.Printf("policy ls output for vsanPolicy [%s] is %s:", policyName, out)
res := strings.Contains(out, active)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

return strings.Contains directly

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.


out, err = admincli.RemoveVsanPolicy(s.esxIP, con.PolicyName)
log.Printf("Remove vsanPolicy \"%s\" returns with %s", con.PolicyName, out)
c.Assert(out, Matches, "Error: Cannot remove.*", Commentf("vsanPolicy is still used by volumes and cannot be removed"))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this check is good. I think err is also not nil here. Can add one more assert.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

err is Nil here.

// 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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This doesn't look right. Can you please check?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

"log"
"os"

con "github.com/vmware/docker-volume-vsphere/tests/constants/admincli"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about admincliconst?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

// limitations under the License.

// This util holds various helper methods related to vmgroup to be consumed by testcases.
// vmgroup creation, deletion or adding, removing and replacing vm from vmgroup is supported currently.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please fix this. This util does not contains vmgroup helper methods

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

cmd := dockercli.InspectVolume + " --format '{{index .Status \"vsan-policy-name\"}}' " + volName
op, _ := ssh.InvokeCommand(hostname, cmd)
if op == "" {
log.Fatal("Null value is returned by docker cli when looking for attached to vm field for volume. Output: ", op)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should avoid using fatal logs.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

@lipingxue lipingxue force-pushed the vsan_policy_test.liping branch 2 times, most recently from 4f52423 to a4fe92c Compare June 7, 2017 23:30
@lipingxue
Copy link
Contributor Author

@pshahzeb @ashahi1 I have addressed your comments, please review it.

Copy link
Contributor

@shaominchen shaominchen left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good. Some nits below.

@@ -85,4 +85,10 @@ const (

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

// ListPolicy referring to list all existing policys
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: policys => policies

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

// See the License for the specific language governing permissions and
// limitations under the License.

// A home to hold test constants related with vmdkops_admin cli.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please update the comments.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.


package admincli

const (
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since we introduced a separate file to hold VSAN policy specific constants, I think we should move the "CreatePolicy" constant from cmd.go to this file.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

PolicyName = "some-policy"

// PolicyContent is the content of vsan policy which will be used in test
PolicyContent = "'((\"proportionalCapacity\" i50)''(\"hostFailuresToTolerate\" i0))'"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since we introduced this constant, let's use this in the existing code: vsan_test.go: line 82.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

@@ -101,3 +103,41 @@ func (s *VsanTestSuite) TestVSANPolicy(c *C) {

misc.LogTestStart(volCreateTest, "TestVSANPolicy")
}

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's add a brief description about the purpose of this test (even though the test name is pretty clear)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

@@ -29,6 +30,26 @@ func CreatePolicy(ip, name, content string) (string, error) {
return ssh.InvokeCommand(ip, admincli.CreatePolicy+" --name "+name+" --content "+content)
}

// RemovePolicy method is going to remove a policy.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's keep it simple: "RemovePolicy removes a policy."

Please note that in Go language a method is a special function with a receiver argument, i.e. it belongs to a specific type.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.


// VerifyActiveFromVsanPolicyListOutput is going to check, for the given vsan policy, the active
// column returned by "vmdkops policy ls" command is the same as the value specified by
// param @active
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: remove this if there's no meaningful comments for this parameter.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

@@ -188,3 +188,13 @@ func VerifyDetachedStatus(name, hostName, esxName string) bool {
log.Printf("Timed out to poll status\n")
return false
}

// GetPolicyNameForVol returns the vsan policy name used by the volume using docker cli
func GetPolicyNameForVol(volName string, hostname string) string {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In the existing code we are following a convention to put the hostname as the 1st parameter, so let's just follow this.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

@@ -366,7 +366,7 @@ e2e-test-runalways:

e2e-test-runonce:
$(log_target)
$(GO) test -v -timeout 30m -tags runonce $(E2E_Tests)
$(GO) test $(E2E_Tests) -v -timeout 30m -check.f VsanPolicyTestSuite
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please revert this before merge.

// 6. run "vmdkops_admin policy rm" to remove the policy, which should fail since the volume is still
// use the vsan policy
func (s *VsanTestSuite) TestDeleteVsanPolicyAlreadyInUse(c *C) {
misc.LogTestStart("VsanTestSuite", "TestDeleteVsanPolicyAlreadyInUse")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: In the existing tests we are following a convention to use the file name, i.e. "vsan_test" instead of "VsanTestSuite". Both are equally fine, but let's just keep all tests consistent.

It looks like the constant at line 41 is not being used. Let's change it to:
testName = "vsan_test"
And use it in these tests.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

// is shown as "In use by 1 volumes"
// 6. run "vmdkops_admin policy rm" to remove the policy, which should fail since the volume is still
// use the vsan policy
func (s *VsanTestSuite) TestDeleteVsanPolicyAlreadyInUse(c *C) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since we are adding more VSAN related test cases, let's also rename the existing test case "TestVSANPolicy" - the name is too generic. In fact we should split it into two.

I know this request is out of the scope of this PR, but I think the change is straightforward, so I'd suggest to fix it.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

@pshahzeb
Copy link
Contributor

pshahzeb commented Jun 8, 2017

Looks good. Please revert vmdk_plugin/Makefile
Will give LGTM once CI passes. U might want to disable volume_access_test by changing it's tag since we are intermittently hitting the issue tracked through #1371

@lipingxue
Copy link
Contributor Author

@shaominchen @pshahzeb I have addressed your comments and CI is passed too. Please take a look.

Copy link
Contributor

@shaominchen shaominchen left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good. Few more nits below.


// 2. Volume creation with valid policy should pass
// 3. Valid volume should be accessible
func (s *VsanTestSuite) TestVolumeWithValidPolicy(c *C) {
Copy link
Contributor

@shaominchen shaominchen Jun 8, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: I think we can rename this to TestValidPolicy (or TestCreateVolumeWithValidPolicy, which seems too long), and add a comment above.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

// 1. Create an invalid vsan policy (wrong content)
// 2. Volume creation with non existing policy should fail
// 3. Volume creation with invalid policy should fail
func (s *VsanTestSuite) TestVolumeWithInValidPolicy(c *C) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same as above, we can rename this to TestInvalidPolicy and add a comment above.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done


// VerifyActiveFromVsanPolicyListOutput is going to check, for the given vsan policy, whether the active
// column returned by "vmdkops policy ls" command matches the value specified by input param "active"
func VerifyActiveFromVsanPolicyListOutput(ip, policyName, active string) bool {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about renaming this to IsVsanPolicyInUse?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1. VerifyActiveFromVsanPolicyListOutput is too long

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This function is not test whether the vsan policy is in use. It need to test whether the active column from vsan policy output is the same as expected value.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would suggest to be renamed as IsVsanPolicyInUse or IsVsanPolicyActive.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since we are using this function to verify "unused" status as well, I think we can rename it to "verifyVsanPolicyStatus".

@@ -36,6 +38,7 @@ import (
)

const (
vsanTest = "vsan_test"
vsanVolumeTest = "vsan_vol"
vsanPolicyFlag = "vsan-policy-name"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this should be part of tests/constants/admincli/vsanpolicy.go

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Those const are only used in this file locally.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I meant for vsan-policy-name, shouldn't it be moved to tests/constants/admincli/vsanpolicy.go?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we only need to put const which need to me shared across the package to /tests/constants/...

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

correct!

By taking vsanOpts := " -o " + vsanPolicyFlag + "=" + policyName as an example; it is going to be consumed by multiple files in the future.

Anyway this is a trivial comment, my only intention is to avoid future refactoring.

// 2. Volume creation with valid policy should pass
// 3. Valid volume should be accessible
func (s *VsanTestSuite) TestVolumeWithValidPolicy(c *C) {
misc.LogTestStart(vsanTest, "TestVolumeWithValidPolicy")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

as discussed during standup today .. let's use c.TestName and avoid using local constant.

Reference: #1368

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

@@ -150,3 +150,13 @@ func VerifyDetachedStatus(name, hostName, esxName string) bool {
log.Printf("Timed out to poll status\n")
return false
}

// GetPolicyNameForVol returns the vsan policy name used by the volume using docker cli
func GetPolicyNameForVol(hostname string, volName string) string {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. better home should be tests/utils/dockercli so the reference will be dockercli. GetPolicyNameForVol

  2. how about renaming to GetAssociatedPolicyName()?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think we should move this function to test/utils/dockercli. This function is used to get some volume attribute, which is the same as existing function in this file.

// GetPolicyNameForVol returns the vsan policy name used by the volume using docker cli
func GetPolicyNameForVol(hostname string, volName string) string {
cmd := dockercli.InspectVolume + " --format '{{index .Status \"vsan-policy-name\"}}' " + volName
op, _ := ssh.InvokeCommand(hostname, cmd)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is there a reason for ignoring error field? Util may return err field to testcase and let test case to fail with proper message.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

PolicyContent = "'((\"proportionalCapacity\" i50)''(\"hostFailuresToTolerate\" i0))'"

// CreatePolicy Create a policy
CreatePolicy = vmdkopsAdmin + " policy create "
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

Copy link
Contributor

@shaominchen shaominchen left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM.

}

// Steps:
// 1. Create an invalid vsan policy (wrong content)
// 2. Volume creation with non existing policy should fail
// 3. Volume creation with invalid policy should fail
func (s *VsanTestSuite) TestVolumeWithInValidPolicy(c *C) {
misc.LogTestStart(vsanTest, "TestVolumeWithInValidPolicy")
func (s *VsanTestSuite) TestInValidPolicy(c *C) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: InValid => Invalid

Copy link
Contributor

@shuklanirdesh82 shuklanirdesh82 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

Please address open comments before merging in.

out, err = admincli.RemovePolicy(s.config.EsxHost, adminclicon.PolicyName)
log.Printf("Remove vsanPolicy \"%s\" returns with %s", adminclicon.PolicyName, out)
c.Assert(out, Matches, "Error: Cannot remove.*", Commentf("vsanPolicy is still used by volumes and cannot be removed"))

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Need to add following verification after removing policy.

invoke ListPolicy (admincli policy ls) and make sure the policy adminclicon.PolicyName is not part of the output ... that validate the policy removal part.

@lipingxue lipingxue merged commit 8ed1887 into master Jun 10, 2017
@shuklanirdesh82 shuklanirdesh82 deleted the vsan_policy_test.liping branch November 10, 2017 05:30
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants