【问题标题】:rspec-puppet: cannot find class that is requiredrspec-puppet:找不到所需的类
【发布时间】:2018-05-25 15:25:37
【问题描述】:

所以我有一个功能齐全的“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 模块。还是一样的错误。

【问题讨论】:

  • 我怀疑 source_dir 正在解析到 ldap 模块的位置。解决这个问题,你应该很高兴。

标签: puppet rspec-puppet


【解决方案1】:

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

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多