Alon Bar-Lev has uploaded a new change for review.

Change subject: packaging: setup: support package upgrade
......................................................................

packaging: setup: support package upgrade

yum reads exclude/include information to sack when first used. this has
a potential conflict with the overall transaction as the ordering
determine when the versionlock is read.

otopi was modified to create a new miniyum instance at when transaction
is started. this enables the PROGRAMS stage to run and read a fresh copy
of versionlock.

we cannot handle the versionlock using the regular transaction as it its
unlocked content should wrap the transaction or we have random yum
incompatibilities.

also, we cannot retrieve our package version in order to perform the
lock, as the setup package may be newer than the other packages, so use
rpm directly in order to figure out the specific versions of packages.

Change-Id: I399fb48d8cbd393ee12f700c0a68e7c1b51218f3
Signed-off-by: Alon Bar-Lev <alo...@redhat.com>
---
M ovirt-engine.spec.in
M packaging/setup/bin/ovirt-engine-setup
M packaging/setup/ovirt_engine_setup/constants.py
M packaging/setup/plugins/ovirt-engine-common/core/offlinepackager.py
M packaging/setup/plugins/ovirt-engine-setup/core/uninstall.py
M packaging/setup/plugins/ovirt-engine-setup/dialog/titles.py
M packaging/setup/plugins/ovirt-engine-setup/distro-rpm/__init__.py
A packaging/setup/plugins/ovirt-engine-setup/distro-rpm/packages.py
D packaging/setup/plugins/ovirt-engine-setup/distro-rpm/versionlock.py
9 files changed, 444 insertions(+), 116 deletions(-)


  git pull ssh://gerrit.ovirt.org:29418/ovirt-engine refs/changes/77/15777/1

diff --git a/ovirt-engine.spec.in b/ovirt-engine.spec.in
index b93b35d..f8a3ae0 100644
--- a/ovirt-engine.spec.in
+++ b/ovirt-engine.spec.in
@@ -233,6 +233,7 @@
 Summary: Setup and upgrade scripts for %{product_name_short}
 Group: Virtualization/Management
 Requires: %{name}
+Requires: libselinux-python
 Requires: libxml2-python
 Requires: lsof
 Requires: nfs-utils
diff --git a/packaging/setup/bin/ovirt-engine-setup 
b/packaging/setup/bin/ovirt-engine-setup
index f66e831..bbe9a01 100755
--- a/packaging/setup/bin/ovirt-engine-setup
+++ b/packaging/setup/bin/ovirt-engine-setup
@@ -31,6 +31,8 @@
         Load configuration files.
     --config-append=file
         Load extra configuration files.
+    --offline
+        Offline mode.
     --generate-answer=file
         Generate answer file.
     --jboss-home=dir
@@ -46,8 +48,6 @@
 baseenv="APPEND:BASE/pluginPath=str:${scriptdir}/../plugins 
APPEND:BASE/pluginGroups=str:ovirt-engine-common:ovirt-engine-setup"
 otopienv=""
 environment=""
-
-environment="${environment} OVESETUP_CORE/offlinePackager=bool:True"
 
 while [ -n "$1" ]; do
        x="$1"
@@ -72,6 +72,9 @@
                --jboss-home=*)
                        environment="${environment} 
OVESETUP_CONFIG/jbossHome=str:${v}"
                ;;
+               --offline)
+                       environment="${environment} 
OVESETUP_CORE/offlinePackager=bool:True PACKAGER/yumpackagerEnabled=bool:False"
+               ;;
                --help)
                        usage
                ;;
diff --git a/packaging/setup/ovirt_engine_setup/constants.py 
b/packaging/setup/ovirt_engine_setup/constants.py
index 9527b37..575811c 100644
--- a/packaging/setup/ovirt_engine_setup/constants.py
+++ b/packaging/setup/ovirt_engine_setup/constants.py
@@ -447,6 +447,7 @@
     DIALOG_TITLES_S_ENGINE = 'osetup.dialog.titles.engine.start'
     DIALOG_TITLES_S_NETWORK = 'osetup.dialog.titles.network.start'
     DIALOG_TITLES_S_FIREWALL = 'osetup.dialog.titles.firewall.start'
