#1248 frontend: delete action fix for incomplete builds
Merged 4 years ago by praiskup. Opened 4 years ago by praiskup.
Unknown source related-fixes-to-1213  into  master

@@ -120,9 +120,18 @@

          Creates a dictionary of chroot builddirs for build delete action

          :type build: models.build

          """

-         chroot_builddirs = {'srpm-builds': [build.result_dir]}

+         chroot_builddirs = {}

  

+         # plan to remove sub-dir in srpm-builds/ directory

+         if build.result_dir:

+             chroot_builddirs['srpm-builds'] = [build.result_dir]

+ 

+         # and all chroot sub-dirs

          for build_chroot in build.build_chroots:

+             if not build_chroot.result_dir:

+                 # when we cancel build when the src.rpm (e.g. SCM method) is not

+                 # yet generated

+                 continue

              chroot_builddirs[build_chroot.name] = [build_chroot.result_dir]

  

          return chroot_builddirs

@@ -251,7 +251,7 @@

          self.b2 = models.Build(

              copr=self.c1, copr_dir=self.c1_dir, package=self.p1,

              user=self.u2, submitted_on=10, srpm_url="http://somesrpm",

-             source_status=StatusEnum("importing"), result_dir='bar',

+             source_status=StatusEnum("importing"), result_dir='00000002',

              source_json='{}')

          self.b3 = models.Build(

              copr=self.c2, copr_dir=self.c2_dir, package=self.p2, user=self.u2, submitted_on=10, srpm_url="http://somesrpm", source_status=StatusEnum("importing"), result_dir='bar')

@@ -202,6 +202,80 @@

          with pytest.raises(NoResultFound):

              BuildsLogic.get(self.b4.id).one()

  

+     def test_delete_build_no_resultdir(

+             self, f_users, f_coprs, f_mock_chroots, f_builds, f_db):

+ 

+         self.b1.pkgs = "http://example.com/copr-keygen-1.58-1.fc20.src.rpm"

+         expected_dir = self.b1.result_dir

+         self.db.session.add(self.b1)

+         bc = self.b1_bc[0]

+         bc.result_dir = ''

+         self.db.session.add(bc)

+         self.db.session.commit()

+ 

+         assert len(ActionsLogic.get_many().all()) == 0

+         BuildsLogic.delete_build(self.u1, self.b1)

+         self.db.session.commit()

+ 

+         assert len(ActionsLogic.get_many().all()) == 1

+         action = ActionsLogic.get_many().one()

+         delete_data = json.loads(action.data)

+         # doesn't contain 'fedora-18-x86_64': ['bar']!

+         assert delete_data['chroot_builddirs'] == {'srpm-builds': ['bar']}

+ 

+         with pytest.raises(NoResultFound):

+             BuildsLogic.get(self.b1.id).one()

+ 

+     def test_delete_mulitple_builds_no_resultdir(

+             self, f_users, f_coprs, f_pr_build, f_db):

+ 

+         self.b1.pkgs = "http://example.com/copr-keygen-1.58-1.fc20.src.rpm"

+         expected_dir = self.b1.result_dir

+         self.db.session.add(self.b1)

+         bc = self.b1_bc[0]

+         bc.result_dir = ''

+ 

+         # one more finished build

+         first = True

+         for bchroot in self.b2_bc:

+             if first:

+                 first = False

+                 bchroot.result_dir = ''

+             bchroot.status = StatusEnum('failed')

+             self.db.session.add(bchroot)

+ 

+         self.db.session.add(bc)

+         self.db.session.commit()

+ 

+         assert len(ActionsLogic.get_many().all()) == 0

+         BuildsLogic.delete_multiple_builds(self.u1, [self.b1, self.b2,

+                                                      self.b_pr])

+         self.db.session.commit()

+ 

+         assert len(ActionsLogic.get_many().all()) == 1

+         action = ActionsLogic.get_many().one()

+         delete_data = json.loads(action.data)

+ 

+         # doesn't contain 'fedora-18-x86_64': ['bar']!

+         assert delete_data == {

+             'ownername': 'user1',

+             'projectname': 'foocopr',

+             'project_dirnames': {

+                 'foocopr': {

+                     'srpm-builds': ['bar', '00000002'],

+                     # 'fedora-18-x86_64': ['bar'] # this has result_dir=''

+                 },

+                 'foocopr:PR': {

+                     'srpm-builds': ['0000PR'],

+                     'fedora-17-x86_64': ['0000PR-pr-package'],

+                 }

+             },

+             'build_ids': [1, 2, 5]

+         }

+ 

+         with pytest.raises(NoResultFound):

+             BuildsLogic.get(self.b1.id).one()

+ 

      def test_delete_build_basic(

              self, f_users, f_coprs, f_mock_chroots, f_builds, f_db):

  

@@ -210,7 +210,7 @@

          ended = self.models.Build.query.filter(

              self.models.Build.id == 2).first()

          assert ended.status == 0

-         assert ended.result_dir == "bar"

+         assert ended.result_dir == "00000002"

          assert ended.chroots_ended_on == {'fedora-18-x86_64': 1390866440}

  

  

@@ -253,7 +253,7 @@

              'foocopr': {

                  # they'd usually look like ID-PKGNAME, not 'bar'

                  'fedora-18-x86_64': ['bar', 'bar'],

-                 'srpm-builds': ['bar', 'bar']},

+                 'srpm-builds': ['bar', '00000002']},

              'foocopr:PR': {

                  'fedora-17-x86_64': ['0000PR-pr-package'],

                  'srpm-builds': ['0000PR'],

Do not ask for build directory removal e.g. if the source RPM (source
method) build did not finish, yet. In such case, BuildChroot items do
not have result_dir set, yet.

Relates: #1213

Metadata Update from @praiskup:
- Pull-request tagged with: needs-tests

4 years ago

Metadata Update from @praiskup:
- Request assigned

4 years ago

Metadata Update from @praiskup:
- Pull-request untagged with: needs-tests

4 years ago

rebased onto ab8d20853652c5535eea744ef9883cd43bb68715

4 years ago

rebased onto bfcafe53b013e8e0dc3845da201a5ada771f0354

4 years ago

Thanks for the review, I only added a new tests after the last +1.

rebased onto 1ba7d22

4 years ago

Pull-Request has been merged by praiskup

4 years ago