# Common database operation implementations
# TODO(QoS): consider handling multiple objects found, or no objects at all
# TODO(QoS): consider changing the name and making it public, officially
-def _find_object(context, model, *kwargs):
+def _find_object(context, model, **kwargs):
with context.session.begin(subtransactions=True):
return (common_db_mixin.model_query(context, model)
.filter_by(**kwargs)
port_id=port_id)
def attach_network(self, network_id):
- qos_db_api.create_policy_network_binding(policy_id=self.id,
+ qos_db_api.create_policy_network_binding(self._context,
+ policy_id=self.id,
network_id=network_id)
def attach_port(self, port_id):
- qos_db_api.create_policy_port_binding(policy_id=self.id,
+ qos_db_api.create_policy_port_binding(self._context,
+ policy_id=self.id,
port_id=port_id)
def detach_network(self, network_id):
# License for the specific language governing permissions and limitations
# under the License.
+from neutron.db import api as db_api
+from neutron.db import models_v2
from neutron.objects.qos import policy
from neutron.tests.unit.objects import test_base
from neutron.tests.unit import testlib_api
class QosPolicyDbObjectTestCase(QosPolicyBaseTestCase,
test_base.BaseDbObjectTestCase,
testlib_api.SqlTestCase):
- pass
+
+ def test_attach_network_get_network_policy(self):
+ obj = policy.QosPolicy(self.context, **self.db_obj)
+ obj.create()
+
+ # TODO(ihrachys): replace with network.create() once we get an object
+ # implementation for networks
+ network = db_api.create_object(self.context, models_v2.Network,
+ {'name': 'test-network1'})
+
+ policy_obj = policy.QosPolicy.get_network_policy(self.context,
+ network['id'])
+ self.assertIsNone(policy_obj)
+
+ # Now attach policy and repeat
+ obj.attach_network(network['id'])
+
+ policy_obj = policy.QosPolicy.get_network_policy(self.context,
+ network['id'])
+ self.assertEqual(obj, policy_obj)
+
+ def test_attach_port_get_port_policy(self):
+ obj = policy.QosPolicy(self.context, **self.db_obj)
+ obj.create()
+
+ # TODO(ihrachys): replace with network.create() once we get an object
+ # implementation for networks
+ network = db_api.create_object(self.context, models_v2.Network,
+ {'name': 'test-network1'})
+
+ # TODO(ihrachys): replace with port.create() once we get an object
+ # implementation for ports
+ port = db_api.create_object(self.context, models_v2.Port,
+ {'name': 'test-port1',
+ 'network_id': network['id'],
+ 'mac_address': 'fake_mac',
+ 'admin_state_up': True,
+ 'status': 'ACTIVE',
+ 'device_id': 'fake_device',
+ 'device_owner': 'fake_owner'})
+
+ policy_obj = policy.QosPolicy.get_port_policy(self.context,
+ port['id'])
+ self.assertIsNone(policy_obj)
+
+ # Now attach policy and repeat
+ obj.attach_port(port['id'])
+
+ policy_obj = policy.QosPolicy.get_port_policy(self.context,
+ port['id'])
+ self.assertEqual(obj, policy_obj)