Created
July 5, 2012 20:25
-
-
Save mnunberg/3056231 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# BEGIN BOILERPLATE | |
from sdk.sdkbasetestcase import SDKBaseTestCase, GetSetWorkload | |
from sdk.sdkbasetestcase import SDKBaseTestCase | |
import basetestcase | |
from cbsdk.dataset import DSSeed, DSInline | |
import cbsdk.driver | |
from cbsdk.constants import StatusCodes as _E | |
import cbsdk.constants as _C | |
# END BOILERPLATE | |
import time | |
class Flapper(SDKBaseTestCase): | |
def setUp(self): | |
super(Flapper, self).setUp() | |
self.cluster.reset() | |
def block_and_failover(self, | |
nblock = 1, | |
grace_period = 30): | |
""" | |
Block a node and fail it over, eventually. | |
@param nblock how many nodes to block | |
@param grace_period - time a node can be 'blocked' before | |
the failover is triggered | |
""" | |
self.cluster.setup(4) | |
driver = self.getDriver() | |
workload = GetSetWorkload(driver, self) | |
self.log.info("Sleeping 10 seconds to get basic flow") | |
time.sleep(10) | |
nodes = self.cluster.getJoinedNodes()[:nblock] | |
for n in nodes: | |
self.log.info("Blocking %s", n) | |
n.fw_block() | |
self.log.info("Sleeping for %s seconds (grace period)", grace_period) | |
time.sleep(grace_period) | |
self.cluster.failoverNodes(nodes, | |
action = self.cluster.FO_EJECT) | |
time.sleep(10) | |
workload.collect() | |
def flap_regularly(self, | |
nflap = 1, | |
interval_ok = 60, | |
interval_bad = 10, | |
cycles = 10): | |
""" | |
Make a node 'flap' back and forth consistently. | |
The node will be up for some time, then down for some time | |
until a given time limit is reached | |
@param nflap Nodes to flap | |
@param interval_ok how long should the node be unblocked for | |
@param interval_bad how long should the node be blocked for | |
@param cycles the amount of iterations for interval_ok + interval_bad | |
""" | |
self.cluster.setup(4) | |
driver = self.getDriver() | |
workload = GetSetWorkload(driver, self) | |
nodes = self.cluster.getJoinedNodes()[:nflap] | |
while cycles: | |
self.log.info("%d cycles remaining..", cycles) | |
for n in nodes: | |
self.log.debug("Blocking %s", n) | |
n.fw_block() | |
self.log.info("Running %d seconds with node(s) down", | |
interval_bad) | |
time.sleep(interval_bad) | |
for n in nodes: | |
self.log.debug("Unblocking %s", n) | |
n.fw_allow() | |
self.log.info("Running %d seconds with node(s) up", | |
interval_ok) | |
time.sleep(interval_ok) | |
cycles -= 1 | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment