示例#1
0
    def test_create_launch_job_pig(self, mock__create_output_ds,
                                   mock__run_job_execution,
                                   mock_generate_random_name):

        self.clients("sahara").jobs.create.return_value = mock.MagicMock(
            id="42")

        jobs_scenario = jobs.SaharaJob()

        jobs_scenario.context = {
            "tenant": {
                "sahara_image": "test_image",
                "sahara_mains": ["main_42"],
                "sahara_libs": ["lib_42"],
                "sahara_cluster": "cl_42",
                "sahara_input": "in_42"
            }
        }
        jobs_scenario.create_launch_job(job_type="pig",
                                        configs={"conf_key": "conf_val"},
                                        job_idx=0)
        self.clients("sahara").jobs.create.assert_called_once_with(
            name=mock_generate_random_name.return_value,
            type="pig",
            description="",
            mains=["main_42"],
            libs=["lib_42"])

        mock__run_job_execution.assert_called_once_with(
            job_id="42",
            cluster_id="cl_42",
            input_id="in_42",
            output_id="out_42",
            configs={"conf_key": "conf_val"},
            job_idx=0)
示例#2
0
    def test_create_launch_job_java(self, mock__run_job_execution):
        self.clients("sahara").jobs.create.return_value = mock.MagicMock(
            id="42")

        self.context.update({
            "tenant": {
                "sahara": {
                    "image": "test_image",
                    "mains": ["main_42"],
                    "libs": ["lib_42"],
                    "cluster": "cl_42",
                    "input": "in_42"
                }
            }
        })
        jobs_scenario = jobs.SaharaJob(self.context)
        jobs_scenario.generate_random_name = mock.Mock(return_value="job_42")

        jobs_scenario.create_launch_job(job_type="java",
                                        configs={"conf_key": "conf_val"},
                                        job_idx=0)
        self.clients("sahara").jobs.create.assert_called_once_with(
            name=jobs_scenario.generate_random_name.return_value,
            type="java",
            description="",
            mains=["main_42"],
            libs=["lib_42"])

        mock__run_job_execution.assert_called_once_with(
            job_id="42",
            cluster_id="cl_42",
            input_id=None,
            output_id=None,
            configs={"conf_key": "conf_val"},
            job_idx=0)
示例#3
0
    def test_create_launch_job_sequence_with_scaling(self, mock__scale_cluster,
                                                     mock__run_job_execution):
        self.clients("sahara").jobs.create.return_value = mock.MagicMock(
            id="42")
        self.clients("sahara").clusters.get.return_value = mock.MagicMock(
            id="cl_42", status="active")

        self.context.update({
            "tenant": {
                "sahara": {
                    "image": "test_image",
                    "mains": ["main_42"],
                    "libs": ["lib_42"],
                    "cluster": "cl_42",
                    "input": "in_42"
                }
            }
        })
        jobs_scenario = jobs.SaharaJob(self.context)
        jobs_scenario.generate_random_name = mock.Mock(return_value="job_42")

        jobs_scenario.create_launch_job_sequence_with_scaling(jobs=[{
            "job_type":
            "java",
            "configs": {
                "conf_key": "conf_val"
            }
        }, {
            "job_type":
            "java",
            "configs": {
                "conf_key2": "conf_val2"
            }
        }],
                                                              deltas=[1, -1])

        jobs_create_call = mock.call(
            name=jobs_scenario.generate_random_name.return_value,
            type="java",
            description="",
            mains=["main_42"],
            libs=["lib_42"])

        self.clients("sahara").jobs.create.assert_has_calls(
            [jobs_create_call, jobs_create_call])

        je_0 = mock.call(job_id="42",
                         cluster_id="cl_42",
                         input_id=None,
                         output_id=None,
                         configs={"conf_key": "conf_val"},
                         job_idx=0)
        je_1 = mock.call(job_id="42",
                         cluster_id="cl_42",
                         input_id=None,
                         output_id=None,
                         configs={"conf_key2": "conf_val2"},
                         job_idx=1)
        mock__run_job_execution.assert_has_calls(
            [je_0, je_1, je_0, je_1, je_0, je_1])
示例#4
0
    def test_create_launch_job_sequence(self, mock__run_job_execution,
                                        mock_generate_random_name):

        self.clients("sahara").jobs.create.return_value = mock.MagicMock(
            id="42")

        jobs_scenario = jobs.SaharaJob()

        jobs_scenario.context = {
            "tenant": {
                "sahara_image": "test_image",
                "sahara_mains": ["main_42"],
                "sahara_libs": ["lib_42"],
                "sahara_cluster": "cl_42",
                "sahara_input": "in_42"
            }
        }
        jobs_scenario.create_launch_job_sequence(jobs=[{
            "job_type": "java",
            "configs": {
                "conf_key": "conf_val"
            }
        }, {
            "job_type": "java",
            "configs": {
                "conf_key2": "conf_val2"
            }
        }])

        jobs_create_call = mock.call(
            name=mock_generate_random_name.return_value,
            type="java",
            description="",
            mains=["main_42"],
            libs=["lib_42"])

        self.clients("sahara").jobs.create.assert_has_calls(
            [jobs_create_call, jobs_create_call])

        mock__run_job_execution.assert_has_calls([
            mock.call(job_id="42",
                      cluster_id="cl_42",
                      input_id=None,
                      output_id=None,
                      configs={"conf_key": "conf_val"},
                      job_idx=0),
            mock.call(job_id="42",
                      cluster_id="cl_42",
                      input_id=None,
                      output_id=None,
                      configs={"conf_key2": "conf_val2"},
                      job_idx=1)
        ])