Example #1
0
def rule_new(request, testplan_id):
    try:
        testplan = TestPlan(auth_token=request.user.password).get(testplan_id)
    except UnauthorizedException:
        logger.warning('User unauthorized. Signing out...')
        return signout(request)
    except NotFoundException:
        return render(request, '404.html')
    except Exception as inst:
        logger.error('Unexpected exception', exc_info=True)
        messages.error(request, inst.message if inst.message else 'Unexpected error')
        return HttpResponseRedirect(reverse('testplan_list'))

    form = RuleForm(request.POST or None)
    if form.is_valid():
        try:
            rule_id = Rule(testplan_id, auth_token=request.user.password).create(form.cleaned_data)
            return HttpResponseRedirect(reverse('rule_details', args=(str(testplan_id), str(rule_id))))
        except UnauthorizedException:
            logger.warning('User unauthorized. Signing out...')
            return signout(request)
        except Exception as inst:
            messages.error(request, inst.message if inst.message else 'Unexpected error')
            return HttpResponseRedirect(reverse('rule_new', args=(str(testplan_id),)))

    return render(request, 'rules/rule_new.html', {'form': form, 'testplan': testplan})
Example #2
0
def session_list(request):
    url = '%s/session/' % (settings.API_BASE_URL,)
    headers = {'X-Auth-Token': request.user.password}
    r = requests.get(url, headers=headers)

    if r.status_code != requests.codes.ok:
        return signout(request)

    sessions = json.loads(r.text)

    return render(request, 'sessions/session_list.html', sessions)
Example #3
0
def session_list(request):
    url = '%s/session/' % (settings.API_BASE_URL, )
    headers = {'X-Auth-Token': request.user.password}
    r = requests.get(url, headers=headers)

    if r.status_code != requests.codes.ok:
        return signout(request)

    sessions = json.loads(r.text)

    return render(request, 'sessions/session_list.html', sessions)
Example #4
0
def session_start(request, session_id):
    if request.method != 'POST':
        return HttpResponseBadRequest('Method must be POST')

    try:
        Session(auth_token=request.user.password).start(session_id)
    except UnauthorizedException:
        logger.warning('User unauthorized. Signing out...')
        signout(request)
        return HttpResponseBadRequest('Unauthorized')
    except NotFoundException:
        logger.warning('The requested Session "%s" does not exist', session_id)
        return HttpResponseBadRequest('Resource not found')
    except ServerErrorException:
        logger.error('Unexpected exception in the API', exc_info=True)
        return HttpResponseServerError()
    except Exception as inst:
        logger.error('Unexpected exception', exc_info=True)
        message = inst.message if inst.message else 'Unexpected error'
        return HttpResponseBadRequest(message)
    return HttpResponse('started')
Example #5
0
def recording_start(request, recording_id):
    if request.method != "POST":
        return HttpResponseBadRequest("Method must be POST")

    try:
        info = Recording(auth_token=request.user.password).start(recording_id)
    except UnauthorizedException:
        logger.warning("User unauthorized. Signing out...")
        signout(request)
        return HttpResponseBadRequest("Unauthorized")
    except NotFoundException:
        logger.warning('The requested Recording "%s" does not exist', recording_id)
        return HttpResponseBadRequest("Resource not found")
    except ServerErrorException:
        logger.error("Unexpected exception in the API", exc_info=True)
        return HttpResponseServerError()
    except Exception as inst:
        logger.error("Unexpected exception", exc_info=True)
        message = inst.message if inst.message else "Unexpected error"
        return HttpResponseBadRequest(message)
    return HttpResponse("started")
Example #6
0
def session_start(request, session_id):
    if request.method != 'POST':
        return HttpResponseBadRequest('Method must be POST')

    try:
        Session(auth_token=request.user.password).start(session_id)
    except UnauthorizedException:
        logger.warning('User unauthorized. Signing out...')
        signout(request)
        return HttpResponseBadRequest('Unauthorized')
    except NotFoundException:
        logger.warning('The requested Session "%s" does not exist', session_id)
        return HttpResponseBadRequest('Resource not found')
    except ServerErrorException:
        logger.error('Unexpected exception in the API', exc_info=True)
        return HttpResponseServerError()
    except Exception as inst:
        logger.error('Unexpected exception', exc_info=True)
        message = inst.message if inst.message else 'Unexpected error'
        return HttpResponseBadRequest(message)
    return HttpResponse('started')
