def __init__(self, name, command_list=None): self.name = name if not command_list: self.command_list = [] else: self.command_list = [command.factory(c) for c in command_list] assert self.command_list, "empty command_list"
def test_commandStart(): c = command.factory("BEGIN") assert (c) assert (c.name == "BEGIN") #c.on_init("whatever") ret, answer = c.execute("vm", None, "arguments")
def test_commandStart(): c = command.factory("BEGIN") assert(c) assert(c.name == "BEGIN") #c.on_init("whatever") ret, answer = c.execute("vm", None, "arguments")
def test_commandSerialize(): c = command.factory(("BEGIN", False, "nothing")) s = c.serialize() cmd = command.unserialize(s) assert (not cmd.success) logging.debug("cmd: %s %s", cmd, type(cmd)) assert (str(cmd).startswith("BEGIN")) #assert str(type(cmd)) == "<class 'AVCommon.Command_START.Command_START'>", "type: %s" % str(type(cmd)) #assert str(type(cmd)) == "<class 'Command_START.Command_START'>", "type: %s" % str(type(cmd)) command.factory(("BEGIN", None, None)) try: command.factory(("BEGIN", "", None)) assert (False) except: pass
def test_commandSerialize(): c = command.factory( ("BEGIN", False, "nothing") ) s = c.serialize() cmd = command.unserialize(s) assert(not cmd.success) logging.debug("cmd: %s %s", cmd, type(cmd)) assert(str(cmd).startswith("BEGIN")) #assert str(type(cmd)) == "<class 'AVCommon.Command_START.Command_START'>", "type: %s" % str(type(cmd)) #assert str(type(cmd)) == "<class 'Command_START.Command_START'>", "type: %s" % str(type(cmd)) command.factory( ("BEGIN", None, None) ) try: command.factory( ("BEGIN", "", None) ) assert(False) except: pass
def test_commandSerialization(): c = command.factory(["BEGIN", True, ['whatever', 'end']]) s = c.serialize() cmd = command.unserialize(s) logging.debug("unserisalized: %s" % type(cmd.result)) assert (cmd.success) assert (type(cmd.result) == list) assert (cmd.args == None) assert (cmd.result == ['whatever', 'end']) assert (str(cmd).startswith("BEGIN"))
def test_commandSerialization(): c = command.factory( ["BEGIN", True, ['whatever','end']]) s = c.serialize() cmd=command.unserialize(s) logging.debug("unserisalized: %s" % type(cmd.result)) assert(cmd.success) assert(type(cmd.result) == list) assert(cmd.args == None) assert(cmd.result == ['whatever','end']) assert(str(cmd).startswith("BEGIN"))
def test_commandUnserialize(): command.context = "mycontext" s = command.factory("BEGIN") logging.debug("Command: %s" % s) assert isinstance( s, command.Command), "type: %s not %s" % (type(s), command.Command) assert s.name == "BEGIN" assert s.args is None assert s.success is None assert s.side == "server", "side: %s" % s.side assert command.context == "mycontext", "wrong context: %s" % s.context assert s.timestamp s = command.factory(["START_VM", None, ["kis", "mcafee"]]) assert s.name == "START_VM" assert s.args == ["kis", "mcafee"] assert s.success is None assert s.side == "server" assert command.context == "mycontext" s = command.factory({"START_VM": ["kis", "mcafee"]}) assert s.name == "START_VM" assert s.args == ["kis", "mcafee"] assert s.success is None assert s.side == "server" assert command.context == "mycontext" s = command.factory(["START_VM", None, ["kis", "mcafee"]]) assert s.name == "START_VM" assert s.args == ["kis", "mcafee"] assert s.success is None assert s.side == "server" assert command.context == "mycontext" s = command.factory(("START_VM", True, ["kis", "mcafee"])) assert s.name == "START_VM" assert not s.args assert s.result == ["kis", "mcafee"] assert s.success is True assert s.side == "server" assert command.context == "mycontext" s = command.factory("""('START_VM', True, ["kis", "mcafee"])""") assert s.name == "START_VM" assert not s.args assert s.result == ["kis", "mcafee"] assert s.success is True assert s.side == "server" assert command.context == "mycontext" s.success = True q = command.factory(s) assert q.name == "START_VM" assert not q.args assert q.result == ["kis", "mcafee"] assert q.success is True assert q.side == "server" assert command.context == "mycontext" try: s = command.factory() assert False, "should not unserialize this" except: pass try: s = command.factory("A", 1, 2) assert False, "should not unserialize this" except: pass try: s = command.factory("B", True, 2, 3) assert False, "should not unserialize this" except: pass try: s = command.factory({"START_VM": ["kis", "mcafee"], "WHATEVER": []}) assert False, "should not unserialize this" except: pass
def append_command(self, new_command): self.command_list.append(command.factory(new_command))
def insert_command(self, new_command): self.command_list.insert(0, command.factory(new_command))
def add_begin_end(self): if self.command_list[0].name != "BEGIN": self.command_list.insert(0, command.factory("BEGIN")) if self.command_list[-1].name != "END": self.command_list.append(command.factory("END"))
def test_commandUnserialize(): command.context = "mycontext" s = command.factory( "BEGIN" ) logging.debug("Command: %s" % s) assert isinstance(s, command.Command), "type: %s not %s" % (type(s), command.Command) assert s.name == "BEGIN" assert s.args is None assert s.success is None assert s.side == "server", "side: %s" % s.side assert command.context == "mycontext", "wrong context: %s" % s.context assert s.timestamp s = command.factory( ["START_VM", None, ["kis", "mcafee"]] ) assert s.name == "START_VM" assert s.args == ["kis", "mcafee"] assert s.success is None assert s.side == "server" assert command.context == "mycontext" s = command.factory( {"START_VM": ["kis", "mcafee"]} ) assert s.name == "START_VM" assert s.args == ["kis", "mcafee"] assert s.success is None assert s.side == "server" assert command.context == "mycontext" s = command.factory( ["START_VM", None, ["kis", "mcafee"]] ) assert s.name == "START_VM" assert s.args == ["kis", "mcafee"] assert s.success is None assert s.side == "server" assert command.context == "mycontext" s = command.factory( ("START_VM", True, ["kis", "mcafee"]) ) assert s.name == "START_VM" assert not s.args assert s.result == ["kis", "mcafee"] assert s.success is True assert s.side == "server" assert command.context == "mycontext" s = command.factory( """('START_VM', True, ["kis", "mcafee"])""" ) assert s.name == "START_VM" assert not s.args assert s.result == ["kis", "mcafee"] assert s.success is True assert s.side == "server" assert command.context == "mycontext" s.success = True q = command.factory( s ) assert q.name == "START_VM" assert not q.args assert q.result == ["kis", "mcafee"] assert q.success is True assert q.side == "server" assert command.context == "mycontext" try: s = command.factory( ) assert False, "should not unserialize this" except: pass try: s = command.factory( "A", 1, 2 ) assert False, "should not unserialize this" except: pass try: s = command.factory( "B", True, 2 , 3 ) assert False, "should not unserialize this" except: pass try: s = command.factory({"START_VM": ["kis", "mcafee"], "WHATEVER": []}) assert False, "should not unserialize this" except: pass