-
-
Save sawanoboly/6633671 to your computer and use it in GitHub Desktop.
Chefのレシピ用リソースに指定する属性のバリデーションを手軽にチェック ref: http://qiita.com/sawanoboly/items/04a22981a7436e737af4
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# echo '* abcde * * * ' | crontab -u root - | |
"-":0: bad hour | |
errors in crontab file, can't install. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# cat <<EOL | chef-apply -s | |
> cron 'hoge' do | |
> minute 'abcde' | |
> end | |
> EOL | |
Recipe: (chef-apply cookbook)::(chef-apply recipe) | |
* cron[hoge] action create | |
================================================================================ | |
Error executing action `create` on resource 'cron[hoge]' | |
================================================================================ | |
Chef::Exceptions::Cron | |
---------------------- | |
Error updating state of hoge, exit: 1 | |
Resource Declaration: | |
--------------------- | |
# In /tmp/recipe-temporary-file20130920-9634-1ps5rqz | |
1: cron 'hoge' do | |
2: minute 'abcde' | |
3: end | |
Compiled Resource: | |
------------------ | |
# Declared in /tmp/recipe-temporary-file20130920-9634-1ps5rqz:1:in `run_chef_recipe' | |
cron("hoge") do | |
action :create | |
retries 0 | |
retry_delay 2 | |
minute "abcde" | |
hour "*" | |
day "*" | |
month "*" | |
weekday "*" | |
user "root" | |
cookbook_name "(chef-apply cookbook)" | |
recipe_name "(chef-apply recipe)" | |
end | |
[2013-09-20T05:18:47+00:00] FATAL: Stacktrace dumped to /var/chef/cache/chef-stacktrace.out | |
[2013-09-20T05:18:47+00:00] FATAL: Chef::Exceptions::Cron: cron[hoge] ((chef-apply cookbook)::(chef-apply recipe) line 1) had an error: Chef::Exceptions::Cron: Error updating state of hoge, exit: 1 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
> cron.minute "abcde" | |
=> "abcde" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
> require 'chef' | |
=> true | |
> cron = Chef::Resource::Cron.new 'my_cron' | |
=> | |
<cron[my_cron] | |
@name: "my_cron" | |
@noop: nil | |
@before: nil | |
@params: {} | |
@provider: nil | |
@allowed_actions: [:nothing, :create, :delete] | |
@action: :create @updated: false @updated_by_last_action: false | |
@supports: {} | |
@ignore_failure: false | |
@retries: 0 | |
@retry_delay: 2 | |
@source_line: nil | |
@elapsed_time: 0 | |
@resource_name: :cron | |
@minute: "*" | |
@hour: "*" | |
@day: "*" | |
@month: "*" | |
@weekday: "*" | |
@command: nil | |
@user: "root" | |
@mailto: nil | |
@path: nil | |
@shell: nil | |
@home: nil | |
@environment: {} | |
> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
## 何も渡さなければ現在の値 | |
> cron.minute | |
=> "*" | |
## なにか渡せば代入 | |
> cron.minute 50 | |
=> "50" | |
## バリデーションに引っかかる例1、99分 | |
> cron.minute 99 | |
RangeError: RangeError | |
from /Users/sawanoboriyu/Dev/Reading/chef/lib/chef/resource/cron.rb:56:in 'minute' | |
## バリデーションに引っかかる例2、コマンドラインがStringでない | |
> cron.command 12 | |
Chef::Exceptions::ValidationFailed: Option command must be a kind of String! You passed 12. | |
from /Users/sawanoboriyu/Dev/Reading/chef/lib/chef/mixin/params_validate.rb:150:in '_pv_kind_of' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment