Fix MeteringLabel model to not clear router's tenant id on deletion

foreign_keys parameter of orm.relationship should point to local columns.
Currently for MeteringLabel it points to Router.tenant_id column which causes
routers tenant_id clearing on label deletion.

Closes-Bug: #1249188
(cherry picked from commit d1220a3c22fccc1d86eaafeebe7ef9c074d4fcb9)
Change-Id: Iccc0daf4f6edd537fd7f9e4b2fc4be094543ca5d
Fix a typo in log exception in the metering agent

This patch fixes a typo when there is a exception
when the agent try to invoke a method of the driver.
This patch also improves exceptions handling of
driver method calls.

Change-Id: I4fcf19fa84f178348abfb3563bbfd52f0dfcc095
Closes-bug: #1256041
(cherry picked from commit 272912b6d82af00a6f7bafc26d8ce7a79b09ef26)
Catch PortNotFound exception during get_dhcp_port

Close-bug: 1252437

Change-Id: I3a7954b869b4f5b909c806f8e47180e1ba6ba374
(cherry picked from commit cbe91fda7b416717a23cf7b29adf8201a8c14822)
Fix check_nvp_config erroneous complaint

Add the missing ingredient to the boolean test. This is
not a straight cherry-pick from a trunk fix, as the
utility tool has been renamed in Icehouse.

Closes-bug: #1265353

Change-Id: I9eb8fc1f85b16fbae83930fa9723db1fd25eeb5d
Merge "Catch PortNotFound exception during get_dhcp_port" into stable/havana
Send DHCP notifications regardless of agent status

The Neutron service, when under load, may not be able to process
agent heartbeats in a timely fashion.  This can result in
agents being erroneously considered inactive.  Previously, DHCP
notifications for which active agents could not be found were
silently dropped.  This change ensures that notifications for
a given network are sent to agents even if those agents do not
appear to be active.

Additionally, if no enabled dhcp agents can be found for a given
network, an error will be logged.  Raising an exception might be
preferable, but has such a large testing impact that it will be
submitted as a separate patch if deemed necessary.

Closes-bug: #1192381
(cherry picked from commit 522f9f94681de5903422cfde11b93f5c0e71e532)

Change-Id: Id3e639d9cf3d16708fd66a4baebd3fbeeed3dde8
Add support for managing async processes

Interacting with a long-running asynchronous process requires the
use of non-blocking io.  This change adds a helper class that can
launch a long-running process and read stdout and stderr in a
non-blocking fashion via eventlet.

This functionality is intended to support monitoring ovsdb via
a long-running and root-privileged invocation of ovsdb-client.

The complexity of the system interaction in this patch suggested
the addition of a functional test that validated actual behaviour.
The test was added under the neutron/tests/functional path which
is now included in the testr search path.

Partial-Bug: #1177973

Change-Id: I9969e556acecf7a9e77d873371cc2ec2647be011
(cherry picked from commit acf0209b28e21eed60158967fab77468eb195e7c)
NVP plugin:fix connectivity to fip from internal nw

The current set of NAT rules configured in the NVP logical router
prevents instances on an internal network from establishing TCP
connections with a floating IP associate with an internal port
on the same Neutron network.

This patch add a SNAT rule to ensure connections coming from the
internal network always appear to the port associate with the
floating IP as coming from the external network.

Change-Id: I12da12ee136c61fddb04f2b216382b51d751a02c
Closes-Bug: 1221419
(cherry picked from commit ed2e32b03123ae8e7555b997152c1d8d941494f2)
Add binding:host_id when creating port for probe

When probe is created it needs to have correct bindings otherwise port
is marked as dead.

Change-Id: If542b715756ccfed548ec89a97742fda2ad9b454
Partial-Bug: #1262785
Fix metering iptables driver doesn't read root_helper param

With this patch the iptables driver instantiates the
iptables_manager with the correct root_helper value.

Change-Id: I9a37bae92dc12a8a78ea2d1b9fc5e995321ca322
Closes-bug: #1256036
(cherry picked from commit 35f64f8026f7607c749727ac6b3ee93c956bdfd2)
Merge "Fix MeteringLabel model to not clear router's tenant id on deletion" into stable/havana
Merge "Send DHCP notifications regardless of agent status" into stable/havana
Avoid loading policy when processing rpc requests

When Neutron server is restarted in the environment where multiple agents
are sending rpc requests to Neutron, it causes loading of policy.json
before API extensions are loaded. That causes different policy check
failures later on.
This patch avoids loading policy when creating a Context in rpc layer.

Change-Id: I66212baa937ec1457e0d284b5445de5243a8931f
Partial-Bug: 1254555
Don't allow qpid receiving thread to die

This patch is a partial backport of
22ec8ff616a799085239e3e529daeeefea6366c4 in oslo-incubator.

https://review.openstack.org/#/c/32235/13

This patch ensures that the thread created by consume_in_thread() can
not be killed off by an unexpected exception.

Related-Bug: #1189711

Change-Id: I4370045b450b2b4b9b3bde1f6f3654cdecc722e2
Remove and recreate interface if already exists

If the dhcp-agent machine restarts when openvswitch comes up it logs the
following warning messages for all tap interfaces that do not exist:

bridge|WARN|could not open network device tap2cf7dbad-9d (No such device)

Once the dhcp-agent starts it recreates the interfaces and re-adds them to the
ovs-bridge. Unfortunately, ovs does not reinitialize the interfaces as they
are already in ovsdb and does not assign them a ofport number.

This situation corrects itself though the next time a port is added to the
ovs-bridge which is why no one has probably noticed this issue till now.

In order to correct this we should first remove interface that exist and
then readd them.

Closes-bug: #1268762

Change-Id: I4bb0019135ab7fa7cdfa6d5db3bff6eafe22fc85
(cherry picked from commit b78eea6146145793a7c61705a1602cf5e9ac3d3a)
Have tox install via setup.py develop

tox 1.6 was released, which means that we can now take advantage of
the feature we added to it - which is using setup.py develop to
install the code into the virtualenv. The logic was taken from
run_tests.sh - so the performance issues around using tox vs. using
install_venv should now be gone.

Additionally, override the tox pip install command to avoid using
the "--pre" option which is the default in tox. "--pre" means
"Include pre-release and development versions." By default, pip will
only install stable versions of software, and that is the behavior
we want.

Change-Id: Ida5e440d1bdb9f8e9031277ea53a02d2ef171438
Co-Authored-By: Monty Taylor <mordred@inaugust.com>
Multiple Neutron operations using script fails on Brocade Plugin

Closes-Bug: 1223754

Change-Id: Ifdeed8407a1cb3df9f17267ea582caab385a63f3
Merge "Multiple Neutron operations using script fails on Brocade Plugin" into stable/havana
Merge "Don't allow qpid receiving thread to die" into stable/havana
Fix passing keystone token to neutronclient instance

Neutron client expects token to be passed as token= argument, while
neutron-metadata-agent passes auth_token= instead. This effectively makes the
client to authenticate against keystone each time it's instantiated. In
neutron-metadata-agent case, it means 'each time a client sends a metadata
request.'

The issue results in high cpu utilization on keystone side when simultaneously
invoking multiple nova instances with cloud-init.

Change-Id: I2a31f9c0c3cfa915975ecc53d71168a3895528d8
Closes-Bug: 1274487
(cherry picked from commit 3799efe792700e7736666c40cc42c265eee09230)