Skip to content
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

Support paramatized yum::versionlock #169

Merged
merged 1 commit into from
May 18, 2020

Conversation

traylenator
Copy link

@traylenator traylenator commented May 6, 2020

Pull Request (PR) description

Support paramatized yum::versionlock

Motivated by the change of format to the versionlock file with DNF systems
change yum::versionlock so it supports parameters version,
release, epoch and arch. If version is specified the namevar is now the package name.

So on a DNF based systemd (e.g CentOS 8) the following must be used.

yum::versionlock{'bash':
  version => '3.4',
}

results in a version lock of on a dnf based system

bash-0:3.4-*

and on a yum based system of

0:bash-3.4-*

A fuller example with all parameters set.

yum::versionlock{'bash':
  version  => '5.4',
  release  => 'alpha-rc3',
  epoch    => 8,
  arch     => 'noarch'
}

results in a version lock on a DNF based system of

bash-8:5.4-alpha-rc3.noarch

The same mechanism on YUM based systems (e.g CentOS 7) can be used.
To specify this new machanism at least a version should be set.

yum::versionlock{'bash':
  version  => '5.4',
  release  => 'alpha-rc3',
  epoch    => 8,
  arch     => 'noarch'
  future   => true,
}

would results in

8:bash-5.4-alpha-rc3.noarch

as used by yum. If version is left default undef then the old mechanism is used so this
is backwards compatable. e.g

yum::versionlock{"0:bash-3.4-7.el8.x86_64"}

is still valid

This Pull Request (PR) fixes the following issues

Fixes #150

@traylenator traylenator added needs-tests needs-work not ready to merge just yet labels May 6, 2020
@traylenator
Copy link
Author

traylenator commented May 6, 2020

Currently if

yum::versionlock{'0:bash-4.1.2-9.el6_2.x86_64':}

is used this compiles on CentOS 8 but is almost certainly not what was wanted.
Can we make the assumption that package names never contain : . It does seem to be case
for Fedora.

In principle could ditch the future parameter in this case and make the choice of mode
automatic on 7.

@traylenator traylenator force-pushed the parameter branch 3 times, most recently from 6278d20 to 882f2e8 Compare May 6, 2020 23:13
@traylenator traylenator changed the title WIP: Support paramatized yum::versionlock Support paramatized yum::versionlock May 6, 2020
@traylenator
Copy link
Author

I tried to enable CentOS 8 accept tests but the framework hangs early.

@traylenator traylenator added bug Something isn't working enhancement New feature or request and removed needs-tests needs-work not ready to merge just yet labels May 6, 2020
@vchepkov
Copy link

vchepkov commented May 7, 2020

IMHO, future attribute is unnecessary. resource should make decision what format to use based on package provider. 'dnf' provider should use new format

manifests/versionlock.pp Outdated Show resolved Hide resolved
@traylenator
Copy link
Author

traylenator commented May 7, 2020

IMHO, future attribute is unnecessary. resource should make decision what format to use based on package provider. 'dnf' provider should use new format

It is in the sense you can ignore it.

On 8 you get the new behaviour.
On 7 you get the old behaviour.

You can choose to get the new behaviour on 7 as well with future => true

$package_provider is is totally used to decide a yum or dnf style format.

README.md Outdated Show resolved Hide resolved
REFERENCE.md Outdated Show resolved Hide resolved
@vchepkov
Copy link

vchepkov commented May 7, 2020

Not sure why you would ever set 'future' on EL7, since it will render configuration invalid.

Ah, I think I got what you are trying to do. IMHO, instead of adding 'future' attribute, why not deduct it from the fact that any of the new attributes are set instead of undef?

README.md Outdated Show resolved Hide resolved
@traylenator
Copy link
Author

traylenator commented May 11, 2020

Sorry for delay - long weekend here.

Ah, I think I got what you are trying to do. IMHO, instead of adding 'future' attribute, why not deduct it from the fact that any of the new attributes are set instead of undef?

My first iteration of this I set arch, release version to undef as default and then used one of them being set to infer we were in modern mode. I changed as I prefer the * defaults as its more useful in the future - a better final interface.

Can I draw your attention to the : in package name comment above as I think that is the best way to drop the need or desire for the a future parameter on 7.

Ah, I think I got what you are trying to do.

Just to confirm I my motivation was to avoid maintaining

if versioncmp($facts['os']['release']['version'],'7') <= 0 {
   yum::versionlock('0:bash-1.2.3.el6':}
} else {
  yum::versionlock('bash':
    version => '1.2.3',
    release  => 'el6',
 }
}

Instead folk can just do for 6 , 7 and 8

yum::versionlock('bash':
    version => '1.2.3',
    release  => 'el6',
    future    => true,
}

with this patch as it stands people have the choice of doing either above.

@traylenator
Copy link
Author

In principle this patch supports someone installing dnf on CentOS 7 as well which is now available. Can't comment on the rest of the module mind you.

@vchepkov
Copy link

