コード例 #1
0
def rename_scenario(handler, scenario_name, new_name):
    """
    Renames specified scenario, renames Stubs, reloads cache
    :param handler: TrackRequest handler
    :param scenario_name: <string> scenario name
    :param new_name: <string> new scenario name
    :return: <tuple> containing status code and message that will be returned
    """
    response = {
        'version': version
    }

    scenario = Scenario()
    # getting hostname
    host = handler.get_argument('host', get_hostname(handler.request))
    # full names hostname:scenario_name
    full_scenario_name = "{0}:{1}".format(host, scenario_name)
    new_full_scenario_name = "{0}:{1}".format(host, new_name)
    # getting scenario object
    scenario_obj = scenario.get(full_scenario_name)
    # checking if scenario exist, if not - quit
    if scenario_obj is None:
        handler.set_status(400)
        handler.track.scenario = scenario_name
        response['error'] = "Scenario not found. Name provided: {0}, host checked: {1}.".format(scenario_name, host)
        log.debug("Scenario not found. Name provided: {0}, host checked: {1}.".format(scenario_name, host))
        return response

    # renaming scenario and all stubs, getting a dict with results
    try:
        response = scenario.change_name(full_scenario_name, new_full_scenario_name)
    except Exception as ex:
        handler.set_status()
        log.debug("Failed to change scenario name, got error: %s" % ex)
        response['error']['database'] = "Failed to change scenario name, got error: %s" % ex
    try:

        cache = Cache(host)
        # change cache
        scenario_sessions = cache.get_sessions_status(scenario_name)
        # scenario sessions contains tuples [(u'myscenario_session2_1', u'dormant'), ....]
        session_info = []

        cache.delete_caches(scenario_name)

        # rebuild cache
        for session_name, mode in scenario_sessions:
            cache.create_session_cache(new_name, session_name)
            session_info.append({'name': session_name})
            # sessions after creation go into playback mode, ending them
            end_session(handler, session_name)

        response['Remapped sessions'] = session_info
    except Exception as ex:
        log.debug("Failed to repopulate cache, got error: %s" % ex)
        response['error']['cache'] = "Failed to repopulate cache, got error: %s" % ex
    return response
コード例 #2
0
ファイル: handlers.py プロジェクト: JohnFDavenport/mirage
    def _end_session(self):
        """

        Ends session

        Example output:
        {
         "version": "0.6.3",
         "data": {
             "message": "Session ended"
             }
        }
        """
        try:
            response = end_session(self, self.session_name)
            self.write(response)
        except Exception as ex:
            log.warn("Failed to end session %s for scenario: %s. Got error: %s" % (self.session_name,
                                                                                   self.scenario_name,
                                                                                   ex))
コード例 #3
0
ファイル: handlers.py プロジェクト: ocoperations/stubo-app
    def _end_session(self):
        """

        Ends session

        Example output:
        {
         "version": "0.6.3",
         "data": {
             "message": "Session ended"
             }
        }
        """
        try:
            response = end_session(self, self.session_name)
            self.write(response)
        except Exception as ex:
            log.warn(
                "Failed to end session %s for scenario: %s. Got error: %s" %
                (self.session_name, self.scenario_name, ex))
コード例 #4
0
def end_session_request(handler):
    session = get_session_arg(handler)
    return end_session(handler, session)