def test_non_persistent_connection(self): mgr = ConnectionManager(persist_connection=False) c1 = mgr.get_connection(self.device) c2 = mgr.get_connection(self.device) self.assertNotEqual(c1.connection_id, c2.connection_id)
def test_persist_connection(self): mgr = ConnectionManager(persist_connection=True) c1 = mgr.get_connection(self.device) c2 = mgr.get_connection(self.device) self.assertEqual(c1, c2)
def test_device_unavailable(self): info = DeviceInfo(wwn="unavailable", addresses=["192.168.0.254"]) mgr = ConnectionManager(connect_timeout=0.01) mgr.device_map["unavailable"] = info with self.assertRaises(exceptions.DeviceNotAvailable): mgr.get_connection("unavailable")
def test_wrong_device(self): info = DeviceInfo(wwn="wrong", addresses=["127.0.0.1"]) mgr = ConnectionManager() mgr.device_map["wrong"] = info with self.assertRaises(exceptions.WrongDeviceConnection): mgr.get_connection("wrong")
def test_not_found(self): mgr = ConnectionManager() with self.assertRaises(exceptions.DeviceNotFound): mgr.get_connection("not_found")
def test_valid_connection(self): mgr = ConnectionManager() c = mgr.get_connection(self.device) c.put('hello', 'world')