def test_get_files_by_template_should_return_empty_list(self):
     service = "testservice"
     expected_list = []
     result_list = get_files_by_template(service, ["non_existing_file", "non_existing_file"])
     self.assertItemsEqual(expected_list, result_list)
     result_list = get_files_by_template(service, ["non_existing_file"])
     self.assertItemsEqual(expected_list, result_list)
     result_list = get_files_by_template(service, [])
     self.assertItemsEqual(expected_list, result_list)
Example #2
0
    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
    def test_get_files_by_template_should_return_files_list(self):
        service = "testservice"
        tempfile1 = NamedTemporaryFile()
        tempfile2 = NamedTemporaryFile()
        expected_list = [tempfile1.name, tempfile2.name]

        result_list = get_files_by_template(service, expected_list)
        self.assertItemsEqual(expected_list, result_list)
 def test_get_files_by_template_should_return_only_existing_files(self):
     service = "testservice"
     tempfile = NamedTemporaryFile()
     expected_list = [tempfile.name]
     result_list = get_files_by_template(service, [tempfile.name, "non_existing_file"])
     self.assertListEqual(expected_list, result_list)