2

IA 有一个基于 Beaker 的带有验收测试的 Puppet 模块。该模块工作正常,在本地运行时,所有验收测试都运行良好。但是当我在 Travis 上运行测试时,我在模块执行中遇到了以下错误:

/Stage[main]/Alfred::Services/Service[alfred]: Could not evaluate: undefined method `[]' for nil:NilClass

Alfred 是一个基于 upstart 的系统服务,它是我模块的一部分。我正在使用 Puppet 4.3.2。这是 travis 构建:https ://travis-ci.org/nicopaez/alfred-puppet

任何想法?

4

1 回答 1

1

看代码,有几个问题。

一是您在 Travis 中使用的环境变量没有设置 Puppet 版本。您需要将该代码添加到您的spec_helper_acceptance.rb

hosts.each do |host|
  install_puppet_on(host,
    :puppet => ENV['PUPPET_VERSION'] || '4.3.2',
  )
end

现在它仍在安装 Puppet 3.8(默认最新)

有关在 Travis 中实际导致问题的原因的更多信息,我分叉了您的存储库并进行了构建,其中启用了烧杯的调试和跟踪选项:

result = apply_manifest(pp, :trace => true, :debug => true)

由此,查看 Travis 构建,git clone exec 存在问题:

Debug: Exec[clone-repo](provider=posix): Executing 'git clone https://github.com/fiuba/alfred.git /var/www/alfred'
  Debug: Executing 'git clone https://github.com/fiuba/alfred.git /var/www/alfred'
  Notice: /Stage[main]/Alfred::App/Exec[clone-repo]/returns: fatal: Could not change back to '/root': Permission denied
  Error: git clone https://github.com/fiuba/alfred.git /var/www/alfred returned 128 instead of one of [0]

您可以通过使用该vcsrepo模块来解决此问题,该模块以更幂等的方式执行 git 克隆:

vcsrepo { '/var/www/alfred':
  ensure   => present,
  source   => 'https://github.com/fiuba/alfred.git',
  provider => git,
  user     => 'deployer',
}

还有一些其他修复,我正在对您的模块进行一些修复以修复它们,并且会在您查看和合并后在 Stack Overflow 答案中添加一个摘要,因为有些是使用几种不同方法的重要重构。

于 2016-04-02T19:04:00.063 回答