Commit Graph

55 Commits

Author SHA1 Message Date
Rajesh Tailor 8ab5ee1d17 Fix remaining typos in comments and tests
Change-Id: I872422cffd1f9a2e59b5e18a86695e5cb6edc2cd
2022-07-06 21:20:27 +05:30
Rodolfo Alonso Hernandez edf1d0c759 Replace "tenant_id" with "project_id" in metering service
This is part of the remaining technical debt of the specs
https://specs.openstack.org/openstack/neutron-specs/specs/newton/moving-to-keystone-v3.html

Change-Id: If86ecce15b077f6baef74903a3a4f41a450ec755
Blueprint: https://blueprints.launchpad.net/neutron/+spec/keystone-v3
2021-10-28 09:42:52 +00:00
Zuul 144c70f896 Merge "Set metering iptables chain not found LOG level to WARNING" 2020-11-20 11:46:59 +00:00
Rafael Weingärtner 3c0d57c884 Set metering iptables chain not found LOG level to WARNING
When routers are migrated from one Neutron agent to the other, the metering IPtables
rules are removed, which can cause some exceptions that can be ignored. The metering
agent already handled this situation. However, it logs the message as an ERROR, which
can triggers alarms. Therefore, we propose here to change the LOG message from error
to warning.

Closes-Bug: #1904874
Change-Id: I1805a07cef7fc7d7b041e582a4d79fb1a805df71
2020-11-19 09:14:28 -03:00
Rafael Weingärtner 10091f9346 Add source_ip_prefix and destination_ip_prefix to metering label rules
As proposed in the RFE and then approved in the spec, we are adding to
the neutron metering rules two new parameters. The source IP prefix, and
destination IP prefix.

Partially-Implements: https://bugs.launchpad.net/neutron/+bug/1889431
RFE: https://bugs.launchpad.net/neutron/+bug/1889431

Depends-On: https://review.opendev.org/#/c/746203/
Depends-On: https://review.opendev.org/#/c/744702/
Depends-On: https://review.opendev.org/#/c/743828/
Depends-On: https://review.opendev.org/#/c/746142/

Change-Id: I38991de2b4937becd0f1f14f3a32dc39c590e0d9
2020-09-29 09:06:03 -03:00
Rafael Weingärtner 95558d0bf5 Metering fix error that might happen when labels are removed during processing
If a metering label is removed during a data collection and processing, and
error might happen. This patch address such situations, and creates an execution
flow that avoids such problems.

Change-Id: Iba68173c304dccf97521dcec9a87fce67e21cec2
2020-09-18 15:01:16 -03:00
Rafael Weingärtner bd1467b47c Granular metering data in neutron-metering-agent
Extend neutron metering agent to generate Granular metering data.
The rationale here is to have data (bytes and packets) not just in
a label basis, but also in tenant, router, and router-label, and tenant-label
basis. This allows operators to develop more complex network monitoring
solutions.

Moreover, I added documentation to explain what is the neutron metering agent,
its configs, and different message formats.

Change-Id: I7b6172f88efd4df89d7bed9a0af52f80c61acbe0
Implements: https://blueprints.launchpad.net/neutron/+spec/granular-metering-data
Closes-Bug: #1886949
2020-09-04 09:20:54 -03:00
Brian Haley 555238da69 Start using oslo_utils.netutils.is_ipv6_enabled()
Seems that is_enabled_and_bind_by_default() from
neutron.common.ipv6_utils was copied directly into
oslo_utils.netutils, so start using it instead.

Trivialfix

Change-Id: I00fa441e7a20fcd1115485bb8ab75750e6a8cf07
2019-10-16 21:44:56 -04:00
Brian Haley b79842f289 Start enforcing E125 flake8 directive
Removed E125 (continuation line does not distinguish itself
from next logical line) from the ignore list and fixed all
the indentation issues.  Didn't think it was going to be
close to 100 files when I started.

Change-Id: I0a6f5efec4b7d8d3632dd9dbb43e0ab58af9dff3
2019-07-19 23:39:41 -04:00
bno1 9f541521bb Retry creating iptables managers and adding metering rules
This change makes the metering agent retry creating the iptables
managers for each router and applying the metering rules.
This is needed in case the metering agent starts before some or all of
the namespaces are created.

