praegustator 0.1.0 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- YWU3YTdhODI3ODg3MWNlOTZmNjMxYzllN2M1OTQ5NTNhNjkyNjVmYw==
4
+ OWNmNzAyMjllY2JjYjc1MWI4Y2VhMGNlZDVhODIwMTZmN2U2MDM3Nw==
5
5
  data.tar.gz: !binary |-
6
- YmE4NzBjMGE3ZGY0Y2NlODk5NWIwYjE2YzU0YmVjOWQwZTMyODJjMA==
6
+ ZWFlOTQzODcyNWRkOGE1MDI3NGJiMTAyYzYyZGZhMjcwMDM0Y2RiOA==
7
7
  SHA512:
8
8
  metadata.gz: !binary |-
9
- NTYxMjViYWRlODljZTRlODExZmMyZDFmODA4MTk5NWM3OWU5YjcwNzYxYzY5
10
- MjQzY2MyNzcwYWY5YTc5MzM4YWRkNzIyOTU1NTI3MDcxOTI2Y2MxNjcyYjFi
11
- Nzk3NDBiNTIxY2UyNGNiMDk3YjRhMmNkNGFjOWU2ZWNlMWVmNDU=
9
+ MzE1YzQ0YTc5OGYyNGY1MmUzZDQ0ZTQwZjA5MDRmNGY5NWJmOTgxZjYyOWMx
10
+ MzU4YTk1YjIxN2I3NWVhYzFhMDQ1MzhmMmNiZDZhM2NjMmViNWI3MTViODc1
11
+ ZWM5NGNiYTBlMWNiNWY5NjdiOWY5MzljMWU5N2RiMDhmZjhmYzY=
12
12
  data.tar.gz: !binary |-
13
- OThlNzM5MzIxNTZiZTU2Y2EwZGE3ZDgyZGFhMjA4YzU0ZTlkMjQ5YzEyN2Uz
14
- ODI5MWRhZmIyNGIzNjM3ODI1OGYyMDdlNjg5OTVkNzNkOGRjZWUxNmRiODcw
15
- YzU1NzkyY2Y1YmYzY2JkZDJjMzViZjEwMzI0MmU1NmUzOTRkYjM=
13
+ NGI4Y2JkYjE3ODY4ZmU0YzFhMzQ2NTJlNzNlYzkyY2EzZDYyZDljNDA0ODBj
14
+ MjM5NDk0NzMxNTNiMGEyOTM1YTkwZmJlYjYxOGY4M2VmZTdjZjVjNWY0Yzlj
15
+ NzFhYWE2MjhmMzg3MWVhYzFkMDA1NjAyNDQ0NjA2MzJkYTcwYTQ=
data/.travis.yml ADDED
@@ -0,0 +1,5 @@
1
+ language: ruby
2
+ rvm:
3
+ - 1.9.3
4
+ script:
5
+ - bundle exec rspec
data/lib/praegustator.rb CHANGED
@@ -33,7 +33,7 @@ module Praegustator
33
33
  config = YAML::load(IO.read(path_to_yaml_file))
34
34
  rescue Psych::SyntaxError
35
35
  p "error while parsing yaml configuration file. using defaults."; return
36
- rescue Exception
36
+ rescue Errno::ENOENT
37
37
  p "yaml configuration file couldn't be found. using defaults."; return
38
38
  end
39
39
  configure(config) if config
@@ -3,10 +3,10 @@ require 'praegustator'
3
3
  module Praegustator
4
4
  class Setup
5
5
  def init(spec_dir)
6
+ create_settings spec_dir
6
7
  mkdir(spec_dir)
7
8
  create_spec spec_dir
8
9
  create_recepie spec_dir
9
- create_settings spec_dir
10
10
  end
11
11
 
12
12
  def mkdir dir
@@ -24,18 +24,23 @@ module Praegustator
24
24
  content = <<-EOF
25
25
  role("*")do
26
26
  check "basic_commands"
27
+ properties :user => "root"
27
28
  end
28
29
  EOF
29
30
  create_file "#{dir}/test_recipe.rb",content
30
31
  end
31
32
 
32
33
  def create_settings dir
34
+ puts "please enter knife's location (default ~/.chef/knife.rb) : "
35
+ knife_location = $stdin.gets.chomp
36
+ knife_location = '~/.chef/knife.rb' if knife_location == ''
37
+
33
38
  content = <<-EOF
34
39
  spec:
35
40
  recipes_dir: "#{dir}/"
36
41
  checks_dir: "#{dir}/checks/"
37
42
  chef:
38
- knife_location: "~/.chef/knife.rb"
43
+ knife_location: "#{knife_location}"
39
44
  # ssh:
40
45
  # user: "root"
41
46
  # pasword: nil
@@ -46,8 +51,9 @@ end
46
51
 
47
52
  def create_spec dir
48
53
  content = <<-EOF
54
+ user = property[:user]
49
55
  describe command('whoami') do
50
- it { should return_stdout 'vagrant' }
56
+ it { should return_stdout user }
51
57
  end
52
58
 
53
59
  describe command('cat /etc/resolv.conf') do
@@ -1,20 +1,27 @@
1
1
  require "praegustator"
2
2
  module Praegustator
3
3
  class TestSuite
4
- attr_accessor :nodes
4
+ attr_accessor :nodes, :checks, :params
5
+
5
6
  def initialize(query)
6
7
  @query = query
7
8
  @checks = {}
9
+ @params = {}
8
10
  @nodes = Praegustator::Wrappers::Chef.search query
9
11
  end
10
- def check(name,opts={})
12
+
13
+ def check(name)
11
14
  @checks[name] = {}
