Commit 579cf79d authored by Nicolas Wavrant's avatar Nicolas Wavrant

free_port: updates recipe to use getValueFromPreviousRun from GenericBaseRecipe

parent 6009e5ac
......@@ -25,12 +25,13 @@
#
##############################################################################
import ConfigParser
import os
import netaddr
import socket
class Recipe(object):
from slapos.recipe.librecipe.generic import GenericBaseRecipe
class Recipe(GenericBaseRecipe):
"""
Uses the socket python standard library to get an unused port.
......@@ -48,17 +49,13 @@ class Recipe(object):
# If this check isn't done, a new port would be picked for every upgrade
# of the software release
try:
parser = ConfigParser.RawConfigParser()
if os.path.exists(buildout['buildout']['installed']):
with open(buildout['buildout']['installed']) as config_file:
parser.readfp(config_file)
port = parser.get(name, 'port')
# Port can be 0 in case of upgrade: some old service still runs on port,
# so 0 is returned by default. Then, on next run, this recipe is processed
# again until a correct value is returned
if port != '0':
self.options['port'] = port
return
port = self.getValueFromPreviousRun(name, 'port')
# Port can be 0 in case of upgrade: some old service still runs on port,
# so 0 is returned by default. Then, on next run, this recipe is processed
# again until a correct value is returned
if port != '0':
self.options['port'] = port
return
except (IOError, ConfigParser.NoSectionError, ConfigParser.NoOptionError):
pass
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment