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

Add glance-simplestreams-sync --set-latest-property functest #853

Conversation

guimaluf
Copy link
Contributor

@guimaluf guimaluf commented Aug 5, 2022

When creating Openstack VMs the user has to specify the image it wants
to use. sstream-mirror-glance adds a date to the image name, so they
always have to recheck which is the current latest image.

This commit tests the usage of the set-latest-property configuration.

When set-latest-property is given sstream-mirror-glance will set the
recently synced image with the latest=true property and then remove
the latest property from all the os_version/architecture matching
images.

Closes-bug: LP #1933130

Copy link
Collaborator

@ajkavanagh ajkavanagh left a comment

Choose a reason for hiding this comment

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

Thanks for the patch; it looks like it is starting to get there. A couple of minor nitpicks, but also a significant issue with the async nature of the models and the code driving them. e.g. config changed -> "config-changed" hook, but that runs asynchronously to the code that starts it. Please take a look at the comments. Thanks.

@guimaluf guimaluf force-pushed the g-s-s_set-latest-property_functest branch 4 times, most recently from d571d81 to e9708be Compare August 8, 2022 09:56
Copy link
Collaborator

@ajkavanagh ajkavanagh left a comment

Choose a reason for hiding this comment

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

So I've taken a step back, and instead of just concentrating on the code in this review, I looked at the associated bug. I'm pretty sure that the code that this might be testing doesn't do what the bug reporter wants: a named alias for the 'latest' version of a particular synced image type.

This code appears to be testing 'adding a property to every image and calling that latest' which doesn't seem that useful to be honest.

I think this solution should be revisited - perhaps email the opendev mailing list, or contact the team via a channel, and see if we can move this forward. Thanks.

@guimaluf
Copy link
Contributor Author

guimaluf commented Aug 8, 2022

I've discussed with @wolsen and @freyes about this topic. it was suggested that instead of changing the name of the image I should add the latest attribute.

I'm probably not doing in the best way, but if you look at my proposal for simplestreams I'm removing the latest property from all other images while letting only the last one synced.

diff --git a/simplestreams/mirrors/glance.py b/simplestreams/mirrors/glance.py
index 9181e9c..b96f8eb 100644
--- a/simplestreams/mirrors/glance.py
+++ b/simplestreams/mirrors/glance.py
@@ -517,6 +523,20 @@ class GlanceMirror(mirrors.BasicMirrorWriter):
 
             print("created %s: %s" % (glance_image.id, full_image_name))
 
+            # TODO(guimalufb) use self.loaded_content or
+            # self.load_products() instead
+            if self.set_latest_property:
+                # Search all images with the same target attributtes
+                _filter_properties = {'filters': {
+                    'latest': 'true',
+                    'os_version': glance_props['os_version'],
+                    'architecture': glance_props['architecture']}}
+                images = self.gclient.images.list(**_filter_properties)
+                for image in images:
+                    if image.id != glance_image.id:
+                        self.gclient.images.update(image.id,
+                                                   remove_props=['latest'])
+

I'd like to test having an image with the latest and then a new image on top. but I have no idea how to force that scenario.

thanks for you careful review!

@guimaluf guimaluf force-pushed the g-s-s_set-latest-property_functest branch from e9708be to 03b2176 Compare August 8, 2022 12:18
@ajkavanagh
Copy link
Collaborator

I've discussed with @wolsen and @freyes about this topic. it was suggested that instead of changing the name of the image I should add the latest attribute.

Okay, at the very least, please go back to the bug and outline the solution so that the bug submitter can take a look at agree/disagree that it solves their problem. Otherwise, whilst it may be a solution, it simply may not work for the bug submitter and their tools.

I'm probably not doing in the best way, but if you look at my proposal for simplestreams I'm removing the latest property from all other images while letting only the last one synced.

That's why I couldn't find the change. This change needs to be on gerrit (review.opendev.org), NOT on launchpad. If you take a look at the code page (https://code.launchpad.net/charm-glance-simplestreams-sync) you'll see that it syncs the code from https://opendev.org/openstack/charm-glance-simplestreams-sync.git - any changes you attempt to make on LP will a) not be merged, and b) if they were, overwritten by a sync. Please re-do your PR on opendev.

diff --git a/simplestreams/mirrors/glance.py b/simplestreams/mirrors/glance.py
index 9181e9c..b96f8eb 100644
--- a/simplestreams/mirrors/glance.py
+++ b/simplestreams/mirrors/glance.py
@@ -517,6 +523,20 @@ class GlanceMirror(mirrors.BasicMirrorWriter):
 
             print("created %s: %s" % (glance_image.id, full_image_name))
 
+            # TODO(guimalufb) use self.loaded_content or
+            # self.load_products() instead
+            if self.set_latest_property:
+                # Search all images with the same target attributtes
+                _filter_properties = {'filters': {
+                    'latest': 'true',
+                    'os_version': glance_props['os_version'],
+                    'architecture': glance_props['architecture']}}
+                images = self.gclient.images.list(**_filter_properties)
+                for image in images:
+                    if image.id != glance_image.id:
+                        self.gclient.images.update(image.id,
+                                                   remove_props=['latest'])
+

I'd like to test having an image with the latest and then a new image on top. but I have no idea how to force that scenario.

Yes, that's tricky from a functional/integration test scenario. Best approach would be to verify that functionality using unit tests and mocking out simplestreams (or even in the g-sss (glance-simplestreams-sync) charm itself).

thanks for you careful review!

No problem. :)

