Ejemplo n.º 1
0
 def test_systemctl(self, mock_systemctl):
     mock_systemctl.return_value = True
     self.mock_runner.run.return_value = ("", 0)
     lib.disable_service(self.mock_runner, self.service)
     self.mock_runner.run.assert_called_once_with(
         ["systemctl", "disable", self.service + ".service"]
     )
Ejemplo n.º 2
0
 def test_systemctl_not_installed(self, mock_is_installed, mock_systemctl):
     mock_is_installed.return_value = False
     mock_systemctl.return_value = True
     lib.disable_service(self.mock_runner, self.service)
     self.assertEqual(self.mock_runner.run.call_count, 0)
     mock_is_installed.assert_called_once_with(self.mock_runner,
                                               self.service, None)
Ejemplo n.º 3
0
 def test_not_systemctl_not_installed(
         self, mock_is_installed, mock_systemctl
 ):
     mock_is_installed.return_value = False
     mock_systemctl.return_value = False
     lib.disable_service(self.mock_runner, self.service)
     self.assertEqual(self.mock_runner.run.call_count, 0)
Ejemplo n.º 4
0
def disable_booth(env: LibraryEnvironment, instance_name=None):
    """
    Disable specified instance of booth service, systemd systems supported only.

    env
    string instance_name -- booth instance name
    """
    external.ensure_is_systemd()
    booth_env = env.get_booth_env(instance_name)
    _ensure_live_env(env, booth_env)
    instance_name = booth_env.instance_name

    try:
        external.disable_service(env.cmd_runner(), "booth", instance_name)
    except external.DisableServiceError as e:
        raise LibraryError(
            ReportItem.error(
                reports.messages.ServiceActionFailed(
                    reports.const.SERVICE_ACTION_DISABLE,
                    "booth",
                    e.message,
                    instance=instance_name,
                )
            )
        )
    env.report_processor.report(
        ReportItem.info(
            reports.messages.ServiceActionSucceeded(
                reports.const.SERVICE_ACTION_DISABLE,
                "booth",
                instance=instance_name,
            )
        )
    )
Ejemplo n.º 5
0
 def test_not_systemctl(self, mock_is_installed, mock_systemctl):
     mock_is_installed.return_value = True
     mock_systemctl.return_value = False
     self.mock_runner.run.return_value = ("", 0)
     lib.disable_service(self.mock_runner, self.service)
     self.mock_runner.run.assert_called_once_with(
         ["chkconfig", self.service, "off"]
     )
Ejemplo n.º 6
0
 def test_systemctl(self, mock_is_installed, mock_systemctl):
     mock_is_installed.return_value = True
     mock_systemctl.return_value = True
     self.mock_runner.run.return_value = ("", "Removed symlink", 0)
     lib.disable_service(self.mock_runner, self.service)
     mock_is_installed.assert_called_once_with(self.mock_runner,
                                               self.service, None)
     self.mock_runner.run.assert_called_once_with(
         [_systemctl, "disable", self.service + ".service"])
Ejemplo n.º 7
0
 def test_not_systemctl(self, mock_is_installed, mock_systemctl):
     mock_is_installed.return_value = True
     mock_systemctl.return_value = False
     self.mock_runner.run.return_value = ("", "", 0)
     lib.disable_service(self.mock_runner, self.service)
     mock_is_installed.assert_called_once_with(self.mock_runner,
                                               self.service, None)
     self.mock_runner.run.assert_called_once_with(
         [_chkconfig, self.service, "off"])
Ejemplo n.º 8
0
 def test_systemctl(self, mock_is_installed, mock_systemctl):
     mock_is_installed.return_value = True
     mock_systemctl.return_value = True
     self.mock_runner.run.return_value = ("", "Removed symlink", 0)
     lib.disable_service(self.mock_runner, self.service)
     mock_is_installed.assert_called_once_with(
         self.mock_runner, self.service, None
     )
     self.mock_runner.run.assert_called_once_with(
         [_systemctl, "disable", self.service + ".service"]
     )
