Skip to content

Commit

Permalink
Fix a stack on pushdisks in the container.kvm driver
Browse files Browse the repository at this point in the history
Happens when the container configuration file is not present.

This patch makes sure we return an empty devices mapping in this case.
And switches a free-style cache implementation to a lazy property.
  • Loading branch information
cvaroqui committed Oct 11, 2018
1 parent 001e76e commit 5d1d439
Showing 1 changed file with 17 additions and 18 deletions.
35 changes: 17 additions & 18 deletions lib/resContainerKvm.py
Expand Up @@ -4,7 +4,7 @@
import os
import rcExceptions as ex
from rcGlobalEnv import rcEnv
from rcUtilities import justcall, cache, clear_cache
from rcUtilities import justcall, cache, clear_cache, lazy
from rcUtilitiesLinux import check_ping
import resContainer

Expand Down Expand Up @@ -156,15 +156,13 @@ def install_drp_flag(self):
tree = ElementTree()
tree.parse(self.cf)

""" create the vdisk if it does not exist yet
"""
# create the vdisk if it does not exist yet
if not os.path.exists(flag_disk_path):
with open(flag_disk_path, 'w') as f:
f.write('')
f.close()

""" check if drp flag is already set up
"""
# check if drp flag is already set up
for disk in tree.getiterator("disk"):
e = disk.find('source')
if e is None:
Expand All @@ -174,8 +172,7 @@ def install_drp_flag(self):
self.log.info("flag virtual disk already exists")
return

""" add vdisk to the vm xml config
"""
# add vdisk to the vm xml config
self.log.info("install drp flag virtual disk")
devices = tree.find("devices")
e = SubElement(devices, "disk", {'device': 'disk', 'type': 'file'})
Expand All @@ -185,17 +182,19 @@ def install_drp_flag(self):
tree.write(self.cf)

def sub_devs(self):
devmapping = self.devmap()
devs = set(map(lambda x: x[0], devmapping))
devs = set(map(lambda x: x[0], self.devmapping))
return devs

def devmap(self):
try:
return getattr(self, "devmapping")
except AttributeError:
pass

self.devmapping = []
@lazy
def devmapping(self):
"""
Return a list of (src, dst) devices tuples fount in the container
conifguration file.
"""
if not os.path.exists(self.cf):
# not yet received from peer node ?
return []
data = []

from xml.etree.ElementTree import ElementTree, SubElement
tree = ElementTree()
Expand All @@ -213,8 +212,8 @@ def devmap(self):
if 'dev' not in s.attrib:
continue
dst = s.attrib['dev']
self.devmapping.append((src, dst))
return self.devmapping
data.append((src, dst))
return data

def _status(self, verbose=False):
return resContainer.Container._status(self, verbose=verbose)
Expand Down

0 comments on commit 5d1d439

Please sign in to comment.