Verify ML2 type driver exists before calling del

Verifies that an ML2 type driver exists for a given
segment type before attempting to call the release_segment
method on it. Logs an error if a type driver is not
found.

This covers the case where a segment is created with
a given type and then ML2 is reconfigured without
support for that type.

DocImpact
The ML2 documentation should be updated with a warning
that disabling a network type driver and re-enabling
it later may lead to possible DB inconsistencies.

Closes-Bug: #1292102
Change-Id: I65a35abf3ed57347bb6e8fee228f8c0697217c00
(cherry picked from commit af89d74d2961db6a04572375150ad908c9e72e78)
Fixes Hyper-V issue due to ML2 RPC versioning

The ML2 RPC version 1.1 breaks the hyper-v agent and
consequentially the RPC version in the Hyper-V agent needs
to be set to 1.1 to match the ML2 RPC base API version.

Conflicts:
	neutron/plugins/hyperv/agent/hyperv_neutron_agent.py

(cherry picked from commit 771327adbe9e563506f98ca561de9ded4d987698)

Change-Id: Idc4ae8d7dcff4331aca148a8f2a7a2b01679b3a8
Closes-Bug: #1353697
Fixes Hyper-V agent issue on Hyper-V 2008 R2

The vmutils.HyperVUtils class used on versions of Hyper-V prior of 2012
is missing the "remove_all_security_rules" method.

Change-Id: Ib14e643c400b230c912589f9480acf59d6e7b147
Closes-Bug: #1360817
Increase the default poll duration for Cisco n1kv

Increase the poll duration for Cisco N1Kv, from 10s to 60s and also
clean up the /etc/neutron/plugins/cisco/cisco_plugins.ini file. The
current poll duration of 10s causes that VSM to unnecessarily taking
frequent CPU cycles, resulting in the failure of other tasks in scale
configurations.

Closes-Bug: 1357030
(cherry picked from commit 6e08e477a9cb46b1d371c2c9812e5ce9f4cf69be)

Conflicts:
	etc/neutron/plugins/cisco/cisco_plugins.ini
	neutron/plugins/cisco/common/config.py

Change-Id: I95747f35bae5b7157391c1698c0fe84d2126aa10
Allow unsharing a network used as gateway/floatingip

If network has ports that connect it as gateway to another network, such
as an external network, or "floating ip" ports it should still be
possible to "unshare" it since these ports represent usage of the
network as an external network, not as a VM data network.

Change-Id: Ic33ae7ac193e4fc9fe06a4cfd579a4aacf0e6354
Closes-bug: #1293184
(cherry picked from commit 7a2053c7a27bdec02e97b46736c5fcce5f2d053a)
Datacenter moid should not be tuple

Remove the comma, because it will convert the string to tuple
Closes-bug: #1362480

Change-Id: I2debb76bae26fe3d437a431f2946f66a1cbe6851
(cherry picked from commit ace3a01ebf980c166b4dfe6d1216b17bf0aec2ed)
Perform policy checks only once on list responses

The policy engine is currently being called for every attribute
of every resource to be returned by a list response. This is
harming the API performance; moreover such a high number of checks
is also unnecessary.

This patch therefore slightly changes the API logic so that list
response first determine the list of attributes which should be
returned querying the policy engine and then use this list for
all resource items to be returned.

To this aim a few methods in base.py needed to be refactored.
This patch also removes the routine check_if_exists from policy.py
and the related PolicyNotFound exception.

Finally, this patch also removes unnecessary admin_or_owner rules
when applied to attributes. This kind of rule indeed has no effect
anyway because of Neutron's ownership checks. The rules were removed
because this change won't allow anymore for having attribute-level
policies whose evaluation result depends on the resource value.

Implements blueprint faster-list-responses

Change-Id: I21b8273add5d5984f512ad94af5a99cf0b0a5d93
(cherry picked from commit 9b2b5e1482ebec818556946230066984bf647186)
Call policy.init() once per API request

This patch changes the policy engine behaviour and the API base
controller in order to ensure policy.init is invoked only once
for each API request.
This will avoid issues arising from policy file updates during
API processing and speed up response generation for list operations,
by about 5%.

This patch also removes an obsolete TODO comment.

Change-Id: I108ebd26fccdea19cb00959f70d87c3bc1587df9
Closes-Bug: 1302611
(cherry picked from commit 1d41ba485f060a4d6dbe0767845391f955247b08)
Pass object to policy when finding fields to strip

