def test_reconnect(self): # test with an inexisting connection (not cached) with ConnectionManager(self.uri) as cm: cm._drv = None self.assertIsNotNone(cm.connection) self.assertIsInstance(cm.connection, libvirt.virConnect) # test with an existing connection (already cached) with ConnectionManager(self.uri) as cmo: # call version to force call to connect() version = cmo.version cmo._drv = None with ConnectionManager(self.uri) as cmi: version = cmi.version self.assertIsNotNone(cmi.connection) self.assertIsInstance(cmi.connection, libvirt.virConnect)
def __init__(self, connection): self._wait_timeout = 30 self._connection = ConnectionManager(connection) self._domain = DomainManager(connection) super(LibVirtMachineManager, self).__init__()
def depends_on(cls, *args, **kwargs): # singleton is based on the uri, extracted from the libvirt handler (handler, ) = args[0] if isinstance(handler, basestring): handler = ConnectionManager(handler) if isinstance(handler, ConnectionManager): handler = handler.connection if not isinstance(handler, libvirt.virConnect): what = type(handler) reason = "Invalid type for 'connection' field: {0}".format(what) raise DomainManagerError(reason) try: uri = handler.getURI() except libvirt.libvirtError as e: reason = "unable to get domain uri from connection handle" raise DomainManagerError(reason) return uri
def depends_on(cls, *args, **kwargs): # singleton is based on the uri, extracted from the libvirt handler (handler,) = args[0] if isinstance(handler, basestring): handler = ConnectionManager(handler) if isinstance(handler, ConnectionManager): handler = handler.connection if not isinstance(handler, libvirt.virConnect): what = type(handler) reason = "Invalid type for 'connection' field: {0}".format(what) raise DomainManagerError(reason) try: uri = handler.getURI() except libvirt.libvirtError as e: reason = "unable to get domain uri from connection handle" raise DomainManagerError(reason) return uri
def test_connection(self): with ConnectionManager(self.uri) as cm: self.assertIsNotNone(cm.connection) self.assertIsInstance(cm.connection, libvirt.virConnect)
def test_uri(self): with ConnectionManager(self.uri) as cm: self.assertEqual(cm.uri, self.uri)
def test_create_uri(self): with self.assertRaises(NotImplementedError): with ConnectionManager(self.uri) as cm: cm.create_uri("dummy")
def test_version(self): with ConnectionManager(self.uri) as cm: self.assertIsNotNone(cm.version) self.assertEqual(len(cm.version), 3) self.assertIsInstance(cm.version, tuple)
def test_with(self): with ConnectionManager(self.uri) as cm: pass
def test_constructor(self): cm = ConnectionManager(self.uri) self.assertIsNotNone(cm)
def test_constructor_with_connection_manager(self): with ConnectionManager(self.uri) as cm: dm = DomainManager(cm) self.assertIsNotNone(dm) self.assertIsInstance(dm, DomainManager)