Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

make private classes private, dont pass params #107

Merged
merged 1 commit into from
Mar 1, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 10 additions & 7 deletions manifests/cli.pp
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,21 @@
#
class jenkins::cli {

if $caller_module_name != $module_name {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Doesn't this cause rake lint to complain about the lack of parenthesis in the if statement?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not at all - http://docs.puppetlabs.com/guides/style_guide.html#conditionals. In fact, under 11.2 the example is without parenthesis.

fail("Use of private class ${name} by ${caller_module_name}")
}

$jar = '/usr/lib/jenkins/jenkins-cli.jar'
$extract_jar = 'unzip /usr/lib/jenkins/jenkins.war WEB-INF/jenkins-cli.jar'
$move_jar = "mv WEB-INF/jenkins-cli.jar ${jar}"
$remove_dir = 'rm -rf WEB-INF'

exec {
'jenkins-cli' :
command => "${extract_jar} && ${move_jar} && ${remove_dir}",
path => ['/bin', '/usr/bin'],
cwd => '/tmp',
creates => $jar,
require => Package['jenkins'];
exec { 'jenkins-cli' :
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Any reason this block has been changed?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We have both resource { name: ... } and resource { \n name: ...} - just picked one to standardize on and the style guid seemed to go this way.

command => "${extract_jar} && ${move_jar} && ${remove_dir}",
path => ['/bin', '/usr/bin'],
cwd => '/tmp',
creates => $jar,
require => Package['jenkins'],
}

}
10 changes: 6 additions & 4 deletions manifests/config.pp
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,15 @@
# }
# }
#
class jenkins::config(
$config_hash = {},
) {
class jenkins::config {

if $caller_module_name != $module_name {
fail("Use of private class ${name} by ${caller_module_name}")
}

include jenkins::package

Class['Jenkins::Package']->Class['Jenkins::Config']
create_resources( 'jenkins::sysconfig', $config_hash )
create_resources( 'jenkins::sysconfig', $::jenkins::config_hash )
}

20 changes: 11 additions & 9 deletions manifests/firewall.pp
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,17 @@
# jenkins::firewall class integrates with the puppetlabs-firewall module for
# opening the port to Jenkins automatically
#
class jenkins::firewall(
$port = 8080
) {
firewall {
'500 allow Jenkins inbound traffic':
action => 'accept',
state => 'NEW',
dport => [$port],
proto => 'tcp',
class jenkins::firewall {

if $caller_module_name != $module_name {
fail("Use of private class ${name} by ${caller_module_name}")
}

firewall { '500 allow Jenkins inbound traffic':
action => 'accept',
state => 'NEW',
dport => [$::jenkins::port],
proto => 'tcp',
}
}

21 changes: 7 additions & 14 deletions manifests/init.pp
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,8 @@
$repo = $jenkins::params::repo,
$service_enable = $jenkins::params::service_enable,
$service_ensure = $jenkins::params::service_ensure,
$config_hash = undef,
$plugin_hash = undef,
$config_hash = {},
$plugin_hash = {},
$configure_firewall = undef,
$install_java = $jenkins::params::install_java,
$proxy_host = undef,
Expand All @@ -84,6 +84,7 @@
) inherits jenkins::params {

validate_bool($lts, $install_java, $repo)
validate_hash($config_hash, $plugin_hash)

if $configure_firewall {
validate_bool($configure_firewall)
Expand All @@ -102,22 +103,14 @@
class {'jenkins::repo':}
}

class {'jenkins::package' :
version => $version;
}
class {'jenkins::package': }

class { 'jenkins::config':
config_hash => $config_hash,
}
class { 'jenkins::config': }

class { 'jenkins::plugins':
plugin_hash => $plugin_hash,
}
class { 'jenkins::plugins': }
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not group this, and the other classes in one big class declaration? E.g.

class {
  'jenkins::package' : ;
  'jenkins::config' : ;
  'jenkins::plugins' : ;
}

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

personally I don't like multiple resources separated with a semicolon, but that's a persona preference. I can update if you'd like.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I took a look at the style guide on this, since you referenced it above. I think they're wrong about this, but I'm fine following Puppet Labs' silly arbitrary guidelines in the module.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't agree with a few of the style guide things and am happy to change whatever - I just like consistency as it makes it easier to modify.


if $proxy_host {
if $proxy_host and $proxy_port {
class { 'jenkins::proxy':
host => $proxy_host,
port => $proxy_port,
require => Package['jenkins'],
notify => Service['jenkins']
}
Expand Down
3 changes: 2 additions & 1 deletion manifests/master.pp
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,6 @@
) inherits jenkins::params {

jenkins::plugin {'swarm':
version => $version }
version => $version ,
}
}
12 changes: 8 additions & 4 deletions manifests/package.pp
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,13 @@
#
# The package might not specify a dependency on Java, so you may need to
# specify that yourself
class jenkins::package($version = 'installed') {
package {
'jenkins' :
ensure => $version;
class jenkins::package {

if $caller_module_name != $module_name {
fail("Use of private class ${name} by ${caller_module_name}")
}

package { 'jenkins' :
ensure => $::jenkins::version;
}
}
61 changes: 29 additions & 32 deletions manifests/plugin.pp
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
#
#
#
define jenkins::plugin($version=0) {
define jenkins::plugin(
$version=0
) {

$plugin = "${name}.hpi"
$plugin_dir = '/var/lib/jenkins/plugins'
$plugin_parent_dir = inline_template('<%= @plugin_dir.split(\'/\')[0..-2].join(\'/\') %>')
Expand All @@ -16,37 +19,33 @@
}

if (!defined(File[$plugin_dir])) {
file {
[$plugin_parent_dir, $plugin_dir]:
ensure => directory,
owner => 'jenkins',
group => 'jenkins',
mode => '0755',
require => [Group['jenkins'], User['jenkins']];
file { [$plugin_parent_dir, $plugin_dir]:
ensure => directory,
owner => 'jenkins',
group => 'jenkins',
mode => '0755',
require => [Group['jenkins'], User['jenkins']],
}
}

if (!defined(Group['jenkins'])) {
group {
'jenkins' :
ensure => present,
require => Package['jenkins'];
group { 'jenkins' :
ensure => present,
require => Package['jenkins'],
}
}

if (!defined(User['jenkins'])) {
user {
'jenkins' :
ensure => present,
home => $plugin_parent_dir,
require => Package['jenkins'];
user { 'jenkins' :
ensure => present,
home => $plugin_parent_dir,
require => Package['jenkins'],
}
}

if (!defined(Package['wget'])) {
package {
'wget' :
ensure => present;
package { 'wget' :
ensure => present,
}
}

Expand All @@ -61,20 +60,18 @@
}
}

exec {
"download-${name}" :
command => "rm -rf ${name} ${name}.* && wget --no-check-certificate ${base_url}${plugin}",
cwd => $plugin_dir,
require => [File[$plugin_dir], Package['wget']],
path => ['/usr/bin', '/usr/sbin', '/bin'];
exec { "download-${name}" :
command => "rm -rf ${name} ${name}.* && wget --no-check-certificate ${base_url}${plugin}",
cwd => $plugin_dir,
require => [File[$plugin_dir], Package['wget']],
path => ['/usr/bin', '/usr/sbin', '/bin'],
}

file {
"${plugin_dir}/${plugin}" :
require => Exec["download-${name}"],
owner => 'jenkins',
mode => '0644',
notify => Service['jenkins'];
file { "${plugin_dir}/${plugin}" :
require => Exec["download-${name}"],
owner => 'jenkins',
mode => '0644',
notify => Service['jenkins'],
}
}

Expand Down
13 changes: 8 additions & 5 deletions manifests/plugins.pp
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
# Class: jenkins::plugins
#
class jenkins::plugins (
$plugin_hash = {}
) {
validate_hash( $plugin_hash )
create_resources('jenkins::plugin',$plugin_hash)
class jenkins::plugins {

if $caller_module_name != $module_name {
fail("Use of private class ${name} by ${caller_module_name}")
}

create_resources('jenkins::plugin',$jenkins::plugin_hash)

}
9 changes: 5 additions & 4 deletions manifests/proxy.pp
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
#
class jenkins::proxy (
$host = undef,
$port = undef,
) {
class jenkins::proxy {

if $caller_module_name != $module_name {
fail("Use of private class ${name} by ${caller_module_name}")
}

file { '/var/lib/jenkins/proxy.xml':
content => template('jenkins/proxy.xml.erb'),
Expand Down
4 changes: 4 additions & 0 deletions manifests/repo.pp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@
#
class jenkins::repo {

if $caller_module_name != $module_name {
fail("Use of private class ${name} by ${caller_module_name}")
}

if ( $::jenkins::repo ) {
case $::osfamily {

Expand Down
7 changes: 6 additions & 1 deletion manifests/repo/debian.pp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@
#
class jenkins::repo::debian
{

if $caller_module_name != $module_name {
fail("Use of private class ${name} by ${caller_module_name}")
}

if $::jenkins::lts {
apt::source { 'jenkins':
location => 'http://pkg.jenkins-ci.org/debian-stable',
Expand All @@ -10,8 +15,8 @@
key => 'D50582E6',
key_source => 'http://pkg.jenkins-ci.org/debian/jenkins-ci.org.key',
include_src => false,
}
}
}
else {
apt::source { 'jenkins':
location => 'http://pkg.jenkins-ci.org/debian',
Expand Down
8 changes: 6 additions & 2 deletions manifests/repo/el.pp
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,16 @@
class jenkins::repo::el
{

if $caller_module_name != $module_name {
fail("Use of private class ${name} by ${caller_module_name}")
}

if $::jenkins::lts {
yumrepo {'jenkins':
descr => 'Jenkins',
baseurl => 'http://pkg.jenkins-ci.org/redhat-stable/',
gpgcheck => 1,
gpgkey => 'http://pkg.jenkins-ci.org/redhat/jenkins-ci.org.key'
gpgkey => 'http://pkg.jenkins-ci.org/redhat/jenkins-ci.org.key',
}
}

Expand All @@ -17,7 +21,7 @@
descr => 'Jenkins',
baseurl => 'http://pkg.jenkins-ci.org/redhat/',
gpgcheck => 1,
gpgkey => 'http://pkg.jenkins-ci.org/redhat/jenkins-ci.org.key'
gpgkey => 'http://pkg.jenkins-ci.org/redhat/jenkins-ci.org.key',
}
}
}
12 changes: 7 additions & 5 deletions manifests/repo/suse.pp
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,23 @@
class jenkins::repo::suse
{

if $caller_module_name != $module_name {
fail("Use of private class ${name} by ${caller_module_name}")
}

if $::jenkins::lts {
zypprepo {'jenkins':
descr => 'Jenkins',
baseurl => 'http://pkg.jenkins-ci.org/opensuse-stable/',
gpgcheck => 1,
gpgkey => 'http://pkg.jenkins-ci.org/redhat/jenkins-ci.org.key'
gpgkey => 'http://pkg.jenkins-ci.org/redhat/jenkins-ci.org.key',
}
}

else {
} else {
zypprepo {'jenkins':
descr => 'Jenkins',
baseurl => 'http://pkg.jenkins-ci.org/opensuse/',
gpgcheck => 1,
gpgkey => 'http://pkg.jenkins-ci.org/redhat/jenkins-ci.org.key'
gpgkey => 'http://pkg.jenkins-ci.org/redhat/jenkins-ci.org.key',
}
}
}
6 changes: 6 additions & 0 deletions manifests/service.pp
Original file line number Diff line number Diff line change
@@ -1,11 +1,17 @@
# Class: jenkins::service
#
class jenkins::service {

if $caller_module_name != $module_name {
fail("Use of private class ${name} by ${caller_module_name}")
}

service { 'jenkins':
ensure => $jenkins::service_ensure,
enable => $jenkins::service_enable,
hasstatus => true,
hasrestart => true,
}

}

Loading