Skip to content

Commit

Permalink
cleanup; fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
whummer committed Jul 9, 2014
1 parent 407ef6c commit 89f7d25
Show file tree
Hide file tree
Showing 14 changed files with 33 additions and 69 deletions.
5 changes: 3 additions & 2 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,9 @@ group :doc do
end
# Authentication module
gem 'devise'
# Get rid of some rails warnings
gem 'thin'
# Use thin server (faster; prints less rails output/warnings)
gem 'thin', '~> 1.6' # 14-07-08: default version 2.0.0.pre is incompatible
# http://stackoverflow.com/questions/19579984/sinatra-server-wont-start-wrong-number-of-arguments

# TOASTER DEPENDENCIES
gem 'hashdiff' # diff hashes
Expand Down
28 changes: 14 additions & 14 deletions Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -11,18 +11,18 @@ rescue Bundler::BundlerError => e
end
require 'rake'

require 'jeweler'
Jeweler::Tasks.new do |gem|
gem.name = "cloud-toaster"
gem.license = "Apache"
gem.authors = ["Waldemar Hummer"]
gem.email = ["hummer@infosys.tuwien.ac.at"]
gem.homepage = "https://github.com/whummer/toaster"
gem.summary = %q{Testing of infrastructure-as-code automations.}
gem.description = %q{This gem provides tools for testing of infrastructure-as-code automations.}
gem.files = FileList['lib/**/*.rb', '[A-Z]*', 'spec/**/*'].to_a
end
Jeweler::RubygemsDotOrgTasks.new
#require 'jeweler'
#Jeweler::Tasks.new do |gem|
# gem.name = "cloud-toaster"
# gem.license = "Apache"
# gem.authors = ["Waldemar Hummer"]
# gem.email = ["hummer@infosys.tuwien.ac.at"]
# gem.homepage = "https://github.com/whummer/toaster"
# gem.summary = %q{Testing of infrastructure-as-code automations.}
# gem.description = %q{This gem provides tools for testing of infrastructure-as-code automations.}
# gem.files = FileList['lib/**/*.rb', '[A-Z]*', 'spec/**/*'].to_a
#end
#Jeweler::RubygemsDotOrgTasks.new

require 'rspec/core'
require 'rspec/core/rake_task'
Expand All @@ -35,8 +35,8 @@ RSpec::Core::RakeTask.new(:rcov) do |spec|
spec.rcov = true
end

require 'cucumber/rake/task'
Cucumber::Rake::Task.new(:features)
#require 'cucumber/rake/task'
#Cucumber::Rake::Task.new(:features)

task :default => :spec

Expand Down
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1.1.4
1.1.5
8 changes: 6 additions & 2 deletions chef/cookbooks/lxc/recipes/setup_database.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,13 @@
node.set['mysql']['server_root_password'] = "root"
include_recipe "mysql::server"

root_dir = File.join(File.dirname(__FILE__), "..","..","..","..")

bash 'db_create' do
code "echo 'create database toaster;' | mysql -u root -p#{node['mysql']['server_root_password']}"
code <<-EOH
echo 'create database toaster;' | mysql -u root -p#{node['mysql']['server_root_password']}
cd #{root_dir}/webapp && ./bin/rake db:migrate RAILS_ENV=development
EOH
not_if "echo \"show databases;\" | mysql -u root -p#{node['mysql']['server_root_password']} | grep toaster"
end

Expand All @@ -19,4 +24,3 @@
end

end

