首页 > 解决方案 > rspec-puppet:找不到所需的类

问题描述

所以我有一个功能齐全的'ldap'类。

现在我想为我的 ldap 目录中的某些用户做一些事情。

我在一个新的“用户”模块中执行此操作,首先创建一个新的defined_type:

define users::admin (
  String $sshkey
) {

  file {"/home/${title}":
    ensure => directory,
    owner => $title,
    group => 'root',
    require => Class['ldap']
  }
  ...
}

然后我在我的“用户”模块的 init.pp 中使用这个定义的类型:

class users {
  users::admin {'ldt':
    sshkey => 'mysshkey',
  }
}

但是,当我尝试对此使用“pdk 测试单元”时,出现以下错误:

failed: rspec: ./spec/classes/users_spec.rb:8: error during compilation:
Could not find resource 'Class[Ldap]' in parameter 'require'
(file: ~/Projects/puppet/modules/users/spec/fixtures/modules/users
/manifests/admin.pp, line: 15) on node <mycomputer>

为了完整起见,这是我的 admin_spec.rb (几乎没有从 pdk 默认更改):

require 'spec_helper'

describe 'users::admin' do
  let(:title) { 'namevar' }
  let(:params) do
    {
      'sshkey' => ''
    }
  end

  on_supported_os.each do |os, os_facts|
    context "on #{os}" do
      let(:facts) { os_facts }

      it { is_expected.to compile }
    end
  end
end

我尝试如下设置我的 .fixtures.yml ,但这没有帮助:

fixtures:
  symlinks:
    ldap: "#{source_dir}"

知道我做错了什么吗?

编辑:将我的 .fictures.yml 更改为:

fixtures:
  symlinks:
    ldap: "#{source_dir}/../ldap"

哎呀,我什至在 spec/fixtures/modules 文件夹中手动添加了一个符号链接到我的 ldap 模块。还是同样的错误。

标签: puppetrspec-puppet

解决方案


所以事实证明这个错误与 rspec 或任何东西无关。

我只需要在我的实际木偶代码中“包含 ldap”。


推荐阅读