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

Verify properties (disk-format, capacity, attached-to-vm) of a volume at vm and esx. #831

Merged

Conversation

ashahi1
Copy link
Contributor

@ashahi1 ashahi1 commented Dec 20, 2016

Replaces and extends #825 (Add a test to verify the capacity of the volume created using vmkfstools)

====
Fixes #847 (Test to verify the 'Attached to VM' field for volume)
Fixes #848 (Test to verify 'Disk Format' field for volume )
Fixes #824 (End_to_End test to verify the size of volume using admin cli and docker cli )

I have tested this latest change by running tests locally on setup consisting of one Esx and two VMs.

Test output:
=== RUN TestVolumeProperties
2017/02/15 07:40:35 running end_to_end tests - current time: 2017-02-15 07:40:35.882135039 +0000 UTC
2017/02/15 07:40:35 Running test on VM - 10.160.196.62
2017/02/15 07:40:36 Docker version: Docker version 1.12.6, build 78d1802

2017/02/15 07:40:36 Creating a volume of Format Type - thin
2017/02/15 07:40:41
successfully created a volume -- dockerVol_1487144436
2017/02/15 07:41:08 Creating a volume of Format Type - zeroedthick
2017/02/15 07:41:13
successfully created a volume -- dockerVol_1487144468
2017/02/15 07:41:40 Creating a volume of Format Type - eagerzeroedthick
2017/02/15 07:41:45
successfully created a volume -- dockerVol_1487144500
--- PASS: TestVolumeProperties (96.77s)
PASS

@ashahi1 ashahi1 self-assigned this Dec 20, 2016
@msterin
Copy link
Contributor

msterin commented Dec 20, 2016

The test LGTM. Do we still need #825 ??

self.assertEqual(os.path.isfile(self.name), True,
"VMDK {0} is missing after create.".format(self.name))
response = vmdkops_admin.get_vmdk_size_info(path=self.name)
head = s.rstrip('bgtmk')
Copy link
Contributor

Choose a reason for hiding this comment

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

why do we have 'k' here?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

'k' was only added for KB

Copy link
Contributor

Choose a reason for hiding this comment

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

Please remove that as input is sizes = ['21gb', '20tb', '200mb']

Copy link
Contributor Author

Choose a reason for hiding this comment

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

OK. I will remove 'k'.

response = vmdkops_admin.get_vmdk_size_info(path=self.name)
head = s.rstrip('bgtmk')
tail = s[len(head):]
self.assertEqual(response["capacity"], "{0:.2f}".format(float(head))+ tail.upper(),\
Copy link
Contributor

Choose a reason for hiding this comment

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

we can simply compare the outcome of response["capacity"] with the expected in this case 's' .. there is no need for extra steps of head and tail ..

Copy link
Contributor Author

Choose a reason for hiding this comment

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

If size of vmdk is 21gb, response we are getting is 21.00GB.
Objective behind passing 21gb to create_vmdk is to verify create_vmdk works if we specify unit is small.

@ashahi1
Copy link
Contributor Author

ashahi1 commented Dec 21, 2016

@msterin No, we do not need #825 after this PR #831 . I wasn't sure if I can close it hence I left it open for the time being.

@shuklanirdesh82
Copy link
Contributor

need to extend verification highlighted at #835

@@ -38,6 +38,7 @@
import auth_api
import error_code
import vmdk_utils
import vmdkops_admin
Copy link
Contributor

Choose a reason for hiding this comment

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

Come across #472 ... I would suggest to limit the dependency on the product code/module and breakdown the utility method for testing purpose.

On a side note this test case was for vmdk_ops and we are creating unnecessary dependency on vmdkops_admin for consuming utility from _admin.

@shuklanirdesh82 shuklanirdesh82 changed the title Verify the size of vmdk with the size reported by vmkfstools Verify the size of vmdk with the size reported by vmkfstools and admin_cli command Dec 21, 2016
@msterin
Copy link
Contributor

msterin commented Jan 10, 2017

this is quite old .... any updates ?

@shuklanirdesh82
Copy link
Contributor

shuklanirdesh82 commented Jan 11, 2017

spoke to @ashahi1 , he is currently working on the change and will update the PR soon.

@ashahi1 ashahi1 force-pushed the issueVerifyVmdkSize-new branch 2 times, most recently from 94e249e to a7ddef4 Compare January 12, 2017 23:44
@shuklanirdesh82
Copy link
Contributor

@ashahi1 seeing some unrelated commits to your PR. You may want to refresh the commit by squashing correctly.

@msterin
Copy link
Contributor

msterin commented Jan 23, 2017

@ashahi1 - if the PR is still being worked on, please close it for now and reopen when it's ready.
If it is ready, then please squash commits properly , as @shuklanirdesh82 requested (no unrelated stuff please) and ping us to review.

@ashahi1
Copy link
Contributor Author

ashahi1 commented Jan 23, 2017

@msterin Yes, I will squash the commits and ping for review.

@ashahi1 ashahi1 force-pushed the issueVerifyVmdkSize-new branch 2 times, most recently from b7b49af to f2a3ff9 Compare January 24, 2017 17:21
@ashahi1
Copy link
Contributor Author

ashahi1 commented Jan 25, 2017

@msterin @shuklanirdesh82 @kerneltime - Please review the changes

Test tries to ssh to photon vm and esx and verifies the capacity, disk format, attached-to-vm fields are same for volume at the vm as well as at the esx.

We do the same steps across both the vms.

op := TestUtil.ExecuteCmd(cmd, vms[i])
if strings.Contains(op, "testVolume_0") {
cmd := "docker volume rm testVolume_0"
TestUtil.ExecuteCmd(cmd, esx)
Copy link
Contributor

Choose a reason for hiding this comment

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

esx ?? This line should be failed ... what is the value set for esx?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Using InvokeCommand method.

@@ -0,0 +1,130 @@
package e2e_test
Copy link
Contributor

Choose a reason for hiding this comment

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

need copyright information

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added the copyright information.

}
}

