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

Introducing test constants into separate files #1272

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions tests/constants/admincli/cmd.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
// Copyright 2017 VMware, Inc. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// 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.

package admincli

const (
// location of the vmdkops binary
vmdkopsAdmin = "/usr/lib/vmware/vmdkops/bin/vmdkops_admin.py "

// vmdkops_admin volume
vmdkopsAdminVolume = vmdkopsAdmin + "volume "

// ListVolumes referring to vmdkops_admin volume ls
ListVolumes = vmdkopsAdminVolume + "ls "
)
31 changes: 31 additions & 0 deletions tests/constants/dockercli/cmd.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
// Copyright 2017 VMware, Inc. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

// A home to hold test constants related with docker cli.

package dockercli

const (
docker = "docker "
Copy link
Contributor

Choose a reason for hiding this comment

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

Nit: why these 2 names start with small case?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

kept it private members ... no need to export them

Copy link
Contributor

Choose a reason for hiding this comment

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

Then above VmdkopsAdmin and VmdkopsAdminVolume should not be exported either.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Agree, updating into the next diff.

dockerVol = docker + "volume "

// ListVolumes to list down docker volumes
ListVolumes = dockerVol + "ls "

// InspectVolume to grab volume properties
InspectVolume = dockerVol + "inspect "

// RemoveVolume constant refers delete volume command
RemoveVolume = dockerVol + "rm "
)
20 changes: 10 additions & 10 deletions tests/utils/verification/volumeproperties.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,15 @@ package verification
import (
"log"
"strings"

"github.com/vmware/docker-volume-vsphere/tests/constants/admincli"
"github.com/vmware/docker-volume-vsphere/tests/constants/dockercli"
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 "

// GetVMAttachedToVolUsingDockerCli returns attached to vm field of volume using docker cli
func GetVMAttachedToVolUsingDockerCli(volName string, hostname string) string {
cmd := dockerCliInspect + " --format '{{index .Status \"attached to VM\"}}' " + volName
cmd := dockercli.InspectVolume + " --format '{{index .Status \"attached to VM\"}}' " + volName
op := ExecCmd(hostname, cmd)
if op == "" {
log.Fatal("Null value is returned by docker cli when looking for attached to vm field for volume. Output: ", op)
Expand All @@ -39,7 +39,7 @@ func GetVMAttachedToVolUsingDockerCli(volName string, hostname string) string {

// GetVMAttachedToVolUsingAdminCli returns attached to vm field of volume using admin cli
func GetVMAttachedToVolUsingAdminCli(volName string, hostname string) string {
cmd := adminCliLs + "-c volume,attached-to 2>/dev/null | grep " + volName
cmd := admincli.ListVolumes + "-c volume,attached-to 2>/dev/null | grep " + volName
op := ExecCmd(hostname, cmd)
volProps := strings.Fields(op)
if op == "" {
Expand All @@ -55,7 +55,7 @@ func GetVMAttachedToVolUsingAdminCli(volName string, hostname string) string {
// GetVolumePropertiesAdminCli returns capacity, attached-to-vm and disk-format field
// for volume using Admin cli
func GetVolumePropertiesAdminCli(volName string, hostname string) string {
cmd := adminCliLs + "-c volume,attached-to,capacity,disk-format 2>/dev/null | grep " + volName
cmd := admincli.ListVolumes + "-c volume,attached-to,capacity,disk-format 2>/dev/null | grep " + volName
op := ExecCmd(hostname, cmd)
if op == "" {
log.Fatal("Null value is returned by admin cli when looking for, size, disk-format and attached to vm. Output: ", op)
Expand All @@ -70,7 +70,7 @@ func GetVolumePropertiesAdminCli(volName string, hostname string) string {
// GetVolumePropertiesDockerCli returns capacity, attached-to-vm and disk-format field
// for volume using Docker cli
func GetVolumePropertiesDockerCli(volName string, hostname string) string {
cmd := dockerCliInspect + " --format '{{index .Status.capacity.size}} {{index .Status.diskformat}} {{index .Status \"attached to VM\"}}' " + volName
cmd := dockercli.InspectVolume + " --format '{{index .Status.capacity.size}} {{index .Status.diskformat}} {{index .Status \"attached to VM\"}}' " + volName
op := ExecCmd(hostname, cmd)
expctedLen := 0
if op == "" {
Expand Down Expand Up @@ -111,9 +111,9 @@ func ExecCmd(hostname string, cmd string) string {
// do not want to run certain verifications
// on docker 1.11
func IsDockerCliCheckNeeded(ipAddr string) bool {
dkrVrsn := GetDockerVersion(ipAddr)
log.Println("Docker version: ", dkrVrsn)
if strings.Contains(dkrVrsn, "Docker version 1.11.") {
dockerVer := GetDockerVersion(ipAddr)
log.Println("Docker version: ", dockerVer)
if strings.Contains(dockerVer, "Docker version 1.11.") {
return false
}
return true
Expand Down
4 changes: 3 additions & 1 deletion vmdk_plugin/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,9 @@ clean-as-root: pkg-post
# GO Code quality checks.

DIRS_TO_VERIFY := . utils/fs utils/config drivers/photon drivers/vmdk drivers/vmdk/vmdkops ../tests/e2e \
../tests/utils/dockercli ../tests/utils/inputparams ../tests/utils/verification
../tests/utils/dockercli ../tests/utils/inputparams ../tests/utils/verification ../tests/constants/admincli \
../tests/constants/dockercli

FILES_TO_VERIFY := $(foreach dir, $(DIRS_TO_VERIFY), $(dir)/*.go)
.code_verify: $(FILES_TO_VERIFY)
@for i in $(DIRS_TO_VERIFY) ; do ${GOPATH}/bin/golint $$i ; done
Expand Down