buildd: check internet after network command fails (CRAFT-1461)
Metadata
Current evaluation
Closed unmerged as superseded; successor PR #189 merged the CRAFT-1461 network-failure connectivity check in commit 634ed19.
Resolution: closed superseded
Reason: The maintainer explicitly marked #176 as superseded by #189. PR #189 merged the revised implementation, recorded in commit 634ed19.
Evaluated by: mr-cal-bot
No scores available.
Issue body
For this I centralized the command run in a helper, that simplifies all the calls and makes the verification easier. Note that I have another PR in mind to simplify the code more.
I tested this IRL, the resulting exception is much more clear than the obscure failings we had in the past:
```
2022-11-11 13:57:44.915 charmcraft internal error: NetworkError(brief='A network related operation failed in a context of no network access.', details=None, resolution='Verify that the environment has internet connectivity.')
2022-11-11 13:57:44.917 Traceback (most recent call last):
2022-11-11 13:57:44.917 File "/snap/charmcraft/x2/lib/craft_providers/bases/buildd.py", line 114, in _execute_run
2022-11-11 13:57:44.917 proc = executor.execute_run(command, check=check, capture_output=capture_output, text=text)
2022-11-11 13:57:44.917 File "/snap/charmcraft/x2/lib/craft_providers/lxd/lxd_instance.py", line 289, in execute_run
2022-11-11 13:57:44.917 return self.lxc.exec(
2022-11-11 13:57:44.917 File "/snap/charmcraft/x2/lib/craft_providers/lxd/lxc.py", line 329, in exec
2022-11-11 13:57:44.917 return runner(final_cmd, **kwargs) # pylint: disable=subprocess-run-check
2022-11-11 13:57:44.917 File "/snap/charmcraft/x2/usr/lib/python3.8/subprocess.py", line 516, in run
2022-11-11 13:57:44.917 raise CalledProcessError(retcode, process.args,
2022-11-11 13:57:44.917 subprocess.CalledProcessError: Command '['lxc', '--project', 'charmcraft', 'exec', 'local:charmcraft-my-super-charm-27791466-0-0-amd64', '--', 'env', 'PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/snap/bin', 'CHARMCRAFT_MANAGED_MODE=1', 'apt-get', 'update']' returned non-zero exit status 100.
2022-11-11 13:57:44.917
2022-11-11 13:57:44.917 The above exception was the direct cause of the following exception:
2022-11-11 13:57:44.917 Traceback (most recent call last):
2022-11-11 13:57:44.917 File "/snap/charmcraft/x2/lib/charmcraft/main.py", line 184, in main
2022-11-11 13:57:44.917 retcode = dispatcher.run()
2022-11-11 13:57:44.917 File "/snap/charmcraft/x2/lib/craft_cli/dispatcher.py", line 448, in run
2022-11-11 13:57:44.917 return self._loaded_command.run(self._parsed_command_args)
2022-11-11 13:57:44.917 File "/snap/charmcraft/x2/lib/charmcraft/commands/pack.py", line 133, in run
2022-11-11 13:57:44.917 pack_method(parsed_args)
2022-11-11 13:57:44.917 File "/snap/charmcraft/x2/lib/charmcraft/commands/pack.py", line 165, in _pack_charm
2022-11-11 13:57:44.917 charms = builder.run(
2022-11-11 13:57:44.917 File "/snap/charmcraft/x2/lib/charmcraft/instrum.py", line 152, in _f
2022-11-11 13:57:44.917 return func(*args, **kwargs)
2022-11-11 13:57:44.917 File "/snap/charmcraft/x2/lib/charmcraft/commands/build.py", line 292, in run
2022-11-11 13:57:44.917 charm_name = self.pack_charm_in_instance(
2022-11-11 13:57:44.917 File "/snap/charmcraft/x2/lib/charmcraft/commands/build.py", line 357, in pack_charm_in_instance
2022-11-11 13:57:44.918 with self.provider.launched_environment(
2022-11-11 13:57:44.918 File "/snap/charmcraft/x2/usr/lib/python3.8/contextlib.py", line 113, in __enter__
2022-11-11 13:57:44.918 return next(self.gen)
2022-11-11 13:57:44.918 File "/snap/charmcraft/x2/lib/craft_providers/lxd/lxd_provider.py", line 126, in launched_environment
2022-11-11 13:57:44.918 instance = launch(
2022-11-11 13:57:44.918 File "/snap/charmcraft/x2/lib/craft_providers/lxd/launcher.py", line 212, in launch
2022-11-11 13:57:44.918 base_configuration.setup(executor=instance)
2022-11-11 13:57:44.918 File "/snap/charmcraft/x2/lib/craft_providers/bases/buildd.py", line 392, in setup
2022-11-11 13:57:44.918 self._setup_apt(executor=executor, deadline=deadline)
2022-11-11 13:57:44.918 File "/snap/charmcraft/x2/lib/craft_providers/bases/buildd.py", line 556, in _setup_apt
2022-11-11 13:57:44.918 _execute_run(executor, ["apt-get", "update"], verify_network=True)
2022-11-11 13:57:44.918 File "/snap/charmcraft/x2/lib/craft_providers/bases/buildd.py", line 117, in _execute_run
2022-11-11 13:57:44.918 raise NetworkError() from exc
2022-11-11 13:57:44.918 craft_providers.bases.errors.NetworkError: A network related operation failed in a context of no network access.
2022-11-11 13:57:44.918 Verify that the environment has internet connectivity.
2022-11-11 13:57:44.918 Full execution log: '/home/facundo/snap/charmcraft/common/cache/charmcraft/log/charmcraft-20221111-135607.196724.log'
```
That said, we will talk about Craft Provider errors not being "crashes" but "failures", but that discussion exceeds this PR.
Evaluation history
| Date | Model | Scores | Action | Summary |
|---|---|---|---|---|
| stealth/space-bunny-alpha | — | closed superseded | Closed unmerged as superseded; successor PR #189 merged the CRAFT-1461 network-failure connectivity check in commit 634ed19. | |
| qwen/qwen3.6-35b-a3b | — | closed superseded | Refactored buildd command execution to centralize calls and improve network error messages. Superseded by #189 before merging. |
Update history
| Date | Change |
|---|---|
| created |
Related work
-
Superseded By:
canonical/craft-providers#189
(confidence 100%)
Merged successor implementing the same CRAFT-1461 network connectivity verification.
Related issues
| Issue | Project | State | Summary | Similarity |
|---|---|---|---|---|
| #189 buildd: check internet after network command fails (CRAFT-1461) | craft-providers | merged | Merged PR #189 added an internet check after buildd network commands fail, resolving CRAFT-1461 in commit 634ed19 and superseding #176. |