-# 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
+#!/bin/bash
-# http://www.apache.org/licenses/LICENSE-2.0
+# Copyright 2017 Intel Research and Development Ireland Limited
+# 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.
+# 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.
+
+echo "Launching tox"
+TOX_PARALLEL_NO_SPINNER=1 tox --parallel=auto
-OUTPUT=$(TOX_PARALLEL_NO_SPINNER=1 tox --parallel=auto)
-printf "$OUTPUT"
)
alarm_action = dict()
for action_type in ["ok", "insufficient-data", "alarm"]:
- if "actions" in alarm_descriptor and action_type in alarm_descriptor["actions"]:
- for url in alarm_descriptor["actions"][action_type]:
+ if (
+ "actions" in alarm_descriptor
+ and action_type in alarm_descriptor["actions"]
+ ):
+ for url in alarm_descriptor["actions"][
+ action_type
+ ]:
if "webhook" in alarm_action:
- alarm_action["webhook"].append(url["url"])
+ alarm_action["webhook"].append(
+ url["url"]
+ )
else:
alarm_action["webhook"] = [url["url"]]
alarm_uuid = await self.mon_client.create_alarm(
nsr_id=nsr_id,
vnf_member_index=vnfr["member-vnf-index-ref"],
vdu_name=vdur["name"],
- last_action='insufficient-data',
+ last_action="insufficient-data",
id_suffix=0,
ok_ack=False,
- alarm_ack=False
+ alarm_ack=False,
)
for action_type in ["ok", "insufficient-data", "alarm"]:
if (
if vnf_member_index is None:
alarm_conditions = VnfAlarm.nsr_id == nsr_id
else:
- query_list = [VnfAlarm.nsr_id == nsr_id,
- VnfAlarm.vnf_member_index == vnf_member_index]
+ query_list = [
+ VnfAlarm.nsr_id == nsr_id,
+ VnfAlarm.vnf_member_index == vnf_member_index,
+ ]
alarm_conditions = functools.reduce(operator.and_, query_list)
for alarm in VnfAlarmRepository.list(alarm_conditions):
log.debug("Deleting vnf alarm %s", alarm.alarm_uuid)
database.db.close()
async def handle_alarm(self, alarm_uuid: str, status: str, payload: dict):
- alert_timeout = int(self.conf.get('alert', 'timeout'))
+ alert_timeout = int(self.conf.get("alert", "timeout"))
database.db.connect()
try:
with database.db.atomic():
If both the status are 'ok', it avoid sending repetitive ok notification.
"""
if action.type == status:
- if bool(self.conf.get('alert', 'enhanced_alarms')):
- if ((status != "ok" or (status == "ok" and alarm.ok_ack is False)) and
- (status != "alarm" or (status == "alarm" and alarm.alarm_ack is False))):
+ if bool(self.conf.get("alert", "enhanced_alarms")):
+ if (
+ status != "ok"
+ or (status == "ok" and alarm.ok_ack is False)
+ ) and (
+ status != "alarm"
+ or (status == "alarm" and alarm.alarm_ack is False)
+ ):
log.info(
"Executing request to url %s for vnf alarm %s with status %s",
action.url,
alarm.alarm_id,
- status
+ status,
)
try:
if status == "alarm" and alarm.last_action == "ok":
except Exception as e:
log.exception(e)
- payload["notify_details"]["alarm_number"] = alarm.id_suffix
+ payload["notify_details"][
+ "alarm_number"
+ ] = alarm.id_suffix
headers = {"content-type": "application/json"}
try:
- resp = requests.post(url=action.url, data=json.dumps(payload),
- headers=headers, verify=False, timeout=alert_timeout)
+ resp = requests.post(
+ url=action.url,
+ data=json.dumps(payload),
+ headers=headers,
+ verify=False,
+ timeout=alert_timeout,
+ )
log.info("Response %s", resp)
if resp.status_code == 200:
if status == "ok":
alarm.alarm_ack = False
alarm.ok_ack = False
alarm.save()
+ except ConnectionError:
+ log.exception(
+ "Error connecting to url %s", action.url
+ )
except RequestException as e:
- log.info("Error: RequestException while connecting to url %s", action.url)
+ log.info(
+ "Error: RequestException while connecting to url %s",
+ action.url,
+ )
log.debug("RequestException %s", e)
- except ConnectionError:
- log.exception("Error connecting to url %s", action.url)
else:
log.info(
"Executing request to url %s for vnf alarm %s with status %s",
action.url,
alarm.alarm_id,
- status
+ status,
)
try:
- requests.post(url=action.url, json=json.dumps(payload), timeout=alert_timeout)
- except RequestException as e:
- log.info("Error: RequestException while connecting to url %s", action.url)
- log.debug("RequestException %s", e)
+ requests.post(
+ url=action.url,
+ json=json.dumps(payload),
+ timeout=alert_timeout,
+ )
except ConnectionError:
log.exception("Error connecting to url %s", action.url)
+ except RequestException as e:
+ log.info(
+ "Error: RequestException while connecting to url %s",
+ action.url,
+ )
+ log.debug("RequestException %s", e)
except VnfAlarm.DoesNotExist:
log.debug(
operation=scaling_criteria[
"scale-in-relational-operation"
],
- action="scale_in"
+ action="scale_in",
)
)
alarm = ScalingAlarmRepository.create(
if vnf_member_index is None:
scale_conditions = ScalingGroup.nsr_id == nsr_id
else:
- query_list = [ScalingGroup.nsr_id == nsr_id,
- ScalingGroup.vnf_member_index == vnf_member_index]
+ query_list = [
+ ScalingGroup.nsr_id == nsr_id,
+ ScalingGroup.vnf_member_index == vnf_member_index,
+ ]
scale_conditions = functools.reduce(operator.and_, query_list)
for scaling_group in ScalingGroupRepository.list(scale_conditions):
for scaling_policy in scaling_group.scaling_policies:
return nslcmop
async def heal(
- self, nsr_id: str, vnfinstance_id: str, vdur_name: str, vdu_id: str,
- vnf_member_index: str, heal_type: str, day1: bool, count_index: int):
+ self,
+ nsr_id: str,
+ vnfinstance_id: str,
+ vdur_name: str,
+ vdu_id: str,
+ vnf_member_index: str,
+ heal_type: str,
+ day1: bool,
+ count_index: int,
+ ):
"""
Sends healing action to LCM through the message bus.
)
nsr = self.db_client.get_nsr(nsr_id)
nslcmop = self._generate_nslcmop_heal(
- nsr_id, vnfinstance_id, vdur_name, vdu_id, vnf_member_index, heal_type, day1,
- count_index, nsr['_admin']
+ nsr_id,
+ vnfinstance_id,
+ vdur_name,
+ vdu_id,
+ vnf_member_index,
+ heal_type,
+ day1,
+ count_index,
+ nsr["_admin"],
)
self.db_client.create_nslcmop(nslcmop)
log.debug("Sending heal action message: %s", json.dumps(nslcmop))
{
"run-day1": day1,
"count-index": count_index,
- "vdu-id": vdu_id
+ "vdu-id": vdu_id,
}
- ]
- }
+ ],
+ },
}
- ]
+ ],
}
nslcmop = {
"nsInstance": "/osm/nslcm/v1/ns_instances/" + nsr_id,
},
"_admin": {
- "projects_read": admin['projects_read'],
- "projects_write": admin['projects_write']
- }
+ "projects_read": admin["projects_read"],
+ "projects_write": admin["projects_write"],
+ },
}
return nslcmop
threshold: int,
operation: str,
statistic: str = "AVERAGE",
- action: str = '',
+ action: str = "",
):
cor_id = random.randint(1, 10e7)
msg = self._build_create_alarm_payload(
log = logging.getLogger(__name__)
-ALLOWED_KAFKA_KEYS = ["instantiated", "scaled", "terminated", "notify_alarm", "policy_updated", "vnf_terminated"]
+ALLOWED_KAFKA_KEYS = [
+ "instantiated",
+ "scaled",
+ "terminated",
+ "notify_alarm",
+ "policy_updated",
+ "vnf_terminated",
+]
class PolicyModuleAgent:
async def _handle_policy_update(self, content):
log.info("_handle_policy_update: %s", content)
- nsr_id = content['nsr_id']
- vnf_member_index = content['vnf_member_index']
+ nsr_id = content["nsr_id"]
+ vnf_member_index = content["vnf_member_index"]
if (
content["operationState"] == "COMPLETED"
or content["operationState"] == "PARTIALLY_COMPLETED"
):
log.info(
"Updating policies of VNF with nsr_id: %s and vnf-member-index: %s"
- % (nsr_id, vnf_member_index))
- await self.autoscaling_service.delete_scaling_groups(nsr_id, vnf_member_index)
+ % (nsr_id, vnf_member_index)
+ )
+ await self.autoscaling_service.delete_scaling_groups(
+ nsr_id, vnf_member_index
+ )
await self.alarming_service.delete_vnf_alarms(nsr_id, vnf_member_index)
- await self.autoscaling_service.configure_scaling_groups(nsr_id, vnf_member_index)
+ await self.autoscaling_service.configure_scaling_groups(
+ nsr_id, vnf_member_index
+ )
await self.alarming_service.configure_vnf_alarms(nsr_id, vnf_member_index)
else:
log.info(
"Network service is not in COMPLETED or PARTIALLY_COMPLETED state. "
"Current state is %s. Skipping...",
- content['operationState'])
+ content["operationState"],
+ )
async def _handle_vnf_terminated(self, content):
- nsr_id = content['nsr_id']
- vnf_member_index = content['vnf_member_index']
+ nsr_id = content["nsr_id"]
+ vnf_member_index = content["vnf_member_index"]
if (
content["operationState"] == "COMPLETED"
or content["operationState"] == "PARTIALLY_COMPLETED"
):
log.info(
"Deleting policies of VNF with nsr_id: %s and vnf-member-index: %s"
- % (nsr_id, vnf_member_index))
- await self.autoscaling_service.delete_scaling_groups(nsr_id, vnf_member_index)
+ % (nsr_id, vnf_member_index)
+ )
+ await self.autoscaling_service.delete_scaling_groups(
+ nsr_id, vnf_member_index
+ )
await self.alarming_service.delete_vnf_alarms(nsr_id, vnf_member_index)
else:
log.info(
"Network service is not in COMPLETED or PARTIALLY_COMPLETED state. "
"Current state is %s. Skipping...",
- content['operationState'])
+ content["operationState"],
+ )
nsr_id = CharField()
vnf_member_index = CharField()
vdu_name = CharField()
- last_action = CharField(default='insufficient-data')
+ last_action = CharField(default="insufficient-data")
id_suffix = IntegerField()
ok_ack = BooleanField(default=False)
alarm_ack = BooleanField(default=False)
cooldown_time = IntegerField()
count_index = IntegerField()
last_heal = DateTimeField(default=datetime.datetime.now)
- last_status = CharField(default='insufficient-data')
+ last_status = CharField(default="insufficient-data")
day1 = BooleanField(default=False)
class ScalingAlarmRepository:
@staticmethod
def list(*expressions) -> Iterable[ScalingAlarm]:
- return ScalingAlarm.select().where(*expressions)
+ return ScalingAlarm.select().where(*expressions).__iter__()
@staticmethod
def get(*expressions, join_classes: List = None) -> ScalingAlarm:
class ScalingGroupRepository:
@staticmethod
def list(*expressions) -> Iterable[ScalingGroup]:
- return ScalingGroup.select().where(*expressions)
+ return ScalingGroup.select().where(*expressions).__iter__()
@staticmethod
def get(*expressions) -> ScalingGroup:
if join_classes:
for join_class in join_classes:
query = query.join(join_class)
- return query.where(*expressions)
+ return query.where(*expressions).__iter__()
@staticmethod
def get(*expressions, join_classes: List = None) -> ScalingPolicy:
if join_classes:
for join_class in join_classes:
query = query.join(join_class)
- return query.where(*expressions)
+ return query.where(*expressions).__iter__()
@staticmethod
def get(*expressions, join_classes: List = None) -> ScalingCriteria:
class VnfAlarmRepository:
@staticmethod
def list(*expressions) -> Iterable[VnfAlarm]:
- return VnfAlarm.select().where(*expressions)
+ return VnfAlarm.select().where(*expressions).__iter__()
@staticmethod
def get(*expressions) -> VnfAlarm:
class AlarmActionRepository:
@staticmethod
def list(*expressions) -> Iterable[AlarmAction]:
- return AlarmAction.select().where(*expressions)
+ return AlarmAction.select().where(*expressions).__iter__()
@staticmethod
def get(*expressions) -> AlarmAction:
class HealingActionRepository:
@staticmethod
def list(*expressions) -> Iterable[HealingAction]:
- log.info("### Printing healing action db alarm {}".format(HealingAction.select().where(*expressions)))
- return HealingAction.select().where(*expressions)
+ log.info(
+ "### Printing healing action db alarm {}".format(
+ HealingAction.select().where(*expressions)
+ )
+ )
+ return HealingAction.select().where(*expressions).__iter__()
@staticmethod
def get(*expressions) -> HealingAction:
class HealingService:
def __init__(self, config: Config, loop=None):
"""
- Initializing the HealingService
+ Initializing the HealingService
"""
log.info("HealingService Initialized")
self.conf = config
async def configure_healing_alarms(self, nsr_id: str):
"""
- Configuring the Healing alarms
- :param nsr_id: Network service record id
+ Configuring the Healing alarms
+ :param nsr_id: Network service record id
"""
log.info("Configuring Healing alarm for NS %s", nsr_id)
alarms_created = []
with database.db.atomic():
vnfrs = self.db_client.get_vnfrs(nsr_id)
for vnfr in vnfrs:
- vnfd = self.db_client.get_vnfd(vnfr['vnfd-id'])
+ vnfd = self.db_client.get_vnfd(vnfr["vnfd-id"])
df = vnfd.get("df", [{}])[0]
if "healing-aspect" not in df:
log.info("No healing configuration present in vnfd")
continue
healing_aspects = df["healing-aspect"]
for healing_aspect in healing_aspects:
- for healing_policy in healing_aspect.get(
- "healing-policy", ()
- ):
- vdu_id = healing_policy['vdu-id']
+ for healing_policy in healing_aspect.get("healing-policy", ()):
+ vdu_id = healing_policy["vdu-id"]
for vdur in vnfr["vdur"]:
if vdu_id == vdur["vdu-id-ref"]:
try:
HealingActionRepository.get(
- HealingAction.alarm_id == healing_policy['event-name'],
- HealingAction.vdur_name == vdur['name'],
+ HealingAction.alarm_id
+ == healing_policy["event-name"],
+ HealingAction.vdur_name == vdur["name"],
HealingAction.nsr_id == nsr_id,
- HealingAction.cooldown_time == healing_policy['cooldown-time'],
- HealingAction.recovery_action == healing_policy['action-on-recovery'],
- HealingAction.vnfinstance_id == vnfr['id'],
- HealingAction.vdu_id == healing_policy['vdu-id'],
- HealingAction.count_index == vdur['count-index']
+ HealingAction.cooldown_time
+ == healing_policy["cooldown-time"],
+ HealingAction.recovery_action
+ == healing_policy["action-on-recovery"],
+ HealingAction.vnfinstance_id == vnfr["id"],
+ HealingAction.vdu_id
+ == healing_policy["vdu-id"],
+ HealingAction.count_index
+ == vdur["count-index"],
+ )
+ log.debug(
+ "vdu %s already has an alarm configured with same id %s",
+ healing_policy["vdu-id"],
+ healing_policy["event-name"],
)
- log.debug("vdu %s already has an alarm configured with same id %s",
- healing_policy['vdu-id'], healing_policy['event-name'])
continue
except HealingAction.DoesNotExist:
pass
alarm_uuid = await self.mon_client.create_alarm(
metric_name=metric_name,
ns_id=nsr_id,
- vdu_name=vdur['name'],
- vnf_member_index=vnfr[
- 'member-vnf-index-ref'
- ],
+ vdu_name=vdur["name"],
+ vnf_member_index=vnfr["member-vnf-index-ref"],
threshold=1,
operation="LT",
- statistic="AVERAGE"
+ statistic="AVERAGE",
)
alarm = HealingActionRepository.create(
- alarm_id=healing_policy['event-name'],
+ alarm_id=healing_policy["event-name"],
alarm_uuid=alarm_uuid,
nsr_id=nsr_id,
- vnf_member_index=vnfr[
- 'member-vnf-index-ref'
+ vnf_member_index=vnfr["member-vnf-index-ref"],
+ vdur_name=vdur["name"],
+ recovery_action=healing_policy[
+ "action-on-recovery"
],
- vdur_name=vdur['name'],
- recovery_action=healing_policy['action-on-recovery'],
- cooldown_time=healing_policy['cooldown-time'],
- day1=healing_policy['day1'],
- vdu_id=healing_policy['vdu-id'],
- vnfinstance_id=vnfr['id'],
- count_index=vdur['count-index']
+ cooldown_time=healing_policy["cooldown-time"],
+ day1=healing_policy["day1"],
+ vdu_id=healing_policy["vdu-id"],
+ vnfinstance_id=vnfr["id"],
+ count_index=vdur["count-index"],
)
alarms_created.append(alarm)
if len(alarms_created) > 0:
for alarm in alarms_created:
try:
- await self.mon_client.delete_alarm(alarm.nsr_id,
- alarm.vnf_member_index,
- alarm.vdu_name,
- alarm.alarm_uuid)
+ await self.mon_client.delete_alarm(
+ alarm.nsr_id,
+ alarm.vnf_member_index,
+ alarm.vdu_name,
+ alarm.alarm_uuid,
+ )
except ValueError:
- log.exception("Error deleting alarm in MON %s", alarm.alarm_uuid)
+ log.exception(
+ "Error deleting alarm in MON %s", alarm.alarm_uuid
+ )
raise e
finally:
database.db.close()
):
try:
self.db_client.get_vdur(
- nsr_id,
- alarm.vnf_member_index,
- alarm.vdur_name
+ nsr_id, alarm.vnf_member_index, alarm.vdur_name
)
except VdurNotFound:
- log.info(
- "Deleting orphaned alarm %s",
- alarm.alarm_uuid
- )
+ log.info("Deleting orphaned alarm %s", alarm.alarm_uuid)
try:
await self.mon_client.delete_alarm(
alarm.nsr_id,
alarm.vnf_member_index,
alarm.vdur_name,
- alarm.alarm_uuid
+ alarm.alarm_uuid,
)
except ValueError:
log.exception(
- "Error deleting alarm in MON %s",
- alarm.alarm_uuid
+ "Error deleting alarm in MON %s", alarm.alarm_uuid
)
alarm.delete_instance()
async def delete_healing_alarms(self, nsr_id):
"""
- Deleting the healing alarms
- :param nsr_id: Network service record id
+ Deleting the healing alarms
+ :param nsr_id: Network service record id
"""
log.info("Deleting healing vnf alarms for network service %s", nsr_id)
database.db.connect()
alarm.nsr_id,
alarm.vnf_member_index,
alarm.vdur_name,
- alarm.alarm_uuid
+ alarm.alarm_uuid,
)
except ValueError:
log.exception(
- "Error deleting alarm in MON %s",
- alarm.alarm_uuid
+ "Error deleting alarm in MON %s", alarm.alarm_uuid
)
alarm.delete_instance()
async def update_alarm_status(self, alarm_uuid: str, status: str):
"""
- For updating the alarm status
- :param alarm_uuid: vdu uuid
- :param status: Status of an alarm
+ For updating the alarm status
+ :param alarm_uuid: vdu uuid
+ :param status: Status of an alarm
"""
database.db.connect()
try:
alarm.last_status = status
alarm.save()
except HealingAction.DoesNotExist:
- log.debug(
- "There is no healing action configured for alarm %s.", alarm_uuid
- )
+ log.debug("There is no healing action configured for alarm %s.", alarm_uuid)
finally:
database.db.close()
async def handle_alarm(self, alarm_uuid: str, status: str):
"""
- For Handling the healing alarms
- :param alarm_uuid: vdu uuid
- :param status: Status of an alarm
+ For Handling the healing alarms
+ :param alarm_uuid: vdu uuid
+ :param status: Status of an alarm
"""
await self.update_alarm_status(alarm_uuid, status)
database.db.connect()
vnfinstance_id = alarm.vnfinstance_id
alarms = HealingActionRepository.list(
HealingAction.vnf_member_index == vnf_member_index,
- HealingAction.vdur_name == vdur_name
+ HealingAction.vdur_name == vdur_name,
)
statuses = []
for alarm in alarms:
statuses.append(alarm.last_status)
- if ((set(statuses) == {'alarm'}) or ('alarm' in statuses)):
+ if (set(statuses) == {"alarm"}) or ("alarm" in statuses):
delta = datetime.datetime.now() - last_heal
if delta.total_seconds() > cooldown_time:
await self.lcm_client.heal(
vnf_member_index,
heal_type,
day1,
- count_index
+ count_index,
)
last_heal = datetime.datetime.now()
log.info("datetime.datetime.now %s", datetime.datetime.now)
alarm.save()
except HealingAction.DoesNotExist:
- log.info(
- "There is no healing action configured for alarm %s.",
- alarm_uuid
- )
+ log.info("There is no healing action configured for alarm %s.", alarm_uuid)
finally:
database.db.close()
cooldown_time = pw.IntegerField()
count_index = pw.IntegerField()
last_heal = pw.DateTimeField()
- last_status = pw.CharField(max_length=255, default='insufficient-data')
+ last_status = pw.CharField(max_length=255, default="insufficient-data")
day1 = pw.BooleanField(default=False)
class Meta:
def rollback(migrator, database, fake=False, **kwargs):
"""Write your rollback migrations here."""
- migrator.remove_model('healingaction')
+ migrator.remove_model("healingaction")
"recovery-type": "automatic",
"action-on-recovery": "REDEPLOY_ONLY",
"cooldown-time": 180,
- "day1": False
+ "day1": False,
}
],
}
vnf_member_index="1",
threshold=20.0,
operation="LT",
- action="{'webhook': ['localhost:9090', 'localhost:9090', 'localhost:9090']}"
+ action="{'webhook': ['localhost:9090', 'localhost:9090', 'localhost:9090']}",
)
create_alarm.assert_any_call(
metric_name="average_memory_utilization",
vnf_member_index="2",
threshold=20.0,
operation="LT",
- action="{'webhook': ['localhost:9090', 'localhost:9090', 'localhost:9090']}"
+ action="{'webhook': ['localhost:9090', 'localhost:9090', 'localhost:9090']}",
)
@patch.object(DbMongo, "db_connect", Mock())
def setUp(self):
self.config = Config()
self.loop = asyncio.new_event_loop()
- self.payload = {
- "notify_details": {
- "alarm_number": 0
- }
- }
+ self.payload = {"notify_details": {"alarm_number": 0}}
self.headers = {"content-type": "application/json"}
@mock.patch.object(VnfAlarmRepository, "get")
@mock.patch("requests.post")
@mock.patch("osm_policy_module.core.database.db")
def test_handle_alarm_suppression(self, database, requests_post, get_alarm):
- alert_timeout = int(self.config.get('alert', 'timeout'))
+ alert_timeout = int(self.config.get("alert", "timeout"))
mock_alarm = self._build_mock_alarm("test_id", last_action="ok")
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))
+ if bool(self.config.get("alert", "enhanced_alarms")):
+ self.loop.run_until_complete(
+ service.handle_alarm("test_id", "alarm", self.payload)
+ )
requests_post.assert_called_once_with(
- url='http://alarm-url/', data='{"notify_details": {"alarm_number": 1}}',
- headers={'content-type': 'application/json'}, verify=False, timeout=alert_timeout
+ url="http://alarm-url/",
+ data='{"notify_details": {"alarm_number": 1}}',
+ headers={"content-type": "application/json"},
+ verify=False,
+ timeout=alert_timeout,
)
else:
self.loop.run_until_complete(service.handle_alarm("test_id", "alarm", {}))
- requests_post.assert_called_once_with(json="{}", url="http://alarm-url/", timeout=alert_timeout)
+ requests_post.assert_called_once_with(
+ json="{}", url="http://alarm-url/", timeout=alert_timeout
+ )
@mock.patch.object(VnfAlarmRepository, "get")
@mock.patch("requests.post")
@mock.patch("osm_policy_module.core.database.db")
def test_handle_ok_suppression(self, database, requests_post, get_alarm):
- alert_timeout = int(self.config.get('alert', 'timeout'))
+ alert_timeout = int(self.config.get("alert", "timeout"))
mock_alarm = self._build_mock_alarm("test_id", last_action="alarm")
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))
- requests_post.assert_called_once_with(
- url='http://ok-url/', data='{"notify_details": {"alarm_number": 0}}',
- headers={'content-type': 'application/json'}, verify=False, timeout=alert_timeout
+ if bool(self.config.get("alert", "enhanced_alarms")):
+ self.loop.run_until_complete(
+ service.handle_alarm("test_id", "ok", self.payload)
+ )
+ requests_post.assert_called_once_with(
+ url="http://ok-url/",
+ data='{"notify_details": {"alarm_number": 0}}',
+ headers={"content-type": "application/json"},
+ verify=False,
+ timeout=alert_timeout,
)
else:
self.loop.run_until_complete(service.handle_alarm("test_id", "ok", {}))
- requests_post.assert_called_once_with(json="{}", url="http://ok-url/", timeout=alert_timeout)
+ requests_post.assert_called_once_with(
+ json="{}", url="http://ok-url/", timeout=alert_timeout
+ )
@mock.patch.object(VnfAlarmRepository, "get")
@mock.patch("requests.post")
@mock.patch("osm_policy_module.core.database.db")
def test_handle_insufficientalarm(self, database, requests_post, get_alarm):
- alert_timeout = int(self.config.get('alert', 'timeout'))
+ alert_timeout = int(self.config.get("alert", "timeout"))
mock_alarm = self._build_mock_alarm("test_id")
get_alarm.return_value = mock_alarm
service = AlarmingService(self.config)
- if bool(self.config.get('alert', 'enhanced_alarms')):
+ if bool(self.config.get("alert", "enhanced_alarms")):
self.loop.run_until_complete(
service.handle_alarm("test_id", "insufficient-data", self.payload)
)
requests_post.assert_called_once_with(
- url='http://insufficient-data-url/', data='{"notify_details": {"alarm_number": 0}}',
- headers={'content-type': 'application/json'}, verify=False, timeout=alert_timeout
+ url="http://insufficient-data-url/",
+ data='{"notify_details": {"alarm_number": 0}}',
+ headers={"content-type": "application/json"},
+ verify=False,
+ timeout=alert_timeout,
)
else:
self.loop.run_until_complete(
service.handle_alarm("test_id", "insufficient-data", {})
)
requests_post.assert_called_once_with(
- json="{}", url='http://insufficient-data-url/', timeout=alert_timeout
+ json="{}", url="http://insufficient-data-url/", timeout=alert_timeout
)
@mock.patch.object(VnfAlarmRepository, "get")
insufficient_data_url="http://insufficient-data-url/",
ok_url="http://ok-url/",
id_suffix=0,
- last_action="insufficient-data"
+ last_action="insufficient-data",
):
mock_alarm = mock.Mock()
mock_alarm.alarm_id = alarm_id
content = {
"nsr_id": "test_nsr_id",
"vnf_member_index": "1",
- "operationState": "COMPLETED"
+ "operationState": "COMPLETED",
}
failed_content = {
"nsr_id": "test_nsr_id",
"vnf_member_index": "1",
- "operationState": "FAILED"
+ "operationState": "FAILED",
}
configure_scaling_groups.side_effect = mock_configure_scaling_groups
configure_vnf_alarms.side_effect = mock_configure_vnf_alarms
content = {
"nsr_id": "test_nsr_id",
"vnf_member_index": "1",
- "operationState": "COMPLETED"
+ "operationState": "COMPLETED",
}
failed_content = {
"nsr_id": "test_nsr_id",
"vnf_member_index": "1",
- "operationState": "FAILED"
+ "operationState": "FAILED",
}
delete_scaling_groups.side_effect = mock_delete_scaling_groups
delete_vnf_alarms.side_effect = mock_delete_vnf_alarms
"test_vnf_member_index",
"test_heal_type",
"test_day1",
- "test_count_index"
+ "test_count_index",
)
def _build_mock_alarm(
setenv = VIRTUAL_ENV={envdir}
PYTHONDONTWRITEBYTECODE = 1
deps = -r{toxinidir}/requirements.txt
+parallel_show_output = true
#######################################################################################
[testenv:black]
deps = black
skip_install = true
commands =
- - black --check --diff osm_policy_module/
- - black --check --diff setup.py
+ black --check --diff osm_policy_module/
+ black --check --diff setup.py
#######################################################################################
-r{toxinidir}/requirements-test.txt
pylint
commands =
- pylint -E osm_policy_module
+ - pylint -E osm_policy_module
#######################################################################################
ignore =
W291,
W293,
+ W503,
E123,
E125,
E226,