From fa2296fba2d9156e65397efc68b178163ac1b034 Mon Sep 17 00:00:00 2001 Message-Id: From: Philipp Hahn Date: Tue, 8 Oct 2013 13:25:54 +0200 Subject: [PATCH] Bug #30816: USS: handle primary interface Organization: Univention GmbH, Bremen, Germany Fix interface regular expressions. Proposed change --- .../umc/python/setup/__init__.py | 10 ++--- .../umc/python/setup/network.py | 41 ++++++-------------- .../umc/python/setup/util.py | 2 +- 3 files changed, 16 insertions(+), 37 deletions(-) diff --git a/branches/ucs-3.2/ucs-3.2-0/base/univention-system-setup/umc/python/setup/__init__.py b/branches/ucs-3.2/ucs-3.2-0/base/univention-system-setup/umc/python/setup/__init__.py index 5cf7506..7c71d2c 100644 --- a/branches/ucs-3.2/ucs-3.2-0/base/univention-system-setup/umc/python/setup/__init__.py +++ b/branches/ucs-3.2/ucs-3.2-0/base/univention-system-setup/umc/python/setup/__init__.py @@ -63,7 +63,7 @@ _ = Translation('univention-management-console-module-setup').translate PATH_SYS_CLASS_NET = '/sys/class/net' -RE_IPV4 = re.compile(r'^interfaces/(([^/_]+)(_[0-9])?)/(address|netmask)$') +RE_IPV4 = re.compile(r'^interfaces/(([^/]+?)(_[0-9])?)/(address|netmask)$') RE_IPV6_DEFAULT = re.compile(r'^interfaces/([^/]+)/ipv6/default/(prefix|address)$') RE_SPACE = re.compile(r'\s+') RE_SSL = re.compile(r'^ssl/.*') @@ -135,8 +135,7 @@ class Instance(umcm.Base): '''Reconfigures the system according to the values specified in the dict given as option named "values".''' - # get old and new values - orgValues = util.load_values() + # get new values values = request.options.get('values', {}) def _thread(request, obj): @@ -147,8 +146,7 @@ class Instance(umcm.Base): self._progressParser.reset() # write the profile file and run setup scripts - orgValues = util.load_values() - util.pre_save(values, orgValues) + util.pre_save(values) MODULE.info('saving profile values') util.write_profile(values) @@ -211,7 +209,7 @@ class Instance(umcm.Base): self._progressParser.reset() # write the profile file and run setup scripts - util.pre_save(values, orgValues) + util.pre_save(values) # on unjoined DC master the nameserver must be set to the external nameserver if newrole == 'domaincontroller_master' and not orgValues.get('joined'): diff --git a/branches/ucs-3.2/ucs-3.2-0/base/univention-system-setup/umc/python/setup/network.py b/branches/ucs-3.2/ucs-3.2-0/base/univention-system-setup/umc/python/setup/network.py index fc2e701..ff158ca 100644 --- a/branches/ucs-3.2/ucs-3.2-0/base/univention-system-setup/umc/python/setup/network.py +++ b/branches/ucs-3.2/ucs-3.2-0/base/univention-system-setup/umc/python/setup/network.py @@ -46,9 +46,9 @@ ucr.load() _ = Translation('univention-management-console-module-setup').translate -RE_INTERFACE = re.compile(r'^interfaces/(?!(?:primary|restart/auto|handler)$)([^/_]+)(_[0-9]+)?/') +RE_INTERFACE = re.compile(r'^interfaces/(?!(?:primary|restart/auto|handler)$)([^/]+?)(_[0-9]+)?/') RE_IPV6_ID = re.compile(r'^[a-zA-Z0-9]+\Z') -VALID_NAME_RE = re.compile(r'^[^/ \t\n\r\f]{1,16}\Z') +VALID_NAME_RE = re.compile(r'^(?![.]{1,2})[^/ \t\n\r\f]{1,15}\Z') PHYSICAL_INTERFACES = [dev['name'] for dev in detect_interfaces()] @@ -80,21 +80,6 @@ class IP6Set(set): class Interfaces(dict): """All network interfaces""" - @property - def primary(self): - """Returns the primary network interface if exists else None""" - for device in self.values(): - if device.primary: - return device - - @primary.setter - def primary(self, primary=None): - """Removes the primary flag from all devices and sets it to the new device if exists""" - for device in self.values(): - device.primary = False - if primary in self: - self[primary].primary = True - def __init__(self, *args, **kwargs): """Loads all network devices from UCR variables""" super(Interfaces, self).__init__(*args, **kwargs) @@ -102,7 +87,7 @@ class Interfaces(dict): ucr.load() # get all available interfaces - interfaces = set(RE_INTERFACE.match(key).group(1) for key in ucr if RE_INTERFACE.match(key)) + interfaces = set(_.group(1) for _ in (RE_INTERFACE.match(key) for key in ucr) if _) for name in interfaces: device = Device(name, self) device.parse_ucr() @@ -113,7 +98,7 @@ class Interfaces(dict): ucr.load() # remove old devices - to_remove = set(self.keys()).difference(set(interfaces.keys())) + to_remove = set(self.keys()) - set(interfaces.keys()) for name in to_remove: device = _RemovedDevice(name, self) self[device.name] = device @@ -131,7 +116,7 @@ class Interfaces(dict): """Returns a UCR representation of all interfaces""" ucr.load() - ucrv = {'interfaces/primary': None} + ucrv = {} # 'interfaces/primary' is handled in util.py for device in self.values(): ucrv.update(device.to_ucr()) @@ -261,9 +246,6 @@ class Device(object): self.ip4dynamic = False self.ip6dynamic = False - # flag indicating that this interface is the primary network interface of the system - self.primary = False - # flag indicating that this interface should automatically start at system startup self.start = None @@ -420,8 +402,6 @@ class Device(object): pattern = re.compile(r'^interfaces/%s(?:_[0-9]+)?/' % re.escape(name)) vals = dict((key, ucr[key]) for key in ucr if pattern.match(key)) - self.primary = ucr.get('interfaces/primary') == name - self.start = ucr.is_true(value=vals.pop('interfaces/%s/start' % (name), None)) self.type = vals.pop('interfaces/%s/type' % (name), None) @@ -473,9 +453,6 @@ class Device(object): for key, val in self._leftover: vals[key] = val - if self.primary: - vals['interfaces/primary'] = name - if self.start is not None: vals['interfaces/%s/start' % (name)] = str(bool(self.start)).lower() @@ -558,7 +535,12 @@ class Device(object): class _RemovedDevice(Device): """Internal class representing that a device have to be removed from UCR""" def to_ucr(self): - return dict((key, None) for key in ucr.iterkeys() if RE_INTERFACE.match(key)) + to_remove = {} + for key in ucr.iterkeys(): + match = RE_INTERFACE.match(key) + if match and self.name == match.group(1): + to_remove[key] = None + return to_remove def validate(self): return True @@ -823,7 +805,6 @@ class Bridge(Device): try: self.bridge_fd = int(value) except ValueError: - # invalid value pass else: options.append(option) diff --git a/branches/ucs-3.2/ucs-3.2-0/base/univention-system-setup/umc/python/setup/util.py b/branches/ucs-3.2/ucs-3.2-0/base/univention-system-setup/umc/python/setup/util.py index cc7fa45..650f53f 100644 --- a/branches/ucs-3.2/ucs-3.2-0/base/univention-system-setup/umc/python/setup/util.py +++ b/branches/ucs-3.2/ucs-3.2-0/base/univention-system-setup/umc/python/setup/util.py @@ -147,7 +147,7 @@ def _xkeymap(keymap): return xkeymap -def pre_save(newValues, oldValues): +def pre_save(newValues): '''Modify the final dict before saving it to the profile file.''' # use new system role (or as fallback the current system role) -- 1.7.10.4