Tested the template executor for given append join parameter and an unprotected target path. Tested an append parameter implementation for the values: after, before, replace, remove and clear.

packages
Иванов Денис 4 years ago
parent 8344028930
commit 63a10e760e

@ -10,15 +10,6 @@
"tests/templates/format/test_base.py::TestLogicLinesMethod::test_if_input_is_text_document_the_method_returns_list_of_its_lines": true,
"tests/templates/format/test_base.py::TestLogicLinesMethod::test_if_lines_in_document_divided_using_backslash_as_continuation_symbol__method_returns_list_of_full_lines": true,
"tests/templates/format/test_bind.py::TestParsingMethods::test_if_comment_parameter_is_set_for_template__format_object_will_parse_comments_with_comment_symbol_from_this_parameter": true,
"tests/templates/format/test_bind.py::TestParsingMethods::test_if_input_document_contains_blocks_and_parameters_with_action_marks__the_key_tuples_of_object_s_dictionary_have_it_as_its_first_element": true,
"tests/templates/format/test_bind.py::TestParsingMethods::test_if_input_document_contains_just_few_parameter_lines__the_initialised_object_contains_correct_dictionary": true,
"tests/templates/format/test_bind.py::TestParsingMethods::test_if_input_document_contains_parameters_to_delete_without_values_or_with_empty_block__the_document_object_contains_dictionary_with_item_to_delete": true,
"tests/templates/format/test_bind.py::TestParsingMethods::test_if_input_document_contains_some_block_of_parameters__the_initialised_object_contains_correct_dictionary": true,
"tests/templates/format/test_bind.py::TestParsingMethods::test_if_input_document_contains_some_blocks_with_similar_names__the_blocks_join_recursively": true,
"tests/templates/format/test_bind.py::TestParsingMethods::test_if_parameters_and_blocks_in_input_document_has_some_comments__the_comments_will_be_collected_in_the_list_of_parameter_value_or_with_special_key_in_block_dictionary": true,
"tests/templates/format/test_bind.py::TestParsingMethods::test_if_the_IgnoreComments_flag_is_set__the_parser_ignores_all_comments": true,
"tests/templates/format/test_bind.py::TestParsingMethods::test_joining_documents_1": true,
"tests/templates/format/test_bind.py::TestParsingMethods::test_make_template": true,
"tests/templates/format/test_compiz.py::TestParsingMethods::test_if_input_document_contains_few_parameter_lines_and_some_empty_lines__the_initialized_object_contains_correct_dictionary": true,
"tests/templates/format/test_compiz.py::TestParsingMethods::test_if_input_document_contains_just_few_parameter_lines__the_initialised_object_contains_correct_dictionary": true,
"tests/templates/format/test_compiz.py::TestParsingMethods::test_if_input_document_contains_parameters_to_delete_without_assign_symbol_and_any_values_and_sections_to_delete__the_document_object_contains_dictionary_with_item_to_delete": true,
@ -162,6 +153,7 @@
"tests/templates/test_template_executor.py::TestTemplateExecutor::test_for_the_testfiles_backup": true,
"tests/templates/test_template_executor.py::TestTemplateExecutor::test_if_append_clear_directory_method_s_input_is_a_template_with_a_target_path_to_an_unexisting_directory_that_does_not_belong_to_the_template_package__the_method_just_removes_the_directory_and_all_its_files_from_a_package_CONTENTS_file": true,
"tests/templates/test_template_executor.py::TestTemplateExecutor::test_if_append_join_directory_method_s_input_is_a_template_with_a_target_path_to_an_existing_directory_belongs_to_the_template_package__the_method_throws_TemplateCollisionError_error": true,
"tests/templates/test_template_executor.py::TestTemplateExecutor::test_if_append_join_file_method_s_input_is_a_template_with_an_protected_target_path_to_an_existing_file_that_belongs_to_the_template_package_and_the_unbound_parameter_is_set_but_its_hash_sum_does_not_match_the_hash_from_a_CONTENTS_file__the_method_joins_template__removes_a_target_file_path_from_a_package_CONTENTS_file_and_the_config_file": true,
"tests/templates/test_template_executor.py::TestTemplateExecutor::test_if_append_join_file_method_s_input_is_a_template_with_protected_target_path_to_an_existing_file_that_belongs_to_the_template_package_but_its_hash_sum_does_not_match_the_hash_from_a_CONTENTS_file_and_the_chown_and_chmod_parameters_is_set__the_method_creates_a_cfg_file_and_adds_a_target_file_s_path_to_the_config_file": true,
"tests/templates/test_template_executor.py::TestTemplateExecutor::test_if_append_replace_directory_method_s_input_is_a_template_with_a_target_path_to_an_unexisting_directory_and_the_chown_and_the_chmod_parameters_are_set__the_method_creates_new_directory_and_add_it_to_a_package_CONTENTS_file": true,
"tests/templates/test_template_executor.py::TestTemplateExecutor::test_if_the_link_directory_method_s_input_is_a_path_to_an_existing_source_file_and_a_target_path__the_method_creates_a_link_to_a_source_file": true,

