def prepareForShutdown(self): """ Prepare server for shutdown. Should be called before taking server down. """ if not self._shutdownSemaphore.acquire(blocking=False): self.log.debug('cannot run prepareForShutdown concurrently') return errCode['unavail'] try: if not self._enabled: self.log.debug('cannot run prepareForShutdown twice') return errCode['unavail'] self._acceptor.stop() for binding in self.bindings.values(): binding.stop() self._enabled = False secret.clear() self.channelListener.stop() if self.irs: return self.irs.prepareForShutdown() else: return {'status': doneCode} finally: self._shutdownSemaphore.release()
def prepareForShutdown(self): """ Prepare server for shutdown. Should be called before taking server down. """ if not self._shutdownSemaphore.acquire(blocking=False): self.log.debug('cannot run prepareForShutdown concurrently') return errCode['unavail'] try: if not self._enabled: self.log.debug('cannot run prepareForShutdown twice') return errCode['unavail'] self._wait_for_shutting_down_vms() self._acceptor.stop() for binding in self.servers.values(): binding.stop() self._enabled = False secret.clear() self.channelListener.stop() self.qga_poller.stop() if self.irs: return self.irs.prepareForShutdown() else: return {'status': doneCode} finally: self._shutdownSemaphore.release()
def test_clear(self): self.connection.secrets = { "uuid1": vmfakecon.Secret(self.connection, "uuid1", "ceph", "ovirt/name1", None), "uuid2": vmfakecon.Secret(self.connection, "uuid2", "ceph", "name2", None), } secret.clear() self.assertNotIn("uuid1", self.connection.secrets) self.assertIn("uuid2", self.connection.secrets)
def test_clear(self): self.connection.secrets = { "uuid1": vmfakecon.Secret(self.connection, "uuid1", "ceph", "ovirt/name1", None), "uuid2": vmfakecon.Secret(self.connection, "uuid2", "ceph", "name2", None), } secret.clear() assert "uuid1" not in self.connection.secrets assert "uuid2" in self.connection.secrets
def test_clear_skip_failed(self): def fail(): raise vmfakecon.Error(libvirt.VIR_ERR_INTERNAL_ERROR) self.connection.secrets = { "uuid1": vmfakecon.Secret(self.connection, "uuid1", "ceph", "ovirt/name1", None), "uuid2": vmfakecon.Secret(self.connection, "uuid2", "ceph", "ovirt/name2", None), } self.connection.secrets["uuid1"].undefine = fail secret.clear() self.assertNotIn("uuid2", self.connection.secrets)
def __init__(self, irs, log, scheduler): """ Initialize the (single) clientIF instance :param irs: a Dispatcher object to be used as this object's irs. :type irs: :class:`storage.dispatcher.Dispatcher` :param log: a log object to be used for this object's logging. :type log: :class:`logging.Logger` """ self.vmContainerLock = threading.Lock() self._networkSemaphore = threading.Semaphore() self._shutdownSemaphore = threading.Semaphore() self.irs = irs if self.irs: self._contEIOVmsCB = partial(clientIF.contEIOVms, proxy(self)) self.irs.registerDomainStateChangeCallback(self._contEIOVmsCB) self.log = log self._recovery = True self.channelListener = Listener(self.log) self._generationID = str(uuid.uuid4()) self.mom = None self.bindings = {} self._broker_client = None self._subscriptions = defaultdict(list) self._scheduler = scheduler if _glusterEnabled: self.gluster = gapi.GlusterApi(self, log) else: self.gluster = None try: self.vmContainer = {} self.lastRemoteAccess = 0 self._enabled = True self._netConfigDirty = False self._prepareMOM() secret.clear() concurrent.thread(self._recoverThread, name='clientIFinit').start() self.channelListener.settimeout( config.getint('vars', 'guest_agent_timeout')) self.channelListener.start() self.threadLocal = threading.local() self.threadLocal.client = '' host = config.get('addresses', 'management_ip') port = config.getint('addresses', 'management_port') # When IPv6 is not enabled, fallback to listen on IPv4 address try: self._createAcceptor(host, port) except socket.error as e: if e.errno == errno.EAFNOSUPPORT and host in ('::', '::1'): fallback_host = '0.0.0.0' self._createAcceptor(fallback_host, port) else: raise self._prepareXMLRPCBinding() self._prepareJSONRPCBinding() self._connectToBroker() except: self.log.error('failed to init clientIF, ' 'shutting down storage dispatcher') if self.irs: self.irs.prepareForShutdown() raise
def __init__(self, irs, log, scheduler): """ Initialize the (single) clientIF instance :param irs: a Dispatcher object to be used as this object's irs. :type irs: :class:`vdsm.storage.dispatcher.Dispatcher` :param log: a log object to be used for this object's logging. :type log: :class:`logging.Logger` """ self.vmContainerLock = threading.Lock() self._networkSemaphore = threading.Semaphore() self._shutdownSemaphore = threading.Semaphore() self.irs = irs if self.irs: self._contEIOVmsCB = partial(clientIF.contEIOVms, proxy(self)) self.irs.registerDomainStateChangeCallback(self._contEIOVmsCB) self.log = log self._recovery = True # TODO: The guest agent related code spreads around too much. There is # QemuGuestAgentPoller and ChannelListner here and then many instances # of GuestAgent per VM in vm.py. This should be refactored and # operated by single object. Idealy the distinction between what is # served by QEMU-GA and what is server by oVirt GA should not be # visible to the rest of the code. self.channelListener = Listener(self.log) self.qga_poller = QemuGuestAgentPoller(self, log, scheduler) self.mom = None self.servers = {} self._broker_client = None self._subscriptions = defaultdict(list) self._scheduler = scheduler self._unknown_vm_ids = set() if _glusterEnabled: self.gluster = gapi.GlusterApi() else: self.gluster = None try: self.vmContainer = {} self.lastRemoteAccess = 0 self._enabled = True self._netConfigDirty = False self.mom = MomClient(config.get("mom", "socket_path")) self.mom.connect() secret.clear() concurrent.thread(self._recoverThread, name='vmrecovery').start() self.channelListener.settimeout( config.getint('vars', 'guest_agent_timeout')) self.channelListener.start() self.qga_poller.start() self.threadLocal = threading.local() self.threadLocal.client = '' host = config.get('addresses', 'management_ip') port = config.getint('addresses', 'management_port') # When IPv6 is not enabled, fallback to listen on IPv4 address try: self._createAcceptor(host, port) except socket.error as e: if e.errno == errno.EAFNOSUPPORT and host in ('::', '::1'): fallback_host = '0.0.0.0' self._createAcceptor(fallback_host, port) else: raise self._prepareHttpServer() self._prepareJSONRPCServer() self._connectToBroker() except: self.log.error('failed to init clientIF, ' 'shutting down storage dispatcher') if self.irs: self.irs.prepareForShutdown() raise
def __init__(self, irs, log, scheduler): """ Initialize the (single) clientIF instance :param irs: a Dispatcher object to be used as this object's irs. :type irs: :class:`vdsm.storage.dispatcher.Dispatcher` :param log: a log object to be used for this object's logging. :type log: :class:`logging.Logger` """ self.vmContainerLock = threading.Lock() self._networkSemaphore = threading.Semaphore() self._shutdownSemaphore = threading.Semaphore() self.irs = irs if self.irs: self._contEIOVmsCB = partial(clientIF.contEIOVms, proxy(self)) self.irs.registerDomainStateChangeCallback(self._contEIOVmsCB) self.log = log self._recovery = True self.channelListener = Listener(self.log) self.mom = None self.servers = {} self._broker_client = None self._subscriptions = defaultdict(list) self._scheduler = scheduler self._unknown_vm_ids = set() if _glusterEnabled: self.gluster = gapi.GlusterApi() else: self.gluster = None try: self.vmContainer = {} self.lastRemoteAccess = 0 self._enabled = True self._netConfigDirty = False self._prepareMOM() secret.clear() concurrent.thread(self._recoverThread, name='vmrecovery').start() self.channelListener.settimeout( config.getint('vars', 'guest_agent_timeout')) self.channelListener.start() self.threadLocal = threading.local() self.threadLocal.client = '' host = config.get('addresses', 'management_ip') port = config.getint('addresses', 'management_port') # When IPv6 is not enabled, fallback to listen on IPv4 address try: self._createAcceptor(host, port) except socket.error as e: if e.errno == errno.EAFNOSUPPORT and host in ('::', '::1'): fallback_host = '0.0.0.0' self._createAcceptor(fallback_host, port) else: raise self._prepareHttpServer() self._prepareJSONRPCServer() self._connectToBroker() except: self.log.error('failed to init clientIF, ' 'shutting down storage dispatcher') if self.irs: self.irs.prepareForShutdown() raise