I understand. IMHO, you can set default value for version to undef and use that as indicator of the future format instead.

@vchepkov
Copy link

In principle this patch supports someone installing dnf on CentOS 7 as well which is now available. Can't comment on the rest of the module mind you.

Oh, haven't realized that. It's not in any major repositories. In this case maybe parameter should be Enum['dnf','yum'] $format = 'yum' ?

@traylenator
Copy link
Author

I understand. IMHO, you can set default value for version to undef and use that as indicator of the future format instead.

Seems sensibe. Indeed I can't think of use case where you would set release to something and leave version as * and even if you did want that you could change version to *.

I'll make those changes.

Oh, haven't realized that. It's not in any major repositories. In this case maybe parameter should be Enum['dnf','yum'] $format = 'yum' ?

I think we would have to assume that package_provider fact would be changed to dnf on dnf installed on 7 machine. Certainly assume it until someone actually tries it. Not something I will do until CentOS 6 is dead and out the window.

@vchepkov
Copy link

vchepkov commented May 11, 2020

If this new parameter is just to accommodate EL7 users with dnf installed, then disregard my last comment.

package_provider comes from stdlib module, but it just uses logic from the puppet itself

https://github.com/puppetlabs/puppet/blob/master/lib/puppet/provider/package/dnf.rb#L31-L34

According to it, package_provider will be set to yum on EL7

@vchepkov
Copy link

Another option is to drop the old format and make this incompatible change release.
The old code is bad, since you are allowed to 'lock' multiple versions of the same package without ever noticing.

@vchepkov
Copy link

You should probably remove that future attribute, since you don't use it anymore.
Other than that looks good!

@traylenator traylenator added needs-squash needs-work not ready to merge just yet labels May 11, 2020
@dhoppe dhoppe requested a review from ekohl May 11, 2020 18:46
Copy link
Member

