示例#1
0
    def test_check_for_zombie_proxy_users(self, mock_conductor_je_get,
                                          mock_user_delete,
                                          mock_users_list):
        user_0 = mock.MagicMock()
        user_0.name = "admin"
        user_0.id = 0

        user_1 = mock.MagicMock()
        user_1.name = "job_0"
        user_1.id = 1

        user_2 = mock.MagicMock()
        user_2.name = "job_1"
        user_2.id = 2

        mock_users_list.return_value = [user_0, user_1, user_2]

        je_0 = mock.MagicMock()
        je_0.id = 0
        je_0.info = {"status": "KILLED"}

        je_1 = mock.MagicMock()
        je_1.id = 1
        je_1.info = {"status": "WAITING"}

        mock_conductor_je_get.side_effect = [je_0, je_1]

        p._make_periodic_tasks().check_for_zombie_proxy_users(None)

        mock_user_delete.assert_called_once_with(user_id=1)
示例#2
0
    def test_check_for_zombie_proxy_users(self, mock_conductor_je_get,
                                          mock_user_delete, mock_users_list):
        user_0 = mock.MagicMock()
        user_0.name = "admin"
        user_0.id = 0

        user_1 = mock.MagicMock()
        user_1.name = "job_0"
        user_1.id = 1

        user_2 = mock.MagicMock()
        user_2.name = "job_1"
        user_2.id = 2

        mock_users_list.return_value = [user_0, user_1, user_2]

        je_0 = mock.MagicMock()
        je_0.id = 0
        je_0.info = {"status": "KILLED"}

        je_1 = mock.MagicMock()
        je_1.id = 1
        je_1.info = {"status": "WAITING"}

        mock_conductor_je_get.side_effect = [je_0, je_1]

        p._make_periodic_tasks().check_for_zombie_proxy_users(None)

        mock_user_delete.assert_called_once_with(user_id=1)
示例#3
0
    def test_transient_cluster_terminate(self, terminate_cluster,
                                         use_os_admin_auth_token):

        timeutils.set_time_override(datetime.datetime(2005, 2, 1, 0, 0))

        ctx = context.ctx()
        job = self.api.job_create(ctx, te.SAMPLE_JOB)
        ds = self.api.data_source_create(ctx, te.SAMPLE_DATA_SOURCE)

        self._make_cluster('1')
        self._make_cluster('2')

        self._create_job_execution({"end_time": timeutils.utcnow(),
                                    "id": 1,
                                    "cluster_id": "1"},
                                   job, ds, ds)
        self._create_job_execution({"end_time": None,
                                    "id": 2,
                                    "cluster_id": "2"},
                                   job, ds, ds)
        self._create_job_execution({"end_time": None,
                                    "id": 3,
                                    "cluster_id": "2"},
                                   job, ds, ds)

        timeutils.set_time_override(datetime.datetime(2005, 2, 1, 0, 1))

        p._make_periodic_tasks().terminate_unneeded_transient_clusters(None)
        self.assertEqual(1, terminate_cluster.call_count)
        terminate_cluster.assert_has_calls([mock.call(u'1')])
        self.assertEqual(1, use_os_admin_auth_token.call_count)
示例#4
0
    def test_cluster_terminate(self, terminate_cluster, utcnow):

        utcnow.return_value = datetime.datetime(2005, 2, 1, 0, 0)

        ctx = context.ctx()
        job = self.api.job_create(ctx, te.SAMPLE_JOB)
        ds = self.api.data_source_create(ctx, te.SAMPLE_DATA_SOURCE)

        self._make_cluster('1')
        self._make_cluster('2')

        self._create_job_execution({"end_time": timeutils.utcnow(),
                                    "id": 1,
                                    "cluster_id": "1"},
                                   job, ds, ds)
        self._create_job_execution({"end_time": None,
                                    "id": 2,
                                    "cluster_id": "2"},
                                   job, ds, ds)
        self._create_job_execution({"end_time": None,
                                    "id": 3,
                                    "cluster_id": "2"},
                                   job, ds, ds)

        utcnow.return_value = datetime.datetime(2005, 2, 1, 0, 1)

        p._make_periodic_tasks().terminate_unneeded_clusters(None)
        self.assertEqual(terminate_cluster.call_count, 1)
        terminate_cluster.assert_has_calls([mock.call(u'1')])
示例#5
0
    def test_transient_cluster_terminate(self, terminate_cluster):

        timeutils.set_time_override(datetime.datetime(2005, 2, 1, 0, 0))

        ctx = context.ctx()
        job = self.api.job_create(ctx, te.SAMPLE_JOB)
        ds = self.api.data_source_create(ctx, te.SAMPLE_DATA_SOURCE)

        self._make_cluster('1')
        self._make_cluster('2')

        self._create_job_execution(
            {
                "end_time": timeutils.utcnow(),
                "id": 1,
                "cluster_id": "1"
            }, job, ds, ds)
        self._create_job_execution(
            {
                "end_time": None,
                "id": 2,
                "cluster_id": "2"
            }, job, ds, ds)
        self._create_job_execution(
            {
                "end_time": None,
                "id": 3,
                "cluster_id": "2"
            }, job, ds, ds)

        timeutils.set_time_override(datetime.datetime(2005, 2, 1, 0, 1))

        p._make_periodic_tasks().terminate_unneeded_transient_clusters(None)
        self.assertEqual(terminate_cluster.call_count, 1)
        terminate_cluster.assert_has_calls([mock.call(u'1')])
示例#6
0
    def test_not_transient_cluster_does_not_terminate(self, terminate_cluster):

        timeutils.set_time_override(datetime.datetime(2005, 2, 1, 0, 0))
        self._make_cluster('1', is_transient=False)
        timeutils.set_time_override(datetime.datetime(2005, 2, 1, 0, 1))
        p._make_periodic_tasks().terminate_unneeded_transient_clusters(None)

        self.assertEqual(0, terminate_cluster.call_count)
示例#7
0
 def test_run_verifications_executed(self, cluster_update, ver_valid):
     self._make_cluster('1')
     p._make_periodic_tasks().run_verifications(None)
     self.assertEqual(1, ver_valid.call_count)
     cluster_update.assert_called_once_with(
         '1', {'verification': {
             'status': 'START'
         }})
示例#8
0
    def test_not_transient_cluster_does_not_terminate(self, terminate_cluster):

        timeutils.set_time_override(datetime.datetime(2005, 2, 1, 0, 0))
        self._make_cluster('1', is_transient=False)
        timeutils.set_time_override(datetime.datetime(2005, 2, 1, 0, 1))
        p._make_periodic_tasks().terminate_unneeded_transient_clusters(None)

        self.assertEqual(0, terminate_cluster.call_count)
示例#9
0
    def test_transient_cluster_not_killed_too_early(self, terminate_cluster):

        timeutils.set_time_override(datetime.datetime(2005, 2, 1, second=0))

        self._make_cluster('1')

        timeutils.set_time_override(datetime.datetime(2005, 2, 1, second=20))

        p._make_periodic_tasks().terminate_unneeded_transient_clusters(None)
        self.assertEqual(terminate_cluster.call_count, 0)
示例#10
0
    def test_transient_cluster_not_killed_too_early(self, terminate_cluster):

        timeutils.set_time_override(datetime.datetime(2005, 2, 1, second=0))

        self._make_cluster('1')

        timeutils.set_time_override(datetime.datetime(2005, 2, 1, second=20))

        p._make_periodic_tasks().terminate_unneeded_transient_clusters(None)
        self.assertEqual(0, terminate_cluster.call_count)
示例#11
0
    def test_cluster_not_killed_too_early(self, terminate_cluster, utcnow):

        utcnow.return_value = datetime.datetime(2005, 2, 1, second=0)

        self._make_cluster('1')

        utcnow.return_value = datetime.datetime(2005, 2, 1, second=20)

        p._make_periodic_tasks().terminate_unneeded_clusters(None)
        self.assertEqual(terminate_cluster.call_count, 0)
示例#12
0
    def test_cluster_not_killed_too_early(self, terminate_cluster, utcnow):

        utcnow.return_value = datetime.datetime(2005, 2, 1, second=0)

        self._make_cluster('1')

        utcnow.return_value = datetime.datetime(2005, 2, 1, second=20)

        p._make_periodic_tasks().terminate_unneeded_clusters(None)
        self.assertEqual(terminate_cluster.call_count, 0)
示例#13
0
    def test_cluster_killed_in_time(self, terminate_cluster, utcnow):

        utcnow.return_value = datetime.datetime(2005, 2, 1, second=0)

        self._make_cluster('1')

        utcnow.return_value = datetime.datetime(2005, 2, 1, second=40)

        p._make_periodic_tasks().terminate_unneeded_clusters(None)
        self.assertEqual(terminate_cluster.call_count, 1)
        terminate_cluster.assert_has_calls([mock.call(u'1')])