+    DIALOG_TITLES_S_PACKAGES = 'osetup.dialog.titles.packaging.start'
     DIALOG_TITLES_S_PKI = 'osetup.dialog.titles.pki.start'
     DIALOG_TITLES_S_SYSTEM = 'osetup.dialog.titles.system.start'
     DIALOG_TITLES_E_APACHE = 'osetup.dialog.titles.apache.end'
@@ -454,6 +455,7 @@
     DIALOG_TITLES_E_ENGINE = 'osetup.dialog.titles.engine.end'
     DIALOG_TITLES_E_NETWORK = 'osetup.dialog.titles.network.end'
     DIALOG_TITLES_E_FIREWALL = 'osetup.dialog.titles.firewall.end'
+    DIALOG_TITLES_E_PACKAGES = 'osetup.dialog.titles.packages.end'
     DIALOG_TITLES_E_PKI = 'osetup.dialog.titles.pki.end'
     DIALOG_TITLES_E_SYSTEM = 'osetup.dialog.titles.system.end'
 
@@ -475,7 +477,6 @@
     USER_ADMIN = 'admin'
     DOMAIN_INTERNAL = 'internal'
     ENGINE_SERVICE_NAME = 'ovirt-engine'
-    ENGINE_PACKAGE_NAME = 'ovirt-engine'
     PKI_PASSWORD = 'mypass'
     DEFAULT_CLUSTER_ID = '99408929-82CF-4DC7-A532-9D998063FA95'
     MINIMUM_SPACE_ISODOMAIN_MB = 350
@@ -484,10 +485,14 @@
 
     ENGINE_URI = '/ovirt-engine'
 
