async def test_get_sequencer_last_updated_at(self):
        async with MockAdminAPI() as client:
            cv = await get_cluster_view(client)
            node_id = cv.get_node_view(node_index=0).node_id
            await apply_maintenance(client=client, sequencer_nodes=[node_id])

            cv = await get_cluster_view(client)
            mv = list(cv.get_all_maintenance_views())[0]
            self.assertIsNone(mv.get_sequencer_last_updated_at(node_id))

            ts = datetime.now()
            client._set_sequencer_maintenance_progress(
                node_id=node_id,
                maintenance_progress=SequencerMaintenanceProgress(
                    status=MaintenanceStatus.STARTED,
                    target_state=SequencingState.UNKNOWN,
                    created_at=datetime.now(),
                    last_updated_at=datetime.now(),
                    associated_group_ids=["johnsnow"],
                ).to_thrift(),
            )
            cv = await get_cluster_view(client)
            mv = list(cv.get_all_maintenance_views())[0]
            self.assertTrue(
                mv.get_sequencer_last_updated_at(node_id) -
                ts < timedelta(seconds=2))
Exemple #2
0
 def get_sequencer_last_updated_at(self,
                                   sequencer: NodeID) -> Optional[datetime]:
     sequencer_state = self.get_sequencer_state(sequencer)
     if sequencer_state is None:
         raise NodeIsNotASequencerError(f"{sequencer}")
     elif sequencer_state.maintenance is not None:
         return SequencerMaintenanceProgress.from_thrift(
             sequencer_state.maintenance).last_updated_at
     else:
         return None
 def get_sequencer_last_updated_at(self,
                                   sequencer: NodeID) -> Optional[datetime]:
     sequencer_state = self.get_sequencer_state(sequencer)
     if sequencer_state is None:
         raise NodeIsNotASequencerError(f"{sequencer}")
     elif sequencer_state.maintenance is not None:
         return SequencerMaintenanceProgress.from_thrift(
             # pyre-fixme[6]: Expected `SequencerMaintenanceProgress` for 1st
             #  param but got `Optional[SequencerMaintenanceProgress]`.
             sequencer_state.maintenance).last_updated_at
     else:
         return None
Exemple #4
0
    async def test_smoke(self):
        created_at = datetime.now() - timedelta(hours=2)
        last_updated_at = datetime.now() - timedelta(minutes=5)
        maintenance_status = MaintenanceStatus.NOT_STARTED
        target_state = SequencingState.DISABLED
        associated_group_ids = ["johnsnow"]

        thrift_smp = ThriftSequencerMaintenanceProgress(
            status=maintenance_status,
            target_state=target_state,
            created_at=int(created_at.timestamp() * _MILLISECONDS_IN_SECOND),
            last_updated_at=int(last_updated_at.timestamp() *
                                _MILLISECONDS_IN_SECOND),
            associated_group_ids=associated_group_ids,
        )
        smp = SequencerMaintenanceProgress(
            status=maintenance_status,
            target_state=target_state,
            created_at=created_at,
            last_updated_at=last_updated_at,
            associated_group_ids=associated_group_ids,
        )
        self.assertEqual(thrift_smp, smp.to_thrift())
        self.assertEqual(thrift_smp.status, smp.status)
        self.assertEqual(
            thrift_smp.created_at // _MILLISECONDS_IN_SECOND,
            int(smp.created_at.timestamp()),
        )
        self.assertEqual(
            thrift_smp.last_updated_at // _MILLISECONDS_IN_SECOND,
            int(smp.last_updated_at.timestamp()),
        )

        from_thrift = SequencerMaintenanceProgress.from_thrift(thrift_smp)
        self.assertEqual(smp.status, from_thrift.status)
        self.assertEqual(smp.target_state, from_thrift.target_state)
        self.assertEqual(smp.created_at, from_thrift.created_at)
        self.assertEqual(smp.last_updated_at, from_thrift.last_updated_at)
        self.assertEqual(smp.associated_group_ids,
                         from_thrift.associated_group_ids)
    async def test_sequencer_maintenance_status(self):
        async with MockAdminAPI() as client:
            cv = await get_cluster_view(client)
            node_id = cv.get_node_view(node_index=0).node_id
            await apply_maintenance(client=client, sequencer_nodes=[node_id])

            # Just started
            cv = await get_cluster_view(client)
            mv = list(cv.get_all_maintenance_views())[0]
            self.assertEqual(
                mv.get_sequencer_maintenance_status(node_id),
                MaintenanceStatus.NOT_STARTED,
            )
            self.assertEqual(mv.num_sequencers_total, 1)
            self.assertEqual(mv.num_sequencers_done, 0)
            self.assertFalse(mv.are_all_sequencers_done)
            self.assertFalse(mv.is_everything_done)
            self.assertFalse(mv.is_blocked)
            self.assertFalse(mv.is_completed)
            self.assertTrue(mv.is_in_progress)
            self.assertEqual(mv.overall_status,
                             MaintenanceOverallStatus.IN_PROGRESS)

            # In progress
            client._set_sequencer_maintenance_progress(
                node_id=node_id,
                maintenance_progress=SequencerMaintenanceProgress(
                    status=MaintenanceStatus.STARTED,
                    target_state=SequencingState.UNKNOWN,
                    created_at=datetime.now(),
                    last_updated_at=datetime.now(),
                    associated_group_ids=["johnsnow"],
                ).to_thrift(),
            )
            cv = await get_cluster_view(client)
            mv = list(cv.get_all_maintenance_views())[0]
            self.assertEqual(mv.get_sequencer_maintenance_status(node_id),
                             MaintenanceStatus.STARTED)
            self.assertEqual(mv.num_sequencers_done, 0)
            self.assertFalse(mv.are_all_sequencers_done)
            self.assertFalse(mv.is_everything_done)
            self.assertFalse(mv.is_blocked)
            self.assertFalse(mv.is_completed)
            self.assertTrue(mv.is_in_progress)
            self.assertEqual(mv.overall_status,
                             MaintenanceOverallStatus.IN_PROGRESS)

            # Blocked
            client._set_sequencer_maintenance_progress(
                node_id=node_id,
                maintenance_progress=SequencerMaintenanceProgress(
                    status=MaintenanceStatus.BLOCKED_UNTIL_SAFE,
                    target_state=SequencingState.UNKNOWN,
                    created_at=datetime.now(),
                    last_updated_at=datetime.now(),
                    associated_group_ids=["johnsnow"],
                ).to_thrift(),
            )
            cv = await get_cluster_view(client)
            mv = list(cv.get_all_maintenance_views())[0]
            self.assertEqual(
                mv.get_sequencer_maintenance_status(node_id),
                MaintenanceStatus.BLOCKED_UNTIL_SAFE,
            )
            self.assertEqual(mv.num_sequencers_done, 0)
            self.assertFalse(mv.are_all_sequencers_done)
            self.assertFalse(mv.is_everything_done)
            self.assertTrue(mv.is_blocked)
            self.assertFalse(mv.is_completed)
            self.assertFalse(mv.is_in_progress)
            self.assertEqual(mv.overall_status,
                             MaintenanceOverallStatus.BLOCKED)

            # Done
            client._set_sequencing_state(node_id, SequencingState.DISABLED)
            cv = await get_cluster_view(client)
            mv = list(cv.get_all_maintenance_views())[0]
            self.assertEqual(
                mv.get_sequencer_maintenance_status(node_id),
                MaintenanceStatus.COMPLETED,
            )
            self.assertEqual(mv.overall_status,
                             MaintenanceOverallStatus.COMPLETED)