projects
/
osm
/
POL.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Updates for Python 3.10 and Ubuntu 22.04
[osm/POL.git]
/
osm_policy_module
/
tests
/
unit
/
autoscaling
/
test_autoscaling_service.py
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
(file)
--- 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()
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")
@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)
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.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.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()
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)
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")
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
"""
"""
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
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)
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")
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.
"""
"""
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
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)
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")
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
"""
"""
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
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)
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")
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
"""
"""
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
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)
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")
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
"""
"""
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
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)
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")
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.
"""
"""
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
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)
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")
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
"""
"""
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
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)
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")
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
"""
"""
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
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)
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(
scale.assert_called_with("test_nsr_id", "test_group", "1", "scale_out")
def _build_mock_alarm(