예제 #1
0
    def test_has_networking(self):
        """ Test for the networking availability checker. """
        global MOCK_sercmd_ret

        c = Connection()
        self.assertFalse(c.has_networking())

        MOCK_sercmd_ret = "123.456.789.012"
        self.assertTrue(c.has_networking())
예제 #2
0
    def test_host(self):
        """ Unittest for the host property. """
        c = Connection()

        # first, let the connection figure out the hot IP by itself
        global MOCK_sercmd_ret
        MOCK_sercmd_ret = "534.117.9.15"
        self.assertEquals(c.host, MOCK_sercmd_ret)

        # then, check whether we can set it
        c.host = "www.heise.de"
        self.assertEquals(c.host, "www.heise.de")

        # finally: check the deleter and the getter's exception handling
        del c.host
        MOCK_sercmd_ret = "unparseable IP address"
        self.assertRaises(Exception, lambda: c.host)
        del c.host
예제 #3
0
    def test_cmd(self):
        """ Test for the command dispatcher. """
        global MOCK_sercmd_ret, MOCK_sshcmd_ret, MOCK_sshcmd_raise
        MOCK_sercmd_ret = "Serial command execution"
        MOCK_sshcmd_ret = "SSH command execution"

        c = Connection(network_setup = ("hurz", "bla-if0"))
        MockSerialConn.called = deepcopy(MockSerialConn._MockSerialConn__called)

        # check for ssh command execution
        self.assertEquals(c.cmd("test-command"), (0, MOCK_sshcmd_ret))

        self.assertEquals(len(MockSshConn.called["cmd"]), 1)
        self.assertEquals(MockSshConn.called["cmd"][0], "test-command")
        self.assertEquals(len(MockSerialConn.called["cmd"]), 0)

        # generate an exception for ssh to check for serial execution
        MOCK_sshcmd_raise = Exception()
        self.assertEquals(c.cmd("test-2-command"), (0, MOCK_sercmd_ret))
        self.assertEquals(MockSerialConn.called["cmd"][0], "test-2-command")
        self.assertEquals(len(MockSerialConn.called["cmd"]), 1)