Exemplo n.º 1
0
def overview_get_data():
    columns = get_table_columns()
    data = []
    blue_teams = Team.get_all_blue_teams()

    if len(blue_teams) > 0:
        current_score_row_data = {'': 'Current Score'}
        current_place_row_data = {'': 'Current Place'}
        for blue_team in blue_teams:
            current_score_row_data[blue_team.name] = blue_team.current_score
            current_place_row_data[blue_team.name] = blue_team.place
        data.append(current_score_row_data)
        data.append(current_place_row_data)

        for service in blue_teams[0].services:
            service_row_data = {'': service.name}
            for blue_team in blue_teams:
                service = session.query(Service).filter(
                    Service.name == service.name).filter(
                        Service.team == blue_team).first()
                service_text = service.host
                if str(service.port) != '0':
                    service_text += ':' + str(service.port)
                service_data = {
                    'result': str(service.last_check_result()),
                    'host_info': service_text
                }
                service_row_data[blue_team.name] = service_data
            data.append(service_row_data)

        return json.dumps({'columns': columns, 'data': data})
    else:
        return '{}'
Exemplo n.º 2
0
class TestIntegration(object):
    def test_overall(self):
        blue_teams = Team.get_all_blue_teams()
        assert len(blue_teams) == 10, \
            "Incorrect number of blue teams"

    def test_round_num(self):
        assert Round.get_last_round_num() == NUM_OVERALL_ROUNDS, \
            "Expecting only {0} of rounds to have run...".format(NUM_OVERALL_ROUNDS)

    @pytest.mark.parametrize("blue_team", Team.get_all_blue_teams())
    def test_blue_teams(self, blue_team):
        assert len(blue_team.services) == NUM_TESTBED_SERVICES, \
            "Invalid number of services enabled per team {0}".format(blue_team.name)
        assert blue_team.current_score == (SERVICE_TOTAL_POINTS_PER_ROUND * NUM_OVERALL_ROUNDS), \
            "Invalid number of overall points per team {0}".format(blue_team.name)

    @pytest.mark.parametrize("service", session.query(Service).all())
    def test_services(self, service):
        assert service.last_check_result() is True, \
            "{0} service failed on {1}".format(service.name, service.team.name)
        assert service.percent_earned == 100

    @pytest.mark.parametrize("check", session.query(Check).all())
    def test_checks(self, check):
        assert check.result is True, \
            "{0} on round {1} failed for team {2}\nReason: {3}\nOutput: {4}".format(check.service.name, check.round.number, check.service.team.name, check.reason, check.output)
Exemplo n.º 3
0
def home():
    results = Team.get_all_rounds_results()
    team_data = {}
    # We start at one because that's how javascript expects the team_data
    current_index = 1
    for name in sorted(results['scores'].keys()):
        scores = results['scores'][name]
        rgb_color = results['rgb_colors'][name]
        team_data[current_index] = {
            "label": name,
            "data": scores,
            "color": rgb_color
        }
        current_index += 1

    team_labels = []
    team_scores = []
    scores_colors = []
    for blue_team in Team.get_all_blue_teams():
        team_labels.append(blue_team.name)
        team_scores.append(blue_team.current_score)
        scores_colors.append(blue_team.rgb_color)

    return render_template('scoreboard.html',
                           round_labels=results['rounds'],
                           team_data=team_data,
                           team_labels=team_labels,
                           team_scores=team_scores,
                           scores_colors=scores_colors)
Exemplo n.º 4
0
def get_table_columns():
    blue_teams = Team.get_all_blue_teams()
    columns = []
    columns.append({"title": "", "data": ""})
    for team in blue_teams:
        columns.append({"title": team.name, "data": team.name})
    return columns
Exemplo n.º 5
0
def get_table_columns():
    blue_teams = Team.get_all_blue_teams()
    columns = []
    columns.append({'title': '', 'data': ''})
    for team in blue_teams:
        columns.append({'title': team.name, 'data': team.name})
    return columns
Exemplo n.º 6
0
def manage():
    if current_user.is_white_team:
        users = session.query(User).with_entities(User.id, User.username).all()
        teams = session.query(Team).with_entities(Team.id, Team.name).all()
        blue_teams = Team.get_all_blue_teams()
        return render_template('admin/manage.html', users=sorted(users, key=itemgetter(0)), teams=teams, blue_teams=blue_teams)
    else:
        return redirect(url_for('auth.unauthorized'))
Exemplo n.º 7
0
def progress():
    if current_user.is_white_team:
        teams = Team.query.with_entities(Team.id, Team.name).all()
        blue_teams = Team.get_all_blue_teams()
        return render_template('admin/progress.html',
                               teams=teams,
                               blue_teams=blue_teams)
    else:
        return redirect(url_for('auth.unauthorized'))
Exemplo n.º 8
0
 def setup(self):
     super(TestGoodSetup, self).setup()
     competition = Competition(self.setup)
     competition.save(self.session)
     self.blue_teams = Team.get_all_blue_teams()
     self.blue_team = self.blue_teams[0]
     self.service = self.blue_team.services[0]
     self.account = self.service.accounts[0]
     self.environment = self.service.environments[0]
     self.property = self.environment.properties[0]
Exemplo n.º 9
0
def service(id):
    if current_user.is_white_team:
        service = session.query(Service).get(id)
        blue_teams = Team.get_all_blue_teams()
        if service is None:
            return redirect(url_for('auth.unauthorized'))

        return render_template('admin/service.html', service=service, blue_teams=blue_teams)
    else:
        return redirect(url_for('auth.unauthorized'))
Exemplo n.º 10
0
def team(id):
    if current_user.is_white_team:
        team = Team.query.get(id)
        blue_teams = Team.get_all_blue_teams()
        if team is None:
            return redirect(url_for('auth.unauthorized'))

        return render_template('admin/team.html',
                               team=team,
                               blue_teams=blue_teams)
    else:
        return redirect(url_for('auth.unauthorized'))
Exemplo n.º 11
0
def settings():
    if current_user.is_white_team:
        about_page_content = Setting.get_setting('about_page_content').value
        welcome_page_content = Setting.get_setting(
            'welcome_page_content').value
        blue_teams = Team.get_all_blue_teams()
        return render_template('admin/settings.html',
                               blue_teams=blue_teams,
                               about_page_content=about_page_content,
                               welcome_page_content=welcome_page_content)
    else:
        return redirect(url_for('auth.unauthorized'))
Exemplo n.º 12
0
    def get_queue_stats():
        finished_queue_facts = []

        queues_facts = {}

        all_services = session.query(Service).all()
        for service in all_services:
            if service.worker_queue not in queues_facts:
                queues_facts[service.worker_queue] = {
                    "name": service.worker_queue,
                    "workers": [],
                    "services_running": {}
                }
            if service.team.name not in queues_facts[
                    service.worker_queue]['services_running']:
                queues_facts[service.worker_queue]['services_running'][
                    service.team.name] = []
            queues_facts[service.worker_queue]['services_running'][
                service.team.name].append(service.name)

        for queue_name, queue_facts in queues_facts.items():
            # If all of the services are listed for this specific worker, let's just alias it as 'All'
            queue_services_total_running = 0
            for team_name, team_services in queues_facts[
                    service.worker_queue]['services_running'].items():
                queue_services_total_running += len(team_services)
            if queue_services_total_running == len(all_services):
                queues_facts[service.worker_queue]['services_running'] = 'All'
            else:
                blue_teams = Team.get_all_blue_teams()
                for blue_team in blue_teams:
                    if blue_team.name in queue_facts[
                            'services_running'] and len(
                                blue_team.services) == len(
                                    queue_facts['services_running'][
                                        blue_team.name]):
                        # Summarize it for each team if the worker runs all services
                        queues_facts[service.worker_queue]['services_running'][
                            blue_team.name] = 'ALL'

        for queue_name, queue_facts in queues_facts.items():
            # Get which workers are assigned to which queues
            active_queues = celery_app.control.inspect().active_queues()
            # If we don't have any queues, we also have no workers
            if active_queues is not None:
                for worker_name, queues in active_queues.items():
                    if queue_name in [k['name'] for k in queues]:
                        queue_facts['workers'].append(worker_name)

        for queue_name, queue_facts in queues_facts.items():
            finished_queue_facts.append(queue_facts)
        return finished_queue_facts
Exemplo n.º 13
0
def permissions():
    if current_user.is_white_team:
        blue_teams = Team.get_all_blue_teams()
        return render_template(
            'admin/permissions.html',
            blue_teams=blue_teams,
            blue_team_update_hostname=Setting.get_setting('blue_team_update_hostname').value,
            blue_team_update_port=Setting.get_setting('blue_team_update_port').value,
            blue_team_update_account_usernames=Setting.get_setting('blue_team_update_account_usernames').value,
            blue_team_update_account_passwords=Setting.get_setting('blue_team_update_account_passwords').value,
        )
    else:
        return redirect(url_for('auth.unauthorized'))
