Skip to content

Commit

Permalink
kdc: Don't return a WARNING if there are no ARGS and cpus == 1
Browse files Browse the repository at this point in the history
If there is only a single CPU at installation time then
KRB5KDC_ARGS is nnot set and it may contain an empty value like:

KRB5KDC_ARSG=

Treat this as a successful execution.

Related: #258

Signed-off-by: Rob Crittenden <rcritten@redhat.com>
  • Loading branch information
rcritten committed Jun 6, 2022
1 parent 89d1736 commit c9feb33
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 6 deletions.
15 changes: 10 additions & 5 deletions src/ipahealthcheck/ipa/kdc.py
Expand Up @@ -40,11 +40,16 @@ def check(self):
args_read = True
sline = sline.split('=', maxsplit=1)[1]
if sline.find("-w") == -1:
yield Result(self, constants.WARNING, key=key,
sysconfig=SYSCONFIG,
msg='No KDC workers defined in '
'{sysconfig}')
return
if cpus == 1:
# -w is not configured when cpus == 1
yield Result(self, constants.SUCCESS, key=key)
return
else:
yield Result(self, constants.WARNING, key=key,
sysconfig=SYSCONFIG,
msg='No KDC workers defined in '
'{sysconfig}')
return

# Making an assumption that this line is not misconfigured
# otherwise the KDC wouldn't start at all.
Expand Down
42 changes: 41 additions & 1 deletion tests/test_ipa_kdc.py
Expand Up @@ -14,7 +14,7 @@
class TestKDCWorkers(BaseTest):
@patch('ipahealthcheck.ipa.kdc.get_contents')
@patch('os.sysconf')
def test_no_workers(self, mock_sysconf, mock_sysconfig):
def test_no_workers_noargs(self, mock_sysconf, mock_sysconfig):
mock_sysconf.return_value = 1
mock_sysconfig.return_value = ""
framework = object()
Expand All @@ -33,6 +33,46 @@ def test_no_workers(self, mock_sysconf, mock_sysconfig):
assert result.kw.get('sysconfig') == '/etc/sysconfig/krb5kdc'
assert result.kw.get('msg') == 'KRB5KDC_ARGS is not set in {sysconfig}'

@patch('ipahealthcheck.ipa.kdc.get_contents')
@patch('os.sysconf')
def test_no_workers_empty_noargs(self, mock_sysconf, mock_sysconfig):
mock_sysconf.return_value = 1
mock_sysconfig.return_value = ("KRB5KDC_ARGS=",)
framework = object()
registry.initialize(framework, config.Config)
f = KDCWorkersCheck(registry)

self.results = capture_results(f)

assert len(self.results) == 1

result = self.results.results[0]
assert result.result == constants.SUCCESS
assert result.source == 'ipahealthcheck.ipa.kdc'
assert result.check == 'KDCWorkersCheck'
assert result.kw.get('key') == 'workers'

@patch('ipahealthcheck.ipa.kdc.get_contents')
@patch('os.sysconf')
def test_with_workers_empty_noargs(self, mock_sysconf, mock_sysconfig):
mock_sysconf.return_value = 2
mock_sysconfig.return_value = ("KRB5KDC_ARGS=",)
framework = object()
registry.initialize(framework, config.Config)
f = KDCWorkersCheck(registry)

self.results = capture_results(f)

assert len(self.results) == 1

result = self.results.results[0]
assert result.result == constants.WARNING
assert result.source == 'ipahealthcheck.ipa.kdc'
assert result.check == 'KDCWorkersCheck'
assert result.kw.get('key') == 'workers'
assert result.kw.get('sysconfig') == '/etc/sysconfig/krb5kdc'
assert result.kw.get('msg') == 'No KDC workers defined in {sysconfig}'

@patch('ipahealthcheck.ipa.kdc.get_contents')
@patch('os.sysconf')
def test_workers_match_single(self, mock_sysconf, mock_sysconfig):
Expand Down

0 comments on commit c9feb33

Please sign in to comment.