Skip to content

Commit

Permalink
clean up murphy
Browse files Browse the repository at this point in the history
  • Loading branch information
cmcmarrow committed Sep 5, 2023
1 parent efaa2cd commit 534e588
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 122 deletions.
32 changes: 31 additions & 1 deletion tests/pytests/functional/utils/test_gitfs.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,8 @@ def _get_gitfs(opts, *remotes):

def _test_gitfs_simple(gitfs_opts):
g = _get_gitfs(
gitfs_opts, "https://github.com/saltstack/salt-test-pillar-gitfs.git"
gitfs_opts,
{"https://github.com/saltstack/salt-test-pillar-gitfs.git": [{"name": "bob"}]},
)
g.fetch_remotes()
assert len(g.remotes) == 1
Expand Down Expand Up @@ -154,3 +155,32 @@ def test_gitpython_gitfs_minion(gitpython_gitfs_opts):
@skipif_no_pygit2
def test_pygit2_gitfs_minion(pygit2_gitfs_opts):
_test_gitfs_minion(pygit2_gitfs_opts)


def _test_fetch_request_with_mountpoint(opts):
mpoint = [{"mountpoint": "salt/m"}]
p = _get_gitfs(
opts,
{"https://github.com/saltstack/salt-test-pillar-gitfs.git": mpoint},
)
p.fetch_remotes()
assert len(p.remotes) == 1
repo = p.remotes[0]
assert repo.mountpoint("testmount") == "salt/m"
assert set(p.file_list({"saltenv": "testmount"})) == {
"salt/m/test_dir1/testfile3",
"salt/m/test_dir1/test_dir2/testfile2",
"salt/m/.gitignore",
"salt/m/README.md",
"salt/m/test_dir1/test_dir2/testfile1",
}


@skipif_no_gitpython
def test_gitpython_fetch_request_with_mountpoint(gitpython_gitfs_opts):
_test_fetch_request_with_mountpoint(gitpython_gitfs_opts)


@skipif_no_pygit2
def test_pygit2_fetch_request_with_mountpoint(pygit2_gitfs_opts):
_test_fetch_request_with_mountpoint(pygit2_gitfs_opts)
121 changes: 0 additions & 121 deletions tests/pytests/functional/utils/test_pillar.py
Original file line number Diff line number Diff line change
Expand Up @@ -306,124 +306,3 @@ def test_gitpython_clear_old_remotes(gitpython_pillar_opts):
@skipif_no_pygit2
def test_pygit2_clear_old_remotes(pygit2_pillar_opts):
_test_clear_old_remotes(pygit2_pillar_opts)

@skipif_no_pygit2
def test_pygit2_fetch_request_with_mountpoint(pygit2_pillar_opts):
opts = pygit2_pillar_opts
mpoint = [{"mountpoint": "test_dir1/test_dir2"}]
p = _get_pillar(
opts,
{"__env__ https://github.com/saltstack/salt-test-pillar-gitfs.git": mpoint},
{"testmount https://github.com/saltstack/salt-test-pillar-gitfs.git": mpoint},
)
log.warning(f"DGM test_pygit2_fetch_request_with_mountpoint p '{p}', p.remote[0] '{p.remotes[0]}', working_dir op '{p.remotes[0].get_salt_working_dir()}'")
frequest = os.path.join(p.remotes[0].get_salt_working_dir(), "fetch_request")
frequest_testmount = os.path.join(p.remotes[1].get_salt_working_dir(), "fetch_request")
log.warning(f"DGM test_pygit2_fetch_request_with_mountpoint frequest '{frequest}'")
log.warning(f"DGM test_pygit2_fetch_request_with_mountpoint frequest_testmount '{frequest_testmount}'")
opts["pillarenv"] = "main"
p2 = _get_pillar(
opts, {"__env__ https://github.com/saltstack/salt-test-pillar-gitfs.git": mpoint}
)
log.warning(f"DGM test_pygit2_fetch_request_with_mountpoint p2 '{p2}', p.remote[0] '{p.remotes[0]}', working_dir op '{p2.remotes[0].get_salt_working_dir()}'")
frequest2 = os.path.join(p2.remotes[0].get_salt_working_dir(), "fetch_request")
log.warning(f"DGM test_pygit2_fetch_request_with_mountpoint frequest2 '{frequest2}'")
assert frequest != frequest2
assert os.path.isfile(frequest) is False
assert os.path.isfile(frequest2) is False
assert os.path.isfile(frequest_testmount) is False
p.fetch_remotes()
assert os.path.isfile(frequest) is False
# fetch request was placed
assert os.path.isfile(frequest2) is True
p2.checkout()
# fetch request was found
assert os.path.isfile(frequest2) is False
p2.fetch_remotes()
assert os.path.isfile(frequest) is True
assert os.path.isfile(frequest2) is False
assert os.path.isfile(frequest_testmount) is False
for _ in range(3):
p2.fetch_remotes()
assert os.path.isfile(frequest) is True
assert os.path.isfile(frequest2) is False
assert os.path.isfile(frequest_testmount) is False
# fetch request should still be processed even on fetch_on_fail=False
p.checkout(fetch_on_fail=False)
assert os.path.isfile(frequest) is False
assert os.path.isfile(frequest2) is False
assert os.path.isfile(frequest_testmount) is False



