Пример #1
0
    def test_stop(self):

        pred = ZookeeperGoodUntilTime("test", {},
                                      None,
                                      "/path",
                                      None,
                                      interval=self.interval)
        self.mox.StubOutWithMock(pred, "_watch_node")
        pred._watch_node()

        self.mox.ReplayAll()

        pred.start()
        pred.stop()
        pred.stop()
        pred.stop()

        self.mox.VerifyAll()
Пример #2
0
    def test_stop(self):

        pred = ZookeeperGoodUntilTime("test", {}, None, "/path", None,
                                      interval=self.interval)
        self.mox.StubOutWithMock(pred, "_watch_node")
        pred._watch_node()

        self.mox.ReplayAll() 

        pred.start()
        pred.stop()
        pred.stop()
        pred.stop()

        self.mox.VerifyAll() 
Пример #3
0
    def test_start(self):

        pred = ZookeeperGoodUntilTime("test", {},
                                      None,
                                      "/path",
                                      None,
                                      interval=self.interval)
        self.mox.StubOutWithMock(pred, "_watch_node")
        pred._watch_node()

        self.mox.ReplayAll()

        print "This test should complete quickly"
        pred.start()
        pred.start()  # should noop
        pred.start()  # should noop
        pred.stop()

        self.mox.VerifyAll()
Пример #4
0
    def test_start(self):

        pred = ZookeeperGoodUntilTime("test", {}, None, "/path", None,
                                      interval=self.interval)
        self.mox.StubOutWithMock(pred, "_watch_node")
        pred._watch_node()

        self.mox.ReplayAll() 

        print "This test should complete quickly"
        pred.start()
        pred.start()  # should noop
        pred.start()  # should noop
        pred.stop()

        self.mox.VerifyAll() 
Пример #5
0
    def create(self, xmlpart, callback=None, parent=None):
        """
        :type xmlpart: xml.etree.ElementTree.Element
        :type callback: types.FunctionType or None
        :type parent: str or None
        """
        if xmlpart is None:
            # A dummy predicate will be returned if there are no predicates
            # met is true b/c we don't want to block on no predicates
            return create_dummy(comp=self._component_name,
                                parent=self._action,
                                met=True)

        if isinstance(xmlpart, str):
            root = ElementTree.fromstring(xmlpart)
        else:
            root = xmlpart

        if parent is None:
            parent = self._action

        ptype = verify_attribute(root, 'type').lower()
        operational = bool(
            verify_attribute(root, 'operational', none_allowed=True))

        if ptype == 'simple':
            return self._ensure_new(SimplePredicate(self._component_name,
                                                    operational=operational,
                                                    parent=parent),
                                    callback=callback)
        elif ptype == PredicateType.ZOOKEEPERNODEEXISTS:
            return self._ensure_new(ZookeeperNodeExists(
                self._component_name,
                self.zkclient,
                verify_attribute(root, 'path'),
                operational=operational,
                parent=parent),
                                    callback=callback)
        elif ptype == PredicateType.ZOOKEEPERHASCHILDREN:
            return self._ensure_new(ZookeeperHasChildren(
                self._component_name,
                self.zkclient,
                verify_attribute(root, 'path'),
                ephemeral_only=verify_attribute(root,
                                                'ephemeral_only',
                                                none_allowed=True,
                                                default=True),
                operational=operational,
                parent=parent),
                                    callback=callback)
        elif ptype == PredicateType.ZOOKEEPERHASGRANDCHILDREN:
            return self._ensure_new(ZookeeperHasGrandChildren(
                self._component_name,
                self.zkclient,
                verify_attribute(root, 'path'),
                ephemeral_only=verify_attribute(root,
                                                'ephemeral_only',
                                                none_allowed=True,
                                                default=True),
                operational=operational,
                parent=parent),
                                    callback=callback)
        elif ptype == PredicateType.ZOOKEEPERGLOB:
            return self._ensure_new(ZookeeperGlob(
                self._component_name,
                self.zkclient,
                verify_attribute(root, 'path'),
                ephemeral_only=verify_attribute(root,
                                                'ephemeral_only',
                                                none_allowed=True,
                                                default=True),
                operational=operational,
                parent=parent),
                                    callback=callback)
        elif ptype == PredicateType.ZOOKEEPERGOODUNTILTIME:
            return self._ensure_new(ZookeeperGoodUntilTime(
                self._component_name,
                self.zkclient,
                verify_attribute(root, 'path'),
                operational=operational,
                parent=parent),
                                    callback=callback)
        elif ptype == PredicateType.PROCESS:
            return self._ensure_new(PredicateProcess(self._component_name,
                                                     self._proc_client,
                                                     verify_attribute(
                                                         root,
                                                         'interval',
                                                         cast=float),
                                                     operational=operational,
                                                     parent=parent),
                                    callback=callback)
        elif ptype == PredicateType.API:
            return self._ensure_new(APIPredicate(
                self._component_name,
                verify_attribute(root, 'url'),
                verb=verify_attribute(root,
                                      'verb',
                                      none_allowed=True,
                                      default='GET'),
                expected_code=verify_attribute(root,
                                               'expected_code',
                                               none_allowed=True,
                                               cast=int,
                                               default=200),
                interval=verify_attribute(root, 'interval', cast=float),
                operational=operational,
                parent=parent),
                                    callback=callback)
        elif ptype == PredicateType.HEALTH:
            return self._ensure_new(PredicateHealth(
                self._component_name,
                verify_attribute(root, 'command'),
                verify_attribute(root, 'interval', cast=float),
                self._system,
                operational=operational,
                parent=parent),
                                    callback=callback)
        elif ptype == PredicateType.HOLIDAY:
            return self._ensure_new(PredicateHoliday(self._component_name,
                                                     self.zkclient,
                                                     path=self._holiday_path,
                                                     operational=operational,
                                                     parent=parent),
                                    callback=callback)
        elif ptype == PredicateType.WEEKEND:
            return self._ensure_new(PredicateWeekend(self._component_name,
                                                     operational=operational,
                                                     parent=parent),
                                    callback=callback)
        elif ptype == PredicateType.TIMEWINDOW:
            return self._ensure_new(TimeWindow(
                self._component_name,
                begin=verify_attribute(root, 'begin', none_allowed=True),
                end=verify_attribute(root, 'end', none_allowed=True),
                weekdays=verify_attribute(root, 'weekdays', none_allowed=True),
                operational=operational,
                parent=parent),
                                    callback=callback)

        # below, use recursion to get nested predicates
        elif ptype == PredicateType.NOT:
            for element in root.findall('Predicate'):
                dep = self.create(element, callback=callback)
                return self._ensure_new(
                    PredicateNot(self._component_name,
                                 dep,
                                 parent=self._parent_name(parent, 'not')))
        elif ptype == PredicateType.AND:
            deps = list()
            for element in root.findall('Predicate'):
                deps.append(
                    self.create(element,
                                callback=callback,
                                parent=self._parent_name(parent, 'and')))
            return self._ensure_new(
                PredicateAnd(self._component_name, deps, parent=parent))
        elif ptype == PredicateType.OR:
            deps = list()
            for element in root.findall('Predicate'):
                deps.append(
                    self.create(element,
                                callback=callback,
                                parent=self._parent_name(parent, 'or')))
            return self._ensure_new(
                PredicateOr(self._component_name, deps, parent=parent))
        else:
            self._log.error(
                'Unknown predicate type "{0}". Ignoring'.format(ptype))
            # create dummy if it is an unknown predicate type.
            # met is set to true b/c we don't want to block on error
            return create_dummy(comp=self._component_name,
                                parent=self._action,
                                met=True)