]> git.apps.os.sepia.ceph.com Git - teuthology.git/commitdiff
Fix arguments to schedule_fail() again
authorDan Mick <dan.mick@redhat.com>
Wed, 6 Jul 2016 02:12:16 +0000 (19:12 -0700)
committerDan Mick <dan.mick@redhat.com>
Wed, 6 Jul 2016 17:36:11 +0000 (10:36 -0700)
Signed-off-by: Dan Mick <dan.mick@redhat.com>
teuthology/suite/run.py
teuthology/suite/test/test_run_.py

index 1b3529961a215bbe13140f8d109c1e5d6ec7ee8d..cb86ff1b9f809ff3af14156b2423d47362a2e210 100644 (file)
@@ -114,8 +114,8 @@ class Run(object):
             )
             if not kernel_hash:
                 util.schedule_fail(
-                    message="Kernel branch '{branch}' not found".format(
-                        branch=self.args.kernel_branch), name=self.name
+                    "Kernel branch '{branch}' not found".format(
+                     branch=self.args.kernel_branch), name
                 )
         if kernel_hash:
             log.info("kernel sha1: {hash}".format(hash=kernel_hash))
@@ -442,10 +442,8 @@ class Run(object):
                 new_sha1 = \
                     util.find_git_parent('ceph', self.base_config.sha1)
                 if new_sha1 is None:
-                    util.schedule_fail(
-                        name, message='Backtrack for --newest failed'
-                    )
-                # rebuild the base config to resubstitute sha1
+                    util.schedule_fail('Backtrack for --newest failed', name)
+                 # rebuild the base config to resubstitute sha1
                 self.config_input['ceph_hash'] = new_sha1
                 self.base_config = self.build_base_config()
                 backtrack += 1
@@ -458,7 +456,7 @@ class Run(object):
             if self.args.newest:
                 util.schedule_fail(
                     'Exceeded %d backtracks; raise --newest value' % limit,
-                    name=name,
+                    name,
                 )
 
         if self.args.dry_run:
index 7bd99b567c8c98b86772a67e558e14e09471d251..abbd0826b27ea6f74967a31bb162a8ed4d93cd31 100644 (file)
@@ -111,3 +111,195 @@ class TestRun(object):
         self.args.ceph_sha1 = 'ceph_hash_dne'
         with pytest.raises(ScheduleFailError):
             self.klass(self.args)
