-
Notifications
You must be signed in to change notification settings - Fork 293
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
[PREVIEW] teuthology: add support for graph walks of QA suites #2012
Open
batrick
wants to merge
3
commits into
ceph:main
Choose a base branch
from
batrick:graph-walk
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 1 commit
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -95,7 +95,7 @@ def current_branch(path: str) -> str: | |
return result | ||
|
||
|
||
def enforce_repo_state(repo_url, dest_path, branch, commit=None, remove_on_error=True): | ||
def enforce_repo_state(dest_clone, dest_path, repo_url, branch, commit=None, remove_on_error=True): | ||
""" | ||
Use git to either clone or update a given repo, forcing it to switch to the | ||
specified branch. | ||
|
@@ -114,25 +114,100 @@ def enforce_repo_state(repo_url, dest_path, branch, commit=None, remove_on_error | |
# sentinel to track whether the repo has checked out the intended | ||
# version, in addition to being cloned | ||
repo_reset = os.path.join(dest_path, '.fetched_and_reset') | ||
log.info("enforce_repo_state %s %s %s %s %s", dest_clone, dest_path, repo_url, branch, commit) | ||
try: | ||
if not os.path.isdir(dest_path): | ||
clone_repo(repo_url, dest_path, branch, shallow=commit is None) | ||
if not os.path.isdir(dest_clone): | ||
bare_repo(dest_clone) | ||
elif not commit and not is_fresh(sentinel): | ||
set_remote(dest_path, repo_url) | ||
fetch_branch(dest_path, branch) | ||
#set_remote(dest_path, repo_url) | ||
#fetch_branch(dest_path, branch) | ||
touch_file(sentinel) | ||
|
||
if commit and os.path.exists(repo_reset): | ||
return | ||
#if commit and os.path.exists(repo_reset): | ||
#return | ||
|
||
reset_repo(repo_url, dest_path, branch, commit) | ||
touch_file(repo_reset) | ||
myfetch(dest_clone, repo_url, branch, commit) | ||
myworkspace(dest_clone, dest_path) | ||
#reset_repo(repo_url, dest_path, branch, commit) | ||
#touch_file(repo_reset) | ||
# remove_pyc_files(dest_path) | ||
except (BranchNotFoundError, CommitNotFoundError): | ||
if remove_on_error: | ||
shutil.rmtree(dest_path, ignore_errors=True) | ||
raise | ||
|
||
def bare_repo(git_dir): | ||
log.info("bare_repo %s", git_dir) | ||
args = ['git', 'init', '--bare', git_dir] | ||
proc = subprocess.Popen(args) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If you don't need a lot of the complexity that Popen provides, I heartily recommend using the simpler |
||
#args, | ||
#stdout=subprocess.PIPE, | ||
#stderr=subprocess.STDOUT) | ||
if proc.wait() != 0: | ||
raise RuntimeError("oops") | ||
|
||
def myworkspace(git_dir, workspace_dir): | ||
log.info("myworkspace %s %s", git_dir, workspace_dir) | ||
|
||
if os.path.exists(workspace_dir): | ||
args = [ | ||
'git', | ||
'log', | ||
'-1', | ||
] | ||
proc = subprocess.Popen(args,cwd=workspace_dir) | ||
if proc.wait() != 0: | ||
raise RuntimeError("oops") | ||
return | ||
|
||
args = [ | ||
'git', | ||
'worktree', | ||
'add', | ||
#'--detach', | ||
'-B', os.path.basename(workspace_dir), | ||
'--no-track', | ||
'--force', | ||
workspace_dir, | ||
'FETCH_HEAD' | ||
] | ||
proc = subprocess.Popen(args,cwd=git_dir) | ||
#args, | ||
#stdout=subprocess.PIPE, | ||
#stderr=subprocess.STDOUT) | ||
if proc.wait() != 0: | ||
raise RuntimeError("oops") | ||
|
||
|
||
def myfetch(git_dir, url, branch, commit=None): | ||
log.info("myfetch %s %s %s %s", git_dir, url, branch, commit) | ||
validate_branch(branch) | ||
if commit is not None: | ||
args = ['git', 'log', '-1', commit] | ||
proc = subprocess.Popen(args, cwd=git_dir, stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL) | ||
if proc.wait() == 0: | ||
return | ||
args = ['git', 'fetch', url] | ||
if commit is not None: | ||
args.append(commit) | ||
else: | ||
args.append(branch) | ||
proc = subprocess.Popen(args,cwd=git_dir) | ||
#proc = subprocess.Popen( | ||
#args, | ||
#cwd=git_dir, | ||
#) | ||
#stdout=subprocess.PIPE, | ||
#stderr=subprocess.STDOUT) | ||
if proc.wait() != 0: | ||
not_found_str = "fatal: couldn't find remote ref %s" % branch | ||
out = proc.stdout.read().decode() | ||
log.error(out) | ||
if not_found_str in out.lower(): | ||
raise BranchNotFoundError(branch) | ||
else: | ||
raise GitError("git fetch failed!") | ||
|
||
|
||
def clone_repo(repo_url, dest_path, branch, shallow=True): | ||
""" | ||
|
@@ -354,6 +429,7 @@ def fetch_repo(url, branch, commit=None, bootstrap=None, lock=True): | |
os.mkdir(src_base_path) | ||
ref_dir = ref_to_dirname(commit or branch) | ||
dirname = '%s_%s' % (url_to_dirname(url), ref_dir) | ||
dest_clone = os.path.join(src_base_path, url_to_dirname(url)) | ||
dest_path = os.path.join(src_base_path, dirname) | ||
# only let one worker create/update the checkout at a time | ||
lock_path = dest_path.rstrip('/') + '.lock' | ||
|
@@ -362,7 +438,8 @@ def fetch_repo(url, branch, commit=None, bootstrap=None, lock=True): | |
try: | ||
while proceed(): | ||
try: | ||
enforce_repo_state(url, dest_path, branch, commit) | ||
#enforce_repo_state(url, dest_path, branch, commit) | ||
enforce_repo_state(dest_clone, dest_path, url, branch, commit) | ||
if bootstrap: | ||
sentinel = os.path.join(dest_path, '.bootstrapped') | ||
if commit and os.path.exists(sentinel) or is_fresh(sentinel): | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd prefer not to change initial signature and leave repo_url at first position, and add
dest_cone
as an optional argument with defaults value.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure, there will probably be lots of reworking to this code but it was a dirty hack to start because the clones after every QA suite tweak was driving me nuts. That's why it's in this PR.