Example #1
0
class TestHostManagerImpl(unittest.TestCase):
    ## init test case
    # @param self The object pointer
    def setUp(self):
        arg = {"host": "localhost", "user": "******", "password": "******"}
        ## remote interface
        self.__interface = RemoteInterfaceImpl(**arg)
        ## host OS manager
        self.__manager = HostManagerImpl(**arg)
    ## check if the bridge exists
    # @param self The object pointer
    # @param network_address The network address of the bridge
    # @return Whether the bridge exists
    def __checkBridgeExist(self, network):
        return self.__interface.sudo("ip addr show | grep br_" + str(network).split("/")[0], True).rc == 0
    ## test HostManager.createBridge(network_address)
    # @param self The object pointer
    def testCreateBridge(self):
        ip = ip_interface(u"192.168.33.10/24")
        b = self.__manager.createBridge(ip.network)
        self.assertTrue(self.__checkBridgeExist(ip.network))
        del b
        self.assertFalse(self.__checkBridgeExist(ip.network))

    ## test HostManager.createBridge(network_address) fail because the bridge already exists
    # @param self The object pointer
    def testFailCreateBridge(self):
        ip = ip_interface(u"192.168.33.10/24")
        self.__interface.sudo("brctl addbr br_" + str(ip.network).split("/")[0])
        with self.assertRaises(RuntimeError):
            b = self.__manager.createBridge(ip.network)
        self.__interface.sudo("ip link set br_" + str(ip.network).split("/")[0] + " down")
        self.__interface.sudo("brctl delbr br_" + str(ip.network).split("/")[0])
Example #2
0
 def setUp(self):
     arg = {"host": "localhost", "user": "******", "password": "******"}
     ## remote interface
     self.__interface = RemoteInterfaceImpl(**arg)
     ## host OS manager
     self.__manager = HostManagerImpl(**arg)