@ -116,7 +116,6 @@
"tests/templates/test_template_executor.py::TestTemplateExecutor::test_if_append_join_file_method_s_input_is_a_template_with_protected_target_path_to_an_unexisting_file_that_should_exist_and_autoupdate_parameters_is_set__the_method_creates_new_empty_file_joins_a_template_with_them_and_adds_it_to_config_file",
"tests/templates/test_template_executor.py::TestTemplateExecutor::test_if_append_join_file_method_s_input_is_a_template_with_protected_target_path_to_an_unexisting_file_that_should_not_exist_and_chown_and_chmod_parameters_are_set__the_method_creates_new_empty_file__joins_a_template_with_them__adds_file_to_the_package_CONTENTS_file__create_an_archive_version_of_a_file_and_chown_and_chmod_it",
"tests/templates/test_template_executor.py::TestTemplateExecutor::test_if_append_join_file_method_s_input_is_a_template_with_protected_target_path_to_an_unexisting_file_that_should_exist_and_chown_and_chmod_parameters_are_set__the_method_creates_new_empty_cfg_file__joins_a_template_with_them__adds_it_to_config_file_and_chown_and_chmod_it",
"tests/templates/test_template_executor.py::TestTemplateExecutor::test_add_to_contents",
"tests/templates/test_template_executor.py::TestTemplateExecutor::test_if_append_join_file_method_s_input_is_a_template_with_protected_target_path_to_an_existing_file_that_belongs_to_the_template_package_and_its_hash_sum_matches_the_hash_from_a_CONTENTS_file__the_method_joins_an_input_file_with_a_template__changes_its_hash_in_the_CONTENTS__updates_config_archive",
"tests/templates/test_template_executor.py::TestTemplateExecutor::test_if_append_join_file_method_s_input_is_a_template_with_protected_target_path_to_an_existing_file_that_belongs_to_the_template_package_its_hash_sum_matches_the_hash_from_a_CONTENTS_file_and_a_chown_and_chmod_parameters_are_set__the_method_joins_an_input_file_with_a_template__changes_its_hash_in_the_CONTENTS__updates_config_archive_and_chown_and_chmod_it",
"tests/templates/test_template_executor.py::TestTemplateExecutor::test_if_append_join_file_method_s_input_is_a_template_with_protected_target_path_to_an_existing_file_that_belongs_to_the_template_package_but_its_hash_sum_does_not_match_the_hash_from_a_CONTENTS_file__the_method_creates_a_cfg_file_and_adds_a_target_file_s_path_to_the_config_file",
@ -125,10 +124,21 @@
"tests/templates/test_template_executor.py::TestTemplateExecutor::test_if_append_join_file_method_s_input_is_a_template_with_protected_target_path_to_an_existing_file_that_belongs_to_the_template_package_but_its_hash_sum_does_not_match_the_hash_from_a_CONTENTS_file_and_there_is_some_cfg_files_and_the_autoupdate_parameter_is_set__the_method_joins_a_target_file_and_a_template__removes_a_path_to_file_from_the_config_file__removes_all_cfg_files_and_updates_a_package_CONTENTS_file",
"tests/templates/test_template_executor.py::TestTemplateExecutor::test_if_append_join_file_method_s_input_is_a_template_with_protected_target_path_to_an_existing_file_that_belongs_to_the_template_package_but_its_hash_sum_does_not_match_the_hash_from_a_CONTENTS_file_and_there_is_two_cfg_files__the_method_creates_third_cfg_file_and_updates_config_file",
"tests/templates/test_template_executor.py::TestTemplateExecutor::test_if_append_join_file_method_s_input_is_a_template_with_protected_target_path_to_an_existing_file_that_belongs_to_the_template_package_but_its_hash_sum_does_not_match_the_hash_from_a_CONTENTS_file_and_there_is_two_cfg_files_and_changes_from_a_template_is_similar_to_the_last_one__the_method_does_nothing",
"tests/templates/test_template_executor.py::TestTemplateExecutor::test_unprotected_for_file_without_changes",
"tests/templates/test_template_executor.py::TestTemplateExecutor::test_unprotected_for_file_with_changes",
"tests/templates/test_template_executor.py::TestTemplateExecutor::test_unbound_for_file_without_changes",
"tests/templates/test_template_executor.py::TestTemplateExecutor::test_unbound_for_file_with_changes",
"tests/templates/test_template_executor.py::TestTemplateExecutor::test_if_append_join_file_method_s_input_is_a_template_with_an_unprotected_target_path_to_an_existing_file_that_belongs_to_the_template_package__the_method_just_joins_a_template_to_a_target_file_without_updating_a_CONTENTS_file_and_creating_an_archive_file",
"tests/templates/test_template_executor.py::TestTemplateExecutor::test_if_append_join_file_method_s_input_is_a_template_with_an_unprotected_target_path_to_an_existing_file_that_belongs_to_the_template_package_but_its_hash_sum_does_not_match_the_hash_from_a_CONTENTS_file__the_method_just_joins_a_template_to_a_target_file_without_updating_a_package_CONTENTS_and_the_config_files_and_creating_an_archive_file",
"tests/templates/test_template_executor.py::TestTemplateExecutor::test_if_append_join_file_method_s_input_is_a_template_with_an_protected_target_path_to_an_existing_file_that_belongs_to_the_template_package_and_the_unbound_parameter_is_set__the_method_joins_template_and_removes_a_target_file_path_from_a_package_CONTENTS_file",
"tests/templates/test_template_executor.py::TestTemplateExecutor::test_if_append_join_file_method_s_input_is_a_template_with_an_protected_target_path_to_an_existing_file_that_belongs_to_the_template_package_and_the_unbound_parameter_is_set_but_its_hash_sum_does_not_match_the_hash_from_a_CONTENTS_file__the_method_joins_template__removes_a_target_file_path_from_a_package_CONTENTS_file",
"tests/templates/test_template_executor.py::TestTemplateExecutor::test_if_append_join_file_method_s_input_is_a_template_with_an_protected_target_path_to_an_existing_file_that_belongs_to_the_template_package_and_the_unbound_parameter_is_set_but_its_hash_sum_does_not_match_the_hash_from_a_CONTENTS_file_and_there_are_some_cfg_file__the_method_joins_template__removes_a_target_file_path_from_a_package_CONTENTS_file_and_the_config_file",
"tests/templates/test_template_executor.py::TestTemplateExecutor::test_if_the_append_after_file_method_s_input_is_a_not_empty_template__the_template_s_text_and_sections_joins_after_the_text_of_the_target_file",
"tests/templates/test_template_executor.py::TestTemplateExecutor::test_if_the_append_before_file_method_s_input_is_a_not_empty_template__the_template_s_text_and_sections_joins_before_the_text_of_the_target_file",
"tests/templates/test_template_executor.py::TestTemplateExecutor::test_if_the_append_replace_file_method_s_input_is_a_not_empty_template_with_a_target_path_to_an_existing_file__the_method_joins_a_template_with_the_empty_text_and_replaces_the_target_file_with_the_template_join_result",
"tests/templates/test_template_executor.py::TestTemplateExecutor::test_if_the_append_remove_file_method_s_input_is_a_template_with_a_target_path_to_an_existing_file_that_belongs_to_the_template_package__the_method_removes_a_target_file_in_a_filesystem_and_in_a_package_CONTENTS_file",
"tests/templates/test_template_executor.py::TestTemplateExecutor::test_if_the_append_remove_file_method_s_input_is_a_template_with_a_target_path_to_an_unexisting_file_that_belongs_to_the_template_package__the_method_removes_a_target_file_in_a_package_CONTENTS_file",
"tests/templates/test_template_executor.py::TestTemplateExecutor::test_if_the_append_remove_file_method_s_input_is_a_template_with_a_target_path_to_an_existing_file_that_does_not_belong_to_any_package__the_method_removes_a_target_file_in_a_package_CONTENTS_file",
"tests/templates/test_template_executor.py::TestTemplateExecutor::test_add_file_0",
"tests/templates/test_template_executor.py::TestTemplateExecutor::test_if_the_append_clear_file_method_s_input_is_a_template_with_a_target_path_to_an_existing_empty_file_that_belongs_to_the_template_package__the_method_just_updates_a_package_CONTENTS_file",
"tests/templates/test_template_executor.py::TestTemplateExecutor::test_if_the_append_clear_file_method_s_input_is_a_template_with_a_target_path_to_an_existing_not_empty_file_that_belongs_to_the_template_package__the_method_clears_a_target_file_and_updates_a_package_CONTENTS_file",
"tests/templates/test_template_executor.py::TestTemplateExecutor::test_if_the_append_clear_file_method_s_input_is_a_template_with_a_target_path_to_an_existing_not_empty_file_that_belongs_to_the_template_package_and_the_chown_and_chmod_parameters_are_set__the_method_clears_a_target_file_and_updates_a_package_CONTENTS_file",
"tests/templates/test_template_executor.py::TestTemplateExecutor::test_to_remove_changed_testfiles",
"tests/templates/test_template_wrapper.py::TestTemplateWrapper::test_if_the_TemplateWrapper_object_has_already_been_created__it_contains_the_correct_list_of_protected_and_unprotected_paths",
"tests/templates/test_template_wrapper.py::TestTemplateWrapper::test_if_template_type_is_FILE_and_target_file_does_not_exist__the_TemplateWrapper_target_type_is_None",
@ -216,6 +226,7 @@
"tests/templates/format/test_bind.py::TestParsingMethods::test_if_input_document_contains_blocks_and_parameters_with_action_marks__the_key_tuples_of_object_s_dictionary_have_it_as_its_first_element",
"tests/templates/format/test_bind.py::TestParsingMethods::test_if_parameters_and_blocks_in_input_document_has_some_comments__the_comments_will_be_collected_in_the_list_of_parameter_value_or_with_special_key_in_block_dictionary",
"tests/templates/format/test_bind.py::TestParsingMethods::test_if_the_IgnoreComments_flag_is_set__the_parser_ignores_all_comments",
"tests/templates/format/test_bind.py::TestParsingMethods::test_join_before",
"tests/templates/format/test_bind.py::TestParsingMethods::test_if_input_document_contains_parameters_to_delete_without_values_or_with_empty_block__the_document_object_contains_dictionary_with_item_to_delete",
"tests/templates/format/test_bind.py::TestParsingMethods::test_joining_documents_1",
"tests/templates/format/test_bind.py::TestParsingMethods::test_make_template",

