Ejemplo n.º 1
0
 def setup(self, request, class_reset_folder_structure, c_sc_stub):
     """TestCompileBat setup"""
     request.cls.test_path = test_folder_structure_path()
     server_instance_name = "training"
     sb = ServerBatSettings(
         server_title="ODK Training Server",
         server_port="2202",
         server_config_file_name="serverTraining.cfg",
         server_cfg_file_name="Arma3Training.cfg",
         server_max_mem="8192",
         server_flags="-filePatching -autoinit -enableHT")
     sc = c_sc_stub
     request.cls.settings = ServerInstanceSettings(
         server_instance_name=server_instance_name,
         bat_settings=sb,
         config_settings=sc,
         arma_folder=self.test_path,
         server_instance_root=self.test_path,
         mods_to_be_copied=["CBA_A3"],
         user_mods_list=["ace", "CBA_A3", "ODKAI"],
         server_mods_list=["AdvProp", "ODKMIN"],
     )
     request.cls.instance = ServerInstance(self.settings)
     self.instance._new_server_folder()
     self.instance._compile_bat_file()
     request.cls.compiled_bat = join(
         self.instance.get_server_instance_path(), "run_server.bat")
Ejemplo n.º 2
0
    def setup(self, request, c_sc_stub, c_sb_stub,
              class_reset_folder_structure):
        """TestAModFixOdkailocal setup"""
        # prepare the local folder
        request.cls.test_path = test_folder_structure_path()
        local_folder = join(self.test_path, "local_odkai")
        mkdir(local_folder)
        touch(join(local_folder, "local_mod"), "this is a local mod")

        fix_settings = ModFixSettings(
            enabled_fixes=["odkai_local"],
            mod_fix_settings={"odkai_local_path": local_folder})
        settings = ServerInstanceSettings("test",
                                          c_sb_stub,
                                          c_sc_stub,
                                          user_mods_list=["ODKAI"],
                                          arma_folder=self.test_path,
                                          server_instance_root=self.test_path,
                                          fix_settings=fix_settings)
        request.cls.instance = ServerInstance(settings)
        self.instance._new_server_folder()
        self.instance._prepare_server_core()
        self.instance._start_op_on_mods("init", ["ODKAI"])
        request.cls.mod_folder = join(self.instance.get_server_instance_path(),
                                      self.instance.S.linked_mod_folder_name,
                                      "@ODKAI")
Ejemplo n.º 3
0
 def test_should_stop_with_non_existing_mod(self, reset_folder_structure, mocker):
     """A server manager at init should stop with non existing mod."""
     rmtree(join(test_folder_structure_path(), "!Workshop", "@CBA_A3"))
     # this skips the user input check
     mocker.patch("builtins.input", return_value="y")
     self._assert_aborting(self.sm.manage_instance, {
                           "config_file": self.config_file})
Ejemplo n.º 4
0
 def setup(self, request, class_reset_folder_structure, c_sc_stub,
           c_sb_stub):
     """TestModFixCba setup"""
     request.cls.test_path = test_folder_structure_path()
     request.cls.custom_cba = join(self.test_path, "cba_settings.sqf")
     touch(self.custom_cba, "test")
     fix_settings = ModFixSettings(
         enabled_fixes=["cba_a3"],
         mod_fix_settings={"cba_settings": self.custom_cba})
     settings = ServerInstanceSettings("test",
                                       c_sb_stub,
                                       c_sc_stub,
                                       user_mods_list=["CBA_A3"],
                                       arma_folder=self.test_path,
                                       server_instance_root=self.test_path,
                                       fix_settings=fix_settings)
     request.cls.instance = ServerInstance(settings)
     self.instance._new_server_folder()
     self.instance._prepare_server_core()
     request.cls.mod_folder = join(self.instance.get_server_instance_path(),
                                   self.instance.S.linked_mod_folder_name,
                                   "@CBA_A3")
     request.cls.cba_settings = join(
         self.instance.get_server_instance_path(), "userconfig",
         "cba_settings.sqf")
Ejemplo n.º 5
0
 def setup(self, request):
     """TestCompileFromTemplate setup"""
     template_file = abspath(join(test_resources, "template.txt"))
     with open(template_file, "r") as f:
         request.cls.template_file_content = f.read()
     request.cls.compiled_file = join(test_folder_structure_path(),
                                      "compiled.ini")
