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

Make bootstrap.py compatible with Puppet 4 #230

Merged
merged 4 commits into from Jan 15, 2018

Conversation

h4xr
Copy link
Contributor

@h4xr h4xr commented Jan 3, 2018

Fixes #229

Signed-off-by: Saurabh Badhwar sbadhwar@redhat.com

Signed-off-by: Saurabh Badhwar <sbadhwar@redhat.com>
bootstrap.py Outdated
@@ -383,7 +383,10 @@ def install_puppet_agent():
call_yum("install", "puppet")
enable_service("puppet")

puppet_conf = open('/etc/puppet/puppet.conf', 'wb')
if os.path.isfile('/etc/puppet/puppet.conf'):
Copy link
Member

Choose a reason for hiding this comment

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

can we turn that around and handle /etc/puppetlabs as the special case? feels slightly "cleaner" to me

bootstrap.py Outdated
@@ -407,7 +410,10 @@ def install_puppet_agent():
print_generic("Running Puppet in noop mode to generate SSL certs")
print_generic("Visit the UI and approve this certificate via Infrastructure->Capsules")
print_generic("if auto-signing is disabled")
exec_failexit("/usr/bin/puppet agent --test --noop --tags no_such_tag --waitforcert 10")
if os.path.isfile('/usr/bin/puppet'):
Copy link
Member

Choose a reason for hiding this comment

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

can we turn that around and test for /opt/puppetlabs/puppet/bin/puppet? and in the else case, run puppet without a path at all, so the shell can find it even in another folder?

The changes add functionality for detecting the installed version
of puppet and configures the puppet accordingly.

Signed-off-by: Saurabh Badhwar <sbadhwar@redhat.com>
bootstrap.py Outdated
return executable_path


def get_puppet_version():
Copy link
Member

@evgeni evgeni Jan 5, 2018

Choose a reason for hiding this comment

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

I think I'd still prefer using the RPMdb like this:

def get_puppet_version():
    ts = rpm.TransactionSet()
    for name in ['puppet', 'puppet-agent']:
        mi = ts.dbMatch('name', name)
        for h in mi:
            puppet_version = int(h['version'].split('.')[0])
            if h['name'] == 'puppet-agent' and puppet_version == 1:
                puppet_version = 4
            return puppet_version

This works fine for Puppet 3, 4 and 5

@sideangleside whatcha think?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@evgeni If I am not getting wrong, we are comparing the puppet-agent packaging version here. I doubt if this will be future proof or not, in case packaging convention changes in future for the newer releases of Puppet.

Copy link
Member

Choose a reason for hiding this comment

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

correct, it's using the packaging version. I would not expect the major version of the packaging to differ from the major version of the agent in the future (well, puppet4 agent is an exemption here :()

Copy link
Member

Choose a reason for hiding this comment

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

I am strongly supportive of checking the RPMs version number as it is consistent with other checks for packages that we do. Additionally, checking via an executable's location is just as prone to packaging changes as anything else, so i'd want to be consistent.

bootstrap.py Outdated
puppet_major_version = get_puppet_version()
if puppet_major_version == 3:
puppet_conf_file = '/etc/puppet/puppet.conf'
elif puppet_major_version == 4:
Copy link
Member

Choose a reason for hiding this comment

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

can we make this puppet_major_version in [4,5]? as Puppet5 uses the same path and that would make it more future proof

Copy link
Member

Choose a reason for hiding this comment

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

👍

@@ -218,6 +218,45 @@ def install_prereqs():
delete_file('/etc/yum.repos.d/katello-client-bootstrap-deps.repo')


def get_puppet_path():
Copy link
Member

Choose a reason for hiding this comment

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

this would be then (if we use the RPMdb)

puppet_major_version = get_puppet_version()
if puppet_major_version == 3:
    return '/usr/bin/puppet'
elif puppet_major_version in [4,5]:
    return '/opt/puppetlabs/puppet/bin/puppet'
else:
    error

Signed-off-by: Saurabh Badhwar <sbadhwar@redhat.com>
@h4xr
Copy link
Contributor Author

h4xr commented Jan 9, 2018

@evgeni Addressed the changes in the commit. Please review :)

@evgeni
Copy link
Member

evgeni commented Jan 9, 2018

code LGTM 👍

