QoS integration - callbacks should support a list of policies

Patch I1117925360a29ecbd1902fa527b2f24f94ce81ec changed the QoS
callbacks api - instead of a single policy, it now receives a list

Change-Id: Icd598fca250aa6812066a816b82b6930cd8a0283
This commit is contained in:
Adit Sarfaty 2016-08-11 15:08:55 +03:00 committed by garyk
parent d1103e24f2
commit 466bde4b40
7 changed files with 42 additions and 31 deletions

View File

@ -3184,8 +3184,8 @@ class NsxVPluginV2(addr_pair_db.AllowedAddressPairsMixin,
error = _("Configured %s not found") % field error = _("Configured %s not found") % field
raise nsx_exc.NsxPluginException(err_msg=error) raise nsx_exc.NsxPluginException(err_msg=error)
def _handle_qos_notification(self, qos_policy, event_type): def _handle_qos_notification(self, qos_policys, event_type):
qos_utils.handle_qos_notification(qos_policy, event_type, self._dvs) qos_utils.handle_qos_notification(qos_policys, event_type, self._dvs)
def get_az_by_hint(self, hint): def get_az_by_hint(self, hint):
az = self._availability_zones_data.get_availability_zone(hint) az = self._availability_zones_data.get_availability_zone(hint)

View File

@ -90,28 +90,34 @@ class NsxVQosRule(object):
return self return self
def handle_qos_notification(policy_obj, event_type, dvs): def handle_qos_notification(policies_list, event_type, dvs):
# Check if QoS policy rule was created/deleted/updated # Check if QoS policy rule was created/deleted/updated
# Only if the policy rule was updated, we need to update the dvs # Only if the policy rule was updated, we need to update the dvs
if (event_type == callbacks_events.UPDATED and if event_type != callbacks_events.UPDATED:
hasattr(policy_obj, "rules")): return
# Reload the policy as admin so we will have a context for policy_obj in policies_list:
context = n_context.get_admin_context() if hasattr(policy_obj, "rules"):
admin_policy = qos_policy.QosPolicy.get_object( handle_qos_policy_notification(policy_obj, dvs)
context, id=policy_obj.id)
# get all the bound networks of this policy
networks = admin_policy.get_bound_networks()
qos_rule = NsxVQosRule(context=context,
qos_policy_id=policy_obj.id)
for net_id in networks:
# update the new bw limitations for this network def handle_qos_policy_notification(policy_obj, dvs):
net_morefs = nsx_db.get_nsx_switch_ids(context.session, net_id) # Reload the policy as admin so we will have a context
for moref in net_morefs: context = n_context.get_admin_context()
# update the qos restrictions of the network admin_policy = qos_policy.QosPolicy.get_object(
dvs.update_port_groups_config( context, id=policy_obj.id)
net_id, # get all the bound networks of this policy
moref, networks = admin_policy.get_bound_networks()
dvs.update_port_group_spec_qos, qos_rule = NsxVQosRule(context=context,
qos_rule) qos_policy_id=policy_obj.id)
for net_id in networks:
# update the new bw limitations for this network
net_morefs = nsx_db.get_nsx_switch_ids(context.session, net_id)
for moref in net_morefs:
# update the qos restrictions of the network
dvs.update_port_groups_config(
net_id,
moref,
dvs.update_port_group_spec_qos,
qos_rule)

View File

@ -26,4 +26,4 @@ class NsxV3QosNotificationDriver(
""" """
def create_policy(self, context, policy): def create_policy(self, context, policy):
self.notification_api.push(context, policy, events.CREATED) self.notification_api.push(context, [policy], events.CREATED)

View File

@ -32,7 +32,12 @@ LOG = logging.getLogger(__name__)
MAX_KBPS_MIN_VALUE = 1024 MAX_KBPS_MIN_VALUE = 1024
def handle_qos_notification(policy_obj, event_type): def handle_qos_notification(policies_list, event_type):
for policy_obj in policies_list:
handle_qos_policy_notification(policy_obj, event_type)
def handle_qos_policy_notification(policy_obj, event_type):
handler = QosNotificationsHandler() handler = QosNotificationsHandler()
context = n_context.get_admin_context() context = n_context.get_admin_context()

View File

@ -609,7 +609,7 @@ class TestNetworksV2(test_plugin.TestNetworksV2, NsxVPluginV2TestCase):
return_value=fake_policy): return_value=fake_policy):
with mock.patch.object(qos_pol.QosPolicy, "get_bound_networks", with mock.patch.object(qos_pol.QosPolicy, "get_bound_networks",
return_value=[net["id"]]): return_value=[net["id"]]):
plugin._handle_qos_notification(fake_policy, plugin._handle_qos_notification([fake_policy],
callbacks_events.UPDATED) callbacks_events.UPDATED)
# make sure the policy data was read, and the dvs was updated # make sure the policy data was read, and the dvs was updated
self.assertTrue(fake_init_from_policy.called) self.assertTrue(fake_init_from_policy.called)

View File

@ -22,10 +22,10 @@ class DummyNotificationDriver(
message_queue.RpcQosServiceNotificationDriver): message_queue.RpcQosServiceNotificationDriver):
def create_policy(self, context, policy): def create_policy(self, context, policy):
qos_utils.handle_qos_notification(policy, events.CREATED) qos_utils.handle_qos_notification([policy], events.CREATED)
def update_policy(self, context, policy): def update_policy(self, context, policy):
qos_utils.handle_qos_notification(policy, events.UPDATED) qos_utils.handle_qos_notification([policy], events.UPDATED)
def delete_policy(self, context, policy): def delete_policy(self, context, policy):
qos_utils.handle_qos_notification(policy, events.DELETED) qos_utils.handle_qos_notification([policy], events.DELETED)

View File

@ -33,7 +33,7 @@ class DummyNsxVNotificationDriver(
pass pass
def update_policy(self, context, policy): def update_policy(self, context, policy):
qos_utils.handle_qos_notification(policy, events.UPDATED, self._dvs) qos_utils.handle_qos_notification([policy], events.UPDATED, self._dvs)
def delete_policy(self, context, policy): def delete_policy(self, context, policy):
qos_utils.handle_qos_notification(policy, events.DELETED, self._dvs) qos_utils.handle_qos_notification([policy], events.DELETED, self._dvs)