Ejemplo n.º 1
0
def test_reloadChutes(mockStore, mockSettings, mResources, mWait, mTime, mOut, mTimeint):
    """
    Test that the reloadChutes function does it's job.
    """
    #Test that if pdconfd isn't enabled we return an empty list
    mockSettings.PDCONFD_ENABLED = False
    storage = MagicMock()
    mockStore.return_value = storage

    #Call
    ret = restart.reloadChutes()

    #Assertions
    assert ret == []
    assert not mockStore.called

    #Test that if pdconfd is enabled we do our job
    mTimeint.return_value = 'Now'
    mockSettings.PDCONFD_ENABLED = True
    mockSettings.RESERVED_CHUTE = 'PDROP'
    ch1 = MagicMock()
    ch2 = MagicMock()
    ch3 = MagicMock()
    ch1.state = 'running'
    ch1.name = 'ch1'
    ch2.state = 'stopped'
    ch3.state = 'running'
    ch3.name = 'ch3'
    storage.getChuteList.return_value = [ch1, ch2, ch3]
    mWait.side_effect = [None, None, '[{"success": false, "comment": "PDROP"},{"success": false, "comment": "ch1"},{"success": false, "comment": "ch2"},{"success": true, "comment": "ch3"},{"success": true, "comment": "error"}]']

    #Call
    ret = restart.reloadChutes()

    #Assertions
    mResources.assert_called_with(ch3)
    assert mResources.call_count == 2
    assert mTime.sleep.call_count == 2
    assert mTime.sleep.called_with(1)
    assert mOut.warn.call_count == 2
    assert 'Failed to load a system config section' in str(mOut.warn.call_args_list[0])
    assert 'Failed to load config section for unrecognized chute: ch2' in str(mOut.warn.call_args_list[1])
    assert dict(updateClass='CHUTE', updateType='stop', name=ch1.name, tok=mTimeint.return_value, func=restart.updateStatus, warning=restart.FAILURE_WARNING) in ret
    assert dict(updateClass='CHUTE', updateType='restart', name=ch3.name, tok=mTimeint.return_value, func=restart.updateStatus) in ret
Ejemplo n.º 2
0
    def performUpdates(self):
        """This is the main working function of the PDConfigurer class.
            It should be executed as a separate thread, it does the following:
                checks for any updates to perform
                does them
                responds to the server
                removes the update
                checks for more updates
                    if more exist it calls itself again more quickly
                    else it puts itself to sleep for a little while
        """

        #add any chutes that should already be running to the front of the update queue before processing any updates
        startQueue = reloadChutes()
        self.updateLock.acquire()
        # insert the data into the front of our update queue so that all old chutes restart befor new ones are processed
        for updateObj in startQueue:
            self.updateQueue.insert(0, updateObj)
        self.updateLock.release()

        # Always perform this work
        while(self.reactor.running):
            # Check for new updates
            updateObj = self.getNextUpdate()
            if(updateObj is None):
                time.sleep(1)
                continue

            try:
                # Take the object and identify the update type
                update = updateObject.parse(updateObj)
                out.info('Performing update %s\n' % (update))

                # TESTING start
                if(settings.FC_BOUNCE_UPDATE): # pragma: no cover
                    out.testing('Bouncing update %s, result: %s\n' % (
                        update, settings.FC_BOUNCE_UPDATE))
                    update.complete(success=True, message=settings.FC_BOUNCE_UPDATE)
                    continue
                # TESTING end

                # Based on each update type execute could be different
                update.execute()

            except Exception as e:
                out.exception(e, True)