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
This commit is contained in:
Sławek Kapłoński 2017-05-30 23:21:41 +00:00 committed by Slawek Kaplonski
parent 978937da63
commit 09c946910f
3 changed files with 5 additions and 3 deletions

View File

@ -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,

View File

@ -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()

View File

@ -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')