|
4 |
# Univention Management Console |
4 |
# Univention Management Console |
5 |
# module: manages updates |
5 |
# module: manages updates |
6 |
# |
6 |
# |
7 |
# Copyright 2008-2013 Univention GmbH |
7 |
# Copyright 2008-2014 Univention GmbH |
8 |
# |
8 |
# |
9 |
# http://www.univention.de/ |
9 |
# http://www.univention.de/ |
10 |
# |
10 |
# |
|
35 |
import univention.debug as ud |
35 |
import univention.debug as ud |
36 |
except ImportError: |
36 |
except ImportError: |
37 |
import univention.debug2 as ud |
37 |
import univention.debug2 as ud |
|
|
38 |
from univention.lib.policy_result import policy_result |
38 |
|
39 |
|
39 |
# TODO: Convert to absolute imports only AFTER the unit test has been adopted |
40 |
# TODO: Convert to absolute imports only AFTER the unit test has been adopted |
40 |
from commands import cmd_update, cmd_dist_upgrade_sim, cmd_dist_upgrade |
41 |
from commands import cmd_update, cmd_dist_upgrade_sim, cmd_dist_upgrade |
|
49 |
import httplib |
50 |
import httplib |
50 |
import socket |
51 |
import socket |
51 |
import univention.config_registry |
52 |
import univention.config_registry |
52 |
import traceback |
|
|
53 |
import urllib2 |
53 |
import urllib2 |
54 |
from urllib import quote |
54 |
from urllib import quote |
55 |
import subprocess |
55 |
import subprocess |
56 |
from operator import attrgetter, itemgetter |
|
|
57 |
import new |
56 |
import new |
58 |
import tempfile |
57 |
import tempfile |
59 |
import shutil |
58 |
import shutil |
|
160 |
raise ValueError( 'string does not match UCS version pattern' ) |
159 |
raise ValueError( 'string does not match UCS version pattern' ) |
161 |
self.major, self.minor, self.patchlevel = map(int, match.groups()) |
160 |
self.major, self.minor, self.patchlevel = map(int, match.groups()) |
162 |
|
161 |
|
|
|
162 |
def to_dict(self): |
163 |
return {'major' : self.major, 'minor' : self.minor, 'patchlevel' : self.patchlevel} |
164 |
|
163 |
def __getitem__(self, k): |
165 |
def __getitem__(self, k): |
164 |
'''Dual natured dictionary: retrieve value from attribute.''' |
166 |
'''Dual natured dictionary: retrieve value from attribute.''' |
165 |
return self.__dict__[k] |
167 |
return self.__dict__[k] |
|
554 |
self.architectures = [ os.popen('dpkg --print-architecture 2>/dev/null').readline()[:-1] ] |
556 |
self.architectures = [ os.popen('dpkg --print-architecture 2>/dev/null').readline()[:-1] ] |
555 |
|
557 |
|
556 |
self.ucr_reinit() |
558 |
self.ucr_reinit() |
|
|
559 |
self._policy_limit = None |
557 |
|
560 |
|
558 |
def config_repository( self ): |
561 |
def config_repository( self ): |
559 |
'''Retrieve configuration to access repository. Overridden in UniventionMirror.''' |
562 |
'''Retrieve configuration to access repository. Overridden in UniventionMirror.''' |
|
568 |
'''Re-initialize settings''' |
571 |
'''Re-initialize settings''' |
569 |
self.configRegistry=univention.config_registry.ConfigRegistry() |
572 |
self.configRegistry=univention.config_registry.ConfigRegistry() |
570 |
self.configRegistry.load() |
573 |
self.configRegistry.load() |
|
|
574 |
self._policy_limit = None |
571 |
|
575 |
|
572 |
self.is_repository_server = self.configRegistry.is_true('local/repository', False) |
576 |
self.is_repository_server = self.configRegistry.is_true('local/repository', False) |
573 |
|
577 |
|
|
628 |
self.log.exception('Failed server detection: %s' % (e,)) |
632 |
self.log.exception('Failed server detection: %s' % (e,)) |
629 |
raise |
633 |
raise |
630 |
|
634 |
|
|
|
635 |
def _get_policy_limit(self): |
636 |
if self._policy_limit is None: |
637 |
ucs_version = UCS_Version((100, 100, 100)) |
638 |
try: |
639 |
result, policies = policy_result(self.configRegistry['ldap/hostdn']) |
640 |
except Exception as e: |
641 |
ud.debug(ud.NETWORK, ud.WARN, str(e)) |
642 |
else: |
643 |
try: |
644 |
active = result['univentionUpdateActivate'][0] |
645 |
version = result['univentionUpdateVersion'][0] |
646 |
except (KeyError, IndexError): |
647 |
pass |
648 |
else: |
649 |
if active == 'TRUE': |
650 |
try: |
651 |
ucs_version = UCS_Version(version) |
652 |
except (ValueError, TypeError): |
653 |
ud.debug(ud.NETWORK, ud.WARN, 'Unable to parse univentionUpdateVersion %s' % version) |
654 |
self._policy_limit = ucs_version |
655 |
return self._policy_limit |
656 |
|
631 |
def get_next_version(self, version, components=[], errorsto='stderr'): |
657 |
def get_next_version(self, version, components=[], errorsto='stderr'): |
632 |
'''Check if a new patchlevel, minor or major release is available for the given version. |
658 |
'''Check if a new patchlevel, minor or major release is available for the given version. |
633 |
Components must be available for the same major.minor version. |
659 |
Components must be available for the same major.minor version. |
|
637 |
|
663 |
|
638 |
def versions(major, minor, patchlevel): |
664 |
def versions(major, minor, patchlevel): |
639 |
"""Generate next valid version numbers as hash.""" |
665 |
"""Generate next valid version numbers as hash.""" |
|
|
666 |
next_versions = [] |
667 |
policy_limit = self._get_policy_limit() |
640 |
if patchlevel < 99: |
668 |
if patchlevel < 99: |
641 |
yield {'major':major, 'minor':minor, 'patchlevel':patchlevel+1} |
669 |
next_versions.append(UCS_Version((major, minor, patchlevel + 1))) |
642 |
if minor < 99: |
670 |
if minor < 99: |
643 |
yield {'major':major, 'minor':minor+1, 'patchlevel':0} |
671 |
next_versions.append(UCS_Version((major, minor + 1, 0))) |
644 |
if major < 99: |
672 |
if major < 99: |
645 |
yield {'major':major+1, 'minor':0, 'patchlevel':0} |
673 |
next_versions.append(UCS_Version((major + 1, 0, 0))) |
|
|
674 |
for next_version in next_versions: |
675 |
if next_version <= policy_limit: |
676 |
yield next_version.to_dict() |
677 |
else: |
678 |
ud.debug(ud.NETWORK, ud.PROCESS, '%s not used because Policy only allows releases up to %s' % (next_version, policy_limit)) |
646 |
|
679 |
|
647 |
for ver in versions(version.major, version.minor, version.patchlevel): |
680 |
for ver in versions(version.major, version.minor, version.patchlevel): |
648 |
repo = UCSRepoPool(prefix=self.server, part='maintained', **ver) |
681 |
repo = UCSRepoPool(prefix=self.server, part='maintained', **ver) |