Example #7
0
def session_create(request):
    data = json.loads(request.body)

    try:
        session_id = Session(auth_token=request.user.password).create(data)
    except UnauthorizedException:
        logger.warning('User unauthorized. Signing out...')
        return signout(request)
    except Exception as inst:
        logger.error('Unexpected exception', exc_info=True)
        return render(request, '500.html', {'message': inst.message})

    url = reverse('session_details', args=(session_id,))
    return HttpResponse(url)
Example #8
0
def session_create(request):
    data = json.loads(request.body)

    try:
        session_id = Session(auth_token=request.user.password).create(data)
    except UnauthorizedException:
        logger.warning('User unauthorized. Signing out...')
        return signout(request)
    except Exception as inst:
        logger.error('Unexpected exception', exc_info=True)
        return render(request, '500.html', {'message': inst.message})

    url = reverse('session_details', args=(session_id, ))
    return HttpResponse(url)
Example #9
0
def rule_details(request, testplan_id, rule_id):
    try:
        testplan = TestPlan(auth_token=request.user.password).get(testplan_id)
        rule = Rule(testplan_id, auth_token=request.user.password).get(rule_id)
        # check if the Rule belongs to the Test Plan
        # FIXME: API should return the "testplanId" within the Rule
        # if str(rule['testPlanId']) != testplan_id:
        #     return render(request, '404.html')
    except UnauthorizedException:
        logger.warning('User unauthorized. Signing out...')
        return signout(request)
    except NotFoundException:
        logger.warning('The requested Rule "%s" does not exists in the given Test Plan "%s"', rule_id, testplan_id)
        return render(request, '404.html')
    except Exception as inst:
        logger.error('Unexpected exception', exc_info=True)
        messages.error(request, inst.message if inst.message else 'Unexpected error')
        return HttpResponseRedirect(reverse('testplan_list'))

    initial_data = _rule_to_post_data(rule)

    form = RuleRequestForm(request.POST or None, initial=initial_data)
    if form.is_valid():
        try:
            Rule(testplan_id, auth_token=request.user.password).update(rule['id'], form.cleaned_data)
            messages.success(request, "The rule was updated successfully.")
            return HttpResponseRedirect(reverse('rule_details', args=(str(testplan_id), str(rule_id))))
        except UnauthorizedException:
            logger.warning('User unauthorized. Signing out...')
            return signout(request)
        except Exception as inst:
            logger.error('Unexpected exception', exc_info=True)
            messages.error(request, inst.message if inst.message else 'Unexpected error')
            return HttpResponseRedirect(reverse('rule_details', args=(str(testplan_id), str(rule_id))))

    data = {'testplan': testplan, 'rule': rule, 'form': form}
    return render(request, 'rules/rule_details.html', data)
Example #10
0
def qos_new(request):
    form = QoSForm(request.POST or None)
    if form.is_valid():
        try:
            qos_id = QoS(auth_token=request.user.password).create(form.cleaned_data)
            return HttpResponseRedirect(reverse("qos_details", args=(str(qos_id),)))
        except UnauthorizedException:
            logger.warning("User unauthorized. Signing out...")
            return signout(request)
        except Exception as inst:
            logger.error("Unexpected exception", exc_info=True)
            messages.error(request, inst.message if inst.message else "Unexpected error")
            return HttpResponseRedirect(reverse("qos_list"))

    return render(request, "qos/qos_new.html", {"form": form})
Example #11
0
def qos_list(request):

    try:
        qoss = QoS(auth_token=request.user.password).get_all()
    except UnauthorizedException:
        logger.warning("User unauthorized. Signing out...")
        return signout(request)
    except Exception as inst:
        logger.error("Unexpected exception", exc_info=True)
        return render(request, "500.html", {"message": inst.message})

    if request.is_ajax():
        return JsonResponse(qoss)

    return render(request, "qos/qos_list.html", qoss)
Example #12
0
def recording_list(request):
    try:
        recordings = Recording(auth_token=request.user.password).get_all()
    except UnauthorizedException:
        logger.warning("User unauthorized. Signing out...")
        return signout(request)
    except Exception as inst:
        logger.error("Unexpected exception", exc_info=True)
        return render(request, "500.html", {"message": inst.message})

    form = RecordingForm()
    data = dict()
    data["recordings"] = recordings["recordings"]
    data["form"] = form
    return render(request, "recording/recording_list.html", data)
