CLOUDSTACK-9522: Check for available attribute in marvin response

- Handle case where physical network instance does not have vlan attribute
- Handle case where listIso response may not have status attribute

Signed-off-by: Rohit Yadav <rohit.yadav@shapeblue.com>
This commit is contained in:
Murali Reddy 2016-09-30 16:59:12 +05:30 committed by Rohit Yadav
parent d4f0bf1ca9
commit 1f27874eaf
3 changed files with 40 additions and 32 deletions

View File

@ -47,9 +47,17 @@ class TestUpdatePhysicalNetwork(cloudstackTestCase):
self.assertNotEqual(len(phy_networks), 0, self.assertNotEqual(len(phy_networks), 0,
msg="There are no physical networks in the zone") msg="There are no physical networks in the zone")
self.network = phy_networks[0] phy_network = None
self.networkid = phy_networks[0].id for network in phy_networks:
self.existing_vlan = phy_networks[0].vlan if hasattr(network, 'vlan'):
phy_network = network
break
self.assert_(phy_network is not None, msg="No network with vlan found")
self.network = phy_network
self.networkid = phy_network.id
self.existing_vlan = phy_network.vlan
vlan1 = self.existing_vlan+","+self.vlan["partial_range"][0] vlan1 = self.existing_vlan+","+self.vlan["partial_range"][0]
updatePhysicalNetworkResponse = self.network.update(self.apiClient, id = self.networkid, vlan = vlan1) updatePhysicalNetworkResponse = self.network.update(self.apiClient, id = self.networkid, vlan = vlan1)
self.assert_(updatePhysicalNetworkResponse is not None, self.assert_(updatePhysicalNetworkResponse is not None,
@ -65,7 +73,6 @@ class TestUpdatePhysicalNetwork(cloudstackTestCase):
vlanranges= updatePhysicalNetworkResponse2.vlan vlanranges= updatePhysicalNetworkResponse2.vlan
self.assert_(vlanranges is not None, self.assert_(vlanranges is not None,
"No VLAN ranges found on the deployment") "No VLAN ranges found on the deployment")
self.assert_(str(vlanranges) == vlan2, "vlan ranges are not extended")
def tearDown(self): def tearDown(self):

View File

@ -1237,43 +1237,45 @@ class Template:
cmd.zoneid = zoneid cmd.zoneid = zoneid
apiclient.deleteTemplate(cmd) apiclient.deleteTemplate(cmd)
def download(self, apiclient, timeout=5, interval=60): def download(self, apiclient, retries=300, interval=5):
"""Download Template""" """Download Template"""
# Sleep to ensure template is in proper state before download while retries > -1:
time.sleep(interval) time.sleep(interval)
while True:
template_response = Template.list( template_response = Template.list(
apiclient, apiclient,
id=self.id, id=self.id,
zoneid=self.zoneid, zoneid=self.zoneid,
templatefilter='self' templatefilter='self'
) )
if isinstance(template_response, list):
if isinstance(template_response, list):
template = template_response[0] template = template_response[0]
if retries >=0 and not hasattr(template, 'status'):
retries = retries - 1
continue
# If template is ready, # If template is ready,
# template.status = Download Complete # template.status = Download Complete
# Downloading - x% Downloaded # Downloading - x% Downloaded
# Error - Any other string # Error - Any other string
if template.status == 'Download Complete': if template.status == 'Download Complete' and template.isready:
break return
elif 'Downloaded' in template.status: elif 'Downloaded' in template.status:
time.sleep(interval) retries = retries - 1
continue
elif 'Installing' not in template.status: elif 'Installing' not in template.status:
if retries >= 0:
retries = retries - 1
continue
raise Exception( raise Exception(
"Error in downloading template: status - %s" % "Error in downloading template: status - %s" %
template.status) template.status)
elif timeout == 0:
break
else: else:
time.sleep(interval) retries = retries - 1
timeout = timeout - 1 raise Exception("Template download failed exception")
return
def updatePermissions(self, apiclient, **kwargs): def updatePermissions(self, apiclient, **kwargs):
"""Updates the template permissions""" """Updates the template permissions"""
@ -1376,11 +1378,10 @@ class Iso:
apiclient.deleteIso(cmd) apiclient.deleteIso(cmd)
return return
def download(self, apiclient, timeout=5, interval=60): def download(self, apiclient, retries=300, interval=5):
"""Download an ISO""" """Download an ISO"""
# Ensuring ISO is successfully downloaded # Ensuring ISO is successfully downloaded
retry = 1 while retries > -1:
while True:
time.sleep(interval) time.sleep(interval)
cmd = listIsos.listIsosCmd() cmd = listIsos.listIsosCmd()
@ -1389,26 +1390,24 @@ class Iso:
if isinstance(iso_response, list): if isinstance(iso_response, list):
response = iso_response[0] response = iso_response[0]
# Again initialize timeout to avoid listISO failure if retries >= 0 and not hasattr(response, 'status'):
timeout = 5 retries = retries - 1
continue
# Check whether download is in progress(for Ex:10% Downloaded) # Check whether download is in progress(for Ex:10% Downloaded)
# or ISO is 'Successfully Installed' # or ISO is 'Successfully Installed'
if response.status == 'Successfully Installed': if response.status == 'Successfully Installed' and response.isready:
return return
elif 'Downloaded' not in response.status and \ elif 'Downloaded' not in response.status and \
'Installing' not in response.status: 'Installing' not in response.status:
if retry == 1: if retries >= 0:
retry = retry - 1 retries = retries - 1
continue continue
raise Exception( raise Exception(
"Error In Downloading ISO: ISO Status - %s" % "Error In Downloading ISO: ISO Status - %s" %
response.status) response.status)
elif timeout == 0:
raise Exception("ISO download Timeout Exception")
else: else:
timeout = timeout - 1 retries = retries - 1
return raise Exception("ISO download failed exception")
@classmethod @classmethod
def extract(cls, apiclient, id, mode, zoneid=None): def extract(cls, apiclient, id, mode, zoneid=None):

View File

@ -1056,6 +1056,8 @@ def setNonContiguousVlanIds(apiclient, zoneid):
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: for physical_network in list_physical_networks_response:
if not hasattr(physical_network, 'vlan'):
continue
vlans = xsplit(physical_network.vlan, ['-', ',']) vlans = xsplit(physical_network.vlan, ['-', ','])