Join GitHub today
GitHub is home to over 20 million developers working together to host and review code, manage projects, and build software together.
Bug 1690456: validate directory provided by --metadata-url during bootstrap #7354
Conversation
wallyworld
requested changes
May 17, 2017
Please also expand the PR description to explain the issue
| - tools.DefaultBaseURL = metadataDir | ||
| + if _, err := os.Stat(metadataDir); err != nil { | ||
| + if !os.IsNotExist(err) { | ||
| + return nil, errors.Annotate(err, "cannot access metadata directory") |
| + if !os.IsNotExist(err) { | ||
| + return nil, errors.Annotate(err, "cannot access metadata directory") | ||
| + } | ||
| + logger.Infof("metadata source: %s, not found", metadataDir) |
wallyworld
May 17, 2017
Owner
We should return a not found error here so it bubbles up and aborts bootstrap
return errors.NotFoundf("simplestreams metadata source directory %v", metadataDir)
| + if !os.IsNotExist(err) { | ||
| + return nil, errors.Annotate(err, "cannot access tools metadata") | ||
| + } | ||
| + logger.Infof("default tools metadata source: %s", tools.DefaultBaseURL) |
| + } | ||
| + logger.Infof("default tools metadata source: %s", tools.DefaultBaseURL) | ||
| + } else { | ||
| + logger.Infof("setting default tools metadata source: %s", toolsMetadataDir) |
| + logger.Infof("default tools metadata source: %s", tools.DefaultBaseURL) | ||
| + } else { | ||
| + logger.Infof("setting default tools metadata source: %s", toolsMetadataDir) | ||
| + tools.DefaultBaseURL = metadataDir |
wallyworld
May 17, 2017
Owner
we only want to do this if metadataDir ends with /tools
so the logic for this block should be:
toolsMetadataDir = metadataDir
if not toolsMetadataDir endswith /tools then
toolsMetadataDir += /tools
if toolsMetadataDir exists then
tools.DefaultBaseURL = toolsMetadataDir
| + } else { | ||
| + logger.Infof("setting default tools metadata source: %s", toolsMetadataDir) | ||
| + tools.DefaultBaseURL = metadataDir | ||
| + } | ||
| imageMetadataDir := filepath.Join(metadataDir, storage.BaseImagesPath) |
wallyworld
May 17, 2017
Owner
we want the same logic as for tools above.
ie
the user can specify --metadata-source as one of:
somedir
somedir/tools
somedir/images
and the logic should Do The Right Thing
|
working on tests now. |
jameinel
changed the title from
Bug 1690456: validate directory provided by --metadata-url during
to
Bug 1690456: validate directory provided by --metadata-url during bootstrap
May 20, 2017
jameinel
requested changes
May 20, 2017
I tweaked your review request comment so that it formats correctly as Markdown.
I do think a better fix would be to not overload one CLI arg to mean 2 possible things. In config we have 'image-metadata-url' and 'agent-metadata-url' as 2 different config options that can be set, we probably shouldn't have a single CLI arg that means both of them.
(we probably have to keep it for compatibility, but I think we can add more for users to be clearer about what they are doing.)
| ) | ||
| c.Check(s.tw.Log(), jc.LogMatches, []jc.SimpleMessage{ | ||
| - {loggo.ERROR, "failed to bootstrap model: cannot package bootstrap agent binary: no agent binaries for you"}, | ||
| + {loggo.ERROR, "failed to bootstrap model: no matching tools available"}, |
jameinel
May 20, 2017
Owner
'agent binaries' is the preferred name to 'matching tools'.
Mark especially doesn't like the word 'tools' and we should avoid using it in messages to users.
wallyworld
May 22, 2017
Owner
There's still legacy error messages floating around - agree it would be good to fix those as a driveby. We should also support looking for "agents" as well as "tools" as a sub dir under metadatasource dir.
hmlanigan
May 22, 2017
Member
The wording update in this specific case will be addressed in a follow-on PR, as will
looking for an 'agents' directory.
| -// for tools syncing, and adds an image metadata source after verifying | ||
| -// the contents. | ||
| +// setPrivateMetadataSources verifys the metadataDir and uses it to | ||
| +// set the default tools metadata source for tools syncing, and adds |
jameinel
May 20, 2017
Owner
s/tools/agent binaries/
I realize we're currently looking for a directory ending in 'tools' but telling people 'we find agent binaries in a directory named tools' is still clearer what we are actually looking for. 'tools' could be anything (such as helper commands, eg juju-metadata, etc).
| + } else { | ||
| + if ending == storage.BaseToolsPath { | ||
| + tools.DefaultBaseURL = filepath.Dir(metadataDir) | ||
| + logger.Debugf("setting default tools metadata source: %s", tools.DefaultBaseURL) |
jameinel
May 20, 2017
Owner
agent binaries
especially given the config option would be "agent-metadata-url"
|
@jameinel the reason for one directory is that the user can choose to put there whatever necessary metadata is needed. They may want to provide image metadata, agent metadata, or both. They do this by using sub directories "images" or "tools" <- yes, "tools" is outdated. We should add support for "agents" as well. Regardless, the --metadata-source dir is meant to be the top level dir which contains sub dirs. The issue addressed here is partly a bug (Juju wasn't checking the validity of the dir supplied), but also a usability issue - people have been specifying a full path to "sourcedir/images" instead of "sourcedir". So part of the change here is to support DWIM. |
|
!!testme!! |
wallyworld
approved these changes
May 23, 2017
Thank you. Might be worth re-doing the manual QA just to be sure given the changes done
| -// setPrivateMetadataSources sets the default tools metadata source | ||
| -// for tools syncing, and adds an image metadata source after verifying | ||
| -// the contents. | ||
| +// setPrivateMetadataSources verifys the metadataDir and uses it to |
| -// the contents. | ||
| +// setPrivateMetadataSources verifys the metadataDir and uses it to | ||
| +// set the default agent binaries metadata source for agent binary | ||
| +// syncing, and adds an image metadata source after verifying the |
| +// set the default agent binaries metadata source for agent binary | ||
| +// syncing, and adds an image metadata source after verifying the | ||
| +// contents. If the directory ends in tools, only the default tools | ||
| +// metadata source will be set. Same for images. |
| + if !os.IsNotExist(err) { | ||
| + return nil, errors.Annotate(err, "cannot access agent binary metadata") | ||
| + } | ||
| + logger.Debugf("default agent binary metadata source: %s", tools.DefaultBaseURL) |
wallyworld
May 23, 2017
Owner
can we reword to "no agent directory found, using default agent binary....."
| + if ending == storage.BaseToolsPath { | ||
| + tools.DefaultBaseURL = filepath.Dir(metadataDir) | ||
| + logger.Debugf("setting default agent binary metadata source: %s", tools.DefaultBaseURL) | ||
| + return nil, nil |
| +// juju bootstrap --metadata-source <dir> | ||
| +// juju bootstrap --metadata-source <dir>/images | ||
| +// where <dir>/tools doesn't exist | ||
| +func (s *bootstrapSuite) TestBootstrapMetadataImagesNoTools(c *gc.C) { |
wallyworld
May 23, 2017
Owner
this should either be 2 tests, or a single test inside a for loop
metadataDir, _ := createImageMetadata(c)
for _, suffix := range []string{"", "images"} {
sourceDir := filepath.Join(metadataDir, suffix)
do test stuff...
}
| +// juju bootstrap --metadata-source <dir> | ||
| +// juju bootstrap --metadata-source <dir>/tools | ||
| +// where <dir>/images doesn't exist | ||
| +func (s *bootstrapSuite) TestBootstrapMetadataToolsNoImages(c *gc.C) { |
|
manual QA has been done on the last changes. |
|
$$merge$$ |
|
Status: merge request accepted. Url: http://juju-ci.vapour.ws:8080/job/github-merge-juju |
|
Build failed: Tests failed |
|
$$merge$$ |
|
Status: merge request accepted. Url: http://juju-ci.vapour.ws:8080/job/github-merge-juju |
hmlanigan commentedMay 17, 2017
•
Edited 1 time
-
jameinel
May 18, 2017
If the directory ends in 'tools' or images', assume
that only the respective value will be used. If a high level
directory is listed, check for tools and images in it. If no
tools are listed, use tools from streams.canonical.com.
Description of change
Attempting to anticipate what users intend with bootstrap --metadata-source.
The contents of tools and images are validated further on.
QA steps
Bootstrap openstack with arm64 nova compute nodes from a host machine with an a
different processor (arm64), don't use a nightly build to test as tools for nightly are not
on streams.canonical.com. - to verify bug fix.
Unit tests will be updated to verify the listed possibilities.
Documentation changes
N/A
Bug reference
https://bugs.launchpad.net/juju/+bug/1690456