|
|
|
@ -46,13 +46,9 @@ other_package_name = PackageAtomName(
|
|
|
|
|
@pytest.mark.template_executor
|
|
|
|
|
class TestTemplateExecutor:
|
|
|
|
|
def test_function_to_copy_testfiles(self):
|
|
|
|
|
try:
|
|
|
|
|
shutil.copytree(os.path.join(CHROOT_PATH, 'etc.backup'),
|
|
|
|
|
os.path.join(CHROOT_PATH, 'etc'),
|
|
|
|
|
ignore_dangling_symlinks=True)
|
|
|
|
|
except Exception as error:
|
|
|
|
|
# pytest.fail(str(error))
|
|
|
|
|
pass
|
|
|
|
|
shutil.copytree(os.path.join(CHROOT_PATH, 'etc.backup'),
|
|
|
|
|
os.path.join(CHROOT_PATH, 'etc'),
|
|
|
|
|
symlinks=True)
|
|
|
|
|
|
|
|
|
|
# Сначала протестируем класс для работы с /var/lib/calculate/config файлом.
|
|
|
|
|
def test_if_config_file_does_not_exist__a_CalculateConfigFile_object_will_create_one_while_its_initialization(self):
|
|
|
|
@ -837,7 +833,7 @@ class TestTemplateExecutor:
|
|
|
|
|
CHROOT_PATH,
|
|
|
|
|
'/etc/append_clear_dir_testfiles/dir_0')
|
|
|
|
|
parameters_object = ParametersContainer({'package': test_package_name,
|
|
|
|
|
'append': 'join'})
|
|
|
|
|
'append': 'clear'})
|
|
|
|
|
template_wrapper = TemplateWrapper(
|
|
|
|
|
target_path,
|
|
|
|
|
parameters_object, DIR,
|
|
|
|
@ -845,11 +841,286 @@ class TestTemplateExecutor:
|
|
|
|
|
config_archive_path=CONFIG_ARCHIVE_PATH)
|
|
|
|
|
template_executor._append_clear_directory(template_wrapper)
|
|
|
|
|
assert not os.listdir(target_path)
|
|
|
|
|
assert os.path.join(target_path, 'file')\
|
|
|
|
|
assert '/etc/append_clear_dir_testfiles/dir_0/file'\
|
|
|
|
|
not in template_wrapper.target_package
|
|
|
|
|
|
|
|
|
|
def test_if_append_clear_directory_method_s_input_is_a_template_with_a_target_path_to_an_unexisting_directory_that_belongs_to_the_template_package__the_method_just_removes_the_directory_and_all_its_files_from_a_package_CONTENTS_file(self):
|
|
|
|
|
target_path = join_paths(CHROOT_PATH,
|
|
|
|
|
'/etc/append_clear_dir_testfiles/dir_1')
|
|
|
|
|
parameters_object = ParametersContainer({'package': test_package_name,
|
|
|
|
|
'append': 'clear'})
|
|
|
|
|
template_wrapper = TemplateWrapper(
|
|
|
|
|
target_path,
|
|
|
|
|
parameters_object, DIR,
|
|
|
|
|
chroot_path=CHROOT_PATH,
|
|
|
|
|
config_archive_path=CONFIG_ARCHIVE_PATH)
|
|
|
|
|
template_executor._append_clear_directory(template_wrapper)
|
|
|
|
|
# Метод выполняется при сохранении файла CONTENTS,
|
|
|
|
|
# здесь вызывем напрямую.
|
|
|
|
|
template_wrapper.target_package.remove_empty_directories()
|
|
|
|
|
assert '/etc/append_clear_dir_testfiles/dir_1'\
|
|
|
|
|
not in template_wrapper.target_package
|
|
|
|
|
|
|
|
|
|
def 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_does_nothing(self):
|
|
|
|
|
target_path = join_paths(CHROOT_PATH,
|
|
|
|
|
'/etc/append_clear_dir_testfiles/dir_2')
|
|
|
|
|
parameters_object = ParametersContainer({'package': test_package_name,
|
|
|
|
|
'append': 'clear'})
|
|
|
|
|
template_wrapper = TemplateWrapper(
|
|
|
|
|
target_path,
|
|
|
|
|
parameters_object, DIR,
|
|
|
|
|
chroot_path=CHROOT_PATH,
|
|
|
|
|
config_archive_path=CONFIG_ARCHIVE_PATH)
|
|
|
|
|
template_executor._append_clear_directory(template_wrapper)
|
|
|
|
|
assert not os.path.exists(target_path)
|
|
|
|
|
|
|
|
|
|
def test_if_append_clear_directory_method_s_input_is_a_template_with_a_target_path_to_an_existing_directory_with_some_files_that_belongs_to_the_template_package__the_method_clears_directory_and_removes_all_its_files_from_a_package_CONTENTS_file(self):
|
|
|
|
|
pass
|
|
|
|
|
target_path = join_paths(CHROOT_PATH,
|
|
|
|
|
'/etc/append_clear_dir_testfiles/dir_3')
|
|
|
|
|
parameters_object = ParametersContainer({'package': test_package_name,
|
|
|
|
|
'append': 'clear'})
|
|
|
|
|
template_wrapper = TemplateWrapper(
|
|
|
|
|
target_path,
|
|
|
|
|
parameters_object, DIR,
|
|
|
|
|
chroot_path=CHROOT_PATH,
|
|
|
|
|
config_archive_path=CONFIG_ARCHIVE_PATH)
|
|
|
|
|
template_executor._append_clear_directory(template_wrapper)
|
|
|
|
|
assert not os.listdir(target_path)
|
|
|
|
|
assert '/etc/append_clear_dir_testfiles/dir_3/file_0'\
|
|
|
|
|
not in template_wrapper.target_package
|
|
|
|
|
assert '/etc/append_clear_dir_testfiles/dir_3/file_1'\
|
|
|
|
|
not in template_wrapper.target_package
|
|
|
|
|
assert '/etc/append_clear_dir_testfiles/dir_3/link'\
|
|
|
|
|
not in template_wrapper.target_package
|
|
|
|
|
|
|
|
|
|
def test_if_append_clear_directory_method_s_input_is_a_template_with_a_target_path_to_an_existing_directory_with_some_directories_with_files_that_belongs_to_the_template_package__the_method_clears_directory_and_removes_all_its_files_from_a_package_CONTENTS_file(self):
|
|
|
|
|
target_path = join_paths(
|
|
|
|
|
CHROOT_PATH,
|
|
|
|
|
'/etc/append_clear_dir_testfiles/dir_4')
|
|
|
|
|
parameters_object = ParametersContainer({'package': test_package_name,
|
|
|
|
|
'append': 'clear'})
|
|
|
|
|
template_wrapper = TemplateWrapper(
|
|
|
|
|
target_path,
|
|
|
|
|
parameters_object, DIR,
|
|
|
|
|
chroot_path=CHROOT_PATH,
|
|
|
|
|
config_archive_path=CONFIG_ARCHIVE_PATH)
|
|
|
|
|
template_executor._append_clear_directory(template_wrapper)
|
|
|
|
|
assert not os.listdir(target_path)
|
|
|
|
|
assert '/etc/append_clear_dir_testfiles/dir_4/subdir_0/file'\
|
|
|
|
|
not in template_wrapper.target_package
|
|
|
|
|
assert '/etc/append_clear_dir_testfiles/dir_4/subdir_0'\
|
|
|
|
|
not in template_wrapper.target_package
|
|
|
|
|
assert '/etc/append_clear_dir_testfiles/dir_4/subdir_1/file'\
|
|
|
|
|
not in template_wrapper.target_package
|
|
|
|
|
assert '/etc/append_clear_dir_testfiles/dir_4/subdir_1'\
|
|
|
|
|
not in template_wrapper.target_package
|
|
|
|
|
assert '/etc/append_clear_dir_testfiles/dir_4/link'\
|
|
|
|
|
not in template_wrapper.target_package
|
|
|
|
|
|
|
|
|
|
def test_if_append_clear_directory_method_s_input_is_a_template_with_a_target_path_to_an_existing_directory_that_belongs_to_the_template_package_and_chmod_and_chown_parameters_are_set__the_method_clears_directory_removes_all_its_files_from_a_package_CONTENTS_file_and_chmod_and_chown_one(self):
|
|
|
|
|
target_path = join_paths(CHROOT_PATH,
|
|
|
|
|
'/etc/append_clear_dir_testfiles/dir_5')
|
|
|
|
|
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, DIR,
|
|
|
|
|
chroot_path=CHROOT_PATH,
|
|
|
|
|
config_archive_path=CONFIG_ARCHIVE_PATH)
|
|
|
|
|
template_executor._append_clear_directory(template_wrapper)
|
|
|
|
|
assert not os.listdir(target_path)
|
|
|
|
|
assert template_executor._get_file_owner(target_path) == chown_value
|
|
|
|
|
assert template_executor._get_file_mode(target_path) == chmod_value
|
|
|
|
|
|
|
|
|
|
def test_if_append_replace_directory_method_s_input_is_a_template_with_a_target_path_to_an_unexisting_directory__the_method_creates_new_directory_and_add_it_to_a_package_CONTENTS_file(self):
|
|
|
|
|
target_path = join_paths(CHROOT_PATH,
|
|
|
|
|
'/etc/append_replace_dir_testfiles/dir_0')
|
|
|
|
|
parameters_object = ParametersContainer({'package': test_package_name,
|
|
|
|
|
'append': 'replace'})
|
|
|
|
|
template_wrapper = TemplateWrapper(
|
|
|
|
|
target_path,
|
|
|
|
|
parameters_object, DIR,
|
|
|
|
|
chroot_path=CHROOT_PATH,
|
|
|
|
|
config_archive_path=CONFIG_ARCHIVE_PATH)
|
|
|
|
|
template_executor._append_replace_directory(template_wrapper)
|
|
|
|
|
assert os.path.exists(target_path)
|
|
|
|
|
assert '/etc/append_replace_dir_testfiles/dir_0'\
|
|
|
|
|
in template_wrapper.target_package
|
|
|
|
|
|
|
|
|
|
def 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_adds_it_to_a_package_CONTENTS_file_and_chown_and_chmod_directory(self):
|
|
|
|
|
target_path = join_paths(CHROOT_PATH,
|
|
|
|
|
'/etc/append_replace_dir_testfiles/dir_1')
|
|
|
|
|
chown_value = {'uid': os.getuid(), 'gid': os.getgid()}
|
|
|
|
|
chmod_value = int(0o777)
|
|
|
|
|
|
|
|
|
|
parameters_object = ParametersContainer({'package': test_package_name,
|
|
|
|
|
'append': 'replace',
|
|
|
|
|
'chown': chown_value,
|
|
|
|
|
'chmod': chmod_value})
|
|
|
|
|
template_wrapper = TemplateWrapper(
|
|
|
|
|
target_path,
|
|
|
|
|
parameters_object, DIR,
|
|
|
|
|
chroot_path=CHROOT_PATH,
|
|
|
|
|
config_archive_path=CONFIG_ARCHIVE_PATH)
|
|
|
|
|
template_executor._append_replace_directory(template_wrapper)
|
|
|
|
|
assert os.path.exists(target_path)
|
|
|
|
|
assert '/etc/append_replace_dir_testfiles/dir_1'\
|
|
|
|
|
in template_wrapper.target_package
|
|
|
|
|
assert template_executor._get_file_owner(target_path) == chown_value
|
|
|
|
|
assert template_executor._get_file_mode(target_path) == chmod_value
|
|
|
|
|
|
|
|
|
|
def test_add_to_contents(self):
|
|
|
|
|
if False:
|
|
|
|
|
target_path = join_paths(
|
|
|
|
|
CHROOT_PATH,
|
|
|
|
|
'/etc/append_replace_dir_testfiles/dir_5')
|
|
|
|
|
parameters_object = ParametersContainer(
|
|
|
|
|
{'package': test_package_name,
|
|
|
|
|
'append': 'replace'})
|
|
|
|
|
template_wrapper = TemplateWrapper(
|
|
|
|
|
target_path,
|
|
|
|
|
parameters_object, DIR,
|
|
|
|
|
chroot_path=CHROOT_PATH,
|
|
|
|
|
config_archive_path=CONFIG_ARCHIVE_PATH)
|
|
|
|
|
template_wrapper.target_package.add_sym('/etc/append_replace_dir_testfiles/dir_5/link')
|
|
|
|
|
template_wrapper.save_changes()
|
|
|
|
|
assert True
|
|
|
|
|
|
|
|
|
|
def test_if_append_replace_directory_method_s_input_is_a_template_with_a_target_path_to_an_existing_empty_directory_that_belongs_to_the_template_package__the_method_does_nothing(self):
|
|
|
|
|
target_path = join_paths(
|
|
|
|
|
CHROOT_PATH,
|
|
|
|
|
'/etc/append_replace_dir_testfiles/dir_2')
|
|
|
|
|
parameters_object = ParametersContainer({'package': test_package_name,
|
|
|
|
|
'append': 'replace'})
|
|
|
|
|
template_wrapper = TemplateWrapper(
|
|
|
|
|
target_path,
|
|
|
|
|
parameters_object, DIR,
|
|
|
|
|
chroot_path=CHROOT_PATH,
|
|
|
|
|
config_archive_path=CONFIG_ARCHIVE_PATH)
|
|
|
|
|
template_executor._append_clear_directory(template_wrapper)
|
|
|
|
|
assert not os.listdir(target_path)
|
|
|
|
|
assert '/etc/append_replace_dir_testfiles/dir_2/file'\
|
|
|
|
|
not in template_wrapper.target_package
|
|
|
|
|
|
|
|
|
|
def test_if_append_replace_directory_method_s_input_is_a_template_with_a_target_path_to_an_existing_empty_directory_that_belongs_to_the_template_package_and_the_chown_and_chmod_parameters_are_set__the_method_just_chown_and_chmod_a_target_directory(self):
|
|
|
|
|
target_path = join_paths(
|
|
|
|
|
CHROOT_PATH,
|
|
|
|
|
'/etc/append_replace_dir_testfiles/dir_3')
|
|
|
|
|
chown_value = {'uid': os.getuid(), 'gid': os.getgid()}
|
|
|
|
|
chmod_value = int(0o777)
|
|
|
|
|
|
|
|
|
|
parameters_object = ParametersContainer({'package': test_package_name,
|
|
|
|
|
'append': 'replace',
|
|
|
|
|
'chown': chown_value,
|
|
|
|
|
'chmod': chmod_value})
|
|
|
|
|
template_wrapper = TemplateWrapper(
|
|
|
|
|
target_path,
|
|
|
|
|
parameters_object, DIR,
|
|
|
|
|
chroot_path=CHROOT_PATH,
|
|
|
|
|
config_archive_path=CONFIG_ARCHIVE_PATH)
|
|
|
|
|
template_executor._append_clear_directory(template_wrapper)
|
|
|
|
|
assert not os.listdir(target_path)
|
|
|
|
|
assert '/etc/append_replace_dir_testfiles/dir_3/file'\
|
|
|
|
|
not in template_wrapper.target_package
|
|
|
|
|
assert template_executor._get_file_owner(target_path) == chown_value
|
|
|
|
|
assert template_executor._get_file_mode(target_path) == chmod_value
|
|
|
|
|
|
|
|
|
|
def test_if_append_replace_directory_method_s_input_is_a_template_with_a_target_path_to_an_existing_directory_with_some_files_that_belongs_to_the_template_package__the_method_clears_directory_and_removes_all_its_files_from_a_package_CONTENTS_file(self):
|
|
|
|
|
target_path = join_paths(CHROOT_PATH,
|
|
|
|
|
'/etc/append_replace_dir_testfiles/dir_4')
|
|
|
|
|
parameters_object = ParametersContainer({'package': test_package_name,
|
|
|
|
|
'append': 'replace'})
|
|
|
|
|
template_wrapper = TemplateWrapper(
|
|
|
|
|
target_path,
|
|
|
|
|
parameters_object, DIR,
|
|
|
|
|
chroot_path=CHROOT_PATH,
|
|
|
|
|
config_archive_path=CONFIG_ARCHIVE_PATH)
|
|
|
|
|
template_executor._append_replace_directory(template_wrapper)
|
|
|
|
|
assert not os.listdir(target_path)
|
|
|
|
|
assert '/etc/append_replace_dir_testfiles/dir_4/file_0'\
|
|
|
|
|
not in template_wrapper.target_package
|
|
|
|
|
assert '/etc/append_replace_dir_testfiles/dir_4/file_1'\
|
|
|
|
|
not in template_wrapper.target_package
|
|
|
|
|
assert '/etc/append_replace_dir_testfiles/dir_4/link'\
|
|
|
|
|
not in template_wrapper.target_package
|
|
|
|
|
|
|
|
|
|
def test_if_append_replace_directory_method_s_input_is_a_template_with_a_target_path_to_an_existing_directory_with_some_directories_with_files_that_belongs_to_the_template_package__the_method_clears_directory_and_removes_all_its_files_from_a_package_CONTENTS_file(self):
|
|
|
|
|
target_path = join_paths(
|
|
|
|
|
CHROOT_PATH,
|
|
|
|
|
'/etc/append_replace_dir_testfiles/dir_5')
|
|
|
|
|
parameters_object = ParametersContainer({'package': test_package_name,
|
|
|
|
|
'append': 'replace'})
|
|
|
|
|
template_wrapper = TemplateWrapper(
|
|
|
|
|
target_path,
|
|
|
|
|
parameters_object, DIR,
|
|
|
|
|
chroot_path=CHROOT_PATH,
|
|
|
|
|
config_archive_path=CONFIG_ARCHIVE_PATH)
|
|
|
|
|
template_executor._append_replace_directory(template_wrapper)
|
|
|
|
|
assert not os.listdir(target_path)
|
|
|
|
|
assert '/etc/append_replace_dir_testfiles/dir_5/subdir_0/file'\
|
|
|
|
|
not in template_wrapper.target_package
|
|
|
|
|
assert '/etc/append_replace_dir_testfiles/dir_5/subdir_0'\
|
|
|
|
|
not in template_wrapper.target_package
|
|
|
|
|
assert '/etc/append_replace_dir_testfiles/dir_5/subdir_1/file'\
|
|
|
|
|
not in template_wrapper.target_package
|
|
|
|
|
assert '/etc/append_replace_dir_testfiles/dir_5/subdir_1'\
|
|
|
|
|
not in template_wrapper.target_package
|
|
|
|
|
assert '/etc/append_replace_dir_testfiles/dir_5/link'\
|
|
|
|
|
not in template_wrapper.target_package
|
|
|
|
|
|
|
|
|
|
def test_append_link_directory_method_s_input_is_a_template_with_a_target_path_and_a_source_path_to_the_existing_directory__the_method_creates_a_link_to_the_source_directory(self):
|
|
|
|
|
target_path = join_paths(
|
|
|
|
|
CHROOT_PATH,
|
|
|
|
|
'/etc/append_link_dir_testfiles/link_dir_0')
|
|
|
|
|
source_path = join_paths(
|
|
|
|
|
CHROOT_PATH,
|
|
|
|
|
'/etc/append_link_dir_testfiles/dir_0')
|
|
|
|
|
|
|
|
|
|
parameters_object = ParametersContainer({'package': test_package_name,
|
|
|
|
|
'append': 'link',
|
|
|
|
|
'source': source_path})
|
|
|
|
|
template_wrapper = TemplateWrapper(
|
|
|
|
|
target_path,
|
|
|
|
|
parameters_object, DIR,
|
|
|
|
|
chroot_path=CHROOT_PATH,
|
|
|
|
|
config_archive_path=CONFIG_ARCHIVE_PATH)
|
|
|
|
|
template_executor._append_link_directory(template_wrapper)
|
|
|
|
|
assert os.path.exists(target_path)
|
|
|
|
|
assert os.path.islink(target_path)
|
|
|
|
|
assert os.readlink(target_path) == source_path
|
|
|
|
|
|
|
|
|
|
def test_append_link_directory_method_s_input_is_a_template_with_a_target_path_and_a_source_path_to_the_existing_directory_and_the_chown_and_chmod_parameters_are_set__the_method_creates_a_link_to_the_source_directory(self):
|
|
|
|
|
target_path = join_paths(
|
|
|
|
|
CHROOT_PATH,
|
|
|
|
|
'/etc/append_link_dir_testfiles/link_dir_1')
|
|
|
|
|
source_path = join_paths(
|
|
|
|
|
CHROOT_PATH,
|
|
|
|
|
'/etc/append_link_dir_testfiles/dir_1')
|
|
|
|
|
|
|
|
|
|
chown_value = {'uid': os.getuid(), 'gid': os.getgid()}
|
|
|
|
|
chmod_value = int(0o777)
|
|
|
|
|
|
|
|
|
|
parameters_object = ParametersContainer({'package': test_package_name,
|
|
|
|
|
'append': 'link',
|
|
|
|
|
'source': source_path,
|
|
|
|
|
'chown': chown_value,
|
|
|
|
|
'chmod': chmod_value})
|
|
|
|
|
template_wrapper = TemplateWrapper(
|
|
|
|
|
target_path,
|
|
|
|
|
parameters_object, DIR,
|
|
|
|
|
chroot_path=CHROOT_PATH,
|
|
|
|
|
config_archive_path=CONFIG_ARCHIVE_PATH)
|
|
|
|
|
template_executor._append_link_directory(template_wrapper)
|
|
|
|
|
assert os.path.exists(target_path)
|
|
|
|
|
assert os.path.islink(target_path)
|
|
|
|
|
assert os.readlink(target_path) == source_path
|
|
|
|
|
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'))
|
|
|
|
|