How do you debug opscode chef / ruby errors? - ruby

I'm a python guy and struggling to make sense of ruby stacktraces. I'd appreciate if anyone can tell me a systematic method to get to the bottom of what is causing a message like this. Running Opscode 11.4. I thought its probably due to an outdated opscode cookbook, so updated ark to 0.0.17 - the latest. However the problem persists. I thought perhaps it was a dependancy of another cookbook. It is, elasticsearch, however no version is specified. In any case this method seems like guess work however there is not a clear stack trace of where the underlaying problem is. What is the correct way to action such a message?
Synchronizing Cookbooks:
- users
- ark
- elasticsearch
- openssl
- sudo
- yum
- ohai
- munin
- bluepill
- runit
- postgresql
- build-essential
- apt
- git
- nginx
Compiling Cookbooks...
================================================================================
Recipe Compile Error in /var/chef/cache/cookbooks/ark/libraries/resource_ark.rb
================================================================================
NoMethodError
-------------
undefined method `attribute' for Chef::Resource::Ark:Class
Cookbook Trace:
---------------
/var/chef/cache/cookbooks/ark/libraries/resource_ark.rb:37
Relevant File Content:
----------------------
/var/chef/cache/cookbooks/ark/libraries/resource_ark.rb:
30: #allowed_actions.push(:install, :dump, :cherry_pick, :put, :install_with_make, :configure, :setup_py_build, :setup_py_install, :setup_py)
31: #action = :install
32: #provider = Chef::Provider::Ark
33: end
34:
35: attr_accessor :path, :release_file, :prefix_bin, :prefix_root, :home_dir, :extension, :version
36:
37>> attribute :owner, :kind_of => String, :default => 'root'
38: attribute :group, :kind_of => [String, Fixnum], :default => 0
39: attribute :url, :kind_of => String, :required => true
40: attribute :path, :kind_of => String, :default => nil
41: attribute :full_path, :kind_of => String, :default => nil
42: attribute :append_env_path, :kind_of => [TrueClass, FalseClass], :default => false
43: attribute :checksum, :regex => /^[a-zA-Z0-9]{64}$/, :default => nil
44: attribute :has_binaries, :kind_of => Array, :default => []
45: attribute :creates, :kind_of => String, :default => nil
46: attribute :release_file, :kind_of => String, :default => ''
[2013-02-25T00:19:30+00:00] ERROR: Running exception handlers
[2013-02-25T00:19:30+00:00] FATAL: Saving node information to /var/chef/cache/failed-run-data.json
[2013-02-25T00:19:30+00:00] ERROR: Exception handlers complete
Chef Client failed. 0 resources updated
[2013-02-25T00:19:30+00:00] FATAL: Stacktrace dumped to /var/chef/cache/chef-stacktrace.out
[2013-02-25T00:19:30+00:00] FATAL: NoMethodError: undefined method `attribute' for Chef::Resource::Ark:Class

Seems that the community site version 0.0.17 is not the same as the current head even though they have the same version number. Installing source from github https://github.com/opscode-cookbooks/ark/commit/b8c4aaf17d6e88aa857af6b2038eb0dba9981c0b solved the problem.

Related

bundle exec rake snorby:setup - error rake aborted! invalid hash

While executing below command to setup the snorby on ruby on rails, i get the error: rake aborted! invalid hash. Pls help
#bundle exec rake snorby:setup
#Jammit Warning: Asset compression disabled -- Java unavailable.
No time_zone specified in snorby_config.yml; detected time_zone: Asia/Kolkata
750d6d911891ab576bdbc6b1c4dc5ecf73cb95fd145ab7b16194636094daa3b4ba42b01c05d991c8c174919162e00152a129c645b1e0508850042cf224f165af
mysql: [Warning] Using a password on the command line interface can be insecure.
ERROR 1007 (HY000) at line 1: Can't create database 'snorby'; database exists
[datamapper] Finished auto_upgrade! for :default repository 'snorby'
rake aborted!
invalid hash
Tasks: TOP => db:seed
(See full trace by running task with --trace)
Below are the versions currently used:
#ruby 1.9.3p551 (2014-11-13 revision 48406) [x86_64-linux]
#Bundler version 1.9.3
#Ubuntu 20.04 LTS (focal)
Modifying the entries in seeds.rb file as given below, the error has been resolved. In the seeds.rb changed the line for Default user setup from
User.create(:name => 'Administrator', :email => 'snorby#snorby.org', :password => 'snorby', :password_confirmation => 'snorby', :admin => true) if User.all.blank?
To
User.create(:name => 'Administrator', :email => 'snorby#snorby.org', :encrypted_password => 'snorby', :password_confirmation => 'snorby', :admin => true) if User.all.blank?
i.e the :password was changed to :encrypted_password

