-
Notifications
You must be signed in to change notification settings - Fork 104
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
(PDK-1096, PDK-1097, PDK-1098) Add puppet-dev flag to validate and test unit #559
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,13 @@ | ||
require 'pdk/util' | ||
require 'pdk/util/git' | ||
|
||
module PDK | ||
module Util | ||
class PuppetVersion | ||
class << self | ||
extend Forwardable | ||
|
||
def_delegators :instance, :find_gem_for, :from_pe_version, :from_module_metadata, :latest_available | ||
def_delegators :instance, :puppet_dev_env, :puppet_dev_path, :fetch_puppet_dev, :find_gem_for, :from_pe_version, :from_module_metadata, :latest_available | ||
|
||
attr_writer :instance | ||
|
||
|
@@ -16,6 +17,19 @@ def instance | |
end | ||
|
||
PE_VERSIONS_URL = 'https://forgeapi.puppet.com/private/versions/pe'.freeze | ||
DEFAULT_PUPPET_DEV_URL = 'https://github.com/puppetlabs/puppet'.freeze | ||
DEFAULT_PUPPET_DEV_BRANCH = 'master'.freeze | ||
|
||
def puppet_dev_env | ||
{ | ||
gem_version: 'file://%{path}' % { path: puppet_dev_path }, | ||
ruby_version: PDK::Util::RubyVersion.default_ruby_version, | ||
} | ||
end | ||
|
||
def puppet_dev_path | ||
'%{cache}/src/puppet' % { cache: PDK::Util.cachedir } | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should this use |
||
end | ||
|
||
def latest_available | ||
latest = find_gem(Gem::Requirement.create('>= 0')) | ||
|
@@ -27,6 +41,25 @@ def latest_available | |
latest | ||
end | ||
|
||
def fetch_puppet_dev | ||
unless PDK::Util::Git.remote_repo? puppet_dev_path | ||
FileUtils.mkdir_p puppet_dev_path | ||
clone_result = PDK::Util::Git.git('clone', DEFAULT_PUPPET_DEV_URL, puppet_dev_path) | ||
unless clone_result[:exit_code].zero? | ||
PDK.logger.error clone_result[:stdout] | ||
PDK.logger.error clone_result[:stderr] | ||
raise PDK::CLI::FatalError, _("Unable to clone git repository at '%{repo}'.") % { repo: DEFAULT_PUPPET_DEV_URL } | ||
end | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Might be worth returning early after the clone since the subsequent |
||
end | ||
|
||
fetch_result = PDK::Util::Git.git('fetch', '--quiet', puppet_dev_path) | ||
return if fetch_result[:exit_code].zero? | ||
|
||
PDK.logger.error fetch_result[:stdout] | ||
PDK.logger.error fetch_result[:stderr] | ||
raise PDK::CLI::FatalError, _("Unable to fetch updates for git repository at '%{cachedir}'.") % { repo: puppet_dev_path } | ||
end | ||
|
||
def find_gem_for(version_str) | ||
version = parse_specified_version(version_str) | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -221,4 +221,32 @@ | |
}.to exit_zero | ||
end | ||
end | ||
|
||
context 'with --puppet-dev' do | ||
it 'activates resolved puppet version' do | ||
expect { | ||
PDK::CLI.run(['validate', '--puppet-dev']) | ||
}.to exit_zero | ||
end | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This test isn't actually asserting anything about activating the right puppet version yet, I assume this that part hasn't been implemented in this PR. But maybe it would be better to leave this out or mark it as pending so that we don't accidentally leave it this way later? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah, good point. I was going to address it in the next PR when I do get the puppet-version selection parts tested. |
||
end | ||
|
||
context 'with both --puppet-version and --puppet-dev' do | ||
it 'exits with an error' do | ||
expect(logger).to receive(:error).with(a_string_matching(%r{cannot specify.*--puppet-dev.*and.*--puppet-version}i)) | ||
|
||
expect { | ||
PDK::CLI.run(%w[validate --puppet-version 4.10.10 --puppet-dev]) | ||
}.to exit_nonzero | ||
end | ||
end | ||
|
||
context 'with both --pe-version and --puppet-dev' do | ||
it 'exits with an error' do | ||
expect(logger).to receive(:error).with(a_string_matching(%r{cannot specify.*--puppet-dev.*and.*--pe-version}i)) | ||
|
||
expect { | ||
PDK::CLI.run(%w[validate --pe-version 2018.1 --puppet-dev]) | ||
}.to exit_nonzero | ||
end | ||
end | ||
end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think it's optimal for
puppet_from_opts_or_env
to have the side effect of cloning/fetching the repo every time it's called. Could this be exposed separately and maybe this method can raise if the local repo doesn't exist?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hm. I figured it would be appropriate because
puppet_from_opts_or_env
is called on 3 occasions:pdk validate
,pdk test unit
, andpdk bundle
and the clone or fetch is only performed if--puppet-dev
orPDK_PUPPET_DEV
is true.I can abstract the call that clones/fetch the git repo elsewhere, but it would still be called every time
puppet-dev
is true in order to get the latest from github.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, it currently is a 1-1 correlation with the places you want to call it, but I think it's just unclear that calling that method will have that side effect, so I'd rather see explicit calls in those places.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, that's fair. I can make that change and at this part, I'll just call
.puppet_dev_env
to get the hash.