|
|
|
@ -1377,12 +1377,201 @@ class TestTemplateExecutor:
|
|
|
|
|
assert os.path.exists(target_path)
|
|
|
|
|
assert os.path.exists(output_path)
|
|
|
|
|
|
|
|
|
|
assert os.path.exists(join_paths(
|
|
|
|
|
CONFIG_ARCHIVE_PATH,
|
|
|
|
|
'/etc/append_join_file_testfiles/file_7'))
|
|
|
|
|
assert '/etc/append_join_file_testfiles/file_7'\
|
|
|
|
|
in template_executor.calculate_config_file
|
|
|
|
|
with open(template_wrapper.output_path, 'r') as output_file:
|
|
|
|
|
assert output_file.read() == output_text
|
|
|
|
|
|
|
|
|
|
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_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_and_chown_and_chmod_it(self):
|
|
|
|
|
target_path = join_paths(
|
|
|
|
|
CHROOT_PATH,
|
|
|
|
|
'/etc/append_join_file_testfiles/file_8')
|
|
|
|
|
output_path = os.path.join(os.path.dirname(target_path),
|
|
|
|
|
'._cfg0001_file_8')
|
|
|
|
|
chown_value = {'uid': os.getuid(), 'gid': os.getgid()}
|
|
|
|
|
chmod_value = int(0o777)
|
|
|
|
|
|
|
|
|
|
parameters_object = ParametersContainer({'package': test_package_name,
|
|
|
|
|
'append': 'join',
|
|
|
|
|
'format': 'bind',
|
|
|
|
|
'chown': chown_value,
|
|
|
|
|
'chmod': chmod_value})
|
|
|
|
|
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(output_path)
|
|
|
|
|
assert template_executor._get_file_owner(output_path) == chown_value
|
|
|
|
|
assert template_executor._get_file_mode(output_path) == chmod_value
|
|
|
|
|
|
|
|
|
|
assert '/etc/append_join_file_testfiles/file_8'\
|
|
|
|
|
in template_executor.calculate_config_file
|
|
|
|
|
with open(template_wrapper.output_path, 'r') as output_file:
|
|
|
|
|
assert output_file.read() == output_text
|
|
|
|
|
|
|
|
|
|
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_but_its_hash_sum_does_not_match_the_hash_from_a_CONTENTS_file_and_the_autoupdate_parameter_is_set__the_method_joins_a_target_file_and_a_template__removes_a_path_to_file_from_the_config_file_and_updates_a_package_CONTENTS_file(self):
|
|
|
|
|
target_path = join_paths(
|
|
|
|
|
CHROOT_PATH,
|
|
|
|
|
'/etc/append_join_file_testfiles/file_9')
|
|
|
|
|
cfg_path = os.path.join(os.path.dirname(target_path),
|
|
|
|
|
'._cfg0001_file_9')
|
|
|
|
|
|
|
|
|
|
parameters_object = ParametersContainer({'package': test_package_name,
|
|
|
|
|
'append': 'join',
|
|
|
|
|
'format': 'bind',
|
|
|
|
|
'autoupdate': 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)
|
|
|
|
|
|
|
|
|
|
assert '/etc/append_join_file_testfiles/file_9'\
|
|
|
|
|
not in template_executor.calculate_config_file
|
|
|
|
|
|
|
|
|
|
assert '/etc/append_join_file_testfiles/file_9'\
|
|
|
|
|
in template_wrapper.target_package
|
|
|
|
|
with open(template_wrapper.output_path, 'r') as output_file:
|
|
|
|
|
assert output_file.read() == output_text
|
|
|
|
|
|
|
|
|
|
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_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(self):
|
|
|
|
|
target_path = join_paths(
|
|
|
|
|
CHROOT_PATH,
|
|
|
|
|
'/etc/append_join_file_testfiles/file_10')
|
|
|
|
|
cfg_path_1 = os.path.join(os.path.dirname(target_path),
|
|
|
|
|
'._cfg0001_file_10')
|
|
|
|
|
cfg_path_2 = os.path.join(os.path.dirname(target_path),
|
|
|
|
|
'._cfg0002_file_10')
|
|
|
|
|
parameters_object = ParametersContainer({'package': test_package_name,
|
|
|
|
|
'append': 'join',
|
|
|
|
|
'format': 'bind',
|
|
|
|
|
'autoupdate': True})
|
|
|
|
|
template_text = 'section-name { parameter-4 yes; }'
|
|
|
|
|
output_text =\
|
|
|
|
|
'section-name {\n parameter-1 yes;\n parameter-4 yes;\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)
|
|
|
|
|
print('input path = {}'.format(template_wrapper.input_path))
|
|
|
|
|
assert os.path.exists(target_path)
|
|
|
|
|
assert not os.path.exists(cfg_path_1)
|
|
|
|
|
assert not os.path.exists(cfg_path_2)
|
|
|
|
|
|
|
|
|
|
assert '/etc/append_join_file_testfiles/file_10'\
|
|
|
|
|
not in template_executor.calculate_config_file
|
|
|
|
|
|
|
|
|
|
assert '/etc/append_join_file_testfiles/file_10'\
|
|
|
|
|
in template_wrapper.target_package
|
|
|
|
|
with open(template_wrapper.output_path, 'r') as output_file:
|
|
|
|
|
output_file_text = output_file.read()
|
|
|
|
|
print('Output:\n{}'.format(output_file_text))
|
|
|
|
|
assert output_file_text == output_text
|
|
|
|
|
|
|
|
|
|
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_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(self):
|
|
|
|
|
target_path = join_paths(
|
|
|
|
|
CHROOT_PATH,
|
|
|
|
|
'/etc/append_join_file_testfiles/file_11')
|
|
|
|
|
cfg_path_1 = os.path.join(os.path.dirname(target_path),
|
|
|
|
|
'._cfg0001_file_11')
|
|
|
|
|
cfg_path_2 = os.path.join(os.path.dirname(target_path),
|
|
|
|
|
'._cfg0002_file_11')
|
|
|
|
|
cfg_path_3 = os.path.join(os.path.dirname(target_path),
|
|
|
|
|
'._cfg0003_file_11')
|
|
|
|
|
|
|
|
|
|
parameters_object = ParametersContainer({'package': test_package_name,
|
|
|
|
|
'append': 'join',
|
|
|
|
|
'format': 'bind'})
|
|
|
|
|
template_text = 'section-name { parameter-4 yes; }'
|
|
|
|
|
output_text =\
|
|
|
|
|
'section-name {\n parameter-1 yes;\n parameter-4 yes;\n};\n'
|
|
|
|
|
output_md5 = hashlib.md5(output_text.encode()).hexdigest()
|
|
|
|
|
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)
|
|
|
|
|
print('output_path = {}'.format(template_wrapper.output_path))
|
|
|
|
|
assert os.path.exists(target_path)
|
|
|
|
|
assert os.path.exists(cfg_path_1)
|
|
|
|
|
assert os.path.exists(cfg_path_2)
|
|
|
|
|
assert os.path.exists(cfg_path_3)
|
|
|
|
|
|
|
|
|
|
assert '/etc/append_join_file_testfiles/file_11'\
|
|
|
|
|
in template_executor.calculate_config_file
|
|
|
|
|
assert template_executor.calculate_config_file.compare_md5(
|
|
|
|
|
'/etc/append_join_file_testfiles/file_11', output_md5)
|
|
|
|
|
with open(template_wrapper.output_path, 'r') as output_file:
|
|
|
|
|
output_file_text = output_file.read()
|
|
|
|
|
print('Output:\n{}'.format(output_file_text))
|
|
|
|
|
assert output_file_text == output_text
|
|
|
|
|
|
|
|
|
|
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_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(self):
|
|
|
|
|
target_path = join_paths(
|
|
|
|
|
CHROOT_PATH,
|
|
|
|
|
'/etc/append_join_file_testfiles/file_12')
|
|
|
|
|
cfg_path_2 = os.path.join(os.path.dirname(target_path),
|
|
|
|
|
'._cfg0002_file_12')
|
|
|
|
|
cfg_path_3 = os.path.join(os.path.dirname(target_path),
|
|
|
|
|
'._cfg0003_file_12')
|
|
|
|
|
|
|
|
|
|
parameters_object = ParametersContainer({'package': test_package_name,
|
|
|
|
|
'append': 'join',
|
|
|
|
|
'format': 'bind'})
|
|
|
|
|
template_text = 'section-name { parameter-3 10; }'
|
|
|
|
|
output_text =\
|
|
|
|
|
'section-name {\n parameter-1 yes;\n parameter-3 10;\n};\n'
|
|
|
|
|
output_md5 = hashlib.md5(output_text.encode()).hexdigest()
|
|
|
|
|
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(cfg_path_2)
|
|
|
|
|
assert not os.path.exists(cfg_path_3)
|
|
|
|
|
|
|
|
|
|
assert '/etc/append_join_file_testfiles/file_12'\
|
|
|
|
|
in template_executor.calculate_config_file
|
|
|
|
|
assert template_executor.calculate_config_file.compare_md5(
|
|
|
|
|
'/etc/append_join_file_testfiles/file_12', output_md5)
|
|
|
|
|
with open(cfg_path_2, 'r') as output_file:
|
|
|
|
|
output_file_text = output_file.read()
|
|
|
|
|
assert output_file_text == output_text
|
|
|
|
|
|
|
|
|
|
def test_unprotected_for_file_without_changes(self):
|
|
|
|
|
pass
|
|
|
|
|
|
|
|
|
|
def test_unprotected_for_file_with_changes(self):
|
|
|
|
|
pass
|
|
|
|
|
|
|
|
|
|
def test_unbound_for_file_without_changes(self):
|
|
|
|
|
pass
|
|
|
|
|
|
|
|
|
|
def test_unbound_for_file_with_changes(self):
|
|
|
|
|
pass
|
|
|
|
|
|
|
|
|
|
def test_to_remove_changed_testfiles(self):
|
|
|
|
|
shutil.rmtree(os.path.join(CHROOT_PATH, 'etc'))
|
|
|
|
|
shutil.rmtree(os.path.join(CHROOT_PATH,
|
|
|
|
|