Change-Id: Ifc565feb98c7f02df5c2831a3607c3e526a2e703
Closes-Bug: #1807153
2019-07-13 16:10:19 +03:00
Boden R 9bbe9911c4 remove neutron.common.constants
All of the externally consumed variables from neutron.common.constants
now live in neutron-lib. This patch removes neutron.common.constants
and switches all uses over to lib.

NeutronLibImpact

Depends-On: https://review.openstack.org/#/c/647836/
Change-Id: I3c2f28ecd18996a1cee1ae3af399166defe9da87
2019-04-04 14:10:26 -06:00
Hongbin Lu 38309ca4dc Update metering driver to load interface driver
Currently the metering iptables driver is using the old method
to load the interface driver. This patch allows it to load
interface driver via stevedore aliases.

Change-Id: I9e3027c1ec695ec3a09db0c53a0388e406e4ced6
Related-Bug: #1504536
2018-08-10 15:44:50 +00:00
leegy 92db1d4a2c Fix meter-label-rule creation
The existing method is to meter outgoing traffic from the entire VM
to a specific "remote_ip_addr"(in case of outbound),
but the method I suggested can meter outgoing traffic
from a particular subnet to external network.

From a metering point of view,
it does not matter which address/CIDR is the destination for outbound.
But, it is important to know where(subnet or VM) the packet leaves from.
That way you can see how much VMs are using the external network.
For outbound metering, dst is 0.0.0.0/0 and src is network of VMs
and for inbound metering, src is 0.0.0.0/0 and dst is network of VMs.

When creating a meter-label-rule, it is correct
to specify src address for "remote_ip_prefix" option for outbound
and specify dst address for inbound.
If you are confused by the term "remote_ip_prefix",
you need to clarify this option.

Change-Id: Ia3f3e26410a73d7b44abae637703fda41c4bc09a
Closes-Bug: #1716913
2017-12-03 09:20:53 +00:00
Brian Haley 4f627b4e8d Change ip_lib network namespace code to use pyroute2
Change network namespace add/delete/list code to use
pyroute2 library instead of calling /sbin/ip.

Also changed all in-tree callers to use the new calls.

Closes-bug: #1717582
Related-bug: #1492714

Change-Id: Id802e77543177fbb95ff15c2c7361172e8824633
2017-10-04 21:09:28 +00:00
sindhu devale 51ca683797 Refactoring agent linux&ovsdb config
Refactoring neutron agent linux and ovsdb config opts
to be in neutron/conf/agent so that all the config options
reside in a centralized location. This simplifies the
process of looking up the config opts and provides an easy
way to import.

NeutronLibImpact

Change-Id: Ib1e0e63dec2985c417412d1ecc68e2a74ef87182
Partial-Bug: #1563069
2017-08-25 10:41:39 -04:00
Inessa Vasilevskaya 7322bd6efb Make code follow log translation guideline
Since Pike log messages should not be translated.
This patch removes calls to i18n _LC, _LI, _LE, _LW from
logging logic throughout the code. Translators definition
from neutron._i18n is removed as well.
This patch also removes log translation verification from
ignore directive in tox.ini.

Change-Id: If9aa76fcf121c0e61a7c08088006c5873faee56e
2017-08-14 02:01:48 +00:00
Jenkins 96d13e42f4 Merge "Verify metering label exists before applying rule" 2017-05-02 21:01:30 +00:00
Jenkins 16c37c1e0f Merge "Replace six.iteritems with dict.items(Part-2)" 2017-04-18 18:07:55 +00:00
fpxie 574312165b Replace six.iteritems with dict.items(Part-2)
according to https://wiki.openstack.org/wiki/Python3, now we should avoid
using six.iteritems and replace it with dict.items.

Change-Id: I58a399baa2275f280acc0e6d649f81838648ce5c
Closes-Bug: #1680761
2017-04-18 18:56:46 +08:00
Béla Vancsics 4698b7b931 Remove unused variable
TrivialFix

Change-Id: I9483695a4ad9a1aa3ae26afd9b760891376c23c6
2017-04-14 23:09:21 +00:00
Brian Haley 29652e0aff Verify metering label exists before applying rule
If the metering-agent receives a label rule before it
has added the label, it will fail to update the iptables
rules as there are no existing chains.

When the action is "create", check if there is an existing
label, and create one and the corresponding iptables chains,
before trying to add the rule.

Closes-Bug: #1617248

Change-Id: Ia0ec1361188cca53023667d249c2b1e10bc22089
2017-03-28 14:27:05 -04:00
John Perkins 7f23ccce23 Agent common config
Refactoring Neutron configuration options for agent common config to be
in neutron/conf/agent/common. This will allow centralization of all
configuration options and provide an easy way to import.

Partial-Bug: #1563069
Change-Id: Iebac0cdd3bcfd0135349128921b7ad7a1a939ab8
Needed-By: Ib676003bbe909b5a9013a3178b12dbe291d936af
2017-03-15 09:52:18 -06:00
Jenkins 2614bc6498 Merge "DVR: Fix IPtables driver for metering with DVR routers" 2017-01-20 04:08:55 +00:00
Swaminathan Vasudevan ec6ed98cfa DVR: Fix IPtables driver for metering with DVR routers
IPTables driver for metering was not handling the DVR router
namespaces properly for configuring the metering forward rules.

This patch addresses the issue by configuring the iptables
manager based on the availability of the namespace and selecting
the respective namespaces such as router namespace and snat
namespace with the right external device.

Change-Id: I6790d6ff42d9f8fa220e1a231ae94cbf8b60506c
Closes-Bug: #1506567
2016-12-08 16:51:13 -05:00
Hunt Xu 7962dd49ef Metering: sync only active routers hosted on the same host
When syncing data from neutron server, metering-agent may receive
information about routers that are not hosted by the l3-agent on the
same host, because the server didn't filter them out. This could lead to
the following problems:
  * metering-agent tries to setup iptables rules for a router that is not
    on the host
  * metering-agent tries to get get traffic counters for a router that
    was once on the host but is already removed
  * metering-agent not sets up iptables rules for a router that is
    removed then added back to the host, because nothing about the
    router is changed from metering-agent's perspective

This commit fixes the aforementioned problems by making metering-agent
only receive information about routers that are on the same host, and
update metering-agent's knowledge about which routers it should care.

However, there could still be problem if one removes then adds a router
back to the same l3-agent, or just sets the router's admin_state_up
property to False then True in a short time(shorter than the interval
between two syncs). Because the metering-agent sees nothing changed
while during the same time the router's namespace is removed and added
back on the host. Thus metering-agent will fail to get such router's
traffic counters. This commit also make iptables-driver to forget such
routers and leave the metering-agent to reconfigure them later.

Closes-Bug: #1580548

Change-Id: Ia6ae82c676582b06710d6f96b9938c215258182d
Signed-off-by: Hunt Xu <mhuntxu@gmail.com>
2016-11-21 19:44:22 +00:00
Henry Gessau b0e56ac646 Retire deprecations for constants, exceptions, attributes
Subprojects have had enough time to switch to neutron-lib for
the deprecated items from these modules.

Change-Id: Ib2f4acf7e0153667389c57a52f2db33a23758b24
2016-11-09 23:43:38 -05:00
Dustin Lundquist 4f0caa0ece Rename ipv6_utils.is_enabled()
IPv6 utils is_enabled() doesn't actually determine if IPv6 is enabled on
the host. It checks if /proc/sys/net/ipv6/conf/default/disable_ipv6 is
present and is set to 0. This kernel configuration option controls if
the kernel will automatically assign IPv6 link-local addresses to newly
created network interfaces when their link state changes to up. The
existence of this /proc files does indicate that the Linux kernel has
the ipv6 module loaded or ipv6 was compiled in. Having this /proc file
set to zero does not indicate IPv6 is not available on the system, just
that newly created interfaces will inherit this configuration and will
not have IPv6 addresses bound to them unless the administrator changes
the interfaces specific /proc/sys/net/ipv6/conf/$IFACE/disable_ipv6
configuration.

This check was added to Neutron so it could operate with distributions
which didn't load the ipv6 kernel module, preventing errors when
attempting to make IPv6 specific configurations in the iptables firewall
driver and the L3 agent. Removing it would break existing deployments.

Renaming this function to provide clarity for complex conditions tested
by this function. In fact it is a good security practice to set this
default disable_ipv6 option to 1, and explicitly enable IPv6 by setting
disable_ipv6=0 on individual interfaces which the administrator intends
to bind IPv6 addresses on. This establishes parity with IPv4 behavior
where interfaces are not active in an address family until the
administrator explicitly configures them to be active in that address
family. This practice does not currently work as expected with the
Neutron, since setting /proc/sys/net/ipv6/conf/default/disable_ipv6 to 1
unexpectedly disables creating IPv6 security group rules leaving
instances completely exposed via IPv6 regardless of security group
rules.

Change-Id: I844b992240a5db642766ec9c04e3b5fcab8e2e23
2016-10-26 02:11:57 -07:00
gaozhengwei 5b7c71a327 Preventing iptables rule to be thrashed
When update meter label or rule, iptables_manager will update iptables
rule in router's namespace. In order to, it will clean traffic counter
number collected in interval time, the other iptables always trashing
that will clean old iptalbes rule and generate new same significance
iptables rule.

Change-Id: Ide2b26c98587258175234acded38ce481b7e7f76
Closes-Bug: #1618879
2016-09-13 12:24:17 -04:00
Sergey Belous f73dae0a65 Add check that external gw port exist when metering-agent adds a rule
If router has no gateway port when metering-agent wants to add
a metering-label-rule method _process_metering_label_rules() fails
with error "cannot concatenate 'str' and 'NoneType' objects"
because there is no check that router has an external gateway port.
This patch adds this check and adds some unit test.

Closes-bug: #1527274
Change-Id: Ic9f626db41bfb6343187742e209402dd7d5232d1
2016-04-18 15:03:49 +03:00
Dmitry Sutyagin 5d2d1120fc Switches metering agent to stateless iptables
If state_less parameter is not specified then
neutron-postrouting-bottom rule goes up in POSTROUTING
chain, which causes premature NATing of traffic,
for ex. traffic between internal networks becomes NATed.

Closes-Bug: 1544508
Co-Authored-By: Sergey Belous <sbelous@mirantis.com>
Change-Id: I2e0011237d50a59d417cfee01dcd5f9d0da2e7f5
2016-03-30 19:53:42 +03:00
Yu Fukuyama 6659a93558 Fix meter label rule creation
In the case of outbound traffic, set remote_ip to dst.
In the case of inbound traffic, set remote_ip to src.

Change-Id: I7f27b93efa67baf3efccaa94f6a1337d6886e230
Closes-Bug: #1528137
DocImpact: Clarify remote_ip_prefix description of metering label rule in API site
2016-01-06 14:08:07 +00:00
Akihiro Motoki 2d8632e412 Use _ from neutron._i18n
Partial-Bug: #1520094
Change-Id: I874a4aa1d71d1f7034a1ff0b7450b419ef5c6864
2015-12-06 19:39:04 +09:00
Doug Wiegley dd726ed494 Move i18n to _i18n, as per oslo_i18n guidelines
- This does NOT break other projects that rely on neutron.i18n,
  as this change includes a debtcollector shim to maintain those
  older entry points, until they can migrate.
- Also updates _i18n.py to the latest pattern defined by oslo_i18n
- Guidance and template are from the reference:
  http://docs.openstack.org/developer/oslo.i18n/usage.html

Partially-Closes-Bug: #1519493
Change-Id: I1aa3a5fd837d9156da4643a367013c869ed8bf9d
2015-12-01 19:29:10 -07:00
Cedric Brandily 23b907bc6e Remove deprecated use_namespaces option
The use_namespaces option has been defined as a workaround to kernels
not properly supporting namespaces. This limitation is behind us, it's
time to remove use_namespaces after its deprecation in Kilo in order to
simplify code and remove a poorly tested case (use_namespaces=False).

