class PredicateFactoryTest(TestCase): def setUp(self): self.mox = mox.Mox() self.comp_name = "Test Predicate Or" self.predat = SimplePredicate("a", ThreadSafeObject({})) self.predat.set_met(True) self.predbt = SimplePredicate("b", ThreadSafeObject({})) self.predbt.set_met(True) self.predaf = SimplePredicate("a", ThreadSafeObject({})) self.predbf = SimplePredicate("b", ThreadSafeObject({})) self.list = [self.predaf, self.predbf, self.predat, self.predbt] self.factory = PredicateFactory(component_name="factory", zkclient=None, proc_client=None, system=None, pred_list=self.list, settings={}) def tearDown(self): pass def test_match(self): new = SimplePredicate("a", ThreadSafeObject({})) ret = self.factory._ensure_new(new) self.assertTrue(new is not ret) def test_no_match(self): new = SimplePredicate("c", ThreadSafeObject({})) ret = self.factory._ensure_new(new) self.assertTrue(new is ret)
class PredicateFactoryTest(TestCase): def setUp(self): self.mox = mox.Mox() self.comp_name = "Test Predicate Or" self.predat = SimplePredicate("a", ThreadSafeObject({})) self.predat.set_met(True) self.predbt = SimplePredicate("b", ThreadSafeObject({})) self.predbt.set_met(True) self.predaf = SimplePredicate("a", ThreadSafeObject({})) self.predbf = SimplePredicate("b", ThreadSafeObject({})) self.list = [self.predaf, self.predbf, self.predat, self.predbt] self.factory = PredicateFactory(component_name="factory", parent=None, zkclient=None, proc_client=None, system=None, pred_list=self.list, settings={}) def tearDown(self): pass def test_match(self): new = SimplePredicate("a", ThreadSafeObject({})) ret = self.factory._ensure_new(new) self.assertTrue(new is not ret) def test_no_match(self): new = SimplePredicate("c", ThreadSafeObject({})) ret = self.factory._ensure_new(new) self.assertTrue(new is ret)
def __init__(self, name, component_name, action, xmlpart, staggerpath=None, staggertime=None, mode_controlled=False, action_q=None, zkclient=None, proc_client=None, mode=None, system=None, pred_list=None, settings=None, disabled=False, pd_enabled=True, op_action=None, pd_reason=None, app_state=None): """ :param action: The function to run when all the action's predicates are met :param xmlpart: The part of XML pertaining to this Action :param mode_controlled: Whether or not the action will run based on the ApplicationMode :param op_action: The function to run if this action's operation dependencies go down. :type name: str :type component_name: str :type action: types.FunctionType :type xmlpart: xml.etree.ElementTree.Element :type staggerpath: str :type staggertime: int :type mode_controlled: bool :type action_q: zoom.agent.entities.unique_queue.UniqueQueue :type zkclient: kazoo.client.KazooClient :type proc_client: zoom.agent.client.process_client.ProcessClient :type mode: zoom.agent.entities.thread_safe_object.ApplicationMode :type system: zoom.common.types.PlatformType :type pred_list: list :type settings: dict :type disabled: bool :type pd_enabled: bool :type op_action: types.FunctionType or None :type pd_reason: str or None :type app_state: zoom.agent.entities.thread_safe_object.ThreadSafeObject """ self.name = name self.disabled = disabled self.component_name = component_name self._log = logging.getLogger('sent.{0}.act'.format(component_name)) self._action = action self._action_queue = action_q self._mode_controlled = mode_controlled self._mode = mode self._pd_enabled = pd_enabled self._op_action = op_action self._pd_reason = pd_reason self._acquire_lock = ThreadSafeObject(True) if staggerpath is not None and staggertime is not None: self._stag_lock = StaggerLock(staggerpath, staggertime, parent=self.component_name, acquire_lock=self._acquire_lock, app_state=app_state) self._log.info('Using {0}'.format(self._stag_lock)) else: self._stag_lock = None factory = PredicateFactory(component_name=component_name, action=self.name, zkclient=zkclient, proc_client=proc_client, system=system, pred_list=pred_list, settings=settings) self._predicate = factory.create(xmlpart.find('./Dependency/Predicate'), callback=self._callback)
def setUp(self): self.mox = mox.Mox() self.comp_name = "Test Predicate Or" self.predat = SimplePredicate("a", ThreadSafeObject({})) self.predat.set_met(True) self.predbt = SimplePredicate("b", ThreadSafeObject({})) self.predbt.set_met(True) self.predaf = SimplePredicate("a", ThreadSafeObject({})) self.predbf = SimplePredicate("b", ThreadSafeObject({})) self.list = [self.predaf, self.predbf, self.predat, self.predbt] self.factory = PredicateFactory(component_name="factory", zkclient=None, proc_client=None, system=None, pred_list=self.list, settings={})
def __init__(self, name, component_name, action, xmlpart, staggerpath=None, staggertime=None, mode_controlled=False, action_q=None, zkclient=None, proc_client=None, mode=None, system=None, pred_list=None, settings=None, disabled=False, pd_enabled=True, op_action=None, pd_reason=None, app_state=None): """ :param action: The function to run when all the action's predicates are met :param xmlpart: The part of XML pertaining to this Action :param mode_controlled: Whether or not the action will run based on the ApplicationMode :param op_action: The function to run if this action's operation dependencies go down. :type name: str :type component_name: str :type action: types.FunctionType :type xmlpart: xml.etree.ElementTree.Element :type staggerpath: str :type staggertime: int :type mode_controlled: bool :type action_q: zoom.agent.entities.unique_queue.UniqueQueue :type zkclient: kazoo.client.KazooClient :type proc_client: zoom.agent.client.process_client.ProcessClient :type mode: zoom.agent.entities.thread_safe_object.ApplicationMode :type system: zoom.common.types.PlatformType :type pred_list: list :type settings: dict :type disabled: bool :type pd_enabled: bool :type op_action: types.FunctionType or None :type pd_reason: str or None :type app_state: zoom.agent.entities.thread_safe_object.ThreadSafeObject """ self.name = name self.disabled = disabled self.component_name = component_name self._log = logging.getLogger('sent.{0}.act'.format(component_name)) self._action = action self._action_queue = action_q self._mode_controlled = mode_controlled self._mode = mode self._pd_enabled = pd_enabled self._op_action = op_action self._pd_reason = pd_reason self._acquire_lock = ThreadSafeObject(True) if staggerpath is not None and staggertime is not None: self._stag_lock = StaggerLock(staggerpath, staggertime, parent=self.component_name, acquire_lock=self._acquire_lock, app_state=app_state) self._log.info('Using {0}'.format(self._stag_lock)) else: self._stag_lock = None factory = PredicateFactory(component_name=component_name, action=self.name, zkclient=zkclient, proc_client=proc_client, system=system, pred_list=pred_list, settings=settings) self._predicate = factory.create( xmlpart.find('./Dependency/Predicate'), callback=self._callback)