+
+class TestScheduleSuite(object):
+    klass = run.Run
+
+    def setup(self):
+        self.args_dict = dict(
+            suite='suite',
+            suite_dir='suite_dir',
+            suite_branch='master',
+            ceph_branch='ceph_branch',
+            ceph_sha1='ceph_sha1',
+            teuthology_branch='master',
+            kernel_branch=None,
+            kernel_flavor='kernel_flavor',
+            distro='ubuntu',
+            machine_type='machine_type',
+            base_yaml_paths=list(),
+        )
+        self.args = YamlConfig.from_dict(self.args_dict)
+
+    @patch('teuthology.suite.run.Run.schedule_jobs')
+    @patch('teuthology.suite.util.has_packages_for_distro')
+    @patch('teuthology.suite.util.get_package_versions')
+    @patch('teuthology.suite.util.get_install_task_flavor')
+    @patch('__builtin__.file')
+    @patch('teuthology.suite.run.build_matrix')
+    @patch('teuthology.suite.util.git_ls_remote')
+    @patch('teuthology.suite.util.package_version_for_hash')
+    @patch('teuthology.suite.util.git_validate_sha1')
+    def test_successful_schedule(
+        self,
+        m_git_validate_sha1,
+        m_package_version_for_hash,
+        m_git_ls_remote,
+        m_build_matrix,
+        m_file,
+        m_get_install_task_flavor,
+        m_get_package_versions,
+        m_has_packages_for_distro,
+        m_schedule_jobs,
+    ):
+        m_git_validate_sha1.return_value = self.args.ceph_sha1
+        m_package_version_for_hash.return_value = 'ceph_version'
+        m_git_ls_remote.return_value = 'suite_hash'
+        build_matrix_desc = 'desc'
+        build_matrix_frags = ['frag1.yml', 'frag2.yml']
+        build_matrix_output = [
+            (build_matrix_desc, build_matrix_frags),
+        ]
+        m_build_matrix.return_value = build_matrix_output
+        frag1_read_output = 'field1: val1'
+        frag2_read_output = 'field2: val2'
+        m_file.side_effect = [
+            StringIO(frag1_read_output),
+            StringIO(frag2_read_output),
+        ]
+        m_get_install_task_flavor.return_value = 'basic'
+        m_get_package_versions.return_value = dict()
+        m_has_packages_for_distro.return_value = True
+        # schedule_jobs() is just neutered; check calls below
+
+        self.args.newest = 0
+        runobj = self.klass(self.args)
+        runobj.base_args = list()
+        count = runobj.schedule_suite()
+        assert(count == 1)
+        m_has_packages_for_distro.assert_has_calls(
+            [call('ceph_sha1', 'ubuntu', 'basic', {})],
+        )
+        frags = (frag1_read_output, frag2_read_output)
+        expected_job = dict(
+            yaml = yaml.load('\n'.join(frags)),
+            sha1 = 'ceph_sha1',
+            args = [
+                '--description',
+                os.path.join(self.args.suite, build_matrix_desc),
+                '--',
+                ANY,
+                build_matrix_frags[0],
+                build_matrix_frags[1],
+            ],
+            desc=os.path.join(self.args.suite, build_matrix_desc),
+        )
+
+        m_schedule_jobs.assert_has_calls(
+            [call([], [expected_job], runobj.name)],
+        )
+
+
+    @patch('teuthology.suite.util.find_git_parent')
+    @patch('teuthology.suite.run.Run.schedule_jobs')
+    @patch('teuthology.suite.util.has_packages_for_distro')
+    @patch('teuthology.suite.util.get_package_versions')
+    @patch('teuthology.suite.util.get_install_task_flavor')
+    @patch('__builtin__.file')
+    @patch('teuthology.suite.run.build_matrix')
+    @patch('teuthology.suite.util.git_ls_remote')
+    @patch('teuthology.suite.util.package_version_for_hash')
+    @patch('teuthology.suite.util.git_validate_sha1')
+    def test_newest_failure(
+        self,
+        m_git_validate_sha1,
+        m_package_version_for_hash,
+        m_git_ls_remote,
+        m_build_matrix,
+        m_file,
+        m_get_install_task_flavor,
+        m_get_package_versions,
+        m_has_packages_for_distro,
+        m_schedule_jobs,
+        m_find_git_parent,
+    ):
+        m_git_validate_sha1.return_value = self.args.ceph_sha1
+        m_package_version_for_hash.return_value = 'ceph_version'
+        m_git_ls_remote.return_value = 'suite_hash'
+        build_matrix_desc = 'desc'
+        build_matrix_frags = ['frag.yml']
+        build_matrix_output = [
+            (build_matrix_desc, build_matrix_frags),
+        ]
+        m_build_matrix.return_value = build_matrix_output
+        m_file.side_effect = [StringIO('field: val\n') for i in xrange(11)]
+        m_get_install_task_flavor.return_value = 'basic'
+        m_get_package_versions.return_value = dict()
+        m_has_packages_for_distro.side_effect = [
+            False for i in xrange(11)
+        ]
+
+        m_find_git_parent.side_effect = lambda proj, sha1: sha1 + '^'
+
+        self.args.newest = 10
+        runobj = self.klass(self.args)
+        runobj.base_args = list()
+        with pytest.raises(ScheduleFailError) as exc:
+            runobj.schedule_suite()
+        assert 'Exceeded 10 backtracks' in str(exc.value)
+        m_find_git_parent.assert_has_calls(
+            [call('ceph', 'ceph_sha1' + i * '^') for i in xrange(10)]
+        )
+
+    @patch('teuthology.suite.util.find_git_parent')
+    @patch('teuthology.suite.run.Run.schedule_jobs')
+    @patch('teuthology.suite.util.has_packages_for_distro')
+    @patch('teuthology.suite.util.get_package_versions')
+    @patch('teuthology.suite.util.get_install_task_flavor')
+    @patch('__builtin__.file')
+    @patch('teuthology.suite.run.build_matrix')
+    @patch('teuthology.suite.util.git_ls_remote')
+    @patch('teuthology.suite.util.package_version_for_hash')
+    @patch('teuthology.suite.util.git_validate_sha1')
+    def test_newest_success(
+        self,
+        m_git_validate_sha1,
+        m_package_version_for_hash,
+        m_git_ls_remote,
+        m_build_matrix,
+        m_file,
+        m_get_install_task_flavor,
+        m_get_package_versions,
+        m_has_packages_for_distro,
+        m_schedule_jobs,
+        m_find_git_parent,
+    ):
+        m_git_validate_sha1.return_value = self.args.ceph_sha1
+        m_package_version_for_hash.return_value = 'ceph_version'
+        m_git_ls_remote.return_value = 'suite_hash'
+        build_matrix_desc = 'desc'
+        build_matrix_frags = ['frag.yml']
+        build_matrix_output = [
+            (build_matrix_desc, build_matrix_frags),
+        ]
+        m_build_matrix.return_value = build_matrix_output
+        m_file.side_effect = [StringIO('field: val\n') for i in xrange(11)]
+        m_get_install_task_flavor.return_value = 'basic'
+        m_get_package_versions.return_value = dict()
+        m_has_packages_for_distro.side_effect = \
+            [False for i in xrange(5)] + [True]
+
+        m_find_git_parent.side_effect = lambda proj, sha1: sha1 + '^'
+
+        self.args.newest = 10
+        runobj = self.klass(self.args)
+        runobj.base_args = list()
+        count = runobj.schedule_suite()
+        assert count == 1
+        m_has_packages_for_distro.assert_has_calls(
+            [call('ceph_sha1' + '^' * i, 'ubuntu', 'basic', {})
+             for i in xrange(5)]
+        )
+        m_find_git_parent.assert_has_calls(
+            [call('ceph', 'ceph_sha1' + i * '^') for i in xrange(5)]
+        )