summaryrefslogtreecommitdiffstats
path: root/src/service-dbus
diff options
context:
space:
mode:
authorTomas Bzatek <tbzatek@redhat.com>2014-01-07 14:56:14 +0100
committerTomas Bzatek <tbzatek@redhat.com>2014-01-07 14:56:14 +0100
commit78b6f0937d74de0fc48d6a7adcf4a7b22dcbdbaa (patch)
tree4701bafa1bbdad33050f9630e63b1e154b076fc3 /src/service-dbus
parentc562ebd9aa436bad774671b7d51fe342b49d7acf (diff)
downloadopenlmi-providers-78b6f0937d74de0fc48d6a7adcf4a7b22dcbdbaa.tar.gz
openlmi-providers-78b6f0937d74de0fc48d6a7adcf4a7b22dcbdbaa.tar.xz
openlmi-providers-78b6f0937d74de0fc48d6a7adcf4a7b22dcbdbaa.zip
service: Port tests to lmishell base
Diffstat (limited to 'src/service-dbus')
-rw-r--r--src/service-dbus/test/testService.py58
1 files changed, 23 insertions, 35 deletions
diff --git a/src/service-dbus/test/testService.py b/src/service-dbus/test/testService.py
index be12b4d..2ac346d 100644
--- a/src/service-dbus/test/testService.py
+++ b/src/service-dbus/test/testService.py
@@ -21,36 +21,24 @@
import unittest
import subprocess
+from lmi.test import lmibase
import lmi.shell as lmishell
import os
import shutil
import time
import pywbem # for CIMError
-HOST = os.environ.get("LMI_CIMOM_URL", "https://localhost")
-USER = os.environ.get("LMI_CIMOM_USERNAME", "root")
-PASSWD = os.environ.get("LMI_CIMOM_PASSWORD", "blank")
-BROKER = os.environ.get("LMI_CIMOM_BROKER", "tog-pegasus")
-
DEV_NULL = open("/dev/null", 'w')
# NOTES
# - systemd/service status returns code 3 for stopped (dead) services on Fedora
-class TestServiceProvider(unittest.TestCase):
+class TestServiceProvider(lmibase.LmiTestCase):
"""
TestCase class testing OpenLMI service functionality.
"""
- def setUp(self):
- """Set up and check connection to remote server."""
- self.conn = lmishell.connect(HOST, USER, PASSWD)
- self.assertTrue(isinstance(self.conn, lmishell.LMIConnection), "Couldn't connect to remote provider")
-
-
- def tearDown(self):
- pass
-
+ CLASS_NAME = "LMI_Service"
def test_list_services(self):
"""
@@ -64,7 +52,7 @@ class TestServiceProvider(unittest.TestCase):
service.Started returns correct value for each service against systemctl
"""
# Get list of services from OpenLMI service provider
- lmi_services_insts = self.conn.root.cimv2.LMI_Service.instances()
+ lmi_services_insts = self.cim_class.instances()
self.assertTrue(lmi_services_insts, "No services returned")
lmi_services = dict((s.Name, s.Started) for (s) in lmi_services_insts)
@@ -116,7 +104,7 @@ class TestServiceProvider(unittest.TestCase):
service_status_ret = subprocess.call("service cups status".split())
self.assertEqual(service_status_ret, 3)
- service = self.conn.root.cimv2.LMI_Service.first_instance({"Name": "cups.service"})
+ service = self.cim_class.first_instance({"Name": "cups.service"})
self.assertFalse(service.Started, "Service is not in stopped state")
@@ -161,7 +149,7 @@ class TestServiceProvider(unittest.TestCase):
service_pid_before = 0
# Try to start up the service by using RestartService()
- service = self.conn.root.cimv2.LMI_Service.first_instance({"Name": "cups.service"})
+ service = self.cim_class.first_instance({"Name": "cups.service"})
service.RestartService()
service.refresh()
self.assertTrue(service.Started, "Service couldn't be started BACK after RestartService() [OpenLMI]")
@@ -192,7 +180,7 @@ class TestServiceProvider(unittest.TestCase):
service_pid_before = subprocess.check_output("pidof cupsd".split())
# Try to restart the service by using RestartService()
- service = self.conn.root.cimv2.LMI_Service.first_instance({"Name": "cups.service"})
+ service = self.cim_class.first_instance({"Name": "cups.service"})
service.RestartService()
self.assertTrue(service.Started, "Service couldn't be started UP after RestartService() [OpenLMI]")
@@ -225,14 +213,14 @@ class TestServiceProvider(unittest.TestCase):
self.assertEqual(service_status, 3)
# Try to get ..!non_exists">" service from OpenLMI
- service = self.conn.root.cimv2.LMI_Service.first_instance({"Name": service_evil_name + ".service"})
+ service = self.cim_class.first_instance({"Name": service_evil_name + ".service"})
self.assertEqual(service, None, "Non None object returned of non-existing service")
def test_restart_service_broker(self):
"""
Test if is possible to restart broker over OpenLMI
"""
- service = self.conn.root.cimv2.LMI_Service.first_instance({"Name": BROKER + ".service"})
+ service = self.cim_class.first_instance({"Name": self.cimom + ".service"})
service.RestartService()
# Wait up to 10 seconds for the CIMOM to start
@@ -240,7 +228,7 @@ class TestServiceProvider(unittest.TestCase):
while timer > 0:
time.sleep(1)
try:
- service = self.conn.root.cimv2.LMI_Service.first_instance({"Name": BROKER + ".service"})
+ service = self.cim_class.first_instance({"Name": self.cimom + ".service"})
if service is not None:
break
except pywbem.CIMError:
@@ -251,7 +239,7 @@ class TestServiceProvider(unittest.TestCase):
self.assertTrue (service.Started)
# now try to cumunicate with broker
- servicecups = self.conn.root.cimv2.LMI_Service.first_instance({"Name": "cups.service"})
+ servicecups = self.cim_class.first_instance({"Name": "cups.service"})
self.assertNotEqual(servicecups, None)
servicecups.RestartService()
servicecups.refresh()
@@ -268,7 +256,7 @@ class TestServiceProvider(unittest.TestCase):
Cases:
the "null" service can't be initialized (returned from LMI_Service)
"""
- service = self.conn.root.cimv2.LMI_Service.first_instance({"Name": "\0"})
+ service = self.cim_class.first_instance({"Name": "\0"})
self.assertEqual(service, None, "Non None object returned of non-existing service")
@@ -286,7 +274,7 @@ class TestServiceProvider(unittest.TestCase):
service_status = subprocess.call("service cups stop".split())
self.assertEqual(service_status, 0, "Service is not stopped or is in unknown state")
- service = self.conn.root.cimv2.LMI_Service.first_instance({"Name": "cups.service"})
+ service = self.cim_class.first_instance({"Name": "cups.service"})
self.assertFalse(service_status, "Service is not in stopped state")
# Check that service can't be started by using TryRestartService()
@@ -314,7 +302,7 @@ class TestServiceProvider(unittest.TestCase):
# Try the TryRestartService and check that pid has changed - service
# war physically restarted
- service = self.conn.root.cimv2.LMI_Service.first_instance({"Name": "cups.service"})
+ service = self.cim_class.first_instance({"Name": "cups.service"})
service.TryRestartService()
self.assertTrue(service.Started, "Try-restarted service NOT running")
@@ -341,7 +329,7 @@ class TestServiceProvider(unittest.TestCase):
service_status = subprocess.call("service cups stop".split())
self.assertEqual(service_status, 0, "Service is not stopped or is in unknown state")
- service = self.conn.root.cimv2.LMI_Service.first_instance({"Name": "cups.service"})
+ service = self.cim_class.first_instance({"Name": "cups.service"})
self.assertFalse(service.Started, "Service is not in stopped state")
# Make sure the service is running and try to get status
@@ -370,10 +358,10 @@ class TestServiceProvider(unittest.TestCase):
self.assertEqual(service_status, 0, "Service is not stopped or is in unknown state")
# Get two instances of the same service and check both statuses are False - not running
- service = self.conn.root.cimv2.LMI_Service.first_instance({"Name": "cups.service"})
+ service = self.cim_class.first_instance({"Name": "cups.service"})
self.assertFalse(service.Started, "Service is not in stopped state")
- service2 = self.conn.root.cimv2.LMI_Service.first_instance({"Name": "cups.service"})
+ service2 = self.cim_class.first_instance({"Name": "cups.service"})
self.assertFalse(service2.Started, "Service is not in stopped state")
# Start up one service instance and check both statuses are True - running
@@ -397,7 +385,7 @@ class TestServiceProvider(unittest.TestCase):
"""
# Start the service, disable it and check if it's disabled
# and service is still running
- service = self.conn.root.cimv2.LMI_Service.first_instance({"Name": "cups.service"})
+ service = self.cim_class.first_instance({"Name": "cups.service"})
service.StartService()
service.refresh()
service.TurnServiceOff()
@@ -429,19 +417,19 @@ class TestServiceProvider(unittest.TestCase):
"Service is not stopped after enabled [systemctl]")
-class TestServiceProviderFailingService(unittest.TestCase):
+class TestServiceProviderFailingService(lmibase.LmiTestCase):
"""
TestCase class testing LMI_Service functionality against constantly failing service.
"""
+ CLASS_NAME = "LMI_Service"
+
def setUp(self):
"""
Set up connection to remote server and load failing.service.
Failing service is copied to systemd and systemctl is reloaded.
"""
- self.conn = lmishell.connect(HOST, USER, PASSWD)
- self.assertTrue(isinstance(self.conn, lmishell.LMIConnection), "Couldn't connect to remote provider")
shutil.copy2(os.path.dirname(os.path.abspath(__file__)) + "/failing.service", "/etc/systemd/system/failing.service")
subprocess.call ("systemctl daemon-reload".split())
@@ -466,7 +454,7 @@ class TestServiceProviderFailingService(unittest.TestCase):
failing service is not running after TryRestartService
"""
# Try to start failing service and check OpenLMI knows it failed
- service = self.conn.root.cimv2.LMI_Service.first_instance({"Name": "failing.service"})
+ service = self.cim_class.first_instance({"Name": "failing.service"})
service.StartService()
self.assertFalse (service.Started)
service_status = subprocess.call("service failing status".split())
@@ -502,7 +490,7 @@ class TestServiceProviderFailingService(unittest.TestCase):
"""
# Get the failing service instance from LMI_Service, unlink
# the service from systemd and reload the daemon
- service = self.conn.root.cimv2.LMI_Service.first_instance({"Name": "failing.service"})
+ service = self.cim_class.first_instance({"Name": "failing.service"})
os.unlink ("/etc/systemd/system/failing.service")
subprocess.call ("systemctl daemon-reload".split())