Exemplo n.º 1
0
    def test_register_before_instance(self):
        ServiceControl.register_listener('test_service_2', self.example_func)

        test_service_2 = ServiceControl.create('test_service_2')

        self.add_commands(
            CommandCaptureCommand(('/sbin/service', 'test_service_2', 'start'),
                                  executions_remaining=1),
            CommandCaptureCommand(
                ('/sbin/service', 'test_service_2', 'status'),
                executions_remaining=1),
            CommandCaptureCommand(('/sbin/service', 'test_service_2', 'stop'),
                                  executions_remaining=1),
            CommandCaptureCommand(
                ('/sbin/service', 'test_service_2', 'status'),
                rc=1,
                executions_remaining=1))

        self.received_codes = []

        response = test_service_2.start(retry_time=0.1, validate_time=0.1)

        self.assertEqual(response, None)
        self.assertListEqual(self.received_codes,
                             [('test_service_2', 'SERVICESTARTING'),
                              ('test_service_2', 'SERVICESTARTED')])

        self.received_codes = []

        ServiceControl.unregister_listener('test_service_2', self.example_func)

        response = test_service_2.stop(retry_time=0.1, validate_time=0.1)

        self.assertEqual(response, None)
        self.assertListEqual(self.received_codes, [])
Exemplo n.º 2
0
    def test_service_register_listener_and_receive_fail_validation(self):
        self.add_commands(
            CommandCaptureCommand(('/sbin/service', 'test_service', 'start')),
            CommandCaptureCommand(('/sbin/service', 'test_service', 'status'),
                                  rc=1))

        self.received_codes = []

        ServiceControl.register_listener('test_service', self.example_func)

        response = self.test_service.start(retry_time=0.1, validate_time=0.1)

        self.assertEqual(
            response,
            'Service test_service is not running after being started')
        self.assertListEqual(self.received_codes,
                             [('test_service', 'SERVICESTARTING'),
                              ('test_service', 'SERVICESTARTERROR')])

        # reset so we can test both stop and start fail validation within same test
        self.reset_command_capture()
        self.add_commands(
            CommandCaptureCommand(('/sbin/service', 'test_service', 'stop')),
            CommandCaptureCommand(('/sbin/service', 'test_service', 'status'),
                                  rc=0))
        self.received_codes = []
        response = self.test_service.stop(retry_time=0.1, validate_time=0.1)

        self.assertEqual(
            response,
            'Service test_service is still running after being stopped')
        self.assertListEqual(self.received_codes,
                             [('test_service', 'SERVICESTOPPING'),
                              ('test_service', 'SERVICESTOPERROR')])
Exemplo n.º 3
0
    def test_service_register_listener_and_receive_success(self):
        self.add_commands(
            CommandCaptureCommand(('/sbin/service', 'test_service', 'start'),
                                  executions_remaining=1),
            CommandCaptureCommand(('/sbin/service', 'test_service', 'status'),
                                  executions_remaining=1),
            CommandCaptureCommand(('/sbin/service', 'test_service', 'stop'),
                                  executions_remaining=1),
            CommandCaptureCommand(('/sbin/service', 'test_service', 'status'),
                                  rc=1,
                                  executions_remaining=1))

        self.received_codes = []

        ServiceControl.register_listener('test_service', self.example_func)

        response = self.test_service.start(retry_time=0.1, validate_time=0.1)

        self.assertEqual(response, None)
        self.assertListEqual(self.received_codes,
                             [('test_service', 'SERVICESTARTING'),
                              ('test_service', 'SERVICESTARTED')])

        self.received_codes = []
        response = self.test_service.stop(retry_time=0.1, validate_time=0.1)

        self.assertEqual(response, None)
        self.assertListEqual(self.received_codes,
                             [('test_service', 'SERVICESTOPPING'),
                              ('test_service', 'SERVICESTOPPED')])
Exemplo n.º 4
0
def _stop_talker_thread():
    global talker_thread

    if talker_thread is not None:
        console_log.debug("Stopping talker thread")
        talker_thread.stop()
        talker_thread = None
        ServiceControl.unregister_listener('corosync', _corosync_listener)
Exemplo n.º 5
0
def _start_talker_thread(interface):
    global talker_thread

    if talker_thread is None:
        console_log.debug("Starting talker thread")
        talker_thread = TalkerThread(interface, console_log)
        talker_thread.start()
        ServiceControl.register_listener('corosync', _corosync_listener)
