ifupdown2 used /var/tmp/network/ to store its state file
upstream users reported that when /var/tmp is not mounted
before network configuration ifupdown2 fails. We now let
user define which location they want to use for the state
file.
closes: #918832
Reported-by: Maximilian Wilhelm <max@sdn.clinic>
Signed-off-by: Julien Fortin <julien@cumulusnetworks.com>
+ifupdown2 (1.2.4-1) unstable; urgency=medium
+
+ * Fix: statemanager directory path customization via ifupdown2.conf
+ (closes: #918832)
+
+ -- Julien Fortin <julien@cumulusnetworks.com> Fri, 11 Jan 2019 23:42:42 +0000
+
ifupdown2 (1.2.3-1) unstable; urgency=medium
* Fix: log: use stderr if syslog initialization fails (closes: #917534)
ifupdown2 (1.2.3-1) unstable; urgency=medium
* Fix: log: use stderr if syslog initialization fails (closes: #917534)
# based on the physical interface they are running on top of.
# set this flag to 0 to disable this behaviour
adjust_logical_dev_mtu=1
# based on the physical interface they are running on top of.
# set this flag to 0 to disable this behaviour
adjust_logical_dev_mtu=1
+
+# directory where the state file is stored
+# if this directory doesn't exists ifupdown2 will create it
+# if directory creation fails or state_dir variable is empty
+# state_dir will default to /run/network/
+state_dir=/run/network/
self._cache_no_repeats = {}
self._cache_no_repeats = {}
+ # initialize global config object with config passed by the user
+ # This makes config available to addon modules
+ ifupdownConfig.config = self.config
+ statemanager.statemanager_api.init()
+
if self.flags.STATEMANAGER_ENABLE:
self.statemanager = statemanager.statemanager_api
try:
if self.flags.STATEMANAGER_ENABLE:
self.statemanager = statemanager.statemanager_api
try:
self._ifaceobj_squash_internal = True if self.config.get(
'ifaceobj_squash_internal', '1') == '1' else False
self._ifaceobj_squash_internal = True if self.config.get(
'ifaceobj_squash_internal', '1') == '1' else False
- # initialize global config object with config passed by the user
- # This makes config available to addon modules
- ifupdownConfig.config = self.config
-
self.validate_keywords = {
'<mac>': self._keyword_mac,
'<text>': self._keyword_text,
self.validate_keywords = {
'<mac>': self._keyword_mac,
'<text>': self._keyword_text,
from ifupdown2.ifupdown.iface import *
import ifupdown2.ifupdown.exceptions as exceptions
from ifupdown2.ifupdown.iface import *
import ifupdown2.ifupdown.exceptions as exceptions
+ import ifupdown2.ifupdown.ifupdownconfig as ifupdownConfig
except ImportError:
from ifupdown.iface import *
import ifupdown.exceptions as exceptions
except ImportError:
from ifupdown.iface import *
import ifupdown.exceptions as exceptions
+ import ifupdown.ifupdownconfig as ifupdownConfig
- state_dir = '/var/tmp/network/'
- """directory where the state file is stored """
+ __DEFAULT_STATE_DIR = "/run/network/"
state_filename = 'ifstatenew'
"""name of the satefile """
state_filename = 'ifstatenew'
"""name of the satefile """
which includes a dictionary of last pickled iface objects
"""
which includes a dictionary of last pickled iface objects
"""
+ self.state_dir = None
+ self.state_file = None
self.ifaceobjdict = OrderedDict()
self.logger = logging.getLogger('ifupdown.' +
self.__class__.__name__)
self.ifaceobjdict = OrderedDict()
self.logger = logging.getLogger('ifupdown.' +
self.__class__.__name__)
- if not os.path.exists(self.state_dir):
- os.mkdir(self.state_dir)
+
+ def init(self):
+ self.state_dir = ifupdownConfig.config.get("state_dir")
+ used_default = False
+
+ if not self.state_dir:
+ self.logger.debug("statemanager: state_dir not defined in config file, using default: %s" % self.__DEFAULT_STATE_DIR)
+ self.state_dir = self.__DEFAULT_STATE_DIR
+ used_default = True
+
+ try:
+ self._init_makedirs_state_dir()
+ except Exception as e:
+ if used_default:
+ # if the default path was used but still throws an exception...
+ raise
+ self.logger.info("statemanager: %s: using default directory: %s" % (e, self.__DEFAULT_STATE_DIR))
+ self.state_dir = self.__DEFAULT_STATE_DIR
+ try:
+ self._init_makedirs_state_dir()
+ except Exception as e:
+ raise Exception("statemanager: unable to create required directory: %s" % str(e))
+
if not os.path.exists(self.state_rundir):
if not os.path.exists(self.state_rundir):
- os.mkdir(self.state_rundir)
- self.state_file = self.state_dir + self.state_filename
+ os.makedirs(self.state_rundir)
+
+ self.state_file = "%s/%s" % (self.state_dir, self.state_filename)
+
+ def _init_makedirs_state_dir(self):
+ if not os.path.exists(self.state_dir):
+ os.makedirs(self.state_dir)
+
def save_ifaceobj(self, ifaceobj):
self.ifaceobjdict.setdefault(ifaceobj.name,
def save_ifaceobj(self, ifaceobj):
self.ifaceobjdict.setdefault(ifaceobj.name,