@ -194,7 +194,7 @@ class TemplateWrapper:
# не нужно.
return
if self.parameters.append in {'join', 'before', 'after'}:
if self.parameters.append in {'join', 'before', 'after', 'replace'}:
# Получаем класс соответствующего формата файла.
if self.parameters.format:
self.format_class = ParametersProcessor.\
@ -430,7 +430,7 @@ class TemplateWrapper:
# Приоритет отдаем пути из параметра source.
if self.parameters.source:
self.input_path = self.parameters.source
elif self.cfg_list:
elif self.cfg_list and not self.parameters.unbound:
self.input_path = self.archive_path
else:
self.input_path = self.target_path
@ -780,8 +780,7 @@ class TemplateExecutor:
else:
chown = self.file_default_parameters.get('chown', False)
if template_object.format_class.EXECUTABLE or\
template_object.md5_matching:
if template_format.EXECUTABLE or template_object.md5_matching:
# Действия при совпадении md5 из CONTENTS и md5 целевого файла.
# А также если шаблон просто исполнительный.
output_paths = [output_path]
@ -800,7 +799,7 @@ class TemplateExecutor:
input_text = ''
parsed_template = template_format(template_object.template_text,
join_before=join_before)
ignore_comments=True)
if not template_object.format_class.EXECUTABLE:
parsed_input = template_format(input_text,
@ -862,8 +861,10 @@ class TemplateExecutor:
else:
input_text = ''
parsed_input = template_format(input_text)
parsed_template = template_format(template_object.template_text)
parsed_input = template_format(input_text,
join_before=join_before)
parsed_template = template_format(template_object.template_text,
ignore_comments=True)
parsed_input.join_template(parsed_template)
@ -877,11 +878,11 @@ class TemplateExecutor:
if not self.calculate_config_file.compare_md5(
template_object.target_path,
output_text_md5):
print('compare_md5 == False')
if not os.path.exists(os.path.dirname(output_path)):
self._create_directory(
template_object,
path_to_create=os.path.dirname(output_path))
template_object,
path_to_create=os.path.dirname(output_path))
with open(output_path, 'w') as output_file:
output_file.write(output_text)
@ -898,7 +899,6 @@ class TemplateExecutor:
output_text_md5)
else:
# Действия если CL совпало. Пока ничего не делаем.
print('compare_md5 == True')
pass
# Обновляем CONTENTS.
@ -941,11 +941,11 @@ class TemplateExecutor:
self._clear_file(template_object.target_path)
# Меняем владельца и права доступа к очищенному файлу, если нужно.
if template_object.chown:
if template_object.parameters.chown:
self._chown_file(template_object.target_path,
template_object.parameters.chown)
if template_object.chmod:
if template_object.parameters.chmod:
self._chmod_file(template_object.target_path,
template_object.parameters.chmod)

@ -255,6 +255,54 @@ acl "dns_servers" {
bind_object = BINDFormat(document_text, ignore_comments=True)
assert bind_object._document_dictionary == result
def test_join_before(self):
original_text = '''// Comment1
section-name-2 {
parameter-name /home/divanov/Home;
// Comment2
// Comment3
other-parameter yes;
};
section-name-3 {
// Comment
another-parameter 1;
}'''
template_text = '''
section-name-1 {
parameter-name /homeless/poorness;
one-more-parameter no;
};
section-name-3 {
// Comment
unspoken-parameter 1;
};'''
result = OrderedDict({('', 'section-name-1'):
OrderedDict({('', 'parameter-name'):
['/homeless/poorness'],
('', 'one-more-parameter'):
['no']}),
('', 'section-name-2'):
OrderedDict({'#': ['// Comment1'],
('', 'parameter-name'):
['/home/divanov/Home'],
('', 'other-parameter'):
['// Comment2', '// Comment3', 'yes']}),
('', 'section-name-3'):
OrderedDict({('', 'another-parameter'):
['// Comment', '1'],
('', 'unspoken-parameter'):
['1']})})
bind_original_object = BINDFormat(original_text, join_before=True)
bind_template_object = BINDFormat(template_text, ignore_comments=True)
bind_original_object.join_template(bind_template_object)
assert bind_original_object._document_dictionary == result
print('result text:\n{}\n'.format(bind_original_object.document_text))
def test_if_input_document_contains_parameters_to_delete_without_values_or_with_empty_block__the_document_object_contains_dictionary_with_item_to_delete(self):
document_text = '''
!pid-file;

@ -49,6 +49,9 @@ class TestTemplateExecutor:
shutil.copytree(os.path.join(CHROOT_PATH, 'etc.backup'),
os.path.join(CHROOT_PATH, 'etc'),
symlinks=True)
shutil.copytree(os.path.join(CHROOT_PATH, 'unprotected.backup'),
os.path.join(CHROOT_PATH, 'unprotected'),
symlinks=True)
shutil.copytree(os.path.join(
CHROOT_PATH,
'var/lib/calculate/config-archive.backup'),
@ -1272,23 +1275,6 @@ class TestTemplateExecutor:
with open(template_wrapper.output_path, 'r') as output_file:
assert output_file.read() == output_text
def test_add_to_contents(self):
if False:
target_path = join_paths(
CHROOT_PATH,
'/etc/append_join_file_testfiles/file_5')
parameters_object = ParametersContainer(
{'package': test_package_name,
'append': 'join'})
template_wrapper = TemplateWrapper(
target_path,
parameters_object, FILE,
chroot_path=CHROOT_PATH,
config_archive_path=CONFIG_ARCHIVE_PATH)
template_wrapper.add_to_contents()
template_wrapper.save_changes()
assert True
def test_if_append_join_file_method_s_input_is_a_template_with_protected_target_path_to_an_existing_file_that_belongs_to_the_template_package_and_its_hash_sum_matches_the_hash_from_a_CONTENTS_file__the_method_joins_an_input_file_with_a_template__changes_its_hash_in_the_CONTENTS__updates_config_archive(self):
target_path = join_paths(
CHROOT_PATH,
@ -1560,19 +1546,371 @@ class TestTemplateExecutor:
output_file_text = output_file.read()
assert output_file_text == output_text
def test_unprotected_for_file_without_changes(self):
pass
def test_if_append_join_file_method_s_input_is_a_template_with_an_unprotected_target_path_to_an_existing_file_that_belongs_to_the_template_package__the_method_just_joins_a_template_to_a_target_file_without_updating_a_CONTENTS_file_and_creating_an_archive_file(self):
target_path = join_paths(
CHROOT_PATH,
'/unprotected/append_join_file_testfiles/file_0')
def test_unprotected_for_file_with_changes(self):
pass
parameters_object = ParametersContainer({'package': test_package_name,
'append': 'join',
'format': 'bind'})
template_text = 'section-name { parameter-2 no; }'
output_text =\
'section-name {\n parameter-1 yes;\n parameter-2 no;\n};\n'
template_wrapper = TemplateWrapper(
target_path,
parameters_object, FILE,
template_text=template_text,
chroot_path=CHROOT_PATH,
config_archive_path=CONFIG_ARCHIVE_PATH)
template_executor._append_join_file(template_wrapper)
assert not template_wrapper.protected
assert os.path.exists(target_path)
assert not os.path.exists(join_paths(
CONFIG_ARCHIVE_PATH,
'/unprotected/append_join_file_testfiles/file_0'))
assert '/unprotected/append_join_file_testfiles/file_0'\
in template_wrapper.target_package
with open(template_wrapper.output_path, 'r') as output_file:
output_file_text = output_file.read()
assert output_file_text == output_text
assert hashlib.md5(output_file_text.encode()).hexdigest !=\
template_wrapper.target_package.get_md5(target_path)
def test_unbound_for_file_without_changes(self):
pass
def test_if_append_join_file_method_s_input_is_a_template_with_an_unprotected_target_path_to_an_existing_file_that_belongs_to_the_template_package_but_its_hash_sum_does_not_match_the_hash_from_a_CONTENTS_file__the_method_just_joins_a_template_to_a_target_file_without_updating_a_package_CONTENTS_and_the_config_files_and_creating_an_archive_file(self):
target_path = join_paths(
CHROOT_PATH,
'/unprotected/append_join_file_testfiles/file_1')
cfg_path_1 = os.path.join(os.path.dirname(target_path),
'._cfg0001_file_1')
def test_unbound_for_file_with_changes(self):
pass
parameters_object = ParametersContainer({'package': test_package_name,
'append': 'join',
'format': 'bind'})
template_text = 'section-name { parameter-2 no; }'
output_text =\
'section-name {\n parameter-1 no;\n parameter-2 no;\n};\n'
template_wrapper = TemplateWrapper(
target_path,
parameters_object, FILE,
template_text=template_text,
chroot_path=CHROOT_PATH,
config_archive_path=CONFIG_ARCHIVE_PATH)
template_executor._append_join_file(template_wrapper)
assert not template_wrapper.protected
assert os.path.exists(target_path)
assert not os.path.exists(cfg_path_1)
assert not os.path.exists(join_paths(
CONFIG_ARCHIVE_PATH,
'/unprotected/append_join_file_testfiles/file_1'))
assert '/unprotected/append_join_file_testfiles/file_1'\
not in template_executor.calculate_config_file
assert '/unprotected/append_join_file_testfiles/file_1'\
in template_wrapper.target_package
with open(template_wrapper.output_path, 'r') as output_file:
output_file_text = output_file.read()
assert output_file_text == output_text
assert hashlib.md5(output_file_text.encode()).hexdigest !=\
template_wrapper.target_package.get_md5(target_path)
def test_if_append_join_file_method_s_input_is_a_template_with_an_protected_target_path_to_an_existing_file_that_belongs_to_the_template_package_and_the_unbound_parameter_is_set__the_method_joins_template_and_removes_a_target_file_path_from_a_package_CONTENTS_file(self):
target_path = join_paths(
CHROOT_PATH,
'/etc/append_join_file_testfiles/file_13')
parameters_object = ParametersContainer({'package': test_package_name,
'append': 'join',
'format': 'bind',
'unbound': True})
template_text = 'section-name { parameter-2 no; }'
output_text =\
'section-name {\n parameter-1 yes;\n parameter-2 no;\n};\n'
template_wrapper = TemplateWrapper(
target_path,
parameters_object, FILE,
template_text=template_text,
chroot_path=CHROOT_PATH,
config_archive_path=CONFIG_ARCHIVE_PATH)
template_executor._append_join_file(template_wrapper)
assert os.path.exists(target_path)
assert os.path.exists(join_paths(
CONFIG_ARCHIVE_PATH,
'/etc/append_join_file_testfiles/file_13'))
assert '/etc/append_join_file_testfiles/file_13'\
not in template_wrapper.target_package
with open(template_wrapper.output_path, 'r') as output_file:
output_file_text = output_file.read()
assert output_file_text == output_text
def test_if_append_join_file_method_s_input_is_a_template_with_an_protected_target_path_to_an_existing_file_that_belongs_to_the_template_package_and_the_unbound_parameter_is_set_but_its_hash_sum_does_not_match_the_hash_from_a_CONTENTS_file__the_method_joins_template__removes_a_target_file_path_from_a_package_CONTENTS_file(self):
target_path = join_paths(
CHROOT_PATH,
'/etc/append_join_file_testfiles/file_14')
cfg_path_1 = os.path.join(os.path.dirname(target_path),
'._cfg0001_file_14')
parameters_object = ParametersContainer({'package': test_package_name,
'append': 'join',
'format': 'bind',
'unbound': True})
template_text = 'section-name { parameter-2 no; }'
output_text =\
'section-name {\n parameter-1 no;\n parameter-2 no;\n};\n'
template_wrapper = TemplateWrapper(
target_path,
parameters_object, FILE,
template_text=template_text,
chroot_path=CHROOT_PATH,
config_archive_path=CONFIG_ARCHIVE_PATH)
template_executor._append_join_file(template_wrapper)
assert os.path.exists(target_path)
assert not os.path.exists(cfg_path_1)
assert os.path.exists(join_paths(
CONFIG_ARCHIVE_PATH,
'/etc/append_join_file_testfiles/file_14'))
assert '/etc/append_join_file_testfiles/file_14'\
not in template_wrapper.target_package
assert '/etc/append_join_file_testfiles/file_14'\
not in template_executor.calculate_config_file
with open(template_wrapper.output_path, 'r') as output_file:
output_file_text = output_file.read()
assert output_file_text == output_text
def test_if_append_join_file_method_s_input_is_a_template_with_an_protected_target_path_to_an_existing_file_that_belongs_to_the_template_package_and_the_unbound_parameter_is_set_but_its_hash_sum_does_not_match_the_hash_from_a_CONTENTS_file_and_there_are_some_cfg_file__the_method_joins_template__removes_a_target_file_path_from_a_package_CONTENTS_file_and_the_config_file(self):
target_path = join_paths(
CHROOT_PATH,
'/etc/append_join_file_testfiles/file_15')
cfg_path_1 = os.path.join(os.path.dirname(target_path),
'._cfg0001_file_15')
cfg_path_2 = os.path.join(os.path.dirname(target_path),
'._cfg0002_file_15')
cfg_path_3 = os.path.join(os.path.dirname(target_path),
'._cfg0003_file_15')
parameters_object = ParametersContainer({'package': test_package_name,
'append': 'join',
'format': 'bind',
'unbound': True})
template_text = 'section-name { parameter-2 no; }'
output_text =\
'section-name {\n parameter-1 no;\n parameter-2 no;\n};\n'
template_wrapper = TemplateWrapper(
target_path,
parameters_object, FILE,
template_text=template_text,
chroot_path=CHROOT_PATH,
config_archive_path=CONFIG_ARCHIVE_PATH)
template_executor._append_join_file(template_wrapper)
assert os.path.exists(target_path)
assert not os.path.exists(cfg_path_1)
assert not os.path.exists(cfg_path_2)
assert not os.path.exists(cfg_path_3)
assert os.path.exists(join_paths(
CONFIG_ARCHIVE_PATH,
'/etc/append_join_file_testfiles/file_15'))
assert '/etc/append_join_file_testfiles/file_15'\
not in template_wrapper.target_package
assert '/etc/append_join_file_testfiles/file_15'\
not in template_executor.calculate_config_file
with open(template_wrapper.output_path, 'r') as output_file:
output_file_text = output_file.read()
assert output_file_text == output_text
def test_if_the_append_after_file_method_s_input_is_a_not_empty_template__the_template_s_text_and_sections_joins_after_the_text_of_the_target_file(self):
target_path = join_paths(
CHROOT_PATH,
'/etc/append_after_file_testfiles/file_0')
parameters_object = ParametersContainer({'package': test_package_name,
'append': 'after',
'format': 'bind'})
template_text = 'section-1 { parameter-2 no; } section-2 { parameter-1 10; }'
output_text =\
'section-1 {\n parameter-1 yes;\n parameter-2 no;\n};\n\nsection-2 {\n parameter-1 10;\n};\n'
template_wrapper = TemplateWrapper(
target_path,
parameters_object, FILE,
template_text=template_text,
chroot_path=CHROOT_PATH,
config_archive_path=CONFIG_ARCHIVE_PATH)
template_executor._append_after_file(template_wrapper)
assert os.path.exists(target_path)
assert '/etc/append_after_file_testfiles/file_0'\
in template_wrapper.target_package
with open(template_wrapper.output_path, 'r') as output_file:
output_file_text = output_file.read()
assert output_file_text == output_text
def test_if_the_append_before_file_method_s_input_is_a_not_empty_template__the_template_s_text_and_sections_joins_before_the_text_of_the_target_file(self):
target_path = join_paths(
CHROOT_PATH,
'/etc/append_before_file_testfiles/file_0')
parameters_object = ParametersContainer({'package': test_package_name,
'append': 'before',
'format': 'bind'})
template_text = 'section-1 { parameter-1 no; } section-2 { parameter-2 10; }'
output_text =\
'section-1 {\n parameter-1 no;\n};\n\nsection-2 {\n parameter-1 yes;\n parameter-2 10;\n};\n'
template_wrapper = TemplateWrapper(
target_path,
parameters_object, FILE,
template_text=template_text,
chroot_path=CHROOT_PATH,
config_archive_path=CONFIG_ARCHIVE_PATH)
template_executor._append_before_file(template_wrapper)
assert os.path.exists(target_path)
assert '/etc/append_after_file_testfiles/file_0'\
in template_wrapper.target_package
with open(template_wrapper.output_path, 'r') as output_file:
output_file_text = output_file.read()
print('output text:\n{}\n'.format(output_file_text))
assert output_file_text == output_text
def test_if_the_append_replace_file_method_s_input_is_a_not_empty_template_with_a_target_path_to_an_existing_file__the_method_joins_a_template_with_the_empty_text_and_replaces_the_target_file_with_the_template_join_result(self):
target_path = join_paths(
CHROOT_PATH,
'/etc/append_replace_file_testfiles/file_0')
parameters_object = ParametersContainer({'package': test_package_name,
'append': 'replace',
'format': 'bind'})
template_text = 'section-1 { parameter-1 no; }; section-2 { parameter-1 10; }'
output_text =\
'section-1 {\n parameter-1 no;\n};\n\nsection-2 {\n parameter-1 10;\n};\n'
template_wrapper = TemplateWrapper(
target_path,
parameters_object, FILE,
template_text=template_text,
chroot_path=CHROOT_PATH,
config_archive_path=CONFIG_ARCHIVE_PATH)
template_executor._append_replace_file(template_wrapper)
assert os.path.exists(target_path)
assert '/etc/append_after_file_testfiles/file_0'\
in template_wrapper.target_package
with open(template_wrapper.output_path, 'r') as output_file:
output_file_text = output_file.read()
output_md5 = hashlib.md5(output_file_text.encode()).hexdigest()
print('output text:\n{}\n'.format(output_file_text))
assert output_file_text == output_text
assert template_wrapper.target_package.get_md5(target_path) ==\
output_md5
def test_if_the_append_remove_file_method_s_input_is_a_template_with_a_target_path_to_an_existing_file_that_belongs_to_the_template_package__the_method_removes_a_target_file_in_a_filesystem_and_in_a_package_CONTENTS_file(self):
target_path = join_paths(CHROOT_PATH,
'/etc/append_remove_file_testfiles/file_0')
parameters_object = ParametersContainer({'package': test_package_name,
'append': 'remove'})
template_wrapper = TemplateWrapper(
target_path,
parameters_object, FILE,
chroot_path=CHROOT_PATH,
config_archive_path=CONFIG_ARCHIVE_PATH)
template_executor._append_remove_file(template_wrapper)
assert not os.path.exists(target_path)
assert '/etc/append_remove_file_testfiles/file_0'\
not in template_wrapper.target_package
def test_if_the_append_remove_file_method_s_input_is_a_template_with_a_target_path_to_an_unexisting_file_that_belongs_to_the_template_package__the_method_removes_a_target_file_in_a_package_CONTENTS_file(self):
target_path = join_paths(CHROOT_PATH,
'/etc/append_remove_file_testfiles/file_1')
parameters_object = ParametersContainer({'package': test_package_name,
'append': 'remove'})
template_wrapper = TemplateWrapper(
target_path,
parameters_object, FILE,
chroot_path=CHROOT_PATH,
config_archive_path=CONFIG_ARCHIVE_PATH)
template_executor._append_remove_file(template_wrapper)
assert '/etc/append_remove_file_testfiles/file_1'\
not in template_wrapper.target_package
def test_if_the_append_remove_file_method_s_input_is_a_template_with_a_target_path_to_an_existing_file_that_does_not_belong_to_any_package__the_method_removes_a_target_file_in_a_package_CONTENTS_file(self):
target_path = join_paths(CHROOT_PATH,
'/etc/append_remove_file_testfiles/file_2')
parameters_object = ParametersContainer({'package': test_package_name,
'append': 'remove'})
template_wrapper = TemplateWrapper(
target_path,
parameters_object, FILE,
chroot_path=CHROOT_PATH,
config_archive_path=CONFIG_ARCHIVE_PATH)
template_executor._append_remove_file(template_wrapper)
assert not os.path.exists(target_path)
assert '/etc/append_remove_file_testfiles/file_2'\
not in template_wrapper.target_package
def test_if_the_append_clear_file_method_s_input_is_a_template_with_a_target_path_to_an_existing_empty_file_that_belongs_to_the_template_package__the_method_just_updates_a_package_CONTENTS_file(self):
target_path = join_paths(
CHROOT_PATH,
'/etc/append_clear_file_testfiles/file_0')
parameters_object = ParametersContainer({'package': test_package_name,
'append': 'clear'})
template_wrapper = TemplateWrapper(
target_path,
parameters_object, FILE,
chroot_path=CHROOT_PATH,
config_archive_path=CONFIG_ARCHIVE_PATH)
template_executor._append_clear_file(template_wrapper)
with open(template_wrapper.output_path, 'r') as output_file:
output_file_text = output_file.read()
assert not output_file_text
assert template_wrapper.target_package.get_md5(target_path) ==\
hashlib.md5(''.encode()).hexdigest()
def test_if_the_append_clear_file_method_s_input_is_a_template_with_a_target_path_to_an_existing_not_empty_file_that_belongs_to_the_template_package__the_method_clears_a_target_file_and_updates_a_package_CONTENTS_file(self):
target_path = join_paths(
CHROOT_PATH,
'/etc/append_clear_file_testfiles/file_1')
parameters_object = ParametersContainer({'package': test_package_name,
'append': 'clear'})
template_wrapper = TemplateWrapper(
target_path,
parameters_object, FILE,
chroot_path=CHROOT_PATH,
config_archive_path=CONFIG_ARCHIVE_PATH)
template_executor._append_clear_file(template_wrapper)
with open(template_wrapper.output_path, 'r') as output_file:
output_file_text = output_file.read()
assert not output_file_text
assert template_wrapper.target_package.get_md5(target_path) ==\
hashlib.md5(''.encode()).hexdigest()
def test_if_the_append_clear_file_method_s_input_is_a_template_with_a_target_path_to_an_existing_not_empty_file_that_belongs_to_the_template_package_and_the_chown_and_chmod_parameters_are_set__the_method_clears_a_target_file_and_updates_a_package_CONTENTS_file(self):
target_path = join_paths(
CHROOT_PATH,
'/etc/append_clear_file_testfiles/file_2')
chown_value = {'uid': os.getuid(), 'gid': os.getgid()}
chmod_value = int(0o777)
parameters_object = ParametersContainer({'package': test_package_name,
'append': 'clear',
'chown': chown_value,
'chmod': chmod_value})
template_wrapper = TemplateWrapper(
target_path,
parameters_object, FILE,
chroot_path=CHROOT_PATH,
config_archive_path=CONFIG_ARCHIVE_PATH)
template_executor._append_clear_file(template_wrapper)
with open(template_wrapper.output_path, 'r') as output_file:
output_file_text = output_file.read()
assert not output_file_text
assert template_wrapper.target_package.get_md5(target_path) ==\
hashlib.md5(''.encode()).hexdigest()
assert template_executor._get_file_owner(target_path) ==\
chown_value
assert template_executor._get_file_mode(target_path) ==\
chmod_value
def test_to_remove_changed_testfiles(self):
shutil.rmtree(os.path.join(CHROOT_PATH, 'etc'))
shutil.rmtree(os.path.join(CHROOT_PATH, 'unprotected'))
shutil.rmtree(os.path.join(CHROOT_PATH,
'var/lib/calculate/config-archive'))

@ -53,3 +53,24 @@ obj /etc/append_join_file_testfiles/file_8 ee090b452dbf92d697124eb424f5de5b 1592
obj /etc/append_join_file_testfiles/file_9 ee090b452dbf92d697124eb424f5de5b 1592574626
obj /etc/append_join_file_testfiles/file_10 ee090b452dbf92d697124eb424f5de5b 1592574626
obj /etc/append_join_file_testfiles/file_11 ee090b452dbf92d697124eb424f5de5b 1592574626
obj /etc/append_join_file_testfiles/file_12 ee090b452dbf92d697124eb424f5de5b 1592574626
obj /etc/append_join_file_testfiles/file_13 ee090b452dbf92d697124eb424f5de5b 1592574626
obj /etc/append_join_file_testfiles/file_14 ee090b452dbf92d697124eb424f5de5b 1592574626
obj /etc/append_join_file_testfiles/file_15 ee090b452dbf92d697124eb424f5de5b 1592574626
dir /unprotected
dir /unprotected/append_join_file_testfiles
obj /unprotected/append_join_file_testfiles/file_0 ee090b452dbf92d697124eb424f5de5b 1592574626
obj /unprotected/append_join_file_testfiles/file_1 ee090b452dbf92d697124eb424f5de5b 1592574626
dir /etc/append_after_file_testfiles
obj /etc/append_after_file_testfiles/file_0 fcf24b9e2b4368c7345a97b75ba286b7 1592915839
dir /etc/append_before_file_testfiles
obj /etc/append_before_file_testfiles/file_0 f8be0da370f582614fbc97a53ac15761 1592918826
dir /etc/append_replace_file_testfiles
obj /etc/append_replace_file_testfiles/file_0 f8be0da370f582614fbc97a53ac15761 1592920484
dir /etc/append_remove_file_testfiles
obj /etc/append_remove_file_testfiles/file_0 d41d8cd98f00b204e9800998ecf8427e 1592922202
obj /etc/append_remove_file_testfiles/file_1 d41d8cd98f00b204e9800998ecf8427e 1592922630
dir /etc/append_clear_file_testfiles
obj /etc/append_clear_file_testfiles/file_0 d41d8cd98f00b204e9800998ecf8427e 1592923720
obj /etc/append_clear_file_testfiles/file_1 bd98ac718c432c5139edca29680e74b2 1592923838
obj /etc/append_clear_file_testfiles/file_2 bd98ac718c432c5139edca29680e74b2 1592923838

@ -1,3 +1,4 @@
/etc/append_join_file_testfiles/file_10 1668d31fd2a8e3f2c9ecedc5335d8f67
/etc/append_join_file_testfiles/file_11 1668d31fd2a8e3f2c9ecedc5335d8f67
/etc/append_join_file_testfiles/file_12 1668d31fd2a8e3f2c9ecedc5335d8f67
/etc/append_join_file_testfiles/file_15 1668d31fd2a8e3f2c9ecedc5335d8f67

Loading…
Cancel
Save