From: Dario Faccin Date: Wed, 24 May 2023 14:40:12 +0000 (+0200) Subject: Update from master X-Git-Url: https://osm.etsi.org/gitweb/?a=commitdiff_plain;h=refs%2Fchanges%2F56%2F13456%2F1;p=osm%2FPOL.git Update from master Squashed commit of the following: commit d37c54c64eec65c9a3c490a31eef3a02a76cb474 Author: Mark Beierl Date: Wed May 10 11:15:10 2023 -0400 Updates for Python 3.10 and Ubuntu 22.04 Removes the loop parameter passing Updates dependencies Change-Id: Idf86a86691afe6e1fd92dd2e3ace1955a0680efe Signed-off-by: Mark Beierl commit c72b9d5f574d51608e4810294004414c7a9c02fe Author: garciadeblas Date: Tue Jan 17 16:46:55 2023 +0100 Enable pylint in tox.ini Change-Id: I943fc7fbbe5664bb069f8ac5359d5a90060636ca Signed-off-by: garciadeblas commit f0b82fca0f4a3551e7335d1a4a5c88e5beec3d0b Author: garciadeblas Date: Tue Apr 4 15:29:01 2023 +0200 Clean stage-archive.sh and use allowlist in tox.ini Change-Id: I15fd118f9198f165daf9bb56e5ff32fc1ac15dda Signed-off-by: garciadeblas Change-Id: I9b21a644b62cecb2514de61b5f624bc914d50006 Signed-off-by: Dario Faccin --- diff --git a/Dockerfile b/Dockerfile index c597522..27ab273 100644 --- a/Dockerfile +++ b/Dockerfile @@ -21,7 +21,7 @@ # devops-stages/stage-build.sh # -FROM ubuntu:20.04 +FROM ubuntu:22.04 ARG APT_PROXY RUN if [ ! -z $APT_PROXY ] ; then \ @@ -37,7 +37,9 @@ RUN DEBIAN_FRONTEND=noninteractive apt-get update && \ python3 \ python3-all \ python3-dev \ - python3-setuptools + python3-setuptools \ + python3-pip \ + tox -RUN python3 -m easy_install pip==21.3.1 -RUN pip install tox==3.24.5 +ENV LC_ALL C.UTF-8 +ENV LANG C.UTF-8 diff --git a/devops-stages/stage-archive.sh b/devops-stages/stage-archive.sh index 1514025..d741a4c 100755 --- a/devops-stages/stage-archive.sh +++ b/devops-stages/stage-archive.sh @@ -1,34 +1,22 @@ -# Copyright 2017 Intel Research and Development Ireland Limited -# ************************************************************* - -# This file is part of OSM Monitoring module -# All Rights Reserved to Intel Corporation - -# Licensed under the Apache License, Version 2.0 (the "License"); you may -# not use this file except in compliance with the License. You may obtain -# a copy of the License at - -# http://www.apache.org/licenses/LICENSE-2.0 - -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations -# under the License. - -# For those usages not covered by the Apache License, Version 2.0 please -# contact: prithiv.mohan@intel.com or adrian.hoban@intel.com - -#__author__ = "Prithiv Mohan" -#__date__ = "25/Sep/2017" - - #!/bin/sh +####################################################################################### +# Copyright ETSI Contributors and Others. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or +# implied. +# See the License for the specific language governing permissions and +# limitations under the License. +####################################################################################### rm -rf pool rm -rf dists mkdir -p pool/POL mv deb_dist/*.deb pool/POL/ -mkdir -p dists/unstable/POL/binary-amd64/ -apt-ftparchive packages pool/POL > dists/unstable/POL/binary-amd64/Packages -gzip -9fk dists/unstable/POL/binary-amd64/Packages -echo 'dists/**,pool/POL/*.deb' + diff --git a/osm_policy_module/alarming/service.py b/osm_policy_module/alarming/service.py index dbc375e..fceffda 100644 --- a/osm_policy_module/alarming/service.py +++ b/osm_policy_module/alarming/service.py @@ -22,7 +22,6 @@ # For those usages not covered by the Apache License, Version 2.0 please # contact: bdiaz@whitestack.com or glavado@whitestack.com ## -import asyncio import json import logging import operator @@ -47,14 +46,11 @@ log = logging.getLogger(__name__) class AlarmingService: - def __init__(self, config: Config, loop=None): + def __init__(self, config: Config): self.conf = config - if not loop: - loop = asyncio.get_event_loop() - self.loop = loop self.db_client = CommonDbClient(config) - self.mon_client = MonClient(config, loop=self.loop) - self.lcm_client = LcmClient(config, loop=self.loop) + self.mon_client = MonClient(config) + self.lcm_client = LcmClient(config) async def configure_vnf_alarms(self, nsr_id: str, vnf_member_index=None): log.info("Configuring vnf alarms for network service %s", nsr_id) diff --git a/osm_policy_module/autoscaling/service.py b/osm_policy_module/autoscaling/service.py index 33472fd..fd96da3 100644 --- a/osm_policy_module/autoscaling/service.py +++ b/osm_policy_module/autoscaling/service.py @@ -22,7 +22,6 @@ # For those usages not covered by the Apache License, Version 2.0 please # contact: bdiaz@whitestack.com or glavado@whitestack.com ## -import asyncio import datetime import json import logging @@ -50,14 +49,11 @@ log = logging.getLogger(__name__) class AutoscalingService: - def __init__(self, config: Config, loop=None): + def __init__(self, config: Config): self.conf = config - if not loop: - loop = asyncio.get_event_loop() - self.loop = loop self.db_client = CommonDbClient(config) - self.mon_client = MonClient(config, loop=self.loop) - self.lcm_client = LcmClient(config, loop=self.loop) + self.mon_client = MonClient(config) + self.lcm_client = LcmClient(config) async def configure_scaling_groups(self, nsr_id: str, vnf_member_index=None): """ diff --git a/osm_policy_module/cmd/policy_module_agent.py b/osm_policy_module/cmd/policy_module_agent.py index 43dbc34..1f85cdc 100644 --- a/osm_policy_module/cmd/policy_module_agent.py +++ b/osm_policy_module/cmd/policy_module_agent.py @@ -22,7 +22,6 @@ # contact: bdiaz@whitestack.com or glavado@whitestack.com ## import argparse -import asyncio import logging import sys import os @@ -59,8 +58,7 @@ def main(): db_manager.create_tables() log.info("Database initialized correctly.") log.info("Starting policy module agent...") - loop = asyncio.get_event_loop() - agent = PolicyModuleAgent(cfg, loop) + agent = PolicyModuleAgent(cfg) agent.run() diff --git a/osm_policy_module/common/lcm_client.py b/osm_policy_module/common/lcm_client.py index c94a424..e78420d 100644 --- a/osm_policy_module/common/lcm_client.py +++ b/osm_policy_module/common/lcm_client.py @@ -21,7 +21,6 @@ # For those usages not covered by the Apache License, Version 2.0 please # contact: bdiaz@whitestack.com or glavado@whitestack.com ## -import asyncio import datetime import json import logging @@ -40,12 +39,9 @@ class LcmClient: Client to communicate with LCM through the message bus. """ - def __init__(self, config: Config, loop=None): + def __init__(self, config: Config): self.db_client = CommonDbClient(config) self.msg_bus = MessageBusClient(config) - if not loop: - loop = asyncio.get_event_loop() - self.loop = loop async def scale( self, nsr_id: str, scaling_group_name: str, vnf_member_index: str, action: str diff --git a/osm_policy_module/common/message_bus_client.py b/osm_policy_module/common/message_bus_client.py index 4073d0f..1356dc5 100644 --- a/osm_policy_module/common/message_bus_client.py +++ b/osm_policy_module/common/message_bus_client.py @@ -21,7 +21,6 @@ # For those usages not covered by the Apache License, Version 2.0 please # contact: bdiaz@whitestack.com or glavado@whitestack.com ## -import asyncio from typing import List, Callable from osm_common import msgkafka, msglocal @@ -30,7 +29,7 @@ from osm_policy_module.core.config import Config class MessageBusClient: - def __init__(self, config: Config, loop=None): + def __init__(self, config: Config): if config.get("message", "driver") == "local": self.msg_bus = msglocal.MsgLocal() elif config.get("message", "driver") == "kafka": @@ -40,9 +39,6 @@ class MessageBusClient: "Unknown message bug driver {}".format(config.get("section", "driver")) ) self.msg_bus.connect(config.get("message")) - if not loop: - loop = asyncio.get_event_loop() - self.loop = loop async def aioread(self, topics: List[str], callback: Callable = None, **kwargs): """ @@ -52,7 +48,7 @@ class MessageBusClient: :param kwargs: Keyword arguments to be passed to callback function. :return: None """ - await self.msg_bus.aioread(topics, self.loop, aiocallback=callback, **kwargs) + await self.msg_bus.aioread(topics, aiocallback=callback, **kwargs) async def aiowrite(self, topic: str, key: str, msg: dict): """ @@ -62,7 +58,7 @@ class MessageBusClient: :param msg: Dictionary containing message to be written. :return: None """ - await self.msg_bus.aiowrite(topic, key, msg, self.loop) + await self.msg_bus.aiowrite(topic, key, msg) async def aioread_once(self, topic: str): """ @@ -70,5 +66,5 @@ class MessageBusClient: :param topic: topic to retrieve message from. :return: tuple(topic, key, message) """ - result = await self.msg_bus.aioread(topic, self.loop) + result = await self.msg_bus.aioread(topic) return result diff --git a/osm_policy_module/common/mon_client.py b/osm_policy_module/common/mon_client.py index f9a51cd..d5e8dfc 100644 --- a/osm_policy_module/common/mon_client.py +++ b/osm_policy_module/common/mon_client.py @@ -21,7 +21,6 @@ # For those usages not covered by the Apache License, Version 2.0 please # contact: bdiaz@whitestack.com or glavado@whitestack.com ## -import asyncio import json import logging import random @@ -36,13 +35,10 @@ log = logging.getLogger(__name__) class MonClient: - def __init__(self, config: Config, loop=None): + def __init__(self, config: Config): self.kafka_server = "{}:{}".format( config.get("message", "host"), config.get("message", "port") ) - if not loop: - loop = asyncio.get_event_loop() - self.loop = loop async def create_alarm( self, @@ -69,7 +65,6 @@ class MonClient: ) log.debug("Sending create_alarm_request %s", msg) producer = AIOKafkaProducer( - loop=self.loop, bootstrap_servers=self.kafka_server, key_serializer=str.encode, value_serializer=str.encode, @@ -84,7 +79,6 @@ class MonClient: log.debug("Waiting for create_alarm_response...") consumer = AIOKafkaConsumer( "alarm_response_" + str(cor_id), - loop=self.loop, bootstrap_servers=self.kafka_server, key_deserializer=bytes.decode, value_deserializer=bytes.decode, @@ -119,7 +113,6 @@ class MonClient: ) log.debug("Sending delete_alarm_request %s", msg) producer = AIOKafkaProducer( - loop=self.loop, bootstrap_servers=self.kafka_server, key_serializer=str.encode, value_serializer=str.encode, @@ -134,7 +127,6 @@ class MonClient: log.debug("Waiting for delete_alarm_response...") consumer = AIOKafkaConsumer( "alarm_response_" + str(cor_id), - loop=self.loop, bootstrap_servers=self.kafka_server, key_deserializer=bytes.decode, value_deserializer=bytes.decode, diff --git a/osm_policy_module/core/agent.py b/osm_policy_module/core/agent.py index 2daebde..696f69c 100644 --- a/osm_policy_module/core/agent.py +++ b/osm_policy_module/core/agent.py @@ -48,19 +48,16 @@ ALLOWED_KAFKA_KEYS = [ class PolicyModuleAgent: - def __init__(self, config: Config, loop=None): + def __init__(self, config: Config): self.conf = config - if not loop: - loop = asyncio.get_event_loop() - self.loop = loop self.msg_bus = MessageBusClient(config) self.db_client = CommonDbClient(config) - self.autoscaling_service = AutoscalingService(config, loop) - self.alarming_service = AlarmingService(config, loop) - self.healing_service = HealingService(config, loop) + self.autoscaling_service = AutoscalingService(config) + self.alarming_service = AlarmingService(config) + self.healing_service = HealingService(config) def run(self): - self.loop.run_until_complete(self.start()) + asyncio.run(self.start()) async def start(self): Path("/tmp/osm_pol_agent_health_flag").touch() diff --git a/osm_policy_module/healing/service.py b/osm_policy_module/healing/service.py index 1885d05..7c6739c 100644 --- a/osm_policy_module/healing/service.py +++ b/osm_policy_module/healing/service.py @@ -22,7 +22,6 @@ # For those usages not covered by the Apache License, Version 2.0 please # contact: bdiaz@whitestack.com or glavado@whitestack.com ## -import asyncio import logging import datetime @@ -41,18 +40,15 @@ log = logging.getLogger(__name__) class HealingService: - def __init__(self, config: Config, loop=None): + def __init__(self, config: Config): """ Initializing the HealingService """ log.info("HealingService Initialized") self.conf = config - if not loop: - loop = asyncio.get_event_loop() - self.loop = loop self.db_client = CommonDbClient(config) - self.mon_client = MonClient(config, loop=self.loop) - self.lcm_client = LcmClient(config, loop=self.loop) + self.mon_client = MonClient(config) + self.lcm_client = LcmClient(config) log.info("Constructor created for HealingService") async def configure_healing_alarms(self, nsr_id: str): diff --git a/osm_policy_module/tests/integration/test_policy_agent.py b/osm_policy_module/tests/integration/test_policy_agent.py index 73db304..e96c7e6 100644 --- a/osm_policy_module/tests/integration/test_policy_agent.py +++ b/osm_policy_module/tests/integration/test_policy_agent.py @@ -513,7 +513,7 @@ class PolicyModuleAgentTest(unittest.TestCase): create_alarm.side_effect = _test_configure_scaling_groups_create_alarm create_alarm.assert_not_called_with = assert_not_called_with config = Config() - agent = PolicyModuleAgent(config, self.loop) + agent = PolicyModuleAgent(config) self.loop.run_until_complete( agent.autoscaling_service.configure_scaling_groups("test_nsr_id") ) @@ -581,7 +581,7 @@ class PolicyModuleAgentTest(unittest.TestCase): get_vnfd.return_value = vnfd_record_mock create_alarm.side_effect = _test_configure_vnf_alarms_create_alarm config = Config() - agent = PolicyModuleAgent(config, self.loop) + agent = PolicyModuleAgent(config) self.loop.run_until_complete( agent.alarming_service.configure_vnf_alarms("test_nsr_id") ) @@ -628,7 +628,7 @@ class PolicyModuleAgentTest(unittest.TestCase): get_vnfd.return_value = vnfd_record_mock create_alarm.side_effect = _test_configure_healing_alarms_create_alarm config = Config() - agent = PolicyModuleAgent(config, self.loop) + agent = PolicyModuleAgent(config) self.loop.run_until_complete( agent.healing_service.configure_healing_alarms("test_nsr_id") ) diff --git a/osm_policy_module/tests/unit/alarming/test_alarming_service.py b/osm_policy_module/tests/unit/alarming/test_alarming_service.py index af672e6..65025e5 100644 --- a/osm_policy_module/tests/unit/alarming/test_alarming_service.py +++ b/osm_policy_module/tests/unit/alarming/test_alarming_service.py @@ -38,7 +38,6 @@ from osm_policy_module.core.database import VnfAlarmRepository class TestAlarmingService(TestCase): def setUp(self): self.config = Config() - self.loop = asyncio.new_event_loop() self.payload = {"notify_details": {"alarm_number": 0}} self.headers = {"content-type": "application/json"} @@ -51,9 +50,7 @@ class TestAlarmingService(TestCase): get_alarm.return_value = mock_alarm service = AlarmingService(self.config) if bool(self.config.get("alert", "enhanced_alarms")): - self.loop.run_until_complete( - service.handle_alarm("test_id", "alarm", self.payload) - ) + asyncio.run(service.handle_alarm("test_id", "alarm", self.payload)) requests_post.assert_called_once_with( url="http://alarm-url/", data='{"notify_details": {"alarm_number": 1}}', @@ -62,7 +59,7 @@ class TestAlarmingService(TestCase): timeout=alert_timeout, ) else: - self.loop.run_until_complete(service.handle_alarm("test_id", "alarm", {})) + asyncio.run(service.handle_alarm("test_id", "alarm", {})) requests_post.assert_called_once_with( json="{}", url="http://alarm-url/", timeout=alert_timeout ) @@ -76,9 +73,7 @@ class TestAlarmingService(TestCase): get_alarm.return_value = mock_alarm service = AlarmingService(self.config) if bool(self.config.get("alert", "enhanced_alarms")): - self.loop.run_until_complete( - service.handle_alarm("test_id", "ok", self.payload) - ) + asyncio.run(service.handle_alarm("test_id", "ok", self.payload)) requests_post.assert_called_once_with( url="http://ok-url/", data='{"notify_details": {"alarm_number": 0}}', @@ -87,7 +82,7 @@ class TestAlarmingService(TestCase): timeout=alert_timeout, ) else: - self.loop.run_until_complete(service.handle_alarm("test_id", "ok", {})) + asyncio.run(service.handle_alarm("test_id", "ok", {})) requests_post.assert_called_once_with( json="{}", url="http://ok-url/", timeout=alert_timeout ) @@ -101,7 +96,7 @@ class TestAlarmingService(TestCase): get_alarm.return_value = mock_alarm service = AlarmingService(self.config) if bool(self.config.get("alert", "enhanced_alarms")): - self.loop.run_until_complete( + asyncio.run( service.handle_alarm("test_id", "insufficient-data", self.payload) ) requests_post.assert_called_once_with( @@ -112,9 +107,7 @@ class TestAlarmingService(TestCase): timeout=alert_timeout, ) else: - self.loop.run_until_complete( - service.handle_alarm("test_id", "insufficient-data", {}) - ) + asyncio.run(service.handle_alarm("test_id", "insufficient-data", {})) requests_post.assert_called_once_with( json="{}", url="http://insufficient-data-url/", timeout=alert_timeout ) @@ -126,7 +119,7 @@ class TestAlarmingService(TestCase): mock_alarm = self._build_mock_alarm("test_id") get_alarm.return_value = mock_alarm service = AlarmingService(self.config) - self.loop.run_until_complete(service.handle_alarm("test_id", "unknown", {})) + asyncio.run(service.handle_alarm("test_id", "unknown", {})) requests_post.assert_not_called() def _build_mock_alarm( 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( diff --git a/osm_policy_module/tests/unit/common/test_message_bus_client.py b/osm_policy_module/tests/unit/common/test_message_bus_client.py index 81ca832..8011a04 100644 --- a/osm_policy_module/tests/unit/common/test_message_bus_client.py +++ b/osm_policy_module/tests/unit/common/test_message_bus_client.py @@ -34,39 +34,38 @@ class TestMessageBusClient(TestCase): def setUp(self): self.config = Config() self.config.set("message", "driver", "kafka") - self.loop = asyncio.new_event_loop() @mock.patch.object(MsgKafka, "aioread") def test_aioread(self, aioread): async def mock_callback(): pass - future = asyncio.Future(loop=self.loop) + future = asyncio.Future(loop=asyncio.new_event_loop()) future.set_result("mock") aioread.return_value = future - msg_bus = MessageBusClient(self.config, loop=self.loop) + msg_bus = MessageBusClient(self.config) topic = "test_topic" - self.loop.run_until_complete(msg_bus.aioread([topic], mock_callback)) - aioread.assert_called_with(["test_topic"], self.loop, aiocallback=mock_callback) + asyncio.run(msg_bus.aioread([topic], mock_callback)) + aioread.assert_called_with(["test_topic"], aiocallback=mock_callback) @mock.patch.object(MsgKafka, "aiowrite") def test_aiowrite(self, aiowrite): - future = asyncio.Future(loop=self.loop) + future = asyncio.Future(loop=asyncio.new_event_loop()) future.set_result("mock") aiowrite.return_value = future - msg_bus = MessageBusClient(self.config, loop=self.loop) + msg_bus = MessageBusClient(self.config) topic = "test_topic" key = "test_key" msg = {"test": "test_msg"} - self.loop.run_until_complete(msg_bus.aiowrite(topic, key, msg)) - aiowrite.assert_called_with(topic, key, msg, self.loop) + asyncio.run(msg_bus.aiowrite(topic, key, msg)) + aiowrite.assert_called_with(topic, key, msg) @mock.patch.object(MsgKafka, "aioread") def test_aioread_once(self, aioread): - future = asyncio.Future(loop=self.loop) + future = asyncio.Future(loop=asyncio.new_event_loop()) future.set_result("mock") aioread.return_value = future - msg_bus = MessageBusClient(self.config, loop=self.loop) + msg_bus = MessageBusClient(self.config) topic = "test_topic" - self.loop.run_until_complete(msg_bus.aioread_once(topic)) - aioread.assert_called_with("test_topic", self.loop) + asyncio.run(msg_bus.aioread_once(topic)) + aioread.assert_called_with("test_topic") diff --git a/osm_policy_module/tests/unit/core/test_policy_agent.py b/osm_policy_module/tests/unit/core/test_policy_agent.py index 43bc508..32d88a2 100644 --- a/osm_policy_module/tests/unit/core/test_policy_agent.py +++ b/osm_policy_module/tests/unit/core/test_policy_agent.py @@ -76,7 +76,7 @@ class PolicyAgentTest(unittest.TestCase): pass config = Config() - agent = PolicyModuleAgent(config, self.loop) + agent = PolicyModuleAgent(config) assert autoscaling_lcm_client.called assert autoscaling_mon_client.called assert alarming_lcm_client.called @@ -138,7 +138,7 @@ class PolicyAgentTest(unittest.TestCase): pass config = Config() - agent = PolicyModuleAgent(config, self.loop) + agent = PolicyModuleAgent(config) assert autoscaling_lcm_client.called assert autoscaling_mon_client.called assert alarming_lcm_client.called @@ -191,7 +191,7 @@ class PolicyAgentTest(unittest.TestCase): pass config = Config() - agent = PolicyModuleAgent(config, self.loop) + agent = PolicyModuleAgent(config) assert autoscaling_lcm_client.called assert autoscaling_mon_client.called assert alarming_lcm_client.called @@ -242,7 +242,7 @@ class PolicyAgentTest(unittest.TestCase): pass config = Config() - agent = PolicyModuleAgent(config, self.loop) + agent = PolicyModuleAgent(config) assert autoscaling_lcm_client.called assert autoscaling_mon_client.called assert alarming_lcm_client.called diff --git a/requirements-dev.txt b/requirements-dev.txt index 0304e4f..67d95d8 100644 --- a/requirements-dev.txt +++ b/requirements-dev.txt @@ -22,21 +22,25 @@ async-timeout==4.0.2 # aiokafka dataclasses==0.6 # via -r https://osm.etsi.org/gitweb/?p=osm/common.git;a=blob_plain;f=requirements.txt;hb=paas +dnspython==2.3.0 + # via + # -r https://osm.etsi.org/gitweb/?p=osm/common.git;a=blob_plain;f=requirements.txt;hb=paas + # pymongo kafka-python==2.0.2 # via # -r https://osm.etsi.org/gitweb/?p=osm/common.git;a=blob_plain;f=requirements.txt;hb=paas # aiokafka -motor==1.3.1 +motor==3.1.2 # via -r https://osm.etsi.org/gitweb/?p=osm/common.git;a=blob_plain;f=requirements.txt;hb=paas osm-common @ git+https://osm.etsi.org/gerrit/osm/common.git@paas # via -r requirements-dev.in -packaging==23.0 +packaging==23.1 # via # -r https://osm.etsi.org/gitweb/?p=osm/common.git;a=blob_plain;f=requirements.txt;hb=paas # aiokafka pycryptodome==3.17 # via -r https://osm.etsi.org/gitweb/?p=osm/common.git;a=blob_plain;f=requirements.txt;hb=paas -pymongo==3.13.0 +pymongo==4.3.3 # via # -r https://osm.etsi.org/gitweb/?p=osm/common.git;a=blob_plain;f=requirements.txt;hb=paas # motor diff --git a/requirements-test.txt b/requirements-test.txt index fd0128d..295394e 100644 --- a/requirements-test.txt +++ b/requirements-test.txt @@ -14,9 +14,9 @@ # See the License for the specific language governing permissions and # limitations under the License. ####################################################################################### -coverage==7.1.0 +coverage==7.2.5 # via -r requirements-test.in -mock==5.0.1 +mock==5.0.2 # via -r requirements-test.in -nose2==0.12.0 +nose2==0.13.0 # via -r requirements-test.in diff --git a/requirements.in b/requirements.in index 1f1485e..c083f65 100644 --- a/requirements.in +++ b/requirements.in @@ -14,9 +14,9 @@ # limitations under the License. aiokafka -peewee==3.8.* -jsonschema==2.6.* +peewee +jsonschema pyyaml==5.4.1 -pymysql==0.9.* -peewee-migrate==1.1.* -requests==2.* +pymysql +peewee-migrate +requests diff --git a/requirements.txt b/requirements.txt index 7daf6e1..1690bf4 100644 --- a/requirements.txt +++ b/requirements.txt @@ -18,35 +18,35 @@ aiokafka==0.8.0 # via -r requirements.in async-timeout==4.0.2 # via aiokafka -cached-property==1.5.2 - # via peewee-migrate -certifi==2022.12.7 +attrs==23.1.0 + # via jsonschema +certifi==2023.5.7 # via requests -charset-normalizer==3.0.1 +charset-normalizer==3.1.0 # via requests click==8.1.3 # via peewee-migrate idna==3.4 # via requests -jsonschema==2.6.0 +jsonschema==4.17.3 # via -r requirements.in kafka-python==2.0.2 # via aiokafka -mock==5.0.1 - # via peewee-migrate -packaging==23.0 +packaging==23.1 # via aiokafka -peewee==3.8.2 +peewee==3.16.2 # via # -r requirements.in # peewee-migrate -peewee-migrate==1.1.6 +peewee-migrate==1.7.1 # via -r requirements.in -pymysql==0.9.3 +pymysql==1.0.3 # via -r requirements.in +pyrsistent==0.19.3 + # via jsonschema pyyaml==5.4.1 # via -r requirements.in -requests==2.28.2 +requests==2.30.0 # via -r requirements.in -urllib3==1.26.14 +urllib3==2.0.2 # via requests diff --git a/tox.ini b/tox.ini index 87f7e21..caddd6d 100644 --- a/tox.ini +++ b/tox.ini @@ -23,7 +23,7 @@ toxworkdir = /tmp/.tox [testenv] usedevelop = True -basepython = python3.8 +basepython = python3.10 setenv = VIRTUAL_ENV={envdir} PYTHONDONTWRITEBYTECODE = 1 deps = -r{toxinidir}/requirements.txt @@ -37,12 +37,12 @@ commands = black --check --diff osm_policy_module/ black --check --diff setup.py - ####################################################################################### [testenv:cover] deps = {[testenv]deps} -r{toxinidir}/requirements-dev.txt -r{toxinidir}/requirements-test.txt +allowlist_externals = sh commands = sh -c 'rm -f nosetests.xml' coverage erase @@ -50,8 +50,6 @@ commands = coverage report --omit='*tests*' coverage html -d ./cover --omit='*tests*' coverage xml -o coverage.xml --omit=*tests* -whitelist_externals = sh - ####################################################################################### [testenv:flake8] @@ -59,7 +57,6 @@ deps = flake8 commands = flake8 osm_policy_module/ setup.py - ####################################################################################### [testenv:pylint] deps = {[testenv]deps} @@ -67,8 +64,7 @@ deps = {[testenv]deps} -r{toxinidir}/requirements-test.txt pylint commands = - - pylint -E osm_policy_module - + pylint -E osm_policy_module ####################################################################################### [testenv:safety] @@ -80,12 +76,11 @@ deps = {[testenv]deps} commands = - safety check --full-report - ####################################################################################### [testenv:pip-compile] deps = pip-tools==6.6.2 skip_install = true -whitelist_externals = bash +allowlist_externals = bash [ commands = - bash -c "for file in requirements*.in ; do \ @@ -101,7 +96,7 @@ commands = [testenv:dist] deps = {[testenv]deps} -r{toxinidir}/requirements-dist.txt - +allowlist_externals = sh # In the commands, we copy the requirements.txt to be presented as a source file (.py) # so it gets included in the .deb package for others to consume commands = @@ -109,7 +104,7 @@ commands = python3 setup.py --command-packages=stdeb.command sdist_dsc sh -c 'cd deb_dist/osm-policy-module*/ && dpkg-buildpackage -rfakeroot -uc -us' sh -c 'rm osm_policy_module/requirements.txt' -whitelist_externals = sh + ####################################################################################### [flake8]