0

Jenkins ジョブで Chef Inspec exec プロファイルを実行していますが、Rspec 非推奨の警告が返されます。問題は、これらの警告が inspec exec コマンドが作成する json 出力に含まれていることです。sed/awk を試して、開始パターンと終了パターン /{/ 、 /}/ を使用して json オブジェクトの外側のすべての文字を削除しましたが、何も機能していません、テキストがまだファイルにあるたびに。両方の構文を許可するために、spec_helper.rb ファイルに rspec 例外を追加しましたが、それでも警告が表示されます。次を含むファイルが残っています:

Invalid expiration date or inactive date or both
Invalid expiration date or inactive date or both

1 deprecation warning total
{"version":"0.30.0","profiles":{  ..... }- this part is actually valid json, excluding from this post to keep it short.

Inspec 0.30.0、Ruby 2.0.0p645、Rspec 3.5.2 を使用。

ssh を介してローカルターゲットで inspec プロファイルを実行するために使用しているコマンドは次のとおりです。

    VmIp=$(vmrun getGuestIPAddress output-vmware-iso/${templateName}.vmx -wait)
    inspec exec  ./inspecRepo/ --format json-min -t ssh://vagrant@${VmIp} --password vagrant --sudo | tee Test_Results.json

Jenkins ジョブ出力のスニペットを次に示します。

+ VmPath=/app_2/jenkins-work/workspace/xl-release/output-vmware-iso/rhel7.vmware.template.vmx
++ vmrun getGuestIPAddress output-vmware-iso/rhel7.vmware.template.vmx -wait
+ VmIp=172.16.81.159
+ inspec exec ./inspecRepo/ --format json -t ssh://vagrant@172.16.81.159 --password vagrant --sudo
+ tee Test_Results.json
./inspecRepo/controls/filesystem.rb:60: warning: already initialized constant #<Class:0x00000001a25ac0>::BASELINE
./inspecRepo/controls/filesystem.rb:60: warning: previous definition of BASELINE was here
./inspecRepo/controls/filesystem.rb:60: warning: already initialized constant #<Class:0x00000001a25ac0>::BASELINE
./inspecRepo/controls/filesystem.rb:60: warning: previous definition of BASELINE was here
./inspecRepo/controls/filesystem.rb:60: warning: already initialized constant #<Class:0x00000001a25ac0>::BASELINE
./inspecRepo/controls/filesystem.rb:60: warning: previous definition of BASELINE was here

Deprecation Warnings:

Using `should` from rspec-expectations' old `:should` syntax without explicitly enabling the syntax is deprecated. Use the new `:expect` syntax or explicitly enable `:should` with `config.expect_with(:rspec) { |c| c.syntax = :should }` instead. Called from ./inspecRepo/controls/app_config.rb:466:in `block (4 levels) in load'.


If you need more of the backtrace for any of these deprecations to
identify where to make the necessary changes, you can configure
`config.raise_errors_for_deprecations!`, and it will turn the
deprecation warnings into errors, giving you the full backtrace.
Invalid expiration date or inactive date or both
Invalid expiration date or inactive date or both

1 deprecation warning total
{"version":"0.30.0","profiles":{"rhel7-baseline":{ ..............

:should & :expect syntax include を追加した spec_helper.rb のスニペットを次に示します。

   Spec_helper.rb :
# See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
RSpec.configure do |config|
config.expect_with(:rspec){|c| c.syntax = [:should, :expect]}
  # rspec-expectations config goes here. You can use an alternate
  # assertion/expectation library such as wrong or the stdlib/minitest
  # assertions if you prefer.
  config.expect_with :rspec do |expectations|

構文警告を生成しているテストは次のとおりです: \

    control 'password-inactive' do

  impact 0.5

  title "Ensure password inactivity is configured"

  desc "The password inactive in /etc/shadow is configured"



  DATE_FMT = '%b %d, %Y' # date format used by chage(1) as specified by strptime(3)

  command('egrep ^[^:]+:[^\!*] /etc/shadow | cut -d: -f1').stdout.each_line do |line|   # extract all users(username) with password



    pwExipre = command("chage --list #{line}").stdout.split("\n")[1].split(":")[1].strip  # extract date and convert to right format

    pwInactive = command("chage --list #{line}").stdout.split("\n")[2].split(":")[1].strip

    if pwExipre == 'never' || pwInactive == 'never'

      puts "Invalid expiration date or inactive date or both"

      describe true do

        it { should eq false }

      end

    else

      expire = Date.strptime(pwExipre, DATE_FMT) # convert to desired format

      inactive = Date.strptime(pwInactive, DATE_FMT)

      describe (inactive - expire) do

        it { should eq 30 } # 30 days' difference

      end

    end

  end

end
4

1 に答える 1

0

代わりにnewexpect()またはis_expected構文を使用するようにコードを修正するだけです。より簡単に思えますが、それはとにかく前進する標準です。失敗した実際のテスト コードを含めると、より具体的になる可能性があります。

于 2016-08-20T01:32:52.023 に答える