I'll give it a few test runs later today and merge afterwards, unless @sideangleside is faster ;)

@evgeni
Copy link
Member

evgeni commented Jan 9, 2018

So I gave it a fair spin, and it seems to work fine. However I spotted a few differences in the puppet.conf compared to the version Foreman deploys by default:

our:

vardir = /var/lib/puppet
logdir = /var/log/puppet
rundir = /var/run/puppet
ssldir = $vardir/ssl

foreman:

vardir = /opt/puppetlabs/puppet/cache
logdir = /var/log/puppetlabs/puppet
rundir = /var/run/puppetlabs
ssldir = /etc/puppetlabs/puppet/ssl

I think we should align this for the Puppet4/5 case.

@evgeni
Copy link
Member

evgeni commented Jan 9, 2018

and with that change, we should also extend https://github.com/h4xr/katello-client-bootstrap/blob/2a9f0662d26b90042141a79cda9d216eb3118079/bootstrap.py#L384 to wipe /opt/puppetlabs/puppet/cache and /etc/puppetlabs/puppet/ssl

bootstrap.py Outdated
rundir = /var/run/puppet
ssldir = /etc/puppetlabs/puppet/ssl
""")
else:
Copy link
Member

Choose a reason for hiding this comment

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

that code is unreached, we already verified that it's version 3, 4 or 5 when looking for the conf path

bootstrap.py Outdated
print_error("Unsupported puppet version")
sys.exit(1)
puppet_conf = open(puppet_conf_file, 'wb')
if puppet_major_version == 3:
Copy link
Member

Choose a reason for hiding this comment

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

I think instead of having another set of if/elif here, I'd put the dirs (or the whole [main] section) into a variable during the conf path detection, and just use the variable in one write().

Copy link
Member

@evgeni evgeni left a comment

Choose a reason for hiding this comment

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

two comments, which would make the code a bit cleaner (IMHO), but neither is really blocking and the code works just fine as it is. ACK from me.

would love to hear a second ACK from @sideangleside before merging, though

Copy link
Member

@evgeni evgeni left a comment

Choose a reason for hiding this comment

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

one functional, and two cosmetic comments, good to go when at least the functional is addressed.

bootstrap.py Outdated
[main]
vardir = /opt/puppetlabs/puppet/cache
logdir = /var/log/puppetlabs/puppet
rundir = /var/run/puppet
Copy link
Member

Choose a reason for hiding this comment

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

this should be /var/run/puppetlabs

bootstrap.py Outdated
puppet_major_version = get_puppet_version()
if puppet_major_version == 3:
puppet_conf_file = '/etc/puppet/puppet.conf'
main_section = """
Copy link
Member

Choose a reason for hiding this comment

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

cosmetic: this makes main_section start with a newline, and thus the generated puppet.conf starts with two newlines. can we change this to main_section = """[main]…?

bootstrap.py Outdated
"""
elif puppet_major_version in [4, 5]:
puppet_conf_file = '/etc/puppetlabs/puppet/puppet.conf'
main_section = """
Copy link
Member

Choose a reason for hiding this comment

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

cosmetic: this makes main_section start with a newline, and thus the generated puppet.conf starts with two newlines. can we change this to main_section = """[main]…?

Signed-off-by: Saurabh Badhwar <sbadhwar@redhat.com>
Copy link
Member

@evgeni evgeni left a comment

Choose a reason for hiding this comment

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

ACK

waiting on @sideangleside

@sideangleside
Copy link
Member

LGTM 👍

@sideangleside
Copy link
Member

Thanks for the PR @h4xr

@sideangleside sideangleside merged commit 2787352 into Katello:master Jan 15, 2018
evgeni added a commit to evgeni/katello-client-bootstrap that referenced this pull request Jan 23, 2018
* make bootstrap.py compatible with Puppet 4 (Katello#230)
* add ansible example playbook (Katello#197)
* remove SAMs CA consumer RPM in remove_obsolete_packages() (Katello#234)
* allow FIPS enabled systems to register successfully with puppet (Katello#236)
* allow configuring timeout for API calls and subscription-manager (Katello#237)
* implement switching proxy / caps without destroying the host in Foreman (Katello#227)
@evgeni evgeni mentioned this pull request Jan 23, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants