Beispiel #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")
Beispiel #2
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()
Beispiel #3
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")
Beispiel #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")
Beispiel #5
0
 def test_should_accept_other_settings_container(self):
     """A server instance settings should accept other settings container."""
     si = ServerInstanceSettings("testing",
                                 bat_settings=self.sb,
                                 config_settings=self.sc)
     assert si.bat_settings == self.sb
     assert si.config_settings == self.sc
    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)
Beispiel #7
0
 def test_should_ignore_the_preset_without_proper_setting(self, mocker, sc_stub, sb_stub):
     """Preset importing should ignore the preset without proper setting."""
     manager = ServerManager("")
     mocker.patch(
         "odk_servermanager.manager.ServerManager._parse_config", side_effect=None)
     parse_preset_fun = mocker.patch(
         "odk_servermanager.manager.ServerManager._parse_mods_preset", side_effect=None)
     manager.settings = ServerInstanceSettings(
         "test", bat_settings=sb_stub, config_settings=sc_stub)
     manager._recover_settings()
     parse_preset_fun.assert_not_called()
Beispiel #8
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)
Beispiel #9
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)
 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")
Beispiel #11
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")
Beispiel #12
0
 def test_should_have_decent_defaults(self):
     """A server instance settings should have decent defaults."""
     server_instance_name = "training"
     si = ServerInstanceSettings(server_instance_name=server_instance_name,
                                 bat_settings=self.sb,
                                 config_settings=self.sc)
     assert si.arma_folder == r"C:\Program Files (x86)\Steam\steamapps\common\Arma 3"
     assert si.mods_to_be_copied == []
     assert si.linked_mod_folder_name == "!Mods_linked"
     assert si.copied_mod_folder_name == "!Mods_copied"
     assert si.server_instance_prefix == "__server__"
     assert si.server_instance_root == si.arma_folder
     assert si.user_mods_list == []
     assert si.server_mods_list == []
     assert si.skip_keys == ["!DO_NOT_CHANGE_FILES_IN_THESE_FOLDERS"]
     assert isinstance(si.fix_settings, ModFixSettings)
     assert si.fix_settings.enabled_fixes == []
     assert si.fix_settings.mod_fix_settings == {}
Beispiel #13
0
 def test_should_set_its_fields(self):
     """A server instance settings should set its fields."""
     server_instance_name = "training"
     arma_folder = r"c:\new path"
     mods_to_be_copied = ["CBA_A3"]
     linked_mod_folder_name = "!M_linked",
     copied_mod_folder_name = "!M_copied",
     server_instance_prefix = "__instance__"
     server_instance_root = r"c:\instance-path"
     server_mods_list = ["ODKMIN"]
     user_mods_list = ["ace", "CBA_A3"]
     skip_keys = ["CBA_A3"]
     si = ServerInstanceSettings(
         server_instance_name=server_instance_name,
         bat_settings=self.sb,
         config_settings=self.sc,
         arma_folder=arma_folder,
         fix_settings=self.mf,
         mods_to_be_copied=mods_to_be_copied,
         linked_mod_folder_name=linked_mod_folder_name,
         copied_mod_folder_name=copied_mod_folder_name,
         server_instance_prefix=server_instance_prefix,
         server_instance_root=server_instance_root,
         user_mods_list=user_mods_list,
         server_mods_list=server_mods_list,
         skip_keys=skip_keys)
     assert si.server_instance_name == server_instance_name
     assert si.arma_folder == arma_folder
     assert si.mods_to_be_copied == mods_to_be_copied
     assert si.linked_mod_folder_name == linked_mod_folder_name
     assert si.copied_mod_folder_name == copied_mod_folder_name
     assert si.server_instance_prefix == server_instance_prefix
     assert si.server_instance_root == server_instance_root
     assert si.user_mods_list == user_mods_list
     assert si.server_mods_list == server_mods_list
     assert si.skip_keys == skip_keys + [
         "!DO_NOT_CHANGE_FILES_IN_THESE_FOLDERS"
     ]
     assert si.server_drive == "c:"  # this is computed
     assert si.fix_settings == self.mf
Beispiel #14
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)
Beispiel #15
0
 def _parse_config(self) -> None:
     """Parse the config file and create all settings container object."""
     # Recover data in the file
     data = ConfigIni.read_file(self.config_file)
     # Create settings containers
     config_settings = ServerConfigSettings(**data["config"])
     bat_settings = ServerBatSettings(**data["bat"])
     enabled_fixes = []
     if "enabled_fixes" in data["mod_fix_settings"]:
         enabled_fixes = data["mod_fix_settings"].pop("enabled_fixes")
     fix_settings = ModFixSettings(
         enabled_fixes=enabled_fixes,
         mod_fix_settings=data["mod_fix_settings"])
     # create the global settings container
     self.settings = ServerInstanceSettings(**data["ODKSM"],
                                            bat_settings=bat_settings,
                                            config_settings=config_settings,
                                            fix_settings=fix_settings)
     # add missing mod_fix mods to mods_to_be_copied
     from odk_servermanager.modfix import register_fixes
     mod_fixes = register_fixes(fix_settings.enabled_fixes)
     for fix in mod_fixes:
         # Check that it's a required mod:
         if fix.name in self.settings.user_mods_list + self.settings.server_mods_list:
             copy_hooks = [
                 "hook_init_copy_pre", "hook_init_copy_replace",
                 "hook_init_copy_post", "hook_update_copy_pre",
                 "hook_update_copy_replace", "hook_update_copy_post"
             ]
             for copy_hook in copy_hooks:
                 # Check if there's a copy hook enabled...
                 if getattr(
                         fix, copy_hook
                 ) is not None and fix.name not in self.settings.mods_to_be_copied:
                     # ... if so, add the mod to mods_to_be_copied
                     self.settings.mods_to_be_copied.append(fix.name)
Beispiel #16
0
 def test_should_save_its_config(self, sc_stub, sb_stub):
     """A server instance should save its config."""
     settings = ServerInstanceSettings("server0", sb_stub, sc_stub)
     instance = ServerInstance(settings)
     assert instance.S == settings