Example #13
0
def testplan_list(request):

    try:
        testplans = TestPlan(auth_token=request.user.password).get_all()
    except UnauthorizedException:
        logger.warning('User unauthorized. Signing out...')
        return signout(request)
    except Exception as inst:
        logger.error('Unexpected exception', exc_info=True)
        return render(request, '500.html', {'message': inst.message})

    if request.is_ajax():
        return JsonResponse(testplans)

    return render(request, 'testplan/testplan_list.html', testplans)
Example #14
0
def qos_list(request):

    try:
        qoss = QoS(auth_token=request.user.password).get_all()
    except UnauthorizedException:
        logger.warning('User unauthorized. Signing out...')
        return signout(request)
    except Exception as inst:
        logger.error('Unexpected exception', exc_info=True)
        return render(request, '500.html', {'message': inst.message})

    if request.is_ajax():
        return JsonResponse(qoss)

    return render(request, 'qos/qos_list.html', qoss)
Example #15
0
def recording_list(request):
    try:
        recordings = Recording(auth_token=request.user.password).get_all()
    except UnauthorizedException:
        logger.warning('User unauthorized. Signing out...')
        return signout(request)
    except Exception as inst:
        logger.error('Unexpected exception', exc_info=True)
        return render(request, '500.html', {'message': inst.message})

    form = RecordingForm()
    data = dict()
    data['recordings'] = recordings['recordings']
    data['form'] = form
    return render(request, 'recording/recording_list.html', data)
Example #16
0
def serveroverload_new(request):
    form = ServerOverloadForm(request.POST or None)
    if form.is_valid():
        try:
            serveroverload_id = ServerOverload(auth_token=request.user.password).create(form.cleaned_data)
            return HttpResponseRedirect(reverse('serveroverload_details', args=(str(serveroverload_id),)))
        except UnauthorizedException:
            logger.warning('User unauthorized. Signing out...')
            return signout(request)
        except Exception as inst:
            logger.error('Unexpected exception', exc_info=True)
            messages.error(request, inst.message if inst.message else 'Unexpected error')
            return HttpResponseRedirect(reverse('serveroverload_list'))

    return render(request, 'serveroverload/serveroverload_new.html', {'form': form})
Example #17
0
def serveroverload_list(request):

    try:
        serveroverloads = ServerOverload(auth_token=request.user.password).get_all()
    except UnauthorizedException:
        logger.warning('User unauthorized. Signing out...')
        return signout(request)
    except Exception as inst:
        logger.error('Unexpected exception', exc_info=True)
        return render(request, '500.html', {'message': inst.message})

    if request.is_ajax():
        return JsonResponse(serveroverloads)

    return render(request, 'serveroverload/serveroverload_list.html', serveroverloads)
Example #18
0
def qos_details(request, qos_id):
    try:
        qos = QoS(auth_token=request.user.password).get(qos_id)
    except UnauthorizedException:
        logger.warning("User unauthorized. Signing out...")
        return signout(request)
    except NotFoundException:
        logger.warning('The requested Test Plan "%s" does not exist', qos_id)
        return render(request, "404.html")
    except Exception as inst:
        logger.error("Unexpected exception", exc_info=True)
        messages.error(request, inst.message if inst.message else "Unexpected error")
        return HttpResponseRedirect(reverse("qos_list"))

    data = {"qos": qos}
    return render(request, "qos/qos_details.html", data)
Example #19
0
def serveroverload_details(request, serveroverload_id):
    try:
        serveroverload = ServerOverload(auth_token=request.user.password).get(serveroverload_id)
    except UnauthorizedException:
        logger.warning('User unauthorized. Signing out...')
        return signout(request)
    except NotFoundException:
        logger.warning('The requested Server Overload profile "%s" does not exist', serveroverload_id)
        return render(request, '404.html')
    except Exception as inst:
        logger.error('Unexpected exception', exc_info=True)
        messages.error(request, inst.message if inst.message else 'Unexpected error')
        return HttpResponseRedirect(reverse('serveroverload_list'))

    data = {'serveroverload': serveroverload}
    return render(request, 'serveroverload/serveroverload_details.html', data)
Example #20
0
def session_execute(request, session_id):

    try:
        session = Session(auth_token=request.user.password).get(session_id)
        data = {'session': session}
        return render(request, 'sessions/session_execution.html', data)
    except UnauthorizedException:
        logger.warning('User unauthorized. Signing out...')
        return signout(request)
    except NotFoundException:
        logger.warning('The requested Session "%s" does not exist', session_id)
        return render(request, '404.html')
    except Exception as inst:
        logger.error('Unexpected exception', exc_info=True)
        messages.error(request, inst.message if inst.message else 'Unexpected error')
        return HttpResponseRedirect(reverse('session_details', args=(str(session_id),)))