@ekohl ekohl left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The actual code change looks ok. I'd like to see some tests for the type aliases. https://rspec-puppet.com/documentation/type_aliases/ makes this very easy to test. I'm mostly interested because I don't remember if Pattern needs ^ and $ or if it's a full match so the it { is_expected.to allow_value('-a') for RpmVersion would be interesting.

REFERENCE.md Outdated Show resolved Hide resolved
REFERENCE.md Outdated Show resolved Hide resolved
REFERENCE.md Outdated Show resolved Hide resolved
manifests/versionlock.pp Outdated Show resolved Hide resolved
types/rpmarch.pp Outdated Show resolved Hide resolved
types/rpmarch.pp Outdated Show resolved Hide resolved
types/rpmepoch.pp Outdated Show resolved Hide resolved
types/rpmname.pp Outdated Show resolved Hide resolved
@traylenator
Copy link
Author

@ekohl Indeed the regexs on version, release , ... absolutely needed a ^ and $.

@vchepkov
Copy link

vchepkov commented May 12, 2020

  • puppetlabs/stdlib just recently went through replacing all regex with ^ and $ to \A and \z instead
  • epoch can't be '*', in fact you added test in line 8 in yum_rpmepoch_spec.rb that it can't be star, but Variant allows it
  • line with assert_type(Yum::RpmVersion is redundant, this is already done by argument type validation
  • I am not sure where the symbols that are allowed by type Yum::RpmName are coming from.
    the referenced spec file doesn't mention it, but according https://docs.fedoraproject.org/en-US/packaging-guidelines/Naming/ only few symbols are allowed in the name

@ekohl
Copy link
Member

ekohl commented May 12, 2020

puppetlabs/stdlib just recently went through replacing all regex with ^ and $ to \A and \z instead

Just to help me understand: what's the reason for this?

@vchepkov
Copy link

vchepkov commented May 12, 2020

puppetlabs/stdlib just recently went through replacing all regex with ^ and $ to \A and \z instead

Just to help me understand: what's the reason for this?

It was just an observation. I presume it's to avoid allowing a multiline string ?
Here is the commit puppetlabs/puppetlabs-stdlib@b74585b

@traylenator
Copy link
Author

puppetlabs/stdlib just recently went through replacing all regex with ^ and $ to \A and \z instead

updated.

epoch can't be '*', in fact you added test in line 8 in yum_rpmepoch_spec.rb that it can't be star, but Variant allows it
line with assert_type(Yum::RpmVersion is redundant, this is already done by argument type validation

That makes sense to me. RPM's do not support arch of * but versionlock files do
support a * for arch.

I am not sure where the symbols that are allowed by type Yum::RpmName are coming from.
the referenced spec file doesn't mention it, but according https://docs.fedoraproject.org/en-US/packaging-guidelines/Naming/ only few symbols are allowed in the name

I think they were lifted from the previous versionlock type.

Above link is a guideline rather than enforced. If I try and make the RPM with a crazy name.

Name: p.u_p+p%%e{t}ag-ent

I do indeed get an RPM

/home/steve/rpmbuild/SRPMS/p.u_p+p%e{t}ag-ent-5.5.19.5.g340c40ba-1.fc32.src.rpm

:-)

The * does cause an exception so I'll remove the * as an option from name now.

@traylenator
Copy link
Author

line with assert_type(Yum::RpmVersion is redundant, this is already done by argument type validation

agreed.

@traylenator
Copy link
Author

l> line with assert_type(Yum::RpmVersion is redundant, this is already done by argument type validation

agreed.

It is needed afterall. The argument type allows undef for a yum based machine but on a
dnf based machine version must be set.

@vchepkov I believe I have addressed your comments.

@vchepkov
Copy link

It is needed afterall. The argument type allows undef for a yum based machine but on a
dnf based machine version must be set.

IMHO, you don't need it, but it's not important, it's just a matter of preference.
In your case value of undef is unacceptable, the type assertion is not necessary.
also, I wouldn't ascertain $version twice. pseudo code:

  if $version {
   # Variable is defined, must be a new style and pattern validated by type
    case $facts['package_provider'] {
       'yum': { yum pattern }
       'dnf': { dnf pattern }
       default: { fail not supported yet}
    }
  } else {
  # old style, assert name type
 }

@vchepkov
Copy link

That makes sense to me. RPM's do not support arch of * but versionlock files do
support a * for arch.

I was talking about epoch, which can't be '*'

[root@puppet ~]# cat /etc/yum/pluginconf.d/versionlock.list 
puppet-agent-*:6.14.0-1.el8.*
[root@puppet ~]# yum update
Last metadata expiration check: 0:03:32 ago on Tue 12 May 2020 12:49:55 PM UTC.
Versionlock plugin: could not parse pattern: puppet-agent-*:6.14.0-1.el8.*

@traylenator
Copy link
Author

That makes sense to me. RPM's do not support arch of * but versionlock files do
support a * for arch.

I was talking about epoch, which can't be '*'

[root@puppet ~]# cat /etc/yum/pluginconf.d/versionlock.list 
puppet-agent-*:6.14.0-1.el8.*
[root@puppet ~]# yum update
Last metadata expiration check: 0:03:32 ago on Tue 12 May 2020 12:49:55 PM UTC.
Versionlock plugin: could not parse pattern: puppet-agent-*:6.14.0-1.el8.*

@traylenator traylenator reopened this May 12, 2020
@traylenator
Copy link
Author

I was talking about epoch, which can't be '*'

epoch is now just an Integer[0]

@traylenator
Copy link
Author

Have squashed commits , will merge Monday if no more comment.

REFERENCE.md Outdated Show resolved Hide resolved
Motivated by the change of format to the versionlock file with DNF systems
change `yum::versionlock` so it supports parameters `version`,
`release`, `epoch` and `arch`. If version is specified the namevar is now the package name.

So on a DNF based systemd (e.g CentOS 8) the following must be used.

```puppet
yum::versionlock{'bash':
  version => '3.4',
}
```

results in a version lock of on a dnf based system

```
bash-0:3.4-*
```

and on a yum based system of

```
0:bash-3.4-*
```

A fuller example with all parameters set.

```puppet
yum::versionlock{'bash':
  version  => '5.4',
  release  => 'alpha-rc3',
  epoch    => 8,
  arch     => 'noarch'
}
```

results in a version lock on a DNF based system of

```
bash-8:5.4-alpha-rc3.noarch
```

The same mechanism on YUM based systems (e.g CentOS 7) can be used.
To specify this new machanism at least a `version` should be set.

```puppet
yum::versionlock{'bash':
  version  => '5.4',
  release  => 'alpha-rc3',
  epoch    => 8,
  arch     => 'noarch'
  future   => true,
}
```

would results in

```
8:bash-5.4-alpha-rc3.noarch
```

as used by yum. If `version` is left default `undef`  then the old mechanism is used so this
is backwards compatable. e.g

```puppet
yum::versionlock{"0:bash-3.4-7.el8.x86_64"}
```
is still valid

Fixes: 150
spec/defines/versionlock_spec.rb Show resolved Hide resolved
@traylenator traylenator merged commit aa9b065 into voxpupuli:master May 18, 2020
traylenator added a commit to traylenator/puppet-yum that referenced this pull request May 18, 2020
Use the new versionlock specification from voxpupuli#169 on CentOS 8.

Also test the new specification on 7 and 8 also.

Finally test that if samba-devel is filtered at
an impossible version it is no longer available.

This for the yum case probably assumes that samba-devel is not
actually installed.
traylenator added a commit to traylenator/puppet-yum that referenced this pull request May 18, 2020
Correct acceptence tests for DNF (8) system

Use the new versionlock specification from voxpupuli#169 on CentOS 8.

Also test the new specification on 7 and 8 also.

Finally test that if samba-devel is filtered at
an impossible version it is no longer available.

This for the yum case probably assumes that samba-devel is not
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Rhel/Centos 8 versionlock doesn't work
4 participants