Scope GetTemplateByName/GetIsoByName by-ID lookup to the zone (#87)#153
Open
jmsperu wants to merge 1 commit into
Open
Scope GetTemplateByName/GetIsoByName by-ID lookup to the zone (#87)#153jmsperu wants to merge 1 commit into
jmsperu wants to merge 1 commit into
Conversation
) GetTemplateByName (and GetIsoByName) resolve the id with the zoneid constraint via GetTemplateID, then call GetTemplateByID/GetIsoByID WITHOUT the zone. A template/ISO registered in multiple zones lists one row per zone for the same UUID, so the helper fails with 'There is more then one result for Template UUID: ...!' (apache#87). Fix the generator to pass the zone into the by-ID lookup via the existing WithZone option for Template/Iso, and apply it to the two generated helpers. WithZone is a no-op on empty zoneid and uses the id directly for a UUID. Adds a regression test reproducing apache#87. Signed-off-by: James Peru <james@xcobean.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #87.
Problem
GetTemplateByNameresolves the template id with thezoneidconstraint (viaGetTemplateID), but then callsGetTemplateByIDwithout it:A template registered in multiple zones lists one row per zone for the same UUID, so the by-id lookup returns
count > 1and the helper fails:GetIsoByNamehas the identical issue.Fix
These helpers are generated, so the fix is in the generator (
generate/generate.go): forTemplate/Iso, pass the zone into the by-ID lookup using the existingWithZoneoption, then apply it to the two generated helpers:WithZoneis a no-op whenzoneidis empty and sets the id directly when given a UUID (no extra lookup), so this is safe and adds no API calls.Test
Adds
test/GetTemplateByNameZoneRegression_test.go: the mock returns two rows for the unscoped by-id lookup and one whenzoneidis present. It fails with the exactThere is more then one resulterror on currentmainand passes with the fix.Verification
go build ./...— cleango test ./test/ -run TestGetTemplateByNameScopesByIDLookupToZone— passes (and fails with the GetTemplateByName with zoneid constraint fails on template in multiple zones #87 error when the fix is reverted)