From 09c946910f3ab2646a3fa3e7d1d3bfadbd1428d0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C5=82awek=20Kap=C5=82o=C5=84ski?= Date: Tue, 30 May 2017 23:21:41 +0000 Subject: [PATCH] Fix updating Qos policy to be default/not default During QoS policy update there was no project_id attribute loaded to QoS object. That caused problem with updating policy object because "get_default()" method requires project_id. This patch fixes it by first getting QoS policy object and then update it. Additionally there was mistake in assertion in QoS Default policy fullstack test and this patch fixes it also. Change-Id: I57011bd4d40479855203061554090d19bb668960 Closes-Bug: 1694553 --- neutron/services/qos/qos_plugin.py | 2 +- neutron/tests/fullstack/test_qos.py | 2 +- neutron/tests/unit/services/qos/test_qos_plugin.py | 4 +++- 3 files changed, 5 insertions(+), 3 deletions(-) diff --git a/neutron/services/qos/qos_plugin.py b/neutron/services/qos/qos_plugin.py index 0da98691ceb..8b61fbceab3 100644 --- a/neutron/services/qos/qos_plugin.py +++ b/neutron/services/qos/qos_plugin.py @@ -186,7 +186,7 @@ class QoSPlugin(qos.QoSPluginBase): """ policy_data = policy['policy'] with db_api.context_manager.writer.using(context): - policy_obj = policy_object.QosPolicy(context, id=policy_id) + policy_obj = self._get_policy_obj(context, policy_id) policy_obj.update_fields(policy_data, reset_changes=True) policy_obj.update() self.driver_manager.call(qos_consts.UPDATE_POLICY_PRECOMMIT, diff --git a/neutron/tests/fullstack/test_qos.py b/neutron/tests/fullstack/test_qos.py index 1f5d2376b73..039d4945be7 100644 --- a/neutron/tests/fullstack/test_qos.py +++ b/neutron/tests/fullstack/test_qos.py @@ -330,7 +330,7 @@ class TestQoSPolicyIsDefault(base.BaseFullStackTestCase): qos_policy = self._create_qos_policy(project_id, True) self.assertTrue(qos_policy['is_default']) qos_policy = self._update_qos_policy(qos_policy['id'], False) - self.assertTrue(qos_policy['policy']['is_default']) + self.assertFalse(qos_policy['policy']['is_default']) def test_update_default_status_conflict(self): project_id = uuidutils.generate_uuid() diff --git a/neutron/tests/unit/services/qos/test_qos_plugin.py b/neutron/tests/unit/services/qos/test_qos_plugin.py index 1dfa37c283e..5b0529383f6 100644 --- a/neutron/tests/unit/services/qos/test_qos_plugin.py +++ b/neutron/tests/unit/services/qos/test_qos_plugin.py @@ -359,12 +359,14 @@ class TestQosPlugin(base.BaseQosTestCase): QosMocked.assert_called_once_with(self.ctxt, **policy_details) + @mock.patch.object(policy_object.QosPolicy, "get_object") @mock.patch( 'neutron.objects.rbac_db.RbacNeutronDbObjectMixin' '.create_rbac_policy') @mock.patch.object(policy_object.QosPolicy, 'update') def test_update_policy(self, mock_qos_policy_update, - mock_create_rbac_policy): + mock_create_rbac_policy, mock_qos_policy_get): + mock_qos_policy_get.return_value = self.policy mock_manager = mock.Mock() mock_manager.attach_mock(mock_qos_policy_update, 'update') mock_manager.attach_mock(self.qos_plugin.driver_manager, 'driver')