Ejemplo n.º 9
0
 def test_instance_systemctl(self, mock_is_installed, mock_systemctl):
     instance = "test"
     mock_is_installed.return_value = True
     mock_systemctl.return_value = True
     self.mock_runner.run.return_value = ("", "Removed symlink", 0)
     lib.disable_service(self.mock_runner, self.service, instance=instance)
     mock_is_installed.assert_called_once_with(self.mock_runner,
                                               self.service, instance)
     self.mock_runner.run.assert_called_once_with([
         _systemctl, "disable",
         "{0}@{1}.service".format(self.service, "test")
     ])
Ejemplo n.º 10
0
 def test_instance_systemctl(self, mock_is_installed, mock_systemctl):
     instance = "test"
     mock_is_installed.return_value = True
     mock_systemctl.return_value = True
     self.mock_runner.run.return_value = ("", "Removed symlink", 0)
     lib.disable_service(self.mock_runner, self.service, instance=instance)
     mock_is_installed.assert_called_once_with(
         self.mock_runner, self.service, instance
     )
     self.mock_runner.run.assert_called_once_with([
         _systemctl,
         "disable",
         "{0}@{1}.service".format(self.service, "test")
     ])
Ejemplo n.º 11
0
def disable_booth(env, name=None):
    """
    Disable specified instance of booth service. Currently it is supported only
    systemd systems.

    env -- LibraryEnvironment
    name -- string, name of booth instance
    """
    external.ensure_is_systemd()
    try:
        external.disable_service(env.cmd_runner(), "booth", name)
    except external.DisableServiceError as e:
        raise LibraryError(
            reports.service_disable_error("booth", e.message, instance=name))
    env.report_processor.process(
        reports.service_disable_success("booth", instance=name))
Ejemplo n.º 12
0
def disable_booth(env):
    """
    Disable specified instance of booth service. Currently it is supported only
    systemd systems.

    env -- LibraryEnvironment
    """
    external.ensure_is_systemd()
    name = env.booth.name
    try:
        external.disable_service(env.cmd_runner(), "booth", name)
    except external.DisableServiceError as e:
        raise LibraryError(reports.service_disable_error(
            "booth", e.message, instance=name
        ))
    env.report_processor.process(reports.service_disable_success(
        "booth", instance=name
    ))
Ejemplo n.º 13
0
 def test_systemctl_failed(self, mock_systemctl):
     mock_systemctl.return_value = True
     self.mock_runner.run.return_value = ("", 1)
     self.assertRaises(
         lib.DisableServiceError,
         lambda: lib.disable_service(self.mock_runner, self.service)
     )
     self.mock_runner.run.assert_called_once_with(
         ["systemctl", "disable", self.service + ".service"]
     )
Ejemplo n.º 14
0
 def test_not_systemctl_failed(self, mock_is_installed, mock_systemctl):
     mock_is_installed.return_value = True
     mock_systemctl.return_value = False
     self.mock_runner.run.return_value = ("", 1)
     self.assertRaises(
         lib.DisableServiceError,
         lambda: lib.disable_service(self.mock_runner, self.service)
     )
     self.mock_runner.run.assert_called_once_with(
         ["chkconfig", self.service, "off"]
     )
Ejemplo n.º 15
0
 def test_not_systemctl_failed(self, mock_is_installed, mock_systemctl):
     mock_is_installed.return_value = True
     mock_systemctl.return_value = False
     self.mock_runner.run.return_value = ("", "error", 1)
     self.assertRaises(
         lib.DisableServiceError,
         lambda: lib.disable_service(self.mock_runner, self.service))
     mock_is_installed.assert_called_once_with(self.mock_runner,
                                               self.service, None)
     self.mock_runner.run.assert_called_once_with(
         [_chkconfig, self.service, "off"])