Exemplo n.º 14
0
def scoreboard_get_bar_data():
    team_data = {}
    team_labels = []
    team_scores = []
    scores_colors = []
    for blue_team in Team.get_all_blue_teams():
        team_labels.append(blue_team.name)
        team_scores.append(blue_team.current_score)
        scores_colors.append(blue_team.rgb_color)

    team_data['labels'] = team_labels
    team_data['scores'] = team_scores
    team_data['colors'] = scores_colors
    return jsonify(team_data)
Exemplo n.º 15
0
def overview_get_data():
    # columns = get_table_columns()
    data = []
    blue_teams = Team.get_all_blue_teams()
    last_round = Round.get_last_round_num()

    current_scores = ["Current Score"]
    current_places = ["Current Place"]
    service_ratios = ["Up/Down Ratio"]

    if len(blue_teams) > 0:
        for blue_team in blue_teams:
            num_up_services = (session.query(
                Service.team_id, ).join(Check).join(Round).filter(
                    Check.result.is_(True)).filter(
                        Service.team_id == blue_team.id).filter(
                            Round.number == last_round).count())

            num_down_services = (session.query(
                Service.team_id, ).join(Check).join(Round).filter(
                    Check.result.is_(False)).filter(
                        Service.team_id == blue_team.id).filter(
                            Round.number == last_round).count())

            current_scores.append(str(blue_team.current_score))
            current_places.append(str(blue_team.place))
            service_ratios.append("{0} / {1}".format(num_up_services,
                                                     num_down_services))
        data.append(current_scores)
        data.append(current_places)
        data.append(service_ratios)

        services = []
        services.append([
            service[0] for service in session.query(Service.name).distinct(
                Service.name).group_by(Service.name).all()
        ])
        for blue_team in blue_teams:
            checks = (session.query(Check.result).join(Service).filter(
                Check.round_id == last_round).filter(
                    Service.team_id == blue_team.id).order_by(
                        Service.name).all())
            services.append([check[0] for check in checks])
        data += list(
            zip(*services))  # zip these to get the right datatables format

        return json.dumps({"data": data})
    else:
        return "{}"
Exemplo n.º 16
0
 def rank(self):
     services = []
     for blue_team in Team.get_all_blue_teams():
         for service in blue_team.services:
             if self.name == service.name:
                 services.append(service)
     sorted_services = sorted(services, key=lambda service: service.score_earned, reverse=True)
     place = 0
     previous_place = 1
     for service in sorted_services:
         if not self.score_earned == service.score_earned:
             previous_place += 1
         if self.id == service.id:
             place = previous_place
     return place
Exemplo n.º 17
0
def settings():
    if current_user.is_white_team:
        about_page_content = Setting.get_setting('about_page_content').value
        welcome_page_content = Setting.get_setting('welcome_page_content').value
        round_time_sleep = Setting.get_setting('round_time_sleep').value
        worker_refresh_time = Setting.get_setting('worker_refresh_time').value
        blue_teams = Team.get_all_blue_teams()
        return render_template(
            'admin/settings.html',
            blue_teams=blue_teams,
            round_time_sleep=round_time_sleep,
            worker_refresh_time=worker_refresh_time,
            about_page_content=about_page_content,
            welcome_page_content=welcome_page_content
        )
    else:
        return redirect(url_for('auth.unauthorized'))
Exemplo n.º 18
0
def settings():
    if current_user.is_white_team:
        about_page_content = Setting.get_setting("about_page_content").value
        welcome_page_content = Setting.get_setting(
            "welcome_page_content").value
        target_round_time = Setting.get_setting("target_round_time").value
        worker_refresh_time = Setting.get_setting("worker_refresh_time").value
        blue_teams = Team.get_all_blue_teams()
        return render_template(
            "admin/settings.html",
            blue_teams=blue_teams,
            target_round_time=target_round_time,
            worker_refresh_time=worker_refresh_time,
            about_page_content=about_page_content,
            welcome_page_content=welcome_page_content,
        )
    else:
        return redirect(url_for("auth.unauthorized"))
