ресурсы inspec не определены - PullRequest
0 голосов
/ 04 июня 2018

Я использую тестовую среду inspec с ruby ​​для тестирования инфраструктуры.Я написал тест в элементах управления

Вот мой тест:

require 'aws-sdk'

credentials = Aws::AssumeRoleCredentials.new(
   role_arn: 'some_value',
   role_session_name: 'pipeline')

client_params = {
  region: 'ap-southeast-2',
  credentials: credentials
}

ec2_client = Aws::EC2::Resource.new(client_params)
instance = ec2_client.instances(filters: [{name:'tag:component', values: ['api', 'fxsnet', 'admin']}])


puts "ec2 Client is : #{ec2_client}"
puts "list of instances based on tag is: #{instance}"


instance.each do |i| 
  puts 'ID:    ' + i.id
  puts 'State: ' + i.state.name

#for each of the instance check if tmp file exist 
  describe file('/tmp') do                  # The actual test
    it { should exist }
  end 
end

но при выполнении я получаю ошибку ниже

An error occurred while loading ./inspec-infra-tests/controls/apiInstances.rb.
Failure/Error:
  describe file('/tmp') do                  # The actual test
    it { should exist }
  end

NoMethodError:
  undefined method `file' for main:Object
  Did you mean?  fail
# ./inspec-infra-tests/controls/apiInstances.rb:46:in `block in <top (required)>'
# ./inspec-infra-tests/controls/apiInstances.rb:35:in `<top (required)>'
No examples found.

0 examples, 0 failures, 0 passed

файл InSpec для аудита ресурсапроверить все типы системных файлов, включая файлы, каталоги, символические ссылки, именованные каналы, сокеты и т. д.

#InspecWithRuby #inspec #inspecResourcesNotIdentified #InspecResourcesNotFound 

Ответы [ 2 ]

0 голосов
/ 01 октября 2018

Я не знаком с AWS SDK, но если вы хотите проверить набор файлов с помощью InSpec, вы можете сделать это следующим образом:

myfiles = %w(temp.err temp.out)

control 'tmp-files-1' do
  title 'Test for a set of temp files.'
  myfiles.each do |myfile|
    describe file('/tmp/' + myfile) do
      it { should exist }
    end
  end
end

Если вы выполните этот элемент управления, онвернет следующее (при условии, что эти файлы действительно существуют в вашей папке /tmp:

  ✔  tmp-files-1: Test for a set of temp files.
     ✔  File /tmp/temp.err should exist
     ✔  File /tmp/temp.out should exist

Я надеюсь, что вы можете взять этот пример и адаптировать его к вашим потребностям AWS.

0 голосов
/ 07 июня 2018

Мне кажется, что вы пытаетесь запустить тест inspec, выполнив с помощью ruby, а не с inspec exec.Я могу воспроизвести локально, вставив ваш тест в файл:

inspec_example.rb

  describe file('/tmp') do                  # The actual test
    it { should exist }
  end

Выполнение непосредственно с ruby ​​

ruby inspec_example.rb дает:

Traceback (most recent call last):
inspec_example.rb:1:in `<main>': undefined method `file' for main:Object (NoMethodError)
Did you mean?  fail

Выполнение с inspec exec работает как ожидалось:

inspec exec inspec_example.rb дает:

Profile: tests from inspec_example.rb (tests from inspec_example.rb)
Version: (not specified)
Target:  local://

  File /tmp
     ✔  should exist
...