'Update the agent if possible'

def _checkForUpdate(self):

    res = urllib2.urlopen((self.settings.version_url % {'key': self.settings.mms_key}))
    resBson = None
    try:
        resBson = bson.decode_all(res.read())
    finally:
        if (res is not None):
            res.close()
            res = None
    if (len(resBson) != 1):
        return
    versionResponse = resBson[0]
    if (('status' not in versionResponse) or (versionResponse['status'] != 'ok')):
        return
    if (('agentVersion' not in versionResponse) or ('authCode' not in versionResponse)):
        return
    remoteAgentVersion = versionResponse['agentVersion']
    authCode = versionResponse['authCode']
    if (authCode != hmac.new(self.settings.secret_key, remoteAgentVersion, digestmod=hashlib.sha1).hexdigest()):
        self.logger.error('Invalid    auth    code    -    please    confirm    your    secret    key    (defined    on    Settings    page)    is    correct    and    hmac    is    properly    installed    -    http://mms.10gen.com/help/')
        return
    if self._shouldUpgradeAgent(self.settings.settingsAgentVersion, remoteAgentVersion):
        self._upgradeAgent(remoteAgentVersion)
