Fix default qos policy when creating network

In _create_network_policy(), policy object is passed into _get_policy_obj()
although it expects to be passed policy id. This patch passes policy id
instead of policy object and adds a unit test and API tests.

Change-Id: Ic4c755c54d93d7ca3312b432b7c1e6770f25c359
Closes-bug: #1712278
diff --git a/neutron/tests/tempest/api/test_qos.py b/neutron/tests/tempest/api/test_qos.py
index 7735710..6a44abb 100644
--- a/neutron/tests/tempest/api/test_qos.py
+++ b/neutron/tests/tempest/api/test_qos.py
@@ -37,6 +37,17 @@
             if driver['name'] == driver_name:
                 return driver
 
+    def _create_project(self):
+        # Add a project to conduct the test
+        test_project = data_utils.rand_name('test_project_')
+        test_description = data_utils.rand_name('desc_')
+        project = self.identity_admin_client.create_project(
+            name=test_project,
+            description=test_description)['project']
+        self.addCleanup(
+            self.identity_admin_client.delete_project, project['id'])
+        return project
+
     @decorators.idempotent_id('108fbdf7-3463-4e47-9871-d07f3dcf5bbb')
     def test_create_policy(self):
         policy = self.create_qos_policy(name='test-policy',
@@ -385,6 +396,37 @@
             self.client.create_qos_policy,
             'test-policy', 'test policy', False)
 
+    @decorators.idempotent_id('18d94f22-b9d5-4390-af12-d30a0cfc4cd3')
+    def test_default_policy_creating_network_without_policy(self):
+        project_id = self._create_project()['id']
+        policy = self.create_qos_policy(name='test-policy',
+                                        tenant_id=project_id,
+                                        is_default=True)
+        network = self.create_network('test network', client=self.admin_client,
+                                      project_id=project_id)
+        self.addCleanup(self._disassociate_network,
+                        self.admin_client, network['id'])
+        retrieved_network = self.admin_client.show_network(network['id'])
+        self.assertEqual(
+            policy['id'], retrieved_network['network']['qos_policy_id'])
+
+    @decorators.idempotent_id('807cce45-38e5-482d-94db-36e1796aba73')
+    def test_default_policy_creating_network_with_policy(self):
+        project_id = self._create_project()['id']
+        self.create_qos_policy(name='test-policy',
+                               tenant_id=project_id,
+                               is_default=True)
+        policy = self.create_qos_policy(name='test-policy',
+                                        tenant_id=project_id)
+        network = self.create_network('test network', client=self.admin_client,
+                                      project_id=project_id,
+                                      qos_policy_id=policy['id'])
+        self.addCleanup(self._disassociate_network,
+                        self.admin_client, network['id'])
+        retrieved_network = self.admin_client.show_network(network['id'])
+        self.assertEqual(
+            policy['id'], retrieved_network['network']['qos_policy_id'])
+
 
 class QosBandwidthLimitRuleTestJSON(base.BaseAdminNetworkTest):