func TestVolumeProperties(t *testing.T) {
Copy link
Contributor

Choose a reason for hiding this comment

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

It should be better to have test steps information to get better review; steps would be helpful for future reference too.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added the steps.

}

func TestVolumeProperties(t *testing.T) {
defer teardownFunction()
Copy link
Contributor

Choose a reason for hiding this comment

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

isn't this redundant?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed it.

dkrVrsn := TestUtil.GetDockerVersion(vms[j])
fmt.Println("---- ", dkrVrsn)
if strings.Contains(dkrVrsn, "Docker version 1.11.") {
fmt.Println("Since docker version is less than 1.12, skipping test on this host")
Copy link
Contributor

Choose a reason for hiding this comment

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

we have decided to skip the verification not the test, need to address that comment.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed it.

func GetDiskFormat_AdminCli(volName string, hostname string) string {
cmd := "/usr/lib/vmware/vmdkops/bin/vmdkops_admin.py ls -c volume,disk-format | grep " + volName
io := ExecuteCmd(cmd, hostname)
if strings.Contains(io, "stty: standard input: Inappropriate ioctl for device") {
Copy link
Contributor

Choose a reason for hiding this comment

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

#58 - #60 can be replaced by appending 2>/dev/null to the command as it is being ignored here

io := ExecuteCmd(cmd, hostname)
volProps := strings.Fields(io)
i := 0
for range volProps {
Copy link
Contributor

Choose a reason for hiding this comment

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

can you help me to understand this code block? or you may want to add some inline comment for better review

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added the comments to the function

// returns attached to vm field of volume using docker cli
func GetVmAttachedToVol_DockerCli(volName string, hostname string) string {
cmd := "docker volume inspect " + volName
io := ExecuteCmd(cmd, hostname)
Copy link
Contributor

Choose a reason for hiding this comment

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

this code has been copied atleast 3 times .. it should be properly organized by moving into separate util.

}

// ssh to the vm and executes the command
func ExecuteCmd(cmd 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.

we do have InvokeCommand .. please try to reuse or improve further by keeping only one copy

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.

@ashahi1 ashahi1 force-pushed the issueVerifyVmdkSize-new branch 7 times, most recently from 40140a7 to 7c8f7f3 Compare February 4, 2017 09:04
// method checks if the output from the ssh commands contains the expected values
func contains(volmProps []string, op string) bool {
for i := 0; i < len(volmProps); i++ {
if !strings.Contains(op, volmProps[i]) {
Copy link
Contributor

Choose a reason for hiding this comment

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

oh wait! some confusion here .. what if ssh command's output contains additional values compare with the expected one? We are going to miss some serious bug if additional output returns back.

}

// method checks if the output from the ssh commands contains the expected values
func contains(volmProps []string, op 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.

need to improve method name .. it is misleading and lead to confusion with strings.contain() method

@@ -0,0 +1,91 @@
// Copyright 2017 VMware, Inc. All Rights Reserved.
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 rename this file name something like VolumePropertiesVerificationUtil.go certainly not VolumePropertiesUtil.go

func GetVmAttachedToVolUsingDockerCli(volName string, hostname string) string {
cmd := DOCKER_CLI_INSPC + " --format '{{index .Status \"created by VM\"}}' " + volName
op := ExecCmd(hostname, cmd)
return strings.TrimSpace(string(op))
Copy link
Contributor

Choose a reason for hiding this comment

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

some confusion here .. ExecCmd returns string .. I don't think we need to convert it again at line 35

cmd := ADMIN_CLI_LS + "-c volume,attached-to 2>/dev/null | grep " + volName
op := ExecCmd(hostname, cmd)
volProps := strings.Fields(op)
return string(volProps[1])
Copy link
Contributor

Choose a reason for hiding this comment

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

This raises a serious concern by taking account of the common code...

some thoughts

  1. what happens op is null or empty i.e. the asked volume not found .. this util will not be useful
  2. let's say there is a bug in the system and return duplicates .. this approach is dangerous as it is returning 1st index.

func GetVolumePropertiesAdminCli(volName string, hostname string) string {
cmd := ADMIN_CLI_LS + "-c volume,attached-to,capacity,disk-format 2>/dev/null | grep " + volName
op := ExecCmd(hostname, cmd)
return string(op)
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

func GetVolumePropertiesDockerCli(volName string, hostname string) string {
cmd := DOCKER_CLI_INSPC + " --format '{{index .Status.capacity.size}} {{index .Status.diskformat}} {{index .Status \"attached to VM\"}}' " + volName
op := ExecCmd(hostname, cmd)
return string(op)
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

//method takes command and host and calls InvokeCommand
//and then returns the output after converting to string
func ExecCmd(hostname string, cmd string) string {
io, err := TestUtil.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.

io .. what does it mean?

// So this method can be useful if we
// do not want to run certain verifications
// on docker 1.11
func IsDockerCliCheckNeeded(hostname 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.

does it hold IPAddr or Name?

IMO, variable name should reflect its meaning.

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.

Overall looks fine to me ... supplying some comments for your review.

@msterin msterin changed the title [End-to-End test] Verify properties (disk-format, capacity, attached-to-vm) of a volume at vm and esx. Issue #847, #848 and #824. Verify properties (disk-format, capacity, attached-to-vm) of a volume at vm and esx. Feb 15, 2017

var (
esx string = os.Getenv("ESX")
volSizes = []string{"100MB"}
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: the code is either misaligned or has some tabs - can you check it ?

}
if len(strings.Fields(op)) != expctedLen {
log.Println("Actual docker cli inspect output when looking for size, disk-format and attached to vm - ", string(op))
log.Fatal("Docker cli inpect output is expected to consist of three elements only - size, disk-format and attached-to-vm status")
Copy link
Contributor

Choose a reason for hiding this comment

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

the overall message looks weird Why to Prinln and then Fatal instead of single Fatal , multi-lined ? That applies to multiple places where PrintLn();Fatal() is used

@ashahi1 ashahi1 force-pushed the issueVerifyVmdkSize-new branch 3 times, most recently from 31b0a90 to a93c601 Compare February 15, 2017 17:58
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.

It seems some of the comments were not addressed so providing required changes and providing contingent approval on the CI pass after addressing few comments.

// Properties being verified - capacity, disk-format and vm-attached field.

// Test assumes that SSH cert has been setup to enable password-less login
package e2e_test.
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: need to remove period . from package name.

formatTypes = []string{"thin", "zeroedthick", "eagerzeroedthick"}
vmIp string = ""
dockerVolmRmvCmd string = "docker volume rm "
dockerCliCheck bool = true
Copy link
Contributor

Choose a reason for hiding this comment

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

no need to initialize value here ... let the method decide what to set for dockerCliCheck

volmPropertiesDkrCli := TestUtil.GetVolumePropertiesDockerCli(volName, vms[vmIndx])
expctdPropsDkr := []string{"100MB", formatTypes[k], "<no value>"}
if !hasElement(expctdPropsDkr, volmPropertiesDkrCli) {
log.Fatal("Volume properties on admin cli do not matches the expected values")
Copy link
Contributor

Choose a reason for hiding this comment

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

logging statement needs to be corrected ... while checking against docker cli outcome; logging should not be about "admin cli"

volmPropertiesDkrCli := TestUtil.GetVolumePropertiesDockerCli(volName, vms[vmIndx])
expctdPropsDkr := []string{"100MB", formatTypes[k]}
if !hasElement(expctdPropsDkr, volmPropertiesDkrCli) {
log.Fatal("Volume properties on ESX fetcchced using admin cli do not matches the expected values")
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

  1. logging is misleading
  2. fetcchced ??

log.Fatal("Volume properties on admin cli do not matches the expected values")
}
}
TestUtil.InvokeCommand(vms[vmIndx], "docker run -d -v "+volName+":/vol --name e2e busybox tail -f /dev/null")
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 offline: better to randomize container name to avoid cascading failure if test stops abruptly

@ashahi1 ashahi1 force-pushed the issueVerifyVmdkSize-new branch 5 times, most recently from 746abaa to ea6b455 Compare February 16, 2017 22:09
Run test across both the VMs.

Cleaned up the code

Unique name for each volume

Used TestUtil.InvokeCommand

Addressed review comments from Nirdesh

Review comments from Nirdesh addressed

Trivial change to restart CI run

Modified the log output

Minor change in log stmt to restart CI run

CI didn't pick the last changes so pushing again

Change to restart CI run

Restarting CI run

Run test on only one VM

Trivial change so that CI run can restart

Addressed recent comments from Nirdesh - still incomplete

Addressed review comments

Change to restart CI run

Addressed Nirdesh's comments

Minor change to restart CI run

Modified test clean-up

Previous changes were not picked up by drone, hence re-pushing to restart the CI run

Restarting CI

More logging to figure out time-out failure on one particular host

Modified deploy-and-test-wrapper to only run end-to-end test

Restarting CI run

Trivial change to restart CI

Restarting CI as previous run failed due to - Issue 887

Refactoring cleanup code

Re-pushing to start new CI run. Last CI run failed because of - Issue 878

Repushing to restart CI run - Issue 887

Re-pushing to restart CI run as last run failed because of Issue - 887

Pushing to restart CI

Push to restart CI run

Contains changes from PR - 894

Running test-esx and test-vm as well with E2E tests

Making changes so that test picks VM2

Repushing to restart CI

Repushing to CI

Repushing to start CI

Push to restart CI

Push to restart CI

Addressed Mark's review comments

Push to restart CI

Reverted deploy-and-test-wrapper.sh

Restart CI

Addressed review comments from Nirdesh

Reverted changes to misc/drone-scripts/setup.sh

Restart CI

Rebased feature branch with master

Pushing to restart CI

Pushing to restart CI run

Created a seperate util class consisting of methods that return properties of volume like cpacity, disk-format and attached-to-vm fields using docker cli and admin cli

Push to restart CI run

Restarting CI

Addressed latest review comments from Nirdesh

Added the new file

Removing unnecessary log statements

Addressed review comments from Mark

Re-pushing with trivial change to restart CI run as previous run failed due to - no route to host

Improved logging

Aligned a piece of code

Push to restart CI

Addressed latest review comments from Nirdesh.

Trivial change to restart CI run as previous run failed due to - no route to host

Saving the current changes

Repushing after taking latest changes from vmware master

Previous changes were not picked by CI, hence repushing

Previous run failed due to 'no route to host' hence repushing to restart ci

Pushing to restart CI.
containerName = "busybox_" + strconv.FormatInt(time.Now().Unix(), 20)
log.Println("Creating a volume of Format Type - ", formatTypes[k])
volName := TestInputParamsUtil.GetVolumeNameWithTimeStamp("dockerVol")
_, err := TestUtil.InvokeCommand(vms[vmIndx], "docker volume create --driver=vmdk --name="+volName+" -o size="+volSizes[i]+" -o diskformat="+formatTypes[k])
Copy link
Contributor

Choose a reason for hiding this comment

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

nit - this line is WAY to looong.

@shuklanirdesh82 shuklanirdesh82 merged commit 52376c8 into vmware-archive:master Feb 17, 2017
@ashahi1 ashahi1 deleted the issueVerifyVmdkSize-new branch June 8, 2017 00:12
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.

None yet

4 participants