Esempio n. 1
0
def syncer(obj, obj_type, queue1):

    hostname = os.environ.get('RMQ_HOSTNAME', 'localhost')
    port = int(os.environ.get('RMQ_PORT', 5672))
    username = os.environ.get('RMQ_USERNAME')
    password = os.environ.get('RMQ_PASSWORD')

    credentials = pika.PlainCredentials(username, password)
    rmq_conn_params = pika.ConnectionParameters(host=hostname,
                                                port=port,
                                                credentials=credentials)
    mq_connection = pika.BlockingConnection(rmq_conn_params)
    mq_channel = mq_connection.channel()

    sid = 'test.0015'
    rmgr = BaseRmgr({}, sid, None, {})
    tmgr = BaseTmgr(sid=sid,
                    pending_queue=['pending-1'],
                    completed_queue=['completed-1'],
                    rmgr=rmgr,
                    rmq_conn_params=rmq_conn_params,
                    rts=None)

    tmgr._sync_with_master(obj, obj_type, mq_channel, queue1)

    mq_connection.close()
Esempio n. 2
0
        def component_execution(packets, conn_params, queue):

            tmgr = BaseTmgr(None, None, None, None, None, None)
            tmgr._log = mocked_Logger
            tmgr._prof = mocked_Profiler
            mq_connection2 = pika.BlockingConnection(rmq_conn_params)
            mq_channel2 = mq_connection2.channel()
            for obj_type, obj, in packets:
                tmgr._sync_with_master(obj, obj_type, mq_channel2, conn_params,
                                       queue)
                if mq_channel2.is_open:
                    mq_channel2.close()
def syncer(obj, obj_type, queue1):

    hostname = os.environ.get('RMQ_HOSTNAME', 'localhost')
    port = int(os.environ.get('RMQ_PORT', 5672))

    mq_connection = pika.BlockingConnection(
        pika.ConnectionParameters(host=hostname, port=port))
    mq_channel = mq_connection.channel()

    sid = 'test.0015'
    rmgr = BaseRmgr({}, sid, None, {})
    tmgr = BaseTmgr(sid=sid,
                    pending_queue=['pending-1'],
                    completed_queue=['completed-1'],
                    rmgr=rmgr,
                    mq_hostname=hostname,
                    port=port,
                    rts=None)

    tmgr._sync_with_master(obj, obj_type, mq_channel, queue1)

    mq_connection.close()
Esempio n. 4
0
    def test_advance(self, mocked_init, mocked_Logger, mocked_Profiler,
                     mocked_BlockingConnection):

        mocked_BlockingConnection.channel = mock.MagicMock(
            spec=pika.BlockingConnection.channel)
        mocked_BlockingConnection.close = mock.MagicMock(return_value=None)
        mocked_BlockingConnection.channel.queue_delete = mock.MagicMock(
            return_value=None)
        mocked_BlockingConnection.channel.queue_declare = mock.MagicMock(
            return_value=None)
        rmq_params = mock.MagicMock(spec=ConnectionParameters)
        rmgr = mock.MagicMock(spec=Base_ResourceManager)
        tmgr = Tmgr('test_tmgr', ['pending_queues'], ['completed_queues'],
                    rmgr, rmq_params, 'test_rts')

        global_syncs = []

        def _sync_side_effect(obj, obj_type, channel, conn_params, queue):
            nonlocal global_syncs
            global_syncs.append([obj, obj_type, channel, conn_params, queue])

        tmgr._log = mocked_Logger
        tmgr._prof = mocked_Profiler
        tmgr._sync_with_master = mock.MagicMock(side_effect=_sync_side_effect)
        tmgr._uid = 'tmgr.0000'
        obj = mock.Mock()
        obj.parent_stage = {'uid': 'test_stage'}
        obj.parent_pipeline = {'uid': 'test_pipe'}
        obj.uid = 'test_object'
        obj.state = 'test_state'
        tmgr._advance(obj, 'Task', None, 'channel', 'params', 'queue')
        self.assertEqual(global_syncs[0],
                         [obj, 'Task', 'channel', 'params', 'queue'])
        self.assertIsNone(obj.state)
        global_syncs = []
        tmgr._advance(obj, 'Stage', 'new_state', 'channel', 'params', 'queue')
        self.assertEqual(global_syncs[0],
                         [obj, 'Stage', 'channel', 'params', 'queue'])
        self.assertEqual(obj.state, 'new_state')