cuken 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
data/.document ADDED
@@ -0,0 +1,5 @@
1
+ lib/**/*.rb
2
+ bin/*
3
+ -
4
+ features/**/*.feature
5
+ LICENSE.txt
data/.rspec ADDED
@@ -0,0 +1 @@
1
+ --color
data/Gemfile ADDED
@@ -0,0 +1,22 @@
1
+ source "http://rubygems.org"
2
+ # Add dependencies required to use your gem here.
3
+ # Example:
4
+ # gem "activesupport", ">= 2.3.5"
5
+ group :default do
6
+ gem 'aruba', "~> 0.3.3"
7
+ gem 'ssh-forever',
8
+ :git => "git://github.com/hedgehog/ssh-forever.git",
9
+ :branch => 'master'
10
+ end
11
+ # Add dependencies to develop your gem here.
12
+ # Include everything needed to run rake, tests, features, etc.
13
+ group :development do
14
+ gem "rspec", "~> 2.5.0"
15
+ gem "yard", "~> 0.6.0"
16
+ gem "cucumber", ">= 0"
17
+ gem "bundler", "~> 1.0.10"
18
+ gem "jeweler", "~> 1.5.2"
19
+ gem "rcov", ">= 0"
20
+ gem "reek", "~> 1.2.8"
21
+ gem "roodi", "~> 2.1.0"
22
+ end
data/Gemfile.lock ADDED
@@ -0,0 +1,75 @@
1
+ GIT
2
+ remote: git://github.com/hedgehog/ssh-forever.git
3
+ revision: c0c71bf01707a6de0bcbc775f891c9e5db0417d6
4
+ branch: master
5
+ specs:
6
+ ssh-forever (0.4.0)
7
+ open4 (>= 1.0.1)
8
+
9
+ GEM
10
+ remote: http://rubygems.org/
11
+ specs:
12
+ aruba (0.3.3)
13
+ childprocess (~> 0.1.7)
14
+ cucumber (~> 0.10)
15
+ rspec (~> 2.5)
16
+ builder (3.0.0)
17
+ childprocess (0.1.7)
18
+ ffi (~> 0.6.3)
19
+ cucumber (0.10.0)
20
+ builder (>= 2.1.2)
21
+ diff-lcs (~> 1.1.2)
22
+ gherkin (~> 2.3.2)
23
+ json (~> 1.4.6)
24
+ term-ansicolor (~> 1.0.5)
25
+ diff-lcs (1.1.2)
26
+ ffi (0.6.3)
27
+ rake (>= 0.8.7)
28
+ gherkin (2.3.4)
29
+ json (~> 1.4.6)
30
+ git (1.2.5)
31
+ jeweler (1.5.2)
32
+ bundler (~> 1.0.0)
33
+ git (>= 1.2.5)
34
+ rake
35
+ json (1.4.6)
36
+ open4 (1.0.1)
37
+ rake (0.8.7)
38
+ rcov (0.9.9)
39
+ reek (1.2.8)
40
+ ruby2ruby (~> 1.2)
41
+ ruby_parser (~> 2.0)
42
+ sexp_processor (~> 3.0)
43
+ roodi (2.1.0)
44
+ ruby_parser
45
+ rspec (2.5.0)
46
+ rspec-core (~> 2.5.0)
47
+ rspec-expectations (~> 2.5.0)
48
+ rspec-mocks (~> 2.5.0)
49
+ rspec-core (2.5.1)
50
+ rspec-expectations (2.5.0)
51
+ diff-lcs (~> 1.1.2)
52
+ rspec-mocks (2.5.0)
53
+ ruby2ruby (1.2.5)
54
+ ruby_parser (~> 2.0)
55
+ sexp_processor (~> 3.0)
56
+ ruby_parser (2.0.6)
57
+ sexp_processor (~> 3.0)
58
+ sexp_processor (3.0.5)
59
+ term-ansicolor (1.0.5)
60
+ yard (0.6.5)
61
+
62
+ PLATFORMS
63
+ ruby
64
+
65
+ DEPENDENCIES
66
+ aruba (~> 0.3.3)
67
+ bundler (~> 1.0.10)
68
+ cucumber
69
+ jeweler (~> 1.5.2)
70
+ rcov
71
+ reek (~> 1.2.8)
72
+ roodi (~> 2.1.0)
73
+ rspec (~> 2.5.0)
74
+ ssh-forever!
75
+ yard (~> 0.6.0)
data/LICENSE.txt ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2011 Hedgehog
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,31 @@
1
+ = Cuken
2
+
3
+ Reusable Cucumber steps and API for Nagios systems testing.
4
+ Pronounced: Cookin'
5
+
6
+ == Usage
7
+
8
+ Typically you will require this library in Cucumber's support folder:
9
+ features/support/env.rb
10
+
11
+ For example usage see the [Cucumber-Nagios][0] gem.
12
+ [0]: https://github.com/auxesis/cucumber-nagios
13
+
14
+ This library structure is modeled on Aruba, and infact
15
+ largely uses Aruba's steps.
16
+
17
+ == Contributing to cuken
18
+
19
+ * Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet
20
+ * Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it
21
+ * Fork the project
22
+ * Start a feature/bugfix branch
23
+ * Commit and push until you are happy with your contribution
24
+ * Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
25
+ * Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.
26
+
27
+ == Copyright
28
+
29
+ Copyright (c) 2011 Hedgehog. See LICENSE.txt for
30
+ further details.
31
+
data/Rakefile ADDED
@@ -0,0 +1,59 @@
1
+ require 'rubygems'
2
+ require 'bundler'
3
+ begin
4
+ Bundler.setup(:default, :development)
5
+ rescue Bundler::BundlerError => e
6
+ $stderr.puts e.message
7
+ $stderr.puts "Run `bundle install` to install missing gems"
8
+ exit e.status_code
9
+ end
10
+ require 'rake'
11
+
12
+ require 'jeweler'
13
+ Jeweler::Tasks.new do |gem|
14
+ # gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options
15
+ gem.name = "cuken"
16
+ gem.homepage = "http://github.com/hedgehog/cuken"
17
+ gem.license = "MIT"
18
+ gem.summary = %Q{Reusable Cucumber steps and API for Nagios systems testing}
19
+ gem.description = %Q{Reusable Cucumber steps and API for Nagios systems testing}
20
+ gem.email = "hedgehogshiatus@gmail.com"
21
+ gem.authors = ["Hedgehog"]
22
+ # Include your dependencies below. Runtime dependencies are required when using your gem,
23
+ # and development dependencies are only needed for development (ie running rake tasks, tests, etc)
24
+ # gem.add_runtime_dependency 'jabber4r', '> 0.1'
25
+ # gem.add_development_dependency 'rspec', '> 1.2.3'
26
+ end
27
+ Jeweler::RubygemsDotOrgTasks.new
28
+
29
+ require 'rspec/core'
30
+ require 'rspec/core/rake_task'
31
+ RSpec::Core::RakeTask.new(:spec) do |spec|
32
+ spec.pattern = FileList['spec/**/*_spec.rb']
33
+ end
34
+
35
+ RSpec::Core::RakeTask.new(:rcov) do |spec|
36
+ spec.pattern = 'spec/**/*_spec.rb'
37
+ spec.rcov = true
38
+ end
39
+
40
+ require 'cucumber/rake/task'
41
+ Cucumber::Rake::Task.new(:features)
42
+
43
+ require 'reek/rake/task'
44
+ Reek::Rake::Task.new do |t|
45
+ t.fail_on_error = true
46
+ t.verbose = false
47
+ t.source_files = 'lib/**/*.rb'
48
+ end
49
+
50
+ require 'roodi'
51
+ require 'roodi_task'
52
+ RoodiTask.new do |t|
53
+ t.verbose = false
54
+ end
55
+
56
+ task :default => :spec
57
+
58
+ require 'yard'
59
+ YARD::Rake::YardocTask.new
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.1.0
data/cuken.gemspec ADDED
@@ -0,0 +1,100 @@
1
+ # Generated by jeweler
2
+ # DO NOT EDIT THIS FILE DIRECTLY
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
4
+ # -*- encoding: utf-8 -*-
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = %q{cuken}
8
+ s.version = "0.1.0"
9
+
10
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
+ s.authors = ["Hedgehog"]
12
+ s.date = %q{2011-03-17}
13
+ s.description = %q{Reusable Cucumber steps and API for Nagios systems testing}
14
+ s.email = %q{hedgehogshiatus@gmail.com}
15
+ s.extra_rdoc_files = [
16
+ "LICENSE.txt",
17
+ "README.md"
18
+ ]
19
+ s.files = [
20
+ ".document",
21
+ ".rspec",
22
+ "Gemfile",
23
+ "Gemfile.lock",
24
+ "LICENSE.txt",
25
+ "README.md",
26
+ "Rakefile",
27
+ "VERSION",
28
+ "cuken.gemspec",
29
+ "features/commands.feature",
30
+ "features/cuken.feature",
31
+ "features/files.feature",
32
+ "features/ssh.feature",
33
+ "features/step_definitions/cuken_steps.rb",
34
+ "features/support/env.rb",
35
+ "lib/cuken.rb",
36
+ "lib/cuken/api/cmd.rb",
37
+ "lib/cuken/api/common.rb",
38
+ "lib/cuken/api/file.rb",
39
+ "lib/cuken/api/ssh.rb",
40
+ "lib/cuken/api/ssh/password.rb",
41
+ "lib/cuken/cmd.rb",
42
+ "lib/cuken/common.rb",
43
+ "lib/cuken/cucumber/cmd.rb",
44
+ "lib/cuken/cucumber/file.rb",
45
+ "lib/cuken/cucumber/ssh.rb",
46
+ "lib/cuken/file.rb",
47
+ "lib/cuken/ssh.rb",
48
+ "spec/cuken_spec.rb",
49
+ "spec/spec_helper.rb"
50
+ ]
51
+ s.homepage = %q{http://github.com/hedgehog/cuken}
52
+ s.licenses = ["MIT"]
53
+ s.require_paths = ["lib"]
54
+ s.rubygems_version = %q{1.6.2}
55
+ s.summary = %q{Reusable Cucumber steps and API for Nagios systems testing}
56
+ s.test_files = [
57
+ "spec/cuken_spec.rb",
58
+ "spec/spec_helper.rb"
59
+ ]
60
+
61
+ if s.respond_to? :specification_version then
62
+ s.specification_version = 3
63
+
64
+ if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
65
+ s.add_runtime_dependency(%q<aruba>, ["~> 0.3.3"])
66
+ s.add_runtime_dependency(%q<ssh-forever>, [">= 0"])
67
+ s.add_development_dependency(%q<rspec>, ["~> 2.5.0"])
68
+ s.add_development_dependency(%q<yard>, ["~> 0.6.0"])
69
+ s.add_development_dependency(%q<cucumber>, [">= 0"])
70
+ s.add_development_dependency(%q<bundler>, ["~> 1.0.10"])
71
+ s.add_development_dependency(%q<jeweler>, ["~> 1.5.2"])
72
+ s.add_development_dependency(%q<rcov>, [">= 0"])
73
+ s.add_development_dependency(%q<reek>, ["~> 1.2.8"])
74
+ s.add_development_dependency(%q<roodi>, ["~> 2.1.0"])
75
+ else
76
+ s.add_dependency(%q<aruba>, ["~> 0.3.3"])
77
+ s.add_dependency(%q<ssh-forever>, [">= 0"])
78
+ s.add_dependency(%q<rspec>, ["~> 2.5.0"])
79
+ s.add_dependency(%q<yard>, ["~> 0.6.0"])
80
+ s.add_dependency(%q<cucumber>, [">= 0"])
81
+ s.add_dependency(%q<bundler>, ["~> 1.0.10"])
82
+ s.add_dependency(%q<jeweler>, ["~> 1.5.2"])
83
+ s.add_dependency(%q<rcov>, [">= 0"])
84
+ s.add_dependency(%q<reek>, ["~> 1.2.8"])
85
+ s.add_dependency(%q<roodi>, ["~> 2.1.0"])
86
+ end
87
+ else
88
+ s.add_dependency(%q<aruba>, ["~> 0.3.3"])
89
+ s.add_dependency(%q<ssh-forever>, [">= 0"])
90
+ s.add_dependency(%q<rspec>, ["~> 2.5.0"])
91
+ s.add_dependency(%q<yard>, ["~> 0.6.0"])
92
+ s.add_dependency(%q<cucumber>, [">= 0"])
93
+ s.add_dependency(%q<bundler>, ["~> 1.0.10"])
94
+ s.add_dependency(%q<jeweler>, ["~> 1.5.2"])
95
+ s.add_dependency(%q<rcov>, [">= 0"])
96
+ s.add_dependency(%q<reek>, ["~> 1.2.8"])
97
+ s.add_dependency(%q<roodi>, ["~> 2.1.0"])
98
+ end
99
+ end
100
+
@@ -0,0 +1,37 @@
1
+ # For complete Aruba step listing see:
2
+ # lib/aruba/cucumber.rb
3
+ # or https://github.com/aslakhellesoy/aruba/blob/master/lib/aruba/cucumber.rb
4
+ Feature: Executing commands
5
+ In order to test a running local system
6
+ As an administrator
7
+ I want to use Aruba steps to run commands and test output
8
+
9
+ Background:
10
+ Given that "cuken/cmd" is required
11
+ # Given the Gem "aruba" has been required
12
+
13
+ Scenario: Check Stdout
14
+ When I do aruba I run "echo 'i like cheese'"
15
+ Then I see aruba the stdout from "echo 'i like cheese'" should contain "i like cheese"
16
+
17
+ Scenario: Check Stderr
18
+ When I do aruba I run "echo 'i like cheese' 1>&2"
19
+ Then I see aruba the stderr from "echo 'i like cheese' 1>&2" should contain "i like cheese"
20
+
21
+ Scenario: Check Stdout for multiple lines
22
+ When I run "echo 'one\none\none\n'"
23
+ Then the output should contain:
24
+ """
25
+ one
26
+ one
27
+ one
28
+ """
29
+
30
+ Scenario: Check exit code
31
+ When I run "true"
32
+ Then the exit status should be 0
33
+
34
+ Scenario: Check exit code
35
+ When I run "false"
36
+ Then the exit status should be 1
37
+
@@ -0,0 +1,9 @@
1
+ #Feature: something something
2
+ # In order to something something
3
+ # A user something something
4
+ # something something something
5
+ #
6
+ # Scenario: something something
7
+ # Given inspiration
8
+ # When I create a sweet new gem
9
+ # Then everyone should see how awesome I am
@@ -0,0 +1,80 @@
1
+ # For complete Aruba step listing see:
2
+ # lib/aruba/cucumber.rb
3
+ # or https://github.com/aslakhellesoy/aruba/blob/master/lib/aruba/cucumber.rb
4
+ Feature: Examining files
5
+ In order to test a running system
6
+ As an administrator
7
+ I want to examine files
8
+
9
+ @steps
10
+ Scenario: File exists
11
+ Given the empty file "foo.file"
12
+ Then the file "foo.file" exists
13
+
14
+ @steps
15
+ Scenario: File does not exist
16
+ Then the file "foo.filepants" does not exist
17
+
18
+ @steps
19
+ Scenario: Atime
20
+ Given the empty file "foo.file"
21
+ And we record the a/mtime of "foo.file"
22
+ And I run "sleep 1"
23
+ And I run "touch -a foo.file"
24
+ Then the atime of "foo.file" changes
25
+
26
+ @steps
27
+ Scenario: Mtime
28
+ Given an empty file named "foo.file"
29
+ And we record the a/mtime of "foo.file"
30
+ And I run "sleep 1"
31
+ And I run "touch -m foo.file"
32
+ Then the mtime of "foo.file" changes
33
+
34
+ @steps
35
+ Scenario: File contents
36
+ When I write to "monkeytest.file" with:
37
+ """
38
+ monkeypants
39
+ monkeyshorts
40
+ """
41
+ Then the file "monkeytest.file" contains "monkeypants"
42
+
43
+ @steps
44
+ Scenario: File contents multiple times
45
+ When I write to "monkeytest.file" with:
46
+ """
47
+ monkeypants
48
+ monkeyshorts
49
+
50
+ """
51
+ Then the file "monkeytest.file" contains exactly:
52
+ """
53
+ monkeypants
54
+ monkeyshorts
55
+
56
+ """
57
+ @steps
58
+ Scenario: File modes
59
+ When I run "touch filemode.file"
60
+ And I run "chmod 644 filemode.file"
61
+ Then the file "filemode.file" has mode "644"
62
+ And the file "filemode.file" has mode "0644"
63
+
64
+ @steps
65
+ Scenario: Directory exists
66
+ When I run "mkdir -p dirtest"
67
+ Then the directory "dirtest" exists
68
+
69
+ @steps
70
+ Scenario: Directory does not exist
71
+ Then the directory "dirtest-m000" does not exist
72
+
73
+ @steps
74
+ Scenario: Directory mode
75
+ When I run "mkdir -p dirtest"
76
+ And I run "chmod 755 dirtest"
77
+ Then the directory "dirtest" has mode "755"
78
+ And the directory "dirtest" has mode "0755"
79
+
80
+
@@ -0,0 +1,26 @@
1
+ # For complete Aruba step listing see:
2
+ # lib/aruba/cucumber.rb
3
+ # or https://github.com/aslakhellesoy/aruba/blob/master/lib/aruba/cucumber.rb
4
+ Feature: SSH steps
5
+ In order to specify remote command execution
6
+ As a developer using Cucumber
7
+ I want to use Aruba and custom steps to describe SSH sessions
8
+
9
+ Background:
10
+ Given that "cuken/ssh" is required
11
+ And the Gem "ssh-forever" has been required
12
+ And default ssh-forever options
13
+ And I initialize password-less SSH access
14
+
15
+ Scenario: Aruba steps for remote commands via password-less SSH access
16
+ Given I successfully run "ssh cuken 'echo Supercalifragilisticexpialidocious;'"
17
+ Then the output should contain "Supercalifragilisticexpialidocious"
18
+
19
+ Scenario: Batch initialize password-less SSH access
20
+ When I initialize password-less SSH access for:
21
+ | user | hostname | name | port |
22
+ | `whoami` | `hostname` | `echo cuken` | `echo 22` |
23
+ | :default | localhost | `echo cuken` | 22 |
24
+ | :default | :default | :default | :default |
25
+ And I successfully run "ssh cuken 'echo Supercalifragilisticexpialidocious;'"
26
+ Then the output should contain "Supercalifragilisticexpialidocious"
@@ -0,0 +1,28 @@
1
+ Given /^the Gem "([^\"]*)" has been required$/ do |gem|
2
+ Gem.loaded_specs.key?(gem).should be_true
3
+ end
4
+
5
+ Given /^that "([^\"]*)" has been required$/ do |lib|
6
+ require(lib).should be_false
7
+ end
8
+
9
+ Given /^that "([^\"]*)" is required$/ do |lib|
10
+ require(lib).should be_false
11
+ end
12
+
13
+ When /^I do aruba (.*)$/ do |aruba_step|
14
+ begin
15
+ When(aruba_step)
16
+ rescue => e
17
+ @aruba_exception = e
18
+ end
19
+ end
20
+
21
+ Then /^I see aruba (.*)$/ do |aruba_step|
22
+ begin
23
+ Then(aruba_step)
24
+ rescue => e
25
+ @aruba_exception = e
26
+ end
27
+ end
28
+
@@ -0,0 +1,15 @@
1
+ require 'bundler'
2
+ begin
3
+ Bundler.setup(:default, :development)
4
+ rescue Bundler::BundlerError => e
5
+ $stderr.puts e.message
6
+ $stderr.puts "Run `bundle install` to install missing gems"
7
+ exit e.status_code
8
+ end
9
+
10
+ $LOAD_PATH.unshift(File.dirname(__FILE__) + '/../../lib')
11
+ require 'cuken/ssh'
12
+ require 'cuken/cmd'
13
+ require 'cuken/file'
14
+
15
+ require 'rspec/expectations'
data/lib/cuken.rb ADDED
@@ -0,0 +1,2 @@
1
+ # We *really* imitate Aruba ;)
2
+ # Load nothing - just keep the file here to keep bundler happy.
@@ -0,0 +1,9 @@
1
+ require 'aruba/api' unless defined? Aruba::Api
2
+
3
+ module Cuken
4
+ module Api
5
+ module Cmd
6
+
7
+ end
8
+ end
9
+ end
@@ -0,0 +1 @@
1
+ require 'aruba/api' unless defined? Aruba::Api
@@ -0,0 +1,54 @@
1
+ require 'aruba/api' unless defined? Aruba::Api
2
+ require 'etc'
3
+
4
+ module Cuken
5
+ module Api
6
+ module File
7
+ include Etc
8
+
9
+ def parse_mode(mode)
10
+ if mode.respond_to?(:oct)
11
+ mode.oct.to_s(8)
12
+ else
13
+ '%o' % mode
14
+ end
15
+ end
16
+
17
+ def record_amtimes(filename)
18
+ in_current_dir do
19
+ @recorded_mtime = ::File.mtime(filename)
20
+ @recorded_atime = ::File.atime(filename)
21
+ end
22
+ end
23
+
24
+ def check_octalmodes(expected_mode, filename)
25
+ in_current_dir do
26
+ cstats = ::File.stat(filename)
27
+ parse_mode(cstats.mode)[/#{parse_mode(expected_mode)}\Z/].should_not be_nil
28
+ end
29
+ end
30
+
31
+ def check_uid(dirname, owner)
32
+ in_current_dir do
33
+ uid = ::Etc.getpwnam(owner).uid
34
+ cstats = ::File.stat(dirname)
35
+ cstats.uid.should == uid
36
+ end
37
+ end
38
+
39
+ def check_amtime_change(filename, time_type)
40
+ in_current_dir do
41
+ case time_type
42
+ when "m"
43
+ current_mtime = ::File.mtime(filename)
44
+ current_mtime.should_not == @recorded_mtime
45
+ when "a"
46
+ current_atime = ::File.atime(filename)
47
+ current_atime.should_not == @recorded_atime
48
+ end
49
+ end
50
+ end
51
+
52
+ end
53
+ end
54
+ end
@@ -0,0 +1,88 @@
1
+ require 'aruba/api' unless defined? Aruba::Api
2
+ require 'ssh-forever' unless defined? SecureShellForever
3
+
4
+ module Cuken
5
+ module Api
6
+ module Ssh
7
+
8
+ def ssh_init_password_less
9
+ @ssh_forever_options ||= ssh_forever_default_options
10
+ cmd = ssh_forever(@ssh_forever_options)
11
+ run_simple(unescape(cmd))
12
+ end
13
+
14
+ def ssh_init_password_less_batch(table=nil)
15
+ if table == :default
16
+ return @ssh_forever_options = ssh_forever_default_options
17
+ elsif table.nil?
18
+ return @ssh_forever_options ||={}
19
+ end
20
+ table.hashes.each do |hash|
21
+ hsh = parse_ssh_forever_options(hash)
22
+ cmd = ssh_forever(hsh)
23
+ run_simple(unescape(cmd))
24
+ end
25
+ end
26
+
27
+ def ssh_forever_options(table=nil)
28
+ if table == :default
29
+ return @ssh_forever_options = ssh_forever_default_options
30
+ elsif table.nil?
31
+ return @ssh_forever_options ||={}
32
+ end
33
+ table.hashes.each do |hash|
34
+ hsh = parse_ssh_forever_options(hash)
35
+ cmd = ssh_forever(hsh)
36
+ run_simple(unescape(cmd))
37
+ end
38
+ end
39
+
40
+ def ssh_client_hostname(n=nil)
41
+ name = ENV['HOSTNAME']|| ENV['HOST']||ENV['COMPUTERNAME']||ENV['COMPUTER']||(`hostname`).strip rescue 'localhost'
42
+ if @ssh_forever_options
43
+ @ssh_forever_options[:user] = n.nil? ? name : n
44
+ end
45
+ name
46
+ end
47
+
48
+ def ssh_client_username(n=nil)
49
+ name = ENV['USER']|| ENV['USERNAME']|| (`whoami`).strip rescue 'root'
50
+ if @ssh_forever_options
51
+ @ssh_forever_options[:hostname] = n.nil? ? name : n
52
+ end
53
+ name
54
+ end
55
+
56
+ private
57
+
58
+ def ssh_forever(hsh)
59
+ "ssh-forever #{hsh[:user]}@#{hsh[:hostname]} -p #{hsh[:port]} -i ~/.ssh/id_rsa_cuken -n #{hsh[:name]} -b"
60
+ end
61
+
62
+ def parse_ssh_forever_options(hsh)
63
+ new_hsh = hsh.inject({}) { |h, (k, v)| h[k.intern] = v; h }
64
+ ssh_forever_default_options.merge(new_hsh).inject({}) do |h, (k, v)|
65
+ v=v.to_s
66
+ if v[/\:default/]
67
+ v = ssh_forever_default_options[k.to_sym]
68
+ h[k]=v
69
+ next h
70
+ end
71
+ if v[/`(.*)`/]
72
+ cmd=v.gsub(/`/,'')
73
+ run_simple(unescape(cmd))
74
+ v = output_from(cmd).strip
75
+ end
76
+ h[k]=v
77
+ h
78
+ end
79
+ end
80
+
81
+ def ssh_forever_default_options
82
+ {:user => ssh_client_username, :hostname => ssh_client_hostname,
83
+ :port => 22, :name => 'cuken', :identity_file => '~/.ssh/id_rsa_cuken',
84
+ :auto => true, :intense => true, :quiet => true }
85
+ end
86
+ end
87
+ end
88
+ end
@@ -0,0 +1,7 @@
1
+ module Cuken
2
+ module Api
3
+ module Ssh
4
+
5
+ end
6
+ end
7
+ end
data/lib/cuken/cmd.rb ADDED
@@ -0,0 +1,3 @@
1
+ require 'cuken/common'
2
+ require 'cuken/api/cmd'
3
+ require 'cuken/cucumber/cmd'
@@ -0,0 +1,3 @@
1
+ require 'pathname'
2
+ require 'aruba/cucumber' unless defined? Aruba
3
+
@@ -0,0 +1,3 @@
1
+ require 'aruba/cucumber' unless defined? Aruba
2
+
3
+ World(::Cuken::Api::Cmd)
@@ -0,0 +1,98 @@
1
+ require 'aruba/cucumber' unless defined? Aruba
2
+
3
+ World(::Cuken::Api::File)
4
+
5
+ #
6
+ # These have been submitted to Aruba - awaiting release...
7
+ #
8
+ Then /^the output from "(.*)" contains exactly:$/ do |cmd, exact_output|
9
+ output_from(unescape(cmd)).should == exact_output
10
+ end
11
+ Then /^the output from "([^"]*)" does not contain exactly:$/ do |cmd, exact_output|
12
+ output_from(unescape(cmd)).should_not == exact_output
13
+ end
14
+ Then /^the output from "([^"]*)" contains:$/ do |cmd, partial_output|
15
+ output_from(unescape(cmd)).should =~ regexp(partial_output)
16
+ end
17
+ Then /^the output from "([^"]*)" does not contain:$/ do |cmd, partial_output|
18
+ output_from(unescape(cmd)).should_not =~ regexp(partial_output)
19
+ end
20
+
21
+ #
22
+ # Refactorings, yet to be submitted to Aruba:
23
+ #
24
+ Given /^the empty file "([^"]*)"$/ do |file_name|
25
+ Given %Q{an empty file named "#{file_name}"}
26
+ end
27
+
28
+ Given /^the file "([^"]*)" with:$/ do |file_name, file_content|
29
+ Given %Q{a file named "#{file_name}" with:}, file_content
30
+ end
31
+
32
+ Then /^the file "([^"]*)" exists$/ do |arg1|
33
+ Then %Q{a file named \"#{arg1}\" should exist}
34
+ end
35
+
36
+ Then /^the file "([^"]*)" does not exist$/ do |arg1|
37
+ Then %Q{a file named \"#{arg1}\" should not exist}
38
+ end
39
+
40
+ Then /^the directory "([^"]*)" exists$/ do |arg1|
41
+ Then %Q{a directory named \"#{arg1}\" should exist}
42
+ end
43
+
44
+ Then /^the directory "([^"]*)" does not exist$/ do |arg1|
45
+ Then %Q{a directory named \"#{arg1}\" should not exist}
46
+ end
47
+
48
+ Then /^the file "([^"]*)" contains "([^"]*)"$/ do |file, content|
49
+ Then %Q{the file "#{file}" should contain "#{content}"}
50
+ end
51
+
52
+ Then /^the file "([^"]*)" contains exactly:$/ do |file, content|
53
+ Then %Q{the file "#{file}" should contain exactly:}, content
54
+ end
55
+
56
+ Then /^these directories exist:$/ do |table|
57
+ Then %Q{the following directories should exist:}, table
58
+ end
59
+
60
+ Then /^these directories do not exist:$/ do |table|
61
+ Then %Q{the following directories should not exist:}, table
62
+ end
63
+
64
+ Then /^these files exist:$/ do |table|
65
+ Then %Q{the following files should exist:}, table
66
+ end
67
+
68
+ Then /^these files do not exist:$/ do |table|
69
+ Then %Q{the following files should exist:}, table
70
+ end
71
+
72
+ #
73
+ # Cucumber Nagios specific
74
+ #
75
+ Given /^we record the a\/mtime of "(.+)"$/ do |filename|
76
+ record_amtimes(filename)
77
+ end
78
+
79
+ Then /^the file "([^"]*)" has mode "([^"]*)"$/ do |filename, expected_mode|
80
+ check_octalmodes(expected_mode, filename)
81
+ end
82
+
83
+ Then /^the directory "([^"]*)" has mode "(\d+)"$/ do |dirname, expected_mode|
84
+ check_octalmodes(expected_mode, dirname)
85
+ end
86
+
87
+ Then /^the directory "(.+)" is owned by "(.+)"$/ do |dirname, owner|
88
+ check_uid(dirname, owner)
89
+ end
90
+
91
+ Then /^the file named "(.+)" should be owned by "(.+)"$/ do |filename, owner|
92
+ check_uid(filename, owner)
93
+ end
94
+
95
+ Then /^the (.)time of "(.+)" changes$/ do |time_type, filename|
96
+ check_amtime_change(filename, time_type)
97
+ end
98
+
@@ -0,0 +1,41 @@
1
+ require 'aruba/cucumber' unless defined? Aruba
2
+
3
+ World(::Cuken::Api::Ssh)
4
+
5
+ Before do
6
+ @aruba_timeout_seconds.nil? || @aruba_timeout_seconds < 3 ? @aruba_timeout_seconds = 3 : @aruba_timeout_seconds
7
+ end
8
+
9
+ Given /^a SSH client user "([^\"]*)"$/ do |name|
10
+ ssh_client_hostname name
11
+ end
12
+
13
+ Given /^a SSH client user$/ do
14
+ ssh_client_hostname
15
+ end
16
+
17
+ Given /^a SSH client hostname "([^\"]*)"$/ do |name|
18
+ ssh_client_hostname name
19
+ end
20
+
21
+ Given /^a SSH client hostname$/ do
22
+ ssh_client_hostname
23
+ end
24
+
25
+ Given /^default ssh\-forever options$/ do
26
+ ssh_forever_options(:default)
27
+ end
28
+
29
+ Given /^the ssh\-forever options:$/ do |table|
30
+ ssh_forever_options(table)
31
+ end
32
+
33
+ When /^I initialize password\-less SSH access for:$/ do |table|
34
+ ssh_init_password_less_batch(table)
35
+ end
36
+
37
+ Given /^I initialize password\-less SSH access$/ do
38
+ ssh_init_password_less
39
+ end
40
+
41
+
data/lib/cuken/file.rb ADDED
@@ -0,0 +1,3 @@
1
+ require 'cuken/common'
2
+ require 'cuken/api/file'
3
+ require 'cuken/cucumber/file'
data/lib/cuken/ssh.rb ADDED
@@ -0,0 +1,3 @@
1
+ require 'cuken/common'
2
+ require 'cuken/api/ssh'
3
+ require 'cuken/cucumber/ssh'
@@ -0,0 +1,7 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
2
+
3
+ describe "Cuken" do
4
+ it "fails" do
5
+ fail "hey buddy, you should probably rename this file and start specing for real"
6
+ end
7
+ end
@@ -0,0 +1,12 @@
1
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
2
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
3
+ require 'rspec'
4
+ require 'cuken'
5
+
6
+ # Requires supporting files with custom matchers and macros, etc,
7
+ # in ./support/ and its subdirectories.
8
+ Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each {|f| require f}
9
+
10
+ RSpec.configure do |config|
11
+
12
+ end
metadata ADDED
@@ -0,0 +1,199 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: cuken
3
+ version: !ruby/object:Gem::Version
4
+ prerelease:
5
+ version: 0.1.0
6
+ platform: ruby
7
+ authors:
8
+ - Hedgehog
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+
13
+ date: 2011-03-17 00:00:00 +11:00
14
+ default_executable:
15
+ dependencies:
16
+ - !ruby/object:Gem::Dependency
17
+ name: aruba
18
+ requirement: &id001 !ruby/object:Gem::Requirement
19
+ none: false
20
+ requirements:
21
+ - - ~>
22
+ - !ruby/object:Gem::Version
23
+ version: 0.3.3
24
+ type: :runtime
25
+ prerelease: false
26
+ version_requirements: *id001
27
+ - !ruby/object:Gem::Dependency
28
+ name: ssh-forever
29
+ requirement: &id002 !ruby/object:Gem::Requirement
30
+ none: false
31
+ requirements:
32
+ - - ">="
33
+ - !ruby/object:Gem::Version
34
+ version: "0"
35
+ type: :runtime
36
+ prerelease: false
37
+ version_requirements: *id002
38
+ - !ruby/object:Gem::Dependency
39
+ name: rspec
40
+ requirement: &id003 !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ~>
44
+ - !ruby/object:Gem::Version
45
+ version: 2.5.0
46
+ type: :development
47
+ prerelease: false
48
+ version_requirements: *id003
49
+ - !ruby/object:Gem::Dependency
50
+ name: yard
51
+ requirement: &id004 !ruby/object:Gem::Requirement
52
+ none: false
53
+ requirements:
54
+ - - ~>
55
+ - !ruby/object:Gem::Version
56
+ version: 0.6.0
57
+ type: :development
58
+ prerelease: false
59
+ version_requirements: *id004
60
+ - !ruby/object:Gem::Dependency
61
+ name: cucumber
62
+ requirement: &id005 !ruby/object:Gem::Requirement
63
+ none: false
64
+ requirements:
65
+ - - ">="
66
+ - !ruby/object:Gem::Version
67
+ version: "0"
68
+ type: :development
69
+ prerelease: false
70
+ version_requirements: *id005
71
+ - !ruby/object:Gem::Dependency
72
+ name: bundler
73
+ requirement: &id006 !ruby/object:Gem::Requirement
74
+ none: false
75
+ requirements:
76
+ - - ~>
77
+ - !ruby/object:Gem::Version
78
+ version: 1.0.10
79
+ type: :development
80
+ prerelease: false
81
+ version_requirements: *id006
82
+ - !ruby/object:Gem::Dependency
83
+ name: jeweler
84
+ requirement: &id007 !ruby/object:Gem::Requirement
85
+ none: false
86
+ requirements:
87
+ - - ~>
88
+ - !ruby/object:Gem::Version
89
+ version: 1.5.2
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: *id007
93
+ - !ruby/object:Gem::Dependency
94
+ name: rcov
95
+ requirement: &id008 !ruby/object:Gem::Requirement
96
+ none: false
97
+ requirements:
98
+ - - ">="
99
+ - !ruby/object:Gem::Version
100
+ version: "0"
101
+ type: :development
102
+ prerelease: false
103
+ version_requirements: *id008
104
+ - !ruby/object:Gem::Dependency
105
+ name: reek
106
+ requirement: &id009 !ruby/object:Gem::Requirement
107
+ none: false
108
+ requirements:
109
+ - - ~>
110
+ - !ruby/object:Gem::Version
111
+ version: 1.2.8
112
+ type: :development
113
+ prerelease: false
114
+ version_requirements: *id009
115
+ - !ruby/object:Gem::Dependency
116
+ name: roodi
117
+ requirement: &id010 !ruby/object:Gem::Requirement
118
+ none: false
119
+ requirements:
120
+ - - ~>
121
+ - !ruby/object:Gem::Version
122
+ version: 2.1.0
123
+ type: :development
124
+ prerelease: false
125
+ version_requirements: *id010
126
+ description: Reusable Cucumber steps and API for Nagios systems testing
127
+ email: hedgehogshiatus@gmail.com
128
+ executables: []
129
+
130
+ extensions: []
131
+
132
+ extra_rdoc_files:
133
+ - LICENSE.txt
134
+ - README.md
135
+ files:
136
+ - .document
137
+ - .rspec
138
+ - Gemfile
139
+ - Gemfile.lock
140
+ - LICENSE.txt
141
+ - README.md
142
+ - Rakefile
143
+ - VERSION
144
+ - cuken.gemspec
145
+ - features/commands.feature
146
+ - features/cuken.feature
147
+ - features/files.feature
148
+ - features/ssh.feature
149
+ - features/step_definitions/cuken_steps.rb
150
+ - features/support/env.rb
151
+ - lib/cuken.rb
152
+ - lib/cuken/api/cmd.rb
153
+ - lib/cuken/api/common.rb
154
+ - lib/cuken/api/file.rb
155
+ - lib/cuken/api/ssh.rb
156
+ - lib/cuken/api/ssh/password.rb
157
+ - lib/cuken/cmd.rb
158
+ - lib/cuken/common.rb
159
+ - lib/cuken/cucumber/cmd.rb
160
+ - lib/cuken/cucumber/file.rb
161
+ - lib/cuken/cucumber/ssh.rb
162
+ - lib/cuken/file.rb
163
+ - lib/cuken/ssh.rb
164
+ - spec/cuken_spec.rb
165
+ - spec/spec_helper.rb
166
+ has_rdoc: true
167
+ homepage: http://github.com/hedgehog/cuken
168
+ licenses:
169
+ - MIT
170
+ post_install_message:
171
+ rdoc_options: []
172
+
173
+ require_paths:
174
+ - lib
175
+ required_ruby_version: !ruby/object:Gem::Requirement
176
+ none: false
177
+ requirements:
178
+ - - ">="
179
+ - !ruby/object:Gem::Version
180
+ hash: 4582846900001686992
181
+ segments:
182
+ - 0
183
+ version: "0"
184
+ required_rubygems_version: !ruby/object:Gem::Requirement
185
+ none: false
186
+ requirements:
187
+ - - ">="
188
+ - !ruby/object:Gem::Version
189
+ version: "0"
190
+ requirements: []
191
+
192
+ rubyforge_project:
193
+ rubygems_version: 1.6.2
194
+ signing_key:
195
+ specification_version: 3
196
+ summary: Reusable Cucumber steps and API for Nagios systems testing
197
+ test_files:
198
+ - spec/cuken_spec.rb
199
+ - spec/spec_helper.rb