LoginSignup
0
1

More than 5 years have passed since last update.

備忘録 Serverspec fileリソースのbe_linked_to での苦悩。

Last updated at Posted at 2017-06-01

Serverspec、はじめました。

1. やりたいこと

指定したファイルがシンボリックリンクになっているかどうかを確認した。

■対象ファイル

・/etc/localtime
・/etc/pam.d/system-auth
・/etc/pam.d/password-auth


$ ls -l /etc/localtime
lrwxrwxrwx 1 root root 25 Apr 26 13:50 /etc/localtime -> /usr/share/zoneinfo/Japan
$ ls -l /etc/pam.d/system-auth
lrwxrwxrwx. 1 root root 14 Jan 13 01:51 /etc/pam.d/system-auth -> system-auth-ac
$ ls -l /etc/pam.d/password-auth
lrwxrwxrwx. 1 root root 16 Jan 13 01:51 /etc/pam.d/password-auth -> password-auth-ac

2.コードを書く

linuxos_spec.rb
require 'spec_helper'

describe file('/etc/localtime') do
    it { should be_linked_to '/usr/share/zoneinfo/Japan' }
end

describe file('/etc/pam.d/password-auth') do
it { should be_liked_to '/etc/pam.d/password-auth-ac' }
end

describe file('/etc/pam.d/system-auth') do
it { should be_liked_to '/etc/pam.d/system-auth-ac' }
end

3.テスト実行する

悲しいかな失敗に終わる。

$ rake spec:test01 ASK_SUDO_PASSWORD=1
(in /home/serverspec)
/opt/chef/embedded/bin/ruby -I/opt/chef/embedded/lib/ruby/gems/2.3.0/gems/rspec-support-3.5.0/lib:/opt/chef/embedded/lib/ruby/gems/2.3.0/gems/rspec-core-3.5.4/lib /opt/chef/embedded/lib/ruby/gems/2.3.0/gems/rspec-core-3.5.4/exe/rspec --pattern spec/test01/\*_spec.rb
Enter sudo password:

File "/etc/localtime"
test@test01's password:
  should be linked to "/usr/share/zoneinfo/Japan"

File "/etc/pam.d/password-auth"
  should be liked to "/etc/pam.d/password-auth-ac" (FAILED - 1)

File "/etc/pam.d/system-auth"
  should be liked to "/etc/pam.d/system-auth-ac" (FAILED - 2)

Failures:

  1) File "/etc/pam.d/password-auth" should be liked to "/etc/pam.d/password-auth-ac"
     On host `sistest01'
     Failure/Error: it { should be_liked_to '/etc/pam.d/password-auth-ac' }
       expected File "/etc/pam.d/password-auth" to respond to `liked_to?`

     # ./spec/test01/linuxos_spec.rb:8:in `block (2 levels) in <top (required)>'

  2) File "/etc/pam.d/system-auth" should be liked to "/etc/pam.d/system-auth-ac"
     On host `test01'
     Failure/Error: it { should be_liked_to '/etc/pam.d/system-auth-ac' }
       expected File "/etc/pam.d/system-auth" to respond to `liked_to?`

     # ./spec/test01/linuxos_spec.rb:12:in `block (2 levels) in <top (required)>'

Finished in 2.89 seconds (files took 2.34 seconds to load)
3 examples, 2 failures

Failed examples:

rspec ./spec/test01/linuxos_spec.rb:8 # File "/etc/pam.d/password-auth" should be liked to "/etc/pam.d/password-auth-ac"
rspec ./spec/test01/linuxos_spec.rb:12 # File "/etc/pam.d/system-auth" should be liked to "/etc/pam.d/system-auth-ac"

/opt/chef/embedded/bin/ruby -I/opt/chef/embedded/lib/ruby/gems/2.3.0/gems/rspec-support-3.5.0/lib:/opt/chef/embedded/lib/ruby/gems/2.3.0/gems/rspec-core-3.5.4/lib /opt/chef/embedded/lib/ruby/gems/2.3.0/gems/rspec-core-3.5.4/exe/rspec --pattern spec/test01/\*_spec.rb failed

/etc/pam.d/system-authも/etc/pam.d/password-authもシンボリックリンクファイルですが?

中年の悩みは解消しないこと3日・・・

0
1
2

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
1