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: add a build image setup facility #2192

Merged
merged 8 commits into from
Aug 8, 2018

Conversation

sergiusens
Copy link
Collaborator

@sergiusens sergiusens commented Aug 3, 2018

Download the correct build image to build a base for the corresponding architecture.
Use a cached download if available and setup the original build disk image as the
backing store for the newly setup image.

LP: #1782779

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

  • Have you followed the guidelines for contributing?
  • Have you signed the CLA?
  • If this is a bugfix. Have you checked that there is a bug report open for the issue you are trying to fix on bug reports?
  • If this is a new feature. Have you discussed the design on the forum?
  • Have you successfully run ./runtests.sh static?
  • Have you successfully run ./runtests.sh unit?

You test the UI by doing

from snapcraft.internal.build_providers import images
images.setup(base="core18", snap_arch="amd64", size="4G", image_path="image.qcow2")

Copy link
Contributor

@kyrofa kyrofa left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good progress here! I have a number of suggestions/comments/questions inline.

return path
elif shutil.which(command_name):
return shutil.which(command_name)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like the elif here, but not the side effect of the fact that we have to run which twice. I suggest using an if instead so we only need to run it once.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

assignment expressions will come soon :-P

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

did is fixed in #2193

"A tool snapcraft depends on could not be found: {command!r}.\n"
"Ensure the tool is installed and available, and try again."
)
raise RequiredCommandNotFound(fmt=fmt, command=command_name)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we refactor this error so the message doesn't depend so much on the caller? Is there a reason it isn't setup so we can just pass the missing command to it and use a standard message?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I will create a new one and add a TODO, your suggestion was my original idea, but the changes delve too deep into deprecated logic.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is mitigated in #2193

fmt = (
"An issue was encountered when trying to retrieve the build image for {base!r}.\n"
"The server responded with HTTP status code {status_code!r}.\n"
"Contact the creator of {base!r} for further assistance."
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can make this more succinct and get rid of a newline:

"Failed to retrieve build image for {base!r}:"
"The server responded with HTTP status code {status_code!r}.\n"
Contact the creator of {base!r} for assistance."


fmt = (
"An issue occurred when setting up the build image for this project.\n"
"The command exited with exit code {exit_code!r}."
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This one could be shortened a bit as well, getting rid of the newline.

"Failed to set up the build image for this project:"
"The command exited with exit code {exit_code!r}."

fmt = (
"Cannot find a suitable build image to use to create snaps for the "
"base {base!r} and architecture {snap_arch!r}.\n"
"Contact the creator of {base!r} for further assistance."
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested rewording:

"Cannot find suitable build image for base {base!r} and architecture {snap_arch!r}.\n"
"Contact the creator of {base!r} for assistance."

base="core16",
snap_arch="amd64",
url="https://cloud-images.ubuntu.com/releases/16.04/release-20180703/ubuntu-16.04-server-cloudimg-amd64-disk1.img", # noqa: E501
checksum="79549e87ddfc61b1cc8626a67ccc025cd7111d1af93ec28ea46ba6de70819f8c", # noqa: E501
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I thought we decided to not checksum the images for now?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hm, yes, the notes. I am going on the fact that it is easier to remove this requirement in the future. Also, the fact that we are using this as a backing store means we need to have different entities for each project (related to pruning). I also had download issues :-)

Eventually we could keep this list online and marshal it from some json living on snapcore.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, okay.



def setup(*, base: str, snap_arch: str, size: str, image_path: str) -> None:
"""Setup an instance for base and snap_arch on sized size image_path."""
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not parsing this description: "... on sized size image_path" ? Also, mind adding sphinx docs?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

s/on/of/ :man_shrugging:

# qemu-img parameters:
# -q: quiet.
# -f: first image format.
# -b: backing file.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for this.

base=self.base, status_code=request.status_code
)
# First create the prefix as tempfile.TemporaryDirectory does not do that for you
os.makedirs(self._image_cache.file_cache, exist_ok=True)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

\o/

@@ -0,0 +1,137 @@
# -*- Mode:Python; indent-tabs-mode:nil; tab-width:4 -*-
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you elaborate a little regarding the placement of this file? We have build_providers/_qemu and build_providers/_multipass, and now a build_providers/images.py that is very qemu-specific? What is the plan for multipass support with this interface?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We will use these to launch the mutlipass images too.

@@ -26,12 +26,12 @@
class FileCache(SnapcraftCache):
"""Generic file cache."""

def __init__(self):
def __init__(self, *, taxonomy: str = "files") -> None:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Github decided to hide my comment, so I'll try again:

I don't know what to think when I see "taxonomy" as an argument. It's a field of study. From how it's used, perhaps "namespace" would make more sense?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was having troubles thinking of a word. Your suggestion is so obvious now!

Change get_tool_path to always return an absolute path and fail if
the required command cannot be found.

The unit tests have been adapted to not be path dependent and tests
for retrieving environment dependent paths have been added.

LP: #1785320

Signed-off-by: Sergio Schvezov <sergio.schvezov@canonical.com>
Download the correct build image to build a base for the corresponding architecture.
Use a cached download if available and setup the original build disk image as the
backing store for the newly setup image.

LP: #1782779

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

codecov-io commented Aug 4, 2018

Codecov Report

❗ No coverage uploaded for pull request base (master@1af1ae5). Click here to learn what that means.
The diff coverage is 100%.

Impacted file tree graph

@@            Coverage Diff            @@
##             master    #2192   +/-   ##
=========================================
  Coverage          ?   91.18%           
=========================================
  Files             ?      202           
  Lines             ?    12987           
  Branches          ?     1921           
=========================================
  Hits              ?    11842           
  Misses            ?      777           
  Partials          ?      368
Impacted Files Coverage Δ
snapcraft/internal/cache/_cache.py 100% <ø> (ø)
snapcraft/internal/cache/_file.py 96.66% <100%> (ø)
snapcraft/internal/build_providers/_images.py 100% <100%> (ø)
snapcraft/internal/build_providers/errors.py 100% <100%> (ø)

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 1af1ae5...eba2d20. Read the comment docs.

Copy link
Contributor

@kyrofa kyrofa left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Excellent, thank you!

@sergiusens sergiusens merged commit df9b64d into canonical:master Aug 8, 2018
@sergiusens sergiusens deleted the images branch August 8, 2018 18:08
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.

None yet

3 participants