Links creation is fixed #18

master
Иванов Денис 4 years ago
parent 22663d464b
commit e00423b52b

@ -491,38 +491,38 @@ class TemplateWrapper:
# Путь к архивной версии файла. # Путь к архивной версии файла.
self.archive_path = self._get_archive_path(self.target_path) self.archive_path = self._get_archive_path(self.target_path)
self.md5_matching = (self.parameters.autoupdate self.contents_matching = (self.parameters.autoupdate
or self.parameters.force) or self.parameters.force)
if not self.protected: if not self.protected:
self.md5_matching = True self.contents_matching = True
elif self.parameters.unbound: elif self.parameters.unbound:
# Если присутствует unbound, то просто модифицируем файл и # Если присутствует unbound, то просто модифицируем файл и
# удаляем его из CONTENTS. # удаляем его из CONTENTS.
self.md5_matching = True self.contents_matching = True
elif self.target_type is None: elif self.target_type is None:
# Если целевой файл отсутствует. # Если целевой файл отсутствует.
if self.target_path in self.target_package: if self.target_path in self.target_package:
# Проверка -- был ли файл удален. # Проверка -- был ли файл удален.
# self.md5_matching = self.md5_matching # self.contents_matching = self.contents_matching
pass pass
else: else:
self.md5_matching = True self.contents_matching = True
elif self.target_without_package: elif self.target_without_package:
# Если файл по целевому пути не относится к какому-либо пакету. # Если файл по целевому пути не относится к какому-либо пакету.
# self.md5_matching = False # self.contents_matching = False
pass pass
elif not self.md5_matching: elif not self.contents_matching:
# Если файл есть и он относится к текущему пакету. # Если файл есть и он относится к текущему пакету.
# Если по каким-то причинам уже нужно считать, что хэш-суммы # Если по каким-то причинам уже нужно считать, что хэш-суммы
# совпадают -- в дальнейшей проверке нет необходимости. # совпадают -- в дальнейшей проверке нет необходимости.
target_md5 = self.target_package.get_md5(self.target_path) # target_md5 = self.target_package.get_md5(self.target_path)
self.md5_matching = self.target_package.is_md5_equal( self.contents_matching = self.target_package.check_contents_data(
self.target_path, self.target_path,
file_md5=target_md5) symlink=self.target_is_link)
# Если по целевому пути файл не относящийся к какому-либо пакету и # Если по целевому пути файл не относящийся к какому-либо пакету и
# присутствует параметр autoupdate -- удаляем этот файл. # присутствует параметр autoupdate -- удаляем этот файл.
@ -531,7 +531,7 @@ class TemplateWrapper:
self.remove_original = True self.remove_original = True
# Определяем пути входных и выходных файлов. # Определяем пути входных и выходных файлов.
if self.md5_matching: if self.contents_matching:
# Приоритет отдаем пути из параметра source. # Приоритет отдаем пути из параметра source.
if self.parameters.source: if self.parameters.source:
self.input_path = self.parameters.source self.input_path = self.parameters.source
@ -972,13 +972,18 @@ class TemplateExecutor:
else: else:
chown = self.file_default_parameters.get('chown', False) chown = self.file_default_parameters.get('chown', False)
if template_format.EXECUTABLE or template_object.md5_matching: if template_format.EXECUTABLE or template_object.contents_matching:
# Действия, если целевой файл не имеет пользовательских изменений
# или если он исполнительный.
# Парсим текст шаблона используя его формат.
parsed_template = template_format(template_object.template_text, parsed_template = template_format(template_object.template_text,
template_object.template_path, template_object.template_path,
ignore_comments=True) ignore_comments=True)
if (not parsed_template and not template_object.parameters.source if (not parsed_template and template_object.parameters.source
and template_object.format_class.EXECUTABLE): and template_object.format_class.EXECUTABLE):
# Если шаблон пуст, параметром source не задан входной файл,
# а шаблон является исполнительным
if template_object.target_type is DIR: if template_object.target_type is DIR:
self._remove_directory(template_object.target_path) self._remove_directory(template_object.target_path)
shutil.copytree(input_path, shutil.copytree(input_path,
@ -994,8 +999,7 @@ class TemplateExecutor:
self._chmod_file(template_object.target_path, chmod) self._chmod_file(template_object.target_path, chmod)
elif not template_object.format_class.EXECUTABLE: elif not template_object.format_class.EXECUTABLE:
# Действия при совпадении md5 из CONTENTS и md5 целевого файла. # Действия для шаблонов не являющихся исполнительными.
# А также если шаблон просто исполнительный.
output_paths = [output_path] output_paths = [output_path]
# Если целевой файл защищен, а шаблон не userspace. # Если целевой файл защищен, а шаблон не userspace.
@ -1167,7 +1171,7 @@ class TemplateExecutor:
# Обновляем CONTENTS. # Обновляем CONTENTS.
template_object.add_to_contents(file_md5=output_text_md5) template_object.add_to_contents(file_md5=output_text_md5)
else: else:
# Действия если CL совпало. Пока ничего не делаем. # Действия если CL совпало. Hичего не делаем.
pass pass
def _append_after_file(self, template_object: TemplateWrapper) -> None: def _append_after_file(self, template_object: TemplateWrapper) -> None:
@ -1233,24 +1237,83 @@ class TemplateExecutor:
def _append_link_file(self, template_object: TemplateWrapper) -> None: def _append_link_file(self, template_object: TemplateWrapper) -> None:
'''Метод описывающий действия при append = "link", если шаблон -- '''Метод описывающий действия при append = "link", если шаблон --
файл. Создает ссылку на файл, указанный в параметре source.''' файл. Создает ссылку на файл, указанный в параметре source.'''
self._link_file(template_object.parameters.source, input_path = template_object.input_path
template_object.target_path) output_path = template_object.output_path
if template_object.contents_matching:
output_paths = [output_path]
# Если целевой файл защищен, а шаблон не userspace.
if (template_object.protected
and not template_object.is_userspace):
# Тогда также обновляем архив.
output_paths.append(template_object.archive_path)
for link_path in output_paths:
if not os.path.exists(os.path.dirname(link_path)):
self._create_directory(
template_object,
path_to_create=os.path.dirname(link_path))
elif os.path.exists(link_path):
os.unlink(link_path)
self._link_file(input_path, link_path)
# Корректируем список измененных файлов.
if template_object.target_path not in self.changed_files:
self.changed_files[template_object.target_path] = 'N'
else:
self.changed_files[template_object.target_path] = 'M'
if self.dbpkg:
# Убираем целевой файл из CL.
self.calculate_config_file.remove_file(
template_object.target_path)
if template_object.parameters.unbound:
template_object.remove_from_contents()
else:
template_object.add_to_contents()
else:
source_path_md5 = self._get_source_hash(input_path)
if not self.calculate_config_file.compare_md5(
template_object.target_path,
source_path_md5
):
if not os.path.exists(os.path.dirname(output_path)):
self._create_directory(
template_object,
path_to_create=os.path.dirname(output_path))
elif os.path.exists(output_path):
os.unlink(output_path)
self._link_file(input_path, output_path)
self.changed_files[template_object.target_path] = 'C'
if self.dbpkg:
template_object.add_to_contents()
# Обновляем CL.
self.calculate_config_file.set_files_md5(
template_object.target_path,
source_path_md5)
self.changed_files[template_object.target_path] = 'C'
# Обновляем CONTENTS.
template_object.add_to_contents()
else:
# Действия если CL совпало. Hичего не делаем.
pass
# Меняем права и владельца файла, на который указывает ссылка. # Меняем права и владельца файла, на который указывает ссылка.
if template_object.parameters.chmod: if template_object.parameters.chmod:
self._chmod_file(template_object.parameters.source, self._chmod_file(input_path, template_object.parameters.chmod)
template_object.parameters.chmod)
if template_object.parameters.chown: if template_object.parameters.chown:
self._chown_file(template_object.parameters.source, self._chown_file(input_path, template_object.parameters.chown)
template_object.parameters.chown)
def _get_source_hash(self, source_path: str) -> str:
# Корректируем список измененных файлов. if (self.chroot_path != "/" and
if template_object.target_path not in self.changed_files: source_path.startswith(self.chroot_path)):
self.changed_files[template_object.target_path] = 'N' source_path = source_path[len(self.chroot_path):]
if not source_path.startswith("/"):
if self.dbpkg: source_path = "/" + source_path
template_object.add_to_contents() return hashlib.md5(source_path.encode()).hexdigest()
def _create_directory(self, template_object: TemplateWrapper, def _create_directory(self, template_object: TemplateWrapper,
path_to_create=None) -> None: path_to_create=None) -> None:

@ -982,18 +982,36 @@ class Package:
file_md5 = hashlib.md5(file_text).hexdigest() file_md5 = hashlib.md5(file_text).hexdigest()
return file_md5 return file_md5
def is_md5_equal(self, file_path, file_md5=None): def get_link_target(self, link_path):
try:
return read_link(link_path)
except FilesError as error:
raise PackageError(str(error))
def check_contents_data(self, file_path, file_md5=None,
sym_target=None, symlink=False):
'''Метод для проверки соответствия md5 хэш суммы файла той, что указана '''Метод для проверки соответствия md5 хэш суммы файла той, что указана
в файле CONTENTS.''' в файле CONTENTS.'''
if file_md5 is None: contents_path = file_path
file_md5 = self.get_md5(file_path) if self.chroot_path != "/" and contents_path.startswith(
self.chroot_path):
if self.chroot_path != "/" and file_path.startswith(self.chroot_path): contents_path = contents_path[len(self.chroot_path):]
file_path = file_path[len(self.chroot_path):] contents_path = self.remove_cfg_prefix(contents_path)
file_path = self.remove_cfg_prefix(file_path)
if (not symlink and
contents_md5 = self.contents_dictionary[file_path]['md5'] self.contents_dictionary[contents_path]["type"] != "sym"):
return file_md5 == contents_md5 if file_md5 is None:
file_md5 = self.get_md5(file_path)
contents_md5 = self.contents_dictionary[contents_path]['md5']
return file_md5 == contents_md5
elif (symlink and
self.contents_dictionary[contents_path]["type"] == "sym"):
if sym_target is None:
sym_target = self.get_link_target(file_path)
return (sym_target ==
self.contents_dictionary[contents_path]["target"])
else:
return False
def __contains__(self, file_path): def __contains__(self, file_path):
if self.chroot_path != "/": if self.chroot_path != "/":

@ -313,9 +313,10 @@ class TestDirectoryProcessor:
output_file_text = output_file.read() output_file_text = output_file.read()
assert output_file_text == output_text assert output_file_text == output_text
assert '/etc/file_1' in test_package assert '/etc/file_1' in test_package
assert test_package.is_md5_equal('/etc/file_1', assert test_package.check_contents_data('/etc/file_1',
hashlib.md5( hashlib.md5(
output_text.encode()).hexdigest()) output_text.encode()
).hexdigest())
assert directory_processor.template_executor.\ assert directory_processor.template_executor.\
changed_files == {join_paths(CHROOT_PATH, '/etc/file_1'): 'M'} changed_files == {join_paths(CHROOT_PATH, '/etc/file_1'): 'M'}
@ -353,7 +354,7 @@ class TestDirectoryProcessor:
'/etc/dir_6/file_0'), 'r') as output_file: '/etc/dir_6/file_0'), 'r') as output_file:
output_file_text = output_file.read() output_file_text = output_file.read()
assert output_file_text == output_text assert output_file_text == output_text
assert test_package.is_md5_equal('/etc/dir_6/file_0', assert test_package.check_contents_data('/etc/dir_6/file_0',
hashlib.md5( hashlib.md5(
output_text.encode()).hexdigest()) output_text.encode()).hexdigest())
assert directory_processor.template_executor.\ assert directory_processor.template_executor.\
@ -393,7 +394,7 @@ class TestDirectoryProcessor:
'/etc/._cfg0001_file_2'), 'r') as output_file: '/etc/._cfg0001_file_2'), 'r') as output_file:
output_file_text = output_file.read() output_file_text = output_file.read()
assert output_file_text == output_text assert output_file_text == output_text
assert test_package.is_md5_equal('/etc/._cfg0001_file_2', assert test_package.check_contents_data('/etc/._cfg0001_file_2',
hashlib.md5( hashlib.md5(
output_text.encode()).hexdigest()) output_text.encode()).hexdigest())
@ -433,7 +434,7 @@ class TestDirectoryProcessor:
'/etc/._cfg0001_file_3'), 'r') as output_file: '/etc/._cfg0001_file_3'), 'r') as output_file:
output_file_text = output_file.read() output_file_text = output_file.read()
assert output_file_text == output_text assert output_file_text == output_text
assert test_package.is_md5_equal('/etc/._cfg0001_file_3', assert test_package.check_contents_data('/etc/._cfg0001_file_3',
hashlib.md5( hashlib.md5(
output_text.encode()).hexdigest()) output_text.encode()).hexdigest())
@ -506,23 +507,24 @@ class TestDirectoryProcessor:
'/etc/file_4'), 'r') as output_file: '/etc/file_4'), 'r') as output_file:
output_file_text = output_file.read() output_file_text = output_file.read()
assert output_file_text == output_text_1 assert output_file_text == output_text_1
assert test_package.is_md5_equal('/etc/file_4', assert test_package.check_contents_data('/etc/file_4',
hashlib.md5( hashlib.md5(
output_text_1.encode()).hexdigest()) output_text_1.encode()).hexdigest())
with open(join_paths(CHROOT_PATH, with open(join_paths(CHROOT_PATH,
'/etc/file_5'), 'r') as output_file: '/etc/file_5'), 'r') as output_file:
output_file_text = output_file.read() output_file_text = output_file.read()
assert output_file_text == output_text_2 assert output_file_text == output_text_2
assert test_package.is_md5_equal('/etc/file_5', assert test_package.check_contents_data('/etc/file_5',
hashlib.md5( hashlib.md5(
output_text_2.encode()).hexdigest()) output_text_2.encode()).hexdigest())
with open(join_paths(CHROOT_PATH, with open(join_paths(CHROOT_PATH,
'/etc/dir_7/file_0'), 'r') as output_file: '/etc/dir_7/file_0'), 'r') as output_file:
output_file_text = output_file.read() output_file_text = output_file.read()
assert output_file_text == output_text_3 assert output_file_text == output_text_3
assert test_package.is_md5_equal('/etc/dir_7/file_0', assert test_package.check_contents_data('/etc/dir_7/file_0',
hashlib.md5( hashlib.md5(
output_text_3.encode()).hexdigest()) output_text_3.encode()
).hexdigest())
assert directory_processor.template_executor.\ assert directory_processor.template_executor.\
changed_files == {join_paths(CHROOT_PATH, changed_files == {join_paths(CHROOT_PATH,

@ -72,9 +72,8 @@ class TestTemplateParameters:
pytest.fail('Unexpected exception: {0}'. pytest.fail('Unexpected exception: {0}'.
format(str(error))) format(str(error)))
assert parameters_object.source == join_paths( assert parameters_object.source == join_paths(CHROOT_PATH,
CHROOT_PATH, '/test_dir_1/file.test')
'/test_dir_1/file.test')
def test_if_TemplateParameters_object_is_intialized_as_dir_parameters_object_using_correct_source_parameter_with_append_link__the_object_will_be_initialized_successfully(self): def test_if_TemplateParameters_object_is_intialized_as_dir_parameters_object_using_correct_source_parameter_with_append_link__the_object_will_be_initialized_successfully(self):
parameters = {'append': 'link', 'source': '/test_dir_1'} parameters = {'append': 'link', 'source': '/test_dir_1'}

@ -2410,12 +2410,10 @@ class TestTemplateExecutor:
chmod_value chmod_value
def test_if_append_link_file_method_s_input_is_a_template_with_a_target_path_and_a_source_path_to_the_existing_file__the_method_creates_a_link_to_the_source_file_and_adds_this_link_to_the_package_CONTENTS_file(self): def test_if_append_link_file_method_s_input_is_a_template_with_a_target_path_and_a_source_path_to_the_existing_file__the_method_creates_a_link_to_the_source_file_and_adds_this_link_to_the_package_CONTENTS_file(self):
target_path = join_paths( target_path = join_paths(CHROOT_PATH,
CHROOT_PATH, '/etc/append_link_file_testfiles/link_file_0')
'/etc/append_link_file_testfiles/link_file_0') source_path = join_paths(CHROOT_PATH,
source_path = join_paths( '/etc/append_link_file_testfiles/file_0')
CHROOT_PATH,
'/etc/append_link_file_testfiles/file_0')
parameters_object = ParametersContainer({'package': test_package_name, parameters_object = ParametersContainer({'package': test_package_name,
'append': 'link', 'append': 'link',
@ -2427,12 +2425,75 @@ class TestTemplateExecutor:
chroot_path=CHROOT_PATH, chroot_path=CHROOT_PATH,
config_archive_path=CONFIG_ARCHIVE_PATH) config_archive_path=CONFIG_ARCHIVE_PATH)
template_executor._append_link_file(template_wrapper) template_executor._append_link_file(template_wrapper)
assert os.path.exists(target_path) assert os.path.exists(template_wrapper.output_path)
assert os.path.islink(target_path) assert os.path.islink(template_wrapper.output_path)
assert os.readlink(target_path) == source_path assert os.readlink(template_wrapper.output_path) == source_path
assert '/etc/append_link_file_testfiles/link_file_0'\ assert '/etc/append_link_file_testfiles/link_file_0'\
in template_wrapper.target_package in template_wrapper.target_package
assert os.path.exists(template_wrapper.archive_path)
def test_if_append_link_file_method_s_input_is_a_template_with_a_target_path_to_an_existing_link_without_user_changes_and_a_source_path_to_the_existing_file__the_method_(self):
target_path = join_paths(CHROOT_PATH,
'/etc/append_link_file_testfiles/link_file_2')
source_path = join_paths(CHROOT_PATH,
'/etc/append_link_file_testfiles/file_2')
parameters_object = ParametersContainer({'package': test_package_name,
'append': 'link',
'source': source_path})
template_wrapper = TemplateWrapper(
target_path,
parameters_object, FILE,
'/path/to/template',
chroot_path=CHROOT_PATH,
config_archive_path=CONFIG_ARCHIVE_PATH)
template_executor._append_link_file(template_wrapper)
assert os.path.exists(template_wrapper.output_path)
assert os.path.islink(template_wrapper.output_path)
assert os.readlink(template_wrapper.output_path) == source_path
assert '/etc/append_link_file_testfiles/link_file_2'\
in template_wrapper.target_package
assert os.path.exists(template_wrapper.archive_path)
def test_if_append_link_file_method_s_input_is_a_template_with_a_target_path_to_an_existing_link_with_user_changes_and_a_source_path_to_the_existing_file__the_method_(self):
target_path = join_paths(CHROOT_PATH,
'/etc/append_link_file_testfiles/link_file_3')
source_path = join_paths(CHROOT_PATH,
'/etc/append_link_file_testfiles/file_3')
output_path = join_paths(
CHROOT_PATH,
'/etc/append_link_file_testfiles/._cfg0001_link_file_3')
parameters_object = ParametersContainer({'package': test_package_name,
'append': 'link',
'source': source_path})
template_wrapper = TemplateWrapper(
target_path,
parameters_object, FILE,
'/path/to/template',
chroot_path=CHROOT_PATH,
config_archive_path=CONFIG_ARCHIVE_PATH)
template_executor._append_link_file(template_wrapper)
assert os.path.exists(output_path)
assert os.path.islink(output_path)
assert os.readlink(target_path) == "file_5"
assert os.readlink(output_path) == source_path
assert '/etc/append_link_file_testfiles/link_file_3'\
in template_wrapper.target_package
assert (template_wrapper.target_package.contents_dictionary[
'/etc/append_link_file_testfiles/link_file_3'][
'target'] == source_path)
assert ('/etc/append_link_file_testfiles/link_file_3'
in template_executor.calculate_config_file)
assert (template_executor.calculate_config_file._config_dictionary[
'/etc/append_link_file_testfiles/link_file_3']
== hashlib.md5('/etc/append_link_file_testfiles/file_3'
.encode()).hexdigest())
def test_if_append_link_file_method_s_input_is_a_template_with_a_target_path_and_a_source_path_to_the_existing_file_and_the_chown_and_chmod_parameters_are_set__the_method_creates_a_link_to_the_source_file_and_adds_this_link_to_the_package_CONTENTS_file(self): def test_if_append_link_file_method_s_input_is_a_template_with_a_target_path_and_a_source_path_to_the_existing_file_and_the_chown_and_chmod_parameters_are_set__the_method_creates_a_link_to_the_source_file_and_adds_this_link_to_the_package_CONTENTS_file(self):
target_path = join_paths( target_path = join_paths(

@ -695,7 +695,7 @@ class TestTemplateWrapper:
assert not template_wrapper.protected assert not template_wrapper.protected
# Тестируем проверку хэш-сумм и флаг получаемый в результате нее. # Тестируем проверку хэш-сумм и флаг получаемый в результате нее.
def test_if_a_target_file_is_not_protected__the_TemplateWrapper_sets_the_md5_matching_flag_as_True(self): def test_if_a_target_file_is_not_protected__the_TemplateWrapper_sets_the_contents_matching_flag_as_True(self):
parameters_object = ParametersContainer({'append': 'join', parameters_object = ParametersContainer({'append': 'join',
'format': 'samba'}) 'format': 'samba'})
try: try:
@ -708,9 +708,9 @@ class TestTemplateWrapper:
config_archive_path=CONFIG_ARCHIVE_PATH) config_archive_path=CONFIG_ARCHIVE_PATH)
except Exception as error: except Exception as error:
pytest.fail("Unexpected exception: {}".format(str(error))) pytest.fail("Unexpected exception: {}".format(str(error)))
assert template_wrapper.md5_matching assert template_wrapper.contents_matching
def test_if_a_template_contains_the_unbound_parameter__the_TemplateWrapper_sets_the_md5_matching_flag_as_True(self): def test_if_a_template_contains_the_unbound_parameter__the_TemplateWrapper_sets_the_contents_matching_flag_as_True(self):
parameters_object = ParametersContainer({'append': 'join', parameters_object = ParametersContainer({'append': 'join',
'format': 'samba', 'format': 'samba',
'unbound': True}) 'unbound': True})
@ -724,9 +724,9 @@ class TestTemplateWrapper:
config_archive_path=CONFIG_ARCHIVE_PATH) config_archive_path=CONFIG_ARCHIVE_PATH)
except Exception as error: except Exception as error:
pytest.fail("Unexpected exception: {}".format(str(error))) pytest.fail("Unexpected exception: {}".format(str(error)))
assert template_wrapper.md5_matching assert template_wrapper.contents_matching
def test_if_a_target_file_does_not_exist_and_CONTENTS_file_of_the_file_s_package_does_not_contain_this_file__the_TemplateWrapper_sets_the_md5_matching_flag_as_True(self): def test_if_a_target_file_does_not_exist_and_CONTENTS_file_of_the_file_s_package_does_not_contain_this_file__the_TemplateWrapper_sets_the_contents_matching_flag_as_True(self):
parameters_object = ParametersContainer({'package': test_package_name, parameters_object = ParametersContainer({'package': test_package_name,
'append': 'join', 'append': 'join',
'format': 'json'}) 'format': 'json'})
@ -740,9 +740,9 @@ class TestTemplateWrapper:
config_archive_path=CONFIG_ARCHIVE_PATH) config_archive_path=CONFIG_ARCHIVE_PATH)
except Exception as error: except Exception as error:
pytest.fail("Unexpected exception: {}".format(str(error))) pytest.fail("Unexpected exception: {}".format(str(error)))
assert template_wrapper.md5_matching assert template_wrapper.contents_matching
def test_if_a_target_file_was_deleted_by_a_user__the_TemplateWrapper_object_sets_the_md5_matching_flag_as_False(self): def test_if_a_target_file_was_deleted_by_a_user__the_TemplateWrapper_object_sets_the_contents_matching_flag_as_False(self):
parameters_object = ParametersContainer({'package': test_package_name, parameters_object = ParametersContainer({'package': test_package_name,
'append': 'join', 'append': 'join',
'format': 'json'}) 'format': 'json'})
@ -756,9 +756,9 @@ class TestTemplateWrapper:
config_archive_path=CONFIG_ARCHIVE_PATH) config_archive_path=CONFIG_ARCHIVE_PATH)
except Exception as error: except Exception as error:
pytest.fail("Unexpected exception: {}".format(str(error))) pytest.fail("Unexpected exception: {}".format(str(error)))
assert not template_wrapper.md5_matching assert not template_wrapper.contents_matching
def test_if_a_target_file_does_not_belong_to_any_package__the_TemplateWrapper_object_sets_the_md5_matching_flag_as_False(self): def test_if_a_target_file_does_not_belong_to_any_package__the_TemplateWrapper_object_sets_the_contents_matching_flag_as_False(self):
parameters_object = ParametersContainer({'package': test_package_name, parameters_object = ParametersContainer({'package': test_package_name,
'append': 'join', 'append': 'join',
'format': 'json'}) 'format': 'json'})
@ -772,9 +772,9 @@ class TestTemplateWrapper:
config_archive_path=CONFIG_ARCHIVE_PATH) config_archive_path=CONFIG_ARCHIVE_PATH)
except Exception as error: except Exception as error:
pytest.fail("Unexpected exception: {}".format(str(error))) pytest.fail("Unexpected exception: {}".format(str(error)))
assert not template_wrapper.md5_matching assert not template_wrapper.contents_matching
def test_if_a_template_contains_the_autoupdate_parameter__the_TemplateWrapper_sets_the_md5_matching_flag_as_True(self): def test_if_a_template_contains_the_autoupdate_parameter__the_TemplateWrapper_sets_the_contents_matching_flag_as_True(self):
parameters_object = ParametersContainer({'append': 'join', parameters_object = ParametersContainer({'append': 'join',
'format': 'samba', 'format': 'samba',
'autoupdate': True}) 'autoupdate': True})
@ -788,9 +788,9 @@ class TestTemplateWrapper:
config_archive_path=CONFIG_ARCHIVE_PATH) config_archive_path=CONFIG_ARCHIVE_PATH)
except Exception as error: except Exception as error:
pytest.fail("Unexpected exception: {}".format(str(error))) pytest.fail("Unexpected exception: {}".format(str(error)))
assert template_wrapper.md5_matching assert template_wrapper.contents_matching
def test_if_a_template_contains_the_autoupdate_parameter_and_a_target_file_does_not_belong_to_any_package__the_TemplateWrapper_sets_the_md5_matching_flag_as_True(self): def test_if_a_template_contains_the_autoupdate_parameter_and_a_target_file_does_not_belong_to_any_package__the_TemplateWrapper_sets_the_contents_matching_flag_as_True(self):
parameters_object = ParametersContainer({'package': test_package_name, parameters_object = ParametersContainer({'package': test_package_name,
'append': 'join', 'append': 'join',
'format': 'samba', 'format': 'samba',
@ -806,9 +806,9 @@ class TestTemplateWrapper:
except Exception as error: except Exception as error:
pytest.fail("Unexpected exception: {}".format(str(error))) pytest.fail("Unexpected exception: {}".format(str(error)))
assert template_wrapper.target_without_package assert template_wrapper.target_without_package
assert template_wrapper.md5_matching assert template_wrapper.contents_matching
def test_if_a_target_file_s_hash_matches_the_hash_from_the_package_s_CONTENTS_file__the_TemplateWrapper_object_sets_the_md5_matching_flag_as_True(self): def test_if_a_target_file_s_hash_matches_the_hash_from_the_package_s_CONTENTS_file__the_TemplateWrapper_object_sets_the_contents_matching_flag_as_True(self):
parameters_object = ParametersContainer({'package': test_package_name, parameters_object = ParametersContainer({'package': test_package_name,
'append': 'join', 'append': 'join',
'format': 'json'}) 'format': 'json'})
@ -822,9 +822,9 @@ class TestTemplateWrapper:
config_archive_path=CONFIG_ARCHIVE_PATH) config_archive_path=CONFIG_ARCHIVE_PATH)
except Exception as error: except Exception as error:
pytest.fail("Unexpected exception: {}".format(str(error))) pytest.fail("Unexpected exception: {}".format(str(error)))
assert template_wrapper.md5_matching assert template_wrapper.contents_matching
def test_if_a_target_file_s_hash_does_not_match_the_hash_from_the_package_s_CONTENTS_file__the_TemplateWrapper_object_sets_the_md5_matching_flag_as_False(self): def test_if_a_target_file_s_hash_does_not_match_the_hash_from_the_package_s_CONTENTS_file__the_TemplateWrapper_object_sets_the_contents_matching_flag_as_False(self):
parameters_object = ParametersContainer({'append': 'join', parameters_object = ParametersContainer({'append': 'join',
'format': 'json'}) 'format': 'json'})
try: try:
@ -837,11 +837,11 @@ class TestTemplateWrapper:
config_archive_path=CONFIG_ARCHIVE_PATH) config_archive_path=CONFIG_ARCHIVE_PATH)
except Exception as error: except Exception as error:
pytest.fail("Unexpected exception: {}".format(str(error))) pytest.fail("Unexpected exception: {}".format(str(error)))
assert not template_wrapper.md5_matching assert not template_wrapper.contents_matching
# Тестируем вывод путей к входному и выходному файлам исполнительного # Тестируем вывод путей к входному и выходному файлам исполнительного
# модуля. # модуля.
def test_if_after_the_target_file_check_md5_matching_flag_is_set_as_True_and_a_template_does_not_contain_source_parameter__the_output_and_the_input_paths_for_the_TemplateExecutor_is_the_same_and_it_is_target_path(self): def test_if_after_the_target_file_check_contents_matching_flag_is_set_as_True_and_a_template_does_not_contain_source_parameter__the_output_and_the_input_paths_for_the_TemplateExecutor_is_the_same_and_it_is_target_path(self):
parameters_object = ParametersContainer({'package': test_package_name, parameters_object = ParametersContainer({'package': test_package_name,
'append': 'join', 'append': 'join',
'format': 'json'}) 'format': 'json'})
@ -860,7 +860,7 @@ class TestTemplateWrapper:
assert template_wrapper.output_path == join_paths(CHROOT_PATH, assert template_wrapper.output_path == join_paths(CHROOT_PATH,
'/etc/dir/file.conf') '/etc/dir/file.conf')
def test_if_after_the_target_file_check_md5_matching_flag_is_set_as_False_and_a_template_does_not_contain_source_parameter__the_output_path_is_the_cfg_file_path_and_the_input_path_is_the_calculate_archive_path(self): def test_if_after_the_target_file_check_contents_matching_flag_is_set_as_False_and_a_template_does_not_contain_source_parameter__the_output_path_is_the_cfg_file_path_and_the_input_path_is_the_calculate_archive_path(self):
parameters_object = ParametersContainer({'append': 'join', parameters_object = ParametersContainer({'append': 'join',
'format': 'json'}) 'format': 'json'})
try: try:
@ -879,7 +879,7 @@ class TestTemplateWrapper:
CHROOT_PATH, CHROOT_PATH,
'/etc/dir_0/._cfg0001_file') '/etc/dir_0/._cfg0001_file')
def test_if_after_the_target_file_check_md5_matching_flag_is_set_as_True_and_a_template_contains_source_parameter__the_output_and_the_input_paths_for_the_TemplateExecutor_is_the_same_and_it_is_target_path(self): def test_if_after_the_target_file_check_contents_matching_flag_is_set_as_True_and_a_template_contains_source_parameter__the_output_and_the_input_paths_for_the_TemplateExecutor_is_the_same_and_it_is_target_path(self):
source = join_paths(CHROOT_PATH, '/etc/file') source = join_paths(CHROOT_PATH, '/etc/file')
parameters_object = ParametersContainer({'package': test_package_name, parameters_object = ParametersContainer({'package': test_package_name,
'append': 'join', 'append': 'join',
@ -899,7 +899,7 @@ class TestTemplateWrapper:
assert template_wrapper.output_path == join_paths(CHROOT_PATH, assert template_wrapper.output_path == join_paths(CHROOT_PATH,
'/etc/dir/file.conf') '/etc/dir/file.conf')
def test_if_after_the_target_file_check_md5_matching_flag_is_set_as_False_and_a_template_contains_source_parameter__the_output_path_is_the_cfg_file_path_and_the_input_path_is_the_calculate_archive_path(self): def test_if_after_the_target_file_check_contents_matching_flag_is_set_as_False_and_a_template_contains_source_parameter__the_output_path_is_the_cfg_file_path_and_the_input_path_is_the_calculate_archive_path(self):
source = join_paths(CHROOT_PATH, '/etc/file') source = join_paths(CHROOT_PATH, '/etc/file')
parameters_object = ParametersContainer({'append': 'join', parameters_object = ParametersContainer({'append': 'join',
'format': 'json', 'format': 'json',

@ -87,3 +87,6 @@ dir /etc/append_clear_file_testfiles
obj /etc/append_clear_file_testfiles/file_0 d41d8cd98f00b204e9800998ecf8427e 1592923720 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_1 bd98ac718c432c5139edca29680e74b2 1592923838
obj /etc/append_clear_file_testfiles/file_2 bd98ac718c432c5139edca29680e74b2 1592923838 obj /etc/append_clear_file_testfiles/file_2 bd98ac718c432c5139edca29680e74b2 1592923838
dir /etc/append_link_file_testfiles/
sym /etc/append_link_file_testfiles/link_file_2 -> file_2 1605513794
sym /etc/append_link_file_testfiles/link_file_3 -> file_4 1605513794

Loading…
Cancel
Save