@guimaluf
Copy link
Contributor Author

guimaluf commented Aug 8, 2022

Okay, at the very least, please go back to the bug and outline the solution so that the bug submitter can take a look at agree/disagree that it solves their problem. Otherwise, whilst it may be a solution, it simply may not work for the bug submitter and their tools.

done!

That's why I couldn't find the change. This change needs to be on gerrit (review.opendev.org), NOT on launchpad. If you take a look at the code page (https://code.launchpad.net/charm-glance-simplestreams-sync) you'll see that it syncs the code from https://opendev.org/openstack/charm-glance-simplestreams-sync.git - any changes you attempt to make on LP will a) not be merged, and b) if they were, overwritten by a sync. Please re-do your PR on opendev.

my bad. I ran git review for the simplestreams repository and it didn't work, thus I assumed it would work for g-s-s.
done!

Yes, that's tricky from a functional/integration test scenario. Best approach would be to verify that functionality using unit tests and mocking out simplestreams (or even in the g-sss (glance-simplestreams-sync) charm itself).

That has been done on simplestreams repository

@guimaluf guimaluf force-pushed the g-s-s_set-latest-property_functest branch 2 times, most recently from 7009710 to 1d19b6a Compare September 2, 2022 08:05
When creating Openstack VMs the user has to specify the image it wants
to use. sstream-mirror-glance adds a date to the image name, so they
always have to recheck which is the current latest image.

This commit tests the usage of the `set_latest_property` configuration.

When --set-latest-property is given sstream-mirror-glance will set the
recently synced image with the `latest=true` property and then remove
the `latest` property from all the os_version/architecture matching
images.

Closes-bug: LP #1933130

Use simplestreams edge channel to test set-latest-property
@guimaluf guimaluf force-pushed the g-s-s_set-latest-property_functest branch from 1d19b6a to 60557c2 Compare September 22, 2022 08:35
openstack-mirroring pushed a commit to openstack/charm-glance-simplestreams-sync that referenced this pull request Sep 26, 2022
When creating Openstack VMs the user has to specify the image it wants
to use. sstream-mirror-glance adds a date to the image name, so they
always have to recheck which is the current latest image.

This commit adds the `set_latest_property` configuration to include
--set-latest-property to sstream-mirror-glance command line argument.

When --set-latest-property is given sstream-mirror-glance will set the
recently synced image with the `latest=true` property and then remove
the `latest` property from all the os_version/architecture matching
images.

Configure bundles to fetch simplestreams snap from edge channel

Closes-bug: #1933130
Change-Id: Idf78294db7abb8c81d637086e8142782bf1dd36f
Func-Test-PR: openstack-charmers/zaza-openstack-tests#853
openstack-mirroring pushed a commit to openstack/openstack that referenced this pull request Sep 26, 2022
* Update charm-glance-simplestreams-sync from branch 'master'
  to 4754aca4209d1d18854b05360953bd5ba33cd668
  - Add set_latest_property config to new image
    
    When creating Openstack VMs the user has to specify the image it wants
    to use. sstream-mirror-glance adds a date to the image name, so they
    always have to recheck which is the current latest image.
    
    This commit adds the `set_latest_property` configuration to include
    --set-latest-property to sstream-mirror-glance command line argument.
    
    When --set-latest-property is given sstream-mirror-glance will set the
    recently synced image with the `latest=true` property and then remove
    the `latest` property from all the os_version/architecture matching
    images.
    
    Configure bundles to fetch simplestreams snap from edge channel
    
    Closes-bug: #1933130
    Change-Id: Idf78294db7abb8c81d637086e8142782bf1dd36f
    Func-Test-PR: openstack-charmers/zaza-openstack-tests#853
@ChrisMacNaughton
Copy link
Collaborator

Landing this change but only after raising #947 to resolve the strangely placed config setting

@ChrisMacNaughton ChrisMacNaughton merged commit 98faf67 into openstack-charmers:master Oct 7, 2022
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