From 3736ad8763cea8da9eedcb45392f97b470a9ad8c Mon Sep 17 00:00:00 2001 From: Benjamin Diaz Date: Wed, 5 Jun 2019 16:24:34 -0300 Subject: [PATCH] Changes vnf_member_index to a string bug 690 Change-Id: I13200cef5039368215a6df2c7f0e93a7de12f2a4 Signed-off-by: Benjamin Diaz --- osm_policy_module/alarming/service.py | 2 +- osm_policy_module/autoscaling/service.py | 6 +- osm_policy_module/common/common_db_client.py | 4 +- osm_policy_module/common/lcm_client.py | 6 +- osm_policy_module/common/mon_client.py | 8 +-- osm_policy_module/core/database.py | 6 +- .../005_change_vnf_index_member_to_str.py | 65 +++++++++++++++++++ 7 files changed, 81 insertions(+), 16 deletions(-) create mode 100644 osm_policy_module/migrations/005_change_vnf_index_member_to_str.py diff --git a/osm_policy_module/alarming/service.py b/osm_policy_module/alarming/service.py index b916724..9be0467 100644 --- a/osm_policy_module/alarming/service.py +++ b/osm_policy_module/alarming/service.py @@ -99,7 +99,7 @@ class AlarmingService: alarm_id=alarm_descriptor['alarm-id'], alarm_uuid=alarm_uuid, nsr_id=nsr_id, - vnf_member_index=int(vnfr['member-vnf-index-ref']), + vnf_member_index=vnfr['member-vnf-index-ref'], vdu_name=vdur['name'] ) for action_type in ['ok', 'insufficient-data', 'alarm']: diff --git a/osm_policy_module/autoscaling/service.py b/osm_policy_module/autoscaling/service.py index 09b78b2..d14904d 100644 --- a/osm_policy_module/autoscaling/service.py +++ b/osm_policy_module/autoscaling/service.py @@ -71,7 +71,7 @@ class AutoscalingService: try: scaling_group_record = ScalingGroupRepository.get( ScalingGroup.nsr_id == nsr_id, - ScalingGroup.vnf_member_index == int(vnfr['member-vnf-index-ref']), + ScalingGroup.vnf_member_index == vnfr['member-vnf-index-ref'], ScalingGroup.name == scaling_group['name'] ) log.debug("Found existing scaling group record in DB...") @@ -203,7 +203,7 @@ class AutoscalingService: alarm = ScalingAlarmRepository.create( alarm_uuid=alarm_uuid, action='scale_in', - vnf_member_index=int(vnfr['member-vnf-index-ref']), + vnf_member_index=vnfr['member-vnf-index-ref'], vdu_name=vdur['name'], scaling_criteria=scaling_criteria_record ) @@ -220,7 +220,7 @@ class AutoscalingService: alarm = ScalingAlarmRepository.create( alarm_uuid=alarm_uuid, action='scale_out', - vnf_member_index=int(vnfr['member-vnf-index-ref']), + vnf_member_index=vnfr['member-vnf-index-ref'], vdu_name=vdur['name'], scaling_criteria=scaling_criteria_record ) diff --git a/osm_policy_module/common/common_db_client.py b/osm_policy_module/common/common_db_client.py index 5731155..accbbfc 100644 --- a/osm_policy_module/common/common_db_client.py +++ b/osm_policy_module/common/common_db_client.py @@ -37,9 +37,9 @@ class CommonDbClient: raise Exception("Unknown database driver {}".format(config.get('section', 'driver'))) self.common_db.db_connect(config.get("database")) - def get_vnfr(self, nsr_id: str, member_index: int): + def get_vnfr(self, nsr_id: str, member_index: str): vnfr = self.common_db.get_one("vnfrs", - {"nsr-id-ref": nsr_id, "member-vnf-index-ref": str(member_index)}) + {"nsr-id-ref": nsr_id, "member-vnf-index-ref": member_index}) return vnfr def get_vnfrs(self, nsr_id: str): diff --git a/osm_policy_module/common/lcm_client.py b/osm_policy_module/common/lcm_client.py index 13ac54e..e8f79cf 100644 --- a/osm_policy_module/common/lcm_client.py +++ b/osm_policy_module/common/lcm_client.py @@ -43,14 +43,14 @@ class LcmClient: loop = asyncio.get_event_loop() self.loop = loop - async def scale(self, nsr_id: str, scaling_group_name: str, vnf_member_index: int, action: str): + async def scale(self, nsr_id: str, scaling_group_name: str, vnf_member_index: str, action: str): log.debug("scale %s %s %s %s", nsr_id, scaling_group_name, vnf_member_index, action) nslcmop = self._generate_nslcmop(nsr_id, scaling_group_name, vnf_member_index, action) self.db_client.create_nslcmop(nslcmop) log.debug("Sending scale action message: %s", json.dumps(nslcmop)) await self.msg_bus.aiowrite("ns", "scale", nslcmop) - def _generate_nslcmop(self, nsr_id: str, scaling_group_name: str, vnf_member_index: int, action: str): + def _generate_nslcmop(self, nsr_id: str, scaling_group_name: str, vnf_member_index: str, action: str): log.debug("_generate_nslcmop %s %s %s %s", nsr_id, scaling_group_name, vnf_member_index, action) _id = str(uuid.uuid4()) now = time.time() @@ -60,7 +60,7 @@ class LcmClient: "scaleVnfType": action.upper(), "scaleByStepData": { "scaling-group-descriptor": scaling_group_name, - "member-vnf-index": str(vnf_member_index) + "member-vnf-index": vnf_member_index } }, "scaleTime": "{}Z".format(datetime.datetime.utcnow().isoformat()) diff --git a/osm_policy_module/common/mon_client.py b/osm_policy_module/common/mon_client.py index 5e91552..19f317d 100644 --- a/osm_policy_module/common/mon_client.py +++ b/osm_policy_module/common/mon_client.py @@ -43,7 +43,7 @@ class MonClient: loop = asyncio.get_event_loop() self.loop = loop - async def create_alarm(self, metric_name: str, ns_id: str, vdu_name: str, vnf_member_index: int, threshold: int, + async def create_alarm(self, metric_name: str, ns_id: str, vdu_name: str, vnf_member_index: str, threshold: int, statistic: str, operation: str): cor_id = random.randint(1, 10e7) msg = self._build_create_alarm_payload(cor_id, @@ -92,7 +92,7 @@ class MonClient: raise ValueError('No alarm deletion response from MON. Is MON up?') return alarm_uuid - async def delete_alarm(self, ns_id: str, vnf_member_index: int, vdu_name: str, alarm_uuid: str): + async def delete_alarm(self, ns_id: str, vnf_member_index: str, vdu_name: str, alarm_uuid: str): cor_id = random.randint(1, 10e7) msg = self._build_delete_alarm_payload(cor_id, ns_id, vdu_name, vnf_member_index, alarm_uuid) log.debug("Sending delete_alarm_request %s", msg) @@ -137,7 +137,7 @@ class MonClient: metric_name: str, ns_id: str, vdu_name: str, - vnf_member_index: int, + vnf_member_index: str, threshold: int, statistic: str, operation: str): @@ -160,7 +160,7 @@ class MonClient: return msg def _build_delete_alarm_payload(self, cor_id: int, ns_id: str, vdu_name: str, - vnf_member_index: int, alarm_uuid: str): + vnf_member_index: str, alarm_uuid: str): alarm_delete_request = { 'correlation_id': cor_id, 'alarm_uuid': alarm_uuid, diff --git a/osm_policy_module/core/database.py b/osm_policy_module/core/database.py index e326ca2..3a89652 100644 --- a/osm_policy_module/core/database.py +++ b/osm_policy_module/core/database.py @@ -48,7 +48,7 @@ class BaseModel(Model): class ScalingGroup(BaseModel): nsr_id = CharField() - vnf_member_index = IntegerField() + vnf_member_index = CharField() name = CharField() content = TextField() @@ -71,7 +71,7 @@ class ScalingCriteria(BaseModel): class ScalingAlarm(BaseModel): alarm_uuid = CharField(unique=True) action = CharField() - vnf_member_index = IntegerField() + vnf_member_index = CharField() vdu_name = CharField() scaling_criteria = ForeignKeyField(ScalingCriteria, related_name='scaling_alarms', on_delete='CASCADE') last_status = CharField(default='insufficient-data') @@ -81,7 +81,7 @@ class VnfAlarm(BaseModel): alarm_id = CharField() alarm_uuid = CharField(unique=True) nsr_id = CharField() - vnf_member_index = IntegerField() + vnf_member_index = CharField() vdu_name = CharField() diff --git a/osm_policy_module/migrations/005_change_vnf_index_member_to_str.py b/osm_policy_module/migrations/005_change_vnf_index_member_to_str.py new file mode 100644 index 0000000..36d2c65 --- /dev/null +++ b/osm_policy_module/migrations/005_change_vnf_index_member_to_str.py @@ -0,0 +1,65 @@ +# -*- coding: utf-8 -*- + +# Copyright 2018 Whitestack, LLC +# ************************************************************* + +# This file is part of OSM Monitoring module +# All Rights Reserved to Whitestack, LLC + +# 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: bdiaz@whitestack.com or glavado@whitestack.com +## +"""Peewee migrations -- 005_change_vnf_index_member_to_str.py. + +Some examples (model - class or model name):: + + > Model = migrator.orm['model_name'] # Return model in current state by name + + > migrator.sql(sql) # Run custom SQL + > migrator.python(func, *args, **kwargs) # Run python code + > migrator.create_model(Model) # Create a model (could be used as decorator) + > migrator.remove_model(model, cascade=True) # Remove a model + > migrator.add_fields(model, **fields) # Add fields to a model + > migrator.change_fields(model, **fields) # Change fields + > migrator.remove_fields(model, *field_names, cascade=True) + > migrator.rename_field(model, old_field_name, new_field_name) + > migrator.rename_table(model, new_table_name) + > migrator.add_index(model, *col_names, unique=False) + > migrator.drop_index(model, *col_names) + > migrator.add_not_null(model, *field_names) + > migrator.drop_not_null(model, *field_names) + > migrator.add_default(model, field_name, default) + +""" + +import peewee as pw + +SQL = pw.SQL + + +def migrate(migrator, database, fake=False, **kwargs): + """Write your migrations here.""" + + migrator.change_fields('scalingalarm', vnf_member_index=pw.CharField(max_length=255)) + migrator.change_fields('vnfalarm', vnf_member_index=pw.CharField(max_length=255)) + migrator.change_fields('scalinggroup', vnf_member_index=pw.CharField(max_length=255)) + + +def rollback(migrator, database, fake=False, **kwargs): + """Write your rollback migrations here.""" + + migrator.change_fields('scalingalarm', vnf_member_index=pw.IntegerField()) + migrator.change_fields('vnfalarm', vnf_member_index=pw.IntegerField()) + migrator.change_fields('scalinggroup', vnf_member_index=pw.IntegerField()) -- 2.25.1