Ejemplo n.º 16
0
 def test_systemctl_failed(self, mock_is_installed, mock_systemctl):
     mock_is_installed.return_value = True
     mock_systemctl.return_value = True
     self.mock_runner.run.return_value = ("", "Failed", 1)
     self.assertRaises(
         lib.DisableServiceError,
         lambda: lib.disable_service(self.mock_runner, self.service))
     mock_is_installed.assert_called_once_with(self.mock_runner,
                                               self.service, None)
     self.mock_runner.run.assert_called_once_with(
         [_systemctl, "disable", self.service + ".service"])
Ejemplo n.º 17
0
def disable_booth(env, instance_name=None):
    """
    Disable specified instance of booth service, systemd systems supported only.

    LibraryEnvironment env
    string instance_name -- booth instance name
    """
    external.ensure_is_systemd()
    booth_env = env.get_booth_env(instance_name)
    _ensure_live_env(env, booth_env)
    instance_name = booth_env.instance_name

    try:
        external.disable_service(env.cmd_runner(), "booth", instance_name)
    except external.DisableServiceError as e:
        raise LibraryError(
            reports.service_disable_error("booth",
                                          e.message,
                                          instance=instance_name))
    env.report_processor.process(
        reports.service_disable_success("booth", instance=instance_name))
Ejemplo n.º 18
0
def qdevice_disable(runner):
    """
    make qdevice not start automatically on boot on local host
    """
    external.disable_service(runner, __service_name)
Ejemplo n.º 19
0
def qdevice_disable(runner):
    """
    make qdevice not start automatically on boot on local host
    """
    external.disable_service(runner, __service_name)
Ejemplo n.º 20
0
def cluster_destroy(argv):
    if argv:
        raise CmdLineInputError()
    if "--all" in utils.pcs_options:
        # destroy remote and guest nodes
        cib = None
        lib_env = utils.get_lib_env()
        try:
            cib = lib_env.get_cib()
        except LibraryError as e:
            warn("Unable to load CIB to get guest and remote nodes from it, "
                 "those nodes will not be deconfigured.")
        if cib is not None:
            try:
                all_remote_nodes = get_existing_nodes_names(cib=cib)
                if len(all_remote_nodes) > 0:
                    _destroy_pcmk_remote_env(lib_env,
                                             all_remote_nodes,
                                             skip_offline_nodes=True,
                                             allow_fails=True)
            except LibraryError as e:
                utils.process_library_reports(e.args)

        # destroy full-stack nodes
        destroy_cluster(utils.get_corosync_conf_facade().get_nodes_names())
    else:
        print("Shutting down pacemaker/corosync services...")
        for service in ["pacemaker", "corosync-qdevice", "corosync"]:
            # Returns an error if a service is not running. It is safe to
            # ignore it since we want it not to be running anyways.
            utils.stop_service(service)
        print("Killing any remaining services...")
        kill_local_cluster_services()
        try:
            utils.disableServices()
        except:
            # previously errors were suppressed in here, let's keep it that way
            # for now
            pass
        try:
            disable_service(utils.cmd_runner(), lib_sbd.get_sbd_service_name())
        except:
            # it's not a big deal if sbd disable fails
            pass

        print("Removing all cluster configuration files...")
        dummy_output, dummy_retval = utils.run([
            "rm",
            "-f",
            settings.corosync_conf_file,
            settings.corosync_authkey_file,
            settings.pacemaker_authkey_file,
        ])
        state_files = [
            "cib.xml*", "cib-*", "core.*", "hostcache", "cts.*", "pe*.bz2",
            "cib.*"
        ]
        for name in state_files:
            dummy_output, dummy_retval = utils.run([
                "find", "/var/lib/pacemaker", "-name", name, "-exec", "rm",
                "-f", "{}", ";"
            ])
        try:
            qdevice_net.client_destroy()
        except:
            # errors from deleting other files are suppressed as well
            # we do not want to fail if qdevice was not set up
            pass