From 90f921e038c39fd4153529e2351f1b0c90fb4b23 Mon Sep 17 00:00:00 2001 From: Vokhmin Alexey V Date: Thu, 22 May 2014 02:58:13 +0400 Subject: [PATCH] #390: added ability to rerun tests --- .../controllers/build_lists_controller.js.erb | 12 +++++---- app/controllers/api/v1/jobs_controller.rb | 4 ++- .../projects/build_lists_controller.rb | 26 ++++++++++++------- app/models/ability.rb | 2 +- app/models/build_list.rb | 19 ++++++++++++-- app/views/projects/build_lists/show.html.haml | 7 +++++ config/locales/models/build_list.en.yml | 5 ++++ config/locales/models/build_list.ru.yml | 5 ++++ config/routes.rb | 1 + lib/abf_worker/rpm_worker_observer.rb | 8 +++--- 10 files changed, 67 insertions(+), 22 deletions(-) diff --git a/app/assets/javascripts/angularjs/controllers/build_lists_controller.js.erb b/app/assets/javascripts/angularjs/controllers/build_lists_controller.js.erb index f9d6da334..95defadd2 100644 --- a/app/assets/javascripts/angularjs/controllers/build_lists_controller.js.erb +++ b/app/assets/javascripts/angularjs/controllers/build_lists_controller.js.erb @@ -9,11 +9,13 @@ RosaABF.controller('BuildListsController', ['$scope', '$http', '$location', '$ti $scope.opened = {}; $scope.map_priorities = { - <%=BuildList::WAITING_FOR_RESPONSE%>: 11, - <%=BuildList::BUILD_PENDING%>: 10, - <%=BuildList::BUILD_CANCELING%>: 9, - <%=BuildList::BUILD_CANCELED%>: 8, - <%=BuildList::BUILD_STARTED%>: 7, + <%=BuildList::WAITING_FOR_RESPONSE%>: 13, + <%=BuildList::BUILD_PENDING%>: 12, + <%=BuildList::RERUN_TESTS%>: 11, + <%=BuildList::BUILD_CANCELING%>: 10, + <%=BuildList::BUILD_CANCELED%>: 9, + <%=BuildList::BUILD_STARTED%>: 8, + <%=BuildList::RERUNINNG_TESTS%>: 7, <%=BuildList::BUILD_PUBLISH%>: 6, <%=BuildList::BUILD_PUBLISHED%>: 5, <%=BuildList::BUILD_ERROR%>: 4, diff --git a/app/controllers/api/v1/jobs_controller.rb b/app/controllers/api/v1/jobs_controller.rb index e634efc08..a40714285 100644 --- a/app/controllers/api/v1/jobs_controller.rb +++ b/app/controllers/api/v1/jobs_controller.rb @@ -14,7 +14,9 @@ class Api::V1::JobsController < Api::V1::BaseController else platform_ids = Platform.where(name: params[:platforms].split(',')).pluck(:id) if params[:platforms].present? arch_ids = Arch.where(name: params[:arches].split(',')).pluck(:id) if params[:arches].present? - build_lists = BuildList.for_status(BuildList::BUILD_PENDING).scoped_to_arch(arch_ids). + build_lists = BuildList.scoped_to_arch(arch_ids). + for_status([BuildList::BUILD_PENDING, BuildList::RERUN_TESTS]). + scoped_to_arch(arch_ids). oldest.order(:created_at) build_lists = build_lists.for_platform(platform_ids) if platform_ids.present? diff --git a/app/controllers/projects/build_lists_controller.rb b/app/controllers/projects/build_lists_controller.rb index 96254d147..216ca58ba 100644 --- a/app/controllers/projects/build_lists_controller.rb +++ b/app/controllers/projects/build_lists_controller.rb @@ -119,30 +119,29 @@ class Projects::BuildListsController < Projects::BaseController end @build_list.publisher = current_user - message = @build_list.publish ? 'success' : 'fail' - redirect_to :back, notice: t("layout.build_lists.publish_#{message}") + do_and_back(:publish, 'publish_') end def publish_into_testing @build_list.publisher = current_user - message = @build_list.publish_into_testing ? 'success' : 'fail' - redirect_to :back, notice: t("layout.build_lists.publish_#{message}") + do_and_back(:publish_into_testing, 'publish_') + end + + def rerun_tests + do_and_back(:rerun_tests, 'rerun_tests_') end def reject_publish @build_list.publisher = current_user - message = @build_list.reject_publish ? 'success' : 'fail' - redirect_to :back, notice: t("layout.build_lists.reject_publish_#{message}") + do_and_back(:reject_publish, 'reject_publish_') end def create_container - message = @build_list.publish_container ? 'success' : 'fail' - redirect_to :back, notice: t("layout.build_lists.create_container_#{message}") + do_and_back(:publish_container, 'create_container_') end def cancel - message = @build_list.cancel ? 'will_be_canceled' : 'cancel_fail' - redirect_to :back, notice: t("layout.build_lists.#{message}") + do_and_back(:cancel, nil, 'will_be_canceled', 'cancel_fail') end def log @@ -184,6 +183,13 @@ class Projects::BuildListsController < Projects::BaseController protected + def do_and_back(action, prefix, success = 'success', fail = 'fail') + result = @build_list.send(action) + message = result ? success : fail + flash[result ? :notice : :error] = t("layout.build_lists.#{prefix}#{message}") + redirect_to :back + end + def find_build_list @build_list = BuildList.find(params[:id]) end diff --git a/app/models/ability.rb b/app/models/ability.rb index f3c01f2d5..38eadba95 100644 --- a/app/models/ability.rb +++ b/app/models/ability.rb @@ -87,7 +87,7 @@ class Ability can([:read, :log, :everything, :list], BuildList, read_relations_with_projects('build_lists')) {|build_list| can? :read, build_list.project} can(:publish_into_testing, BuildList) { |build_list| can?(:create, build_list) && build_list.save_to_platform.main? } - can(:create, BuildList) {|build_list| + can([:create, :rerun_tests], BuildList) {|build_list| build_list.project.is_package && can?(:write, build_list.project) && (build_list.build_for_platform.blank? || can?(:show, build_list.build_for_platform)) diff --git a/app/models/build_list.rb b/app/models/build_list.rb index 5f57427ca..7c06b3598 100644 --- a/app/models/build_list.rb +++ b/app/models/build_list.rb @@ -86,6 +86,8 @@ class BuildList < ActiveRecord::Base %w(BUILD_CANCELED 5000), %w(WAITING_FOR_RESPONSE 4000), %w(BUILD_PENDING 2000), + %w(RERUN_TESTS 2500), + %w(RERUNINNG_TESTS 2550), %w(BUILD_PUBLISHED 6000), %w(BUILD_PUBLISH 7000), %w(FAILED_PUBLISH 8000), @@ -156,9 +158,10 @@ class BuildList < ActiveRecord::Base state_machine :status, initial: :waiting_for_response do - after_transition(on: :place_build) do |build_list, transition| + after_transition(on: [:place_build, :rerun_tests]) do |build_list, transition| build_list.add_job_to_abf_worker_queue if build_list.external_nodes.blank? end + after_transition on: :published, do: [:set_version_and_tag, :actualize_packages] after_transition on: :publish, do: :set_publisher @@ -177,18 +180,25 @@ class BuildList < ActiveRecord::Base transition waiting_for_response: :build_pending end + event :rerun_tests do + transition %i(success tests_failed) => :rerun_tests + end + event :start_build do transition build_pending: :build_started + transition rerun_tests: :reruninng_tests end event :cancel do transition [:build_pending, :build_started] => :build_canceling + transition [:rerun_tests, :reruninng_tests] => :tests_failed end # build_canceling: :build_canceled - canceling from UI # build_started: :build_canceled - canceling from worker by time-out (time_living has been expired) event :build_canceled do transition [:build_canceling, :build_started, :build_pending] => :build_canceled + transition [:rerun_tests, :reruninng_tests] => :tests_failed end event :published do @@ -245,12 +255,13 @@ class BuildList < ActiveRecord::Base # ===== into testing - end event :build_success do - transition [:build_started, :build_canceling, :build_canceled] => :success + transition [:build_started, :build_canceling, :build_canceled, :reruninng_tests] => :success end [:build_error, :tests_failed].each do |kind| event kind do transition [:build_started, :build_canceling, :build_canceled] => kind + transition reruninng_tests: :tests_failed end end @@ -525,6 +536,10 @@ class BuildList < ActiveRecord::Base 'EXTRA_BUILD_SRC_RPM_OPTIONS' => extra_params['build_src_rpm'], 'EXTRA_BUILD_RPM_OPTIONS' => extra_params['build_rpm'] } + cmd_params.merge!( + 'RERUN_TESTS' => true, + 'PACKAGES' => packages.pluck(:sha1).compact * ' ' + ) if rerun_tests? if use_cached_chroot? sha1 = build_for_platform.cached_chroot(arch.name) cmd_params.merge!('CACHED_CHROOT_SHA1' => sha1) if sha1.present? diff --git a/app/views/projects/build_lists/show.html.haml b/app/views/projects/build_lists/show.html.haml index fcf3241d1..9b9420b4f 100644 --- a/app/views/projects/build_lists/show.html.haml +++ b/app/views/projects/build_lists/show.html.haml @@ -181,6 +181,13 @@ data: { confirm: t("layout.publish_again_warning") }, name: 'publish', 'ng-show' => "build_list.can_publish && build_list.status == #{BuildList::BUILD_PUBLISHED}" + - if can? :rerun_tests, @build_list + = link_to t('layout.build_lists.rerun_tests'), + rerun_tests_build_list_path(@build_list), + method: :put, + data: { confirm: t("layout.confirm") }, + class: 'button', + 'ng-show' => "build_list.status == #{BuildList::TESTS_FAILED} || build_list.status == #{BuildList::SUCCESS}" = submit_tag t("layout.publish"), data: { confirm: t('layout.build_lists.tests_failed') }, name: 'publish', 'ng-show' => "build_list.can_publish && build_list.can_publish_in_future && build_list.extra_build_lists_published && build_list.status == #{BuildList::TESTS_FAILED}" diff --git a/config/locales/models/build_list.en.yml b/config/locales/models/build_list.en.yml index da920d984..5a12c388a 100644 --- a/config/locales/models/build_list.en.yml +++ b/config/locales/models/build_list.en.yml @@ -81,6 +81,9 @@ en: cancel: Cancel build will_be_canceled: 'Build will be canceled...' creating: 'creating...' + rerun_tests: Rerun tests + rerun_tests_success: 'Build is queued for rerun tests' + rerun_tests_fail: 'Errors during rerun tests!' create_container_success: 'Container is queued for creating' create_container_fail: 'Errors during container creating!' publish_success: 'Build is queued for publishing' @@ -143,6 +146,8 @@ en: statuses: build_lists: All + rerun_tests: Rerun tests + reruninng_tests: Build is being rerun tests build_error: Build error build_published: Build has been published tests_failed: Tests failed diff --git a/config/locales/models/build_list.ru.yml b/config/locales/models/build_list.ru.yml index 4ea7165e5..a3bb25e56 100644 --- a/config/locales/models/build_list.ru.yml +++ b/config/locales/models/build_list.ru.yml @@ -80,6 +80,9 @@ ru: cancel: Отменить сборку will_be_canceled: 'Сборка будет отменена...' creating: 'создается...' + rerun_tests: Перезапустить тесты + rerun_tests_success: 'Сборка поставлена в очередь на перезапуск тестов' + rerun_tests_fail: 'При перезапуске тестов произошла ошибка!' create_container_success: 'Контейнер поставлен в очередь на создание' create_container_fail: 'При создании контейнера произошла ошибка!' cancel_success: 'Сборка отменена.' @@ -142,6 +145,8 @@ ru: statuses: build_lists: Всего + rerun_tests: перезапуск тестов + reruninng_tests: тесты перезапускаются build_error: ошибка сборки build_published: опубликован tests_failed: тесты не прошли diff --git a/config/routes.rb b/config/routes.rb index 7ef5bdf0c..bcd78fd53 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -276,6 +276,7 @@ Rosa::Application.routes.draw do member do put :cancel put :create_container + put :rerun_tests get :log patch :publish put :reject_publish diff --git a/lib/abf_worker/rpm_worker_observer.rb b/lib/abf_worker/rpm_worker_observer.rb index c97349ade..0fb71ef78 100644 --- a/lib/abf_worker/rpm_worker_observer.rb +++ b/lib/abf_worker/rpm_worker_observer.rb @@ -18,6 +18,8 @@ module AbfWorker item = find_or_create_item fill_container_data if status != STARTED + reruninng_tests = subject.reruninng_tests? + case status when COMPLETED subject.build_success @@ -28,17 +30,17 @@ module AbfWorker end when FAILED subject.build_error - item.update_attributes({status: BuildList::BUILD_ERROR}) + item.update_attributes({status: BuildList::BUILD_ERROR}) unless reruninng_tests when STARTED subject.start_build when CANCELED subject.build_canceled - item.update_attributes({status: BuildList::BUILD_CANCELED}) + item.update_attributes({status: BuildList::BUILD_CANCELED}) unless reruninng_tests when TESTS_FAILED subject.tests_failed end - if [TESTS_FAILED, COMPLETED].include?(status) + if !reruninng_tests && [TESTS_FAILED, COMPLETED].include?(status) item.update_attributes({status: BuildList::SUCCESS}) subject.publish_container if subject.auto_create_container? end