Ejemplo n.º 6
0
 def setup(self, request, class_reset_folder_structure, c_sc_stub):
     """TestServerInstanceInit setup"""
     server_name = "TestServer1"
     request.cls.test_path = test_folder_structure_path()
     sb = ServerBatSettings(
         server_title="ODK Training Server",
         server_port="2202",
         server_config_file_name="serverTraining.cfg",
         server_cfg_file_name="Arma3Training.cfg",
         server_max_mem="8192",
         server_flags="-filePatching -autoinit -enableHT")
     sc = c_sc_stub
     request.cls.settings = ServerInstanceSettings(
         server_instance_name=server_name,
         bat_settings=sb,
         config_settings=sc,
         arma_folder=self.test_path,
         server_instance_root=self.test_path,
         mods_to_be_copied=["CBA_A3"],
         user_mods_list=["ace", "CBA_A3", "ODKAI"],
         server_mods_list=["AdvProp", "ODKMIN"],
     )
     request.cls.instance = ServerInstance(self.settings)
     request.cls.instance_folder = self.instance.get_server_instance_path()
     # set up all needed spies
     with spy(self.instance._new_server_folder) as request.cls.new_server_fun, \
             spy(self.instance._check_mods) as request.cls.check_mods_fun, \
             spy(self.instance._prepare_server_core) as request.cls.prepare_server_fun, \
             spy(self.instance._start_op_on_mods) as request.cls.init_mods_fun, \
             spy(self.instance._link_keys) as request.cls.init_keys_fun, \
             spy(self.instance._compile_bat_file) as request.cls.compiled_bat_fun, \
             spy(self.instance._compile_config_file) as request.cls.compiled_config_fun:
         self.instance.init()
Ejemplo n.º 7
0
    def setup(self, request, reset_folder_structure, sc_stub, sb_stub, mocker):
        """TestACopyModFix setup"""
        class LinkModFix(ModFix):

            name = "ace"

            def hook_init_link_pre(self, server_instance, call_data) -> None:
                pass

        class CopyModFix(ModFix):

            name = "cba_a3"

            def hook_init_copy_pre(self, server_instance, call_data) -> None:
                pass

        request.cls.test_path = test_folder_structure_path()
        settings = ServerInstanceSettings(
            "test",
            sb_stub,
            sc_stub,
            user_mods_list=["cba_a3", "ace"],
            fix_settings=ModFixSettings(enabled_fixes=["cba_a3", "ace"]),
            arma_folder=self.test_path,
            server_instance_root=self.test_path)
        mocker.patch("odk_servermanager.modfix.register_fixes",
                     return_value=[CopyModFix(), LinkModFix()])
        request.cls.instance = ServerInstance(settings)
Ejemplo n.º 8
0
 def test_should_create_a_symlink(self, reset_folder_structure):
     """Symlink function should create a symlink."""
     test_path = test_folder_structure_path()
     src = join(test_path, "TestFolder1")
     dest = join(test_path, "__server__TestServer0", "TestFolder1")
     symlink(src, dest)
     assert islink(dest)
     assert isfile(join(dest, "testFile1.txt"))
Ejemplo n.º 9
0
 def setup(self, request, reset_folder_structure):
     """TestSymlinkEverythingFromDir setup"""
     request.cls.test_path = test_folder_structure_path()
     request.cls.target = join(self.test_path, "folderT")
     request.cls.origin = join(self.test_path, "folderA")
     mkdir(self.target)
     mkdir(self.origin)
     mkdir(join(self.origin, "folderB"))
     touch(join(self.origin, "folderB", "testA"))
     mkdir(join(self.origin, "folderC"))
     touch(join(self.origin, "folderC", "testB"))
     touch(join(self.origin, "testC"))
Ejemplo n.º 10
0
 def test_should_work_on_old_win(self, reset_folder_structure, mocker,
                                 monkeypatch):
     """Symlink function should work on old win."""
     mocker.patch("os.symlink", "")  # disable modern symlink
     test_path = test_folder_structure_path()
     src = join(test_path, "TestFolder1")
     dest = join(test_path, "__server__TestServer0", "TestFolder1")
     symlink(src, dest)
     assert islink(dest)
     assert isfile(join(dest, "testFile1.txt"))
     with pytest.raises(OSError):
         symlink(src, dest)  # check that errors correctly
Ejemplo n.º 11
0
 def setup(self, request, class_reset_folder_structure, c_sc_stub,
           c_sb_stub):
     """TestAnInstanceWithANonExistingMod setup"""
     server_name = "TestServer1"
     request.cls.test_path = test_folder_structure_path()
     request.cls.settings = ServerInstanceSettings(
         server_name,
         c_sb_stub,
         c_sc_stub,
         user_mods_list=["NOT_THERE"],
         arma_folder=self.test_path,
         server_instance_root=self.test_path,
     )
     request.cls.instance = ServerInstance(self.settings)
Ejemplo n.º 12
0
 def setup(self, request, sc_stub, sb_stub):
     """TestOurTestServerInstance setup"""
     server_name = "TestServer0"
     mods_to_be_copied = ["CBA_A3"]
     request.cls.test_path = test_folder_structure_path()
     request.cls.sb = sb_stub
     request.cls.sc = sc_stub
     request.cls.settings = ServerInstanceSettings(
         server_name,
         self.sb,
         self.sc,
         mods_to_be_copied=mods_to_be_copied,
         arma_folder=self.test_path,
         server_instance_root=self.test_path)
     request.cls.instance = ServerInstance(self.settings)
