File tree Expand file tree Collapse file tree 2 files changed +40
-8
lines changed Expand file tree Collapse file tree 2 files changed +40
-8
lines changed Original file line number Diff line number Diff line change 155155 $_ensure = $ensure
156156 }
157157
158- # Check if searching by explicit version.
159- if $_ensure =~ /^((19|20)[0-9][0-9]-(0[1-9]|1[1-2])-([0-2][1-9]|3[0-1])|[0-9]+\.\w+\+?\w*(\.\w+)*)$/ {
160- $grep_regex = " ^${real_pkgname} [[:space:]]\\ +(\\ ?${_ensure}\\ ()$\\ |$\\ |, \\ |[[:space:]]\\ )"
161- } else {
162- $grep_regex = " ^${real_pkgname} [[:space:]].*$"
158+ # We do not try to mimic a version scheme validation which is already implemented by the package manager.
159+ # If it starts with a number it is probably a version.
160+ # If it wasn't or if there is any error, the package manager will trigger a failure.
161+ $grep_regex = $_ensure ? {
162+ /^(present |absent |latest)$/ => " ^${real_pkgname} [[:space:]].*$" ,
163+ /^[0-9].*$/ => " ^${real_pkgname} [[:space:]]\\ +(\\ ?${_ensure}\\ ()$\\ |$\\ |, \\ |[[:space:]]\\ )" ,
164+ default => fail(' ensure can be a version number or one of: present, absent, latest' )
163165 }
164166
165167 $extras_string = empty($extras ) ? {
193195 }
194196 } else {
195197 case $_ensure {
196- /^((19|20)[0-9][0-9]-(0[1-9]|1[1-2])-([0-2][1-9]|3[0-1])|[0-9]+\.\w+\+?\w*(\.\w+)*)$/: {
197- # Version formats as per http://guide.python-distribute.org/specification.html#standard-versioning-schemes
198- # Explicit version.
198+ /^[0-9].*$/: {
199+ # Specific version
199200 $command = " ${pip_install} ${install_args} ${pip_common_args} ==${_ensure}"
200201 $unless_command = " ${pip_env} list | grep -i -e '${grep_regex} '"
201202 }
Original file line number Diff line number Diff line change @@ -74,6 +74,37 @@ class { 'python':
7474 its ( :stdout ) { is_expected . not_to match %r{agent.* 0\. 1\. 2} }
7575 end
7676
77+ context 'fails to install package with wrong version' do
78+ it 'throws an error' do
79+ pp = <<-PUPPET
80+ class { 'python':
81+ version => '3',
82+ dev => 'present',
83+ }
84+
85+ python::pyvenv { '/opt/test-venv':
86+ ensure => 'present',
87+ systempkgs => false,
88+ mode => '0755',
89+ pip_version => '<= 20.3.4',
90+ }
91+
92+ python::pip { 'agent package':
93+ virtualenv => '/opt/test-venv',
94+ pkgname => 'agent',
95+ ensure => '0.1.33+2020-this_is_something-fun',
96+ }
97+ PUPPET
98+
99+ result = apply_manifest ( pp , expect_failures : true )
100+ expect ( result . stderr ) . to contain ( %r{returned 1 instead of one of} )
101+ end
102+ end
103+
104+ describe command ( '/opt/test-venv/bin/pip show agent' ) do
105+ its ( :exit_status ) { is_expected . to eq 1 }
106+ end
107+
77108 context 'install package via extra_index' do
78109 it 'works with no errors' do
79110 pp = <<-PUPPET
You can’t perform that action at this time.
0 commit comments