def test_emit_console_notification_error_status(self, mock_cond_emit):
     notif_utils.emit_console_notification(
         self.task, 'console_set', fields.NotificationStatus.ERROR)
     mock_cond_emit.assert_called_once_with(
         self.task,
         node_objects.NodeConsoleNotification,
         node_objects.NodePayload,
         'console_set',
         fields.NotificationLevel.ERROR,
         fields.NotificationStatus.ERROR,
     )
 def test_emit_console_notification_error_status(self, mock_cond_emit):
     notif_utils.emit_console_notification(
         self.task, 'console_set', fields.NotificationStatus.ERROR)
     mock_cond_emit.assert_called_once_with(
         self.task,
         node_objects.NodeConsoleNotification,
         node_objects.NodePayload,
         'console_set',
         fields.NotificationLevel.ERROR,
         fields.NotificationStatus.ERROR,
     )
Example #3
0
def _start_console_in_deploy(task):
    """Start console at the end of deployment.

    Console is stopped at tearing down not to be exposed to an instance user.
    Then, restart at deployment.

    :param task: a TaskManager instance with an exclusive lock
    """

    if not task.node.console_enabled:
        return

    notify_utils.emit_console_notification(task, 'console_restore',
                                           fields.NotificationStatus.START)
    try:
        task.driver.console.start_console(task)
    except Exception as err:
        msg = (_('Failed to start console while deploying the '
                 'node %(node)s: %(err)s.') % {
                     'node': task.node.uuid,
                     'err': err
                 })
        LOG.error(msg)
        task.node.last_error = msg
        task.node.console_enabled = False
        task.node.save()
        notify_utils.emit_console_notification(task, 'console_restore',
                                               fields.NotificationStatus.ERROR)
    else:
        notify_utils.emit_console_notification(task, 'console_restore',
                                               fields.NotificationStatus.END)
Example #4
0
    def _start_consoles(self, context):
        """Start consoles if set enabled.

        :param: context: request context
        """
        filters = {'console_enabled': True}

        node_iter = self.iter_nodes(filters=filters)

        for node_uuid, driver in node_iter:
            try:
                with task_manager.acquire(context,
                                          node_uuid,
                                          shared=False,
                                          purpose='start console') as task:
                    notify_utils.emit_console_notification(
                        task, 'console_restore',
                        obj_fields.NotificationStatus.START)
                    try:
                        LOG.debug('Trying to start console of node %(node)s',
                                  {'node': node_uuid})
                        task.driver.console.start_console(task)
                        LOG.info(
                            _LI('Successfully started console of node '
                                '%(node)s'), {'node': node_uuid})
                        notify_utils.emit_console_notification(
                            task, 'console_restore',
                            obj_fields.NotificationStatus.END)
                    except Exception as err:
                        msg = (_('Failed to start console of node %(node)s '
                                 'while starting the conductor, so changing '
                                 'the console_enabled status to False, error: '
                                 '%(err)s') % {
                                     'node': node_uuid,
                                     'err': err
                                 })
                        LOG.error(msg)
                        # If starting console failed, set node console_enabled
                        # back to False and set node's last error.
                        task.node.last_error = msg
                        task.node.console_enabled = False
                        task.node.save()
                        notify_utils.emit_console_notification(
                            task, 'console_restore',
                            obj_fields.NotificationStatus.ERROR)
            except exception.NodeLocked:
                LOG.warning(
                    _LW('Node %(node)s is locked while trying to '
                        'start console on conductor startup'),
                    {'node': node_uuid})
                continue
            except exception.NodeNotFound:
                LOG.warning(
                    _LW("During starting console on conductor "
                        "startup, node %(node)s was not found"),
                    {'node': node_uuid})
                continue
            finally:
                # Yield on every iteration
                eventlet.sleep(0)
Example #5
0
    def _start_consoles(self, context):
        """Start consoles if set enabled.

        :param: context: request context
        """
        filters = {'console_enabled': True}

        node_iter = self.iter_nodes(filters=filters)

        for node_uuid, driver in node_iter:
            try:
                with task_manager.acquire(context, node_uuid, shared=False,
                                          purpose='start console') as task:
                    notify_utils.emit_console_notification(
                        task, 'console_restore',
                        obj_fields.NotificationStatus.START)
                    try:
                        LOG.debug('Trying to start console of node %(node)s',
                                  {'node': node_uuid})
                        task.driver.console.start_console(task)
                        LOG.info('Successfully started console of node '
                                 '%(node)s', {'node': node_uuid})
                        notify_utils.emit_console_notification(
                            task, 'console_restore',
                            obj_fields.NotificationStatus.END)
                    except Exception as err:
                        msg = (_('Failed to start console of node %(node)s '
                                 'while starting the conductor, so changing '
                                 'the console_enabled status to False, error: '
                                 '%(err)s')
                               % {'node': node_uuid, 'err': err})
                        LOG.error(msg)
                        # If starting console failed, set node console_enabled
                        # back to False and set node's last error.
                        task.node.last_error = msg
                        task.node.console_enabled = False
                        task.node.save()
                        notify_utils.emit_console_notification(
                            task, 'console_restore',
                            obj_fields.NotificationStatus.ERROR)
            except exception.NodeLocked:
                LOG.warning('Node %(node)s is locked while trying to '
                            'start console on conductor startup',
                            {'node': node_uuid})
                continue
            except exception.NodeNotFound:
                LOG.warning("During starting console on conductor "
                            "startup, node %(node)s was not found",
                            {'node': node_uuid})
                continue
            finally:
                # Yield on every iteration
                eventlet.sleep(0)