12
- @checks[name][:opts] = opts
13
15
  end
16
+
17
+ def properties(params)
18
+ @params = params
19
+ end
20
+
14
21
  def execute
15
22
  # lazy load
16
23
  require 'praegustator/wrappers/server_spec'
17
- Praegustator::Wrappers::ServerSpec.new.execute @nodes,@checks
24
+ Praegustator::Wrappers::ServerSpec.new.execute self
18
25
  end
19
26
  end
20
27
  end
@@ -1,3 +1,3 @@
1
1
  module Praegustator
2
- VERSION = "0.1.0"
2
+ VERSION = "0.2.0"
3
3
  end
@@ -17,14 +17,15 @@ module Praegustator
17
17
  end
18
18
 
19
19
 
20
- def execute nodes,checks
21
- nodes.each do |n|
20
+ def execute suite
21
+ suite.nodes.each do |n|
22
22
  ENV['TARGET_HOST'] = n.ipaddress
23
23
  formatter = RSpec::Core::Formatters::JsonFormatter.new(nil)
24
- #RSpec.reset
25
24
  RSpec.clear_remaining_example_groups
26
25
  load 'serverspec.rb'
27
26
  begin
27
+ params = suite.params
28
+ params[:current_node] = n
28
29
  RSpec.configure do |c|
29
30
  c.host = ENV['TARGET_HOST']
30
31
  options = Net::SSH::Config.for(c.host)
@@ -33,6 +34,7 @@ module Praegustator
33
34
  options[:timeout] = 10
34
35
  c.ssh = Net::SSH.start(c.host, user, options)
35
36
  c.os = backend.check_os
37
+ set_property params
36
38
  c.output = $stdout
37
39
  c.color_enabled = true
38
40
  c.tty = true
@@ -42,16 +44,17 @@ module Praegustator
42
44
  reporter = RSpec::Core::Reporter.new(formatter)
43
45
  c.instance_variable_set(:@reporter, reporter)
44
46
  end
45
- spec_files = checks.keys.map{|check| "#{Dir.pwd}/#{Praegustator.config['spec']['checks_dir']}/#{check}.rb" }
47
+ spec_files = suite.checks.keys.map{|check| "#{Dir.pwd}/#{Praegustator.config['spec']['checks_dir']}/#{check}.rb" }
46
48
  begin
47
49
  RSpec::Core::Runner.run_patched(spec_files, $stderr, $stdout)
48
- rescue Error => e
50
+ rescue Exception => e
49
51
  $stderr.puts "!! spec execution failed #{e.message}"
50
52
  end
51
53
  if Praegustator.config['log_level'] != 'debug'
52
54
  @parser.parse n,formatter.output_hash
53
55
  end
54
56
  rescue Exception => e
57
+ $stderr.puts e.backtrace.join("\n")
55
58
  $stderr.puts "!! failed for #{n.ipaddress} : #{e.message}"
56
59
  end
57
60
  end
data/readme.md CHANGED
@@ -20,21 +20,27 @@ check against them, whereas checks are rspec files with server-spec matchers def
20
20
 
21
21
  sample recipe for praegustator:
22
22
 
23
- ``` ruby sample_recipe.rb
23
+ ``` ruby
24
+ #sample_recipe.rb
24
25
  environment :staging
25
26
 
26
27
  role("web-server") do
27
28
  check "application/nginx"
28
29
  check "application/puma"
29
30
  check "application/s3cmd"
31
+ properties name: "foo"
30
32
  end
31
33
  ```
32
34
  The `role` method mark all nodes with that role . Within the
33
35
  block passed to `role` you can declare checks using the `check` method.
36
+ arbitrary hash can be passed to checks usin `properties` method, also
37
+ current node under test is added automatically to properties hash.
34
38
 
35
39
  Where check are server spec files:
36
40
 
37
- ``` ruby #{spec_dir}/application/nginx.rb
41
+ ``` ruby
42
+ #{spec_dir}/application/nginx.rb
43
+
38
44
  describe package('nginx') do
39
45
  it { should be_installed }
40
46
  end
@@ -43,6 +49,13 @@ describe service('nginx') do
43
49
  it { should be_enabled }
44
50
  it { should be_running }
45
51
  end
52
+
53
+ app_name = property[:name]
54
+ ip_address = property[:current_node].ipaddress
55
+
56
+ describe file("/etc/nginx/conf.d/#{app_name}.conf") do
57
+ it { should contain "server_name #{ip_address}" }
58
+ end
46
59
  ```
47
60
 
48
61
  ## `praeg` command
@@ -35,7 +35,7 @@ describe Praegustator::Dsl do
35
35
  first_suite = suits.first
36
36
  checks = first_suite.instance_variable_get(:@checks)
37
37
  checks["nginx"].should_not nil
38
- checks["puma"][:opts][:target].should == "10.210.10.1"
38
+ first_suite.params[:target].should == "10.210.10.1"
39
39
  end
40
40
  end
41
41
  end
@@ -2,7 +2,8 @@ environment :staging
2
2
 
3
3
  role "web" do
4
4
  check "nginx"
5
- check "puma" , target: "10.210.10.1"
5
+ check "puma"
6
+ properties target: "10.210.10.1"
6
7
  check "logrotate"
7
8
  end
8
9
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: praegustator
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - timusg
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-11-25 00:00:00.000000000 Z
11
+ date: 2013-11-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: thor
@@ -160,6 +160,7 @@ extra_rdoc_files: []
160
160
  files:
161
161
  - .gitignore
162
162
  - .rspec
163
+ - .travis.yml
163
164
  - Gemfile
164
165
  - Gemfile.lock
165
166
  - Rakefile