|
|
import os
|
|
|
import shutil
|
|
|
from calculate.utils.files import join_paths
|
|
|
from calculate.templates.template_engine import Variables
|
|
|
from calculate.utils.package import PackageAtomName, Version, Package
|
|
|
from calculate.templates.template_processor import DirectoryProcessor,\
|
|
|
TemplateWrapper
|
|
|
|
|
|
|
|
|
CHROOT_PATH = os.path.join(os.getcwd(),
|
|
|
'tests/templates/testfiles/test_dir_processor_root')
|
|
|
CONFIG_PATH = os.path.join(CHROOT_PATH, 'var/lib/calculate/config')
|
|
|
CONFIG_ARCHIVE_PATH = os.path.join(CHROOT_PATH,
|
|
|
'var/lib/calculate/config-archive')
|
|
|
EXECUTE_ARCHIVE_PATH = os.path.join(CHROOT_PATH,
|
|
|
'var/lib/calculate/.execute')
|
|
|
|
|
|
test_package_name = PackageAtomName(
|
|
|
{'pkg_path': os.path.join(
|
|
|
CHROOT_PATH,
|
|
|
'var/db/pkg/test-category/test-package-1.0'),
|
|
|
'version': Version('1.0')})
|
|
|
|
|
|
other_package_name = PackageAtomName(
|
|
|
{'pkg_path': os.path.join(
|
|
|
CHROOT_PATH,
|
|
|
'var/db/pkg/test-category/other-package-1.1'),
|
|
|
'version': Version('1.1')})
|
|
|
|
|
|
new_package_name = PackageAtomName(
|
|
|
{'pkg_path': os.path.join(
|
|
|
CHROOT_PATH,
|
|
|
'var/db/pkg/test-category/new-package-0.1.1'),
|
|
|
'version': Version('1.0')})
|
|
|
|
|
|
# Вместо модуля переменных.
|
|
|
group = Variables({'bool': True,
|
|
|
'list': [1, 2, 3]})
|
|
|
|
|
|
variables = Variables({'variable_1': 'value_1',
|
|
|
'variable_2': 'value_2',
|
|
|
'group': group})
|
|
|
|
|
|
install = Variables({'os_disk_dev': 'os_disk_dev_value',
|
|
|
'version': 1.5,
|
|
|
'number': 128,
|
|
|
'boolean': False,
|
|
|
'type': 'static',
|
|
|
'path': '/usr/sbin'})
|
|
|
|
|
|
merge = Variables({'var_1': 674,
|
|
|
'var_2': 48,
|
|
|
'version': 1.0,
|
|
|
'calculate_domains': 'lists.calculate-linux.org',
|
|
|
'ip_value': '127.0.0.0/8'})
|
|
|
|
|
|
main = Variables({'cl_template_path':
|
|
|
'{0},{1}'.format(os.path.join(CHROOT_PATH,
|
|
|
'templates'),
|
|
|
os.path.join(CHROOT_PATH,
|
|
|
'var/calculate/templates')),
|
|
|
'cl_chroot_path': CHROOT_PATH,
|
|
|
'cl_config_path': CONFIG_PATH,
|
|
|
'cl_config_archive': CONFIG_ARCHIVE_PATH,
|
|
|
'cl_exec_dir_path': EXECUTE_ARCHIVE_PATH,
|
|
|
'cl_ignore_files': '*.swp'})
|
|
|
|
|
|
test = ({'test_root': CHROOT_PATH})
|
|
|
|
|
|
datavars = Variables({'install': install,
|
|
|
'merge': merge,
|
|
|
'variables': variables,
|
|
|
'main': main,
|
|
|
'test': test,
|
|
|
'custom': Variables()})
|
|
|
|
|
|
|
|
|
TemplateWrapper._protected_is_set = False
|
|
|
|
|
|
shutil.copytree(os.path.join(CHROOT_PATH, 'etc.backup'),
|
|
|
os.path.join(CHROOT_PATH, 'etc'),
|
|
|
symlinks=True)
|
|
|
shutil.copytree(os.path.join(CHROOT_PATH, 'var.backup'),
|
|
|
os.path.join(CHROOT_PATH, 'var'),
|
|
|
symlinks=True)
|
|
|
|
|
|
|
|
|
datavars.main['cl_template_path'] = os.path.join(CHROOT_PATH,
|
|
|
'templates_20')
|
|
|
directory_processor = DirectoryProcessor('install',
|
|
|
datavars_module=datavars)
|
|
|
directory_processor.process_template_directories()
|
|
|
test_package = Package(test_package_name, chroot_path=CHROOT_PATH)
|
|
|
|
|
|
# Для разнообразия один из шаблонов удаляет файл, а не создает.
|
|
|
# Но в данном случае он ничего не сделает.
|
|
|
assert os.path.exists(join_paths(CHROOT_PATH,
|
|
|
'/etc/dir_20/file_0'))
|
|
|
assert '/etc/dir_20/file_0' not in test_package
|
|
|
|
|
|
assert not os.path.islink(join_paths(CHROOT_PATH, '/etc/dir_19'))
|
|
|
assert os.path.isdir(join_paths(CHROOT_PATH, '/etc/dir_19'))
|
|
|
|
|
|
assert os.path.exists(join_paths(CHROOT_PATH,
|
|
|
'/etc/dir_19/dir_0'))
|
|
|
assert os.path.exists(join_paths(CHROOT_PATH,
|
|
|
'/etc/dir_19/dir_0/file_0'))
|
|
|
assert '/etc/dir_19/dir_0/file_0' in test_package
|
|
|
|
|
|
shutil.rmtree(os.path.join(CHROOT_PATH, 'etc'))
|
|
|
shutil.rmtree(os.path.join(CHROOT_PATH, 'var'))
|