diff --git a/calculate/templates/template_engine.py b/calculate/templates/template_engine.py index abc4bf2..033b950 100644 --- a/calculate/templates/template_engine.py +++ b/calculate/templates/template_engine.py @@ -160,6 +160,8 @@ class ParametersProcessor: 'append': self.check_append_parameter, 'rebuild': self.check_rebuild_parameter, 'restart': self.check_restart_parameter, + 'run': self.check_run_parameter, + 'exec': self.check_exec_parameter, 'stop': self.check_stop_parameter, 'start': self.check_start_parameter, 'chown': self.check_chown_parameter, @@ -366,7 +368,7 @@ class ParametersProcessor: def check_run_parameter(self, parameter_value): if self.template_type == DIR: raise IncorrectParameter("'run' parameter is not available in" - " directory templates.") + " directory templates") if not parameter_value and isinstance(parameter_value, bool): raise IncorrectParameter("'run' parameter value is empty") try: @@ -379,7 +381,7 @@ class ParametersProcessor: def check_exec_parameter(self, parameter_value): if self.template_type == DIR: raise IncorrectParameter("'exec' parameter is not available in" - " directory templates.") + " directory templates") if not parameter_value and isinstance(parameter_value, bool): raise IncorrectParameter("'exec' parameter value is empty") try: diff --git a/tests/templates/test_directory_processor.py b/tests/templates/test_directory_processor.py index 5e269ce..0f12d75 100644 --- a/tests/templates/test_directory_processor.py +++ b/tests/templates/test_directory_processor.py @@ -1008,20 +1008,17 @@ class TestDirectoryProcessor: assert directory_processor.template_executor.\ changed_files == {} - # def test_if_templates_contain_a_directory_with_a_calculate_directory_file_with_the_run_parameter_and_a_correct_script___the_directory_processor_runs_the_script_using_the_interpreter_from_the_run_parameter(self): - # datavars.main['cl_template_path'] = os.path.join(CHROOT_PATH, - # 'templates_30') - # directory_processor = DirectoryProcessor('install', - # datavars_module=datavars) - # directory_processor.process_template_directories() - - # # Скрипт создает файл. - # assert os.path.exists(join_paths(CHROOT_PATH, 'etc/file_14')) - - # # Из скрипта не получить список файлов измененных или созданных - # # шаблоном. - # assert directory_processor.template_executor.\ - # changed_files == {} + def test_if_templates_contain_a_directory_with_a_calculate_directory_file_with_the_run_parameter_and_a_correct_script___the_directory_processor_runs_the_script_using_the_interpreter_from_the_run_parameter(self): + datavars.main['cl_template_path'] = os.path.join(CHROOT_PATH, + 'templates_30') + directory_processor = DirectoryProcessor('install', + datavars_module=datavars) + directory_processor.process_template_directories() + + # Скрипт создает файл. + assert not os.path.exists(join_paths(CHROOT_PATH, 'etc/file_14')) + assert directory_processor.template_executor.\ + changed_files == {} def test_if_templates_contain_some_files_with_the_exec_parameter_and_a_correct_scripts___the_directory_processor_saves_all_the_scripts_in_the_special_execute_directory_and_runs_all_the_files_after_all_templates_are_joined_and_packages_from_the_merge_parameter_is_processed(self): datavars.main['cl_template_path'] = os.path.join(CHROOT_PATH, diff --git a/tests/templates/testfiles/test_dir_processor_root/templates_30/root/.calculate_directory b/tests/templates/testfiles/test_dir_processor_root/templates_30/root/.calculate_directory new file mode 100644 index 0000000..7ae6970 --- /dev/null +++ b/tests/templates/testfiles/test_dir_processor_root/templates_30/root/.calculate_directory @@ -0,0 +1 @@ +{% calculate append = 'skip', action = 'install' %} diff --git a/tests/templates/testfiles/test_dir_processor_root/templates_30/root/dir/.calculate_directory b/tests/templates/testfiles/test_dir_processor_root/templates_30/root/dir/.calculate_directory new file mode 100644 index 0000000..1df5940 --- /dev/null +++ b/tests/templates/testfiles/test_dir_processor_root/templates_30/root/dir/.calculate_directory @@ -0,0 +1,3 @@ +{% calculate append = 'skip', run = '/usr/bin/python' %} +with open('./file_14', 'w') as output: + output.write("Where is my mind")