This change prepares for removal pullup_route method[1] which was only
used when use_namespaces=False.

[1] neutron.agent.linux.ip_lib

DocImpact
UpgradeImpact
Closes-Bug: #1508188
Related-Bug: #1435382
Depends-On: I303038eec560a6d99421140c2822aed8b518470b
Depends-On: I4feb2a15c7e1e4bfdbed2531b18b8e7d798ab3cc
Change-Id: I2fbf65df1250d9f9f1656b3964ee3b6de1ef1118
2015-11-18 19:17:29 +01:00
Ihar Hrachyshka ba05644bc8 Replace custom method call logger with oslo.log helper
oslo.log now provides a logging helper that is similar to custom neutron
helper (actually, the helper in oslo.log started from neutron version).

Now switching to library implementation.

Deprecated neutron.common.log.log

Change-Id: I85d5fc570950ff18cfdb8db20ad20b166e195299
2015-04-20 15:16:54 +00:00
Jenkins aa2d7a2a23 Merge "Send only one rule in queue on rule create/delete" 2015-03-27 19:17:37 +00:00
Ilya Sokolov 6abc6399df Send only one rule in queue on rule create/delete
Now we send all labels and rules per rule create/delete
and rebuild whole iptables chains.
In this patch we send only affected rule and create/
delete only this rule from iptables.

Change-Id: I58ebd8d810c62980c09a340ee1680be17c12b74a
Closes-Bug: #1400280
2015-03-26 21:47:00 +00:00
Fei Long Wang c3b7f1b2ae Fix metering agent failure when chain missing
The metering agent will fail if one of the iptables chains
is missing, which will cause errors extracting data from
all the other chains. Add a simple try/except to let the
loop continue.

Closes-Bug: #1421037

Change-Id: I370ee0e2cc58ca7e1c5ef9bf4dbcce5abf7545a1
2015-03-19 10:03:47 +13:00
Ihar Hrachyshka 22328baf1f Migrate to oslo.log
It's mostly a matter of changing imports to a new location.

Non-obvious changes needed:
* pass overwrite= argument to oslo_context since oslo.log reads context
  from its thread local store and not local.store from incubator
* don't store context at local.store now that there is no code that
  would consume it
* LOG.deprecated() -> versionutils.report_deprecated_feature()
* dropped LOG.audit check from hacking rule since now the method does
  not exist
* WritableLogger is now located in oslo_log.loggers

Dropped log module from the tree. Also dropped local module that is now
of no use (and obsolete, as per oslo team).

Added versionutils back to openstack-common.conf since now we use the
module directly from neutron code and not just as a dependency of some
other oslo-incubator module.

Note: tempest tests are expected to be broken now, so instead of fixing
all the oslo.log related issues for the subtree in this patch, I only
added TODOs with directions for later fix.

Closes-Bug: #1425013
Change-Id: I310e059a815377579de6bb2aa204de168e72571e
2015-03-12 11:22:56 +01:00
Terry Wilson 326e25f932 Remove remaining uses of passing root_helper
This should remove the last bits of passing root_helper around
for execute(). Some tests store and pass the root_helper argument
outside of this, and have been left alone.

Depends-On: I1e3b64e5a1d6cff2aebc638710487bbdbdba61d4
Depends-On: I5d51fa5edc7f427d84d7ae49d3a4c972dca8ac37
Depends-On: I21c6e7795c8b2e8f87bbd2b00a8eb7cb215ece74
Depends-On: I6566e17a1ce07a3bebf2a1a3653ad7e7f397f0b9
Change-Id: I38c901c65fb0c8598589ec56d5afd50d2f882f4f
Partially-Implements: blueprint rootwrap-daemon-mode
2015-02-20 03:24:38 +00:00
Terry Wilson 6095556f96 Remove root_helper arg from IptablesManager
Partially-Implements: blueprint rootwrap-daemon-mode
Change-Id: I4b7da37df4256a1019f16c587e1738175861030e
2015-02-18 11:39:38 +00:00
Ihar Hrachyshka 7a2a85623d oslo: migrate to namespace-less import paths
Oslo project decided to move away from using oslo.* namespace for all their
libraries [1], so we should migrate to new import path.

