You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cloudstack.apache.org by gi...@apache.org on 2014/05/06 12:00:53 UTC
[19/32] CLOUDSTACK-5674:Fixed pep8 errors in python files in marvin
folder Signed-off-by: SrikanteswaraRao Talluri
http://git-wip-us.apache.org/repos/asf/cloudstack/blob/4f1f182c/tools/marvin/marvin/lib/utils.py
----------------------------------------------------------------------
diff --git a/tools/marvin/marvin/lib/utils.py b/tools/marvin/marvin/lib/utils.py
index cb5dcfb..5178f5d 100644
--- a/tools/marvin/marvin/lib/utils.py
+++ b/tools/marvin/marvin/lib/utils.py
@@ -33,13 +33,14 @@ from platform import system
from marvin.cloudstackException import GetDetailExceptionInfo
from marvin.sshClient import SshClient
from marvin.codes import (
- SUCCESS,
- FAIL,
- PASS,
- MATCH_NOT_FOUND,
- INVALID_INPUT,
- EMPTY_LIST,
- FAILED)
+ SUCCESS,
+ FAIL,
+ PASS,
+ MATCH_NOT_FOUND,
+ INVALID_INPUT,
+ EMPTY_LIST,
+ FAILED)
+
def restart_mgmt_server(server):
"""Restarts the management server"""
@@ -121,7 +122,9 @@ def cleanup_resources(api_client, resources):
obj.delete(api_client)
-def is_server_ssh_ready(ipaddress, port, username, password, retries=20, retryinterv=30, timeout=10.0, keyPairFileLocation=None):
+def is_server_ssh_ready(ipaddress, port, username, password,
+ retries=20, retryinterv=30,
+ timeout=10.0, keyPairFileLocation=None):
'''
@Name: is_server_ssh_ready
@Input: timeout: tcp connection timeout flag,
@@ -141,8 +144,10 @@ def is_server_ssh_ready(ipaddress, port, username, password, retries=20, retryin
retries=retries,
delay=retryinterv,
timeout=timeout)
- except Exception, e:
- raise Exception("SSH connection has Failed. Waited %ss. Error is %s" % (retries * retryinterv, str(e)))
+ except Exception as e:
+ raise Exception(
+ "SSH connection has Failed. Waited %ss. Error is %s" %
+ (retries * retryinterv, str(e)))
else:
return ssh
@@ -171,6 +176,7 @@ def fetch_api_client(config_file='datacenterCfg'):
)
)
+
def get_host_credentials(config, hostip):
"""Get login information for a host `hostip` (ipv4) from marvin's `config`
@@ -186,26 +192,35 @@ def get_host_credentials(config, hostip):
try:
if socket.getfqdn(hostip) == socket.getfqdn(hostname):
return host.username, host.password
- except socket.error, e:
- raise Exception("Unresolvable host %s error is %s" % (hostip, e))
- raise KeyError("Please provide the marvin configuration file with credentials to your hosts")
-
-
-def get_process_status(hostip, port, username, password, linklocalip, process, hypervisor=None):
+ except socket.error as e:
+ raise Exception(
+ "Unresolvable host %s error is %s" %
+ (hostip, e))
+ raise KeyError(
+ "Please provide the marvin configuration file "
+ "with credentials to your hosts")
+
+
+def get_process_status(
+ hostip, port, username, password,
+ linklocalip, process, hypervisor=None):
"""Double hop and returns a process status"""
- #SSH to the machine
+ # SSH to the machine
ssh = SshClient(hostip, port, username, password)
if (str(hypervisor).lower() == 'vmware'
- or str(hypervisor).lower() == 'hyperv'):
- ssh_command = "ssh -i /var/cloudstack/management/.ssh/id_rsa -ostricthostkeychecking=no "
+ or str(hypervisor).lower() == 'hyperv'):
+ ssh_command =\
+ "ssh -i /var/cloudstack/management/" \
+ ".ssh/id_rsa -ostricthostkeychecking=no "
else:
- ssh_command = "ssh -i ~/.ssh/id_rsa.cloud -ostricthostkeychecking=no "
+ ssh_command = "ssh -i ~/.ssh/id_rsa.cloud " \
+ "-ostricthostkeychecking=no "
ssh_command = ssh_command +\
- "-oUserKnownHostsFile=/dev/null -p 3922 %s %s" % (
- linklocalip,
- process)
+ "-oUserKnownHostsFile=/dev/null -p 3922 %s %s" % (
+ linklocalip,
+ process)
# Double hop into router
timeout = 5
@@ -242,12 +257,13 @@ def xsplit(txt, seps):
@return: list of split units
"""
default_sep = seps[0]
- for sep in seps[1:]: # we skip seps[0] because that's the default separator
+ # we skip seps[0] because that's the default separator
+ for sep in seps[1:]:
txt = txt.replace(sep, default_sep)
return [i.strip() for i in txt.split(default_sep)]
-def get_hypervisor_type(apiclient):
+def get_hypervisor_type(apiclient):
"""Return the hypervisor type of the hosts in setup"""
cmd = listHosts.listHostsCmd()
@@ -255,62 +271,79 @@ def get_hypervisor_type(apiclient):
cmd.listall = True
hosts = apiclient.listHosts(cmd)
hosts_list_validation_result = validateList(hosts)
- assert hosts_list_validation_result[0] == PASS, "host list validation failed"
+ assert hosts_list_validation_result[
+ 0] == PASS, "host list validation failed"
return hosts_list_validation_result[1].hypervisor
+
def is_snapshot_on_nfs(apiclient, dbconn, config, zoneid, snapshotid):
"""
- Checks whether a snapshot with id (not UUID) `snapshotid` is present on the nfs storage
+ Checks whether a snapshot with id
+ (not UUID) `snapshotid` is present on the nfs storage
@param apiclient: api client connection
@param @dbconn: connection to the cloudstack db
@param config: marvin configuration file
- @param zoneid: uuid of the zone on which the secondary nfs storage pool is mounted
+ @param zoneid: uuid of the zone on which the
+ secondary nfs storage pool is mounted
@param snapshotid: uuid of the snapshot
@return: True if snapshot is found, False otherwise
"""
# snapshot extension to be appended to the snapshot path obtained from db
snapshot_extensions = {"vmware": ".ovf",
- "kvm": "",
- "xenserver": ".vhd",
- "simulator":""}
+ "kvm": "",
+ "xenserver": ".vhd",
+ "simulator": ""}
qresultset = dbconn.execute(
- "select id from snapshots where uuid = '%s';" \
- % str(snapshotid)
- )
+ "select id from snapshots where uuid = '%s';"
+ % str(snapshotid)
+ )
if len(qresultset) == 0:
raise Exception(
"No snapshot found in cloudstack with id %s" % snapshotid)
-
snapshotid = qresultset[0][0]
qresultset = dbconn.execute(
- "select install_path,store_id from snapshot_store_ref where snapshot_id='%s' and store_role='Image';" % snapshotid
+ "select install_path,store_id from snapshot_store_ref"
+ " where snapshot_id='%s' and "
+ "store_role='Image';" % snapshotid
)
- assert isinstance(qresultset, list), "Invalid db query response for snapshot %s" % snapshotid
+ assert isinstance(
+ qresultset, list), "Invalid db query " \
+ "response for snapshot " \
+ "%s" % snapshotid
if len(qresultset) == 0:
- #Snapshot does not exist
+ # Snapshot does not exist
return False
from base import ImageStore
- #pass store_id to get the exact storage pool where snapshot is stored
- secondaryStores = ImageStore.list(apiclient, zoneid=zoneid, id=int(qresultset[0][1]))
-
- assert isinstance(secondaryStores, list), "Not a valid response for listImageStores"
- assert len(secondaryStores) != 0, "No image stores found in zone %s" % zoneid
+ # pass store_id to get the exact storage pool where snapshot is stored
+ secondaryStores = ImageStore.list(
+ apiclient,
+ zoneid=zoneid,
+ id=int(
+ qresultset[0][1]))
+
+ assert isinstance(
+ secondaryStores, list), "Not a valid response for listImageStores"
+ assert len(
+ secondaryStores) != 0, "No image stores found in zone %s" % zoneid
secondaryStore = secondaryStores[0]
if str(secondaryStore.providername).lower() != "nfs":
raise Exception(
- "is_snapshot_on_nfs works only against nfs secondary storage. found %s" % str(secondaryStore.providername))
+ "is_snapshot_on_nfs works only "
+ "against nfs secondary storage."
+ " found %s" % str(secondaryStore.providername))
hypervisor = get_hypervisor_type(apiclient)
# append snapshot extension based on hypervisor, to the snapshot path
- snapshotPath = str(qresultset[0][0]) + snapshot_extensions[str(hypervisor).lower()]
+ snapshotPath = str(qresultset[0][0]) + \
+ snapshot_extensions[str(hypervisor).lower()]
nfsurl = secondaryStore.url
from urllib2 import urlparse
@@ -318,8 +351,11 @@ def is_snapshot_on_nfs(apiclient, dbconn, config, zoneid, snapshotid):
host, path = parse_url.netloc, parse_url.path
if not config.mgtSvr:
- raise Exception("Your marvin configuration does not contain mgmt server credentials")
- mgtSvr, user, passwd = config.mgtSvr[0].mgtSvrIp, config.mgtSvr[0].user, config.mgtSvr[0].passwd
+ raise Exception(
+ "Your marvin configuration does "
+ "not contain mgmt server credentials")
+ mgtSvr, user, passwd = config.mgtSvr[
+ 0].mgtSvrIp, config.mgtSvr[0].user, config.mgtSvr[0].passwd
try:
ssh_client = SshClient(
@@ -329,32 +365,33 @@ def is_snapshot_on_nfs(apiclient, dbconn, config, zoneid, snapshotid):
passwd
)
cmds = [
- "mkdir -p %s /mnt/tmp",
- "mount -t %s %s%s /mnt/tmp" % (
- 'nfs',
- host,
- path,
- ),
- "test -f %s && echo 'snapshot exists'" % (
- os.path.join("/mnt/tmp", snapshotPath)
- ),
- ]
+ "mkdir -p %s /mnt/tmp",
+ "mount -t %s %s%s /mnt/tmp" % (
+ 'nfs',
+ host,
+ path,
+ ),
+ "test -f %s && echo 'snapshot exists'" % (
+ os.path.join("/mnt/tmp", snapshotPath)
+ ),
+ ]
for c in cmds:
result = ssh_client.execute(c)
# Unmount the Sec Storage
cmds = [
- "cd",
- "umount /mnt/tmp",
- ]
+ "cd",
+ "umount /mnt/tmp",
+ ]
for c in cmds:
ssh_client.execute(c)
except Exception as e:
raise Exception("SSH failed for management server: %s - %s" %
- (config.mgtSvr[0].mgtSvrIp, e))
+ (config.mgtSvr[0].mgtSvrIp, e))
return 'snapshot exists' in result
+
def validateList(inp):
"""
@name: validateList
@@ -388,7 +425,8 @@ def validateList(inp):
return ret
return [PASS, inp[0], None]
-def verifyElementInList(inp, toverify, responsevar=None, pos=0):
+
+def verifyElementInList(inp, toverify, responsevar=None, pos=0):
'''
@name: verifyElementInList
@Description:
@@ -400,9 +438,9 @@ def verifyElementInList(inp, toverify, responsevar=None, pos=0):
at a given pos
@Input:
I : Input to be verified whether its a list or not
- II : Element to verify whether it exists in the list
- III : variable name in response object to verify
- default to None, if None, we will verify for the complete
+ II : Element to verify whether it exists in the list
+ III : variable name in response object to verify
+ default to None, if None, we will verify for the complete
first element EX: state of response object object
IV : Position in the list at which the input element to verify
default to 0
@@ -425,25 +463,29 @@ def verifyElementInList(inp, toverify, responsevar=None, pos=0):
return [FAIL, out[2]]
if len(inp) > pos:
if responsevar is None:
- if inp[pos] == toverify:
- return [PASS, None]
+ if inp[pos] == toverify:
+ return [PASS, None]
else:
- if responsevar in inp[pos].__dict__ and getattr(inp[pos], responsevar) == toverify:
- return [PASS, None]
- else:
- return [FAIL, MATCH_NOT_FOUND]
+ if responsevar in inp[pos].\
+ __dict__ and getattr(inp[pos], responsevar) == toverify:
+ return [PASS, None]
+ else:
+ return [FAIL, MATCH_NOT_FOUND]
else:
return [FAIL, MATCH_NOT_FOUND]
+
def checkVolumeSize(ssh_handle=None,
volume_name="/dev/sda",
cmd_inp="/sbin/fdisk -l | grep Disk",
size_to_verify=0):
'''
@Name : getDiskUsage
- @Desc : provides facility to verify the volume size against the size to verify
+ @Desc : provides facility to verify the
+ volume size against the size to verify
@Input: 1. ssh_handle : machine against which to execute the disk size cmd
- 2. volume_name : The name of the volume against which to verify the size
+ 2. volume_name : The name of the volume
+ against which to verify the size
3. cmd_inp : Input command used to veify the size
4. size_to_verify: size against which to compare.
@Output: Returns FAILED in case of an issue, else SUCCESS
@@ -465,14 +507,14 @@ def checkVolumeSize(ssh_handle=None,
if volume_name in line:
parts = line.split()
if str(parts[-2]) == str(size_to_verify):
- return [SUCCESS,str(parts[-2])]
- return [FAILED,"Volume Not Found"]
- except Exception, e:
+ return [SUCCESS, str(parts[-2])]
+ return [FAILED, "Volume Not Found"]
+ except Exception as e:
print "\n Exception Occurred under getDiskUsage: " \
- "%s" %GetDetailExceptionInfo(e)
- return [FAILED,GetDetailExceptionInfo(e)]
+ "%s" % GetDetailExceptionInfo(e)
+ return [FAILED, GetDetailExceptionInfo(e)]
+
-
def verifyRouterState(apiclient, routerid, allowedstates):
"""List the router and verify that its state is in allowed states
@output: List, containing [Result, Reason]
@@ -492,7 +534,7 @@ def verifyRouterState(apiclient, routerid, allowedstates):
if listvalidationresult[0] == FAIL:
return [FAIL, listvalidationresult[2]]
if routers[0].redundantstate not in allowedstates:
- return [FAIL, "Redundant state of the router should be in %s but is %s" %
- (allowedstates, routers[0].redundantstate)]
+ return [FAIL, "Redundant state of the"
+ " router should be in %s but is %s" %
+ (allowedstates, routers[0].redundantstate)]
return [PASS, None]
-
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/cloudstack/blob/4f1f182c/tools/marvin/marvin/marvinInit.py
----------------------------------------------------------------------
diff --git a/tools/marvin/marvin/marvinInit.py b/tools/marvin/marvin/marvinInit.py
index c35fec6..de580ce 100644
--- a/tools/marvin/marvin/marvinInit.py
+++ b/tools/marvin/marvin/marvinInit.py
@@ -134,11 +134,11 @@ class MarvinInit:
'''
try:
if ((self.__parseConfig() != FAILED) and
- (self.__setHypervisorAndZoneInfo())and
- (self.__setTestDataPath() != FAILED) and
- (self.__initLogging() != FAILED) and
- (self.__createTestClient() != FAILED) and
- (self.__deployDC() != FAILED)):
+ (self.__setHypervisorAndZoneInfo())and
+ (self.__setTestDataPath() != FAILED) and
+ (self.__initLogging() != FAILED) and
+ (self.__createTestClient() != FAILED) and
+ (self.__deployDC() != FAILED)):
return SUCCESS
return FAILED
except Exception as e:
@@ -187,7 +187,8 @@ class MarvinInit:
try:
mgt_details = self.__parsedConfig.mgtSvr[0]
dbsvr_details = self.__parsedConfig.dbSvr
- self.__testClient = CSTestClient(mgt_details, dbsvr_details,
+ self.__testClient = CSTestClient(mgt_details,
+ dbsvr_details,
logger=self.__tcRunLogger,
test_data_filepath=
self.__testDataFilePath,
http://git-wip-us.apache.org/repos/asf/cloudstack/blob/4f1f182c/tools/marvin/marvin/marvinPlugin.py
----------------------------------------------------------------------
diff --git a/tools/marvin/marvin/marvinPlugin.py b/tools/marvin/marvin/marvinPlugin.py
index 4200a65..c817cd6 100644
--- a/tools/marvin/marvin/marvinPlugin.py
+++ b/tools/marvin/marvin/marvinPlugin.py
@@ -302,6 +302,6 @@ class MarvinPlugin(Plugin):
cmd = "mv " + src + " " + dst
os.system(cmd)
print "===final results are now copied to: %s===" % str(dst)
- except Exception, e:
+ except Exception as e:
print "=== Exception occurred under finalize :%s ===" % \
str(GetDetailExceptionInfo(e))
http://git-wip-us.apache.org/repos/asf/cloudstack/blob/4f1f182c/tools/marvin/marvin/sshClient.py
----------------------------------------------------------------------
diff --git a/tools/marvin/marvin/sshClient.py b/tools/marvin/marvin/sshClient.py
index 611c8b5..76f3b6d 100644
--- a/tools/marvin/marvin/sshClient.py
+++ b/tools/marvin/marvin/sshClient.py
@@ -204,9 +204,9 @@ class SshClient(object):
self.close()
def close(self):
- if self.ssh is not None:
- self.ssh.close()
- self.ssh = None
+ if self.ssh is not None:
+ self.ssh.close()
+ self.ssh = None
if __name__ == "__main__":