undefined method `entry_mapping' for nil:NilClass

I am trying to play around with the RODA Ruby web framework based on Rack. However, I am having issues with using Minitest with the framework. RSpec was hectic with it too unlike Rails. I tried to reproduce the error with pry, but I couldn't make sense of it. How should I fix this? I am getting
undefined method `entry_mapping' for nil:NilClass.
Below is the associated code:
Gemfile
gem 'contentful_model', '~> 1.3' # ActiveModel-like wrapper for the Contentful SDKs
group :test do
gem 'capybara'
gem 'minitest', '>= 5.7.0'
gem 'minitest-hooks', '>= 1.1.0'
gem "minitest-global_expectations"
gem "warning"
gem 'pry'
end
models/recipe.rb
require 'contentful_model'
class Recipe < ContentfulModel::Base
self.content_type_id = 'recipe'
def self.all_recipes
all.load!
end
end
app.rb | Tree Routing
require './.env' if File.exist?(".env.rb")
require './config/initializers/contentful_model'
require 'roda'
require './models/recipe'
require 'tilt/sass'
class App < Roda
hash_routes do
view '', 'index'
end
route do |r|
#recipes = Recipe.all_recipes
r.public
r.assets
check_csrf!
r.hash_routes('')
r.get String do |id|
#recipe_details = Recipe.find(id)
next unless #recipe_details
view 'show'
end
end
end
spec/models/spec_helper.rb
ENV["RACK_ENV"] = "test"
require_relative '../../models/recipe'
require_relative '../minitest_helper'
spec/models/recipe_spec.rb
require_relative 'spec_helper'
describe Recipe do
let(:recipes) { Recipe.all_recipes }
describe '.all_recipes' do
it 'return all records with content type recipe' do
recipes = Recipe.all_recipes # undefined method `entry_mapping' for nil:NilClass
expect(recipes).to all must_be Recipe
end
end
end
pry debug
From: /Users/tiwa/RubymineProjects/marley-spoon-roda/spec/models/recipe_spec.rb:27 .all_recipes#test_0001_return all records with content type recipe:
24: it 'return all records with content type recipe' do
25: recipes = Recipe.all_recipes # undefined method `entry_mapping' for nil:NilClass
26: binding.pry
=> 27: expect(recipes).to all must_be Recipe
28: end
[1] pry(#<.all_recipes>)> Recipe.all_recipes
NoMethodError: undefined method `entry_mapping' for nil:NilClass
from /Users/tiwa/.gem/ruby/2.7.1/gems/contentful_model-1.3.0/lib/contentful_model/base.rb:124:in `mapping?'
I see the code in contentful_model-1.3.0/lib/contentful_model/base.rb:124 is:
ContentfulModel.configuration.entry_mapping.key?(#content_type_id)
If error msg is undefined method `entry_mapping' for nil:NilClass then
ContentfulModel.configuration
Is nil
To fix this you need configure ContentfulModel. Something like that:
ContentfulModel.configure do |config|
config.access_token = "your access token in here" # Required
config.preview_access_token = "your preview token in here" # Optional - required if you want to use the preview API
config.management_token = "your management token in here" # Optional - required if you want to update or create content
config.space = "your space id in here" # Required
config.environment = "master" # Optional - defaults to 'master'
config.default_locale = "en-US" # Optional - defaults to 'en-US'
config.options = { # Optional
# Extra options to send to the Contentful::Client and Contentful::Management::Client
# See https://github.com/contentful/contentful.rb#configuration
# Optional:
# Use `delivery_api` and `management_api` keys to limit to what API the settings
# will apply. Useful because Delivery API is usually visitor facing, while Management
# is used in background tasks that can run much longer. For example:
delivery_api: {
timeout_read: 6
},
management_api: {
timeout_read: 100
}
}
end
With this config this call is not more nil
ContentfulModel.configuration
See https://github.com/contentful/contentful_model

Unable to Add a Chart to Excel Workbook

I am using the writeexcel gem.
The following is my code snippet:
workbook = WriteExcel.new("graphTest.xls")
worksheet = workbook.add_worksheet(sheetname = "Test")
chart = workbook.add_chart(
:type => "Chart::column",
:name => "Chart",
:embedded => 1
)
and I get the following error:
undefined method `new' for nil:NilClass (NoMethodError)
Full error:
/Users/guy/.rvm/gems/ruby-2.3.0/gems/writeexcel-1.0.5/lib/writeexcel/chart.rb
:79:in 'factory': undefined method 'new' for nil:NilClass (NoMethodError)
from /Users/guy/.rvm/gems/ruby-2.3.0/gems/writeexcel-1.0.5/lib/writee
xcel/workbook.rb:334:in 'add_chart'
from excelGraph.rb:18:in '<main>'
Why am I getting this error message if I am taking an example straight from the gem documentation found here?
The, "Gotcha," found within your code snippet is the capitalization of column in Chart::column:
chart = workbook.add_chart(
:type => "Chart::Column", #capitalized
:name => "Chart",
:embedded => 1
)
instead of
chart = workbook.add_chart(
:type => "Chart::column", #all lowercase
:name => "Chart",
:embedded => 1
)

Unable to add cookbook dependency in metadata.rb chef

I am trying to include my abc-cookbook which has a ruby service installed in metadata.rb of another cookbook (say xyz-cookbook) which i have to launch.
But while deploying the instance in opswork my setup is failing with an error as :
STDERR: Unable to satisfy constraints on package abc-cookbook, which does not exist, due to solution constraint (xyz-cookbook = 0.1.0). Solution constraints that may result in a constraint on abc-cookbook: [(xyz-cookbook = 0.1.0) -> (abc-cookbook >= 0.0.0)]
Missing artifacts: abac-cookbook
Demand that cannot be met: (xyz-cookbook = 0.1.0)
Unable to find a solution for demands: activemq (1.3.3), apacheds (0.1.0), apt (
---- End output of /opt/aws/opsworks/local/bin/berks vendor /opt/aws/opsworks/current/berkshelf-cookbooks ----
Ran /opt/aws/opsworks/local/bin/berks vendor /opt/aws/opsworks/current/berkshelf-cookbooks returned 106
Cookbook Trace:
---------------
/var/lib/aws/opsworks/cache.stage1/cookbooks/opsworks_commons/libraries/shellout.rb:9:in `shellout'
/var/lib/aws/opsworks/cache.stage1/cookbooks/opsworks_berkshelf/providers/runner.rb:13:in `block (3 levels) in class_from_file'
Resource Declaration:
---------------------
# In /var/lib/aws/opsworks/cache.stage1/cookbooks/opsworks_berkshelf/providers/runner.rb
11: ruby_block 'Install the cookbooks specified in the Berksfile and their dependencies' do
12: block do
13: Chef::Log.info OpsWorks::ShellOut.shellout(
14: berks_install_command,
15: :cwd => ::File.dirname(OpsWorks::Berkshelf.berksfile),
16: :environment => {
17: "BERKSHELF_PATH" => Opsworks::InstanceAgent::Environment.berkshelf_cache_path,
18: "LC_ALL" => "en_US.UTF-8"
19: }
20: )
21:
22: ::FileUtils.rm_rf Opsworks::InstanceAgent::Environment.berkshelf_cache_path
23: end
24:
25: only_if do
26: OpsWorks::Berkshelf.berkshelf_installed? && OpsWorks::Berkshelf.berksfile_available?
27: end
28: end
29: end
Compiled Resource:
------------------
# Declared in /var/lib/aws/opsworks/cache.stage1/cookbooks/opsworks_berkshelf/providers/runner.rb:11:in `block in class_from_file'
ruby_block("Install the cookbooks specified in the Berksfile and their dependencies") do
action "run"
retries 0
retry_delay 2
block_name "Install the cookbooks specified in the Berksfile and their dependencies"
cookbook_name "opsworks_berkshelf"
block #<Proc:0x0055813e8bcb70#/var/lib/aws/opsworks/cache.stage1/cookbooks/opsworks_berkshelf/providers/runner.rb:12>
only_if { #code block }
end
[2016-01-08T12:33:45+00:00] INFO: Running queued delayed notifications before re-raising exception
[2016-01-08T12:33:45+00:00] ERROR: Running exception handlers
[2016-01-08T12:33:45+00:00] ERROR: Exception handlers complete
[2016-01-08T12:33:45+00:00] FATAL: Stacktrace dumped to /var/lib/aws/opsworks/cache.stage1/chef-stacktrace.out
[2016-01-08T12:33:45+00:00] ERROR: ruby_block[Install the cookbooks specified in the Berksfile and their dependencies] (/var/lib/aws/opsworks/cache.stage1/cookbooks/opsworks_berkshelf/providers/runner.rb line 11) had an error: Mixlib::ShellOut::ShellCommandFailed
Also I have added the dependency in xyz-cookbook metadata.rb as :
name 'xyz-cookbook'
maintainer ''
maintainer_email ''
license 'All rights reserved'
description 'Installs/Configures create'
long_description 'Installs/Configures create'
version '0.1.0'
depends 'abc-cookbook'
What am I missing and what is the error actually..
I did resolve this by adding dependency in my root Berksfile, which i missed even though i included my cookbook in another custom cookbook.
This helped me :
Important
Do not declare cookbooks by including a metadata line in your
Berksfile and declaring the cookbook dependencies in metadata.rb. For
this to work correctly, both files must be in the same directory. With
AWS OpsWorks, the Berksfile must be in the repository's root
directory, but metadata.rb files must be in their respective cookbook
directories. You should instead explicitly declare external cookbooks
in the Berksfile

Sinatra/ActiveRecord can't handle simultaneous requests?

This is my first Sinatra project and I'm pretty late in and I'm realizing that when make multiple requests at once that use ActiveRecord that I run into problems. If I only make one request, each one works on its own. But when I call both at once, I get failure.
So far I've narrowed it down to the problem being two ActiveRecord requests simultaneously. Maybe I'm not setting up ActiveRecord correctly? I use PostgreSQL because Heroku uses it, and am no inclined to change. (The issue happens on Heroku, too.)
Here's the log:
192.168.1.113 - - [30/Sep/2012:10:33:00 MDT] "GET /version/current?platform=android HTTP/1.1" 200 33
- -> /version/current?platform=android ActiveRecord::StatementInvalid - NoMethodError: undefined method `fields' for nil:NilClass: SELECT "rankings".* FROM "rankings" WHERE "rankings"."user_id" = 1 LIMIT 1:
/Users/zablanc/.rvm/gems/ruby-1.9.3-head#emm/gems/activerecord-3.2.7/lib/active_record/connection_adapters/postgresql_adapter.rb:667:in `block in exec_query'
...
Warning! Rack::Session::Cookie data size exceeds 4K.
Warning! Rack::Session::Cookie failed to save session. Content dropped.
192.168.1.113 - - [30/Sep/2012:10:33:01 MDT] "GET /badges/all HTTP/1.1" 200 311
- -> /badges/all
192.168.1.113 - - [30/Sep/2012:10:33:01 MDT] "GET /moves/ranking/all HTTP/1.1" 500 166185
- -> /moves/ranking/all
I have no idea how to shut up those cookie warnings, tho they seem to have no effect on the app. Here's how I configure my app (in a config file I require from the main script):
enable :logging
use ActiveRecord::ConnectionAdapters::ConnectionManagement
use Rack::Session::Cookie, :key => 'rack.session',
:path => '/',
:expire_after => 31_536_000, # In seconds
:secret => 'jeowkfj...secret...kjn5'
ActiveRecord::Base.include_root_in_json = false
def establish_connection(url)
db = URI.parse(url)
ActiveRecord::Base.establish_connection(
:adapter => db.scheme == 'postgres' ? 'postgresql' : db.scheme,
:host => db.host,
:port => db.port,
:username => db.user,
:password => db.password,
:database => db.path[1..-1],
:encoding => 'utf8'
)
end
configure :development do
establish_connection('postgres://postgres:postgres#localhost:5432/emm')
end
configure :test do
establish_connection('postgres://postgres:postgres#localhost:5432/emm-test')
end
configure :production do
establish_connection(ENV['DATABASE_URL'])
end
I'm guessing I'm not setting up ActiveRecord right, but I think it's just like the tutorials I've seen. What gives?
Sounds like you are using threads but have some non-thread-safe code in your application.
Which webserver are you using, which middleware are you using, which postgresql gem are you using, did you check to see that all your gems are thread-safe?

Resources