-
Notifications
You must be signed in to change notification settings - Fork 95
Conversation
tests/constants/admincli/cmd.go
Outdated
|
||
// CreateVsanPolicy referring to create vsanPolicy | ||
// where --name will be name of the vsanPolicy | ||
CreateVsanPolicy = vmdkopsAdmin + "policy create --name=" |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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" |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
+1
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
There was a problem hiding this 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
tests/e2e/vsan_policy_test.go
Outdated
} | ||
|
||
func (s *VsanPolicyTestSuite) SetUpSuite(c *C) { | ||
s.hostIP = os.Getenv("VM1") |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
tests/e2e/vsan_policy_test.go
Outdated
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) |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
tests/e2e/vsan_policy_test.go
Outdated
// 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") |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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 { |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
tests/utils/admincli/vsan_policy.go
Outdated
return false | ||
} | ||
log.Printf("policy ls output for vsanPolicy [%s] is %s:", policyName, out) | ||
res := strings.Contains(out, active) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
return strings.Contains directly
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
tests/e2e/vsan_policy_test.go
Outdated
|
||
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")) |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
err is Nil here.
tests/e2e/vsan_policy_test.go
Outdated
// 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 |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
tests/e2e/vsan_policy_test.go
Outdated
"log" | ||
"os" | ||
|
||
con "github.com/vmware/docker-volume-vsphere/tests/constants/admincli" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How about admincliconst?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
tests/utils/admincli/vsan_policy.go
Outdated
// 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. |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
4f52423
to
a4fe92c
Compare
There was a problem hiding this 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.
tests/constants/admincli/cmd.go
Outdated
@@ -85,4 +85,10 @@ const ( | |||
|
|||
// ReadWriteAccess read-write rights for the volume | |||
ReadWriteAccess = "read-write" | |||
|
|||
// ListPolicy referring to list all existing policys |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: policys => policies
There was a problem hiding this comment.
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. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please update the comments.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
|
||
package admincli | ||
|
||
const ( |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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))'" |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
tests/e2e/vsan_test.go
Outdated
@@ -101,3 +103,41 @@ func (s *VsanTestSuite) TestVSANPolicy(c *C) { | |||
|
|||
misc.LogTestStart(volCreateTest, "TestVSANPolicy") | |||
} | |||
|
There was a problem hiding this comment.
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)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
tests/utils/admincli/cmd.go
Outdated
@@ -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. |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
tests/utils/admincli/cmd.go
Outdated
|
||
// 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 |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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 { |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
vmdk_plugin/Makefile
Outdated
@@ -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 |
There was a problem hiding this comment.
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.
tests/e2e/vsan_test.go
Outdated
// 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") |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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) { |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
Looks good. Please revert vmdk_plugin/Makefile |
a4fe92c
to
a164d12
Compare
@shaominchen @pshahzeb I have addressed your comments and CI is passed too. Please take a look. |
There was a problem hiding this 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.
tests/e2e/vsan_test.go
Outdated
|
||
// 2. Volume creation with valid policy should pass | ||
// 3. Valid volume should be accessible | ||
func (s *VsanTestSuite) TestVolumeWithValidPolicy(c *C) { |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
tests/e2e/vsan_test.go
Outdated
// 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) { |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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 { |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
.
There was a problem hiding this comment.
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".
tests/e2e/vsan_test.go
Outdated
@@ -36,6 +38,7 @@ import ( | |||
) | |||
|
|||
const ( | |||
vsanTest = "vsan_test" | |||
vsanVolumeTest = "vsan_vol" | |||
vsanPolicyFlag = "vsan-policy-name" |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
?
There was a problem hiding this comment.
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/...
There was a problem hiding this comment.
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.
tests/e2e/vsan_test.go
Outdated
// 2. Volume creation with valid policy should pass | ||
// 3. Valid volume should be accessible | ||
func (s *VsanTestSuite) TestVolumeWithValidPolicy(c *C) { | ||
misc.LogTestStart(vsanTest, "TestVolumeWithValidPolicy") |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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 { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
-
better home should be
tests/utils/dockercli
so the reference will be dockercli. GetPolicyNameForVol -
how about renaming to
GetAssociatedPolicyName()
?
There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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 " |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is better to append --name=
e.g. https://github.com/vmware/docker-volume-vsphere/blob/master/tests/constants/admincli/cmd.go#L37
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
Move the test code to vsan_test.go and delete unused files. Minor fix.
Address comments from Sam. Minor fix.
a164d12
to
c295eca
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM.
tests/e2e/vsan_test.go
Outdated
} | ||
|
||
// 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) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: InValid => Invalid
There was a problem hiding this 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")) | ||
|
There was a problem hiding this comment.
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.
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: