Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/excel/23.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Chef infra 非核心资源的chefspec测试_Chef Infra_Chefspec - Fatal编程技术网

Chef infra 非核心资源的chefspec测试

Chef infra 非核心资源的chefspec测试,chef-infra,chefspec,Chef Infra,Chefspec,谁能告诉我如何为下面的配方代码编写chefspec测试 {'tomcat_exec_t' => '/apps/.*/bin(/.*)?', 'tomcat_unit_file_t' => '/usr/lib/systemd/system/tomcat@.*.service', 'tomcat_cache_t' => '/apps/.*/temp(/.*)?', 'tomcat_cache_t' => '/apps/.*/work(/.*)?', 'et

谁能告诉我如何为下面的配方代码编写chefspec测试

  {'tomcat_exec_t' => '/apps/.*/bin(/.*)?',
  'tomcat_unit_file_t' => '/usr/lib/systemd/system/tomcat@.*.service',
  'tomcat_cache_t' => '/apps/.*/temp(/.*)?',
  'tomcat_cache_t' => '/apps/.*/work(/.*)?',
  'etc_t' => '/apps/.*/conf(/.*)?',
  'tomcat_log_t' => '/apps/.*/logs(/.*)?',
  'tomcat_var_run_t' => '/apps/.*/logs/tomcat.pid',
  'lib_t' => '/apps/.*/lib(/.*)?',
  'tomcat_var_lib_t' => '/apps/.*/webapps(/.*)?'}.each do |sc, f|
    selinux_policy_fcontext f do
      secontext sc
    end
  end
我已经尝试了以下几种方法,但我想这是失败的,因为执行是由selinux_策略食谱执行的

expect(chef_run).to run_execute('selinux-fcontext-tomcat_exec_t-addormodify')
  end
由于未定义任何方法,因此此操作失败:

expect(chef_run).to create_selinux-fcontext('selinux-fcontext-tomcat_exec_t-addormodify').with(
      fspec: '/apps/.*/bin(/.*)?',
      secontext: 'fcontext'
    )
所以我不确定还能做些什么

任何帮助都将不胜感激

谢谢


Edward

您可能需要编写自己的
匹配程序,具体取决于selinux烹饪书是否为您提供了这些程序。签入libraries目录

无论哪种情况,你都会想要

expect(chef_run).to create_selinux_policy_fcontext('selinux-fcontext-tomcat_exec_t-addormodify').with(
  fspec: '/apps/.*/bin(/.*)?',
  secontext: 'fcontext'
end

我假设默认操作是
create
,否则您将用适当的操作替换
create
,您可能需要编写自己的
匹配器,具体取决于selinux cookbook是否为您提供了这些匹配器。签入libraries目录

无论哪种情况,你都会想要

expect(chef_run).to create_selinux_policy_fcontext('selinux-fcontext-tomcat_exec_t-addormodify').with(
  fspec: '/apps/.*/bin(/.*)?',
  secontext: 'fcontext'
end

我假设默认操作是
create
,否则您将用适当的操作替换
create

谢谢Tejay,我刚刚意识到:)谢谢Tejay,我刚刚意识到:)