Repository: spack/spack

Issue:
Spack mirror --all fails immediately
### Steps to reproduce

```
spack --timestamp --debug mirror create --all -n all -d /storage/spack/mirror 
==> [2022-07-18-12:03:13.762045] Imported mirror from built-in commands
==> [2022-07-18-12:03:13.767743] Imported mirror from built-in commands
==> [2022-07-18-12:03:13.769097] Reading config file /storage/spack/spack/etc/spack/defaults/repos.yaml
==> [2022-07-18-12:03:13.898314] Reading config file /storage/spack/spack/etc/spack/defaults/config.yaml
Traceback (most recent call last):
  File "/storage/spack/spack/bin/spack", line 98, in <module>
    sys.exit(spack.main.main())
  File "/storage/spack/spack/lib/spack/spack/main.py", line 893, in main
    return _main(argv)
  File "/storage/spack/spack/lib/spack/spack/main.py", line 848, in _main
    return finish_parse_and_run(parser, cmd_name, env_format_error)
  File "/storage/spack/spack/lib/spack/spack/main.py", line 876, in finish_parse_and_run
    return _invoke_command(command, parser, args, unknown)
  File "/storage/spack/spack/lib/spack/spack/main.py", line 533, in _invoke_command
    return_val = command(parser, args)
  File "/storage/spack/spack/lib/spack/spack/cmd/mirror.py", line 380, in mirror
    action[args.mirror_command](args)
  File "/storage/spack/spack/lib/spack/spack/cmd/mirror.py", line 325, in mirror_create
    mirror_specs = _determine_specs_to_mirror(args)
  File "/storage/spack/spack/lib/spack/spack/cmd/mirror.py", line 301, in _determine_specs_to_mirror
    mirror_specs = spack.mirror.get_all_versions(specs)
  File "/storage/spack/spack/lib/spack/spack/mirror.py", line 427, in get_all_versions
    pkg = spec.package
  File "/storage/spack/spack/lib/spack/spack/spec.py", line 1520, in package
    assert self.concrete, "Spec.package can only be called on concrete specs"
AssertionError: Spec.package can only be called on concrete specs
```

### Error message

See above

### Information on your system

Our script pulls the latest develop. 

```
spack debug report
* **Spack:** 0.19.0.dev0
* **Python:** 3.6.8
* **Platform:** linux-rhel7-broadwell
* **Concretizer:** clingo
```

### General information

- [X] I have run `spack debug report` and reported the version of Spack/Python/Platform
- [X] I have searched the issues of this repo and believe this is not a duplicate
- [X] I have run the failing commands in debug mode and reported the output


Discussion:

Resolving patch:
diff --git a/lib/spack/spack/mirror.py b/lib/spack/spack/mirror.py
--- a/lib/spack/spack/mirror.py
+++ b/lib/spack/spack/mirror.py
@@ -421,18 +421,16 @@ def get_all_versions(specs):
     version, this information will be omitted in the new set; for example; the
     new set of specs will not include variant settings.
     """
-
     version_specs = []
     for spec in specs:
-        pkg = spec.package
-
+        pkg_cls = spack.repo.path.get_pkg_class(spec.name)
         # Skip any package that has no known versions.
-        if not pkg.versions:
-            tty.msg("No safe (checksummed) versions for package %s" % pkg.name)
+        if not pkg_cls.versions:
+            tty.msg("No safe (checksummed) versions for package %s" % pkg_cls.name)
             continue
 
-        for version in pkg.versions:
-            version_spec = spack.spec.Spec(pkg.name)
+        for version in pkg_cls.versions:
+            version_spec = spack.spec.Spec(pkg_cls.name)
             version_spec.versions = VersionList([version])
             version_specs.append(version_spec)
 
@@ -639,6 +637,10 @@ def error(self):
 
 
 def _add_single_spec(spec, mirror, mirror_stats):
+    # Ensure that the spec is concrete, since we'll stage it later
+    if not spec.concrete:
+        spec = spec.concretized()
+
     tty.msg("Adding package {pkg} to mirror".format(
         pkg=spec.format("{name}{@version}")
     ))


Test patch:
diff --git a/lib/spack/spack/test/mirror.py b/lib/spack/spack/test/mirror.py
--- a/lib/spack/spack/test/mirror.py
+++ b/lib/spack/spack/test/mirror.py
@@ -320,3 +320,16 @@ def test_mirror_cache_symlinks(tmpdir):
     assert os.path.exists(link_target)
     assert (os.path.normpath(link_target) ==
             os.path.join(cache.root, reference.storage_path))
+
+
+@pytest.mark.regression('31627')
+@pytest.mark.parametrize('specs,expected_specs', [
+    (['a'], ['a@1.0', 'a@2.0']),
+    (['a', 'brillig'], ['a@1.0', 'a@2.0', 'brillig@1.0.0', 'brillig@2.0.0']),
+])
+def test_get_all_versions(specs, expected_specs):
+    specs = [Spec(s) for s in specs]
+    output_list = spack.mirror.get_all_versions(specs)
+    output_list = [str(x) for x in output_list]
+    # Compare sets since order is not important
+    assert set(output_list) == set(expected_specs)