During the evaluation of fields to strip in responses to list
operations, pass also the first object in the list to the
policy engine.
This will avoid errors in policy evaluation if during
an upgrade from icehouse policy.json was not updated to remove
attribute-level policies dependent on resource values.

Closes-Bug: #1323715

Change-Id: Iaa6ed3bbf4a07ce0b614a4197cabdfa1cb36d427
(cherry picked from commit 2bd97d205b98292be709b0257bda5fc489eb643a)
Cisco N1kv plugin to send subtype on network profile creation

Make sure that the cisco n1kv neutron plugin sends the sub_type too
when a overlay network profile is created

Change-Id: I37e63131039077fa80a28fe725c09f0307acc2ea
Closes-Bug: 1357125
(cherry picked from commit e6ffc08de72a21980cde38d1a716d429311f7819)
Add BSN plugin to agent migration script

Adds the Big Switch plugin to the migration script that creates
the agents table. A recent commit (d3be7b040eaa61a4d0ac617026cf5c9132d3831e)
added it to the agent tables but it missed this one so an error was thrown
during migration when it reached a table that depended on the agents table.

Closes-Bug: #1340405
Change-Id: I90a164a1b632c3794a7f7607f3f1da8f7d7b15db
(cherry picked from commit 2dd0a22fd6cc38cc27942572c8a19bf6a52fb32b)
Merge "Call policy.init() once per API request" into stable/icehouse
Neutron should not use the neutronclient utils module for import_class

Fixes code to use openstack.common.importutils instead.

Conflicts:
	neutron/debug/shell.py

Change-Id: Ia449f8b1d7d03f37483cfdc595ad77e71ea6598c
Closes-bug: 1366917
(cherry picked from commit dbc9c0c799bcbfa378cee3ea1e428d4a41547db7)
NSX: Correct allowed_address_pair return value on create_port

This patch fixes the NSX plugin to return [] rather than None for a
port does not have any allowed_address_pairs when a create_port api
call is made. Currently the NSX plugin is failing every patch because
now tempest is checking for this value to be [].

Change-Id: Ic82c564ff62000c367c544f44a76694be9375790
Closes-bug: 1366921
(cherry picked from commit 1361ad99969d2a729599720f06f8373db230e0ed)
Merge "Perform policy checks only once on list responses" into stable/icehouse
Merge "Pass object to policy when finding fields to strip" into stable/icehouse
Fix metadata agent's auth info caching

metadata agent does not implement auth info cache correctly but
retrieves from keystone every time

Cherry-pick from https://review.openstack.org/#/c/118996/

Conflicts:
	neutron/agent/metadata/agent.py
	neutron/tests/unit/test_metadata_agent.py

Change-Id: Ifc1f580185d7600b48aaf80d112fc80e0c4253f2
Closes-bug: #1365352
NSX: log request body to NSX as debug

Previously we never logged the request body that we sent to NSX. This makes
things hard to debug when issues arise as we don't actually log the body of
the request that we made. This patch adds the body to our issue request log
statement.

Change-Id: I7d98e3d844ebe565fb5919aac3f9afd5b4040e69
Closes-bug: 1360394
(cherry picked from commit 2bc898ff7a18928e94eb81b24dc99d5cb20eae8a)
Add quotas to Cisco N1kv plugins supported extension aliases

When using stable/icehouse branch, due to missing quotas extension,
VM bring up errors out. With the quota table now being created as
part of folsom_initial, adding quotas to supported extension aliases
in the N1kv plugin will fix the VM bring up issue.

Change-Id: I614b6c61c4c816289a71cc1ed125e6fae269781e
Closes-bug: #1375519
Big Switch: Retry on 503 errors from backend

Retries requests to the backend controller up to 3
additional times with 3 seconds in between each request
if a 503 service unavailable message was returned.
The scenarios that return 503 messages from floodlight
are normally short lived locks for things like OpenStack
synchronization or upgrade blocks. Retrying should work
in the majority of cases.

Conflicts:
	neutron/tests/unit/bigswitch/test_servermanager.py

Closes-Bug: #1357105
Change-Id: Ifacd3a384cfc797ba6d6af5f3c8649c333473259
(cherry picked from commit 48a2221648f490540fdf1ee099d39b8e5230f053)