pawnee 0.0.6 → 0.0.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/.travis.yml CHANGED
@@ -2,6 +2,7 @@ language: ruby
2
2
  rvm:
3
3
  - 1.9.2
4
4
  - 1.9.3
5
- - jruby-19mode # JRuby in 1.9 mode
5
+ # # we can't run in jruby right now due to open-ssl lib
6
+ # - jruby-19mode # JRuby in 1.9 mode
6
7
  # uncomment this line if your project needs to run something other than `rake`:
7
8
  # script: bundle exec rspec spec
data/README.md CHANGED
@@ -1,3 +1,6 @@
1
+ [![Build Status](https://secure.travis-ci.org/ryanstout/pawnee.png?branch=master)](http://travis-ci.org/ryanstout/pawnee)
2
+
3
+
1
4
  # Pawnee - making server provisioning easier
2
5
 
3
6
  [NOTE: This is still a work in progress and not ready for use yet]
@@ -111,7 +114,7 @@ standard config options:
111
114
  - aws...
112
115
  - s3...
113
116
 
114
- ## exposed by unicorn for example
117
+ ### exposed by unicorn for example
115
118
  app_server_locations ['localhost:3000', 'localhost:3001'] - gets picked up on by nginx maybe?
116
119
 
117
120
 
data/Rakefile CHANGED
@@ -8,4 +8,24 @@ Rake::TestTask.new do |t|
8
8
  t.verbose = true
9
9
  end
10
10
 
11
- task :default => :test
11
+
12
+ require 'rspec/core/rake_task'
13
+
14
+ desc 'Default: run specs.'
15
+ task :default => :spec
16
+
17
+ desc "Run specs"
18
+ RSpec::Core::RakeTask.new do |t|
19
+ if ENV['TRAVIS']
20
+ # Unfortunately we can't run vagrant on travis,
21
+ # so this limits us quite a bit on what tests
22
+ # we can run
23
+ t.pattern = "./spec/base_spec.rb"
24
+ else
25
+ t.pattern = "./spec/**/*_spec.rb"
26
+ end
27
+ end
28
+
29
+ # ENV['TRAVIS']
30
+
31
+ # task :default => :test
@@ -8,6 +8,7 @@ require 'pawnee/parser/options'
8
8
  require 'active_support/core_ext/hash/deep_merge'
9
9
  require 'pawnee/roles'
10
10
  require 'pawnee/invocation'
11
+ require 'pawnee/modified'
11
12
 
12
13
  module Pawnee
13
14
  # The pawnee gem provides the Pawnee::Base class, which includes actions
@@ -19,6 +20,7 @@ module Pawnee
19
20
  include ThorSsh::Actions
20
21
  include Pawnee::Actions
21
22
  include Pawnee::Invocation
23
+ include Pawnee::Modified
22
24
  include Roles
23
25
 
24
26
  attr_accessor :server
@@ -55,9 +55,12 @@ module Pawnee
55
55
  template(File.join("newgem/README.md.tt"), File.join(target, "README.md"), opts)
56
56
  template(File.join("newgem/gitignore.tt"), File.join(target, ".gitignore"), opts)
57
57
  template(File.join("newgem/newgem.gemspec.tt"), File.join(target, "#{name}.gemspec"), opts)
58
- template(File.join("newgem/lib/pawnee/newgem.rb.tt"), File.join(target, "lib/pawnee/#{name}.rb"), opts)
58
+ template(File.join("newgem/lib/pawnee/newgem.rb.tt"), File.join(target, "lib/pawnee/#{name}.rb"), opts)
59
59
  template(File.join("newgem/lib/pawnee/newgem/version.rb.tt"), File.join(target, "lib/#{folder_name}/version.rb"), opts)
60
60
  template(File.join("newgem/lib/pawnee/newgem/base.rb.tt"), File.join(target, "lib/#{folder_name}/base.rb"), opts)
61
+ template(File.join("newgem/spec/spec_helper.rb.tt"), File.join(target, "spec/spec_helper.rb"), opts)
62
+ template(File.join("newgem/spec/vagrant/Vagrantfile.tt"), File.join(target, "spec/vagrant/Vagrantfile"), opts)
63
+ template(File.join("newgem/spec/vagrant/vagrant.rb.tt"), File.join(target, "spec/vagrant/vagrant.rb"), opts)
61
64
  if options[:bin]
62
65
  template(File.join("newgem/bin/newgem.tt"), File.join(target, 'bin', name), opts)
63
66
  end
@@ -0,0 +1,59 @@
1
+ module Pawnee
2
+ module Modified
3
+ def self.included(base)
4
+ # Extend EmptyDirectory to track modifiations
5
+ Thor::Actions::EmptyDirectory.class_eval do
6
+ alias :old_invoke_with_conflict_check :invoke_with_conflict_check
7
+
8
+ # Change invoke with conflict check to track changes
9
+ # when the block is invoked.
10
+ def invoke_with_conflict_check(*args, &block)
11
+ if block_given?
12
+ old_invoke_with_conflict_check(*args) do
13
+ results = yield
14
+ base.track_modification!
15
+ return results
16
+ end
17
+ else
18
+ return old_invoke_with_conflict_check(*args)
19
+ end
20
+ end
21
+ end
22
+ end
23
+
24
+
25
+ # Actions track if they modify something, or if it is
26
+ # already in the desired state. If they modify, they
27
+ # call the track_modification! method on the base class.
28
+ #
29
+ # modified? returns true if there has been a tracked
30
+ # modification within the current modify_block block
31
+ # or within the current task.
32
+ def modified?
33
+ (@modifications && @modifications.first) || false
34
+ end
35
+
36
+ # Track a modification within the current modification
37
+ # block.
38
+ def track_modification!
39
+ @modifications ||= [false]
40
+ @modifications[@modifications.size-1] = true
41
+ end
42
+
43
+ # Allows you to track modifications within a block. During
44
+ # the block any call to modified? will return the value for
45
+ # only during the block.
46
+ def modify_block(&block)
47
+ @modifications ||= [false]
48
+
49
+ # Add a modification value to the stack
50
+ @modifications << false
51
+
52
+ yield
53
+
54
+ # Return the modification value (can also be retrieved
55
+ # with modified?)
56
+ return @modifications.pop
57
+ end
58
+ end
59
+ end
@@ -20,6 +20,32 @@ Or install it yourself as:
20
20
 
21
21
  TODO: Write usage instructions here
22
22
 
23
+
24
+ ## Running Tests
25
+
26
+ The test run through vagrant, which seemed logical since we want to test ssh stuff.
27
+
28
+ ### Install a box (first time only)
29
+ cd spec/vagrant
30
+ bundle exec vagrant box add ubuntu11 http://timhuegdon.com/vagrant-boxes/ubuntu-11.10.box
31
+ bundle exec vagrant init ubuntu11
32
+
33
+ # enable the sandbox and create a commit we can rollback to
34
+ bundle exec vagrant sandbox on
35
+ bundle exec vagrant sandbox commit
36
+
37
+ ### Start box
38
+ vagrant up
39
+
40
+ ### Run the tests
41
+ cd ../..
42
+ bundle exec rspec
43
+
44
+ ### When you're done
45
+ cd spec/vagrant
46
+ vagrant halt
47
+
48
+
23
49
  ## Contributing
24
50
 
25
51
  1. Fork it
@@ -14,5 +14,15 @@ Gem::Specification.new do |gem|
14
14
  gem.name = "pawnee-<%=config[:name]%>"
15
15
  gem.require_paths = ["lib/pawnee"]
16
16
  gem.add_runtime_dependency 'pawnee'
17
+
18
+ # Pawnee development dependencies - versions for these will
19
+ # be pulled from the main pawnee gem
20
+ gem.add_development_dependency 'turn'
21
+ gem.add_development_dependency 'rspec'
22
+ gem.add_development_dependency 'vagrant'
23
+ gem.add_development_dependency 'sahara'
24
+ gem.add_development_dependency 'rake'
25
+ gem.add_development_dependency 'rdoc'
26
+
17
27
  gem.version = <%=config[:constant_name]%>::VERSION
18
28
  end
@@ -0,0 +1,18 @@
1
+ require 'rspec'
2
+
3
+ libdir = File.expand_path(File.dirname(__FILE__) + "/../lib/pawnee")
4
+ $LOAD_PATH.unshift(libdir) unless $LOAD_PATH.include?(libdir)
5
+
6
+ require 'pawnee/<%= config[:name] %>/base'
7
+ require 'vagrant/vagrant'
8
+
9
+
10
+ RSpec.configure do |config|
11
+ config.after(:suite) do
12
+ unless ENV['TRAVIS']
13
+ # Rollback the server
14
+ puts "Roll back test server"
15
+ `cd spec/vagrant/ ; BUNDLE_GEMFILE=../../Gemfile bundle exec vagrant sandbox rollback`
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,99 @@
1
+ # -*- mode: ruby -*-
2
+ # vi: set ft=ruby :
3
+
4
+ Vagrant::Config.run do |config|
5
+ # All Vagrant configuration is done here. The most common configuration
6
+ # options are documented and commented below. For a complete reference,
7
+ # please see the online documentation at vagrantup.com.
8
+
9
+ # Every Vagrant virtual environment requires a box to build off of.
10
+ config.vm.box = "ubuntu11"
11
+
12
+ # The url from where the 'config.vm.box' box will be fetched if it
13
+ # doesn't already exist on the user's system.
14
+ # config.vm.box_url = "http://domain.com/path/to/above.box"
15
+
16
+ # Boot with a GUI so you can see the screen. (Default is headless)
17
+ # config.vm.boot_mode = :gui
18
+
19
+ # Assign this VM to a host-only network IP, allowing you to access it
20
+ # via the IP. Host-only networks can talk to the host machine as well as
21
+ # any other machines on the same network, but cannot be accessed (through this
22
+ # network interface) by any external networks.
23
+ # config.vm.network :hostonly, "192.168.33.10"
24
+
25
+ # Assign this VM to a bridged network, allowing you to connect directly to a
26
+ # network using the host's network device. This makes the VM appear as another
27
+ # physical device on your network.
28
+ # config.vm.network :bridged
29
+
30
+ # Forward a port from the guest to the host, which allows for outside
31
+ # computers to access the VM, whereas host only networking does not.
32
+ # config.vm.forward_port 80, 8080
33
+
34
+ # Share an additional folder to the guest VM. The first argument is
35
+ # an identifier, the second is the path on the guest to mount the
36
+ # folder, and the third is the path on the host to the actual folder.
37
+ # config.vm.share_folder "v-data", "/vagrant_data", "../data"
38
+
39
+ # Enable provisioning with Puppet stand alone. Puppet manifests
40
+ # are contained in a directory path relative to this Vagrantfile.
41
+ # You will need to create the manifests directory and a manifest in
42
+ # the file ubuntu11.pp in the manifests_path directory.
43
+ #
44
+ # An example Puppet manifest to provision the message of the day:
45
+ #
46
+ # # group { "puppet":
47
+ # # ensure => "present",
48
+ # # }
49
+ # #
50
+ # # File { owner => 0, group => 0, mode => 0644 }
51
+ # #
52
+ # # file { '/etc/motd':
53
+ # # content => "Welcome to your Vagrant-built virtual machine!
54
+ # # Managed by Puppet.\n"
55
+ # # }
56
+ #
57
+ # config.vm.provision :puppet do |puppet|
58
+ # puppet.manifests_path = "manifests"
59
+ # puppet.manifest_file = "ubuntu11.pp"
60
+ # end
61
+
62
+ # Enable provisioning with chef solo, specifying a cookbooks path, roles
63
+ # path, and data_bags path (all relative to this Vagrantfile), and adding
64
+ # some recipes and/or roles.
65
+ #
66
+ # config.vm.provision :chef_solo do |chef|
67
+ # chef.cookbooks_path = "../my-recipes/cookbooks"
68
+ # chef.roles_path = "../my-recipes/roles"
69
+ # chef.data_bags_path = "../my-recipes/data_bags"
70
+ # chef.add_recipe "mysql"
71
+ # chef.add_role "web"
72
+ #
73
+ # # You may also specify custom JSON attributes:
74
+ # chef.json = { :mysql_password => "foo" }
75
+ # end
76
+
77
+ # Enable provisioning with chef server, specifying the chef server URL,
78
+ # and the path to the validation key (relative to this Vagrantfile).
79
+ #
80
+ # The Opscode Platform uses HTTPS. Substitute your organization for
81
+ # ORGNAME in the URL and validation key.
82
+ #
83
+ # If you have your own Chef Server, use the appropriate URL, which may be
84
+ # HTTP instead of HTTPS depending on your configuration. Also change the
85
+ # validation key to validation.pem.
86
+ #
87
+ # config.vm.provision :chef_client do |chef|
88
+ # chef.chef_server_url = "https://api.opscode.com/organizations/ORGNAME"
89
+ # chef.validation_key_path = "ORGNAME-validator.pem"
90
+ # end
91
+ #
92
+ # If you're using the Opscode platform, your validator client is
93
+ # ORGNAME-validator, replacing ORGNAME with your organization name.
94
+ #
95
+ # IF you have your own Chef Server, the default validation client name is
96
+ # chef-validator, unless you changed the configuration.
97
+ #
98
+ # chef.validation_client_name = "ORGNAME-validator"
99
+ end
@@ -0,0 +1,30 @@
1
+ require 'vagrant'
2
+ require 'net/ssh'
3
+
4
+ # Return an ssh connection to the vagrant server
5
+ class VagrantManager
6
+ # Returns a connected Net::SSH connection
7
+ def self.connect
8
+ @vm = Vagrant::Environment.new(:cwd => File.dirname(__FILE__)).primary_vm
9
+
10
+ ssh_info = @vm.ssh.info
11
+
12
+ # Build the options we'll use to initiate the connection via Net::SSH
13
+ opts = {
14
+ :port => ssh_info[:port],
15
+ :keys => [ssh_info[:private_key_path]],
16
+ :keys_only => true,
17
+ :user_known_hosts_file => [],
18
+ :paranoid => false,
19
+ :config => false,
20
+ :forward_agent => ssh_info[:forward_agent]
21
+ }
22
+
23
+ # Check that the private key permissions are valid
24
+ @vm.ssh.check_key_permissions(ssh_info[:private_key_path])
25
+
26
+ # Connect to SSH, giving it a few tries
27
+ return Net::SSH.start(ssh_info[:host], ssh_info[:username], opts)
28
+ end
29
+ end
30
+
@@ -1,3 +1,3 @@
1
1
  module Pawnee
2
- VERSION = "0.0.6"
2
+ VERSION = "0.0.8"
3
3
  end
@@ -0,0 +1,27 @@
1
+ require 'spec_helper'
2
+
3
+ describe Pawnee::Base do
4
+ class PawneeTest < Pawnee::Base
5
+ def self.source_root
6
+ File.dirname(__FILE__)
7
+ end
8
+ end
9
+
10
+ before(:all) do
11
+ @remote_base_path = '/home/vagrant/thortest'
12
+ @remote_test = PawneeTest.new
13
+ @remote_test.destination_connection = VagrantManager.connect
14
+ @remote_test.destination_files.rm_rf(@remote_base_path)
15
+ end
16
+
17
+ after(:all) do
18
+ # Close the remote connection
19
+ @remote_test.destination_connection.close
20
+ end
21
+
22
+ it 'should create an empty directory remotely' do
23
+ @remote_test.empty_directory(@remote_base_path)
24
+ @remote_test.empty_directory(@remote_base_path + '2')
25
+ @remote_test.destination_files.exists?(@remote_base_path)
26
+ end
27
+ end
data/spec/base_spec.rb CHANGED
@@ -42,6 +42,7 @@ describe Pawnee::Base do
42
42
  end
43
43
 
44
44
  it "should have no recipes before they are defined, but should add them after they are defined" do
45
+ Pawnee::Base.instance_variable_set('@recipes', nil)
45
46
  Pawnee::Base.recipes.should == nil
46
47
 
47
48
  # These will persist between tests
@@ -0,0 +1,34 @@
1
+ require 'spec_helper'
2
+
3
+ describe Pawnee::Base do
4
+ before do
5
+ @base = Pawnee::Base.new
6
+ end
7
+
8
+ it "should track modifications" do
9
+ @base.modified?.should == false
10
+ @base.track_modification!
11
+ @base.modified?.should == true
12
+ end
13
+
14
+ describe "when changing files" do
15
+
16
+ before(:all) do
17
+ @remote_base_path = '/home/vagrant/thortest'
18
+ @remote_test = Pawnee::Base.new
19
+ @remote_test.destination_connection = VagrantManager.connect
20
+ @remote_test.destination_files.rm_rf(@remote_base_path)
21
+ end
22
+
23
+ after(:all) do
24
+ # Close the remote connection
25
+ @remote_test.destination_connection.close
26
+ end
27
+
28
+ it "should track modifications when a file changes" do
29
+ @remote_test.should_receive(:track_modification!).once
30
+ @remote_test.empty_directory(@remote_base_path + '/test1')
31
+ @remote_test.empty_directory(@remote_base_path + '/test1')
32
+ end
33
+ end
34
+ end
data/spec/spec_helper.rb CHANGED
@@ -17,8 +17,10 @@ require 'vagrant/vagrant'
17
17
 
18
18
  RSpec.configure do |config|
19
19
  config.after(:suite) do
20
- # Rollback the server
21
- puts "Roll back test server"
22
- `cd spec/vagrant/ ; BUNDLE_GEMFILE=../../Gemfile bundle exec vagrant sandbox rollback`
20
+ unless ENV['TRAVIS']
21
+ # Rollback the server
22
+ puts "Roll back test server"
23
+ `cd spec/vagrant/ ; BUNDLE_GEMFILE=../../Gemfile bundle exec vagrant sandbox rollback`
24
+ end
23
25
  end
24
26
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pawnee
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.6
4
+ version: 0.0.8
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-06-11 00:00:00.000000000 Z
12
+ date: 2012-06-15 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: bundler
@@ -263,6 +263,7 @@ files:
263
263
  - lib/pawnee/pawnee/base.rb
264
264
  - lib/pawnee/pawnee/cli.rb
265
265
  - lib/pawnee/pawnee/invocation.rb
266
+ - lib/pawnee/pawnee/modified.rb
266
267
  - lib/pawnee/pawnee/parser/options.rb
267
268
  - lib/pawnee/pawnee/railtie.rb
268
269
  - lib/pawnee/pawnee/roles.rb
@@ -277,12 +278,17 @@ files:
277
278
  - lib/pawnee/pawnee/templates/newgem/lib/pawnee/newgem/base.rb.tt
278
279
  - lib/pawnee/pawnee/templates/newgem/lib/pawnee/newgem/version.rb.tt
279
280
  - lib/pawnee/pawnee/templates/newgem/newgem.gemspec.tt
281
+ - lib/pawnee/pawnee/templates/newgem/spec/spec_helper.rb.tt
282
+ - lib/pawnee/pawnee/templates/newgem/spec/vagrant/Vagrantfile.tt
283
+ - lib/pawnee/pawnee/templates/newgem/spec/vagrant/vagrant.rb.tt
280
284
  - lib/pawnee/pawnee/version.rb
281
285
  - pawnee.gemspec
282
286
  - spec/actions/compile_spec.rb
287
+ - spec/actions/file_spec.rb
283
288
  - spec/actions/package_spec.rb
284
289
  - spec/actions/user_spec.rb
285
290
  - spec/base_spec.rb
291
+ - spec/modified_spec.rb
286
292
  - spec/spec_helper.rb
287
293
  - spec/vagrant/.vagrant
288
294
  - spec/vagrant/Vagrantfile
@@ -301,7 +307,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
301
307
  version: '0'
302
308
  segments:
303
309
  - 0
304
- hash: -3877937215280368330
310
+ hash: -1028839069221412909
305
311
  required_rubygems_version: !ruby/object:Gem::Requirement
306
312
  none: false
307
313
  requirements:
@@ -310,7 +316,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
310
316
  version: '0'
311
317
  segments:
312
318
  - 0
313
- hash: -3877937215280368330
319
+ hash: -1028839069221412909
314
320
  requirements: []
315
321
  rubyforge_project:
316
322
  rubygems_version: 1.8.22
@@ -319,9 +325,11 @@ specification_version: 3
319
325
  summary: Better server provisioing
320
326
  test_files:
321
327
  - spec/actions/compile_spec.rb
328
+ - spec/actions/file_spec.rb
322
329
  - spec/actions/package_spec.rb
323
330
  - spec/actions/user_spec.rb
324
331
  - spec/base_spec.rb
332
+ - spec/modified_spec.rb
325
333
  - spec/spec_helper.rb
326
334
  - spec/vagrant/.vagrant
327
335
  - spec/vagrant/Vagrantfile