This patch applies new paths for:
- oslo.config
- oslo.db
- oslo.i18n
- oslo.messaging
- oslo.middleware
- oslo.rootwrap
- oslo.serialization
- oslo.utils

Added hacking check to enforce new import paths for all oslo libraries.

Updated setup.cfg entry points.

We'll cleanup old imports from oslo-incubator modules on demand or
if/when oslo officially deprecates old namespace in one of the next
cycles.

[1]: https://blueprints.launchpad.net/oslo-incubator/+spec/drop-namespace-packages

Depends-On: https://review.openstack.org/#/c/147248/
Depends-On: https://review.openstack.org/#/c/152292/
Depends-On: https://review.openstack.org/#/c/147240/

Closes-Bug: #1409733
Change-Id: If0dce29a0980206ace9866112be529436194d47e
2015-02-05 15:09:32 +01:00
Ihar Hrachyshka 3f44c9e278 Migrate to oslo.i18n
Mostly trivial import changes.

- oslo.i18n no longer provide install() method to inject _() into
  globals(), so removed all calls to it;
- removed Babel from dependencies (it will now be grabbed by oslo.i18n);
- updated tox.ini to ignore import violations for oslo.i18n.

Change-Id: I6623d551f512fb7fe9bf35ee734ed6d4c6cbc287
2014-11-26 22:19:24 +01:00
Ihar Hrachyshka dac6a0c79e Migrate to oslo.utils
The following modules are removed:
  - excutils,
  - importutils,
  - network_utils,
  - strutils,
  - timeutils.

Closes-Bug: #1385355
Change-Id: I1f34f17f5dbf37032584008f27e65d4dc4d475f4
2014-11-26 10:31:03 +01:00
Cedric Brandily 8a99a4a35f Enforce log hints in neutron.services.metering
This change enforces log hints use and removes debug level log
translation, modifications are validated through a hacking rule.

Validate that hacking rules apply to directories:
    - neutron/services/metering

Change-Id: Ic763e81e8b06973013115af45c7c09a3e69c673b
Partial-bug: #1320867
2014-11-22 09:42:58 -08:00
Gary Kotton 7edf58495e Remove @author(s) from copyright statements
We have git to track authorship, so let's not pad source files
with it as well.

A hacking check has been added for this. The value is N322.

Change-Id: Iab0b64d417e0bb41a6b455e2ac377deee64ec3ee
2014-09-15 21:40:09 +09:00
Angus Lees 4e80524a61 Remove chain for correct router during update_routers()
The existing code incorrectly used the stale value from a previous list
comprehension - and deleted the chains for the wrong router :(
(Found via pylint)

Also: change to using a set() rather than a list(), since it is used for
repeated membership tests.

Also: refactor test cases to remove test case duplication.

Closes-Bug: #1362466
Change-Id: I4df400d57bab5427362db47a715576faa6340173
2014-09-01 12:54:27 +10:00
Jakub Libosvar b6e9922364 Ensure ip6tables are used only if ipv6 is enabled in kernel
On systems where ipv6 module is not loaded in kernel we need to avoid
usage of ip6tables. This patch reads
/proc/sys/net/ipv6/conf/default/disable_ipv6 file and if ipv6 is
disabled then ip6tables are not used in IptablesManager

Closes-Bug: #1352893

Change-Id: I07e5851aa25eb98b7a97dff86b9850475df85f64
2014-08-19 15:12:18 +02:00
Koteswara Rao Kelam 72e8b5dc5a Add -s option for neutron metering rules
While adding iptables rule, cidr is added as destination for both ingress
and egress directions. Modified code to add -s for egress and -d for ingress.

Closes-bug: 1310589

Change-Id: Id9ca10855e6527d4bec689f8f9bcd6f681221954
2014-07-14 00:12:51 -07:00
Jakub Libosvar ceee7b4ac9 Set ns_name in RouterInfo as attribute
Closes-Bug: #1302007
Change-Id: I02a9b92eea06010569d3d9c5a987e69f89b23be5
2014-04-03 17:13:02 +02:00