def test_is_sysv_service_should_return_correct_value(self, get_chkconfig_output_mock): get_chkconfig_output_mock.return_value = dedent(""" service1 0:off 1:off 2:on 3:on 4:on 5:on 6:off service2 0:off 1:off 2:on 3:on 4:on 5:on 6:off ser3 0:off 1:off 2:off 3:on 4:on 5:on 6:off service4 0:off 1:off 2:on 3:on 4:on 5:on 6:off longservice5 0:off 1:off 2:off 3:on 4:on 5:on 6:off service6 0:off 1:on 2:on 3:on 4:on 5:on 6:off """).strip() self.assertTrue(is_sysv_service("service1")) get_chkconfig_output_mock.assert_called_once_with() self.assertFalse(is_sysv_service("noservice"))
def test_is_sysv_service_should_return_correct_value(self, command): chkconfigmock = Mock() chkconfigmock.return_value = dedent(""" service1 0:off 1:off 2:on 3:on 4:on 5:on 6:off service2 0:off 1:off 2:on 3:on 4:on 5:on 6:off ser3 0:off 1:off 2:off 3:on 4:on 5:on 6:off service4 0:off 1:off 2:on 3:on 4:on 5:on 6:off longservice5 0:off 1:off 2:off 3:on 4:on 5:on 6:off service6 0:off 1:on 2:on 3:on 4:on 5:on 6:off """).strip().split("\n") command.return_value = chkconfigmock self.assertTrue(is_sysv_service("service1")) chkconfigmock.assert_called_once_with() self.assertFalse(is_sysv_service("noservice"))
def get_init_scripts_and_type(cls, service_name): sysv_init_script = '/etc/init.d/%s' % service_name upstart_scripts_temlpates = ['/etc/init/{0}.conf', '/etc/init/{0}.override'] yb = yum.YumBase() yb.doConfigSetup(init_plugins=False) os_release = float(get_yum_releasever(yb)) init_scripts = tuple() if is_sysv_service(service_name): init_type = "sysv" init_scripts = (sysv_init_script,) elif os_release >= 6 and os_release < 7: upstart_scripts = get_files_by_template(service_name, upstart_scripts_temlpates) if upstart_scripts: init_type = "upstart" init_scripts = upstart_scripts elif could_be_sysv_service(service_name): init_type = "sysv" init_scripts = (sysv_init_script,) else: init_type = "serverside" elif os_release >= 7: systemd_scripts = get_systemd_init_scripts(service_name) if systemd_scripts: init_type = "systemd" init_scripts = systemd_scripts elif could_be_sysv_service(service_name): init_type = "sysv" init_scripts = (sysv_init_script,) else: init_type = "serverside" return init_scripts, init_type