Пример #1
0
 def test_encode_resource_job(self):
     self.job_R = make_job("R", plugin="resource")
     result_R = JobResult({
         'job': self.job_R,
         'outcome': JobResult.OUTCOME_PASS,
         'io_log': ((0, 'stdout', "attr: value\n"),)
     })
     jobstate = JobState(self.job_R)
     jobstate.result = result_R
     jobstate_enc = jobstate._get_persistance_subset()
     # The inhibitor list is not saved
     with self.assertRaises(KeyError):
         jobstate_enc['_readiness_inhibitor_list']
     # Resource have to be re evealutated on startup, outcome of the job
     # must be reset to JobResult.OUTCOME_NONE
     self.assertEqual(jobstate_enc['_result'].outcome,
                      JobResult.OUTCOME_NONE)
Пример #2
0
 def test_encode_resource_job(self):
     self.job_R = make_job("R", plugin="resource")
     result_R = JobResult({
         'job': self.job_R,
         'outcome': JobResult.OUTCOME_PASS,
         'io_log': ((0, 'stdout', "attr: value\n"), )
     })
     jobstate = JobState(self.job_R)
     jobstate.result = result_R
     jobstate_enc = jobstate._get_persistance_subset()
     # The inhibitor list is not saved
     with self.assertRaises(KeyError):
         jobstate_enc['_readiness_inhibitor_list']
     # Resource have to be re evealutated on startup, outcome of the job
     # must be reset to JobResult.OUTCOME_NONE
     self.assertEqual(jobstate_enc['_result'].outcome,
                      JobResult.OUTCOME_NONE)
Пример #3
0
class JobStateTests(TestCase):

    def setUp(self):
        self.job = make_job("A")
        self.job_state = JobState(self.job)

    def test_smoke(self):
        self.assertIsNotNone(self.job_state.result)
        self.assertIs(self.job_state.result.job, self.job)
        self.assertIs(self.job_state.result.outcome, JobResult.OUTCOME_NONE)
        self.assertEqual(self.job_state.readiness_inhibitor_list, [
            UndesiredJobReadinessInhibitor])

    def test_getting_job(self):
        self.assertIs(self.job_state.job, self.job)

    def test_setting_job_is_not_allowed(self):
        with self.assertRaises(AttributeError):
            self.job_state.job = None

    def test_setting_result(self):
        result = make_job_result(self.job)
        self.job_state.result = result
        self.assertIs(self.job_state.result, result)

    def test_setting_readiness_inhibitor_list(self):
        inhibitor = JobReadinessInhibitor(JobReadinessInhibitor.UNDESIRED)
        self.job_state.readiness_inhibitor_list = [inhibitor]
        self.assertEqual(self.job_state.readiness_inhibitor_list, [inhibitor])

    def test_can_start(self):
        self.job_state.readiness_inhibitor_list = []
        self.assertTrue(self.job_state.can_start())
        self.job_state.readiness_inhibitor_list = [
            UndesiredJobReadinessInhibitor]
        self.assertFalse(self.job_state.can_start())

    def test_readiness_description(self):
        self.job_state.readiness_inhibitor_list = []
        self.assertEqual(self.job_state.get_readiness_description(),
                         "job can be started")
        self.job_state.readiness_inhibitor_list = [
            UndesiredJobReadinessInhibitor]
        self.assertTrue(
            self.job_state.get_readiness_description().startswith(
                "job cannot be started: "))

    def test_encode_resource_job(self):
        self.job_R = make_job("R", plugin="resource")
        result_R = JobResult({
            'job': self.job_R,
            'outcome': JobResult.OUTCOME_PASS,
            'io_log': ((0, 'stdout', "attr: value\n"),)
        })
        jobstate = JobState(self.job_R)
        jobstate.result = result_R
        jobstate_enc = jobstate._get_persistance_subset()
        # The inhibitor list is not saved
        with self.assertRaises(KeyError):
            jobstate_enc['_readiness_inhibitor_list']
        # Resource have to be re evealutated on startup, outcome of the job
        # must be reset to JobResult.OUTCOME_NONE
        self.assertEqual(jobstate_enc['_result'].outcome,
                         JobResult.OUTCOME_NONE)

    def test_encode_normal_job(self):
        result = JobResult({
            'job': self.job,
            'outcome': JobResult.OUTCOME_PASS,
        })
        self.job_state.result = result
        jobstate_enc = self.job_state._get_persistance_subset()
        # The inhibitor list is not saved
        with self.assertRaises(KeyError):
            jobstate_enc['_readiness_inhibitor_list']
        # Normal jobs should keep their outcome value
        self.assertEqual(jobstate_enc['_result'].outcome,
                         JobResult.OUTCOME_PASS)

    def test_decode(self):
        raw_json = """{
            "_class_id": "JOB_STATE",
            "_job": {
                "_class_id": "JOB_DEFINITION",
                "data": {
                    "name": "X",
                    "plugin": "dummy"
                }
            },
            "_result": {
                "_class_id": "JOB_RESULT",
                "data": {
                    "comments": null,
                    "job": {
                        "_class_id": "JOB_DEFINITION",
                        "data": {
                            "name": "X",
                            "plugin": "dummy"
                        }
                    },
                    "outcome": "pass",
                    "return_code": null
                }
            }
        }"""
        job_dec = json.loads(
            raw_json, object_hook=SessionStateEncoder().dict_to_object)
        self.assertIsInstance(job_dec, JobState)
        self.assertEqual(
            repr(job_dec._result), (
                "<JobResult job:<JobDefinition name:'X'"
                " plugin:'dummy'> outcome:'pass'>"))
