Merge pull request #37 from kbarber/ticket/master/13289
authorRyan Coleman <ryan@puppetlabs.com>
Fri, 23 Mar 2012 23:02:26 +0000 (16:02 -0700)
committerRyan Coleman <ryan@puppetlabs.com>
Fri, 23 Mar 2012 23:02:26 +0000 (16:02 -0700)
Ticket/master/13289 Style violations & rspec cleanup

21 files changed:
.gitmodules [new file with mode: 0644]
Rakefile
manifests/builddep.pp
manifests/debian/testing.pp
manifests/debian/unstable.pp
manifests/force.pp
manifests/init.pp
manifests/key.pp
manifests/pin.pp
manifests/ppa.pp
manifests/release.pp
manifests/source.pp
spec/classes/apt_spec.rb
spec/classes/release_spec.rb
spec/defines/pin_spec.rb
spec/defines/source_spec.rb
spec/fixtures/manifests/site.pp [new file with mode: 0644]
spec/fixtures/modules/apt [new symlink]
spec/fixtures/modules/stdlib [new submodule]
spec/spec_helper.rb
tests/source.pp

diff --git a/.gitmodules b/.gitmodules
new file mode 100644 (file)
index 0000000..eb34d3b
--- /dev/null
@@ -0,0 +1,3 @@
+[submodule "spec/fixtures/modules/stdlib"]
+       path = spec/fixtures/modules/stdlib
+       url = https://github.com/puppetlabs/puppetlabs-stdlib.git
index 6242a3704b18fcc53339e339efed28607be71bd4..705d50de2f8f3a354e8f68e1e0b6127fb6675303 100644 (file)
--- a/Rakefile
+++ b/Rakefile
@@ -1,4 +1,5 @@
 require 'rake'
+require 'puppet-lint/tasks/puppet-lint'
 
 task :default => [:spec]
 
