def test_delete_without_channel(self): cmdlist = [] cmdexecutor = create_cmdexecutor(cmdlist) obj = Node('myNode') myNetDevice1 = NetDevice('myNetDevice1') myNetDevice2 = NetDevice('myNetDevice2') myApp1 = Application('myApp1', DummyApplicationImpl(), {}, {}) myApp2 = Application('myApp2', DummyApplicationImpl(), {}, {}) obj.install_net_device(myNetDevice1) obj.install_net_device(myNetDevice2) obj.install_application(myApp1) obj.install_application(myApp2) obj.create() obj.set_cmdexecutor(cmdexecutor) myNetDevice1.set_cmdexecutor(cmdexecutor) myNetDevice2.set_cmdexecutor(cmdexecutor) obj.delete() expected_cmdlist = [ 'ip link delete myNode-myNetDevice1.t', 'ip link delete myNode-myNetDevice2.t', 'ip netns delete myNode', ] self.assertEquals(len(expected_cmdlist), len(cmdlist)) for idx in range(len(expected_cmdlist)): self.assertEquals(expected_cmdlist[idx], cmdlist[idx]) self.assertEquals(obj, myApp1._impl._stop_called_node) self.assertEquals(obj, myApp2._impl._stop_called_node) self.assertEquals(False, obj._is_created)
def test_delete_without_channel(self): cmdlist = [] cmdexecutor = create_cmdexecutor(cmdlist) obj = Node('myNode') myNetDevice1 = NetDevice('myNetDevice1') myNetDevice2 = NetDevice('myNetDevice2') myApp1 = Application('myApp1', DummyApplicationImpl(), {}, {}) myApp2 = Application('myApp2', DummyApplicationImpl(), {}, {}) obj.install_net_device(myNetDevice1) obj.install_net_device(myNetDevice2) obj.install_application(myApp1) obj.install_application(myApp2) obj.create() obj.set_cmdexecutor(cmdexecutor) myNetDevice1.set_cmdexecutor(cmdexecutor) myNetDevice2.set_cmdexecutor(cmdexecutor) obj.delete() expected_cmdlist = [ 'ip link delete myNode-myNetDevice1.t', 'ip link delete myNode-myNetDevice2.t', 'ip netns delete myNode', ] self.assertEquals(len(expected_cmdlist), len(cmdlist)) for idx in range(len(expected_cmdlist)): self.assertEquals(expected_cmdlist[idx], cmdlist[idx]) self.assertEquals(obj, myApp1._impl._stop_called_node) self.assertEquals(obj, myApp2._impl._stop_called_node) self.assertEquals(False, obj._is_created)
def test_install_net_device(self): obj = Node('myNode') myNetDevice = NetDevice('myNetDevice') obj.install_net_device(myNetDevice) self.assertEquals(True, obj._net_devices.has_key('myNetDevice')) self.assertEquals(myNetDevice, obj._net_devices['myNetDevice']) self.assertEquals('myNode', myNetDevice._node._name)
def test_install_net_device(self): obj = Node('myNode') myNetDevice = NetDevice('myNetDevice') obj.install_net_device(myNetDevice) self.assertEquals(True, obj._net_devices.has_key('myNetDevice')) self.assertEquals(myNetDevice, obj._net_devices['myNetDevice']) self.assertEquals('myNode', myNetDevice._node._name)
def test_uninstall_net_device(self): obj = Node('myNode') myNetDevice = NetDevice('myNetDevice') obj.install_net_device(myNetDevice) obj.uninstall_net_device(myNetDevice) self.assertEquals(False, obj._net_devices.has_key('myNetDevice')) self.assertEquals(None, myNetDevice._node)
def test_uninstall_net_device(self): obj = Node('myNode') myNetDevice = NetDevice('myNetDevice') obj.install_net_device(myNetDevice) obj.uninstall_net_device(myNetDevice) self.assertEquals(False, obj._net_devices.has_key('myNetDevice')) self.assertEquals(None, myNetDevice._node)
def test_install_net_device_already_installed(self): obj = Node('myNode') myNetDevice1 = NetDevice('myNetDevice') myNetDevice2 = NetDevice('myNetDevice') obj.install_net_device(myNetDevice1) obj.install_net_device(myNetDevice2) self.assertEquals(True, obj._net_devices.has_key('myNetDevice')) self.assertEquals(myNetDevice1, obj._net_devices['myNetDevice']) self.assertEquals('myNode', myNetDevice1._node._name) self.assertEquals(None, myNetDevice2._node)
def test_install_net_device_already_installed(self): obj = Node('myNode') myNetDevice1 = NetDevice('myNetDevice') myNetDevice2 = NetDevice('myNetDevice') obj.install_net_device(myNetDevice1) obj.install_net_device(myNetDevice2) self.assertEquals(True, obj._net_devices.has_key('myNetDevice')) self.assertEquals(myNetDevice1, obj._net_devices['myNetDevice']) self.assertEquals('myNode', myNetDevice1._node._name) self.assertEquals(None, myNetDevice2._node)
def test_create(self): cmdlist = [] cmdexecutor = create_cmdexecutor(cmdlist) obj = Node('myNode') obj.set_cmdexecutor(cmdexecutor) myChannel = Channel('myChannel') myNetDevice1 = NetDevice('myNetDevice1') myNetDevice2 = NetDevice('myNetDevice2') myApp1 = Application('myApp1', DummyApplicationImpl(), {}, {}) myApp2 = Application('myApp2', DummyApplicationImpl(), {}, {}) myNetDevice1.connect_to(myChannel) myNetDevice2.connect_to(myChannel) obj.install_net_device(myNetDevice1) obj.install_net_device(myNetDevice2) obj.install_application(myApp1) obj.install_application(myApp2) myNetDevice1.set_cmdexecutor(cmdexecutor) myNetDevice2.set_cmdexecutor(cmdexecutor) obj.create() expected_cmdlist = [ 'ip netns add myNode', 'ip link add myNetDevice1 type veth peer name myNode-myNetDevice1.t', 'ip link set myNetDevice1 netns myNode', 'brctl addif myChannel myNode-myNetDevice1.t', 'ip link set dev myNode-myNetDevice1.t up', 'ip link add myNetDevice2 type veth peer name myNode-myNetDevice2.t', 'ip link set myNetDevice2 netns myNode', 'brctl addif myChannel myNode-myNetDevice2.t', 'ip link set dev myNode-myNetDevice2.t up', ] self.assertEquals(len(expected_cmdlist), len(cmdlist)) for idx in range(len(expected_cmdlist)): self.assertEquals(expected_cmdlist[idx], cmdlist[idx]) self.assertEquals(obj, myApp1._impl._start_called_node) self.assertEquals(obj, myApp2._impl._start_called_node) self.assertEquals(True, obj._is_created)
def test_create(self): cmdlist = [] cmdexecutor = create_cmdexecutor(cmdlist) obj = Node('myNode') obj.set_cmdexecutor(cmdexecutor) myChannel = Channel('myChannel') myNetDevice1 = NetDevice('myNetDevice1') myNetDevice2 = NetDevice('myNetDevice2') myApp1 = Application('myApp1', DummyApplicationImpl(), {}, {}) myApp2 = Application('myApp2', DummyApplicationImpl(), {}, {}) myNetDevice1.connect_to(myChannel) myNetDevice2.connect_to(myChannel) obj.install_net_device(myNetDevice1) obj.install_net_device(myNetDevice2) obj.install_application(myApp1) obj.install_application(myApp2) myNetDevice1.set_cmdexecutor(cmdexecutor) myNetDevice2.set_cmdexecutor(cmdexecutor) obj.create() expected_cmdlist = [ 'ip netns add myNode', 'ip link add myNetDevice1 type veth peer name myNode-myNetDevice1.t', 'ip link set myNetDevice1 netns myNode', 'brctl addif myChannel myNode-myNetDevice1.t', 'ip link set dev myNode-myNetDevice1.t up', 'ip link add myNetDevice2 type veth peer name myNode-myNetDevice2.t', 'ip link set myNetDevice2 netns myNode', 'brctl addif myChannel myNode-myNetDevice2.t', 'ip link set dev myNode-myNetDevice2.t up', ] self.assertEquals(len(expected_cmdlist), len(cmdlist)) for idx in range(len(expected_cmdlist)): self.assertEquals(expected_cmdlist[idx], cmdlist[idx]) self.assertEquals(obj, myApp1._impl._start_called_node) self.assertEquals(obj, myApp2._impl._start_called_node) self.assertEquals(True, obj._is_created)