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

Fix ipa-client-automount install/uninstall with new install states #7100

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
14 changes: 12 additions & 2 deletions ipaclient/install/client.py
Expand Up @@ -1274,7 +1274,7 @@ def create_sshd_ipa_config(options):
logger.info('Configured %s', paths.SSHD_IPA_CONFIG)


def configure_automount(options):
def configure_automount(options, statestore):
logger.info('\nConfiguring automount:')

args = [
Expand All @@ -1287,12 +1287,15 @@ def configure_automount(options):
if not options.sssd:
args.append('--no-sssd')

statestore.backup_state('installation', 'automount', True)
try:
result = run(args)
except Exception as e:
logger.error('Automount configuration failed: %s', str(e))
else:
logger.info('%s', result.output_log)
finally:
statestore.delete_state('installation', 'automount')


def configure_nisdomain(options, domain, statestore):
Expand Down Expand Up @@ -3306,7 +3309,11 @@ def _install(options, tdict):
configure_sshd_config(fstore, options)

if options.location:
configure_automount(options)
configure_automount(options, statestore)

# Reload the state as automount install may have modified it
fstore._load()
statestore._load()

if options.configure_firefox:
configure_firefox(options, statestore, cli_domain)
Expand Down Expand Up @@ -3369,12 +3376,15 @@ def uninstall(options):
fstore = sysrestore.FileStore(paths.IPA_CLIENT_SYSRESTORE)
statestore = sysrestore.StateFile(paths.IPA_CLIENT_SYSRESTORE)

statestore.backup_state('installation', 'automount', True)
try:
run([paths.IPA_CLIENT_AUTOMOUNT, "--uninstall", "--debug"])
except CalledProcessError as e:
if e.returncode != CLIENT_NOT_CONFIGURED:
logger.error(
"Unconfigured automount client failed: %s", str(e))
finally:
statestore.delete_state('installation', 'automount')

# Reload the state as automount unconfigure may have modified it
fstore._load()
Expand Down
24 changes: 13 additions & 11 deletions ipaclient/install/ipa_client_automount.py
Expand Up @@ -36,7 +36,7 @@

from optparse import OptionParser # pylint: disable=deprecated-module
from ipapython import ipachangeconf
from ipaclient.install import ipadiscovery
from ipaclient import discovery
from ipaclient.install.client import (
CLIENT_NOT_CONFIGURED,
CLIENT_ALREADY_CONFIGURED,
Expand Down Expand Up @@ -340,14 +340,16 @@ def configure_nfs(fstore, statestore, options):


def configure_automount():
try:
check_client_configuration()
except ScriptError as e:
print(e.msg)
sys.exit(e.rval)
statestore = sysrestore.StateFile(paths.IPA_CLIENT_SYSRESTORE)
if not statestore.get_state('installation', 'automount'):
# not called from ipa-client-install
try:
check_client_configuration()
except ScriptError as e:
print(e.msg)
sys.exit(e.rval)

fstore = sysrestore.FileStore(paths.IPA_CLIENT_SYSRESTORE)
statestore = sysrestore.StateFile(paths.IPA_CLIENT_SYSRESTORE)

options, _args = parse_options()

Expand Down Expand Up @@ -382,12 +384,12 @@ def configure_automount():
sys.exit(CLIENT_ALREADY_CONFIGURED)

autodiscover = False
ds = ipadiscovery.IPADiscovery()
ds = discovery.IPADiscovery()
if not options.server:
print("Searching for IPA server...")
ret = ds.search(ca_cert_path=ca_cert_path)
logger.debug('Executing DNS discovery')
if ret == ipadiscovery.NO_LDAP_SERVER:
if ret == discovery.NO_LDAP_SERVER:
logger.debug('Autodiscovery did not find LDAP server')
s = urlsplit(api.env.xmlrpc_uri)
server = [s.netloc]
Expand All @@ -407,14 +409,14 @@ def configure_automount():
server = options.server
logger.debug("Verifying that %s is an IPA server", server)
ldapret = ds.ipacheckldap(server, api.env.realm, ca_cert_path)
if ldapret[0] == ipadiscovery.NO_ACCESS_TO_LDAP:
if ldapret[0] == discovery.NO_ACCESS_TO_LDAP:
print("Anonymous access to the LDAP server is disabled.")
print("Proceeding without strict verification.")
print(
"Note: This is not an error if anonymous access has been "
"explicitly restricted."
)
elif ldapret[0] == ipadiscovery.NO_TLS_LDAP:
elif ldapret[0] == discovery.NO_TLS_LDAP:
logger.warning("Unencrypted access to LDAP is not supported.")
elif ldapret[0] != 0:
sys.exit('Unable to confirm that %s is an IPA server' % server)
Expand Down
25 changes: 25 additions & 0 deletions ipatests/test_integration/test_installation_client.py
Expand Up @@ -8,12 +8,14 @@

from __future__ import absolute_import

import os
import pytest
import re
import shlex
import textwrap

from ipaplatform.paths import paths
from ipalib.sysrestore import SYSRESTORE_STATEFILE, SYSRESTORE_INDEXFILE
from ipatests.test_integration.base import IntegrationTest
from ipatests.pytest_ipa.integration import tasks
from ipatests.pytest_ipa.integration.firewall import Firewall
Expand Down Expand Up @@ -90,6 +92,29 @@ def test_client_install_with_krb5(self):
assert 'includedir {dir}'.format(
dir=paths.SSSD_PUBCONF_KRB5_INCLUDE_D_DIR
).encode() not in krb5_cfg
tasks.uninstall_client(self.clients[0])

def test_install_with_automount(self):
"""Test that installation with automount is successful"""
tasks.install_client(self.master, self.clients[0],
extra_args=['--automount-location', 'default'])

def test_uninstall_with_automount(self):
"""Test that uninstall with automount is successful and complete"""
tasks.uninstall_client(self.clients[0])
index = os.path.join(
paths.IPA_CLIENT_SYSRESTORE, SYSRESTORE_INDEXFILE
)
state = os.path.join(
paths.IPA_CLIENT_SYSRESTORE, SYSRESTORE_STATEFILE
)
for filepath in (index, state):
try:
self.clients[0].get_file_contents(filepath)
except IOError:
pass
else:
pytest.fail("The client file %s was not removed" % filepath)


class TestClientInstallBind(IntegrationTest):
Expand Down