def testStatusAfterOneNodeCreated(cli, validNodeNames): """ Testing `status` and `status node <nodeName>` command after one node is created """ nodeName = validNodeNames[0] cli.enterCmd("new node {}".format(nodeName)) # Let the node start up checkNodeStarted(cli, nodeName) cli.enterCmd("status") startedNodeToken = cli.printedTokens[1] printeds = cli.printeds clientStatus = printeds[2] checkForNamedTokens(startedNodeToken, (nodeName, )) assert clientStatus['msg'] == "Clients: No clients are running. Try " \ "typing " \ "'new client <name>'." cli.enterCmd("status node {}".format(nodeName)) msgs = list(reversed(cli.printeds[:11])) node = cli.nodes[nodeName] assert "Name: {}".format(node.name) in msgs[0]['msg'] assert "Node listener: 0.0.0.0:{}".format(node.nodestack.ha[1]) in \ msgs[1]['msg'] assert "Client listener: 0.0.0.0:{}".format(node.clientstack.ha[1]) \ in msgs[2]['msg'] assert "Status:" in msgs[3]['msg'] assert "Connections:" in msgs[4]['msg'] assert not msgs[4]['newline'] assert msgs[5]['msg'] == '<none>' assert "Replicas: 2" in msgs[6]['msg'] assert "Up time (seconds)" in msgs[8]['msg'] assert "Clients: " in msgs[9]['msg'] assert not msgs[9]['newline']
def testStatusAfterOneNodeCreated(cli, validNodeNames): """ Testing `status` and `status node <nodeName>` command after one node is created """ nodeName = validNodeNames[0] cli.enterCmd("new node {}".format(nodeName)) # Let the node start up checkNodeStarted(cli, nodeName) cli.enterCmd("status") startedNodeToken = cli.printedTokens[1] printeds = cli.printeds clientStatus = printeds[2] checkForNamedTokens(startedNodeToken, (nodeName,)) assert clientStatus['msg'] == "Clients: No clients are running. Try " \ "typing " \ "'new client <name>'." cli.enterCmd("status node {}".format(nodeName)) msgs = list(reversed(cli.printeds[:11])) node = cli.nodes[nodeName] assert "Name: {}".format(node.name) in msgs[0]['msg'] assert "Node listener: 0.0.0.0:{}".format(node.nodestack.ha[1]) in \ msgs[1]['msg'] assert "Client listener: 0.0.0.0:{}".format(node.clientstack.ha[1]) \ in msgs[2]['msg'] assert "Status:" in msgs[3]['msg'] assert "Connections:" in msgs[4]['msg'] assert not msgs[4]['newline'] assert msgs[5]['msg'] == '<none>' assert "Replicas: 2" in msgs[6]['msg'] assert "Up time (seconds)" in msgs[8]['msg'] assert "Clients: " in msgs[9]['msg'] assert not msgs[9]['newline']
def testNodeNames(cli, validNodeNames): """ Test adding nodes with valid and invalid names. Also testing adding nodes with duplicate names """ # Add nodes with valid names for i, nm in enumerate(validNodeNames): cli.enterCmd("new node {}".format(nm)) # Count of cli.nodes should increase by 1 assert len(cli.nodes) == (i + 1) checkNodeStarted(cli, nm) checkPoolReady(cli.looper, cli.nodes.values()) # Create a node with a name of an already created node cli.enterCmd("new node {}".format(nm)) msg = cli.lastPrintArgs['msg'] # Appropriate error msg should be printed assert msg == "Node {} already exists.".format(nm) # Count of cli.nodes should not change assert len(cli.nodes) == 4 randName = randomString(10) cli.enterCmd("new node {}".format(randName)) args = cli.printedTokens[-1] token, msg = args['tokens'][0] # An error token should be printed assert isErrorToken(token) # Appropriate error msg should be printed assert msg == "Invalid node name '{}'. ".format(randName) # Count of cli.nodes should not change assert len(cli.nodes) == len(validNodeNames) # Node name should be in cli.nodes assert randName not in cli.nodes
def addNodes(be, do, cli, validNodeNames): # Add nodes with valid names be(cli) for i, nm in enumerate(validNodeNames): do("new node {}".format(nm)) checkNodeStarted(cli, nm)