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,
msg="There are no physical networks in the zone")
self.network = phy_networks[0]
self.networkid = phy_networks[0].id
self.existing_vlan = phy_networks[0].vlan
phy_network = None
for network in phy_networks:
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]
updatePhysicalNetworkResponse = self.network.update(self.apiClient, id = self.networkid, vlan = vlan1)
self.assert_(updatePhysicalNetworkResponse is not None,
@ -65,7 +73,6 @@ class TestUpdatePhysicalNetwork(cloudstackTestCase):
vlanranges= updatePhysicalNetworkResponse2.vlan
self.assert_(vlanranges is not None,
"No VLAN ranges found on the deployment")
self.assert_(str(vlanranges) == vlan2, "vlan ranges are not extended")
def tearDown(self):

View File

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