Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def stop_all(self):
"""Stops all active service instances.
Services will be stopped in the reverse order they were registered.
"""
# OrdereDict#items does not return a sequence in Python 3.4, so we have
# to do a list conversion here.
for alias, service in reversed(list(self._service_objects.items())):
if service.is_alive:
with expects.expect_no_raises('Failed to stop service "%s".' %
alias):
service.stop()
def start_all(self):
"""Starts all inactive service instances.
Services will be started in the order they were registered.
"""
for alias, service in self._service_objects.items():
if not service.is_alive:
with expects.expect_no_raises('Failed to start service "%s".' %
alias):
service.start()
def resume_all(self):
"""Resumes all service instances.
Services will be resumed in the order they were registered.
"""
for alias, service in self._service_objects.items():
with expects.expect_no_raises('Failed to resume service "%s".' %
alias):
service.resume()
def get_controller_info_records(self):
"""Get the info records for all the controller objects in the manager.
New info records for each controller object are created for every call
so the latest info is included.
Returns:
List of records.ControllerInfoRecord objects. Each opject conatins
the info of a type of controller
"""
info_records = []
for controller_module_name in self._controller_objects.keys():
with expects.expect_no_raises(
'Failed to collect controller info from %s' %
controller_module_name):
record = self._create_controller_info_record(
controller_module_name)
if record:
info_records.append(record)
return info_records
def pause_all(self):
"""Pauses all service instances.
Services will be paused in the reverse order they were registered.
"""
# OrdereDict#items does not return a sequence in Python 3.4, so we have
# to do a list conversion here.
for alias, service in reversed(list(self._service_objects.items())):
with expects.expect_no_raises('Failed to pause service "%s".' %
alias):
service.pause()
def unregister_controllers(self):
"""Destroy controller objects and clear internal registry.
This will be called after each test class.
"""
# TODO(xpconanfan): actually record these errors instead of just
# logging them.
for name, module in self._controller_modules.items():
logging.debug('Destroying %s.', name)
with expects.expect_no_raises('Exception occurred destroying %s.' %
name):
module.destroy(self._controller_objects[name])
self._controller_objects = collections.OrderedDict()
self._controller_modules = {}
def for_each(self, func):
"""Executes a function with all registered services.
Args:
func: function, the function to execute. This function should take
a service object as args.
"""
aliases = list(self._service_objects.keys())
for alias in aliases:
with expects.expect_no_raises(
'Failed to execute "%s" for service "%s".' %
(func.__name__, alias)):
func(self._service_objects[alias])
def unregister(self, alias):
"""Unregisters a service instance.
Stops a service and removes it from the manager.
Args:
alias: string, the alias of the service instance to unregister.
"""
if alias not in self._service_objects:
raise Error(self._device,
'No service is registered with alias "%s".' % alias)
service_obj = self._service_objects.pop(alias)
if service_obj.is_alive:
with expects.expect_no_raises(
'Failed to stop service instance "%s".' % alias):
service_obj.stop()