def test_delete_network_postcommit(self): context = mocked_context() driver = mech_datacom.DatacomDriver() driver.dcclient = etc.base_manager(cfg.MultiConfigParser) driver.dcclient.delete_network = mock.Mock() driver.delete_network_postcommit(context) driver.dcclient.delete_network.assertCalledOnceWith(20)
def test_create_network_precommit(self): driver = mech_datacom.DatacomDriver() driver.dcclient = etc.base_manager(cfg.MultiConfigParser) driver.create_network_precommit(mocked_context()) session = db.get_session() query = session.query(DatacomNetwork) resultset = query.filter(DatacomNetwork.vlan == 20) self.assertEquals(1, resultset.count())
def test_delete_port_postcommit(self): context = mocked_port_context() driver = mech_datacom.DatacomDriver() driver.dcclient = etc.base_manager(cfg.MultiConfigParser) driver.dcclient.setup() driver.delete_port_postcommit(context) driver.dcclient.delete_port = mock.Mock() expected_dict = {'192.160.0.1': [1], '192.160.0.2': [2]} driver.dcclient.delete_port.assertCalledOnceWith(20, expected_dict)
def test_delete_port_precommit(self): context = mocked_port_context() driver = mech_datacom.DatacomDriver() driver.dcclient = etc.base_manager(cfg.MultiConfigParser) driver.dcclient.setup() driver.delete_port_precommit(context) session = db.get_session() query = session.query(DatacomPort) self.assertEquals(0, len(query.all()))
def test_delete_network_precommit(self): context = mocked_context() driver = mech_datacom.DatacomDriver() driver.dcclient = etc.base_manager(cfg.MultiConfigParser) driver.dcclient.setup() session = db.get_session() driver.delete_network_precommit(context) query = session.query(DatacomNetwork) self.assertEquals(0, query.count())
def test_update_port_precommit(self): context = mocked_port_context() driver = mech_datacom.DatacomDriver() driver.dcclient = etc.base_manager(cfg.MultiConfigParser) driver.dcclient.setup() session = db.get_session() driver.update_port_precommit(context) ports = session.query(DatacomPort.interface, DatacomNetwork.vlan).all() self.assertIn((1, 20), ports) self.assertIn((2, 20), ports)
def test_initialize(self): manager_class = dcclient.dcclient.Manager manager_class._create_network_xml = mock.Mock() manager_class._update_port_xml = mock.Mock() manager_class._update = mock.Mock() driver = mech_datacom.DatacomDriver() driver.dcclient = etc.base_manager(cfg.MultiConfigParser) driver.initialize() manager_class._update.assert_called_once() self.assertEquals(2, manager_class._create_network_xml.call_count) manager_class._update_port_xml.assert_called_once() first_call = manager_class._create_network_xml.call_args_list[0][0] self.assertEquals((20, 'test1'), first_call) second_call = manager_class._create_network_xml.call_args_list[1][0] self.assertEquals((24, 'test2'), second_call)