-
Notifications
You must be signed in to change notification settings - Fork 95
Verify properties (disk-format, capacity, attached-to-vm) of a volume at vm and esx. #831
Verify properties (disk-format, capacity, attached-to-vm) of a volume at vm and esx. #831
Conversation
The test LGTM. Do we still need #825 ?? |
esx_service/vmdk_ops_test.py
Outdated
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') |
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.
why do we have 'k' here?
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.
'k' was only added for KB
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 remove that as input is sizes = ['21gb', '20tb', '200mb']
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.
OK. I will remove 'k'.
esx_service/vmdk_ops_test.py
Outdated
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(),\ |
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 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 ..
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.
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.
need to extend verification highlighted at #835 |
esx_service/vmdk_ops_test.py
Outdated
@@ -38,6 +38,7 @@ | |||
import auth_api | |||
import error_code | |||
import vmdk_utils | |||
import vmdkops_admin |
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.
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.
this is quite old .... any updates ? |
spoke to @ashahi1 , he is currently working on the change and will update the PR soon. |
94e249e
to
a7ddef4
Compare
@ashahi1 seeing some unrelated commits to your PR. You may want to refresh the commit by squashing correctly. |
@ashahi1 - if the PR is still being worked on, please close it for now and reopen when it's ready. |
@msterin Yes, I will squash the commits and ping for review. |
b7b49af
to
f2a3ff9
Compare
@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) |
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.
esx ?? This line should be failed ... what is the value set for esx?
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.
Using InvokeCommand method.
@@ -0,0 +1,130 @@ | |||
package e2e_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.
need copyright information
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.
Added the copyright information.
} | ||
} | ||
|
||
func TestVolumeProperties(t *testing.T) { |
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 should be better to have test steps information to get better review; steps would be helpful for future reference too.
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.
Added the steps.
} | ||
|
||
func TestVolumeProperties(t *testing.T) { | ||
defer teardownFunction() |
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.
isn't this redundant?
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.
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") |
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 have decided to skip the verification not the test, need to address that comment.
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.
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") { |
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.
io := ExecuteCmd(cmd, hostname) | ||
volProps := strings.Fields(io) | ||
i := 0 | ||
for range volProps { |
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.
can you help me to understand this code block? or you may want to add some inline comment for better review
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.
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) |
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 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 { |
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 do have InvokeCommand
.. please try to reuse or improve further by keeping only one copy
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.
40140a7
to
7c8f7f3
Compare
// 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]) { |
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.
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 { |
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 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. |
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 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)) |
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.
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]) |
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 raises a serious concern by taking account of the common code...
some thoughts
- what happens op is null or empty i.e. the asked volume not found .. this util will not be useful
- 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) |
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
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) |
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
//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) |
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.
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 { |
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.
does it hold IPAddr or Name?
IMO, variable name should reflect its meaning.
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.
Overall looks fine to me ... supplying some comments for your review.
4adade1
to
22c17e0
Compare
|
||
var ( | ||
esx string = os.Getenv("ESX") | ||
volSizes = []string{"100MB"} |
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: 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") |
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.
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
31b0a90
to
a93c601
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.
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. |
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: need to remove period .
from package name.
formatTypes = []string{"thin", "zeroedthick", "eagerzeroedthick"} | ||
vmIp string = "" | ||
dockerVolmRmvCmd string = "docker volume rm " | ||
dockerCliCheck bool = true |
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.
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") |
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.
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") |
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
- logging is misleading
- 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") |
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 offline: better to randomize container name to avoid cascading failure if test stops abruptly
746abaa
to
ea6b455
Compare
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.
ea6b455
to
ec9c6e9
Compare
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]) |
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 - this line is WAY to looong.
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