Example #21
0
def testplan_details(request, testplan_id):
    try:
        testplan = TestPlan(auth_token=request.user.password).get(testplan_id)
        # rules = Rule(testplan_id, auth_token=request.user.password).get_all()
    except UnauthorizedException:
        logger.warning('User unauthorized. Signing out...')
        return signout(request)
    except NotFoundException:
        logger.warning('The requested Test Plan "%s" does not exist', testplan_id)
        return render(request, '404.html')
    except Exception as inst:
        logger.error('Unexpected exception', exc_info=True)
        messages.error(request, inst.message if inst.message else 'Unexpected error')
        return HttpResponseRedirect(reverse('testplan_list'))

    data = {'testplan': testplan}
    return render(request, 'testplan/testplan_details.html', data)
Example #22
0
def session_details(request, session_id):
    try:
        session = Session(auth_token=request.user.password).get(session_id)
    except UnauthorizedException:
        logger.warning('User unauthorized. Signing out...')
        return signout(request)
    except NotFoundException:
        logger.warning('The requested Session "%s" does not exist', session_id)
        return render(request, '404.html')
    except Exception as inst:
        logger.error('Unexpected exception', exc_info=True)
        messages.error(request,
                       inst.message if inst.message else 'Unexpected error')
        return HttpResponseRedirect(reverse('session_list'))

    data = {'session': session}
    return render(request, 'sessions/session_details.html', data)
Example #23
0
def serveroverload_list(request):

    try:
        serveroverloads = ServerOverload(
            auth_token=request.user.password).get_all()
    except UnauthorizedException:
        logger.warning('User unauthorized. Signing out...')
        return signout(request)
    except Exception as inst:
        logger.error('Unexpected exception', exc_info=True)
        return render(request, '500.html', {'message': inst.message})

    if request.is_ajax():
        return JsonResponse(serveroverloads)

    return render(request, 'serveroverload/serveroverload_list.html',
                  serveroverloads)
Example #24
0
def qos_details(request, qos_id):
    try:
        qos = QoS(auth_token=request.user.password).get(qos_id)
    except UnauthorizedException:
        logger.warning('User unauthorized. Signing out...')
        return signout(request)
    except NotFoundException:
        logger.warning('The requested Test Plan "%s" does not exist', qos_id)
        return render(request, '404.html')
    except Exception as inst:
        logger.error('Unexpected exception', exc_info=True)
        messages.error(request,
                       inst.message if inst.message else 'Unexpected error')
        return HttpResponseRedirect(reverse('qos_list'))

    data = {'qos': qos}
    return render(request, 'qos/qos_details.html', data)
Example #25
0
def qos_new(request):
    form = QoSForm(request.POST or None)
    if form.is_valid():
        try:
            qos_id = QoS(auth_token=request.user.password).create(
                form.cleaned_data)
            return HttpResponseRedirect(
                reverse('qos_details', args=(str(qos_id), )))
        except UnauthorizedException:
            logger.warning('User unauthorized. Signing out...')
            return signout(request)
        except Exception as inst:
            logger.error('Unexpected exception', exc_info=True)
            messages.error(
                request, inst.message if inst.message else 'Unexpected error')
            return HttpResponseRedirect(reverse('qos_list'))

    return render(request, 'qos/qos_new.html', {'form': form})
Example #26
0
def recording_live(request, recording_id):
    try:
        recording = Recording(auth_token=request.user.password).get(recording_id)
    except UnauthorizedException:
        logger.warning('User unauthorized. Signing out...')
        return signout(request)
    except NotFoundException:
        logger.warning('The requested Recording "%s" does not exist', recording_id)
        return render(request, '404.html')
    except Exception as inst:
        logger.error('Unexpected exception', exc_info=True)
        messages.error(request, inst.message if inst.message else 'Unexpected error')
        return HttpResponseRedirect(reverse('recording_list'))

    if 'startedAt' and 'stoppedAt' in recording:
        return HttpResponseRedirect(reverse('recording_details', args=(str(recording_id),)))

    data = {'recording': recording}
    return render(request, 'recording/recording_live.html', data)
Example #27
0
def recording_new(request):
    if not request.POST:
        return HttpResponseRedirect(reverse("recording_list"))

    form = RecordingForm(request.POST)
    if form.is_valid():
        try:
            recording_id = Recording(auth_token=request.user.password).create(form.cleaned_data)
            messages.success(request, "Recording created successfully")
            return HttpResponseRedirect(reverse("recording_live", args=(str(recording_id),)))
        except UnauthorizedException:
            logger.warning("User unauthorized. Signing out...")
            return signout(request)
        except Exception as inst:
            logger.error("Unexpected exception", exc_info=True)
            messages.error(request, inst.message if inst.message else "Unexpected error")
            return HttpResponseRedirect(reverse("recording_list"))
    messages.error(request, "Could not create the recording. Invalid fields.")
    return HttpResponseRedirect(reverse("recording_list"))
Example #28
0
def recording_live(request, recording_id):
    try:
        recording = Recording(auth_token=request.user.password).get(recording_id)
    except UnauthorizedException:
        logger.warning("User unauthorized. Signing out...")
        return signout(request)
    except NotFoundException:
        logger.warning('The requested Recording "%s" does not exist', recording_id)
        return render(request, "404.html")
    except Exception as inst:
        logger.error("Unexpected exception", exc_info=True)
        messages.error(request, inst.message if inst.message else "Unexpected error")
        return HttpResponseRedirect(reverse("recording_list"))

    if "startedAt" and "stoppedAt" in recording:
        return HttpResponseRedirect(reverse("recording_details", args=(str(recording_id),)))

    data = {"recording": recording}
    return render(request, "recording/recording_live.html", data)
Example #29
0
    def get(self, request):

        if 'application/json' in request.META.get('HTTP_ACCEPT'):
            return self._handle_ajax(request)

        try:
            stats = Logs(auth_token=request.user.password).stats()
        except UnauthorizedException:
            logger.warning('User unauthorized. Signing out...')
            return signout(request)
        except Exception as inst:
            logger.error('Unexpected exception', exc_info=True)
            messages.error(request, inst.message if inst.message else 'Unexpected error')
            return HttpResponseRedirect(reverse('dashboard'))

        data = dict()
        data['stats'] = stats

        return render(request, self.template_name, data)
Example #30
0
def testplan_details(request, testplan_id):
    try:
        testplan = TestPlan(auth_token=request.user.password).get(testplan_id)
        # rules = Rule(testplan_id, auth_token=request.user.password).get_all()
    except UnauthorizedException:
        logger.warning('User unauthorized. Signing out...')
        return signout(request)
    except NotFoundException:
        logger.warning('The requested Test Plan "%s" does not exist',
                       testplan_id)
        return render(request, '404.html')
    except Exception as inst:
        logger.error('Unexpected exception', exc_info=True)
        messages.error(request,
                       inst.message if inst.message else 'Unexpected error')
        return HttpResponseRedirect(reverse('testplan_list'))

    data = {'testplan': testplan}
    return render(request, 'testplan/testplan_details.html', data)
Example #31
0
def recording_new(request):
    if not request.POST:
        return HttpResponseRedirect(reverse('recording_list'))

    form = RecordingForm(request.POST)
    if form.is_valid():
        try:
            recording_id = Recording(auth_token=request.user.password).create(form.cleaned_data)
            messages.success(request, 'Recording created successfully')
            return HttpResponseRedirect(reverse('recording_live', args=(str(recording_id),)))
        except UnauthorizedException:
            logger.warning('User unauthorized. Signing out...')
            return signout(request)
        except Exception as inst:
            logger.error('Unexpected exception', exc_info=True)
            messages.error(request, inst.message if inst.message else 'Unexpected error')
            return HttpResponseRedirect(reverse('recording_list'))
    messages.error(request, 'Could not create the recording. Invalid fields.')
    return HttpResponseRedirect(reverse('recording_list'))
Example #32
0
    def get(self, request):

        if 'application/json' in request.META.get('HTTP_ACCEPT'):
            return self._handle_ajax(request)

        try:
            stats = Logs(auth_token=request.user.password).stats()
        except UnauthorizedException:
            logger.warning('User unauthorized. Signing out...')
            return signout(request)
        except Exception as inst:
            logger.error('Unexpected exception', exc_info=True)
            messages.error(
                request, inst.message if inst.message else 'Unexpected error')
            return HttpResponseRedirect(reverse('dashboard'))

        data = dict()
        data['stats'] = stats

        return render(request, self.template_name, data)