spack debug create-db-tarball: remove after test failures (#49025)
This commit is contained in:
parent
4dc1a900e2
commit
a7b542dd37
@ -2,23 +2,11 @@
|
||||
#
|
||||
# SPDX-License-Identifier: (Apache-2.0 OR MIT)
|
||||
|
||||
import os
|
||||
import platform
|
||||
import re
|
||||
import sys
|
||||
from datetime import datetime
|
||||
from glob import glob
|
||||
|
||||
import llnl.util.tty as tty
|
||||
from llnl.util.filesystem import working_dir
|
||||
|
||||
import spack
|
||||
import spack.paths
|
||||
import spack.platforms
|
||||
import spack.spec
|
||||
import spack.store
|
||||
import spack.util.git
|
||||
from spack.util.executable import which
|
||||
|
||||
description = "debugging commands for troubleshooting Spack"
|
||||
section = "developer"
|
||||
@ -27,63 +15,9 @@
|
||||
|
||||
def setup_parser(subparser):
|
||||
sp = subparser.add_subparsers(metavar="SUBCOMMAND", dest="debug_command")
|
||||
sp.add_parser("create-db-tarball", help="create a tarball of Spack's installation metadata")
|
||||
sp.add_parser("report", help="print information useful for bug reports")
|
||||
|
||||
|
||||
def _debug_tarball_suffix():
|
||||
now = datetime.now()
|
||||
suffix = now.strftime("%Y-%m-%d-%H%M%S")
|
||||
|
||||
git = spack.util.git.git()
|
||||
if not git:
|
||||
return "nobranch-nogit-%s" % suffix
|
||||
|
||||
with working_dir(spack.paths.prefix):
|
||||
if not os.path.isdir(".git"):
|
||||
return "nobranch.nogit.%s" % suffix
|
||||
|
||||
# Get symbolic branch name and strip any special chars (mainly '/')
|
||||
symbolic = git("rev-parse", "--abbrev-ref", "--short", "HEAD", output=str).strip()
|
||||
symbolic = re.sub(r"[^\w.-]", "-", symbolic)
|
||||
|
||||
# Get the commit hash too.
|
||||
commit = git("rev-parse", "--short", "HEAD", output=str).strip()
|
||||
|
||||
if symbolic == commit:
|
||||
return "nobranch.%s.%s" % (commit, suffix)
|
||||
else:
|
||||
return "%s.%s.%s" % (symbolic, commit, suffix)
|
||||
|
||||
|
||||
def create_db_tarball(args):
|
||||
tar = which("tar")
|
||||
tarball_name = "spack-db.%s.tar.gz" % _debug_tarball_suffix()
|
||||
tarball_path = os.path.abspath(tarball_name)
|
||||
|
||||
base = os.path.basename(str(spack.store.STORE.root))
|
||||
transform_args = []
|
||||
# Currently --transform and -s are not supported by Windows native tar
|
||||
if "GNU" in tar("--version", output=str):
|
||||
transform_args = ["--transform", "s/^%s/%s/" % (base, tarball_name)]
|
||||
elif sys.platform != "win32":
|
||||
transform_args = ["-s", "/^%s/%s/" % (base, tarball_name)]
|
||||
|
||||
wd = os.path.dirname(str(spack.store.STORE.root))
|
||||
with working_dir(wd):
|
||||
files = [spack.store.STORE.db._index_path]
|
||||
files += glob("%s/*/*/*/.spack/spec.json" % base)
|
||||
files += glob("%s/*/*/*/.spack/spec.yaml" % base)
|
||||
files = [os.path.relpath(f) for f in files]
|
||||
|
||||
args = ["-czf", tarball_path]
|
||||
args += transform_args
|
||||
args += files
|
||||
tar(*args)
|
||||
|
||||
tty.msg("Created %s" % tarball_name)
|
||||
|
||||
|
||||
def report(args):
|
||||
host_platform = spack.platforms.host()
|
||||
host_os = host_platform.default_operating_system()
|
||||
@ -95,5 +29,5 @@ def report(args):
|
||||
|
||||
|
||||
def debug(parser, args):
|
||||
action = {"create-db-tarball": create_db_tarball, "report": report}
|
||||
action[args.debug_command](args)
|
||||
if args.debug_command == "report":
|
||||
report(args)
|
||||
|
@ -2,52 +2,16 @@
|
||||
#
|
||||
# SPDX-License-Identifier: (Apache-2.0 OR MIT)
|
||||
|
||||
import os
|
||||
import platform
|
||||
|
||||
import pytest
|
||||
|
||||
import spack
|
||||
import spack.platforms
|
||||
import spack.spec
|
||||
from spack.database import INDEX_JSON_FILE
|
||||
from spack.main import SpackCommand
|
||||
from spack.util.executable import which
|
||||
|
||||
debug = SpackCommand("debug")
|
||||
|
||||
|
||||
@pytest.mark.db
|
||||
def test_create_db_tarball(tmpdir, database):
|
||||
with tmpdir.as_cwd():
|
||||
debug("create-db-tarball")
|
||||
|
||||
# get the first non-dotfile to avoid coverage files in the directory
|
||||
files = os.listdir(os.getcwd())
|
||||
tarball_name = next(
|
||||
f for f in files if not f.startswith(".") and not f.startswith("tests")
|
||||
)
|
||||
|
||||
# debug command made an archive
|
||||
assert os.path.exists(tarball_name)
|
||||
|
||||
# print contents of archive
|
||||
tar = which("tar")
|
||||
contents = tar("tzf", tarball_name, output=str)
|
||||
|
||||
# DB file is included
|
||||
assert INDEX_JSON_FILE in contents
|
||||
|
||||
# specfiles from all installs are included
|
||||
for spec in database.query():
|
||||
# externals won't have a specfile
|
||||
if spec.external:
|
||||
continue
|
||||
|
||||
spec_suffix = "%s/.spack/spec.json" % spec.dag_hash()
|
||||
assert spec_suffix in contents
|
||||
|
||||
|
||||
def test_report():
|
||||
out = debug("report")
|
||||
host_platform = spack.platforms.host()
|
||||
|
@ -929,14 +929,10 @@ _spack_debug() {
|
||||
then
|
||||
SPACK_COMPREPLY="-h --help"
|
||||
else
|
||||
SPACK_COMPREPLY="create-db-tarball report"
|
||||
SPACK_COMPREPLY="report"
|
||||
fi
|
||||
}
|
||||
|
||||
_spack_debug_create_db_tarball() {
|
||||
SPACK_COMPREPLY="-h --help"
|
||||
}
|
||||
|
||||
_spack_debug_report() {
|
||||
SPACK_COMPREPLY="-h --help"
|
||||
}
|
||||
|
@ -1317,16 +1317,10 @@ complete -c spack -n '__fish_spack_using_command create' -s b -l batch -d 'don'"
|
||||
|
||||
# spack debug
|
||||
set -g __fish_spack_optspecs_spack_debug h/help
|
||||
complete -c spack -n '__fish_spack_using_command_pos 0 debug' -f -a create-db-tarball -d 'create a tarball of Spack'"'"'s installation metadata'
|
||||
complete -c spack -n '__fish_spack_using_command_pos 0 debug' -f -a report -d 'print information useful for bug reports'
|
||||
complete -c spack -n '__fish_spack_using_command debug' -s h -l help -f -a help
|
||||
complete -c spack -n '__fish_spack_using_command debug' -s h -l help -d 'show this help message and exit'
|
||||
|
||||
# spack debug create-db-tarball
|
||||
set -g __fish_spack_optspecs_spack_debug_create_db_tarball h/help
|
||||
complete -c spack -n '__fish_spack_using_command debug create-db-tarball' -s h -l help -f -a help
|
||||
complete -c spack -n '__fish_spack_using_command debug create-db-tarball' -s h -l help -d 'show this help message and exit'
|
||||
|
||||
# spack debug report
|
||||
set -g __fish_spack_optspecs_spack_debug_report h/help
|
||||
complete -c spack -n '__fish_spack_using_command debug report' -s h -l help -f -a help
|
||||
|
Loading…
Reference in New Issue
Block a user