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

[Automation] Restart test 1 on plugin side #1265

Merged
merged 1 commit into from
May 18, 2017
Merged

Conversation

pshahzeb
Copy link
Contributor

@pshahzeb pshahzeb commented May 16, 2017

This PR automates test 1 from #1252

Its the part of e2e tests

Usage for gocheck : http://labix.org/gocheck

=== RUN   TestRestart
Creating volume [abc_1494954324] on VM [10.192.99.52]
Attaching volume [abc_1494954324] on VM[10.192.99.52]
Killing docker on VM [10.192.99.52]
Confirming detached status for volume [abc_1494954324]
Destroying volume [abc_1494954324]
OK: 1 passed
--- PASS: TestRestart (37.61s)

@pshahzeb pshahzeb changed the title Automating restart test 1 on plugin side [Automation] Restart test 1 on plugin side May 16, 2017
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.

Great job done - overall looks neat and clean! A few comments below.

package e2e

import (
"os"
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 use 4-space indention consistently.

Copy link
Contributor

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.

"os"
"testing"

. "gopkg.in/check.v1"
Copy link
Contributor

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 :)


func (s *PluginSuite) SetUpTest(c *C) {
s.volumeName = testparams.GetVolumeNameWithTimeStamp("abc")
s.hostName = os.Getenv("VM2")
Copy link
Contributor

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?

Copy link
Contributor Author

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

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.

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 .. gofmt runs as part of the build target which auto corrects the formatting.

Copy link
Contributor Author

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) {
Copy link
Contributor

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

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).

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. not exposing timeout and making it constant as of now.

@pshahzeb pshahzeb force-pushed the issue_1252.pshahzeb branch 2 times, most recently from 9781674 to 332d31b Compare May 17, 2017 18:41

out, err = dockercli.AttachVolume(s.hostName, s.volumeName, s.containerName)
c.Assert(err, IsNil, Commentf(vf.FormatOutput(out)))

Copy link
Contributor

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.

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.

@@ -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 {
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 better to be part of separate util, definitely not as verification util.

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

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

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.

Copy link
Contributor Author

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

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?

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

}

// CleanContainer - clean the container (stops and removes it)
func CleanContainer(ip, containerName string) ([]byte, error) {
Copy link
Contributor

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

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


status := vf.PollStatus(s.volumeName, vf.DetachedStatus, s.hostName)
c.Assert(status, Equals, true, Commentf("Volume %s is still attached", s.volumeName))

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 verification step using admin_cli volume ls

Copy link
Contributor Author

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.

)

// Hook up gocheck into the "go test" runner.
func TestRestart(t *testing.T) { TestingT(t) }
Copy link
Contributor

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.

Copy link
Contributor Author

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

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.

over all looks good to me .. please have a look at some minor comments

@@ -25,4 +25,9 @@ const (

// ListVolumes referring to vmdkops_admin volume ls
ListVolumes = vmdkopsAdminVolume + "ls "

//DetachedStatus - volume detached
Copy link
Contributor

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.

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.

package e2e
Copy link
Contributor

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.

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

s.volumeName = inputparams.GetVolumeNameWithTimeStamp("abc")
s.hostName = os.Getenv("VM2")
s.esxName = os.Getenv("ESX")
s.containerName = "busybox_test"
Copy link
Contributor

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.

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

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

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

Copy link
Contributor Author

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?

Copy link
Contributor

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)

@@ -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 \
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 add all this here .. can you explain why is the need 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.

Did it in alignment with other utils (line 102,103). required to build test files. If not required, should we remove all of them?

Copy link
Contributor

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.

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

Choose a reason for hiding this comment

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

couple things here

  1. "docker rm -f" move as constant
  2. need to check spacing before/after +

Copy link
Contributor Author

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

Copy link
Contributor Author

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

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

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 .. 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.

Copy link
Contributor Author

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.

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 point me to the line?

return true
}
}
log.Printf("Timed out to poll status\n")
Copy link
Contributor

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

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. Using log.Fatalf.

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.

Great work!! LGTM

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.

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.

@pshahzeb pshahzeb merged commit 2de15ce into master May 18, 2017
@shuklanirdesh82 shuklanirdesh82 deleted the issue_1252.pshahzeb branch May 18, 2017 04:41
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.

4 participants