+    ENGINE_PACKAGE_NAME = 'ovirt-engine'
+    ENGINE_PACKAGE_SETUP_NAME = '%s-setup' % ENGINE_PACKAGE_NAME
+    UPGRADE_YUM_GROUP = 'ovirt-engine-3.3'
+
     @classproperty
     def RPM_LOCK_LIST(self):
         return [
-            '{name}%s-{{version}}-{{release}}'.format(
+            '{name}%s'.format(
                 name=self.ENGINE_PACKAGE_NAME,
             ) % package for package in (
                 '',
@@ -805,6 +810,27 @@
 @util.export
 @util.codegen
 @osetupattrsclass
+class RPMDistroEnv(object):
+    @osetupattrs(
+        answerfile=True,
+        summary=True,
+        description=_('Upgrade packages'),
+    )
+    def ENABLE_UPGRADE(self):
+        return 'OSETUP_RPMDISTRO/enableUpgrade'
+
+    @osetupattrs(
+        answerfile=True,
+        summary=True,
+        description=_('Require packages rollback'),
+    )
+    def REQUIRE_ROLLBACK(self):
+        return 'OSETUP_RPMDISTRO/requireRollback'
+
+
+@util.export
+@util.codegen
+@osetupattrsclass
 class AIOEnv(object):
     ENABLE = 'OVESETUP_AIO/enable'
 
diff --git 
a/packaging/setup/plugins/ovirt-engine-common/core/offlinepackager.py 
b/packaging/setup/plugins/ovirt-engine-common/core/offlinepackager.py
index b2eaa97..a95e83a 100644
--- a/packaging/setup/plugins/ovirt-engine-common/core/offlinepackager.py
+++ b/packaging/setup/plugins/ovirt-engine-common/core/offlinepackager.py
@@ -19,6 +19,7 @@
 """Fake packager for offline mode"""
 
 
+import platform
 import gettext
 _ = lambda m: gettext.dgettext(message=m, domain='ovirt-engine-setup')
 
@@ -59,6 +60,9 @@
 
     def __init__(self, context):
         super(Plugin, self).__init__(context=context)
+        self._distribution = platform.linux_distribution(
+            full_distribution_name=0
+        )[0]
 
     @plugin.event(
         stage=plugin.Stages.STAGE_INIT,
@@ -69,7 +73,10 @@
     def _init(self):
         if self.environment.setdefault(
             osetupcons.CoreEnv.OFFLINE_PACKAGER,
-            False
+            (
+                self.environment[osetupcons.CoreEnv.DEVELOPER_MODE] or
+                self._distribution not in ('redhat', 'fedora', 'centos')
+            ),
         ):
             self.logger.debug('Registering offline packager')
             self.context.registerPackager(packager=self)
diff --git a/packaging/setup/plugins/ovirt-engine-setup/core/uninstall.py 
b/packaging/setup/plugins/ovirt-engine-setup/core/uninstall.py
index 3023cc4..05d4d50 100644
--- a/packaging/setup/plugins/ovirt-engine-setup/core/uninstall.py
+++ b/packaging/setup/plugins/ovirt-engine-setup/core/uninstall.py
@@ -97,6 +97,7 @@
 
     @plugin.event(
         stage=plugin.Stages.STAGE_CLEANUP,
+        priority=plugin.Stages.PRIORITY_LOW,
     )
     def _cleanup(self):
         config = configparser.ConfigParser()
diff --git a/packaging/setup/plugins/ovirt-engine-setup/dialog/titles.py 
b/packaging/setup/plugins/ovirt-engine-setup/dialog/titles.py
index 17594bb..d210bb2 100644
--- a/packaging/setup/plugins/ovirt-engine-setup/dialog/titles.py
+++ b/packaging/setup/plugins/ovirt-engine-setup/dialog/titles.py
@@ -19,6 +19,7 @@
 """Titles plugin."""
 
 
+import platform
 import gettext
 _ = lambda m: gettext.dgettext(message=m, domain='ovirt-engine-setup')
 
@@ -41,10 +42,38 @@
 
     def __init__(self, context):
         super(Plugin, self).__init__(context=context)
+        self._distribution = platform.linux_distribution(
+            full_distribution_name=0
+        )[0]
+
+    @plugin.event(
+        stage=plugin.Stages.STAGE_CUSTOMIZATION,
+        name=osetupcons.Stages.DIALOG_TITLES_S_PACKAGES,
+        condition=lambda self: self._distribution in (
+            'redhat', 'fedora', 'centos',
+        ),
+    )
+    def _title_s_packages(self):
+        self._title(
+            text=_('PACKAGES'),
+        )
+
+    @plugin.event(
+        stage=plugin.Stages.STAGE_CUSTOMIZATION,
+        name=osetupcons.Stages.DIALOG_TITLES_E_PACKAGES,
+        after=[
+            osetupcons.Stages.DIALOG_TITLES_S_PACKAGES,
+        ],
+    )
+    def _title_e_packages(self):
+        pass
 
     @plugin.event(
         stage=plugin.Stages.STAGE_CUSTOMIZATION,
         name=osetupcons.Stages.DIALOG_TITLES_S_NETWORK,
+        after=[
+            osetupcons.Stages.DIALOG_TITLES_E_PACKAGES,
+        ],
     )
     def _title_s_network(self):
         self._title(
diff --git a/packaging/setup/plugins/ovirt-engine-setup/distro-rpm/__init__.py 
b/packaging/setup/plugins/ovirt-engine-setup/distro-rpm/__init__.py
index 6b7acdf..49b4be4 100644
--- a/packaging/setup/plugins/ovirt-engine-setup/distro-rpm/__init__.py
+++ b/packaging/setup/plugins/ovirt-engine-setup/distro-rpm/__init__.py
@@ -22,12 +22,12 @@
 
 
 from otopi import util
-from . import versionlock
+from . import packages
 
 
 @util.export
 def createPlugins(context):
-    versionlock.Plugin(context=context)
+    packages.Plugin(context=context)
 
 
 # vim: expandtab tabstop=4 shiftwidth=4
diff --git a/packaging/setup/plugins/ovirt-engine-setup/distro-rpm/packages.py 
b/packaging/setup/plugins/ovirt-engine-setup/distro-rpm/packages.py
new file mode 100644
index 0000000..9785a18
--- /dev/null
+++ b/packaging/setup/plugins/ovirt-engine-setup/distro-rpm/packages.py
@@ -0,0 +1,370 @@
+#
+# ovirt-engine-setup -- ovirt engine setup
+# Copyright (C) 2013 Red Hat, Inc.
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+#     http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+
+
+"""
+Package upgrade plugin.
+"""
+
+import os
+import platform
+import datetime
+import gettext
+_ = lambda m: gettext.dgettext(message=m, domain='ovirt-engine-setup')
+
+
+from otopi import util
+from otopi import plugin
+
+
+from ovirt_engine_setup import constants as osetupcons
+from ovirt_engine_setup import dialog
+
+
+@util.export
+class Plugin(plugin.PluginBase):
+    """
+    Package upgrade plugin.
+    """
+
+    def _filterVersionLock(self):
+        modified = False
+        content = []
+
+        if os.path.exists(
+            osetupcons.FileLocations.OVIRT_ENGINE_YUM_VERSIONLOCK
+        ):
+            with open(
+                osetupcons.FileLocations.OVIRT_ENGINE_YUM_VERSIONLOCK,
+            ) as f:
+                for line in f.read().splitlines():
+                    if line.find(
+                        osetupcons.Const.ENGINE_PACKAGE_NAME
+                    ) == -1:
+                        content.append(line)
+                    else:
+                        modified = True
+
+        return (modified, content)
+
+    def _removeMeFromVersionLock(self):
+        modified, content = self._filterVersionLock()
+        if modified:
+            os.rename(
+                osetupcons.FileLocations.OVIRT_ENGINE_YUM_VERSIONLOCK,
+                '%s.%s' % (
+                    osetupcons.FileLocations.OVIRT_ENGINE_YUM_VERSIONLOCK,
+                    datetime.datetime.now().strftime('%Y%m%d%H%M%S'),
+                ),
+            )
+            with open(
+                osetupcons.FileLocations.OVIRT_ENGINE_YUM_VERSIONLOCK,
+                'w'
+            ) as f:
+                f.write('\n'.join(content)+'\n')
+
+    def _addMeToVersionLock(self):
+        # execute rpm directly
+        # yum is not good in offline usage
+        rc, out, err = self.execute(
+            args=[
+                self.command.get('rpm'),
+                '-q',
+            ] + osetupcons.Const.RPM_LOCK_LIST,
+        )
+
+        self.environment[
+            osetupcons.CoreEnv.UNINSTALL_UNREMOVABLE_FILES
+        ].append(osetupcons.FileLocations.OVIRT_ENGINE_YUM_VERSIONLOCK)
+
+        self.environment[
+            osetupcons.CoreEnv.REGISTER_UNINSTALL_GROUPS
+        ].createGroup(
+            group='versionlock',
+            description='YUM version locking configuration',
+            optional=False
+        ).addLines(
+            'versionlock',
+            osetupcons.FileLocations.OVIRT_ENGINE_YUM_VERSIONLOCK,
+            out,
+        )
+
+        modified, content = self._filterVersionLock()
+        content.extend(out)
+        with open(
+            osetupcons.FileLocations.OVIRT_ENGINE_YUM_VERSIONLOCK,
+            'w',
+        ) as f:
+            f.write('\n'.join(content) + '\n')
+
+    def _getSink(self):
+        class MyMiniYumSink(self._miniyum.MiniYumSinkBase):
+            def __init__(self, log):
+                super(MyMiniYumSink, self).__init__()
+                self._log = log
+
+            def verbose(self, msg):
+                super(MyMiniYumSink, self).verbose(msg)
+                self._log.debug('Yum: %s', msg)
+
+            def info(self, msg):
+                super(MyMiniYumSink, self).info(msg)
+                self._log.info('Yum: %s', msg)
+
+            def error(self, msg):
+                super(MyMiniYumSink, self).error(msg)
+                self._log.error('Yum: %s', msg)
+        return MyMiniYumSink(self.logger)
+
+    def _checkForPackagesUpdate(self, packages):
+        upgradeAvailable = False
+        myum = self._miniyum.MiniYum(
+            sink=self._getSink(),
+            disabledPlugins=['versionlock'],
+        )
+        with myum.transaction():
+            myum.update(
+                packages=packages,
+            )
+            if myum.buildTransaction():
+                upgradeAvailable = True
+
+                # Some debug
+                for p in myum.queryTransaction():
+                    self.logger.debug('PACKAGE: [%s] %s' % (
+                        p['operation'],
+                        p['display_name']
+                    ))
+
+        return upgradeAvailable
+
+    def _checkForProductUpdate(self):
+        haveRollback = True
+        upgradeAvailable = False
+        myum = self._miniyum.MiniYum(
+            sink=self._getSink(),
+            disabledPlugins=['versionlock'],
+        )
+        with myum.transaction():
+            for group in myum.queryGroups():
+                if group['name'] == osetupcons.Const.UPGRADE_YUM_GROUP:
+                    self._useGroup = True
+                    break
+
+            if self._useGroup:
+                myum.updateGroup(
+                    group=osetupcons.Const.UPGRADE_YUM_GROUP
+                )
+            else:
+                myum.update(
+                    packages=(osetupcons.Const.ENGINE_PACKAGE_NAME,)
+                )
+
+            if myum.buildTransaction():
+                upgradeAvailable = True
+
+                # Some debug
+                for p in myum.queryTransaction():
+                    self.logger.debug('PACKAGE: [%s] %s' % (
+                        p['operation'],
+                        p['display_name']
+                    ))
+
+                # Verify all installed packages available in yum
+                for package in myum.queryTransaction():
+                    for query in myum.queryPackages(
+                        patterns=[package['name']]
+                    ):
+                        if query['operation'] == 'installed':
+                            self.logger.debug(
+                                'Checking package %s',
+                                query['display_name'],
+                            )
+                            if not myum.queryPackages(
+                                patterns=[query['display_name']],
+                                showdups=True,
+                            ):
+                                self.logger.debug(
+                                    'package %s not available in cache' % (
+                                        query['display_name']
+                                    )
+                                )
+                                haveRollback = False
+
+        return (upgradeAvailable, haveRollback)
+
+    def __init__(self, context):
+        super(Plugin, self).__init__(context=context)
+        self._enabled = False
+        self._useGroup = False
+        self._distribution = platform.linux_distribution(
+            full_distribution_name=0
+        )[0]
+
+    @plugin.event(
+        stage=plugin.Stages.STAGE_SETUP,
+        condition=lambda self: (
+            not self.environment[
+                osetupcons.CoreEnv.DEVELOPER_MODE
+            ] and
+            not self.environment[
+                osetupcons.CoreEnv.OFFLINE_PACKAGER
+            ]
+        ),
+    )
+    def _setup(self):
+        self.environment.setdefault(
+            osetupcons.RPMDistroEnv.ENABLE_UPGRADE,
+            None
+        )
+        self.environment.setdefault(
+            osetupcons.RPMDistroEnv.REQUIRE_ROLLBACK,
+            None
+        )
+        if self._distribution in ('redhat', 'fedora', 'centos'):
+            self.command.detect('rpm')
+
+            from otopi import miniyum
+            self._miniyum = miniyum
+            self._enabled = True
+
+    @plugin.event(
+        stage=plugin.Stages.STAGE_CUSTOMIZATION,
+        before=[
+            osetupcons.Stages.DIALOG_TITLES_E_PACKAGES,
+        ],
+        after=[
+            osetupcons.Stages.DIALOG_TITLES_S_PACKAGES,
+        ],
+        condition=lambda self: self._enabled,
+    )
+    def _customization(self):
+        upgradeAvailable = None
+        haveRollback = None
+
+        if self.environment[osetupcons.RPMDistroEnv.ENABLE_UPGRADE] is None:
+            self.logger.info(_('Checking for product upgrade...'))
+            (
+                upgradeAvailable,
+                haveRollback,
+            ) = self._checkForProductUpdate()
+
+            if upgradeAvailable:
+                self.environment[
+                    osetupcons.RPMDistroEnv.ENABLE_UPGRADE
+                ] = dialog.queryBoolean(
+                    dialog=self.dialog,
+                    name='OVESETUP_RPMDISTRO_PACKAGE_UPGRADE',
+                    note=_(
+                        'Setup has found packages to be upgrade, '
+                        'do you wish to upgrade them now? '
+                        '(@VALUES@) [@DEFAULT@]: '
+                    ),
+                    prompt=True,
+                    true=_('Yes'),
+                    false=_('No'),
+                    default=True,
+                )
+
+        if self.environment[osetupcons.RPMDistroEnv.ENABLE_UPGRADE]:
+            self.logger.info(_('Checking for setup upgrade...'))
+            if self._checkForPackagesUpdate(
+                packages=(osetupcons.Const.ENGINE_PACKAGE_SETUP_NAME,)
+            ):
+                self.logger.error(
+                    _(
+                        'An upgrade for the etup package was found. '
+                        'Please upgrade that package and the execute '
+                        'setup again. Package name is {package}.'
+                    ).format(
+                        package=osetupcons.Const.ENGINE_PACKAGE_SETUP_NAME,
+                    )
+                )
+                raise RuntimeError(_('Please update setup package'))
+
+            if upgradeAvailable is None:
+                (
+                    upgradeAvailable,
+                    haveRollback,
+                ) = self._checkForProductUpdate()
+
+            if upgradeAvailable:
+                if not haveRollback:
+                    if self.environment[
+                        osetupcons.RPMDistroEnv.REQUIRE_ROLLBACK
+                    ] is None:
+                        self.environment[
+                            osetupcons.RPMDistroEnv.REQUIRE_ROLLBACK
+                        ] = dialog.queryBoolean(
+                            dialog=self.dialog,
+                            name='OVESETUP_RPMDISTRO_REQUIRE_ROLLBACK',
+                            note=_(
+                                'Setup will not be able to rollback new '
+                                'packages in case of a failure because these '
+                                'are missing at repository, do you want to '
+                                'continue? (@VALUES@) [@DEFAULT@]: '
+                            ),
+                            prompt=True,
+                            true=_('Yes'),
+                            false=_('No'),
+                            default=False,
+                        )
+
+                    if self.environment[
+                        osetupcons.RPMDistroEnv.REQUIRE_ROLLBACK
+                    ]:
+                        raise RuntimeError(
+                            _('Package rollback information is unavailable')
+                        )
+
+        self._enabled = self.environment[
+            osetupcons.RPMDistroEnv.ENABLE_UPGRADE
+        ]
+
+        if not upgradeAvailable:
+            self.dialog.note(text=_('No update is available'))
+
+    @plugin.event(
+        stage=plugin.Stages.STAGE_TRANSACTION_BEGIN,
+        priority=plugin.Stages.PRIORITY_HIGH,
+        condition=lambda self: self._enabled,
+    )
+    def transactionBegin(self):
+        self._removeMeFromVersionLock()
+
+    @plugin.event(
+        stage=plugin.Stages.STAGE_PACKAGES,
+        condition=lambda self: self._enabled,
+    )
+    def packages(self):
+        if self._useGroup:
+            self.packager.updateGroup(
+                group=osetupcons.Const.UPGRADE_YUM_GROUP,
+            )
+        else:
+            self.packager.update(
+                packages=(osetupcons.Const.ENGINE_PACKAGE_NAME,),
+            )
+
+    @plugin.event(
+        stage=plugin.Stages.STAGE_CLEANUP,
+    )
+    def cleanup(self):
+        self._addMeToVersionLock()
+
+
+# vim: expandtab tabstop=4 shiftwidth=4
diff --git 
a/packaging/setup/plugins/ovirt-engine-setup/distro-rpm/versionlock.py 
b/packaging/setup/plugins/ovirt-engine-setup/distro-rpm/versionlock.py
deleted file mode 100644
index e351d23..0000000
--- a/packaging/setup/plugins/ovirt-engine-setup/distro-rpm/versionlock.py
+++ /dev/null
@@ -1,109 +0,0 @@
-#
-# ovirt-engine-setup -- ovirt engine setup
-# Copyright (C) 2013 Red Hat, Inc.
-#
-# Licensed under the Apache License, Version 2.0 (the "License");
-# you may not use this file except in compliance with the License.
-# You may obtain a copy of the License at
-#
-#     http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS,
-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-# See the License for the specific language governing permissions and
-# limitations under the License.
-#
-
-
-"""
-Yum versionlock configuration plugin.
-"""
-
-import os
-import platform
-import gettext
-_ = lambda m: gettext.dgettext(message=m, domain='ovirt-engine-setup')
-
-
-from otopi import util
-from otopi import plugin
-from otopi import constants as otopicons
-from otopi import filetransaction
-
-
-from ovirt_engine_setup import constants as osetupcons
-
-
-@util.export
-class Plugin(plugin.PluginBase):
-    """
-    Yum versionlock configuration plugin.
-    """
-    def __init__(self, context):
-        super(Plugin, self).__init__(context=context)
-        self._enabled = False
-        self._distribution = platform.linux_distribution(
-            full_distribution_name=0
-        )[0]
-
-    @plugin.event(
-        stage=plugin.Stages.STAGE_SETUP,
-        condition=lambda self: not self.environment[
-            osetupcons.CoreEnv.DEVELOPER_MODE
-        ],
-    )
-    def _setup(self):
-        if self._distribution in ('redhat', 'fedora', 'centos'):
-            self._enabled = True
-
-    @plugin.event(
-        stage=plugin.Stages.STAGE_MISC,
-        condition=lambda self: self._enabled,
-    )
-    def _configversionlock(self):
-        #Can't assume we're the owner of the locking list.
-        content = osetupcons.Const.RPM_LOCK_LIST
-        self.environment[
-            osetupcons.CoreEnv.REGISTER_UNINSTALL_GROUPS
-        ].createGroup(
-            group='versionlock',
-            description='YUM version locking configuration',
-            optional=False
-        ).addLines(
-            'versionlock',
-            osetupcons.FileLocations.OVIRT_ENGINE_YUM_VERSIONLOCK,
-            '\n'.join(content).format(
-                version=osetupcons.Const.RPM_VERSION,
-                release=osetupcons.Const.RPM_RELEASE,
-            ).splitlines()
-        )
-        if os.path.exists(
-            osetupcons.FileLocations.OVIRT_ENGINE_YUM_VERSIONLOCK
-        ):
-            with open(
-                osetupcons.FileLocations.OVIRT_ENGINE_YUM_VERSIONLOCK
-            ) as f:
-                for line in f.read().splitlines():
-                    if line.find(osetupcons.Const.ENGINE_PACKAGE_NAME) == -1:
-                        content.append(line)
-        self.environment[otopicons.CoreEnv.MAIN_TRANSACTION].append(
-            filetransaction.FileTransaction(
-                name=osetupcons.FileLocations.OVIRT_ENGINE_YUM_VERSIONLOCK,
-                owner=self.environment[osetupcons.SystemEnv.USER_ROOT],
-                mode=0o644,
-                enforcePermissions=True,
-                content=(
-                    '\n'.join(content).format(
-                        version=osetupcons.Const.RPM_VERSION,
-                        release=osetupcons.Const.RPM_RELEASE,
-                    )
-                ),
-            )
-        )
-        self.environment[
-            osetupcons.CoreEnv.UNINSTALL_UNREMOVABLE_FILES
-        ].append(osetupcons.FileLocations.OVIRT_ENGINE_YUM_VERSIONLOCK)
-
-
-# vim: expandtab tabstop=4 shiftwidth=4


-- 
To view, visit http://gerrit.ovirt.org/15777
To unsubscribe, visit http://gerrit.ovirt.org/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I399fb48d8cbd393ee12f700c0a68e7c1b51218f3
Gerrit-PatchSet: 1
Gerrit-Project: ovirt-engine
Gerrit-Branch: master
Gerrit-Owner: Alon Bar-Lev <alo...@redhat.com>
_______________________________________________
Engine-patches mailing list
Engine-patches@ovirt.org
http://lists.ovirt.org/mailman/listinfo/engine-patches

Reply via email to