Skip to content
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

build providers: idempotent destroy for LXD #2529

Merged
merged 1 commit into from
Apr 9, 2019

Conversation

sergiusens
Copy link
Collaborator

@sergiusens sergiusens commented Apr 9, 2019

Fixes SNAPCRAFT-MB

Signed-off-by: Sergio Schvezov sergio.schvezov@canonical.com

  • Have you followed the guidelines for contributing?
  • Have you signed the CLA?
  • Have you successfully run ./runtests.sh static?
  • Have you successfully run ./runtests.sh tests/unit?

Before

(snapcraft) multipass@lxd-snapcraft:~/t$ snapcraft --use-lxd
Using 'snap/snapcraft.yaml': Project assets will be searched for from the 'snap' directory.
The LXD provider is offered as a technology preview for early adopters.
The command line interface, container names or lifecycle handling may change in upcoming releases.
Launching a container.
Sorry, an error occurred in Snapcraft:
Traceback (most recent call last):
  File "/home/multipass/snapcraft/snapcraft/internal/build_providers/_base_provider.py", line 249, in launch_instance
    self._start()
  File "/home/multipass/snapcraft/snapcraft/internal/build_providers/_lxd/_lxd.py", line 166, in _start
    raise errors.ProviderInstanceNotFoundError(instance_name=self.instance_name)
snapcraft.internal.build_providers.errors.ProviderInstanceNotFoundError: Cannot find an instance named 'snapcraft-test'.

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/multipass/snapcraft/snapcraft/internal/build_providers/_lxd/_lxd.py", line 151, in _launch
    container = self._lxd_client.containers.create(config, wait=True)
  File "/home/multipass/venv/snapcraft/lib/python3.6/site-packages/pylxd/models/container.py", line 276, in create
    response = client.api.containers.post(json=config, target=target)
  File "/home/multipass/venv/snapcraft/lib/python3.6/site-packages/pylxd/client.py", line 168, in post
    self._assert_response(response, allowed_status_codes=(200, 201, 202))
  File "/home/multipass/venv/snapcraft/lib/python3.6/site-packages/pylxd/client.py", line 108, in _assert_response
    raise exceptions.LXDAPIException(response)
pylxd.exceptions.LXDAPIException: No storage pool found. Please create a new storage pool

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/home/multipass/snapcraft/snapcraft/internal/build_providers/_base_provider.py", line 117, in __enter__
    self.create()
  File "/home/multipass/snapcraft/snapcraft/internal/build_providers/_lxd/_lxd.py", line 246, in create
    self.launch_instance()
  File "/home/multipass/snapcraft/snapcraft/internal/build_providers/_base_provider.py", line 257, in launch_instance
    self._launch()
  File "/home/multipass/snapcraft/snapcraft/internal/build_providers/_lxd/_lxd.py", line 155, in _launch
    ) from lxd_api_error
snapcraft.internal.build_providers.errors.ProviderLaunchError: An error occurred with the instance when trying to launch with 'LXD': No storage pool found. Please create a new storage pool.
Ensure that 'LXD' is setup correctly and try again.

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/multipass/venv/snapcraft/bin/snapcraft", line 11, in <module>
    load_entry_point('snapcraft', 'console_scripts', 'snapcraft')()
  File "/home/multipass/snapcraft/snapcraft/cli/__main__.py", line 81, in run
    run_snapcraft(prog_name="snapcraft")
  File "/home/multipass/venv/snapcraft/lib/python3.6/site-packages/click/core.py", line 722, in __call__
    return self.main(*args, **kwargs)
  File "/home/multipass/venv/snapcraft/lib/python3.6/site-packages/click/core.py", line 697, in main
    rv = self.invoke(ctx)
  File "/home/multipass/venv/snapcraft/lib/python3.6/site-packages/click/core.py", line 1043, in invoke
    return Command.invoke(self, ctx)
  File "/home/multipass/venv/snapcraft/lib/python3.6/site-packages/click/core.py", line 895, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "/home/multipass/venv/snapcraft/lib/python3.6/site-packages/click/core.py", line 535, in invoke
    return callback(*args, **kwargs)
  File "/home/multipass/venv/snapcraft/lib/python3.6/site-packages/click/decorators.py", line 17, in new_func
    return f(get_current_context(), *args, **kwargs)
  File "/home/multipass/snapcraft/snapcraft/cli/_runner.py", line 93, in run
    ctx.forward(lifecyclecli.commands["snap"])
  File "/home/multipass/venv/snapcraft/lib/python3.6/site-packages/click/core.py", line 553, in forward
    return self.invoke(cmd, **kwargs)
  File "/home/multipass/venv/snapcraft/lib/python3.6/site-packages/click/core.py", line 535, in invoke
    return callback(*args, **kwargs)
  File "/home/multipass/snapcraft/snapcraft/cli/lifecycle.py", line 272, in snap
    _execute(steps.PRIME, parts=[], pack_project=True, output=output, **kwargs)
  File "/home/multipass/snapcraft/snapcraft/cli/lifecycle.py", line 98, in _execute
    with build_provider_class(project=project, echoer=echo) as instance:
  File "/home/multipass/snapcraft/snapcraft/internal/build_providers/_base_provider.py", line 120, in __enter__
    self.destroy()
  File "/home/multipass/snapcraft/snapcraft/internal/build_providers/_lxd/_lxd.py", line 250, in destroy
    self._stop()
  File "/home/multipass/snapcraft/snapcraft/internal/build_providers/_lxd/_lxd.py", line 196, in _stop
    self._container.sync()
AttributeError: 'NoneType' object has no attribute 'sync'
We would appreciate it if you created a bug report at
https://launchpad.net/snapcraft/+filebug with the above text included.

and after

(snapcraft) multipass@lxd-snapcraft:~/t$ snapcraft --use-lxd
Using 'snap/snapcraft.yaml': Project assets will be searched for from the 'snap' directory.
The LXD provider is offered as a technology preview for early adopters.
The command line interface, container names or lifecycle handling may change in upcoming releases.
Launching a container.
An error occurred with the instance when trying to launch with 'LXD': No storage pool found. Please create a new storage pool.
Ensure that 'LXD' is setup correctly and try again.

Fixes SNAPCRAFT-MB

Signed-off-by: Sergio Schvezov <sergio.schvezov@canonical.com>
@codecov-io
Copy link

Codecov Report

Merging #2529 into master will decrease coverage by <.01%.
The diff coverage is 0%.

Impacted file tree graph

@@            Coverage Diff            @@
##           master   #2529      +/-   ##
=========================================
- Coverage    89.1%   89.1%   -0.01%     
=========================================
  Files         201     201              
  Lines       13650   13652       +2     
  Branches     2065    2066       +1     
=========================================
+ Hits        12163   12164       +1     
- Misses       1048    1050       +2     
+ Partials      439     438       -1
Impacted Files Coverage Δ
snapcraft/internal/build_providers/_lxd/_lxd.py 23.39% <0%> (-0.28%) ⬇️
snapcraft/internal/elf.py 81.07% <0%> (+0.35%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update e39d240...afbab78. Read the comment docs.

@sergiusens sergiusens merged commit 1b29058 into canonical:master Apr 9, 2019
@sergiusens sergiusens deleted the lxd-destroy branch April 9, 2019 19:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants