Skip to content

Commit

Permalink
Account for sysvinit in SLE11.
Browse files Browse the repository at this point in the history
- Testinfra has bugs that fail for SUSE.
  - Fix the location of rc?.d dirs.
  - Fix service command to run as root via sudo.
- Remove .service from names to handle SysV names.
  - testinfra automagically adds .service to name if necessary
    for systemctl.
- Update check_service to allow None for args. This always passes.
  I.e. if you only want to check if a service is enabled and it
  can be running or stopped.
  • Loading branch information
smarlowucf committed Aug 21, 2018
1 parent ff82464 commit 62e93c9
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 23 deletions.
8 changes: 4 additions & 4 deletions usr/share/lib/ipa/tests/SLES/EC2/test_sles_ec2_services.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@


@pytest.mark.parametrize('name', [
('cloud-init-local.service'),
('cloud-init.service'),
('cloud-config.service'),
('cloud-final.service')
('cloud-init-local'),
('cloud-init'),
('cloud-config'),
('cloud-final')
])
def test_sles_ec2_services(check_service, name):
assert check_service(name)
28 changes: 14 additions & 14 deletions usr/share/lib/ipa/tests/SLES/GCE/test_sles_gce_services.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,25 +2,25 @@


@pytest.mark.parametrize('name', [
'google-accounts-daemon.service',
'google-clock-skew-daemon.service',
'google-network-daemon.service',
'google-shutdown-scripts.service'
'google-accounts-daemon',
'google-clock-skew-daemon',
'google-network-daemon'
])
def test_sles_gce_running_services(check_service, name):
assert check_service(name)


@pytest.mark.parametrize('name', [
'google-instance-setup.service',
'google-startup-scripts.service',
'google-shutdown-scripts.service' # Exits but remains active
'google-instance-setup',
'google-startup-scripts',
'google-shutdown-scripts'
])
def test_sles_gce_one_shot_services(host, name):
service = host.service(name)
assert service.is_enabled
def test_sles_gce_one_shot_services(check_service, host, name):
assert check_service(name, running=None)

output = host.run(
"systemctl show -p Result {0} | sed 's/Result=//g'".format(name)
)
assert output.stdout.strip() == 'success'
if host.exists('systemctl'):
# No clear way to check a service exited successfully using sysvinit
output = host.run(
"systemctl show -p Result {0} | sed 's/Result=//g'".format(name)
)
assert output.stdout.strip() == 'success'
2 changes: 1 addition & 1 deletion usr/share/lib/ipa/tests/SLES/test_sles_guestregister.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
def test_sles_guestregister(check_service):
assert check_service('guestregister.service', running=False)
assert check_service('guestregister', running=False)
2 changes: 1 addition & 1 deletion usr/share/lib/ipa/tests/SLES/test_sles_haveged.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
def test_sles_haveged(check_service):
assert check_service('haveged.service')
assert check_service('haveged')
32 changes: 29 additions & 3 deletions usr/share/lib/ipa/tests/conftest.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import json
import pytest
import shlex

from susepubliccloudinfoclient import infoserverrequests

Expand All @@ -18,10 +19,35 @@ def f():
@pytest.fixture()
def check_service(host):
def f(service_name, running=True, enabled=True):
service = host.service(service_name)
is_running = None
is_enabled = None

if host.exists('systemctl'):
service = host.service(service_name)

if running is not None:
is_running = service.is_running

if enabled is not None:
is_enabled = service.is_enabled
else:
# SystemV Init
if running is not None:
is_running = host.run_expect(
[0, 1, 3],
'sudo /sbin/service {0} status'.format(service_name)
).rc == 0

if enabled is not None:
is_enabled = bool(host.check_output(
'find -L /etc/init.d/rc?.d/ -name S??{0}'.format(
service_name
),
))

return all([
service.is_running == running,
service.is_enabled == enabled
is_running == running,
is_enabled == enabled
])
return f

Expand Down

0 comments on commit 62e93c9

Please sign in to comment.