Exemplo n.º 6
0
    def test_service_register_listener_and_receive_fail_initial(self):
        self.add_commands(
            CommandCaptureCommand(('/sbin/service', 'test_service', 'start'),
                                  rc=1,
                                  stderr='Service Failed To Start',
                                  executions_remaining=1),
            CommandCaptureCommand(('/sbin/service', 'test_service', 'start'),
                                  rc=1,
                                  stderr='Service Failed To Start',
                                  executions_remaining=1))

        self.received_codes = []

        ServiceControl.register_listener('test_service', self.example_func)

        response = self.test_service.start(retry_time=0.1,
                                           validate_time=0.1,
                                           retry_count=1)

        self.assertEqual(
            response,
            "Error (1) running '/sbin/service test_service start': '' 'Service Failed To Start'"
        )
        self.assertListEqual(self.received_codes,
                             [('test_service', 'SERVICESTARTING'),
                              ('test_service', 'SERVICESTARTERROR')])

        # reset so we can test both stop and start fail validation within same test
        self.reset_command_capture()
        self.add_commands(
            CommandCaptureCommand(('/sbin/service', 'test_service', 'stop'),
                                  rc=1,
                                  stderr='Service Failed To Stop',
                                  executions_remaining=1),
            CommandCaptureCommand(('/sbin/service', 'test_service', 'stop'),
                                  rc=1,
                                  stderr='Service Failed To Stop',
                                  executions_remaining=1))

        self.received_codes = []
        response = self.test_service.stop(retry_time=0.1,
                                          validate_time=0.1,
                                          retry_count=1)

        self.assertEqual(
            response,
            "Error (1) running '/sbin/service test_service stop': '' 'Service Failed To Stop'"
        )
        self.assertListEqual(self.received_codes,
                             [('test_service', 'SERVICESTOPPING'),
                              ('test_service', 'SERVICESTOPERROR')])
Exemplo n.º 7
0
    def setUp(self):
        super(TestServiceStateEL7, self).setUp()

        mock.patch.object(
            util, 'platform_info',
            util.PlatformInfo('Linux', 'CentOS', 0.0, '7.2', 0.0, 0,
                              '')).start()

        self.test = ServiceControl.create('test_service')
        self.assertEqual(type(self.test), ServiceControlEL7)
Exemplo n.º 8
0
def stop_monitored_copytool(id):
    # Stop the monitor after the copytool so that we can relay the
    # unconfigure event.

    for service_name in ['chroma-copytool-monitor', 'chroma-copytool']:
        service = ServiceControl.create('%s-%s' % (service_name, id))

        if os.path.exists(_init_file_name(service_name,
                                          id)) and service.running:
            error = service.stop()

            if error:
                return agent_error(error)

            os.remove(_init_file_name(service_name, id))

        service.daemon_reload(
        )  # Finally cause the system agents to see our changes.

    return agent_result_ok
Exemplo n.º 9
0
def start_monitored_copytool(id):
    # Start the monitor first so that we have a reader on the FIFO when
    # the copytool begins emitting events. Then start the copytool

    copytool_vars = _copytool_vars(id)

    for service_name in ['chroma-copytool-monitor', 'chroma-copytool']:
        _write_service_init(service_name, copytool_vars['id'],
                            copytool_vars['ct_path'],
                            copytool_vars['ct_arguments'])

        service = ServiceControl.create('%s-%s' % (service_name, id))

        service.daemon_reload()

        if service.running:
            error = service.restart()
        else:
            error = service.start()

        if error:
            return agent_error(error)

    return agent_result_ok
Exemplo n.º 10
0
from chroma_agent.log import daemon_log
from manage_corosync import start_corosync, stop_corosync
from chroma_agent.lib.pacemaker import pacemaker_running
from chroma_agent.lib.corosync import corosync_running
from chroma_agent.chroma_common.lib.service_control import ServiceControl
from chroma_agent.chroma_common.lib.agent_rpc import agent_error, agent_result_ok, agent_ok_or_error

# The window of time in which we count resource monitor failures
RSRC_FAIL_WINDOW = "20m"
# The number of times in the above window a resource monitor can fail
# before we migrate it
RSRC_FAIL_MIGRATION_COUNT = "3"

PACEMAKER_CONFIGURE_TIMEOUT = 120

pacemaker_service = ServiceControl.create('pacemaker')
corosync_service = ServiceControl.create('corosync')


def _get_cluster_size():
    # you'd think there'd be a way to query the value of a property
    # such as "expected-quorum-votes" but there does not seem to be, so
    # just count nodes instead
    rc, stdout, stderr = AgentShell.run_old(["crm_node", "-l"])

    if not stdout:
        return 0

    n = 0
    for line in stdout.rstrip().split('\n'):
        node_id, name, status = line.split(" ")
