Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RHELPLAN-59755 - Collection - script - not include symlinks in the collection converted format #32

Merged
merged 1 commit into from
Nov 18, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 15 additions & 26 deletions lsr_role2collection.py
Original file line number Diff line number Diff line change
Expand Up @@ -591,7 +591,7 @@ def copy_tree_with_replace(
lsr_copytree(
src,
dest,
ignore=ignore_patterns(ignoreme),
ignore=ignore_patterns(*ignoreme),
symlinks=symlinks,
dirs_exist_ok=True,
)
Expand All @@ -603,23 +603,11 @@ def copy_tree_with_replace(
lsrxfrm.run()


def cleanup_symlinks(path, role):
def cleanup_roles_dir(path):
"""
Clean up symlinks in tests/roles
- Remove symlinks.
- If linux-system-roles.rolename is an empty dir, rmdir it.
"""
if path.exists():
nodes = sorted(list(path.rglob("*")), reverse=True)
for node in nodes:
if node.is_symlink() and r"linux-system-roles." + role == node.name:
node.unlink()
elif (
node.is_dir()
and r"linux-system-roles." + role == node.name
and not any(node.iterdir())
):
node.rmdir()
roles_dir = path / "roles"
if roles_dir.exists() and not any(roles_dir.iterdir()):
roles_dir.rmdir()
Expand Down Expand Up @@ -1022,12 +1010,12 @@ def role2collection():
TESTS,
transformer_args,
isrole=False,
ignoreme="artifacts",
symlinks=True,
ignoreme=["artifacts", "linux-system-roles.*", "__pycache__"],
symlinks=False,
)

# remove symlinks in the tests/role, then updating the rolename to the collection format
cleanup_symlinks(tests_dir / role, role)
# remove "roles" directory if empty.
cleanup_roles_dir(tests_dir / role)

# ==============================================================================

Expand Down Expand Up @@ -1107,6 +1095,7 @@ def process_readme(src_path, filename, rolename, original=None, issubrole=False)
comment = "## Supported Linux System Roles"
update_readme(src_path, filename, rolename, comment, issubrole)

ignoreme = ["linux-system-roles.*"]
dest = docs_dir / role
for doc in DOCS:
src = src_path / doc
Expand All @@ -1116,7 +1105,7 @@ def process_readme(src_path, filename, rolename, original=None, issubrole=False)
src,
dest,
symlinks=False,
ignore=ignore_patterns("roles"),
ignore=ignore_patterns(*ignoreme),
dirs_exist_ok=True,
)
if doc == "examples":
Expand All @@ -1131,9 +1120,8 @@ def process_readme(src_path, filename, rolename, original=None, issubrole=False)
elif src.is_file():
process_readme(src_path, doc, role)

# Remove symlinks in the docs/role (e.g., in the examples).
# Update the rolename to the collection format as done in the tests.
cleanup_symlinks(dest, role)
# remove "roles" directory if empty.
cleanup_roles_dir(dest)

# ==============================================================================

Expand Down Expand Up @@ -1226,10 +1214,11 @@ def process_readme(src_path, filename, rolename, original=None, issubrole=False)
TESTS,
transformer_args,
isrole=False,
ignoreme="artifacts",
ignoreme=["artifacts", "linux-system-roles.*", "__pycache__"],
symlinks=False,
)
# remove symlinks in the tests/role, then updating the rolename to the collection format
cleanup_symlinks(tests_dir / dr, dr)
# remove "roles" directory if empty.
cleanup_roles_dir(tests_dir / dr)
# copy README.md to dest_path/roles/sr.name
readme = sr / "README.md"
if readme.is_file():
Expand All @@ -1252,7 +1241,7 @@ def process_readme(src_path, filename, rolename, original=None, issubrole=False)
else:
dest = dest_path / extra.name
logging.info(f"Copying extra {extra} to {dest}")
copytree(extra, dest)
lsr_copytree(extra, dest)
# Other extra files.
else:
if extra.name.endswith(".yml") and "playbook" in extra.name:
Expand Down
52 changes: 0 additions & 52 deletions tests/unit/test_lsr_role2collection.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
from lsr_role2collection import (
file_replace,
copy_tree_with_replace,
cleanup_symlinks,
import_replace,
from_replace,
gather_module_utils_parts,
Expand Down Expand Up @@ -277,57 +276,6 @@ def test_copy_tree_with_replace(self):
)
shutil.rmtree(coll_path)

def test_cleanup_symlinks(self):
"""test cleanup_symlinks"""
owner = "linux-system-roles"
params = [
{
"key": "roles",
"subkey": "-",
"value": owner,
"delim": ".",
"subvalue": rolename,
},
]
tmpdir = tempfile.TemporaryDirectory()
coll_path = (
Path(tmpdir.name) / "ansible_collections" / namespace / collection_name
)
role_path = coll_path / "roles" / rolename
self.create_test_tree(
role_path / "tasks", test_yaml_str, params, ".yml", is_vertical=False
)
test_path = coll_path / "tests" / rolename
self.create_test_tree(
test_path, test_yaml_str, params, ".yml", is_vertical=False
)
link = owner + "." + rolename
test_role_path = test_path / "roles"
# case 1. tests/roles/owner.systemrole -> roles/systemrole
self.create_test_link(test_role_path, link, role_path, True)
cleanup_symlinks(test_path, rolename)
self.check_test_link(test_role_path, False)
# case 2. tests/roles/owner.systemrole -> roles/systemrole
# tests/roles/some_file
self.create_test_link(test_role_path, link, role_path, True)
self.create_test_tree(
test_role_path, test_yaml_str, params, ".yml", is_vertical=False
)
cleanup_symlinks(test_path, rolename)
self.check_test_link(test_role_path, True)
self.check_test_link(test_role_path / link, False)
shutil.rmtree(test_role_path)
# case 3. tests/roles/owner.systemrole -> roles/systemrole
# tests/roles/some_symlinks
self.create_test_link(test_role_path, link, role_path, True)
extralink = "extralink"
self.create_test_link(test_role_path, extralink, role_path, True)
cleanup_symlinks(test_path, rolename)
self.check_test_link(test_role_path, True)
self.check_test_link(test_role_path / link, False)
self.check_test_link(test_role_path / extralink, True)
shutil.rmtree(test_role_path)

def test_import_replace(self):
module_names = ["util0", "util1"]
src_module_utils = []
Expand Down