How do you know what variables are frozen?

16 vues
Accéder directement au premier message non lu

Trevor Vaughan

non lue,
15 juil. 2015, 11:59:1615/07/2015
à puppe...@googlegroups.com
I *think* I've just run into a case where I was trying to run strip! on a frozen Facter variable.

1) How do we know what variables are frozen coming from Facter?
2) What is the best way to ensure that our tests check for this case?

Thanks,

Trevor

--
Trevor Vaughan
Vice President, Onyx Point, Inc
(410) 541-6699

-- This account not approved for unencrypted proprietary information --

Peter Huene

non lue,
15 juil. 2015, 12:18:3215/07/2015
à puppe...@googlegroups.com
On Wed, Jul 15, 2015 at 8:59 AM, Trevor Vaughan <tvau...@onyxpoint.com> wrote:
I *think* I've just run into a case where I was trying to run strip! on a frozen Facter variable.

1) How do we know what variables are frozen coming from Facter?

Facter shouldn't be freezing resolved fact values, so is this something that a custom fact is explicitly doing to the returned value?

http://ruby-doc.org/core-2.2.2/Object.html#method-i-frozen-3F should work for checking in an object is frozen, though.
 
2) What is the best way to ensure that our tests check for this case?

Thanks,

Trevor

--
Trevor Vaughan
Vice President, Onyx Point, Inc
(410) 541-6699

-- This account not approved for unencrypted proprietary information --

--
You received this message because you are subscribed to the Google Groups "Puppet Developers" group.
To unsubscribe from this group and stop receiving emails from it, send an email to puppet-dev+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/puppet-dev/CANs%2BFoW0ovdB6E%3DLTFtD7Er126StgUyuaTpB89n2Bz%2BFminS7w%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.



--
Join us at PuppetConf 2015, October 5-9 in Portland, OR - www.2015.puppetconf.com 
Register early to save 40%!

R.I.Pienaar

non lue,
15 juil. 2015, 12:21:4415/07/2015
à puppet-dev


----- Original Message -----
> From: "Peter Huene" <peter...@puppetlabs.com>
> To: "puppet-dev" <puppe...@googlegroups.com>
> Sent: Wednesday, July 15, 2015 5:18:29 PM
> Subject: Re: [Puppet-dev] How do you know what variables are frozen?

> On Wed, Jul 15, 2015 at 8:59 AM, Trevor Vaughan <tvau...@onyxpoint.com>
> wrote:
>
>> I *think* I've just run into a case where I was trying to run strip! on a
>> frozen Facter variable.
>>
>> 1) How do we know what variables are frozen coming from Facter?
>>
>
> Facter shouldn't be freezing resolved fact values, so is this something
> that a custom fact is explicitly doing to the returned value?
>
> http://ruby-doc.org/core-2.2.2/Object.html#method-i-frozen-3F should work
> for checking in an object is frozen, though.
>

but surely you should just assume you cant change variables especially facts?
since that's their intended use, no modifying of variables?

Be interesting to hear why a fact is being tripped in a destructive way :)

Trevor Vaughan

non lue,
15 juil. 2015, 14:50:3915/07/2015
à puppe...@googlegroups.com
In this case, it was a custom function that was tripping things up.

Looking through the code, I *think* this was the scenario:

1) Fact => trusted['certname']
2) Function call to parse_host($trusted['certname'])
3) Parse host:

host = args.first
host.strip! # Here's the offender

I also tried seeing if dup'ing the args would work, but it copies the frozen attribute with the String object (which makes sense).

So, I don't know if I was trying to modify something from a Fact or if the object just happened to be carrying the 'frozen' status as it went along.

Thanks,

Trevor

--
You received this message because you are subscribed to the Google Groups "Puppet Developers" group.
To unsubscribe from this group and stop receiving emails from it, send an email to puppet-dev+...@googlegroups.com.

For more options, visit https://groups.google.com/d/optout.



--

R.I.Pienaar

non lue,
15 juil. 2015, 14:59:0815/07/2015
à puppet-dev


----- Original Message -----
> From: "Trevor Vaughan" <tvau...@onyxpoint.com>
> To: "puppet-dev" <puppe...@googlegroups.com>
> Sent: Wednesday, July 15, 2015 7:50:36 PM
> Subject: Re: [Puppet-dev] How do you know what variables are frozen?

> In this case, it was a custom function that was tripping things up.
>
> Looking through the code, I *think* this was the scenario:
>
> 1) Fact => trusted['certname']
> 2) Function call to parse_host($trusted['certname'])
> 3) Parse host:
>
> host = args.first
> host.strip! # Here's the offender
>
> I also tried seeing if dup'ing the args would work, but it copies the
> frozen attribute with the String object (which makes sense).
>
> So, I don't know if I was trying to modify something from a Fact or if the
> object just happened to be carrying the 'frozen' status as it went along.

so do not use strip! use x = something.strip? this way you dont try to
modify anything in scope.

Trevor Vaughan

non lue,
15 juil. 2015, 15:18:1815/07/2015
à puppe...@googlegroups.com
Indeed, I did change it to that but it would still be nice to know what's going on so that I can stuff it into rspec and check for it.

Thanks,

Trevor

--
You received this message because you are subscribed to the Google Groups "Puppet Developers" group.
To unsubscribe from this group and stop receiving emails from it, send an email to puppet-dev+...@googlegroups.com.

For more options, visit https://groups.google.com/d/optout.

Peter Huene

non lue,
15 juil. 2015, 15:22:5515/07/2015
à puppe...@googlegroups.com
On Wed, Jul 15, 2015 at 12:18 PM, Trevor Vaughan <tvau...@onyxpoint.com> wrote:
Indeed, I did change it to that but it would still be nice to know what's going on so that I can stuff it into rspec and check for it.