Пример #4
0
class JobStateTests(TestCase):
    def setUp(self):
        self.job = make_job("A")
        self.job_state = JobState(self.job)

    def test_smoke(self):
        self.assertIsNotNone(self.job_state.result)
        self.assertIs(self.job_state.result.job, self.job)
        self.assertIs(self.job_state.result.outcome, JobResult.OUTCOME_NONE)
        self.assertEqual(self.job_state.readiness_inhibitor_list,
                         [UndesiredJobReadinessInhibitor])

    def test_getting_job(self):
        self.assertIs(self.job_state.job, self.job)

    def test_setting_job_is_not_allowed(self):
        with self.assertRaises(AttributeError):
            self.job_state.job = None

    def test_setting_result(self):
        result = make_job_result(self.job)
        self.job_state.result = result
        self.assertIs(self.job_state.result, result)

    def test_setting_readiness_inhibitor_list(self):
        inhibitor = JobReadinessInhibitor(JobReadinessInhibitor.UNDESIRED)
        self.job_state.readiness_inhibitor_list = [inhibitor]
        self.assertEqual(self.job_state.readiness_inhibitor_list, [inhibitor])

    def test_can_start(self):
        self.job_state.readiness_inhibitor_list = []
        self.assertTrue(self.job_state.can_start())
        self.job_state.readiness_inhibitor_list = [
            UndesiredJobReadinessInhibitor
        ]
        self.assertFalse(self.job_state.can_start())

    def test_readiness_description(self):
        self.job_state.readiness_inhibitor_list = []
        self.assertEqual(self.job_state.get_readiness_description(),
                         "job can be started")
        self.job_state.readiness_inhibitor_list = [
            UndesiredJobReadinessInhibitor
        ]
        self.assertTrue(self.job_state.get_readiness_description().startswith(
            "job cannot be started: "))

    def test_encode_resource_job(self):
        self.job_R = make_job("R", plugin="resource")
        result_R = JobResult({
            'job': self.job_R,
            'outcome': JobResult.OUTCOME_PASS,
            'io_log': ((0, 'stdout', "attr: value\n"), )
        })
        jobstate = JobState(self.job_R)
        jobstate.result = result_R
        jobstate_enc = jobstate._get_persistance_subset()
        # The inhibitor list is not saved
        with self.assertRaises(KeyError):
            jobstate_enc['_readiness_inhibitor_list']
        # Resource have to be re evealutated on startup, outcome of the job
        # must be reset to JobResult.OUTCOME_NONE
        self.assertEqual(jobstate_enc['_result'].outcome,
                         JobResult.OUTCOME_NONE)

    def test_encode_normal_job(self):
        result = JobResult({
            'job': self.job,
            'outcome': JobResult.OUTCOME_PASS,
        })
        self.job_state.result = result
        jobstate_enc = self.job_state._get_persistance_subset()
        # The inhibitor list is not saved
        with self.assertRaises(KeyError):
            jobstate_enc['_readiness_inhibitor_list']
        # Normal jobs should keep their outcome value
        self.assertEqual(jobstate_enc['_result'].outcome,
                         JobResult.OUTCOME_PASS)

    def test_decode(self):
        raw_json = """{
            "_class_id": "JOB_STATE",
            "_job": {
                "_class_id": "JOB_DEFINITION",
                "data": {
                    "name": "X",
                    "plugin": "dummy"
                }
            },
            "_result": {
                "_class_id": "JOB_RESULT",
                "data": {
                    "comments": null,
                    "job": {
                        "_class_id": "JOB_DEFINITION",
                        "data": {
                            "name": "X",
                            "plugin": "dummy"
                        }
                    },
                    "outcome": "pass",
                    "return_code": null
                }
            }
        }"""
        job_dec = json.loads(raw_json,
                             object_hook=SessionStateEncoder().dict_to_object)
        self.assertIsInstance(job_dec, JobState)
        self.assertEqual(repr(job_dec._result),
                         ("<JobResult job:<JobDefinition name:'X'"
                          " plugin:'dummy'> outcome:'pass'>"))