|
|
|
@ -5,14 +5,10 @@ import hashlib
|
|
|
|
|
from pprint import pprint
|
|
|
|
|
from calculate.templates.template_processor import DirectoryProcessor,\
|
|
|
|
|
TemplateWrapper
|
|
|
|
|
from calculate.utils.package import PackageAtomName, Version, Package,\
|
|
|
|
|
PackageAtomParser
|
|
|
|
|
from calculate.utils.package import PackageAtomName, Version, Package
|
|
|
|
|
from calculate.utils.files import join_paths
|
|
|
|
|
from calculate.utils.io_module import IOModule
|
|
|
|
|
from calculate.templates.template_engine import Variables
|
|
|
|
|
from collections import OrderedDict
|
|
|
|
|
from calculate.variables.datavars import Namespace, Variable, TableType,\
|
|
|
|
|
StringType, ListType
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
CHROOT_PATH = os.path.join(os.getcwd(),
|
|
|
|
@ -23,12 +19,18 @@ CONFIG_ARCHIVE_PATH = os.path.join(CHROOT_PATH,
|
|
|
|
|
EXECUTE_ARCHIVE_PATH = os.path.join(CHROOT_PATH,
|
|
|
|
|
'var/lib/calculate/.execute')
|
|
|
|
|
|
|
|
|
|
test_package_name = PackageAtomName(
|
|
|
|
|
test_package_name_1 = PackageAtomName(
|
|
|
|
|
{'pkg_path': os.path.join(
|
|
|
|
|
CHROOT_PATH,
|
|
|
|
|
'var/db/pkg/test-category/test-package-1.0'),
|
|
|
|
|
'version': Version('1.0')})
|
|
|
|
|
|
|
|
|
|
test_package_name_0 = PackageAtomName(
|
|
|
|
|
{'pkg_path': os.path.join(
|
|
|
|
|
CHROOT_PATH,
|
|
|
|
|
'var/db/pkg/test-category/test-package-0.9.6-r1'),
|
|
|
|
|
'version': Version('0.9.6-r1')})
|
|
|
|
|
|
|
|
|
|
other_package_name = PackageAtomName(
|
|
|
|
|
{'pkg_path': os.path.join(
|
|
|
|
|
CHROOT_PATH,
|
|
|
|
@ -136,7 +138,7 @@ class TestDirectoryProcessor:
|
|
|
|
|
+ ";\n};\n"))
|
|
|
|
|
|
|
|
|
|
assert os.path.exists(join_paths(CHROOT_PATH, '/etc/file_0'))
|
|
|
|
|
test_package = Package(test_package_name, chroot_path=CHROOT_PATH)
|
|
|
|
|
test_package = Package(test_package_name_1, chroot_path=CHROOT_PATH)
|
|
|
|
|
assert '/etc/file_0' in test_package
|
|
|
|
|
with open(join_paths(CHROOT_PATH, '/etc/file_0'), 'r') as output_file:
|
|
|
|
|
output_file_text = output_file.read()
|
|
|
|
@ -189,7 +191,7 @@ class TestDirectoryProcessor:
|
|
|
|
|
|
|
|
|
|
assert os.path.exists(join_paths(CHROOT_PATH, '/etc/dir_2'))
|
|
|
|
|
assert os.path.exists(join_paths(CHROOT_PATH, '/etc/dir_2/file_0'))
|
|
|
|
|
test_package = Package(test_package_name, chroot_path=CHROOT_PATH)
|
|
|
|
|
test_package = Package(test_package_name_1, chroot_path=CHROOT_PATH)
|
|
|
|
|
assert '/etc/dir_2' in test_package
|
|
|
|
|
assert '/etc/dir_2/file_0' in test_package
|
|
|
|
|
with open(join_paths(CHROOT_PATH,
|
|
|
|
@ -232,7 +234,7 @@ class TestDirectoryProcessor:
|
|
|
|
|
|
|
|
|
|
assert os.path.exists(join_paths(CHROOT_PATH, '/etc/dir_4'))
|
|
|
|
|
assert os.path.exists(join_paths(CHROOT_PATH, '/etc/dir_4/file_0'))
|
|
|
|
|
test_package = Package(test_package_name, chroot_path=CHROOT_PATH)
|
|
|
|
|
test_package = Package(test_package_name_1, chroot_path=CHROOT_PATH)
|
|
|
|
|
assert '/etc/dir_4' in test_package
|
|
|
|
|
assert '/etc/dir_4/file_0' in test_package
|
|
|
|
|
with open(join_paths(CHROOT_PATH,
|
|
|
|
@ -245,7 +247,7 @@ class TestDirectoryProcessor:
|
|
|
|
|
assert os.path.exists(join_paths(CHROOT_PATH, '/etc/dir_5/dir_6'))
|
|
|
|
|
assert os.path.exists(join_paths(CHROOT_PATH,
|
|
|
|
|
'/etc/dir_5/dir_6/file_0'))
|
|
|
|
|
test_package = Package(test_package_name, chroot_path=CHROOT_PATH)
|
|
|
|
|
test_package = Package(test_package_name_1, chroot_path=CHROOT_PATH)
|
|
|
|
|
assert '/etc/dir_5' in test_package
|
|
|
|
|
assert '/etc/dir_5/dir_6' in test_package
|
|
|
|
|
assert '/etc/dir_5/dir_6/file_0' in test_package
|
|
|
|
@ -531,7 +533,7 @@ class TestDirectoryProcessor:
|
|
|
|
|
datavars_module=datavars)
|
|
|
|
|
directory_processor.process_template_directories()
|
|
|
|
|
|
|
|
|
|
test_package = Package(test_package_name, chroot_path=CHROOT_PATH)
|
|
|
|
|
test_package = Package(test_package_name_1, chroot_path=CHROOT_PATH)
|
|
|
|
|
other_package = Package(other_package_name, chroot_path=CHROOT_PATH)
|
|
|
|
|
|
|
|
|
|
assert os.path.exists(join_paths(CHROOT_PATH, '/etc/dir_9'))
|
|
|
|
@ -586,7 +588,7 @@ class TestDirectoryProcessor:
|
|
|
|
|
package=other_package_name)
|
|
|
|
|
directory_processor.process_template_directories()
|
|
|
|
|
|
|
|
|
|
test_package = Package(test_package_name, chroot_path=CHROOT_PATH)
|
|
|
|
|
test_package = Package(test_package_name_1, chroot_path=CHROOT_PATH)
|
|
|
|
|
other_package = Package(other_package_name, chroot_path=CHROOT_PATH)
|
|
|
|
|
|
|
|
|
|
assert os.path.exists(join_paths(CHROOT_PATH, '/etc/dir_13'))
|
|
|
|
@ -606,7 +608,7 @@ class TestDirectoryProcessor:
|
|
|
|
|
package=other_package_name)
|
|
|
|
|
directory_processor.process_template_directories()
|
|
|
|
|
|
|
|
|
|
test_package = Package(test_package_name, chroot_path=CHROOT_PATH)
|
|
|
|
|
test_package = Package(test_package_name_1, chroot_path=CHROOT_PATH)
|
|
|
|
|
other_package = Package(other_package_name, chroot_path=CHROOT_PATH)
|
|
|
|
|
|
|
|
|
|
assert os.path.exists(join_paths(CHROOT_PATH, '/etc/dir_15'))
|
|
|
|
@ -624,7 +626,7 @@ class TestDirectoryProcessor:
|
|
|
|
|
directory_processor = DirectoryProcessor('install',
|
|
|
|
|
datavars_module=datavars)
|
|
|
|
|
directory_processor.process_template_directories()
|
|
|
|
|
test_package = Package(test_package_name, chroot_path=CHROOT_PATH)
|
|
|
|
|
test_package = Package(test_package_name_1, chroot_path=CHROOT_PATH)
|
|
|
|
|
|
|
|
|
|
# Для разнообразия один из шаблонов удаляет файл, а не создает.
|
|
|
|
|
assert not os.path.exists(join_paths(CHROOT_PATH,
|
|
|
|
@ -643,7 +645,7 @@ class TestDirectoryProcessor:
|
|
|
|
|
directory_processor = DirectoryProcessor('install',
|
|
|
|
|
datavars_module=datavars)
|
|
|
|
|
directory_processor.process_template_directories()
|
|
|
|
|
test_package = Package(test_package_name, chroot_path=CHROOT_PATH)
|
|
|
|
|
test_package = Package(test_package_name_1, chroot_path=CHROOT_PATH)
|
|
|
|
|
|
|
|
|
|
# Для разнообразия один из шаблонов удаляет файл, а не создает.
|
|
|
|
|
# Но в данном случае он ничего не сделает.
|
|
|
|
@ -668,7 +670,7 @@ class TestDirectoryProcessor:
|
|
|
|
|
package=other_package_name)
|
|
|
|
|
directory_processor.process_template_directories()
|
|
|
|
|
|
|
|
|
|
test_package = Package(test_package_name, chroot_path=CHROOT_PATH)
|
|
|
|
|
test_package = Package(test_package_name_1, chroot_path=CHROOT_PATH)
|
|
|
|
|
other_package = Package(other_package_name, chroot_path=CHROOT_PATH)
|
|
|
|
|
new_package = Package(new_package_name, chroot_path=CHROOT_PATH)
|
|
|
|
|
|
|
|
|
@ -695,7 +697,7 @@ class TestDirectoryProcessor:
|
|
|
|
|
package='test-category/other-package')
|
|
|
|
|
directory_processor.process_template_directories()
|
|
|
|
|
|
|
|
|
|
test_package = Package(test_package_name, chroot_path=CHROOT_PATH)
|
|
|
|
|
test_package = Package(test_package_name_1, chroot_path=CHROOT_PATH)
|
|
|
|
|
other_package = Package(other_package_name, chroot_path=CHROOT_PATH)
|
|
|
|
|
new_package = Package(new_package_name, chroot_path=CHROOT_PATH)
|
|
|
|
|
|
|
|
|
@ -728,7 +730,7 @@ class TestDirectoryProcessor:
|
|
|
|
|
package='test-category/other-package')
|
|
|
|
|
directory_processor.process_template_directories()
|
|
|
|
|
|
|
|
|
|
test_package = Package(test_package_name, chroot_path=CHROOT_PATH)
|
|
|
|
|
test_package = Package(test_package_name_1, chroot_path=CHROOT_PATH)
|
|
|
|
|
other_package = Package(other_package_name, chroot_path=CHROOT_PATH)
|
|
|
|
|
|
|
|
|
|
print('DIRECTORY TREE:')
|
|
|
|
@ -756,7 +758,7 @@ class TestDirectoryProcessor:
|
|
|
|
|
datavars_module=datavars)
|
|
|
|
|
directory_processor.process_template_directories()
|
|
|
|
|
|
|
|
|
|
test_package = Package(test_package_name, chroot_path=CHROOT_PATH)
|
|
|
|
|
test_package = Package(test_package_name_1, chroot_path=CHROOT_PATH)
|
|
|
|
|
assert os.path.exists(join_paths(CHROOT_PATH, '/etc/file_10'))
|
|
|
|
|
assert '/etc/file_10' in test_package
|
|
|
|
|
|
|
|
|
@ -767,7 +769,7 @@ class TestDirectoryProcessor:
|
|
|
|
|
datavars_module=datavars)
|
|
|
|
|
directory_processor.process_template_directories()
|
|
|
|
|
|
|
|
|
|
test_package = Package(test_package_name, chroot_path=CHROOT_PATH)
|
|
|
|
|
test_package = Package(test_package_name_1, chroot_path=CHROOT_PATH)
|
|
|
|
|
assert not os.path.exists(join_paths(CHROOT_PATH, '/etc/file_11'))
|
|
|
|
|
assert '/etc/file_11' not in test_package
|
|
|
|
|
|
|
|
|
@ -778,7 +780,7 @@ class TestDirectoryProcessor:
|
|
|
|
|
datavars_module=datavars)
|
|
|
|
|
directory_processor.process_template_directories()
|
|
|
|
|
|
|
|
|
|
test_package = Package(test_package_name, chroot_path=CHROOT_PATH)
|
|
|
|
|
test_package = Package(test_package_name_1, chroot_path=CHROOT_PATH)
|
|
|
|
|
|
|
|
|
|
assert os.path.exists(join_paths(CHROOT_PATH, '/etc/dir_29'))
|
|
|
|
|
assert os.path.exists(join_paths(CHROOT_PATH, '/etc/dir_29/file_0'))
|
|
|
|
@ -793,7 +795,7 @@ class TestDirectoryProcessor:
|
|
|
|
|
datavars_module=datavars)
|
|
|
|
|
directory_processor.process_template_directories()
|
|
|
|
|
|
|
|
|
|
test_package = Package(test_package_name, chroot_path=CHROOT_PATH)
|
|
|
|
|
test_package = Package(test_package_name_1, chroot_path=CHROOT_PATH)
|
|
|
|
|
|
|
|
|
|
assert not os.path.exists(join_paths(CHROOT_PATH,
|
|
|
|
|
'/etc/dir_30'))
|
|
|
|
@ -871,7 +873,7 @@ class TestDirectoryProcessor:
|
|
|
|
|
directory_processor = DirectoryProcessor(['install', 'update'],
|
|
|
|
|
datavars_module=datavars)
|
|
|
|
|
directory_processor.process_template_directories()
|
|
|
|
|
test_package = Package(test_package_name, chroot_path=CHROOT_PATH)
|
|
|
|
|
test_package = Package(test_package_name_1, chroot_path=CHROOT_PATH)
|
|
|
|
|
|
|
|
|
|
assert os.path.exists(join_paths(CHROOT_PATH,
|
|
|
|
|
'etc/dir_32'))
|
|
|
|
@ -891,7 +893,7 @@ class TestDirectoryProcessor:
|
|
|
|
|
directory_processor = DirectoryProcessor(['install', 'update'],
|
|
|
|
|
datavars_module=datavars)
|
|
|
|
|
directory_processor.process_template_directories()
|
|
|
|
|
test_package = Package(test_package_name, chroot_path=CHROOT_PATH)
|
|
|
|
|
test_package = Package(test_package_name_1, chroot_path=CHROOT_PATH)
|
|
|
|
|
|
|
|
|
|
assert os.path.exists(join_paths(CHROOT_PATH,
|
|
|
|
|
'etc/dir_35'))
|
|
|
|
@ -909,7 +911,7 @@ class TestDirectoryProcessor:
|
|
|
|
|
package='test-category/test-package'
|
|
|
|
|
)
|
|
|
|
|
directory_processor.process_template_directories()
|
|
|
|
|
test_package = Package(test_package_name, chroot_path=CHROOT_PATH)
|
|
|
|
|
test_package = Package(test_package_name_1, chroot_path=CHROOT_PATH)
|
|
|
|
|
|
|
|
|
|
# Тестируем handler_0 -- это просто обработчик-скрипт.
|
|
|
|
|
assert os.path.exists(join_paths(CHROOT_PATH,
|
|
|
|
@ -1054,6 +1056,101 @@ class TestDirectoryProcessor:
|
|
|
|
|
assert os.path.exists(join_paths(CHROOT_PATH, '/etc/dir_56'))
|
|
|
|
|
assert os.path.exists(join_paths(CHROOT_PATH, '/etc/dir_56/file_0'))
|
|
|
|
|
|
|
|
|
|
def test_solving_collisions_for_the_same_packages_from_different_slots(self):
|
|
|
|
|
datavars.main['cl_template_path'] = os.path.join(CHROOT_PATH,
|
|
|
|
|
'templates_39')
|
|
|
|
|
directory_processor = DirectoryProcessor(
|
|
|
|
|
'install',
|
|
|
|
|
datavars_module=datavars,
|
|
|
|
|
package='test-category/test-package'
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
header = ('#' + '-' * 79 + '\n' +
|
|
|
|
|
'# Modified by Calculate Utilities 4.0\n' +
|
|
|
|
|
'# Processed template files:\n' +
|
|
|
|
|
'# ' + '{0}' + '\n' +
|
|
|
|
|
'#' + '-' * 79 + '\n')
|
|
|
|
|
|
|
|
|
|
header = header.format('\n# '.
|
|
|
|
|
join([join_paths(
|
|
|
|
|
CHROOT_PATH,
|
|
|
|
|
'templates_39/install/dir_57/file_0')]))
|
|
|
|
|
output_text = '{0}{1}'.format(header,
|
|
|
|
|
("options {\n parameter-0 yes;"
|
|
|
|
|
+ "\n parameter-1 "
|
|
|
|
|
+ datavars.ns.variable_1
|
|
|
|
|
+ ";\n parameter-2 "
|
|
|
|
|
+ datavars.ns.variable_2
|
|
|
|
|
+ ";\n};\n"))
|
|
|
|
|
|
|
|
|
|
directory_processor.process_template_directories()
|
|
|
|
|
test_package_0 = Package(test_package_name_0, chroot_path=CHROOT_PATH)
|
|
|
|
|
test_package_1 = Package(test_package_name_1, chroot_path=CHROOT_PATH)
|
|
|
|
|
|
|
|
|
|
assert os.path.exists(join_paths(CHROOT_PATH, '/etc/dir_57'))
|
|
|
|
|
assert os.path.exists(join_paths(CHROOT_PATH, '/etc/dir_57/file_0'))
|
|
|
|
|
with open(join_paths(CHROOT_PATH,
|
|
|
|
|
'/etc/dir_57/file_0'), 'r') as output:
|
|
|
|
|
output = output.read()
|
|
|
|
|
assert output_text == output
|
|
|
|
|
assert '/etc/dir_57' in test_package_1
|
|
|
|
|
assert '/etc/dir_57/file_0' in test_package_1
|
|
|
|
|
assert '/etc/dir_57/file_0' not in test_package_0
|
|
|
|
|
|
|
|
|
|
def test_solving_collisions_for_the_same_packages_from_different_slots_but_slot_was_set_in_the_package_parameter(self):
|
|
|
|
|
datavars.main['cl_template_path'] = os.path.join(CHROOT_PATH,
|
|
|
|
|
'templates_40')
|
|
|
|
|
directory_processor = DirectoryProcessor(
|
|
|
|
|
'install',
|
|
|
|
|
datavars_module=datavars)
|
|
|
|
|
|
|
|
|
|
output_text = "options {\n parameter-0 yes;\n};\n"
|
|
|
|
|
|
|
|
|
|
directory_processor.process_template_directories()
|
|
|
|
|
test_package_0 = Package(test_package_name_0, chroot_path=CHROOT_PATH)
|
|
|
|
|
test_package_1 = Package(test_package_name_1, chroot_path=CHROOT_PATH)
|
|
|
|
|
|
|
|
|
|
assert os.path.exists(join_paths(CHROOT_PATH, '/etc/dir_58'))
|
|
|
|
|
assert os.path.exists(join_paths(CHROOT_PATH, '/etc/dir_58/file_0'))
|
|
|
|
|
with open(join_paths(CHROOT_PATH,
|
|
|
|
|
'/etc/dir_58/file_0'), 'r') as output:
|
|
|
|
|
output = output.read()
|
|
|
|
|
assert output_text == output
|
|
|
|
|
|
|
|
|
|
assert '/etc/dir_58' not in test_package_1
|
|
|
|
|
assert '/etc/dir_58/file_0' not in test_package_1
|
|
|
|
|
|
|
|
|
|
assert '/etc/dir_58' in test_package_0
|
|
|
|
|
assert '/etc/dir_58/file_0' in test_package_0
|
|
|
|
|
|
|
|
|
|
def test_solving_collisions_for_the_same_packages_from_different_slots_but_slot_was_set_in_the_for_package_parameter(self):
|
|
|
|
|
datavars.main['cl_template_path'] = os.path.join(CHROOT_PATH,
|
|
|
|
|
'templates_41')
|
|
|
|
|
directory_processor = DirectoryProcessor(
|
|
|
|
|
'install',
|
|
|
|
|
datavars_module=datavars,
|
|
|
|
|
package='test-category/test-package:1'
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
output_text = "options {\n parameter-0 yes;\n};\n"
|
|
|
|
|
|
|
|
|
|
directory_processor.process_template_directories()
|
|
|
|
|
test_package_0 = Package(test_package_name_0, chroot_path=CHROOT_PATH)
|
|
|
|
|
test_package_1 = Package(test_package_name_1, chroot_path=CHROOT_PATH)
|
|
|
|
|
|
|
|
|
|
assert os.path.exists(join_paths(CHROOT_PATH, '/etc/dir_59'))
|
|
|
|
|
assert os.path.exists(join_paths(CHROOT_PATH, '/etc/dir_59/file_0'))
|
|
|
|
|
with open(join_paths(CHROOT_PATH,
|
|
|
|
|
'/etc/dir_59/file_0'), 'r') as output:
|
|
|
|
|
output = output.read()
|
|
|
|
|
assert output_text == output
|
|
|
|
|
|
|
|
|
|
assert '/etc/dir_59' not in test_package_1
|
|
|
|
|
assert '/etc/dir_59/file_0' not in test_package_1
|
|
|
|
|
|
|
|
|
|
assert '/etc/dir_59' in test_package_0
|
|
|
|
|
assert '/etc/dir_59/file_0' in test_package_0
|
|
|
|
|
|
|
|
|
|
def test_view_tree(self):
|
|
|
|
|
list_path = join_paths(CHROOT_PATH, '/etc')
|
|
|
|
|
show_tree(list_path)
|
|
|
|
|