Issue #4429 has been updated by James Turnbull.

Status changed from Unreviewed to Needs design decision
Assigned to set to Luke Kanies


----------------------------------------
Bug #4429: variable confusion when a class includes its sibling
http://projects.puppetlabs.com/issues/4429

Author: martin krafft
Status: Needs design decision
Priority: Normal
Assigned to: Luke Kanies
Category: language
Target version: 
Affected version: 0.25.4
Keywords: class inheritance variable scoping scope weirdness confusion anger
Branch: 


The following test-case illustrates the problem: as soon as the client and
server classes inherit from the same base class, the variable set in the
server class is reset to the value it has in the base class when the client
class is included:

<pre>
class test::base {
    $controlvar = "base"
}

class test::client inherits test::base {
    notify { "in client class before":
        message => "controlvar at the top of the client class is $controlvar"
    }
    $controlvar = $controlvar ? {
        ""      => "client",
        default => $controlvar
    }

    notify { "in client class after":
        message => "controlvar at the end of the client class is $controlvar"
    }
}

class test::server inherits test::base {
    $controlvar = "server"
    notify { "in server class before":
        message => "controlvar in the server class before the include is 
$controlvar"
    }
    include test::client
    notify { "in server class after":
        message => "controlvar in the server class after the include is 
$controlvar"
    }
}
</pre>

This yields the following output:

<pre>
notice: controlvar at the top of the client class is base
notice: controlvar in the server class after the include is server
notice: controlvar in the server class before the include is server
notice: controlvar at the end of the client class is base
</pre>

If the base class does not set $controlvar, it will be empty at the top of the
client class, causing it to be set to "client" by the selector statement.

If I remove the inheritance on the base class from *either* of the client or
the server class, it all works as expected.

PS: it might seem weird what I am trying to do, but it's quite simple: I am
trying to manage puppet itself, and since puppet.conf is shared between client
and server, but will have different contents on pure clients than on the
server (which is also a client), I have to use a different template, which
I store in a variable. The idea is exactly the same as above, and it works as
long as I don't derive from the base class. However, since client and server
have a number of shared variables, I want to factor them out into the base
class.



-- 
You have received this notification because you have either subscribed to it, 
or are involved in it.
To change your notification preferences, please click here: 
http://projects.puppetlabs.com/my/account

-- 
You received this message because you are subscribed to the Google Groups 
"Puppet Bugs" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/puppet-bugs?hl=en.

Reply via email to