Skip to content

Commit

Permalink
manage /etc/apt/sources.list on intrepid, all packages depend on running
Browse files Browse the repository at this point in the history
apt-get update
  • Loading branch information
jnewland committed Nov 23, 2010
1 parent aba6706 commit 4bf74e2
Show file tree
Hide file tree
Showing 7 changed files with 121 additions and 9 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Expand Up @@ -9,4 +9,5 @@ spec/generator.log
.ginger
.rvmrc
.bundle
.DS_Store
.DS_Store
tmp
3 changes: 1 addition & 2 deletions lib/moonshine/capistrano_integration.rb
Expand Up @@ -117,7 +117,6 @@ def self.load_into(capistrano_config)

desc 'Apply the Moonshine manifest for this application'
task :apply, :except => { :no_release => true } do
aptget.update
sudo "RAILS_ROOT=#{latest_release} DEPLOY_STAGE=#{ENV['DEPLOY_STAGE'] || fetch(:stage)} RAILS_ENV=#{fetch(:rails_env)} shadow_puppet #{latest_release}/app/manifests/#{fetch(:moonshine_manifest)}.rb"
end

Expand Down Expand Up @@ -435,7 +434,7 @@ def self.load_into(capistrano_config)

namespace :aptget do
task :update do
run 'if test `lsb_release -rs` != 8.10; then sudo apt-get update; fi'
sudo 'apt-get update'
end
end
end
Expand Down
2 changes: 1 addition & 1 deletion lib/moonshine/manifest/rails.rb
Expand Up @@ -53,7 +53,7 @@ def default_stack
self.class.recipe :sqlite3
end
recipe :rails_rake_environment, :rails_gems, :rails_directories, :rails_bootstrap, :rails_migrations, :rails_logrotate
recipe :ntp, :time_zone, :postfix, :cron_packages, :motd, :security_updates
recipe :ntp, :time_zone, :postfix, :cron_packages, :motd, :security_updates, :apt_sources
end

def rails_template_dir
Expand Down
29 changes: 29 additions & 0 deletions lib/moonshine/manifest/rails/os.rb
Expand Up @@ -88,12 +88,41 @@ def security_updates
:content => template(File.join(File.dirname(__FILE__), "templates", "unattended_upgrades.erb"))
end

def apt_sources
if ubuntu_intrepid?
file '/etc/apt/sources.list',
:ensure => :present,
:mode => '644',
:content => template(File.join(File.dirname(__FILE__), "templates", "sources.list.intrepid"))
exec 'apt-get update', :command => 'apt-get update', :require => file('/etc/apt/sources.list')
else
exec 'apt-get update', :command => 'apt-get update'
end
end

# Override the shadow_puppet package method to inject a dependency on
# exec('apt-get update')
def package(*args)
if args && args.flatten.size == 1
super(*args)
elsif
name = args.first
hash = args.last
hash[:require] = Array(hash[:require]).push(exec('apt-get update'))
super(name, hash)
end
end

private

def ubuntu_lucid?
Facter.lsbdistid == 'Ubuntu' && Facter.lsbdistrelease.to_f == 10.04
end

def ubuntu_intrepid?
Facter.lsbdistid == 'Ubuntu' && Facter.lsbdistrelease.to_f == 8.10
end

def distro_unattended_security_origin
case Facter.lsbdistrelease.to_f
when 8.10 then 'Ubuntu intrepid-security'
Expand Down
8 changes: 8 additions & 0 deletions lib/moonshine/manifest/rails/templates/sources.list.intrepid
@@ -0,0 +1,8 @@
deb http://old-releases.ubuntu.com/ubuntu intrepid main restricted universe multiverse
deb-src http://old-releases.ubuntu.com/ubuntu intrepid main restricted universe multiverse

deb http://old-releases.ubuntu.com/ubuntu intrepid-updates main restricted universe multiverse
deb-src http://old-releases.ubuntu.com/ubuntu intrepid-updates main restricted universe multiverse

deb http://old-releases.ubuntu.com/ubuntu intrepid-security main restricted universe multiverse
deb-src http://old-releases.ubuntu.com/ubuntu intrepid-security main restricted universe multiverse
40 changes: 35 additions & 5 deletions lib/moonshine/matchers.rb
Expand Up @@ -40,22 +40,52 @@ module Matchers
end
end

define :require_resource do |expected|
expected = Array(expected)
resource_string = expected.map { |r| "#{r.type.downcase}('#{r.title}')"}.join(',')
actual_string = ''

match do |resource|
resources = Array(resource.require)
actual_string = resources.flatten.map { |r| "#{r.type.downcase}('#{r.title}')"}.join(',')

if expected.length > resources.length
false
else
expected.each do |expected_resource|
result &&= resources.flatten.detect do |actual_resource|
actual_resource.type == expected_resource.type &&
actual_resource.title == expected_resource.title
end
end
end
end

description do
"should require all of #{resource_string}"
end

failure_message_for_should do |actual|
"expected resource to require all of #{resource_string}, but required #{actual_string}"
end

failure_message_for_should_not do |actual|
"expected resource not to require #{resource_string}, but required #{actual_string}"
end
end

define :have_package do |expected|
match do |manifest|
package = manifest.packages[expected]
result = !package.nil?
if @version
result &&= package.ensure == @version
end
end
if @provider
@actual_provider = package.provider
result &&= @actual_provider == @provider.to_sym
end

if @before
@before.each do |type, names|
end
end
result
end

Expand Down
45 changes: 45 additions & 0 deletions spec/moonshine/manifest/os_spec.rb
Expand Up @@ -19,6 +19,21 @@
)

end

specify "#apt_sources injects a dependency on apt-get update" do
@manifest.apt_sources

@manifest.should exec_command('apt-get update')

@manifest.should_not have_file("/etc/apt/sources.list")

@manifest.package('foo', :ensure => :installed)

@manifest.packages['foo'].should require_resource(@manifest.exec('apt-get update'))

@manifest.execs['apt-get update'].should_not require_resource(@manifest.file('/etc/apt/sources.list'))

end
end

context "Ubuntu Intrepid (8.10)" do
Expand All @@ -35,6 +50,36 @@
)
end

specify "#apt_sources installs customized sources.lst and injects a dependency on it" do
@manifest.apt_sources

@manifest.should exec_command('apt-get update')

@manifest.execs['apt-get update'].should require_resource([
@manifest.file('/etc/apt/sources.list')
])

@manifest.should have_file("/etc/apt/sources.list").with_content(
/deb http:\/\/old-releases.ubuntu.com\/ubuntu intrepid main restricted universe multiverse/
)

@manifest.package('foo', :ensure => :installed)
@manifest.package('too', :ensure => :installed)
@manifest.package('bar', :ensure => :installed, :require => @manifest.package('foo'))
@manifest.package('baz', :ensure => :installed, :require => [@manifest.package('foo'), @manifest.package('too')])

@manifest.packages['foo'].should require_resource(@manifest.exec('apt-get update'))
@manifest.packages['bar'].should require_resource([
@manifest.package('foo'),
@manifest.exec('apt-get update')
])
@manifest.packages['baz'].should require_resource([
@manifest.package('foo'),
@manifest.package('too'),
@manifest.exec('apt-get update')
])
end

end

specify "#security_update" do
Expand Down

0 comments on commit 4bf74e2

Please sign in to comment.