index 8aebc679aea3329223b293d41fe3654dff91c5ff..8891bd903b6095e7bae872904bd3bfb9fe473f82 100644 (file)
@@ -5,7 +5,7 @@ define apt::builddep() {
   Class['apt'] -> Apt::Builddep[$name]
 
   exec { "apt-update-${name}":
-    command     => "/usr/bin/apt-get update",
+    command     => '/usr/bin/apt-get update',
     refreshonly => true,
   }
 
index 4eec1f8dbb65616632b6b886f6028e77f3c249db..cfdeb3cf73ebfd8f063340f28735115942997744 100644 (file)
@@ -8,14 +8,14 @@ class apt::debian::testing {
   # debian-keyring
   # debian-archive-keyring
 
-  apt::source { "debian_testing":
-    location => "http://debian.mirror.iweb.ca/debian/",
-    release => "testing",
-    repos => "main contrib non-free",
-    required_packages => "debian-keyring debian-archive-keyring",
-    key => "55BE302B",
-    key_server => "subkeys.pgp.net",
-    pin => "-10"
+  apt::source { 'debian_testing':
+    location          => 'http://debian.mirror.iweb.ca/debian/',
+    release           => 'testing',
+    repos             => 'main contrib non-free',
+    required_packages => 'debian-keyring debian-archive-keyring',
+    key               => '55BE302B',
+    key_server        => 'subkeys.pgp.net',
+    pin               => '-10',
   }
 
 }
index 782440fb30b1653a4fdc9e3eacd8d603bfab1e0d..3991023d17e0c4160844f4f08d27d183d13b0b8d 100644 (file)
@@ -2,20 +2,20 @@
 
 class apt::debian::unstable {
 
- # deb http://debian.mirror.iweb.ca/debian/ unstable main contrib non-free
- # deb-src http://debian.mirror.iweb.ca/debian/ unstable main contrib non-free
- # Key: 55BE302B  Server: subkeys.pgp.net
- # debian-keyring
- # debian-archive-keyring
 # deb http://debian.mirror.iweb.ca/debian/ unstable main contrib non-free
 # deb-src http://debian.mirror.iweb.ca/debian/ unstable main contrib non-free
 # Key: 55BE302B  Server: subkeys.pgp.net
 # debian-keyring
 # debian-archive-keyring
 
apt::source { "debian_unstable":
-   location => "http://debian.mirror.iweb.ca/debian/",
-   release => "unstable",
-   repos => "main contrib non-free",
-   required_packages => "debian-keyring debian-archive-keyring",
-   key => "55BE302B",
-   key_server => "subkeys.pgp.net",
-   pin => "-10"
- }
 apt::source { 'debian_unstable':
+    location          => 'http://debian.mirror.iweb.ca/debian/',
+    release           => 'unstable',
+    repos             => 'main contrib non-free',
+    required_packages => 'debian-keyring debian-archive-keyring',
+    key               => '55BE302B',
+    key_server        => 'subkeys.pgp.net',
+    pin               => '-10',
 }
 
 }
index ec6f57e2ccdb540bf4c1cad82edc115beb863861..45c5679292b601c9d13954efc401b5377d071130 100644 (file)
@@ -7,15 +7,16 @@ define apt::force(
 ) {
 
   $version_string = $version ? {
-    false => undef,
+    false   => undef,
     default => "=${version}",
   }
 
+  $install_check = $version ? {
+    false   => "/usr/bin/dpkg -s ${name} | grep -q 'Status: install'",
+    default => "/usr/bin/dpkg -s ${name} | grep -q 'Version: ${version}'",
+  }
   exec { "/usr/bin/aptitude -y -t ${release} install ${name}${version_string}":
-    unless => $version ? {
-      false => "/usr/bin/dpkg -s ${name} | grep -q 'Status: install'",
-      default => "/usr/bin/dpkg -s ${name} | grep -q 'Version: ${version}'"
-    }
+    unless => $install_check,
   }
 
 }
index b41d359fbdeb22652a42db531ea387cf9abf05cb..29db697c14c104ef3963de0141586a9e3ec66582 100644 (file)
@@ -33,57 +33,58 @@ class apt(
   validate_bool($purge_sources_list, $purge_sources_list_d)
 
   $refresh_only_apt_update = $always_apt_update? {
-    true => false,
-    false => true
+    true  => false,
+    false => true,
   }
 
-  if ! defined(Package["python-software-properties"]) {
-    package { "python-software-properties": }
+  if ! defined(Package['python-software-properties']) {
+    package { 'python-software-properties': }
   }
 
-  file { "sources.list":
-    path => "${apt::params::root}/sources.list",
-    ensure => present,
-    owner => root,
-    group => root,
-    mode => 644,
-    content => $purge_sources_list ? {
-      false =>  undef,
-      true  => "# Repos managed by puppet.\n",
-    },
+  $sources_list_content = $purge_sources_list ? {
+    false =>  undef,
+    true  => "# Repos managed by puppet.\n",
+  }
+  file { 'sources.list':
+    ensure  => present,
+    path    => "${apt::params::root}/sources.list",
+    owner   => root,
+    group   => root,
+    mode    => '0644',
+    content => $sources_list_content,
   }
 
-  file { "sources.list.d":
-    path => "${apt::params::root}/sources.list.d",
-    ensure => directory,
-    owner => root,
-    group => root,
-    purge => $purge_sources_list_d,
+  file { 'sources.list.d':
+    ensure  => directory,
+    path    => "${apt::params::root}/sources.list.d",
+    owner   => root,
+    group   => root,
+    purge   => $purge_sources_list_d,
     recurse => $purge_sources_list_d,
   }
 
-  exec { "apt_update":
-    command => "${apt::params::provider} update",
-    subscribe => [ File["sources.list"], File["sources.list.d"] ],
+  exec { 'apt_update':
+    command     => "${apt::params::provider} update",
+    subscribe   => [ File['sources.list'], File['sources.list.d'] ],
     refreshonly => $refresh_only_apt_update,
   }
 
   case $disable_keys {
     true: {
-      file { "99unauth":
-        content => "APT::Get::AllowUnauthenticated 1;\n",
+      file { '99unauth':
         ensure  => present,
-        path    => "/etc/apt/apt.conf.d/99unauth",
+        content => "APT::Get::AllowUnauthenticated 1;\n",
+        path    => '/etc/apt/apt.conf.d/99unauth',
       }
     }
     false: {
-      file { "99unauth":
+      file { '99unauth':
         ensure => absent,
-        path   => "/etc/apt/apt.conf.d/99unauth",
+        path   => '/etc/apt/apt.conf.d/99unauth',
       }
     }
     undef: { } # do nothing
-    default: { fail("Valid values for disable_keys are true or false") }
+    default: { fail('Valid values for disable_keys are true or false') }
   }
 
   if($proxy_host) {
index c6e5f6e5651e1b5ce3a237ae23ee7b276e57ed8e..e87968d7fbb504f3f6e8ca8a2e38b2e344ca8566 100644 (file)
@@ -3,7 +3,7 @@ define apt::key (
   $ensure = present,
   $key_content = false,
   $key_source = false,
-  $key_server = "keyserver.ubuntu.com"
+  $key_server = 'keyserver.ubuntu.com'
 ) {
 
   include apt::params
@@ -11,11 +11,11 @@ define apt::key (
   $upkey = upcase($key)
 
   if $key_content {
-    $method = "content"
+    $method = 'content'
   } elsif $key_source {
-    $method = "source"
+    $method = 'source'
   } elsif $key_server {
-    $method = "server"
+    $method = 'server'
   }
 
   # This is a hash of the parts of the key definition that we care about.
@@ -29,26 +29,27 @@ define apt::key (
   case $ensure {
     present: {
 
-      anchor { "apt::key/$title":; }
+      anchor { "apt::key/${title}":; }
 
-      if defined(Exec["apt::key $upkey absent"]) {
-        fail ("Cannot ensure Apt::Key[$upkey] present; $upkey already ensured absent")
+      if defined(Exec["apt::key ${upkey} absent"]) {
+        fail("Cannot ensure Apt::Key[${upkey}] present; ${upkey} already ensured absent")
       }
 
-      if !defined(Anchor["apt::key $upkey present"]) {
-        anchor { "apt::key $upkey present":; }
+      if !defined(Anchor["apt::key ${upkey} present"]) {
+        anchor { "apt::key ${upkey} present":; }
       }
 
       if !defined(Exec[$digest]) {
+        $digest_command = $method ? {
+          'content' => "echo '${key_content}' | /usr/bin/apt-key add -",
+          'source'  => "wget -q '${key_source}' -O- | apt-key add -",
+          'server'  => "apt-key adv --keyserver '${key_server}' --recv-keys '${upkey}'",
+        }
         exec { $digest:
-          path    => "/bin:/usr/bin",
+          path    => '/bin:/usr/bin',
           unless  => "/usr/bin/apt-key list | /bin/grep '${upkey}'",
-          before  => Anchor["apt::key $upkey present"],
-          command => $method ? {
-            "content" => "echo '${key_content}' | /usr/bin/apt-key add -",
-            "source"  => "wget -q '${key_source}' -O- | apt-key add -",
-            "server"  => "apt-key adv --keyserver '${key_server}' --recv-keys '${upkey}'",
-          };
+          before  => Anchor["apt::key ${upkey} present"],
+          command => $digest_command,
         }
       }
 
@@ -57,21 +58,21 @@ define apt::key (
     }
     absent: {
 
-      if defined(Anchor["apt::key $upkey present"]) {
-        fail ("Cannot ensure Apt::Key[$upkey] absent; $upkey already ensured present")
+      if defined(Anchor["apt::key ${upkey} present"]) {
+        fail("Cannot ensure Apt::Key[${upkey}] absent; ${upkey} already ensured present")
       }
 
-      exec { "apt::key $upkey absent":
-        path    => "/bin:/usr/bin",
-        onlyif  => "apt-key list | grep '$upkey'",
-        command => "apt-key del '$upkey'",
-        user    => "root",
-        group   => "root",
+      exec { "apt::key ${upkey} absent":
+        path    => '/bin:/usr/bin',
+        onlyif  => "apt-key list | grep '${upkey}'",
+        command => "apt-key del '${upkey}'",
+        user    => 'root',
+        group   => 'root',
       }
     }
 
     default: {
-      fail "Invalid 'ensure' value '$ensure' for aptkey"
+      fail "Invalid 'ensure' value '${ensure}' for aptkey"
     }
   }
 }
index 40695af5fa8f84eb4cba4a2ca26ebd84b57818d4..46613667ebc0eabe9ad7a299dd0008748d99cba6 100644 (file)
@@ -9,11 +9,11 @@ define apt::pin(
   include apt::params
 
   file { "${name}.pref":
-    path => "${apt::params::root}/preferences.d/${name}",
-    ensure => file,
-    owner => root,
-    group => root,
-    mode => 644,
+    ensure  => file,
+    path    => "${apt::params::root}/preferences.d/${name}",
+    owner   => root,
+    group   => root,
+    mode    => '0644',
     content => "# ${name}\nPackage: ${packages}\nPin: release a=${name}\nPin-Priority: ${priority}",
   }
 }
index 712f425f49b5b50c3de6f74fb639b8088af41ef3..095d8f17b2b86d6318ca3ab24586ad90d314458a 100644 (file)
@@ -9,17 +9,17 @@ define apt::ppa(
   include apt::params
 
   if ! $release {
-    fail("lsbdistcodename fact not available: release parameter required")
+    fail('lsbdistcodename fact not available: release parameter required')
   }
 
   exec { "apt-update-${name}":
-    command     => "/usr/bin/aptitude update",
+    command     => '/usr/bin/aptitude update',
     refreshonly => true,
   }
 
   $filename_without_slashes = regsubst($name,'/','-','G')
-  $filename_without_ppa     = regsubst($filename_without_slashes, '^ppa:','','G')
-  $sources_list_d_filename   = "${filename_without_ppa}-${release}.list"
+  $filename_without_ppa = regsubst($filename_without_slashes, '^ppa:','','G')
+  $sources_list_d_filename = "${filename_without_ppa}-${release}.list"
 
   exec { "add-apt-repository-${name}":
     command => "/usr/bin/add-apt-repository ${name}",
index 9fc0aa38dd58f23a1067dd1347493054a4aabd56..ee94e139faa83d55019114111b3613c85eea015e 100644 (file)
@@ -7,9 +7,9 @@ class apt::release (
   include apt::params
 
   file { "${apt::params::root}/apt.conf.d/01release":
-    owner => root,
-    group => root,
-    mode => 644,
+    owner   => root,
+    group   => root,
+    mode    => '0644',
     content => "APT::Default-Release \"${release_id}\";"
   }
 }
index 42a21e9e49c3293a80886a75c7dc67e4cb43e1d1..95768dcfaa81f919d781294223e286cb1e72ae35 100644 (file)
@@ -17,25 +17,25 @@ define apt::source(
   include apt::params
 
   if $release == undef {
-    fail("lsbdistcodename fact not available: release parameter required")
+    fail('lsbdistcodename fact not available: release parameter required')
   }
 
   file { "${name}.list":
-    path => "${apt::params::root}/sources.list.d/${name}.list",
-    ensure => file,
-    owner => root,
-    group => root,
-    mode => 644,
-    content => template("apt/source.list.erb"),
+    ensure  => file,
+    path    => "${apt::params::root}/sources.list.d/${name}.list",
+    owner   => root,
+    group   => root,
+    mode    => '0644',
+    content => template("${module_name}/source.list.erb"),
   }
 
   if $pin != false {
-    apt::pin { "${release}": priority => "${pin}" } -> File["${name}.list"]
+    apt::pin { $release: priority => $pin } -> File["${name}.list"]
   }
 
   exec { "${name} apt update":
-    command => "${apt::params::provider} update",
-    subscribe => File["${name}.list"],
+    command     => "${apt::params::provider} update",
+    subscribe   => File["${name}.list"],
     refreshonly => true,
   }
 
@@ -49,8 +49,8 @@ define apt::source(
 
   if $key != false {
     apt::key { "Add key: ${key} from Apt::Source ${title}":
-      key         => $key,
       ensure      => present,
+      key         => $key,
       key_server  => $key_server,
       key_content => $key_content,
       key_source  => $key_source,
index 71a438e0627780794fdfb47f1fbad687d6ab3fe4..000793d092783a3740be5cca53e4518bd2fe819a 100644 (file)
@@ -50,7 +50,7 @@ describe 'apt', :type => :class do
             'ensure'  => "present",
             'owner'   => "root",
             'group'   => "root",
-            'mode'    => 644,
+            'mode'    => "0644",
             "content" => "# Repos managed by puppet.\n"
           })
         else
@@ -59,7 +59,7 @@ describe 'apt', :type => :class do
             'ensure'  => "present",
             'owner'   => "root",
             'group'   => "root",
-            'mode'    => 644,
+            'mode'    => "0644",
             'content' => nil
           })
         end
index 221df03683380c2669859b633dfe9dd497da2467..d131b228109dfccd90ec85a9b1cabd61a5e8bb65 100644 (file)
@@ -12,9 +12,9 @@ describe 'apt::release', :type => :class do
 
   it {
     should contain_file("/etc/apt/apt.conf.d/01release").with({
+      "mode"    => "0644",
       "owner"   => "root",
       "group"   => "root",
-      "mode"    => 644,
       "content" => "APT::Default-Release \"#{param_set[:release_id]}\";"
     })
   }
index 52c6bfae19de80abfff93bbc7ec6c3dbab55064d..dbc595c568000caf7a6536356c9395fe17f3f617 100644 (file)
@@ -27,12 +27,12 @@ describe 'apt::pin', :type => :define do
       it { should include_class("apt::params") }
 
       it { should contain_file("#{title}.pref").with({
+          'ensure'  => 'file',
           'path'    => "/etc/apt/preferences.d/#{title}",
-          'ensure'  => "file",
-          'owner'   => "root",
-          'group'   => "root",
-          'mode'    => "644",
-          'content' => "# #{title}\nPackage: #{param_hash[:packages]}\nPin: release a=#{title}\nPin-Priority: #{param_hash[:priority]}"
+          'owner'   => 'root',
+          'group'   => 'root',
+          'mode'    => '0644',
+          'content' => "# #{title}\nPackage: #{param_hash[:packages]}\nPin: release a=#{title}\nPin-Priority: #{param_hash[:priority]}",
         })
       }
     end
index e93137e8e4e32a1ece8895f63a38e933b6445272..284342940b445d161e25851ea2dac321cb5dd679 100644 (file)
@@ -66,12 +66,12 @@ describe 'apt::source', :type => :define do
       it { should contain_apt__params }
 
       it { should contain_file("#{title}.list").with({
+          'ensure'    => 'file',
           'path'      => filename,
-          'ensure'    => "file",
-          'owner'     => "root",
-          'group'     => "root",
-          'mode'      => 644,
-          'content'   => content
+          'owner'     => 'root',
+          'group'     => 'root',
+          'mode'      => '0644',
+          'content'   => content,
         })
       }
 
diff --git a/spec/fixtures/manifests/site.pp b/spec/fixtures/manifests/site.pp
new file mode 100644 (file)
index 0000000..e69de29
diff --git a/spec/fixtures/modules/apt b/spec/fixtures/modules/apt
new file mode 120000 (symlink)
index 0000000..1b20c9f
--- /dev/null
@@ -0,0 +1 @@
+../../../
\ No newline at end of file
diff --git a/spec/fixtures/modules/stdlib b/spec/fixtures/modules/stdlib
new file mode 160000 (submodule)
index 0000000..a70b09d
--- /dev/null
@@ -0,0 +1 @@
+Subproject commit a70b09d5de035de5254ebe6ad6e1519a6d7cf588
index d2648da2b2d6857c4f66bbc769cbd285ce2c2a46..46fe2371c96ac7301a50a8575c465fbdfab0ff88 100644 (file)
@@ -1,11 +1,14 @@
-require 'puppet'
 require 'rubygems'
+require 'puppet'
 require 'rspec-puppet'
 
 def param_value(subject, type, title, param)
   subject.resource(type, title).send(:parameters)[param.to_sym]
 end
 
+fixture_path = File.expand_path(File.join(File.dirname(__FILE__), 'fixtures'))
+
 RSpec.configure do |c|
-  c.module_path = File.join(File.dirname(__FILE__), '../../')
+  c.module_path = File.join(fixture_path, 'modules')
+  c.manifest_dir = File.join(fixture_path, 'manifests')
 end
index 4db740d4175e903f43b3b8a4de59bd4b4c969018..a8702cf58a36c05bfc24f2d1caf1ed2fccdab848 100644 (file)
@@ -1,29 +1,29 @@
 class { 'apt': }
 apt::source { 'foo':
-  location => '',
-  release => 'karmic',
-  repos => 'main',
-  include_src => true,
+  location          => '',
+  release           => 'karmic',
+  repos             => 'main',
+  include_src       => true,
   required_packages => false,
-  key => false,
-  key_server => 'keyserver.ubuntu.com',
-  pin => '600'
+  key               => false,
+  key_server        => 'keyserver.ubuntu.com',
+  pin               => '600',
 }
 
 # test two sources with the same key
-apt::source { "debian_testing":
-  location => "http://debian.mirror.iweb.ca/debian/",
-  release => "testing",
-  repos => "main contrib non-free",
-  key => "55BE302B",
-  key_server => "subkeys.pgp.net",
-  pin => "-10"
+apt::source { 'debian_testing':
+  location   => 'http://debian.mirror.iweb.ca/debian/',
+  release    => 'testing',
+  repos      => 'main contrib non-free',
+  key        => '55BE302B',
+  key_server => 'subkeys.pgp.net',
+  pin        => '-10',
 }
-apt::source { "debian_unstable":
-  location => "http://debian.mirror.iweb.ca/debian/",
-  release => "unstable",
-  repos => "main contrib non-free",
-  key => "55BE302B",
-  key_server => "subkeys.pgp.net",
-  pin => "-10"
+apt::source { 'debian_unstable':
+  location   => 'http://debian.mirror.iweb.ca/debian/',
+  release    => 'unstable',
+  repos      => 'main contrib non-free',
+  key        => '55BE302B',
+  key_server => 'subkeys.pgp.net',
+  pin        => '-10',
 }