2 changes: 1 addition & 1 deletion lib/toaster/api.rb
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,7 @@ def clean()
def web(detached=false)
puts "INFO: Starting Web application on port 8080"
dir = File.join(File.dirname(__FILE__), "..", "..")
cmd = "cd \"#{dir}\" && webapp/bin/rails server thin"
cmd = "cd \"#{dir}\" && #{dir}/webapp/bin/rails server thin"
if detached
Kernel::exec("screen -d -m #{cmd}")
else
Expand Down
6 changes: 2 additions & 4 deletions lib/toaster/chef/chef_util.rb
Original file line number Diff line number Diff line change
Expand Up @@ -161,9 +161,8 @@ def self.create_chef_config(solo_file)
Util.write(solo_file, (<<-EOF
cookbook_path [
"#{File.expand_path(File.join(Dir.pwd, "cookbooks"))}",
"#{File.expand_path(Dir.pwd)}",
"#{File.join(root_dir, "chef", "cookbooks")}",
"#{@@DEFAULT_COOKBOOKS_DIR}"
"#{@@DEFAULT_COOKBOOKS_DIR}",
"#{File.join(root_dir, "chef", "cookbooks")}"
]
EOF
), true)
Expand Down Expand Up @@ -809,7 +808,6 @@ def self.parse_resources(cookbook, recipe_name, version="latest", result = {}, c
puts "WARN: Could not parse code file #{recipe_file} : #{line + 1}"
else
resource_obj = ResourceInspector.get_resource_from_source(code, attributes_source)
puts "received resource_obj: #{resource_obj}"
result[cookbook][recipe_name]["resources"][line] = code
result[cookbook][recipe_name]["resource_objs"][line] = resource_obj
if !code.match(/not_if\s*/) && !code.match(/only_if\s*/)
Expand Down
28 changes: 1 addition & 27 deletions lib/toaster/chef/failsafe_resource_parser.rb
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@ def validate(opts, map)

module DSL
module Recipe
#alias_method :old_method_missing, :method_missing
$old_mm = ::Chef::DSL::Recipe.instance_method(:method_missing)
def attributes_proxy=(attrs)
@attributes_proxy = attrs
Expand All @@ -70,18 +69,10 @@ def instance_eval(string, filename=nil, lineno=nil, &block)
begin
super
rescue Object => ex
puts "WARN: cannot run instance_eval on recipe: #{ex}"
puts "WARN: cannot run instance_eval on recipe: #{ex} - #{ex.backtrace.join("\n")}"
end
end
# def build_resource(type, name, created_at=nil, &resource_attrs_block)
# if !name
# name = "__unnamed__"
# end
# super(type, name, created_at, &resource_attrs_block)
# end
def method_missing(method_symbol, *args, &block)
#puts "method_missing:"
puts method_symbol
begin

# code copied from chef/dsl/recipe.rb
Expand All @@ -104,33 +95,16 @@ def method_missing(method_symbol, *args, &block)
end
end

#old_method_missing(method_symbol, args, block)
#super
if caller.size > 250
puts $old_mm.object_id
puts "--"
puts ::Chef::DSL::Recipe.instance_method(:method_missing).object_id
puts "-------"
return nil
end
# puts "--->"
# puts self
# $old_mm.bind(self).(method_symbol, *args, &block)
rescue Object => ex
# begin
#puts ex
#puts ex.backtrace.join(" \n")
proxy = @attributes_proxy ? @attributes_proxy : $new_node
#puts "proxy (in new line):"
#puts proxy
#puts method_symbol
proxy.send(method_symbol, *args, &block)
# rescue Object => ex1
# puts ex1
# puts ex1.backtrace.join(" \n")
# puts "----"
# puts caller
# end
end
end
end
Expand Down
7 changes: 1 addition & 6 deletions lib/toaster/chef/resource_inspector.rb
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ def self.get_accessed_parameters(task_or_sourcecode, cookbook_paths = [])
if task_or_sourcecode.kind_of?(Task)
param = TaskParameter.new(task_or_sourcecode, param)
else
param = TaskParameter.new(nil, param)
param = TaskParameter.new(:key => param)
end
exists = result.find { |p| (p.kind_of?(TaskParameter) ? p.key : p) ==
(param.kind_of?(TaskParameter) ? param.key : param) }
Expand Down Expand Up @@ -191,11 +191,6 @@ def self.get_resource_from_source(resource_src, attribute_src, cookbook_paths =
msg = ex.to_s
puts msg if attempt <= 1
puts ex.backtrace if attempt <= 1
#puts "----"
#puts resource_src
#puts "----"
# puts msg
# puts ex.backtrace

if msg.match(/Cannot find a resource for/)
pkg_name = msg.gsub(/.*for ([a-z0-9A-Z_]+) on.*/, '\1').to_s
Expand Down
2 changes: 2 additions & 0 deletions lib/toaster/model/key_value_pair.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
# Author: Waldemar Hummer (hummer@dsg.tuwien.ac.at)
#

require "active_record"

module Toaster
class KeyValuePair < ActiveRecord::Base
self.inheritance_column = :type
Expand Down
2 changes: 0 additions & 2 deletions lib/toaster/model/task_parameter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@
module Toaster
class TaskParameter < KeyValuePair

#attr_accessor :uuid, :task, :key, :value, :type, :constraints

@@id_attributes = ["task_id", "key", "value", "type"]

def initialize(attr_hash)
Expand Down
7 changes: 0 additions & 7 deletions test/spec/toaster/chef/resource_inspector_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,20 +21,13 @@
end
EOC

task1 = Task.new(nil, nil, code1)

it "returns only one attribute if multiple occurrences" do
params = ResourceInspector.get_accessed_parameters(code1)
params.size.should eq(1)
params = ResourceInspector.get_accessed_parameters(task1)
params.size.should eq(1)
end
it "parses attributes correctly" do
params = ResourceInspector.get_accessed_parameters(code1)
params = params.collect { |p| p.key }
params.should eq(["'apache'.'dir'"])
params = ResourceInspector.get_accessed_parameters(task1)
params = params.collect { |p| p.key }
params.should eq(["'apache'.'dir'"])
end
end
2 changes: 1 addition & 1 deletion webapp/app/controllers/scripts_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ def import_chef
params[:cookbook], rec, params[:cookbook_version])[params[:cookbook]][rec]
recipe_info["resources"].each do |line,code|
action = "__action__"
resource = "__action__"
resource = "__resource__"
if recipe_info["resource_objs"][line]
action = recipe_info["resource_objs"][line].action
action = action.join(" , ") if action.kind_of?(Array)
Expand Down
2 changes: 1 addition & 1 deletion webapp/app/views/test/gen.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ begin
test_coverage = TestCoverage.new(test_suite, state_graph)
end

test_suites = Toaster::TestSuite.find()
test_suites = Toaster::TestSuite.find().to_a
test_suites.sort! { |x,y| (!x.last_test || !y.last_test) ? 0 :
x.last_test.start_time.to_i <=> y.last_test.start_time.to_i }
rescue => ex
Expand Down
1 change: 0 additions & 1 deletion webapp/config/application.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

root_dir = File.join(File.dirname(__FILE__), "..", "..")
$LOAD_PATH << File.join(root_dir, "lib")
puts File.join(root_dir, "lib")
# load dependencies using bundler
require "toaster/util/load_bundler"

Expand Down

0 comments on commit 89f7d25

Please sign in to comment.