Ejemplo n.º 13
0
 def setup(self, request, reset_folder_structure, sc_stub, sb_stub):
     """TestAServerInstance setup"""
     request.cls.test_path = test_folder_structure_path()
     request.cls.enabled_fixes = ["cba_a3"]
     settings = ServerInstanceSettings(
         "test",
         sb_stub,
         sc_stub,
         user_mods_list=["ace"],
         fix_settings=ModFixSettings(enabled_fixes=self.enabled_fixes),
         arma_folder=self.test_path,
         server_instance_root=self.test_path)
     request.cls.instance = ServerInstance(settings)
     self.instance._new_server_folder()
     self.instance._prepare_server_core()
     self.instance._copy_mod("CBA_A3")
Ejemplo n.º 14
0
 def setup(self, request, c_sc_stub, c_sb_stub, class_reset_folder_structure):
     """TestAModfixGos setup"""
     request.cls.test_path = test_folder_structure_path()
     fix_settings = ModFixSettings(enabled_fixes=["gos"])
     settings = ServerInstanceSettings("test", c_sb_stub, c_sc_stub,
                                       user_mods_list=["G.O.S Dariyah", "G.O.S Al Rayak"],
                                       arma_folder=self.test_path,
                                       server_instance_root=self.test_path,
                                       fix_settings=fix_settings)
     request.cls.instance = ServerInstance(settings)
     self.instance._new_server_folder()
     self.instance._prepare_server_core()
     self.instance._start_op_on_mods("init", ["G.O.S Dariyah"])
     self.instance._start_op_on_mods("init", ["G.O.S Al Rayak"])
     request.cls.moda_folder = join(self.instance.get_server_instance_path(),
                                    self.instance.S.copied_mod_folder_name, "@G.O.S Dariyah")
     request.cls.modb_folder = join(self.instance.get_server_instance_path(),
                                    self.instance.S.copied_mod_folder_name, "@G.O.S Al Rayak")
Ejemplo n.º 15
0
 def test_should_print_the_stacktrace_to_a_file(self, reset_folder_structure, mocker):
     """When debugging should print the stacktrace to a file."""
     import time
     ts = time.gmtime()
     debug_file_folder = test_folder_structure_path()
     debug_file = join(debug_file_folder, "odksm_{}.log".format(
         time.strftime("%Y%m%d_%H%M%S", ts)))
     manager = ServerManager(debug_logs_path=debug_file_folder)
     # first check outside an exception
     manager._print_debug_log()
     assert not isfile(debug_file)
     # now check inside an exception
     try:
         raise Exception("custom_test_exception")
     except Exception:
         mocker.patch("time.gmtime", return_value=ts)
         manager._print_debug_log()
         assert isfile(debug_file)
         with open(debug_file, "r") as log:
             content = log.read()
             assert content.find("custom_test_exception") > 0
Ejemplo n.º 16
0
 def setup(self, request, class_reset_folder_structure, c_sb_stub):
     """TestWhenConfigComposingTheServerInstance setup"""
     request.cls.test_path = test_folder_structure_path()
     server_instance_name = "TestServer0"
     sc = ServerConfigSettings(hostname="TRAINING SERVER",
                               password="******",
                               password_admin="abc",
                               mission_template="mission.name")
     request.cls.settings = ServerInstanceSettings(
         server_instance_name=server_instance_name,
         bat_settings=c_sb_stub,
         config_settings=sc,
         arma_folder=self.test_path,
         server_instance_root=self.test_path,
         mods_to_be_copied=["CBA_A3"],
         user_mods_list=["ace", "CBA_A3", "ODKAI"],
         server_mods_list=["AdvProp", "ODKMIN"],
     )
     request.cls.instance = ServerInstance(self.settings)
     self.instance._compile_config_file()
     request.cls.compiled_config = join(
         self.instance.get_server_instance_path(),
         self.instance.S.bat_settings.server_config_file_name)
Ejemplo n.º 17
0
 def setup(self, request, class_reset_folder_structure):
     """TestAConfigIni setup"""
     request.cls.test_path = test_folder_structure_path()
Ejemplo n.º 18
0
 def setup(self, request, class_reset_folder_structure):
     """TestWhenBootstrapping setup"""
     request.cls.sm = ServerManager()
     request.cls.default_file = join(test_resources, "bootstrap.ini")
     request.cls.test_path = test_folder_structure_path()
Ejemplo n.º 19
0
 def test_should_check_the_config_file(self, reset_folder_structure):
     """A server manager at init should check the config file."""
     sm = ServerManager(join(test_folder_structure_path(), "template.txt"))
     self._assert_aborting(sm.manage_instance, {
                           "config_file": self.config_file})