Exemple #1
0
    def test_clean_stale_with_threads_active(self):
        """verify locks for multiple threads are cleaned up """

        # create sentinels for four threads in our process, and a 'dead'
        # process
        sentinel1 = self._create_sentinel(self.hostname, self.pid, 'Default-1')
        sentinel2 = self._create_sentinel(self.hostname, self.pid, 'Default-2')
        sentinel3 = self._create_sentinel(self.hostname, self.pid, 'Default-3')
        sentinel4 = self._create_sentinel(self.hostname, self.pid, 'Default-4')
        sentinel5 = self._create_sentinel(self.hostname, self.dead_pid,
                                          'Default-1')

        os.link(sentinel1, self.lock_file)

        utils.cleanup_file_locks()

        self.assertTrue(os.path.exists(sentinel1))
        self.assertTrue(os.path.exists(sentinel2))
        self.assertTrue(os.path.exists(sentinel3))
        self.assertTrue(os.path.exists(sentinel4))
        self.assertTrue(os.path.exists(self.lock_file))
        self.assertFalse(os.path.exists(sentinel5))

        os.unlink(sentinel1)
        os.unlink(sentinel2)
        os.unlink(sentinel3)
        os.unlink(sentinel4)
        os.unlink(self.lock_file)
Exemple #2
0
    def test_clean_stale_with_threads_active(self):
        """verify locks for multiple threads are cleaned up """

        # create sentinels for four threads in our process, and a 'dead'
        # process
        sentinel1 = self._create_sentinel(self.hostname, self.pid, 'Default-1')
        sentinel2 = self._create_sentinel(self.hostname, self.pid, 'Default-2')
        sentinel3 = self._create_sentinel(self.hostname, self.pid, 'Default-3')
        sentinel4 = self._create_sentinel(self.hostname, self.pid, 'Default-4')
        sentinel5 = self._create_sentinel(self.hostname, self.dead_pid,
                                          'Default-1')

        os.link(sentinel1, self.lock_file)

        utils.cleanup_file_locks()

        self.assertTrue(os.path.exists(sentinel1))
        self.assertTrue(os.path.exists(sentinel2))
        self.assertTrue(os.path.exists(sentinel3))
        self.assertTrue(os.path.exists(sentinel4))
        self.assertTrue(os.path.exists(self.lock_file))
        self.assertFalse(os.path.exists(sentinel5))

        os.unlink(sentinel1)
        os.unlink(sentinel2)
        os.unlink(sentinel3)
        os.unlink(sentinel4)
        os.unlink(self.lock_file)
Exemple #3
0
def main():
    """Main loop."""
    options, args = parse_options()
    verbose = options.verbose

    if verbose:
        LOG.logger.setLevel(logging.DEBUG)
    else:
        LOG.logger.setLevel(logging.INFO)
    LOG.info('Cleaning stale locks from %s' % FLAGS.lock_path)
    utils.cleanup_file_locks()
    LOG.info('Finished')
Exemple #4
0
    def start(self):
        vcs_string = version.version_string_with_vcs()
        LOG.audit(_('Starting %(topic)s node (version %(vcs_string)s)'), {
            'topic': self.topic,
            'vcs_string': vcs_string
        })
        utils.cleanup_file_locks()
        rpc.register_opts(FLAGS)
        self.manager.init_host()
        self.model_disconnected = False
        ctxt = context.get_admin_context()
        try:
            service_ref = db.service_get_by_args(ctxt, self.host, self.binary)
            self.service_id = service_ref['id']
        except exception.NotFound:
            self._create_service_ref(ctxt)

        if 'nova-compute' == self.binary:
            self.manager.update_available_resource(ctxt)

        self.conn = rpc.create_connection(new=True)
        LOG.debug(
            _("Creating Consumer connection for Service %s") % self.topic)

        rpc_dispatcher = self.manager.create_rpc_dispatcher()

        # Share this same connection for these Consumers
        self.conn.create_consumer(self.topic, rpc_dispatcher, fanout=False)

        node_topic = '%s.%s' % (self.topic, self.host)
        self.conn.create_consumer(node_topic, rpc_dispatcher, fanout=False)

        self.conn.create_consumer(self.topic, rpc_dispatcher, fanout=True)

        # Consume from all consumers in a thread
        self.conn.consume_in_thread()

        if self.report_interval:
            pulse = utils.LoopingCall(self.report_state)
            pulse.start(interval=self.report_interval,
                        initial_delay=self.report_interval)
            self.timers.append(pulse)

        if self.periodic_interval:
            if self.periodic_fuzzy_delay:
                initial_delay = random.randint(0, self.periodic_fuzzy_delay)
            else:
                initial_delay = None

            periodic = utils.LoopingCall(self.periodic_tasks)
            periodic.start(interval=self.periodic_interval,
                           initial_delay=initial_delay)
            self.timers.append(periodic)
def main():
    """Main loop."""
    options, args = parse_options()
    verbose = options.verbose

    if verbose:
        LOG.logger.setLevel(logging.DEBUG)
    else:
        LOG.logger.setLevel(logging.INFO)
    LOG.info('Cleaning stale locks from %s' % FLAGS.lock_path)
    utils.cleanup_file_locks()
    LOG.info('Finished')
