示例#1
0
    def _post_update_alba_plugin_alba(cls, components):
        """
        Execute some functionality after the ALBA plugin packages have been updated for the ASD manager nodes
        :param components: Update components which have been executed
        :type components: list
        :return: None
        :rtype: NoneType
        """
        if PackageFactory.COMP_ALBA not in components:
            return

        # First run post-update migrations to update services, config mgmt, ... and restart services afterwards
        for method_name in ['migrate', 'migrate_sdm']:
            try:
                # noinspection PyUnresolvedReferences
                from ovs.lib.albamigration import AlbaMigrationController
                cls._logger.debug(
                    'Executing migration code: AlbaMigrationController.{0}()'.
                    format(method_name))
                getattr(AlbaMigrationController, method_name)()
            except ImportError:
                cls._logger.error('Could not import AlbaMigrationController')
            except Exception:
                cls._logger.exception(
                    'Migration code for the ALBA plugin failed to be executed')

        # Update ALBA nodes
        method_name = inspect.currentframe().f_code.co_name
        cls._logger.info('Executing hook {0}'.format(method_name))
        alba_nodes = sorted(
            AlbaNodeList.get_albanodes_by_type(AlbaNode.NODE_TYPES.ASD),
            key=lambda an: ExtensionsToolbox.advanced_sort(element=an.ip,
                                                           separator='.'))
        for alba_node in alba_nodes:
            services_to_restart = []
            for component in components:
                if component not in alba_node.package_information:
                    continue

                component_info = alba_node.package_information[component]
                if 'services_post_update' not in component_info:
                    # Package_information still has the old format, so refresh update information
                    # This can occur when updating from earlier than 2.11.0 to 2.11.0 and older
                    try:
                        GenericController.refresh_package_information()
                    except:
                        cls._logger.exception(
                            '{0}: Refreshing package information failed'.
                            format(alba_node.ip))
                    alba_node.discard()
                    component_info = alba_node.package_information.get(
                        component, {})

                services_post_update = dict(
                    (int(key), value) for key, value in component_info.get(
                        'services_post_update', {}).iteritems())
                for restart_order in sorted(services_post_update):
                    for service_name in sorted(
                            services_post_update[restart_order]):
                        if service_name not in services_to_restart:
                            services_to_restart.append(service_name)

            if len(services_to_restart) > 0:
                alba_node.client.restart_services(
                    service_names=services_to_restart)

        # Renew maintenance services
        cls._logger.info('Checkup maintenance agents')
        AlbaController.checkup_maintenance_agents.delay()

        cls._logger.info('Executed hook {0}'.format(method_name))
示例#2
0
    def _package_install_plugin_alba(cls, components=None):
        """
        Update the packages related to the ASD manager
        :param components: Components which have been selected for update
        :type components: list
        :return: Boolean indicating whether to continue with the update or not
        :rtype: bool
        """
        cls._logger.info('Updating packages for ALBA plugin')
        if components is None:
            components = [PackageFactory.COMP_ALBA]

        abort = False
        alba_nodes = sorted(
            AlbaNodeList.get_albanodes_by_type(AlbaNode.NODE_TYPES.ASD),
            key=lambda an: ExtensionsToolbox.advanced_sort(element=an.ip,
                                                           separator='.'))
        for alba_node in alba_nodes:
            cls._logger.debug('ALBA Node {0}: Verifying packages'.format(
                alba_node.ip))
            for component in components:
                packages = alba_node.package_information.get(
                    component, {}).get('packages', {})
                package_names = sorted(packages)
                # Always install the extensions package first
                if PackageFactory.PKG_OVS_EXTENSIONS in package_names:
                    package_names.remove(PackageFactory.PKG_OVS_EXTENSIONS)
                    package_names.insert(0, PackageFactory.PKG_OVS_EXTENSIONS)

                if len(package_names) > 0:
                    cls._logger.debug(
                        'ALBA Node {0}: Packages for component {1}: {2}'.
                        format(alba_node.ip, component, package_names))
                for package_name in package_names:
                    try:
                        installed = packages[package_name]['installed']
                        candidate = packages[package_name]['candidate']

                        if candidate == alba_node.client.update_installed_version_package(
                                package_name=package_name):
                            # Package has already been installed by another hook
                            continue

                        cls._logger.debug(
                            'ALBA Node {0}: Updating package {1} ({2} --> {3})'
                            .format(alba_node.ip, package_name, installed,
                                    candidate))
                        alba_node.client.execute_update(package_name)
                        cls._logger.debug(
                            'ALBA Node {0}: Updated package {1}'.format(
                                alba_node.ip, package_name))
                    except requests.ConnectionError as ce:
                        if 'Connection aborted.' not in ce.message:  # This error is thrown due the post-update code of the SDM package which restarts the asd-manager service
                            cls._logger.exception(
                                'ALBA Node {0}: Failed to update package {1}'.
                                format(alba_node.ip, package_name))
                            abort = True
                    except Exception:
                        cls._logger.exception(
                            'ALBA Node {0}: Failed to update package {1}'.
                            format(alba_node.ip, package_name))
                        abort = True

        if abort is False:
            cls._logger.info('Updated packages for ALBA plugin')
        return abort