X-Git-Url: https://osm.etsi.org/gitweb/?a=blobdiff_plain;f=osm_policy_module%2Ftests%2Funit%2Fautoscaling%2Ftest_autoscaling_service.py;h=e5253eacc6b4a12f927726bc29a1f7c7bacd1599;hb=d37c54c64eec65c9a3c490a31eef3a02a76cb474;hp=053b278a4cb5d0a81e67e3b844aca6f35f3d2346;hpb=c72b9d5f574d51608e4810294004414c7a9c02fe;p=osm%2FPOL.git diff --git a/osm_policy_module/tests/unit/autoscaling/test_autoscaling_service.py b/osm_policy_module/tests/unit/autoscaling/test_autoscaling_service.py index 053b278..e5253ea 100644 --- a/osm_policy_module/tests/unit/autoscaling/test_autoscaling_service.py +++ b/osm_policy_module/tests/unit/autoscaling/test_autoscaling_service.py @@ -39,7 +39,6 @@ from osm_policy_module.core.database import ScalingAlarmRepository class TestAutoscalingService(TestCase): def setUp(self): self.config = Config() - self.loop = asyncio.new_event_loop() @mock.patch.object(ScalingAlarmRepository, "get") @mock.patch("osm_policy_module.core.database.db") @@ -49,19 +48,17 @@ class TestAutoscalingService(TestCase): get_alarm.return_value = mock_alarm service = AutoscalingService(self.config) - self.loop.run_until_complete(service.update_alarm_status("test_uuid", "alarm")) + asyncio.run(service.update_alarm_status("test_uuid", "alarm")) self.assertEqual(mock_alarm.last_status, "alarm") mock_alarm.save.assert_called_with() service = AutoscalingService(self.config) - self.loop.run_until_complete(service.update_alarm_status("test_uuid", "ok")) + asyncio.run(service.update_alarm_status("test_uuid", "ok")) self.assertEqual(mock_alarm.last_status, "ok") mock_alarm.save.assert_called_with() service = AutoscalingService(self.config) - self.loop.run_until_complete( - service.update_alarm_status("test_uuid", "insufficient_data") - ) + asyncio.run(service.update_alarm_status("test_uuid", "insufficient_data")) self.assertEqual(mock_alarm.last_status, "insufficient_data") mock_alarm.save.assert_called_with() @@ -74,7 +71,7 @@ class TestAutoscalingService(TestCase): get_alarm.return_value = mock_alarm service = AutoscalingService(self.config) - self.loop.run_until_complete(service.evaluate_policy("test_uuid")) + asyncio.run(service.evaluate_policy("test_uuid")) list_alarms.assert_not_called() @mock.patch.object(ScalingAlarmRepository, "list") @@ -87,7 +84,7 @@ class TestAutoscalingService(TestCase): """ Tests scale in with AND operation, both alarms triggered """ - future = asyncio.Future(loop=self.loop) + future = asyncio.Future(loop=asyncio.new_event_loop()) future.set_result("mock") scale.return_value = future @@ -103,7 +100,7 @@ class TestAutoscalingService(TestCase): list_alarms.return_value = [mock_alarm, mock_alarm_2] service = AutoscalingService(self.config) - self.loop.run_until_complete(service.evaluate_policy("test_uuid")) + asyncio.run(service.evaluate_policy("test_uuid")) scale.assert_called_with("test_nsr_id", "test_group", "1", "scale_in") @mock.patch.object(ScalingAlarmRepository, "list") @@ -116,7 +113,7 @@ class TestAutoscalingService(TestCase): """ Tests scale in with AND operation, only one alarm triggered. """ - future = asyncio.Future(loop=self.loop) + future = asyncio.Future(loop=asyncio.new_event_loop()) future.set_result("mock") scale.return_value = future @@ -132,7 +129,7 @@ class TestAutoscalingService(TestCase): list_alarms.return_value = [mock_alarm, mock_alarm_2] service = AutoscalingService(self.config) - self.loop.run_until_complete(service.evaluate_policy("test_uuid")) + asyncio.run(service.evaluate_policy("test_uuid")) scale.assert_not_called() @mock.patch.object(ScalingAlarmRepository, "list") @@ -145,7 +142,7 @@ class TestAutoscalingService(TestCase): """ Tests scale in with OR operation, both alarms triggered """ - future = asyncio.Future(loop=self.loop) + future = asyncio.Future(loop=asyncio.new_event_loop()) future.set_result("mock") scale.return_value = future @@ -161,7 +158,7 @@ class TestAutoscalingService(TestCase): list_alarms.return_value = [mock_alarm, mock_alarm_2] service = AutoscalingService(self.config) - self.loop.run_until_complete(service.evaluate_policy("test_uuid")) + asyncio.run(service.evaluate_policy("test_uuid")) scale.assert_called_with("test_nsr_id", "test_group", "1", "scale_in") @mock.patch.object(ScalingAlarmRepository, "list") @@ -174,7 +171,7 @@ class TestAutoscalingService(TestCase): """ Tests scale in with OR operation, only one alarm triggered """ - future = asyncio.Future(loop=self.loop) + future = asyncio.Future(loop=asyncio.new_event_loop()) future.set_result("mock") scale.return_value = future @@ -190,7 +187,7 @@ class TestAutoscalingService(TestCase): list_alarms.return_value = [mock_alarm, mock_alarm_2] service = AutoscalingService(self.config) - self.loop.run_until_complete(service.evaluate_policy("test_uuid")) + asyncio.run(service.evaluate_policy("test_uuid")) scale.assert_called_with("test_nsr_id", "test_group", "1", "scale_in") @mock.patch.object(ScalingAlarmRepository, "list") @@ -203,7 +200,7 @@ class TestAutoscalingService(TestCase): """ Tests scale out with AND operation, both alarms triggered """ - future = asyncio.Future(loop=self.loop) + future = asyncio.Future(loop=asyncio.new_event_loop()) future.set_result("mock") scale.return_value = future @@ -219,7 +216,7 @@ class TestAutoscalingService(TestCase): list_alarms.return_value = [mock_alarm, mock_alarm_2] service = AutoscalingService(self.config) - self.loop.run_until_complete(service.evaluate_policy("test_uuid")) + asyncio.run(service.evaluate_policy("test_uuid")) scale.assert_called_with("test_nsr_id", "test_group", "1", "scale_out") @mock.patch.object(ScalingAlarmRepository, "list") @@ -232,7 +229,7 @@ class TestAutoscalingService(TestCase): """ Tests scale out with AND operation, only one alarm triggered. """ - future = asyncio.Future(loop=self.loop) + future = asyncio.Future(loop=asyncio.new_event_loop()) future.set_result("mock") scale.return_value = future @@ -248,7 +245,7 @@ class TestAutoscalingService(TestCase): list_alarms.return_value = [mock_alarm, mock_alarm_2] service = AutoscalingService(self.config) - self.loop.run_until_complete(service.evaluate_policy("test_uuid")) + asyncio.run(service.evaluate_policy("test_uuid")) scale.assert_not_called() @mock.patch.object(ScalingAlarmRepository, "list") @@ -261,7 +258,7 @@ class TestAutoscalingService(TestCase): """ Tests scale out with OR operation, both alarms triggered """ - future = asyncio.Future(loop=self.loop) + future = asyncio.Future(loop=asyncio.new_event_loop()) future.set_result("mock") scale.return_value = future @@ -277,7 +274,7 @@ class TestAutoscalingService(TestCase): list_alarms.return_value = [mock_alarm, mock_alarm_2] service = AutoscalingService(self.config) - self.loop.run_until_complete(service.evaluate_policy("test_uuid")) + asyncio.run(service.evaluate_policy("test_uuid")) scale.assert_called_with("test_nsr_id", "test_group", "1", "scale_out") @mock.patch.object(ScalingAlarmRepository, "list") @@ -290,7 +287,7 @@ class TestAutoscalingService(TestCase): """ Tests scale out with OR operation, only one alarm triggered """ - future = asyncio.Future(loop=self.loop) + future = asyncio.Future(loop=asyncio.new_event_loop()) future.set_result("mock") scale.return_value = future @@ -306,7 +303,7 @@ class TestAutoscalingService(TestCase): list_alarms.return_value = [mock_alarm, mock_alarm_2] service = AutoscalingService(self.config) - self.loop.run_until_complete(service.evaluate_policy("test_uuid")) + asyncio.run(service.evaluate_policy("test_uuid")) scale.assert_called_with("test_nsr_id", "test_group", "1", "scale_out") def _build_mock_alarm(