Repository: ansible/awx

Issue:
Add error handling to scm_version.py script
##### SUMMARY
I hit cases where this script failed in CI, but then all it tells you is that the subprocess failed, but doesn't give the output of the subprocess.

##### ISSUE TYPE
 - Bug, Docs Fix or other nominal change

##### COMPONENT NAME
 - API




Discussion:
The error I mentioned turns out affects all successful CI runs with this error text:

```
Unable to import setuptools-scm, attempting to install now...
Traceback (most recent call last):
  File "/home/runner/work/awx/awx/tools/scripts/scm_version.py", line 7, in <module>
    from setuptools_scm import get_version
ModuleNotFoundError: No module named 'setuptools_scm'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/runner/work/awx/awx/tools/scripts/scm_version.py", line 12, in <module>
    subprocess.check_output([sys.executable, '-m', 'ensurepip'])
  File "/usr/lib/python3.[10](https://github.com/ansible/awx/actions/runs/4831164595/jobs/8608244693?pr=13924#step:3:11)/subprocess.py", line 4[20](https://github.com/ansible/awx/actions/runs/4831164595/jobs/8608244693?pr=13924#step:3:21), in check_output
    return run(*popenargs, stdout=PIPE, timeout=timeout, check=True,
  File "/usr/lib/python3.10/subprocess.py", line 524, in run
    raise CalledProcessError(retcode, process.args,
subprocess.CalledProcessError: Command '['/usr/bin/python3', '-m', 'ensurepip']' returned non-zero exit status 1.
```

To summarize:
 - it fails to compute the version
 - error details for that error are missing
 - this error is non-fatal
 - rest of checks continue and are successful

Currently, so-far, this PR gets it to the point where it accurately reports the error, which is...

```
Exception: 
Command `/usr/bin/python3 -m ensurepip` failed (rc=1).
stdout:
b'ensurepip is disabled in Debian/Ubuntu for the system python.\n\nPython modules for the system python are usually handled by dpkg and apt-get.\n\n    apt install python3-<module name>\n\nInstall the python3-pip package to use pip itself.  Using pip together\nwith the system python might have unexpected results for any system installed\nmodule, so use it on your own risk, or make sure to only use it in virtual\nenvironments.\n\n'
```

re-formatted...

```
ensurepip is disabled in Debian/Ubuntu for the system python.

Python modules for the system python are usually handled by dpkg and apt-get.

    apt install python3-<module name>

Install the python3-pip package to use pip itself.  Using pip together
with the system python might have unexpected results for any system installed
module, so use it on your own risk, or make sure to only use it in virtual
environments.
```

Obviously, it would also be good to fix the root of the problem... or stop running this script.



Resolving patch:
diff --git a/awxkit/awxkit/api/pages/api.py b/awxkit/awxkit/api/pages/api.py
--- a/awxkit/awxkit/api/pages/api.py
+++ b/awxkit/awxkit/api/pages/api.py
@@ -404,6 +404,11 @@ def import_assets(self, data):
 
         for resource in self._dependent_resources():
             endpoint = getattr(self, resource)
+            # The /api/v2/constructed_inventories endpoint is for the UI but will register as an Inventory endpoint causing import issues, so skip it
+            if endpoint == '/api/v2/constructed_inventories/':
+                log.debug("Ignoring /api/v2/constructed_inventories/ endpoint.")
+                continue
+
             # Load up existing objects, so that we can try to update or link to them
             self._cache.get_page(endpoint)
             imported = self._import_list(endpoint, data.get(resource) or [])


Test patch: