Skip to content

Conversation

@lucasmoura
Copy link

Add logic to fetch daily images directly from the clouds and not through simplestreams.
Right now we are only supporting this behavior for AWS, Azure and GCP.
Additionally, we are also adding support for launching PRO and FIPS PRO tests for those clouds.

PS: We should still add tests for the new methods here, but first I think we need a fixture that is able to create the cloud instances.
However, I think we can add this into a separate PR.

Copy link
Author

@lucasmoura lucasmoura left a comment

Choose a reason for hiding this comment

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

Also, we should define how the handle the released_images method. On GCP and Azure that method was basically using the daily_image method, so we should be fine. But on AWS, there might be a difference, even though I couldn't find the right owner id for the released images.

So I think we can discuss on how we should support that distinction, daily vs released for AWS.

@lucasmoura lucasmoura force-pushed the fetch-latest-image-from-clouds branch from ec27cab to 18ff0ca Compare June 8, 2022 18:10
Copy link
Contributor

@TheRealFalcon TheRealFalcon left a comment

Choose a reason for hiding this comment

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

This looks good to me, but maybe let one more person review.


GENERIC = "generic"
PRO = "PRO"
PRO_FIPS = "FIPS PRO"
Copy link
Contributor

Choose a reason for hiding this comment

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

Nit: the words in the value are reversed compared to the key. Also, up 2 lines, 'generic' is lowercase whereas the rest of the values are uppercase.

Copy link
Author

Choose a reason for hiding this comment

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

Good catch on reversed name, but the uppercase is just because we usually refer to PRO instances using all letters in uppercase. And since we will surface that name on the Exceptions, I have kept that it just for consistency. But I can update that if necessary

Choose a reason for hiding this comment

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

We should standardize on "Pro" and "Pro FIPS". That is how they're marketed. E.g. https://aws.amazon.com/marketplace/pp/prodview-pfsgbblavhjc4

@paride
Copy link
Collaborator

paride commented Jun 9, 2022

I'm going to try using this in some bootspeed jobs and submit my review, but by reading the code it LGTM.

@paride
Copy link
Collaborator

paride commented Jun 9, 2022

One issue I see is that with this change pycloudlib is unable to find AMIs for the devel release:

In [4]: ec2.daily_image(release='bionic')
Out[4]: 'ami-0e8597a872ec674ee'

In [5]: ec2.daily_image(release='kinetic')
---------------------------------------------------------------------------
Exception                                 Traceback (most recent call last)
<ipython-input-5-8e5735439f6c> in <module>
----> 1 ec2.daily_image(release='kinetic')

~/ubuntu/git/pycloudlib/pycloudlib/ec2/cloud.py in daily_image(self, release, arch, image_type)
    174         """
    175         self._log.debug("finding daily Ubuntu image for %s", release)
--> 176         image = self._find_latest_image(
    177             release=release, arch=arch, image_type=image_type
    178         )

~/ubuntu/git/pycloudlib/pycloudlib/ec2/cloud.py in _find_latest_image(self, release, arch, image_type)
    152 
    153         if not images.get("Images"):
--> 154             raise Exception(
    155                 "Could not find {} image for {} release".format(
    156                     image_type.value, release

Exception: Could not find generic image for kinetic release

@lucasmoura
Copy link
Author

Good point, I will double check if we have a specific owner for launching the kinetic image on AWS

@lucasmoura
Copy link
Author

@paride @TheRealFalcon code updated

@paride
Copy link
Collaborator

paride commented Jun 10, 2022

@lucasmoura are you sure you pushed the latest changes? I still see 18ff0ca on the tip of your branch.

@lucasmoura lucasmoura force-pushed the fetch-latest-image-from-clouds branch from 18ff0ca to fe17ce2 Compare June 10, 2022 13:44
@lucasmoura
Copy link
Author

lucasmoura commented Jun 10, 2022

I have pushed to the wrong branch 🤦
Now it is updated @paride

@lucasmoura lucasmoura force-pushed the fetch-latest-image-from-clouds branch from fe17ce2 to be14641 Compare June 10, 2022 14:14
@paride
Copy link
Collaborator

paride commented Jun 10, 2022

I think I found two more issues:

  1. EC2 daily_image() used to accept amd64 as the arch, while now it wants x86_64. Reproducer: ec2.daily_image('bionic', arch='x86_64'). I think specifying the Ubuntu arch name (amd64) makes sense for pycloudlib.
  2. The image serial lookup (still based on streams) doesn't work:
In [11]: image = ec2.daily_image('bionic')

In [12]: ec2.image_serial(image)
---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
<ipython-input-12-c36dc0d66013> in <module>
----> 1 ec2.image_serial(image)

~/ubuntu/git/pycloudlib/pycloudlib/ec2/cloud.py in image_serial(self, image_id)
    198         )
    199         filters = ["id=%s" % image_id]
--> 200         image_info = self._streams_query(filters, daily=True)
    201         if not image_info:
    202             image_info = self._streams_query(filters, daily=False)

~/ubuntu/git/pycloudlib/pycloudlib/cloud.py in _streams_query(filters, daily)
    219         result = stream.query(filters)
    220         if not result:
--> 221             raise ValueError(f"No images found matching filters: {filters}")
    222 
    223         return result

ValueError: No images found matching filters: ['id=ami-0e8597a872ec674ee']

@lucasmoura
Copy link
Author

lucasmoura commented Jun 13, 2022

@paride okay, just addressing the points you made:

  1. Yes, I agree that keeping amd64 would be better, but on aws we cannot use it directly as an architecture filter, as can be seen here:

https://docs.aws.amazon.com/cli/latest/reference/ec2/describe-images.html

We could map amd64into the x86_64 string if you think it is needed.

  1. That one is a little odd. I have identified the image location simplestreams is using and applied it for the new aws image query. The problem is that by querying aws directly, we can fetch images that are newer than the ones on simplestreams, which will cause the problem we are seeing. This can be seen when we try to use xenial using the new name filter I have commented about.

Also, I realized that the image_serial function is also not working for the released images, which were not modified in this PR.
With that said, @paride what do you think should be the best plan forward ? I could try to also adapt image_serial to fetch the cloud directly, by I need to double check if the information is surfaced through the clouds.

PS: I have pushed the new daily name filter on this PR, so you can check the Xenial issue I have described.

@paride
Copy link
Collaborator

paride commented Jun 14, 2022

@lucasmoura apparently the image serial is exposed via the image Name, see for example ami-03d0d5c3a4731a9dd (region: us-west-1), which has serial 20210329.1:

aws --region us-west-1 ec2 describe-images --image-ids ami-03d0d5c3a4731a9dd                                                                                                                
{
    "Images": [
        {
            "Architecture": "x86_64",
            "CreationDate": "2021-03-30T17:42:49.000Z",
            "ImageId": "ami-03d0d5c3a4731a9dd",
            "ImageLocation": "ubuntu-images-us-west-1-release/xenial/20210329.1/hvm/instance-store/image.img.manifest.xml",
            "ImageType": "machine",
            "Public": true,
            "OwnerId": "099720109477",
            "PlatformDetails": "Linux/UNIX",
            "UsageOperation": "RunInstances",
            "State": "available",
            "BlockDeviceMappings": [],
            "Description": "Canonical, Ubuntu, 16.04 LTS, amd64 xenial image build on 2021-03-29",
            "EnaSupport": true,
            "Hypervisor": "xen",
            "Name": "ubuntu/images/hvm-instance/ubuntu-xenial-16.04-amd64-server-20210329.1",
            "RootDeviceType": "instance-store",
            "SriovNetSupport": "simple",
            "VirtualizationType": "hvm",
            "DeprecationTime": "2023-03-30T17:42:49.000Z"
        }
    ]
}

If that's stable (let's ask CPC?) maybe we can extract the serial from there.

@paride
Copy link
Collaborator

paride commented Jun 14, 2022

On the arch name (amd64 vs x86_64): I am not sure. From one side I see pycloudlib as Ubuntu-centric, so I'd like too keep the Ubuntu arch names. OTOH the amd64 <-> x86_64 mapping works well only until there's a simple bijective mapping. Things may become ugly if Ubuntu amd64v2 is released (compiled a with higher baseline for the arch, this is in the talks), or even worse if ec2 starts offering x86_64v2 before Ubuntu releases amd64v2 (e.g. because CPC prepares higher performance builds for some instance types - completely hypothetical not impossible I think). So maybe in the end it's better to keep it simple and use the cloud arch names with no mappings.

@paride
Copy link
Collaborator

paride commented Jun 15, 2022

On daily_image() vs released_image(), note that for a released image we have:

$ aws --region us-east-2 ec2 describe-images --image-id ami-05a2de8ec6f3e7b61
[...]
            "Name": "ubuntu/images/hvm-ssd/ubuntu-jammy-22.04-amd64-server-20220609",

while for a daily image:

$ aws --region us-east-2 ec2 describe-images --image-id ami-02f3416038bdb17fb
[...]
            "Name": "ubuntu/images-testing/hvm-ssd/ubuntu-jammy-daily-amd64-server-20220609",

so maybe the trick is to search for images by Name (given that the format is fixed), and use /images-testing/ for dailies, and /images/ for released images.

@lucasmoura
Copy link
Author

@paride I have updated the code for ec2 to fetch released images directly from AWS while also fixing the image_serial issue that was raised

Copy link
Collaborator

@paride paride left a comment

Choose a reason for hiding this comment

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

Nice! But it doesn't seem to be working yet for released images:

In [13]: ec2 = pycloudlib.EC2(tag='foo', region='us-east-1')

In [14]: ec2.released_image('focal')
Out[14]: 'ami-031cf125b681ca3e0'

In [15]: ec2.image_serial('ami-031cf125b681ca3e0')
---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
<ipython-input-15-3b7825534dd7> in <module>
----> 1 ec2.image_serial('ami-031cf125b681ca3e0')

~/ubuntu/git/pycloudlib/pycloudlib/ec2/cloud.py in image_serial(self, image_id)
    241         )
    242         filters = ["id=%s" % image_id]
--> 243         image_info = self._streams_query(filters, daily=True)
    244         if not image_info:
    245             image_info = self._streams_query(filters, daily=False)

~/ubuntu/git/pycloudlib/pycloudlib/cloud.py in _streams_query(filters, daily)
    219         result = stream.query(filters)
    220         if not result:
--> 221             raise ValueError(f"No images found matching filters: {filters}")
    222 
    223         return result

ValueError: No images found matching filters: ['id=ami-031cf125b681ca3e0']

For this AMI the serial is there:

$ aws --profile cloud-init --region us-east-1 ec2 describe-images --image-id ami-031cf125b681ca3e0
[...]
            "Name": "ubuntu/images/hvm-ssd/ubuntu-focal-20.04-amd64-server-20220615",

@paride
Copy link
Collaborator

paride commented Jun 20, 2022

Also: can you please rebase on main? The change that just landed there will make it easier to test your branch with the bootspeed jobs. Thanks!

@lucasmoura lucasmoura force-pushed the fetch-latest-image-from-clouds branch from e0bf197 to 8e48360 Compare June 20, 2022 20:05
@lucasmoura lucasmoura force-pushed the fetch-latest-image-from-clouds branch from 8e48360 to 289f2c7 Compare June 20, 2022 20:06
@lucasmoura
Copy link
Author

@paride I forgot one last bit 🤦, but it is fixed now.
And I have also rebased on main

Copy link
Collaborator

@paride paride left a comment

Choose a reason for hiding this comment

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

LGTM, also tested in Jenkins with the bootspeed jobs and it works fine. We don't have image_serial() for non-EC2 clouds, but I think that's fine for now, we can add it if/once needed. Thanks for addressing all the review comments!

@TheRealFalcon
Copy link
Contributor

@lucasmoura , is there anything else to do here?

@lucasmoura
Copy link
Author

@TheRealFalcon I was just waiting for a review from someone on the UA team for the PRO machines. But I think we can merge and if we find a bug I can come up with a follow up PR

Copy link

@orndorffgrant orndorffgrant left a comment

Choose a reason for hiding this comment

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

@lucasmoura

Just a nitpick on the naming: We should standardize on "Pro" and "Pro FIPS". That is how they're marketed. E.g. https://aws.amazon.com/marketplace/pp/prodview-pfsgbblavhjc4

@lucasmoura
Copy link
Author

@orndorffgrant done

Copy link

@orndorffgrant orndorffgrant left a comment

Choose a reason for hiding this comment

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

Thanks @lucasmoura and sorry for the nitpick :)

@lucasmoura
Copy link
Author

@orndorffgrant no worries at all

Copy link
Collaborator

@paride paride left a comment

Choose a reason for hiding this comment

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

looks good, +1 again!

@paride
Copy link
Collaborator

paride commented Jul 12, 2022

@lucasmoura do you think this is good to land?

@lucasmoura
Copy link
Author

Yes, merging it right now

@lucasmoura lucasmoura merged commit 0a55726 into canonical:main Jul 12, 2022
@lucasmoura lucasmoura deleted the fetch-latest-image-from-clouds branch July 12, 2022 16:48
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.

4 participants