def test_stop_twice(self): with ServiceControlManagerContext() as scm: infi_service = scm.open_service("VSS") with infi_service: infi_service.safe_stop() time.sleep(6) with ServiceControlManagerContext() as scm: infi_service = scm.open_service("VSS") with infi_service: infi_service.safe_stop() time.sleep(6)
def _delete(self): with ServiceControlManagerContext() as scm: infi_service = scm.open_service(INFI_SERVICE_NAME) infi_service.delete() infi_service.close() # sleep to let the service db refresh or something; otherwise the open succeeds, somehow, sometimes time.sleep(3) with ServiceControlManagerContext() as scm: with self.assertRaisesRegexp( WindowsError, "The specified service does not exist as an installed service." ): infi_service = scm.open_service(INFI_SERVICE_NAME)
def uninstall(self): '''Stop the iscsi service on windows ''' with ServiceControlManagerContext() as scm: with scm.open_service('MSiSCSI') as service: logger.debug("stopping MSiSCSI") service.safe_stop() service.wait_on_pending() service.disable()
def _start_stop(self): with ServiceControlManagerContext() as scm: infi_service = scm.open_service(INFI_SERVICE_NAME) infi_service.start() time.sleep(3) self.assertTrue(infi_service.is_running()) infi_service.stop() time.sleep(6) self.assertFalse(infi_service.is_running()) infi_service.close()
def _register(self): with ServiceControlManagerContext() as scm: python_exe = os.path.abspath( os.path.join(os.path.dirname(__file__), os.path.pardir, "bin", "python.exe")) scm.create_service( INFI_SERVICE_NAME, u"Infinidat Test Service", ServiceType.WIN32_OWN_PROCESS, ServiceStartType.AUTO, "\"{}\" {}".format(python_exe, __file__.replace('.pyc', '.py'))).close()
def install(self): '''start the iSCSI service on windows. in the future will also autostart the service ''' logger.debug("trying to start service MSiSCSI") with ServiceControlManagerContext() as scm: with scm.open_service('MSiSCSI') as service: logger.debug("starting service MSiSCSI") service.start_automatically() service.safe_start() service.wait_on_pending()
def _stop(self): with ServiceControlManagerContext() as scm: infi_service = scm.open_service(INFI_SERVICE_NAME) with infi_service: infi_service.safe_stop() time.sleep(6)
def is_installed(self): '''in windows return True if iSCSI initiator sw is running otherwise return False ''' with ServiceControlManagerContext() as scm: with scm.open_service('MSiSCSI') as service: return service.is_running() and service.is_autostart()