@skipif_no_pygit2
def test_pygit2_multiple_repos_with_mountpoint(pygit2_pillar_opts):
## _test_multiple_repos(pygit2_pillar_opts)
opts = pygit2_pillar_opts
log.warning(f"DGM test_pygit2_multiple_repos_with_mountpoint opts '{opts}'")
mpoint = [{"mountpoint": "test_dir1/test_dir2"}]
p = _get_pillar(
opts,
{"__env__ https://github.com/saltstack/salt-test-pillar-gitfs.git": mpoint},
{"testmount https://github.com/saltstack/salt-test-pillar-gitfs.git": mpoint},
)
p.checkout()
assert len(p.remotes) == 2
# make sure all repos dont share cache and working dir
assert len({r.get_cachedir() for r in p.remotes}) == 2
assert len({r.get_salt_working_dir() for r in p.remotes}) == 2

p2 = _get_pillar(
opts,
{"__env__ https://github.com/saltstack/salt-test-pillar-gitfs.git": mpoint},
{"testmount https://github.com/saltstack/salt-test-pillar-gitfs.git": mpoint},
)
p2.checkout()
assert len(p2.remotes) == 2
# make sure that repos are given same cache dir
for repo, repo2 in zip(p.remotes, p2.remotes):
assert repo.get_cachedir() == repo2.get_cachedir()
assert repo.get_salt_working_dir() == repo2.get_salt_working_dir()
opts["pillarenv"] = "main"
p3 = _get_pillar(
opts,
{"__env__ https://github.com/saltstack/salt-test-pillar-gitfs.git": mpoint},
{"testmount https://github.com/saltstack/salt-test-pillar-gitfs.git": mpoint},
)
p3.checkout()
# check that __env__ has different cache with different pillarenv
assert p.remotes[0].get_cachedir() != p3.remotes[0].get_cachedir()
assert p.remotes[1].get_cachedir() == p3.remotes[1].get_cachedir()

# check that __env__ branch data is in cache
files = set(os.listdir(p.remotes[0].get_cachedir()))
log.warning(f"DGM test_pygit2_multiple_repos_with_mountpoint p 0 files '{files}'")
for f in (".gitignore", "README.md", "file.sls", "top.sls"):
assert f in files
for f in ("test_dir1"):
assert f not in files

# check that testmount branch data is in cache
files = set(os.listdir(p.remotes[1].get_cachedir()))
log.warning(f"DGM test_pygit2_multiple_repos_with_mountpoint p 1 files '{files}'")
for f in (".gitignore", "README.md", ".git", "test_dir1"):
assert f in files

filesp30link = set(os.listdir(p3.remotes[0].get_linkdir()))
log.warning(f"DGM test_pygit2_multiple_repos_with_mountpoint files p3 0 linkdir '{filesp30link}'")
assert filesp30link == {"test_dir1"}

filesp31link = set(os.listdir(p3.remotes[1].get_linkdir()))
log.warning(f"DGM test_pygit2_multiple_repos_with_mountpoint files p3 1 linkdir '{filesp31link}'")
assert filesp31link == {"test_dir1"}

## filesx = set(p3.remotes[1].file_list({"saltenv": "testmount"}))
## pathfilesx = set(os.listdir(p3.remotes[1].get_cachedir()))
pathfilesx = os.path.join(p3.remotes[1].get_cachedir(), "test_dir1")
## filesx = dir(p3.remotes[1])
log.warning(f"DGM test_pygit2_multiple_repos_with_mountpoint pathfilesx p3 1 '{pathfilesx}'")
filesx = list(os.walk(pathfilesx))
log.warning(f"DGM test_pygit2_multiple_repos_with_mountpoint filesx '{filesx}'")
for f in ("test_dir1/test_dir2/testfile1", "test_dir1/test_dir2/testfile2", "test_dir1/testfile3"):
log.warning(f"DGM test_pygit2_multiple_repos_with_mountpoint filesx file f '{f}'")
assert f in filesx

0 comments on commit 534e588

Please sign in to comment.