def testAddNode(self): """ Test for creating new nodes """ # instantiate CSS with some initial data initData = """\ /\t\\N /css_meta\t\\N /css_meta/version\t{version} """ initData = initData.format(version=css.VERSION) css_inst = _makeCss(initData) params = css.NodeParams('worker', 'worker.domain', 5012, 'ACTIVE') nodeName = 'worker-1' css_inst.addNode(nodeName, params) params = css.NodeParams('worker', 'worker.domain', 5013, 'INACTIVE') nodeName = 'worker-2' css_inst.addNode(nodeName, params) node = css_inst.getNodeParams('worker-1') self.assertEqual(node.state, "ACTIVE") self.assertEqual(node.type, 'worker') self.assertEqual(node.host, 'worker.domain') self.assertEqual(node.port, 5012) node = css_inst.getNodeParams('worker-2') self.assertEqual(node.state, "INACTIVE") self.assertEqual(node.type, 'worker') self.assertEqual(node.host, 'worker.domain') self.assertEqual(node.port, 5013) with self.assertRaises(css.NoSuchNode): css_inst.getNodeParams('worker-3')
def testSetNodeState(self): """ Test for changing node state """ # instantiate CSS with some initial data initData = """\ /\t\\N /css_meta\t\\N /css_meta/version\t{version} """ initData = initData.format(version=css.VERSION) css_inst = _makeCss(initData) params = css.NodeParams('worker', 'worker.domain', 5012, 'ACTIVE') nodeName = 'worker-1' css_inst.addNode(nodeName, params) params = css.NodeParams('worker', 'worker.domain', 5013, 'ACTIVE') nodeName = 'worker-2' css_inst.addNode(nodeName, params) node = css_inst.getNodeParams('worker-1') self.assertEqual(node.state, "ACTIVE") node = css_inst.getNodeParams('worker-2') self.assertEqual(node.state, "ACTIVE") css_inst.setNodeState('worker-1', "INACTIVE") node = css_inst.getNodeParams('worker-1') self.assertEqual(node.state, "INACTIVE") css_inst.setNodeState('worker-1', "ACTIVE") node = css_inst.getNodeParams('worker-1') self.assertEqual(node.state, "ACTIVE") css_inst.setNodeState('worker-1', "INACTIVE") css_inst.setNodeState('worker-2', "INACTIVE") node = css_inst.getNodeParams('worker-1') self.assertEqual(node.state, "INACTIVE") node = css_inst.getNodeParams('worker-2') self.assertEqual(node.state, "INACTIVE")
def _parseCreateNode(self, tokens): """ Subparser - handles all CREATE NODE requests. Throws css.CssError, _ToolError. """ if len(tokens) < 2: raise _IllegalCommandError("Unexpected number of arguments.") requiredKeys = self.requiredOpts['createNode'] # parse command, 'type' and 'state' are optional, rest is required options = {'nodeName': tokens[0], 'type': 'worker', 'state': "ACTIVE"} for key, value in self._parseKVList(tokens[1:], requiredKeys): options[key] = value # check that all required options are there self._checkExist(options, requiredKeys) # call CSS to do the rest, remap options to argument names params = css.NodeParams(options['type'], options['host'], int(options.get('port', 0)), options['state']) self._css.addNode(options['nodeName'], params)