Exemplo n.º 19
0
def permissions():
    if current_user.is_white_team:
        blue_teams = Team.get_all_blue_teams()
        return render_template(
            "admin/permissions.html",
            blue_teams=blue_teams,
            blue_team_update_hostname=Setting.get_setting(
                "blue_team_update_hostname").value,
            blue_team_update_port=Setting.get_setting(
                "blue_team_update_port").value,
            blue_team_update_account_usernames=Setting.get_setting(
                "blue_team_update_account_usernames").value,
            blue_team_update_account_passwords=Setting.get_setting(
                "blue_team_update_account_passwords").value,
            blue_team_view_check_output=Setting.get_setting(
                "blue_team_view_check_output").value,
        )
    else:
        return redirect(url_for("auth.unauthorized"))
Exemplo n.º 20
0
 def test_overall(self):
     blue_teams = Team.get_all_blue_teams()
     assert len(blue_teams) == NUM_OVERALL_TEAMS, \
         "Incorrect number of blue teams"
Exemplo n.º 21
0
def status():
    if current_user.is_white_team:
        blue_teams = Team.get_all_blue_teams()
        return render_template('admin/status.html', blue_teams=blue_teams)
    else:
        return redirect(url_for('auth.unauthorized'))
Exemplo n.º 22
0
def home():
    return render_template("overview.html", teams=Team.get_all_blue_teams())
Exemplo n.º 23
0
 def test_overall(self):
     blue_teams = Team.get_all_blue_teams()
     assert len(blue_teams) == 10, \
         "Incorrect number of blue teams"
Exemplo n.º 24
0
    def get_worker_stats():
        finished_worker_facts = []
        worker_facts = {}

        # Get which workers are assigned to which queues
        active_queues = celery_app.control.inspect().active_queues()
        # If we don't have any queues, we also have no workers
        if active_queues is None:
            return finished_worker_facts

        for worker_name, queues in active_queues.items():
            queue_names = []
            for queue in queues:
                queue_names.append(queue['name'])
            worker_facts[worker_name] = {
                'worker_queues': queue_names,
            }

        # Get worker stats about completed tasks and such
        active_stats = celery_app.control.inspect().stats()
        for worker_name, stats in active_stats.items():
            completed_tasks = 0
            if 'execute_command' in stats['total']:
                completed_tasks = stats['total']['execute_command']
            worker_facts[worker_name]['completed_tasks'] = completed_tasks
            worker_facts[worker_name]['num_threads'] = stats['pool'][
                'max-concurrency']

        # Get worker stats about currently running tasks
        active_tasks_stats = celery_app.control.inspect().active()
        for worker_name, stats in active_tasks_stats.items():
            worker_facts[worker_name]['running_tasks'] = len(stats)

        # Produce list of Service checks this worker will run
        all_services = session.query(Service).all()
        for worker_name, facts in worker_facts.items():
            facts['services_running'] = []
            services_running = {}
            for service in all_services:
                if service.worker_queue in facts['worker_queues']:
                    if service.team.name not in services_running:
                        services_running[service.team.name] = []
                    services_running[service.team.name].append(service.name)
            # If all of the services are listed for this specific worker, let's just alias it as 'All'
            worker_services_total_running = 0
            for team_name, team_services in services_running.items():
                worker_services_total_running += len(team_services)
            if worker_services_total_running == len(all_services):
                facts['services_running'] = 'All'
            else:
                facts['services_running'] = services_running
                blue_teams = Team.get_all_blue_teams()
                for blue_team in blue_teams:
                    if blue_team.name in services_running and len(
                            blue_team.services) == len(
                                services_running[blue_team.name]):
                        # Summarize it for each team if the worker runs all services
                        facts['services_running'][blue_team.name] = 'ALL'

            # Instead of an empty string in the table, let's tell them None
            if len(facts['services_running']) == 0:
                facts['services_running'] = 'None'
            # Clean up services_running

            finished_worker_facts.append({
                'worker_name':
                worker_name,
                'services_running':
                facts['services_running'],
                'num_threads':
                facts['num_threads'],
                'completed_tasks':
                facts['completed_tasks'],
                'running_tasks':
                facts['running_tasks'],
                'worker_queues':
                facts['worker_queues']
            })
        return finished_worker_facts
Exemplo n.º 25
0
def queues():
    if current_user.is_white_team:
        blue_teams = Team.get_all_blue_teams()
        return render_template("admin/queues.html", blue_teams=blue_teams)
    else:
        return redirect(url_for("auth.unauthorized"))