-
Notifications
You must be signed in to change notification settings - Fork 32
/
Copy pathRakefile
95 lines (81 loc) · 2.65 KB
/
Rakefile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
# encoding: utf-8
require 'bundler/gem_tasks'
@base_dir = File.dirname(__FILE__)
begin
Bundler.setup(:default, :development)
rescue Bundler::BundlerError => e
$stderr.puts e.message
$stderr.puts "Run `bundle install` to install missing gems"
exit e.status_code
end
require 'rake'
require 'rspec/core'
require 'rspec/core/rake_task'
desc "run unit tests"
RSpec::Core::RakeTask.new(:unit) do |spec|
spec.pattern = FileList['spec/unit/**/*_spec.rb']
end
desc "Run integrations tests against real systems using a vagrant box"
task :vintegration, :user, :pass, :host do |_task, args|
vars = "ipmiuser=#{args[:user]} ipmipass=#{args[:pass]} ipmihost=#{args[:host]}"
puts `cd #{@base_dir}/spec && vagrant up`
puts `cd #{@base_dir}/spec && vagrant provision`
puts `vagrant ssh \"/rubyipmi/rake integration #{vars}\"`
end
desc "Run integrations tests against real systems"
RSpec::Core::RakeTask.new :integration do |spec|
ENV['ipmiuser'] = 'admin'
ENV['ipmipass'] = 'password'
ENV['ipmihost'] = '10.0.1.16'
providers ||= Array(ENV['ipmiprovider']) || ['freeipmi', 'ipmitool']
providers.each do |provider|
ENV['ipmiprovider'] = provider
spec.pattern = FileList['spec/integration/**/*_spec.rb']
end
end
task :default => :unit
require 'rdoc/task'
Rake::RDocTask.new do |rdoc|
version = File.exist?('VERSION') ? File.read('VERSION') : ""
rdoc.rdoc_dir = 'rdoc'
rdoc.title = "rubyipmi #{version}"
rdoc.rdoc_files.include('README*')
rdoc.rdoc_files.include('lib/**/*.rb')
end
desc "send diagnostics to logicminds for testing for the given host"
task :send_diag, :user, :pass, :host do |_t, args|
require 'rubyipmi'
require 'net/smtp'
require 'json'
require "highline/import"
if args.count < 3
raise "You must provide arguments: rake send_diag[user, pass, host]"
end
data = Rubyipmi.get_diag(args[:user], args[:pass], args[:host])
emailto = '[email protected]'
subject = "Rubyipmi diagnostics data"
send_email(emailto, data.to_json, :subject => subject)
end
def send_email(to, data, opts = {})
gmail_id = ask("Enter your gmail account: ")
pass = ask("Enter your gmail password: ") { |q| q.echo = '*' }
opts[:from] = gmail_id
opts[:server] ||= 'smtp.gmail.com'
opts[:from_alias] ||= gmail_id
opts[:subject] ||= @subject
opts[:body] ||= data
opts[:to] ||= to
opts[:port] ||= 587
msg = <<END_OF_MESSAGE
From: #{opts[:from_alias]} <#{opts[:from]}>
To: <#{to}>
Subject: #{opts[:subject]}
Date: #{Time.now.rfc2822}
#{opts[:body]}
END_OF_MESSAGE
smtp = Net::SMTP.new(opts[:server], opts[:port])
smtp.enable_starttls
smtp.start(opts[:server], gmail_id, pass, :login) do
smtp.send_message(msg, gmail_id, to)
end
end