Example #1
0
 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"
Example #2
0
def test_commandStart():
    c = command.factory("BEGIN")
    assert (c)
    assert (c.name == "BEGIN")

    #c.on_init("whatever")
    ret, answer = c.execute("vm", None, "arguments")
Example #3
0
 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"
Example #4
0
def test_commandStart():
    c = command.factory("BEGIN")
    assert(c)
    assert(c.name == "BEGIN")

    #c.on_init("whatever")
    ret, answer = c.execute("vm", None, "arguments")
Example #5
0
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
Example #6
0
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
Example #7
0
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"))
Example #8
0
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"))
Example #9
0
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
Example #10
0
 def append_command(self, new_command):
     self.command_list.append(command.factory(new_command))
Example #11
0
 def insert_command(self, new_command):
     self.command_list.insert(0, command.factory(new_command))
Example #12
0
 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"))
Example #13
0
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
Example #14
0
 def append_command(self, new_command):
     self.command_list.append(command.factory(new_command))
Example #15
0
 def insert_command(self, new_command):
     self.command_list.insert(0, command.factory(new_command))
Example #16
0
 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"))