Merge ~ajorgens/cloud-init:_include-urlerror into cloud-init:master
| Status: | Merged |
|---|---|
| Approved by: | Scott Moser on 2017-11-13 |
| Approved revision: | f9e35a63caeda8eef72140145815421d1bc1f90f |
| Merged at revision: | e10ad2d7854b87024b5d051db50166125fce2279 |
| Proposed branch: | ~ajorgens/cloud-init:_include-urlerror |
| Merge into: | cloud-init:master |
| Diff against target: |
113 lines (+68/-10) 2 files modified
cloudinit/user_data.py (+18/-10) tests/unittests/test_data.py (+50/-0) |
| Related bugs: |
| Reviewer | Review Type | Date Requested | Status |
|---|---|---|---|
| Scott Moser | 2017-10-02 | Approve on 2017-11-13 | |
|
Review via email:
|
|||
Commit Message
Catch UrlError when #include'ing URLs
Without this the entire stage can fail, which will leave an instance
unaccessible.
Description of the Change
Catch UrlError when #include'ing URLs
Without this the entire stage can fail, which will leave an instance unaccessible.
| Scott Moser (smoser) wrote : | # |
| Andrew Jorgensen (ajorgens) wrote : | # |
Revised commit per smoser's advice.
| Ryan Harper (raharper) wrote : | # |
On Tue, Oct 3, 2017 at 8:23 AM, Scott Moser <email address hidden> wrote:
> i approve with 2 small questions in line.
>
>
> Diff comments:
>
> > diff --git a/cloudinit/
> > index 88cb7f8..de459c9 100644
> > --- a/cloudinit/
> > +++ b/cloudinit/
> > @@ -222,16 +223,25 @@ class UserDataProcess
> > if include_once_on and os.path.
> > content = util.load_
> > else:
> > - resp = util.read_
> > -
> ssl_details=
> > - if include_once_on and resp.ok():
> > - util.write_
> mode=0o600)
> > - if resp.ok():
> > - content = resp.contents
> > - else:
> > - LOG.warning(
> > - " a invalid http code of %s"),
> > - include_url, resp.code)
> > + try:
> > + resp = util.read_
> > +
> ssl_details=
> > + if include_once_on and resp.ok():
> > + util.write_
> > + mode=0o600)
> > + if resp.ok():
> > + content = resp.contents
> > + else:
> > + LOG.warning(
> > + " a invalid http code of %s"),
> > + include_url, resp.code)
> > + except UrlError as urle:
> > + LOG.warning(
> > + "Fetching from %s resulted in a UrlError: %s",
> > + include_url, urle.cause)
>
> i think just printing urle here in its string form should be reasonable.
> str(urle) would look like:
> cloudinit.
> http://
> str(urle.cause) would look like:
> requests.
> http://
>
> > + except IOError as ioe:
> > + LOG.warning(
> IOError: %s",
> > + include_url, ioe.strerror)
>
> i guess fine, but is there a reason for 'ioe.strerror' rather than just
> str(ioe) ?
>
> >
> > if content is not None:
> > new_msg = convert_
>
>
In both cases, using an attribute which is already a string will be faster
than calling str() which introduces some lookup and call overhead.
In an exception path, I don't think this matters; however generally I would
say we should avoid
additional function calls if they're not needed.
| Andrew Jorgensen (ajorgens) wrote : | # |
> In an exception path, I don't think this matters;
Do I take this to mean it's okay as it is now, and you approve? Or would you like me to undo the change that Scott suggested before it gets merged?
| Ryan Harper (raharper) wrote : | # |
On Wed, Oct 4, 2017 at 9:28 AM, Andrew Jorgensen <email address hidden>
wrote:
> > In an exception path, I don't think this matters;
>
> Do I take this to mean it's okay as it is now, and you approve? Or would
> you like me to undo the change that Scott suggested before it gets merged?
>
That was a comment for Scott; I'm find with his suggested change; I just
wanted to comment on the general case w.r.t
str() vs. %s formatting overhead.
> --
> https:/
> cloud-init/
> Your team cloud-init commiters is requested to review the proposed merge
> of ~ajorgens/
>
> _______
> Mailing list: https:/
> Post to : <email address hidden>
> Unsubscribe : https:/
> More help : https:/
>
| Scott Moser (smoser) wrote : | # |
@Ryan,
str(foo) == '%s' % foo.
In my comments i was not suggessting that we should use 'str(foo)', but just that the we should print the string representation of the error rather than error.cause.


i approve with 2 small questions in line.