Corrected bug where role_path was wrong for roles in subdirectories

Fixed role name for
    - { role: 'lives/in/a/subdirectory' }
Should be 'lives/in/a/subdirectory', not just 'subdirectory'
pull/6637/merge
Will Thames 10 years ago committed by Michael DeHaan
parent bf9ea81c4b
commit 6e9abefc11

@ -353,6 +353,8 @@ def path_dwim_relative(original, dirname, source, playbook_base, check=True):
return source2 # which does not exist return source2 # which does not exist
def repo_url_to_role_name(repo_url): def repo_url_to_role_name(repo_url):
if '://' not in repo_url:
return repo_url
trailing_path = repo_url.split('/')[-1] trailing_path = repo_url.split('/')[-1]
if trailing_path.endswith('.git'): if trailing_path.endswith('.git'):
trailing_path = trailing_path[:-4] trailing_path = trailing_path[:-4]

@ -781,15 +781,16 @@ class TestUtils(unittest.TestCase):
def test_repo_url_to_role_name(self): def test_repo_url_to_role_name(self):
tests = [("http://git.example.com/repos/repo.git", "repo"), tests = [("http://git.example.com/repos/repo.git", "repo"),
("ssh://git@git.example.com:repos/role-name", "role-name"), ("ssh://git@git.example.com:repos/role-name", "role-name"),
("ssh://git@git.example.com:repos/role-name,v0.1", "role-name")] ("ssh://git@git.example.com:repos/role-name,v0.1", "role-name"),
("directory/role/is/installed/in", "directory/role/is/installed/in")]
for (url, result) in tests: for (url, result) in tests:
self.assertEqual(ansible.utils.repo_url_to_role_name(url), result) self.assertEqual(ansible.utils.repo_url_to_role_name(url), result)
def test_role_spec_parse(self): def test_role_spec_parse(self):
tests = [("git+http://git.example.com/repos/repo.git,v1.0", ('git', 'http://git.example.com/repos/repo.git', 'v1.0', 'repo')), tests = [("git+http://git.example.com/repos/repo.git,v1.0", {'scm': 'git', 'src': 'http://git.example.com/repos/repo.git', 'version': 'v1.0', 'name': 'repo'}),
("http://repo.example.com/download/tarfile.tar.gz", (None, 'http://repo.example.com/download/tarfile.tar.gz', '', 'tarfile')), ("http://repo.example.com/download/tarfile.tar.gz", {'scm': None, 'src': 'http://repo.example.com/download/tarfile.tar.gz', 'version': '', 'name': 'tarfile'}),
("http://repo.example.com/download/tarfile.tar.gz,,nicename", (None, 'http://repo.example.com/download/tarfile.tar.gz', '', 'nicename')), ("http://repo.example.com/download/tarfile.tar.gz,,nicename", {'scm': None, 'src': 'http://repo.example.com/download/tarfile.tar.gz', 'version': '', 'name': 'nicename'}),
("git+http://git.example.com/repos/repo.git,v1.0,awesome", ('git', 'http://git.example.com/repos/repo.git', 'v1.0', 'awesome'))] ("git+http://git.example.com/repos/repo.git,v1.0,awesome", {'scm': 'git', 'src': 'http://git.example.com/repos/repo.git', 'version': 'v1.0', 'name': 'awesome'})]
for (spec, result) in tests: for (spec, result) in tests:
self.assertEqual(ansible.utils.role_spec_parse(spec), result) self.assertEqual(ansible.utils.role_spec_parse(spec), result)

Loading…
Cancel
Save