-
Notifications
You must be signed in to change notification settings - Fork 95
[Automation] Restart test 1 on plugin side #1265
Conversation
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.
Great job done - overall looks neat and clean! A few comments below.
tests/e2e/restart_test.go
Outdated
package e2e | ||
|
||
import ( | ||
"os" |
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 use 4-space indention consistently.
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.
gofmt
does that part ... no need to perform such step.
tests/e2e/restart_test.go
Outdated
"os" | ||
"testing" | ||
|
||
. "gopkg.in/check.v1" |
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 add the reference link (http://labix.org/gocheck) in the PR description to make the reviewer's life easier :)
tests/e2e/restart_test.go
Outdated
|
||
func (s *PluginSuite) SetUpTest(c *C) { | ||
s.volumeName = testparams.GetVolumeNameWithTimeStamp("abc") | ||
s.hostName = os.Getenv("VM2") |
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.
Any specific reason to use VM2 instead of 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.
Was debugging failure on CI, if it is photon(vm1) or ubuntu(vm2) issue.
It wasn't the reason. This can be either VM
// AttachVolume - attach volume to container on given host | ||
func AttachVolume(host, volName, containerName string) ([]byte, error) { | ||
fmt.Printf("Attaching volume [%s] on VM[%s]\n", volName, host) | ||
return InvokeCommand(host, "docker run -d -v "+volName+ |
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: let's add space before and after + operator.
BTW, are you using VS Code as the editor? VS Code plugins should be able to correct code style issues automatically.
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 .. gofmt
runs as part of the build target which auto corrects the formatting.
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.
gofmt removes the spaces
" busybox tail -f /dev/null") | ||
} | ||
|
||
// DeleteVolume - deletes the created volume as per passed volume name. | ||
func DeleteVolume(name string, ip string) ([]byte, error) { |
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 noticed that the APIs defined in these utils are not consistent: some APIs have hostName (or ip) as the 1st parameter, some others have it as the 2nd or last parameter. This inconsistency makes the APIs difficult to use. Can we fix all of them together?
} | ||
|
||
// PollStatusDetached - check if the status gets detached within the timeout | ||
func PollStatusDetached(name, ip string, timeout int) 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.
Can we improve this API to make it generic to support polling both attached and detached status?
Moreover, I'd prefer not to expose the timeout parameter, because it will not only simplify the API client, but also avoid changing multiple places if the default timeout value turns out inappropriate (too long or too short).
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. not exposing timeout and making it constant as of now.
9781674
to
332d31b
Compare
tests/e2e/restart_test.go
Outdated
|
||
out, err = dockercli.AttachVolume(s.hostName, s.volumeName, s.containerName) | ||
c.Assert(err, IsNil, Commentf(vf.FormatOutput(out))) | ||
|
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 to add verification step using docker cli as well as admincli to check whether volume is attached or not.
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.
@@ -107,6 +141,11 @@ func ExecCmd(hostname string, cmd string) string { | |||
return string(out[:]) | |||
} | |||
|
|||
// FormatOutput - convert output of a command to a string | |||
func FormatOutput(out []byte) 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.
It is better to be part of separate util, definitely not as verification util.
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
sshutil "github.com/vmware/docker-volume-vsphere/tests/utils/dockercli" | ||
) | ||
|
||
var adminCliLs = "/usr/lib/vmware/vmdkops/bin/vmdkops_admin.py volume ls " | ||
var dockerCliInspect = "docker volume inspect " | ||
|
||
const ( | ||
//DetachedStatus - volume detached | ||
DetachedStatus = "detached" |
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: you may want to consider it moving to separate constant 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.
moving it to constants package
return InvokeCommand(ip, "docker rm -f "+containerName) | ||
} | ||
|
||
// InvokeCommand - can be consumed by test directly to invoke |
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 you are here: can you please move this util out of 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
} | ||
|
||
// CleanContainer - clean the container (stops and removes it) | ||
func CleanContainer(ip, containerName string) ([]byte, error) { |
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.
CleanContainer
sounds confusing to me .. would it be better to rename as RemoveContainer
or "DeleteContainer" .... would prefer RemoveContainer
instead
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/restart_test.go
Outdated
|
||
status := vf.PollStatus(s.volumeName, vf.DetachedStatus, s.hostName) | ||
c.Assert(status, Equals, true, Commentf("Volume %s is still attached", s.volumeName)) | ||
|
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 verification step using admin_cli volume ls
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.
Yes. Thanks for pointing this.
Added verification for attach and detach. Keeping these checks separate as of now because,
in attached mode, we also verify the the VM name to which volume is attached is same on docker host and esx side.
Also we dont really need to keep trying again to verify attach status, it only happens in detach.
tests/e2e/restart_test.go
Outdated
) | ||
|
||
// Hook up gocheck into the "go test" runner. | ||
func TestRestart(t *testing.T) { TestingT(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.
Nirdesh just did a test - this hook up should be done only once in the whole test group. Otherwise, if we add another test file which also set this hook-up, then all the test cases in two files will be run twice.
So we should have a separate file to hook up this only once.
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.
moving this to init_test.go
332d31b
to
75ac4f0
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.
over all looks good to me .. please have a look at some minor comments
tests/constants/admincli/cmd.go
Outdated
@@ -25,4 +25,9 @@ const ( | |||
|
|||
// ListVolumes referring to vmdkops_admin volume ls | |||
ListVolumes = vmdkopsAdminVolume + "ls " | |||
|
|||
//DetachedStatus - volume detached |
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.
admincli is not better home .. please move this const out .. it leads to confusion.
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/init_test.go
Outdated
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
package e2e |
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: Please add the package level description here to shed some idea on objective of 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
tests/e2e/restart_test.go
Outdated
s.volumeName = inputparams.GetVolumeNameWithTimeStamp("abc") | ||
s.hostName = os.Getenv("VM2") | ||
s.esxName = os.Getenv("ESX") | ||
s.containerName = "busybox_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.
better to randomize this name 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.
done
// remoteHostIP value | ||
func InvokeCommand(remoteHostIP string, cmd string) ([]byte, error) { | ||
return exec.Command("/usr/bin/ssh", append(sshIdentity, "root@"+remoteHostIP, cmd)...).CombinedOutput() | ||
// RemoveContainer - clean the container (stops and removes 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.
nit: clean the container
sounds confusing .. need to improve the method inline doc
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 suggest what needs to be improved?
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.
clean the container (stops and removes it)
=> delete/remove the container forcefully (stops and removes/deletes it)
vmdk_plugin/Makefile
Outdated
@@ -101,7 +101,9 @@ SRC = main.go log_formatter.go utils/refcount/refcnt.go \ | |||
|
|||
TEST_SRC = ../tests/utils/inputparams/testparams.go \ | |||
../tests/utils/dockercli/volumelifecycle.go \ | |||
../tests/utils/verification/volumeproperties.go | |||
../tests/utils/verification/volumeproperties.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.
no need to add all this here .. can you explain why is the need 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.
Did it in alignment with other utils (line 102,103). required to build test files. If not required, should we remove all of them?
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 far as I remember .. IIRC /tests/utils/inputparams/testparams.go
is the only need .. can you verify by adjusting .. keep only the required one and knock of irrelevant.
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
return exec.Command("/usr/bin/ssh", append(sshIdentity, "root@"+remoteHostIP, cmd)...).CombinedOutput() | ||
// RemoveContainer - clean the container (stops and removes it) | ||
func RemoveContainer(ip, containerName string) ([]byte, error) { | ||
return ssh.InvokeCommand(ip, "docker rm -f "+containerName) |
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.
couple things here
- "docker rm -f" move as constant
- need to check spacing before/after
+
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.
gofmt is removing space for me for + operators used inside parenthesis
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.
moved all docker related constants to constants package
vmAttachedHost := GetVMAttachedToVolUsingDockerCli(name, hostName) | ||
vmAttachedESX := GetVMAttachedToVolUsingAdminCli(name, esxName) | ||
|
||
return (vmAttachedHost == vmAttachedESX) |
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 is kind of alarming ... need to add one more check against our expectation. expectedAttachStatus == vmAttachedHost & vmAttachedESX
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 .. let's add inline comment that no way to know about expected vmname and need to rely on vmAttachedHost == vmAttachedESX until we come up with govmomi integration to know about the vm 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.
We have a todo to verify the name of VM with the name from IP. Can be done incrementally.
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 point me to the line?
return true | ||
} | ||
} | ||
log.Printf("Timed out to poll status\n") |
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.
would suggest to use log.Warn
or log.Error
instead of log.Printf
that helps during debugging test failure
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. Using log.Fatalf.
e167e6f
to
4a4f512
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.
Great work!! LGTM
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.
All look great, except that we should have a better name for "restart_test". We can rename it later if there are any ambiguity with other new test suites.
This PR automates test 1 from #1252
Its the part of e2e tests
Usage for gocheck : http://labix.org/gocheck