"""
Corosync verification
"""

from os import remove
from collections import namedtuple
import errno
import re

from chroma_agent.chroma_common.lib.service_control import ServiceControl
from chroma_agent.chroma_common.lib.firewall_control import FirewallControl

from chroma_agent.lib.corosync import CorosyncRingInterface, render_config, write_config_to_file
from chroma_agent.chroma_common.lib.agent_rpc import agent_error, agent_result_ok, agent_ok_or_error

corosync_service = ServiceControl.create('corosync')
firewall_control = FirewallControl.create()


def start_corosync():
    return agent_ok_or_error(corosync_service.start())


def stop_corosync():

    return agent_ok_or_error(corosync_service.stop())


def restart_corosync():
    return agent_ok_or_error(corosync_service.restart())
Exemplo n.º 12
0
# Copyright (c) 2017 Intel Corporation. All rights reserved.
# Use of this source code is governed by a MIT-style
# license that can be found in the LICENSE file.

from chroma_agent.chroma_common.lib.ntp import NTPConfig
from chroma_agent.chroma_common.lib.agent_rpc import agent_ok_or_error
from chroma_agent.chroma_common.lib.service_control import ServiceControl

ntp_service = ServiceControl.create('ntpd')


def unconfigure_ntp():
    """
    Unconfigure the ntp client

    :return: Value using simple return protocol
    """
    return configure_ntp(None)


def configure_ntp(ntp_server):
    """
    Change the ntp configuration file to use the server passed

    :return: Value using simple return protocol
    """
    error = NTPConfig().add(ntp_server)
    if error:
        return error
    else:
        return agent_ok_or_error(ntp_service.restart())
# Copyright (c) 2017 Intel Corporation. All rights reserved.
# Use of this source code is governed by a MIT-style
# license that can be found in the LICENSE file.


import os

from chroma_agent.device_plugins.syslog import SYSLOG_PORT
from chroma_agent.chroma_common.lib.agent_rpc import agent_ok_or_error
from chroma_agent.chroma_common.lib.service_control import ServiceControl

rsyslog_service = ServiceControl.create('rsyslog')


def unconfigure_rsyslog():
    """
    Modify the rsyslogd configuration to stop forwarding messages to chroma

    :return: None
    """
    return _configure_rsyslog("")


def configure_rsyslog():
    """
    Modify the rsyslogd configuration to forward all messages to chroma

    :return: None
    """
    return _configure_rsyslog("127.0.0.1")
Exemplo n.º 14
0
it from manager)
"""

import os

from chroma_agent import config
from chroma_agent.agent_client import AgentClient, HttpError
from chroma_agent.agent_daemon import ServerProperties
from chroma_agent.crypto import Crypto
from chroma_agent.device_plugins.action_runner import CallbackAfterResponse
from chroma_agent.log import console_log
from chroma_agent.plugin_manager import ActionPluginManager, DevicePluginManager
from chroma_agent.chroma_common.lib.service_control import ServiceControl
from chroma_agent.chroma_common.lib.agent_rpc import agent_ok_or_error

agent_service = ServiceControl.create('chroma-agent')


def _service_is_running():
    # returns True if running
    return agent_service.running


def _start_service():
    return agent_ok_or_error(agent_service.start())


def _stop_service():
    return agent_ok_or_error(agent_service.stop())

Corosync verification
"""

from chroma_agent.log import console_log
from chroma_agent.lib.shell import AgentShell
from chroma_agent.lib.corosync import CorosyncRingInterface
from chroma_agent.action_plugins.manage_corosync_common import InterfaceInfo

from chroma_agent.chroma_common.lib.service_control import ServiceControl
from chroma_agent.chroma_common.lib.firewall_control import FirewallControl
from chroma_agent.chroma_common.lib.agent_rpc import agent_error
from chroma_agent.chroma_common.lib.agent_rpc import agent_ok_or_error

PCS_TCP_PORT = 2224

corosync_service = ServiceControl.create('corosync')
pcsd_service = ServiceControl.create('pcsd')
firewall_control = FirewallControl.create()

PCS_USER = '******'
PCS_CLUSTER_NAME = 'lustre-ha-cluster'
COROSYNC_CONF_PATH = '/etc/corosync/corosync.conf'


def start_corosync2():
    return agent_ok_or_error(corosync_service.enable() or corosync_service.start())


def stop_corosync2():
    return agent_ok_or_error(corosync_service.stop())