示例#14
0
    def test_cluster_killed_in_time(self, terminate_cluster, utcnow):

        utcnow.return_value = datetime.datetime(2005, 2, 1, second=0)

        self._make_cluster('1')

        utcnow.return_value = datetime.datetime(2005, 2, 1, second=40)

        p._make_periodic_tasks().terminate_unneeded_clusters(None)
        self.assertEqual(terminate_cluster.call_count, 1)
        terminate_cluster.assert_has_calls([mock.call(u'1')])
示例#15
0
    def test_transient_cluster_killed_in_time(self, terminate_cluster):

        timeutils.set_time_override(datetime.datetime(2005, 2, 1, second=0))

        self._make_cluster('1')

        timeutils.set_time_override(datetime.datetime(2005, 2, 1, second=40))

        p._make_periodic_tasks().terminate_unneeded_transient_clusters(None)
        self.assertEqual(1, terminate_cluster.call_count)
        terminate_cluster.assert_has_calls([mock.call(u'1')])
示例#16
0
    def test_transient_cluster_killed_in_time(self, terminate_cluster):

        timeutils.set_time_override(datetime.datetime(2005, 2, 1, second=0))

        self._make_cluster('1')

        timeutils.set_time_override(datetime.datetime(2005, 2, 1, second=40))

        p._make_periodic_tasks().terminate_unneeded_transient_clusters(None)
        self.assertEqual(terminate_cluster.call_count, 1)
        terminate_cluster.assert_has_calls([mock.call(u'1')])
示例#17
0
    def test_active_cluster_not_killed_as_inactive(self, terminate_cluster):
        self.override_config('cleanup_time_for_incomplete_clusters', 1)

        timeutils.set_time_override(datetime.datetime(2005, 2, 1, second=0))

        self._make_cluster('1')

        timeutils.set_time_override(
            datetime.datetime(2005, 2, 1, hour=1, second=10))

        p._make_periodic_tasks().terminate_incomplete_clusters(None)
        self.assertEqual(terminate_cluster.call_count, 0)
示例#18
0
    def test_incomplete_cluster_not_killed_too_early(self, terminate_cluster):

        self.override_config('cleanup_time_for_incomplete_clusters', 1)

        timeutils.set_time_override(datetime.datetime(2005, 2, 1, second=0))

        self._make_cluster('1', status='Pending')

        timeutils.set_time_override(
            datetime.datetime(2005, 2, 1, minute=59, second=50))

        p._make_periodic_tasks().terminate_incomplete_clusters(None)
        self.assertEqual(terminate_cluster.call_count, 0)
示例#19
0
    def test_active_cluster_not_killed_as_inactive(
            self, terminate_cluster):
        self.override_config('cleanup_time_for_incomplete_clusters', 1)

        timeutils.set_time_override(datetime.datetime(2005, 2, 1, second=0))

        self._make_cluster('1')

        timeutils.set_time_override(datetime.datetime(
            2005, 2, 1, hour=1, second=10))

        p._make_periodic_tasks().terminate_incomplete_clusters(None)
        self.assertEqual(0, terminate_cluster.call_count)
示例#20
0
    def test_incomplete_cluster_not_killed_too_early(self, terminate_cluster):

        self.override_config('cleanup_time_for_incomplete_clusters', 1)

        timeutils.set_time_override(datetime.datetime(2005, 2, 1, second=0))

        self._make_cluster('1', c_u.CLUSTER_STATUS_SPAWNING)

        timeutils.set_time_override(datetime.datetime(
            2005, 2, 1, minute=59, second=50))

        p._make_periodic_tasks().terminate_incomplete_clusters(None)
        self.assertEqual(0, terminate_cluster.call_count)
示例#21
0
    def test_incomplete_cluster_killed_in_time(self, terminate_cluster):

        self.override_config('cleanup_time_for_incomplete_clusters', 1)
        timeutils.set_time_override(datetime.datetime(2005, 2, 1, second=0))

        self._make_cluster('1', status='Pending')

        timeutils.set_time_override(datetime.datetime(
            2005, 2, 1, hour=1, second=10))

        p._make_periodic_tasks().terminate_incomplete_clusters(None)
        self.assertEqual(1, terminate_cluster.call_count)
        terminate_cluster.assert_has_calls([mock.call(u'1')])