Exemple #6
0
    def start(self):
        vcs_string = version.version_string_with_vcs()
        LOG.audit(_('Starting %(topic)s node (version %(vcs_string)s)'),
                  {'topic': self.topic, 'vcs_string': vcs_string})
        utils.cleanup_file_locks()
        rpc.register_opts(FLAGS)
        self.manager.init_host()
        self.model_disconnected = False
        ctxt = context.get_admin_context()
        try:
            service_ref = db.service_get_by_args(ctxt,
                                                 self.host,
                                                 self.binary)
            self.service_id = service_ref['id']
        except exception.NotFound:
            self._create_service_ref(ctxt)

        if 'nova-compute' == self.binary:
            self.manager.update_available_resource(ctxt)

        self.conn = rpc.create_connection(new=True)
        LOG.debug(_("Creating Consumer connection for Service %s") %
                  self.topic)

        rpc_dispatcher = self.manager.create_rpc_dispatcher()

        # Share this same connection for these Consumers
        self.conn.create_consumer(self.topic, rpc_dispatcher, fanout=False)

        node_topic = '%s.%s' % (self.topic, self.host)
        self.conn.create_consumer(node_topic, rpc_dispatcher, fanout=False)

        self.conn.create_consumer(self.topic, rpc_dispatcher, fanout=True)

        # Consume from all consumers in a thread
        self.conn.consume_in_thread()

        if self.report_interval:
            pulse = utils.LoopingCall(self.report_state)
            pulse.start(interval=self.report_interval,
                        initial_delay=self.report_interval)
            self.timers.append(pulse)

        if self.periodic_interval:
            if self.periodic_fuzzy_delay:
                initial_delay = random.randint(0, self.periodic_fuzzy_delay)
            else:
                initial_delay = None

            periodic = utils.LoopingCall(self.periodic_tasks)
            periodic.start(interval=self.periodic_interval,
                           initial_delay=initial_delay)
            self.timers.append(periodic)
Exemple #7
0
    def start(self):
        """Start serving this service using loaded configuration.

        Also, retrieve updated port number in case '0' was passed in, which
        indicates a random port should be used.

        :returns: None

        """
        utils.cleanup_file_locks()
        if self.manager:
            self.manager.init_host()
        self.server.start()
Exemple #8
0
    def start(self):
        """Start serving this service using loaded configuration.

        Also, retrieve updated port number in case '0' was passed in, which
        indicates a random port should be used.

        :returns: None

        """
        utils.cleanup_file_locks()
        if self.manager:
            self.manager.init_host()
        self.server.start()
Exemple #9
0
    def test_nested_external_fails(self):
        """We can not nest external syncs"""

        @utils.synchronized('testlock1', external=True)
        def outer_lock():

            @utils.synchronized('testlock2', external=True)
            def inner_lock():
                pass
            inner_lock()
        try:
            self.assertRaises(lockfile.NotMyLock, outer_lock)
        finally:
            utils.cleanup_file_locks()
Exemple #10
0
    def test_nested_external_fails(self):
        """We can not nest external syncs"""
        @utils.synchronized('testlock1', external=True)
        def outer_lock():
            @utils.synchronized('testlock2', external=True)
            def inner_lock():
                pass

            inner_lock()

        try:
            self.assertRaises(lockfile.NotMyLock, outer_lock)
        finally:
            utils.cleanup_file_locks()
Exemple #11
0
    def test_clean_stale_locks(self):
        """verify locks for dead processes are cleaned up"""

        # create sentinels for two processes, us and a 'dead' one
        # no actve lock
        sentinel1 = self._create_sentinel(self.hostname, self.pid)
        sentinel2 = self._create_sentinel(self.hostname, self.dead_pid)

        utils.cleanup_file_locks()

        self.assertTrue(os.path.exists(sentinel1))
        self.assertFalse(os.path.exists(self.lock_file))
        self.assertFalse(os.path.exists(sentinel2))

        os.unlink(sentinel1)
Exemple #12
0
    def test_clean_stale_locks(self):
        """verify locks for dead processes are cleaned up"""

        # create sentinels for two processes, us and a 'dead' one
        # no active lock
        sentinel1 = self._create_sentinel(self.hostname, self.pid)
        sentinel2 = self._create_sentinel(self.hostname, self.dead_pid)

        utils.cleanup_file_locks()

        self.assertTrue(os.path.exists(sentinel1))
        self.assertFalse(os.path.exists(self.lock_file))
        self.assertFalse(os.path.exists(sentinel2))

        os.unlink(sentinel1)
Exemple #13
0
    def test_clean_bogus_lockfiles(self):
        """verify lockfiles are cleaned """

        lock1 = os.path.join(FLAGS.lock_path, 'nova-testlock1.lock')
        lock2 = os.path.join(FLAGS.lock_path, 'nova-testlock2.lock')
        lock3 = os.path.join(FLAGS.lock_path, 'testlock3.lock')

        open(lock1, 'wb').close()
        open(lock2, 'wb').close()
        open(lock3, 'wb').close()

        utils.cleanup_file_locks()

        self.assertFalse(os.path.exists(lock1))
        self.assertFalse(os.path.exists(lock2))
        self.assertTrue(os.path.exists(lock3))

        os.unlink(lock3)
Exemple #14
0
    def test_clean_bogus_lockfiles(self):
        """verify lockfiles are cleaned """

        lock1 = os.path.join(FLAGS.lock_path, 'nova-testlock1.lock')
        lock2 = os.path.join(FLAGS.lock_path, 'nova-testlock2.lock')
        lock3 = os.path.join(FLAGS.lock_path, 'testlock3.lock')

        open(lock1, 'wb').close()
        open(lock2, 'wb').close()
        open(lock3, 'wb').close()

        utils.cleanup_file_locks()

        self.assertFalse(os.path.exists(lock1))
        self.assertFalse(os.path.exists(lock2))
        self.assertTrue(os.path.exists(lock3))

        os.unlink(lock3)