def test_culling_operations(self): b = BridgeCommand() self.assertTrue(b.action_cull(b.ioc.getConfig().NodeIdentity)) self.assertTrue( b.ioc.getCollection('JobServer').find({ '_id': ObjectId(b.ioc.getConfig().NodeIdentity), 'active': False }).count()) self.assertTrue(b.action_activate(b.ioc.getConfig().NodeIdentity)) self.assertTrue( b.ioc.getCollection('JobServer').find({ '_id': ObjectId(b.ioc.getConfig().NodeIdentity), 'active': True }).count())
def test_assignment_operations(self): b = BridgeCommand() self.assertTrue(b.action_assign(prototype='scan')) self.assertTrue(b.action_assign(role='stage')) self.assertTrue(b.action_assign(prototype='detect', role='dev')) self.assertTrue( b.ioc.getCollection('JobServer').find({ '_id': ObjectId(b.ioc.getConfig().NodeIdentity), 'prototypes': 'scan' }).count()) self.assertTrue(b.action_unassign(prototype='scan')) self.assertTrue(b.action_unassign(role='stage')) self.assertTrue(b.action_unassign(prototype='detect', role='dev'))
def test_node_validation_failed(self): b = BridgeCommand() valid, server = b.valid_server('45u32890JKLdsfikojnf') self.assertFalse(valid)
def test_node_validation(self): b = BridgeCommand() valid, server = b.valid_server() self.assertTrue(valid) valid, server = b.valid_server(b.ioc.getConfig().NodeIdentity) self.assertTrue(valid)
def test_registration(self): b = BridgeCommand() self.assertTrue(b.action_register())
def test_info_wih_bad_oid(self): b = BridgeCommand() self.assertFalse( b.action_info(node='32j45koHJO34523o', jobs=True, prototypeJobs=True))
def test_info_with_oid(self): b = BridgeCommand() self.assertTrue( b.action_info(node=b.ioc.getConfig().NodeIdentity, jobs=True, prototypeJobs=True))
def test_info(self): b = BridgeCommand() self.assertTrue(b.action_info(jobs=True, prototypeJobs=True))
def __init__(self): super(Bridge, self).__init__() self.bridge = BridgeCommand(self.ioc)
class Bridge(Command): """CLI tool for cluster administration The command palate is listed here:: Args: register register this node with a GREASE Cluster as provided in the configuration file info --node:<ObjectID> !Optional! parameter to observe a remote node. Defaults to look at self --jobs !Optional! if set will list jobs executed --pJobs !Optional! include Prototype Jobs in list of jobs assign --prototype:<string> !mandatory if assigning a prototype! prototype to assign !NOTE! THIS MUST BE SEPARATED BY COLON OR EQUAL SIGN --role:<string> !mandatory if assigning a role! role to assign !NOTE! THIS MUST BE SEPARATED BY COLON OR EQUAL SIGN --node:<ObjectID> !Optional! remote node to assign job to unassign --prototype:<string> !mandatory if unassigning a prototype! prototype to unassign !NOTE! THIS MUST BE SEPARATED BY COLON OR EQUAL SIGN --role:<string> !mandatory if unassigning a role! role to unassign !NOTE! THIS MUST BE SEPARATED BY COLON OR EQUAL SIGN --node:<ObjectID> !Optional! remote node to unassign job to cull --node:<ObjectID> !Optional! parameter to cull a remote node. Defaults to look at self activate --node:<ObjectID> !Optional! parameter to activate a remote node. Defaults to look at self --foreground If set will print log messages to the commandline Note: This tool is ever evolving! If you need something more feel free to create an issue! Attributes: bridge (BridgeCommand): Model Instance """ __author__ = "James E. Bell Jr." __version__ = "2.0.0" purpose = "Control node/cluster operations" help = """ CLI for administrators to manage GREASE Clusters Args: register register this node with a GREASE Cluster as provided in the configuration file info --node:<ObjectID> !Optional! parameter to observe a remote node. Defaults to look at self --jobs !Optional! if set will list jobs executed --pJobs !Optional! include Prototype Jobs in list of jobs assign --prototype:<string> !mandatory if assigning a prototype! prototype to assign !NOTE! THIS MUST BE SEPARATED BY COLON OR EQUAL SIGN --role:<string> !mandatory if assigning a role! role to assign !NOTE! THIS MUST BE SEPARATED BY COLON OR EQUAL SIGN --node:<ObjectID> !Optional! remote node to assign job to unassign --prototype:<string> !mandatory if unassigning a prototype! prototype to unassign !NOTE! THIS MUST BE SEPARATED BY COLON OR EQUAL SIGN --role:<string> !mandatory if unassigning a role! role to unassign !NOTE! THIS MUST BE SEPARATED BY COLON OR EQUAL SIGN --node:<ObjectID> !Optional! remote node to unassign job to cull --node:<ObjectID> !Optional! parameter to cull a remote node. Defaults to look at self activate --node:<ObjectID> !Optional! parameter to activate a remote node. Defaults to look at self --foreground If set will print log messages to the commandline """ def __init__(self): super(Bridge, self).__init__() self.bridge = BridgeCommand(self.ioc) def execute(self, context): """This method monitors the environment An [in]finite loop monitoring the cluster nodes for unhealthy ones Args: context (dict): context for the command to use Returns: bool: Command Success """ retVal = False if context.get('foreground'): self.ioc.getLogger().foreground = True if 'register' in context.get('grease_other_args', []): retVal = self.bridge.action_register() elif 'info' in context.get('grease_other_args', []): retVal = self.bridge.action_info(context.get('node'), context.get('jobs'), context.get('pJobs')) elif 'assign' in context.get('grease_other_args', []): retVal = self.bridge.action_assign(context.get('prototype'), context.get('role'), context.get('node')) elif 'unassign' in context.get('grease_other_args', []): retVal = self.bridge.action_unassign(context.get('prototype'), context.get('role'), context.get('node')) elif 'cull' in context.get('grease_other_args', []): retVal = self.bridge.action_cull(context.get('node')) elif 'activate' in context.get('grease_other_args', []): retVal = self.bridge.action_activate(context.get('node')) else: print("Sub-command Not Found! Here is the help information:") print(self.help) retVal = False if context.get('foreground'): self.ioc.getLogger().foreground = False return retVal