示例#22
0
    def test_incomplete_cluster_killed_in_time(self, terminate_cluster):

        self.override_config('cleanup_time_for_incomplete_clusters', 1)
        timeutils.set_time_override(datetime.datetime(2005, 2, 1, second=0))

        self._make_cluster('1', status='Pending')

        timeutils.set_time_override(
            datetime.datetime(2005, 2, 1, hour=1, second=10))

        p._make_periodic_tasks().terminate_incomplete_clusters(None)
        self.assertEqual(terminate_cluster.call_count, 1)
        terminate_cluster.assert_has_calls([mock.call(u'1')])
示例#23
0
 def test_job_status_update(self, get_job_status):
     ctx = context.ctx()
     job = self.api.job_create(ctx, te.SAMPLE_JOB)
     ds = self.api.data_source_create(ctx, te.SAMPLE_DATA_SOURCE)
     self._create_job_execution(
         {
             "end_time": datetime.datetime.now(),
             "id": 1
         }, job, ds, ds)
     self._create_job_execution({"end_time": None, "id": 2}, job, ds, ds)
     self._create_job_execution({"end_time": None, "id": 3}, job, ds, ds)
     p._make_periodic_tasks().update_job_statuses(None)
     self.assertEqual(get_job_status.call_count, 2)
     get_job_status.assert_has_calls([mock.call(u'2'), mock.call(u'3')])
示例#24
0
    def test_incomplete_cluster_killed_in_time(self, terminate_cluster,
                                               use_os_admin_auth_token):

        self.override_config('cleanup_time_for_incomplete_clusters', 1)
        timeutils.set_time_override(datetime.datetime(2005, 2, 1, second=0))

        self._make_cluster('1', c_u.CLUSTER_STATUS_SPAWNING)

        timeutils.set_time_override(
            datetime.datetime(2005, 2, 1, hour=1, second=10))

        p._make_periodic_tasks().terminate_incomplete_clusters(None)
        self.assertEqual(1, terminate_cluster.call_count)
        terminate_cluster.assert_has_calls([mock.call(u'1')])
        self.assertEqual(1, use_os_admin_auth_token.call_count)
示例#25
0
    def test_incomplete_cluster_killed_in_time(self, terminate_cluster,
                                               use_os_admin_auth_token):

        self.override_config('cleanup_time_for_incomplete_clusters', 1)
        timeutils.set_time_override(datetime.datetime(2005, 2, 1, second=0))

        self._make_cluster('1', c_u.CLUSTER_STATUS_SPAWNING)

        timeutils.set_time_override(datetime.datetime(
            2005, 2, 1, hour=1, second=10))

        p._make_periodic_tasks().terminate_incomplete_clusters(None)
        self.assertEqual(1, terminate_cluster.call_count)
        terminate_cluster.assert_has_calls([mock.call(u'1')])
        self.assertEqual(1, use_os_admin_auth_token.call_count)
示例#26
0
 def test_job_status_update(self, get_job_status):
     ctx = context.ctx()
     job = self.api.job_create(ctx, te.SAMPLE_JOB)
     ds = self.api.data_source_create(ctx, te.SAMPLE_DATA_SOURCE)
     self._create_job_execution({"end_time": datetime.datetime.now(),
                                 "id": 1},
                                job, ds, ds)
     self._create_job_execution({"end_time": None,
                                 "id": 2},
                                job, ds, ds)
     self._create_job_execution({"end_time": None,
                                 "id": 3},
                                job, ds, ds)
     p._make_periodic_tasks().update_job_statuses(None)
     self.assertEqual(2, get_job_status.call_count)
     get_job_status.assert_has_calls([mock.call(u'2'),
                                      mock.call(u'3')])
示例#27
0
 def test_run_verifications_not_executed(self, cluster_update, ver_valid):
     self._make_cluster('1', status=c_u.CLUSTER_STATUS_ERROR)
     p._make_periodic_tasks().run_verifications(None)
     ver_valid.assert_not_called()
     cluster_update.assert_not_called()
示例#28
0
 def test_run_verifications_executed(self, cluster_update, ver_valid):
     self._make_cluster('1')
     p._make_periodic_tasks().run_verifications(None)
     self.assertEqual(1, ver_valid.call_count)
     cluster_update.assert_called_once_with(
         '1', {'verification': {'status': 'START'}})
示例#29
0
 def test_run_verifications_not_executed(self, cluster_update, ver_valid):
     self._make_cluster('1', status=c_u.CLUSTER_STATUS_ERROR)
     p._make_periodic_tasks().run_verifications(None)
     ver_valid.assert_not_called()
     cluster_update.assert_not_called()