class SetForceQueueTest(BaseQueueTest):
    @patch("etcd.Client", new=EtcdFactory)
    def setUp(self):
        alarms_patch.start()
        self._p = TestPlugin()
        self._e = EtcdSynchronizer(self._p, "10.0.0.1", "local", "clearwater", "node")
        self._e.WAIT_FOR_TIMER_POP = 0

    def set_force_helper(self, force):
        success = False

        for x in range(10):
            if self._e.set_force(force) == WriteToEtcdStatus.SUCCESS:
                success = True
                break
            sleep(1)

        if not success:
            print "Failed to successfully run set_force"

    # Test that the FORCE value in the JSON can be correctly toggled
    def test_set_force(self):
        self.set_initial_val("{\"FORCE\": false, \"ERRORED\": [], \"COMPLETED\": [], \"QUEUED\": []}")

        self.set_force_helper(False)
        val = json.loads(self._e._client.read("/clearwater/local/configuration/queue_test").value)
        self.assertFalse(val.get("FORCE"))

        self.set_force_helper(True)
        val = json.loads(self._e._client.read("/clearwater/local/configuration/queue_test").value)
        self.assertTrue(val.get("FORCE"))

        self.set_force_helper(False)
        val = json.loads(self._e._client.read("/clearwater/local/configuration/queue_test").value)
        self.assertFalse(val.get("FORCE"))
Beispiel #2
0
class SetForceQueueTest(BaseQueueTest):
    @patch("etcd.Client", new=EtcdFactory)
    def setUp(self):
        alarms_patch.start()
        self._p = TestPlugin()
        self._e = EtcdSynchronizer(self._p, "10.0.0.1", "local", "clearwater",
                                   "node")
        self._e.WAIT_FOR_TIMER_POP = 0

    def set_force_helper(self, force):
        success = False

        for x in range(10):
            if self._e.set_force(force) == WriteToEtcdStatus.SUCCESS:
                success = True
                break
            sleep(1)

        if not success:
            print "Failed to successfully run set_force"

    # Test that the FORCE value in the JSON can be correctly toggled
    def test_set_force(self):
        self.set_initial_val(
            "{\"FORCE\": false, \"ERRORED\": [], \"COMPLETED\": [], \"QUEUED\": []}"
        )

        self.set_force_helper(False)
        val = json.loads(
            self._e._client.read(
                "/clearwater/local/configuration/queue_test").value)
        self.assertFalse(val.get("FORCE"))

        self.set_force_helper(True)
        val = json.loads(
            self._e._client.read(
                "/clearwater/local/configuration/queue_test").value)
        self.assertTrue(val.get("FORCE"))

        self.set_force_helper(False)
        val = json.loads(
            self._e._client.read(
                "/clearwater/local/configuration/queue_test").value)
        self.assertFalse(val.get("FORCE"))
Beispiel #3
0
    while queue_syncer.remove_from_queue(True) != WriteToEtcdStatus.SUCCESS:
        sleep(2)

    logging.debug("Node successfully removed")
elif operation == "remove_failure":
    logging.debug("Removing %s from front of queue and marking as errored" % (local_ip + "-" + node_type))

    while queue_syncer.remove_from_queue(False) != WriteToEtcdStatus.SUCCESS:
        sleep(2)

    logging.debug("Node successfully removed")
elif operation == "force_true":
    logging.debug("Setting the force value to true")

    while queue_syncer.set_force(True) != WriteToEtcdStatus.SUCCESS:
        sleep(2)

    logging.debug("Force value successfully set")
elif operation == "force_false":
    logging.debug("Setting the force value to false")

    while queue_syncer.set_force(False) != WriteToEtcdStatus.SUCCESS:
        sleep(2)

    logging.debug("Force value successfully set")
else:
    logging.debug("Invalid operation requested")

c = etcd.Client(local_ip, 4000)
key = make_key(site, clearwater_key, queue_key)
    while queue_syncer.remove_from_queue(True) != WriteToEtcdStatus.SUCCESS:
        sleep(2)

    _log.debug("Node successfully removed")
elif operation == "remove_failure":
    _log.debug("Removing %s from front of queue and marking as errored" % (local_ip + "-" + node_type))

    while queue_syncer.remove_from_queue(False) != WriteToEtcdStatus.SUCCESS:
        sleep(2)

    _log.debug("Node successfully removed")
elif operation == "force_true":
    _log.debug("Setting the force value to true")

    while queue_syncer.set_force(True) != WriteToEtcdStatus.SUCCESS:
        sleep(2)

    _log.debug("Force value successfully set")
elif operation == "force_false":
    _log.debug("Setting the force value to false")

    while queue_syncer.set_force(False) != WriteToEtcdStatus.SUCCESS:
        sleep(2)

    _log.debug("Force value successfully set")
else:
    _log.debug("Invalid operation requested")

c = etcd.Client(local_ip, 4000)
key = make_key(site, clearwater_key, queue_key)