mirror of https://github.com/apache/cloudstack.git
CLOUDSTACK-5674:Fixed pep8 errors in python files in marvin folder
Signed-off-by: SrikanteswaraRao Talluri <talluri@apache.org>
This commit is contained in:
parent
404ac549bf
commit
4f1f182cba
|
|
@ -149,7 +149,7 @@ class CSConnection(object):
|
|||
[str.lower(r[0]),
|
||||
str.lower(
|
||||
urllib.quote_plus(str(r[1]))
|
||||
).replace("+", "%20")]
|
||||
).replace("+", "%20")]
|
||||
) for r in params]
|
||||
)
|
||||
signature = base64.encodestring(hmac.new(
|
||||
|
|
|
|||
|
|
@ -343,7 +343,7 @@ class CodeGenerator(object):
|
|||
paramProperty.desc = response['description']
|
||||
if 'type' in response:
|
||||
if response['type'] in ['list', 'map', 'set']:
|
||||
# Here list becomes a subproperty
|
||||
# Here list becomes a subproperty
|
||||
if 'response' in response:
|
||||
for innerResponse in response['response']:
|
||||
subProperty =\
|
||||
|
|
@ -359,9 +359,9 @@ class CodeGenerator(object):
|
|||
jsonOut = apiStream.readlines()
|
||||
assert len(jsonOut) > 0
|
||||
apiDict = json.loads(jsonOut[0])
|
||||
if not 'listapisresponse' in apiDict:
|
||||
if 'listapisresponse' not in apiDict:
|
||||
raise Exception("API discovery plugin response failed")
|
||||
if not 'count' in apiDict['listapisresponse']:
|
||||
if 'count' not in apiDict['listapisresponse']:
|
||||
raise Exception("Malformed api response")
|
||||
|
||||
apilist = apiDict['listapisresponse']['api']
|
||||
|
|
@ -397,7 +397,8 @@ class CodeGenerator(object):
|
|||
csCmd.request.append(paramProperty)
|
||||
|
||||
for response in cmd['response']:
|
||||
# FIXME: ExtractImage related APIs return empty dicts in response
|
||||
# FIXME: ExtractImage related APIs return empty dicts in
|
||||
# response
|
||||
if len(response) > 0:
|
||||
paramProperty = self.constructResponseFromJSON(response)
|
||||
csCmd.response.append(paramProperty)
|
||||
|
|
@ -412,11 +413,11 @@ class CodeGenerator(object):
|
|||
@return: The classes in cloudstackAPI/ formed from api discovery json
|
||||
"""
|
||||
if endpointUrl.find('response=json') >= 0:
|
||||
apiStream = urllib2.urlopen(endpointUrl)
|
||||
cmds = self.loadCmdFromJSON(apiStream)
|
||||
for cmd in cmds:
|
||||
self.generate(cmd)
|
||||
self.finalize()
|
||||
apiStream = urllib2.urlopen(endpointUrl)
|
||||
cmds = self.loadCmdFromJSON(apiStream)
|
||||
for cmd in cmds:
|
||||
self.generate(cmd)
|
||||
self.finalize()
|
||||
|
||||
|
||||
def getText(elements):
|
||||
|
|
|
|||
|
|
@ -74,5 +74,5 @@ ADMIN = 1
|
|||
DOMAIN_ADMIN = 2
|
||||
USER = 0
|
||||
XEN_SERVER = "XenServer"
|
||||
ADMIN_ACCOUNT='ADMIN_ACCOUNT'
|
||||
USER_ACCOUNT='USER_ACCOUNT'
|
||||
ADMIN_ACCOUNT = 'ADMIN_ACCOUNT'
|
||||
USER_ACCOUNT = 'USER_ACCOUNT'
|
||||
|
|
|
|||
|
|
@ -47,17 +47,20 @@ class dbServer(object):
|
|||
|
||||
|
||||
class configuration(object):
|
||||
|
||||
def __init__(self):
|
||||
self.name = None
|
||||
self.value = None
|
||||
|
||||
|
||||
class logger(object):
|
||||
|
||||
def __init__(self):
|
||||
self.LogFolderPath = None
|
||||
|
||||
|
||||
class cloudstackConfiguration(object):
|
||||
|
||||
def __init__(self):
|
||||
self.zones = []
|
||||
self.mgtSvr = []
|
||||
|
|
@ -68,6 +71,7 @@ class cloudstackConfiguration(object):
|
|||
|
||||
|
||||
class zone(object):
|
||||
|
||||
def __init__(self):
|
||||
self.dns1 = None
|
||||
self.internaldns1 = None
|
||||
|
|
@ -845,8 +849,8 @@ def descSetupInAdvancedsgMode():
|
|||
memory = 8 * 1024 * 1024 * 1024
|
||||
localstorage = 1 * 1024 * 1024 * 1024 * 1024
|
||||
# h.url = "http://sim/%d%d%d%d/cpucore=1&cpuspeed=8000&\
|
||||
# memory=%d&localstorage=%d" % (l, i, j, k, memory,
|
||||
# localstorage)
|
||||
# memory=%d&localstorage=%d" % (l, i, j, k, memory,
|
||||
# localstorage)
|
||||
h.url = "http://sim/%d%d%d%d" % (l, i, j, k)
|
||||
c.hosts.append(h)
|
||||
|
||||
|
|
@ -855,8 +859,6 @@ def descSetupInAdvancedsgMode():
|
|||
primary = primaryStorage()
|
||||
primary.name = "primary" + \
|
||||
str(l) + str(i) + str(j) + str(m)
|
||||
# primary.url = "nfs://localhost/path%s/size=%d" % \
|
||||
#(str(l) + str(i) + str(j) + str(m), size)
|
||||
primary.url = "nfs://localhost/path%s" % \
|
||||
(str(l) + str(i) + str(j) + str(m))
|
||||
c.primaryStorages.append(primary)
|
||||
|
|
|
|||
|
|
@ -97,8 +97,8 @@ def startMarvin(cfg_file, load_flag):
|
|||
print "\nMarvin Initialization Failed"
|
||||
exit(1)
|
||||
except Exception as e:
|
||||
print "\n Exception occurred while starting Marvin %s" % str(e)
|
||||
exit(1)
|
||||
print "\n Exception occurred while starting Marvin %s" % str(e)
|
||||
exit(1)
|
||||
|
||||
|
||||
def runTCs(num_iter, inp1, inp2):
|
||||
|
|
|
|||
|
|
@ -5,9 +5,9 @@
|
|||
# to you 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
|
||||
|
|
|
|||
File diff suppressed because it is too large
Load Diff
|
|
@ -59,8 +59,6 @@ from marvin.cloudstackAPI import (listConfigurations,
|
|||
listVPCOfferings)
|
||||
|
||||
|
||||
|
||||
|
||||
from marvin.sshClient import SshClient
|
||||
from marvin.codes import (PASS, ISOLATED_NETWORK, VPC_NETWORK,
|
||||
BASIC_ZONE, FAIL, NAT_RULE, STATIC_NAT_RULE)
|
||||
|
|
@ -76,7 +74,8 @@ import time
|
|||
|
||||
def is_config_suitable(apiclient, name, value):
|
||||
"""
|
||||
Ensure if the deployment has the expected `value` for the global setting `name'
|
||||
Ensure if the deployment has the expected
|
||||
`value` for the global setting `name'
|
||||
@return: true if value is set, else false
|
||||
"""
|
||||
configs = Configurations.list(apiclient, name=name)
|
||||
|
|
@ -151,7 +150,8 @@ def add_netscaler(apiclient, zoneid, NSservice):
|
|||
def get_region(apiclient, region_id=None, region_name=None):
|
||||
'''
|
||||
@name : get_region
|
||||
@Desc : Returns the Region Information for a given region id or region name
|
||||
@Desc : Returns the Region Information for a given
|
||||
region id or region name
|
||||
@Input : region_name: Name of the Region
|
||||
region_id : Id of the region
|
||||
@Output : 1. Region Information for the passed inputs else first Region
|
||||
|
|
@ -237,10 +237,12 @@ def get_pod(apiclient, zone_id=None, pod_id=None, pod_name=None):
|
|||
if validateList(cmd_out)[0] != PASS:
|
||||
return FAILED
|
||||
return cmd_out[0]
|
||||
|
||||
|
||||
def get_template(
|
||||
apiclient, zone_id=None, ostype_desc=None, template_filter="featured", template_type='BUILTIN',
|
||||
template_id=None, template_name=None, account=None, domain_id=None, project_id=None,
|
||||
hypervisor=None):
|
||||
apiclient, zone_id=None, ostype_desc=None, template_filter="featured",
|
||||
template_type='BUILTIN', template_id=None, template_name=None,
|
||||
account=None, domain_id=None, project_id=None, hypervisor=None):
|
||||
'''
|
||||
@Name : get_template
|
||||
@Desc : Retrieves the template Information based upon inputs provided
|
||||
|
|
@ -759,20 +761,24 @@ def update_resource_count(apiclient, domainid, accountid=None,
|
|||
)
|
||||
return
|
||||
|
||||
|
||||
def findSuitableHostForMigration(apiclient, vmid):
|
||||
"""Returns a suitable host for VM migration"""
|
||||
suitableHost = None
|
||||
try:
|
||||
hosts = Host.listForMigration(apiclient, virtualmachineid=vmid,
|
||||
)
|
||||
)
|
||||
except Exception as e:
|
||||
raise Exception("Exception while getting hosts list suitable for migration: %s" % e)
|
||||
raise Exception(
|
||||
"Exception while getting hosts list suitable for migration: %s" %
|
||||
e)
|
||||
|
||||
suitablehosts = []
|
||||
if isinstance(hosts, list) and len(hosts) > 0:
|
||||
suitablehosts = [host for host in hosts if (str(host.resourcestate).lower() == "enabled"\
|
||||
and str(host.state).lower() == "up")]
|
||||
if len(suitablehosts)>0:
|
||||
suitablehosts = [host for host in hosts
|
||||
if (str(host.resourcestate).lower() == "enabled"
|
||||
and str(host.state).lower() == "up")]
|
||||
if len(suitablehosts) > 0:
|
||||
suitableHost = suitablehosts[0]
|
||||
|
||||
return suitableHost
|
||||
|
|
@ -798,10 +804,10 @@ def get_resource_type(resource_id):
|
|||
return lookup[resource_id]
|
||||
|
||||
|
||||
|
||||
def get_free_vlan(apiclient, zoneid):
|
||||
"""
|
||||
Find an unallocated VLAN outside the range allocated to the physical network.
|
||||
Find an unallocated VLAN outside the range
|
||||
allocated to the physical network.
|
||||
|
||||
@note: This does not guarantee that the VLAN is available for use in
|
||||
the deployment's network gear
|
||||
|
|
@ -813,7 +819,8 @@ def get_free_vlan(apiclient, zoneid):
|
|||
)
|
||||
assert isinstance(list_physical_networks_response, list)
|
||||
assert len(
|
||||
list_physical_networks_response) > 0, "No physical networks found in zone %s" % zoneid
|
||||
list_physical_networks_response) > 0,\
|
||||
"No physical networks found in zone %s" % zoneid
|
||||
|
||||
physical_network = list_physical_networks_response[0]
|
||||
|
||||
|
|
@ -836,7 +843,8 @@ def get_free_vlan(apiclient, zoneid):
|
|||
|
||||
assert len(vlans) > 0
|
||||
assert int(vlans[0]) < int(
|
||||
vlans[-1]), "VLAN range %s was improperly split" % physical_network.vlan
|
||||
vlans[-1]), "VLAN range %s was improperly split"\
|
||||
% physical_network.vlan
|
||||
|
||||
# Assuming random function will give different integer each time
|
||||
retriesCount = 20
|
||||
|
|
@ -864,7 +872,8 @@ def get_free_vlan(apiclient, zoneid):
|
|||
|
||||
def setNonContiguousVlanIds(apiclient, zoneid):
|
||||
"""
|
||||
Form the non contiguous ranges based on currently assigned range in physical network
|
||||
Form the non contiguous ranges based on currently
|
||||
assigned range in physical network
|
||||
"""
|
||||
|
||||
NonContigVlanIdsAcquired = False
|
||||
|
|
@ -875,7 +884,8 @@ def setNonContiguousVlanIds(apiclient, zoneid):
|
|||
)
|
||||
assert isinstance(list_physical_networks_response, list)
|
||||
assert len(
|
||||
list_physical_networks_response) > 0, "No physical networks found in zone %s" % zoneid
|
||||
list_physical_networks_response) > 0, \
|
||||
"No physical networks found in zone %s" % zoneid
|
||||
|
||||
for physical_network in list_physical_networks_response:
|
||||
|
||||
|
|
@ -883,26 +893,30 @@ def setNonContiguousVlanIds(apiclient, zoneid):
|
|||
|
||||
assert len(vlans) > 0
|
||||
assert int(vlans[0]) < int(
|
||||
vlans[-1]), "VLAN range %s was improperly split" % physical_network.vlan
|
||||
vlans[-1]), "VLAN range %s was improperly split"\
|
||||
% physical_network.vlan
|
||||
|
||||
# Keep some gap between existing vlan and the new vlans which we are going to add
|
||||
# Keep some gap between existing vlan and the new vlans
|
||||
# which we are going to add
|
||||
# So that they are non contiguous
|
||||
|
||||
non_contig_end_vlan_id = int(vlans[-1]) + 6
|
||||
non_contig_start_vlan_id = int(vlans[0]) - 6
|
||||
|
||||
# Form ranges which are consecutive to existing ranges but not immediately contiguous
|
||||
# There should be gap in between existing range and new non contiguous
|
||||
# ranage
|
||||
|
||||
# If you can't add range after existing range, because it's crossing 4095, then
|
||||
# select VLAN ids before the existing range such that they are greater than 0, and
|
||||
# Form ranges which are consecutive to existing ranges but
|
||||
# not immediately contiguous
|
||||
# There should be gap in between existing range
|
||||
# and new non contiguous range
|
||||
# If you can't add range after existing range,
|
||||
# because it's crossing 4095, then select VLAN ids before
|
||||
# the existing range such that they are greater than 0, and
|
||||
# then add this non contiguoud range
|
||||
vlan = {"partial_range": ["", ""], "full_range": ""}
|
||||
|
||||
if non_contig_end_vlan_id < 4095:
|
||||
vlan["partial_range"][0] = str(
|
||||
non_contig_end_vlan_id - 4) + '-' + str(non_contig_end_vlan_id - 3)
|
||||
non_contig_end_vlan_id - 4) + '-' + str(non_contig_end_vlan_id
|
||||
- 3)
|
||||
vlan["partial_range"][1] = str(
|
||||
non_contig_end_vlan_id - 1) + '-' + str(non_contig_end_vlan_id)
|
||||
vlan["full_range"] = str(
|
||||
|
|
@ -910,12 +924,15 @@ def setNonContiguousVlanIds(apiclient, zoneid):
|
|||
NonContigVlanIdsAcquired = True
|
||||
|
||||
elif non_contig_start_vlan_id > 0:
|
||||
vlan["partial_range"][0] = str(
|
||||
non_contig_start_vlan_id) + '-' + str(non_contig_start_vlan_id + 1)
|
||||
vlan["partial_range"][1] = str(
|
||||
non_contig_start_vlan_id + 3) + '-' + str(non_contig_start_vlan_id + 4)
|
||||
vlan["full_range"] = str(
|
||||
non_contig_start_vlan_id) + '-' + str(non_contig_start_vlan_id + 4)
|
||||
vlan["partial_range"][0] = \
|
||||
str(non_contig_start_vlan_id) \
|
||||
+ '-' + str(non_contig_start_vlan_id + 1)
|
||||
vlan["partial_range"][1] = \
|
||||
str(non_contig_start_vlan_id + 3) \
|
||||
+ '-' + str(non_contig_start_vlan_id + 4)
|
||||
vlan["full_range"] = \
|
||||
str(non_contig_start_vlan_id) \
|
||||
+ '-' + str(non_contig_start_vlan_id + 4)
|
||||
NonContigVlanIdsAcquired = True
|
||||
|
||||
else:
|
||||
|
|
@ -930,7 +947,8 @@ def setNonContiguousVlanIds(apiclient, zoneid):
|
|||
else:
|
||||
break
|
||||
|
||||
# If even through looping from all existing physical networks, failed to get relevant non
|
||||
# If even through looping from all existing physical networks,
|
||||
# failed to get relevant non
|
||||
# contiguous vlan ids, then fail the test case
|
||||
|
||||
if not NonContigVlanIdsAcquired:
|
||||
|
|
@ -938,84 +956,111 @@ def setNonContiguousVlanIds(apiclient, zoneid):
|
|||
|
||||
return physical_network, vlan
|
||||
|
||||
|
||||
def is_public_ip_in_correct_state(apiclient, ipaddressid, state):
|
||||
""" Check if the given IP is in the correct state (given)
|
||||
and return True/False accordingly"""
|
||||
retriesCount = 10
|
||||
while True:
|
||||
portableips = PublicIPAddress.list(apiclient, id=ipaddressid)
|
||||
assert validateList(portableips)[0] == PASS, "IPs list validation failed"
|
||||
assert validateList(
|
||||
portableips)[0] == PASS, "IPs list validation failed"
|
||||
if str(portableips[0].state).lower() == state:
|
||||
break
|
||||
elif retriesCount == 0:
|
||||
return False
|
||||
return False
|
||||
else:
|
||||
retriesCount -= 1
|
||||
time.sleep(60)
|
||||
continue
|
||||
return True
|
||||
|
||||
def setSharedNetworkParams(networkServices, range=20):
|
||||
"""Fill up the services dictionary for shared network using random subnet"""
|
||||
|
||||
# @range: range decides the endip. Pass the range as "x" if you want the difference between the startip
|
||||
def setSharedNetworkParams(networkServices, range=20):
|
||||
"""Fill up the services dictionary for shared network
|
||||
using random subnet
|
||||
"""
|
||||
|
||||
# @range: range decides the endip. Pass the range as "x"
|
||||
# if you want the difference between the startip
|
||||
# and endip as "x"
|
||||
# Set the subnet number of shared networks randomly prior to execution
|
||||
# of each test case to avoid overlapping of ip addresses
|
||||
shared_network_subnet_number = random.randrange(1,254)
|
||||
shared_network_subnet_number = random.randrange(1, 254)
|
||||
|
||||
networkServices["gateway"] = "172.16."+str(shared_network_subnet_number)+".1"
|
||||
networkServices["startip"] = "172.16."+str(shared_network_subnet_number)+".2"
|
||||
networkServices["endip"] = "172.16."+str(shared_network_subnet_number)+"."+str(range+1)
|
||||
networkServices["gateway"] = "172.16." + \
|
||||
str(shared_network_subnet_number) + ".1"
|
||||
networkServices["startip"] = "172.16." + \
|
||||
str(shared_network_subnet_number) + ".2"
|
||||
networkServices["endip"] = "172.16." + \
|
||||
str(shared_network_subnet_number) + "." + str(range + 1)
|
||||
networkServices["netmask"] = "255.255.255.0"
|
||||
return networkServices
|
||||
|
||||
|
||||
def createEnabledNetworkOffering(apiclient, networkServices):
|
||||
"""Create and enable network offering according to the type
|
||||
|
||||
@output: List, containing [ Result,Network Offering,Reason ]
|
||||
Ist Argument('Result') : FAIL : If exception or assertion error occurs
|
||||
Ist Argument('Result') : FAIL : If exception or assertion
|
||||
error occurs
|
||||
PASS : If network offering
|
||||
is created and enabled successfully
|
||||
IInd Argument(Net Off) : Enabled network offering
|
||||
In case of exception or
|
||||
assertion error, it will be None
|
||||
assertion error, it will be
|
||||
None
|
||||
IIIrd Argument(Reason) : Reason for failure,
|
||||
default to None
|
||||
"""
|
||||
try:
|
||||
resultSet = [FAIL, None, None]
|
||||
# Create network offering
|
||||
network_offering = NetworkOffering.create(apiclient, networkServices, conservemode=False)
|
||||
network_offering = NetworkOffering.create(
|
||||
apiclient,
|
||||
networkServices,
|
||||
conservemode=False)
|
||||
|
||||
# Update network offering state from disabled to enabled.
|
||||
NetworkOffering.update(network_offering, apiclient, id=network_offering.id,
|
||||
NetworkOffering.update(network_offering,
|
||||
apiclient, id=network_offering.id,
|
||||
state="enabled")
|
||||
except Exception as e:
|
||||
resultSet[2] = e
|
||||
return resultSet
|
||||
return [PASS, network_offering, None]
|
||||
|
||||
|
||||
def shouldTestBeSkipped(networkType, zoneType):
|
||||
"""Decide which test to skip, according to type of network and zone type"""
|
||||
|
||||
# If network type is isolated or vpc and zone type is basic, then test should be skipped
|
||||
# If network type is isolated or vpc and zone type is basic, then test
|
||||
# should be skipped
|
||||
skipIt = False
|
||||
if ((networkType.lower() == str(ISOLATED_NETWORK).lower() or networkType.lower() == str(VPC_NETWORK).lower())
|
||||
and (zoneType.lower() == BASIC_ZONE)):
|
||||
if (networkType.lower() == str(ISOLATED_NETWORK).lower() or
|
||||
networkType.lower() == str(VPC_NETWORK).lower()) and\
|
||||
(zoneType.lower() == BASIC_ZONE):
|
||||
skipIt = True
|
||||
return skipIt
|
||||
|
||||
|
||||
def verifyNetworkState(apiclient, networkid, state):
|
||||
"""List networks and check if the network state matches the given state"""
|
||||
try:
|
||||
networks = Network.list(apiclient, id=networkid)
|
||||
except Exception as e:
|
||||
raise Exception("Failed while fetching network list with error: %s" % e)
|
||||
assert validateList(networks)[0] == PASS, "Networks list validation failed, list is %s" % networks
|
||||
assert str(networks[0].state).lower() == state, "network state should be %s, it is %s" % (state, networks[0].state)
|
||||
raise Exception(
|
||||
"Failed while fetching network list with error: %s" %
|
||||
e)
|
||||
assert validateList(
|
||||
networks)[0] == PASS, "Networks list validation failed, list is %s"\
|
||||
% networks
|
||||
assert str(networks[0].state).lower(
|
||||
) == state, "network state should be %s, it is %s" \
|
||||
% (state, networks[0].state)
|
||||
return
|
||||
|
||||
|
||||
def verifyComputeOfferingCreation(apiclient, computeofferingid):
|
||||
"""List Compute offerings by ID and verify that the offering exists"""
|
||||
|
||||
|
|
@ -1025,11 +1070,12 @@ def verifyComputeOfferingCreation(apiclient, computeofferingid):
|
|||
try:
|
||||
serviceOfferings = apiclient.listServiceOfferings(cmd)
|
||||
except Exception:
|
||||
return FAIL
|
||||
return FAIL
|
||||
if not (isinstance(serviceOfferings, list) and len(serviceOfferings) > 0):
|
||||
return FAIL
|
||||
return FAIL
|
||||
return PASS
|
||||
|
||||
|
||||
def createNetworkRulesForVM(apiclient, virtualmachine, ruletype,
|
||||
account, networkruledata):
|
||||
"""Acquire IP, create Firewall and NAT/StaticNAT rule
|
||||
|
|
@ -1037,26 +1083,28 @@ def createNetworkRulesForVM(apiclient, virtualmachine, ruletype,
|
|||
|
||||
try:
|
||||
public_ip = PublicIPAddress.create(
|
||||
apiclient,accountid=account.name,
|
||||
zoneid=virtualmachine.zoneid,domainid=account.domainid,
|
||||
networkid=virtualmachine.nic[0].networkid)
|
||||
apiclient, accountid=account.name,
|
||||
zoneid=virtualmachine.zoneid, domainid=account.domainid,
|
||||
networkid=virtualmachine.nic[0].networkid)
|
||||
|
||||
FireWallRule.create(
|
||||
apiclient,ipaddressid=public_ip.ipaddress.id,
|
||||
apiclient, ipaddressid=public_ip.ipaddress.id,
|
||||
protocol='TCP', cidrlist=[networkruledata["fwrule"]["cidr"]],
|
||||
startport=networkruledata["fwrule"]["startport"],
|
||||
endport=networkruledata["fwrule"]["endport"]
|
||||
)
|
||||
)
|
||||
|
||||
if ruletype == NAT_RULE:
|
||||
# Create NAT rule
|
||||
NATRule.create(apiclient, virtualmachine,
|
||||
networkruledata["natrule"],ipaddressid=public_ip.ipaddress.id,
|
||||
networkid=virtualmachine.nic[0].networkid)
|
||||
networkruledata[
|
||||
"natrule"], ipaddressid=public_ip.ipaddress.id,
|
||||
networkid=virtualmachine.nic[0].networkid)
|
||||
elif ruletype == STATIC_NAT_RULE:
|
||||
# Enable Static NAT for VM
|
||||
StaticNATRule.enable(apiclient,public_ip.ipaddress.id,
|
||||
virtualmachine.id, networkid=virtualmachine.nic[0].networkid)
|
||||
StaticNATRule.enable(apiclient, public_ip.ipaddress.id,
|
||||
virtualmachine.id,
|
||||
networkid=virtualmachine.nic[0].networkid)
|
||||
except Exception as e:
|
||||
[FAIL, e]
|
||||
return [PASS, public_ip]
|
||||
|
|
|
|||
|
|
@ -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")
|
||||
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):
|
||||
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]))
|
||||
# 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
|
||||
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]
|
||||
|
||||
|
|
@ -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,
|
||||
|
|
|
|||
|
|
@ -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))
|
||||
|
|
|
|||
|
|
@ -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__":
|
||||
|
|
|
|||
Loading…
Reference in New Issue