コード例 #1
0
ファイル: rabbithelper.py プロジェクト: ateranishi/pyon
def clean_by_sysname(connect_string, sysname):
    """
    Utility method to clean sysname-prefixed exchanges and queues on a broker.

    @param  connect_string  The connect string to use with the RabbitManagementHelper.
                            Form is similar to "-H localhost -P 55672 -u guest -p guest -V /"
    @param  sysname         The sysname to use to select exchanges and queues to delete.
                            Must be the prefix to the exchange or queue or this will not be
                            deleted.
    @returns                A 2-tuple of (list of exchanges deleted, list of queues deleted).
    """
    rmh               = RabbitManagementHelper(make_parser(), connect_string)

    exchanges         = rmh.list_names('exchanges')
    deleted_exchanges = rmh.delete_names_with_prefix('exchange', exchanges, sysname)

    queues            = rmh.list_names('queues')
    deleted_queues    = rmh.delete_names_with_prefix('queue', queues, sysname)

    return (deleted_exchanges, deleted_queues)
コード例 #2
0
ファイル: rabbithelper.py プロジェクト: pkediyal/pyon
def clean_by_sysname(connect_string, sysname):
    """
    Utility method to clean sysname-prefixed exchanges and queues on a broker.

    @param  connect_string  The connect string to use with the RabbitManagementHelper.
                            Form is similar to "-H localhost -P 55672 -u guest -p guest -V /"
    @param  sysname         The sysname to use to select exchanges and queues to delete.
                            Must be the prefix to the exchange or queue or this will not be
                            deleted.
    @returns                A 2-tuple of (list of exchanges deleted, list of queues deleted).
    """
    rmh = RabbitManagementHelper(make_parser(), connect_string)

    exchanges = rmh.list_names('exchanges')
    deleted_exchanges = rmh.delete_names_with_prefix('exchange', exchanges,
                                                     sysname)

    queues = rmh.list_names('queues')
    deleted_queues = rmh.delete_names_with_prefix('queue', queues, sysname)

    return (deleted_exchanges, deleted_queues)
コード例 #3
0
    def begin(self):
        """Called before any tests are collected or run. Use this to
        perform any setup needed before testing begins.
        """
        # Make sure we initialize pyon before anything in this plugin executes
        from pyon.core import bootstrap
        if not bootstrap.pyon_initialized:
            bootstrap.bootstrap_pyon()

        try:
            from pyon.public import get_sys_name, CFG
            self.sysname = get_sys_name()

            # Clean exchanges and system queues out there
            try:
                rmh = RabbitManagementHelper(make_parser(), '-H %s -P 55672 -u %s -p %s -V %s'
                        % (CFG.server.amqp.host, CFG.server.amqp.username,
                        CFG.server.amqp.password, CFG.server.amqp.vhost))
                exchanges = rmh.list_names('exchanges')
                deleted = rmh.delete_names_with_prefix('exchange', exchanges, self.sysname)
                debug.write('Deleted exchanges:\n%s \n' % '\n'.join(deleted))
                queues = rmh.list_names('queues')
                deleted = rmh.delete_names_with_prefix('queue', queues, self.sysname)
                debug.write('Deleted queues:\n%s \n' % '\n'.join(deleted))
            except Exception as e:
                pass

            # Force datastore loader to use the same sysname
            from pyon.datastore.datastore_admin import DatastoreAdmin
            self.datastore_admin = DatastoreAdmin(config=CFG)

            self.datastore_admin.clear_datastore(prefix=self.sysname)

            def die(signum, frame):
                # For whatever reason, the parent doesn't die some times
                # when getting KeyboardInterrupt.  Hence this signal
                # handler.

                # Signal is pass through. The child pycc gets
                # its own KeyboardInterrupt and will shut down accordingly.
                debug.write('Received Keyboard Interrupt. Exiting now.\n')
                os._exit(9)

            signal.signal(signal.SIGINT, die)

            def no_zombie(signum, frame):
                # Debug to figure out who's dying
                debug.write('SIGCHLD received\n')
                stack = []
                while frame:
                    stack.append(frame)
                    frame =frame.f_back
                stack.reverse()
                for frame in stack:
                    debug.write('Frame %s in %s at line %s\n' %
                            (frame.f_code.co_name,
                                frame.f_code.co_filename, frame.f_lineno))
                debug.write('Child is dead...Clean up now so there is no zombie\n')
                (pid, status) = os.wait()
                exitstatus, signum = status & 0xff, (status & 0xff00) >> 8
                debug.write('Child pid %d with exit status %d and signum %d\n' % (pid, exitstatus, signum))
            # Could be dangerous.  Comment this out.
            # signal.signal(signal.SIGCHLD, no_zombie)

            def container_started_cb(signum, frame):
                """Callback when child pycc service is ready"""
                self.container_started = True

            signal.signal(signal.SIGUSR1, container_started_cb)

            # Make sure the pycc process has the same sysname as the nose
            ccargs = ['bin/pycc', '--noshell', '-sp', '--sysname=%s' % self.sysname,
                    '--logcfg=res/config/logging.pycc.yml',
                    '--rel=%s' % self.rel,
                    "--config={'system': {'auto_bootstrap': True}}"]
            debug.write('Starting cc process: %s\n' % ' '.join(ccargs))
            newenv = os.environ.copy()
            po = subprocess.Popen(ccargs, env=newenv, close_fds=True)
            self.ccs.append(po)

            # Wait for container to be ready
            while not self.container_started:
                time.sleep(0.2)
            debug.write('Child container is ready...\n')

            # Dump datastore
            self.datastore_admin.dump_datastore(path='res/dd', compact=True)
            debug.write('Dump child container state to file...\n')

            # Clean again to make sure the first nosetest starts on a clean
            # slate
            self.datastore_admin.clear_datastore(prefix=self.sysname)
            # Enable CEI mode for the tests
            os.environ['CEI_LAUNCH_TEST'] = '1'

            debug.write('Start nose tests now...\n')
        except Exception as e:
            self.container_shutdown()
            raise e