Puppet's compiler intentionally freezes $trusted and its values.  If you intend to support operating on arguments like this, you should be creating a copy and not modifying the argument (probably a good rule to follow anyway, especially for a function named "parse").
 

For more options, visit https://groups.google.com/d/optout.



--

Trevor Vaughan

non lue,
15 juil. 2015, 15:39:0415/07/2015
à puppe...@googlegroups.com
Fair enough, and we usually do that. I just wanted to know what was frozen so that we could properly duplicate it in our spec tests.

Out of curiosity, why not freeze all strings from Facter?


For more options, visit https://groups.google.com/d/optout.

Adrien Thebo

non lue,
15 juil. 2015, 15:40:2115/07/2015
à puppe...@googlegroups.com

Adrien Thebo

non lue,
15 juil. 2015, 15:41:3815/07/2015
à puppe...@googlegroups.com
And it looks like _I_ was too hasty; this is done when immutable_node_data is set. (https://github.com/puppetlabs/puppet/commit/8ccb3923b7ddd22e53d53dd193edc618b218a2a6)

Trevor Vaughan

non lue,
15 juil. 2015, 15:44:0315/07/2015
à puppe...@googlegroups.com
Ah, we use trusted_node_data so that's probably why I'm hitting this (and glad that I am so we caught that bug prior to release).

Why wouldn't this be the default?

Thanks,

Trevor


For more options, visit https://groups.google.com/d/optout.

Adrien Thebo

non lue,
15 juil. 2015, 15:50:3915/07/2015
à puppe...@googlegroups.com

Trevor Vaughan

non lue,
15 juil. 2015, 16:01:0915/07/2015
à puppe...@googlegroups.com
Move along, nothing to see here.....

Thanks Adrien.

Trevor


For more options, visit https://groups.google.com/d/optout.

Henrik Lindberg

non lue,
15 juil. 2015, 23:55:1415/07/2015
à puppe...@googlegroups.com
On 2015-15-07 12:22, Peter Huene wrote:
> On Wed, Jul 15, 2015 at 12:18 PM, Trevor Vaughan <tvau...@onyxpoint.com
> <mailto:tvau...@onyxpoint.com>> wrote:
>
> Indeed, I did change it to that but it would still be nice to know
> what's going on so that I can stuff it into rspec and check for it.
>
>
> Puppet's compiler intentionally freezes $trusted and its values. If you
> intend to support operating on arguments like this, you should be
> creating a copy and not modifying the argument (probably a good rule to
> follow anyway, especially for a function named "parse").
>
Peter is right. Rule of thumb, never ever mutate arguments that are
given to you or that you lookup. Unfortunately deep freezing all values
has a high cost or we would do that extensively when the puppet runtime
returns values, or calls into user supplied logic.

Regards
- henrik
> <mailto:puppet-dev%2Bunsu...@googlegroups.com>.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/puppet-dev/1753817636.200946.1436986745705.JavaMail.zimbra%40devco.net.
> For more options, visit https://groups.google.com/d/optout.
>
>
>
>
> --
> Trevor Vaughan
> Vice President, Onyx Point, Inc
> (410) 541-6699 <tel:%28410%29%20541-6699>
>
> -- This account not approved for unencrypted proprietary information --
>
> --
> You received this message because you are subscribed to the Google
> Groups "Puppet Developers" group.
> To unsubscribe from this group and stop receiving emails from it,
> send an email to puppet-dev+...@googlegroups.com
> <mailto:puppet-dev+...@googlegroups.com>.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/puppet-dev/CANs%2BFoWKrP%2Btj%2BJsiENkam9q7ohLGQd5-Z5Gfa%3DoE%2BsSX2D%2Bvw%40mail.gmail.com
> <https://groups.google.com/d/msgid/puppet-dev/CANs%2BFoWKrP%2Btj%2BJsiENkam9q7ohLGQd5-Z5Gfa%3DoE%2BsSX2D%2Bvw%40mail.gmail.com?utm_medium=email&utm_source=footer>.
>
> For more options, visit https://groups.google.com/d/optout.
>
>
>
>
> --
> *Join us at **PuppetConf 2015, October 5-9 in Portland, OR - *www.
> <http://www.google.com/url?q=http%3A%2F%2Fwww.&sa=D&sntz=1&usg=AFQjCNEnS7itqgvQV3E4Se1fu4Um_UapSw>2015.puppetconf.com
> <http://www.google.com/url?q=http%3A%2F%2F2015.puppetconf.com&sa=D&sntz=1&usg=AFQjCNE1uQL4Sh23Vr-XkPLa4xfNcoXSog>**
> /Register early to save 40%!/
>
> --
> You received this message because you are subscribed to the Google
> Groups "Puppet Developers" group.
> To unsubscribe from this group and stop receiving emails from it, send
> an email to puppet-dev+...@googlegroups.com
> <mailto:puppet-dev+...@googlegroups.com>.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/puppet-dev/CACZQQfOK4iJk7KcFT9_9n3pU-4U90Cxnhw2660FdafMCuYAggg%40mail.gmail.com
> <https://groups.google.com/d/msgid/puppet-dev/CACZQQfOK4iJk7KcFT9_9n3pU-4U90Cxnhw2660FdafMCuYAggg%40mail.gmail.com?utm_medium=email&utm_source=footer>.
> For more options, visit https://groups.google.com/d/optout.


--

Visit my Blog "Puppet on the Edge"
http://puppet-on-the-edge.blogspot.se/

Répondre à tous
Répondre à l'auteur
Transférer
0 nouveau message