Commit Graph

37 Commits

Author SHA1 Message Date
Lucian Petrut 253db749a7 Remove async_process, moved to "common"
This module's contents have been moved to the common module, keeping
it for backwards compatibility.

Three subprojects were using it. Once those projects start using
the new location, we can cleanup the old module.

Change-Id: I7f67dea25473552cd815ad734c1ec1c57b8cc5cf
Depends-On: I08563f4e609dfb6d446814c3497961d7d63c336e
Depends-On: I4486794cf04f1ebd08da906379a0f15e5452380a
2018-09-25 06:49:45 +00:00
Lucian Petrut 89915a752e Trivial: Move platform independent modules to common dir
async_process.py and ovsdb_monitor.py are now platform
independent, for which reason we can move them to
neutron/agent/common.

Note that a few subprojects are using async_process. We'll use
debtcollector so that we don't break those projects, while logging
a deprecation warning.

Change-Id: I6a7418cb8680cd71fe16c5d98b9b09ef2d260d37
2018-08-14 09:54:01 +03:00
Claudiu Belu fee630efaa Fix neutron-openvswitch-agent Windows support
Currently, the neutron-openvswitch-agent does not start on Windows
due to Linux specific imports. This patch addresses this issue.

Also, we're wrapping the object returned by subprocess.Popen using
tpool.Proxy in order to prevent IO operations on the stream
handles from blocking other threads. Currently, the ovs db monitor
blocks the whole process.

Closes-Bug: #1775382

Co-Authored-By: Lucian Petrut <lpetrut@cloudbasesolutions.com>
Change-Id: I8bbc9d1f8332e5644a6071f599a7c6a66bef7928
2018-07-18 14:41:21 +03:00
Jakub Libosvar 93c965d0f9 async_process: Log stdout and stderr on process error
The patch adds data from stdout and stderr readers to debug log in case
process spawned by AsyncProcess died unexpectedly. Such message may
help to understand why had the process died.

Change-Id: I9352b36d1f9483366dc9a514bdd59420d4a20cb0
2018-03-07 18:31:36 +00: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
jufeng ee5677bd61 Optimize pid property in AsyncProcess class
The pid property in the the AsyncProcess process class executes
command 'ps --ppid <pid> -o pid=' every time the associated
asynchronous process's pid is needed. This can be very heavy
in high load network and compute nodes. Please see related bug.

This change optimizes the pid property to execute 'ps --ppid <pid> -o
pid=' only the first time it is called, memoizing the retrieved pid for
future calls.

Change-Id: Idd347b0b22320cbfdb5d6a738e218e5788dd7d6b
Closes-Bug:1663465
2017-03-24 08:06:45 +08:00
Jakub Libosvar 42cc227798 Change default exception in wait_until_true
By default, wait_until_true uses default exception from eventlet which
is eventlet.TimeoutError. This class is not subclass of Exception but
BaseException. In case wait_until_true times out in any test, the whole
test executor worker is stopped leaving scheduled tests not executed.
This patch replaces eventlet.TimeoutError with new WaitTimeout
exception, that inherits from Exception and thus won't break execution
of other test cases in case it's raised.

Related-Bug: 1625221
Change-Id: I44c0c22f427f61d84963e6e59393b90fbaa8f058
2017-01-09 05:37:27 -05:00
Daniel Alvarez 1d38f30555 Kill processes when cleaning up namespaces
This patch will kill processes that are listening on any port/UNIX
socket within the namespace to be cleaned up. To kill them it will
issue a SIGTERM to them (or to their parents if they were forked) and,
if they don't die after a few seconds, a SIGKILL to them and all their
children.

This is intended for those cases when there's no specific cleanup and
serves as a fallback method.

Change-Id: I4195f633ef4a1788496d1293846f19eef89416aa
Partial-Bug: #1403455
2016-12-20 10:52:41 +00:00
Gary Kotton 7c0b219e66 neutron-lib: complete usage of helpers
Add support for:
    - get_random_string
    - camelize
    - round_val
    - safe_decode_utf8

Change-Id: I3b5ccbbcfa18aa488b1772f4ae9a591eb494de59
2016-11-10 05:40:15 -08:00
Jakub Libosvar a626172706 Move wait_until_true to neutron.common.utils
We need to be able to re-use wait_until_true in tempest scenario tests.
There is tempest bug https://bugs.launchpad.net/tempest/+bug/1592345
that prevents us to do so.

Also wait_until_true is not linux specific so it makes more sense to
have it in common package.

Change-Id: Ib8b0e51dbd9edaa58391774d428a737836dfdf77
2016-06-27 11:40:11 +00:00
Assaf Muller fd93e19f2a Change get_root_helper_child_pid to stop when it finds cmd
get_root_helper_child_pid recursively finds the child of pid,
until it can no longer find a child. However, the intention is
not to find the deepest child, but to strip away root helpers.
For example 'sudo neutron-rootwrap x' is supposed to find the
pid of x. However, in cases 'x' spawned quick lived children of
its own (For example: ip / brctl / ovs invocations),
get_root_helper_child_pid returned those pids if called in
the wrong time.

Change-Id: I582aa5c931c8bfe57f49df6899445698270bb33e
Closes-Bug: #1558819
2016-04-04 12:15:33 -04: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
Jenkins 830c2e30fd Merge "Make sure we return unicode strings for process output" 2015-11-24 05:13:18 +00:00
Ihar Hrachyshka e30d8cead1 Make sure we return unicode strings for process output
Process output is supposed to be represented with lines, so we should
put Python strings in the queue (not bytes). Just in case, we do it only
for Python 3 environment.

To fix that, we reuse code from utils.execute() linux/windows
implementations.

This fixes the TestAsyncProcess.test_async_process_respawns functional
test for Python 3 environment.

Related-Bug: #1515118
Change-Id: I9efec2290003add44909aab33a0026372a580016
2015-11-20 16:49:51 +01:00
John Schwarz ddaee9f060 Keep reading stdout/stderr until after kill
Currently, when calling AsyncProcess.stop(), the code stops the stdout
and stderr readers and kills the process. There exists an end case (as
described in the bug report) in which after the readers have been
stopped the sub-process will generate a substantial amount of outputs to
either fd. Since the 'subprocess' module is launched with
subprocess.PIPE as stdout/stderr, and since Linux's pipes can be filled
to the point where writing new data to them will block, this may cause a
deadlock if the sub-process has a signal handler for the signal (for
example, the process is handling SIGTERM to produce a graceful exit of
the program).

Therefore, this patch proposes to only kill the readers until AFTER
wait() returned and the process truly died. Also, relying on _kill_event
had to cease since invoking its send() method caused a logical loop back
to _kill, causing eventlet errors.

A different possible solution is closing the stdout/stderr pipes. Alas,
this may raise an exception in the sub-process ("what? No stdout?!
Crash!") and defeats the 'graceful' part of the process.

Closes-Bug: #1506021
Change-Id: I506c41c634a8d656d81a8ad7963412b834bdfa5b
2015-11-19 19:14:13 +02:00
Ihar Hrachyshka bdcf8e6079 ovsdb monitor: get rid of custom _read_stdout/_read_stderr methods
Those methods do the same thing as AsyncProcess counterparts, just
with logging the received output. It's better to move the logging into
AsyncProcess and control it with __init__ arguments.

This allows us to get rid of some duplicate tests for ovsdb monitor.

Change-Id: Ic20ded27ba09afdd73e4d96c47469c2d7b4d4db5
Related-Bug: #1495937
2015-09-21 17:55:38 +02:00
Jakub Libosvar ecbc2e3ed3 Introduce kill_signal parameter to AsynProcess.stop()
All stop() calls of instances of AsyncProcess class were sending
hardcoded SIGKILL signal to its process. This patch leaves the default
behavior to SIGKILL but offers any number to be sent to kill command.

Note: Internal private methods also got a new parameter which is not
      appended. Given that those methods are private and thus not used
      outside of the class, we can afford it.

Change-Id: Ib7b0273c134d59c6a50173d4c2eb35761fcd3d62
Related-Bug: #1487548
2015-09-17 17:39:19 -04:00
Jakub Libosvar 53c64ff1ac Revert "AsyncProcess: try to kill tender"
This change introduced bug 1495937.

This reverts commit 470a7d8a10.

Change-Id: I84fea4fdac71141da335ccd9e0d4c9d6174dfd86
2015-09-15 11:52:34 +00:00
IWAMOTO Toshihiro 470a7d8a10 AsyncProcess: try to kill tender
_kill_process kills processes with SIGKILL, which prevents the
processes' cleanup from running.  Issue SIGTERM first and wait a bit.

Change-Id: Ie7b94011bbd11b1d672c95e3be19bb3c84ef77ec
Closes-bug: 1494363
2015-09-14 17:17:29 +09:00
Ihar Hrachyshka ef409d9da2 Enable most unit tests for py34 job
* Skip TestWSGIServerWithSSL[1] for Python 3 since it seems wsgi + ssl +
  eventlet setup does not behave correctly now,
* Skip test_json_with_utf8[2] until we solve unicode/utf8 encode/decode,
* Fix some more tests to pass for py3,
* Replace print by print() in docs/docstrings.

[1] neutron.tests.unit.test_wsgi (bug 1482633)
[2] neutron.tests.unit.test_wsgi.JSONDictSerializerTest (bug 1491824)

Related-Bug: #1482633
Related-Bug: #1491824
Blueprint: neutron-python3
Co-Authored-By: Cyril Roelandt <cyril@redhat.com>
Co-Authored-By: Cedric Brandily <zzelle@gmail.com>
Co-Authored-By: sonu.kumar <sonu.kumar@nectechnologies.in>
Change-Id: I26e513d4dcf473f4cd79728382fc94af3d901b5d
2015-09-04 08:30:22 +00:00
Cyril Roelandt 6226fb73a4 Python 3: fix neutron.tests.unit.agent.linux.test_async_process
In Python 3, one cannot compare an integer to None.

Change-Id: I8de3ea3752be837540ea65f1bb254a095927de44
Blueprint: neutron-python3
2015-07-20 17:02:14 +02:00
John Schwarz e0ea5edc12 Add full-stack tests framework
This patch introduces the full-stack tests framework, as specified in
the blueprint. In short, this adds the neutron.tests.fullstack module,
which supports test-managed neutron daemons. Currently only
neutron-server is supported and follow-up patches will support for
multiple agents.

Implements: blueprint integration-tests
Co-Authored-By: Maru Newby <marun@redhat.com>
Change-Id: Iff24fc7cd428488e918c5f06bc7f923095760b07
2015-03-26 20:21:40 +02: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
Assaf Muller aec3a94cd3 Introduce ip address monitor
In Juno, we used keepalived notifier scripts to report the local
state of an HA router's state. These have been found to be
unreliable. The proposed approach is to not use them altogether.
Instead, monitor the omnipresent VIP on the HA device - It is
only configured on the master instance. In order to do that,
we'll use the 'ip monitor address' wrapper introduced in this patch
to get address change events as they happen to avoid polling.

Related-Bug: #1402010
Change-Id: Icc2c07efb7e20008ff5b07d7df2104e6099091d7
2015-03-03 20:06:14 -05:00
Assaf Muller 7907d40075 Allow AsyncProcess to block on process start and stop
* Move utility functions from the test tree to the non-test tree
* Add tests for the newly moved functions
* Use these functions in AsyncProcess

This will allow the ip monitor in the following patch to start
and stop in a synchronous manner.

Related-Bug: #1402010
Change-Id: I03727d8acc17e561d3473b0ebecfbe49cb5523b1
2015-02-27 08:47:50 -05:00
Terry Wilson e627803bf4 Remove root_helper arg from AsyncProcess
Removes the root_helper arg from AsyncProcess and areas whose use
of root_helper was soley for passing it to AsyncProcess.

Change-Id: I6c34f2d8466444c82f8712a2a765975695795fd7
Partially-Implements: rootwrap-daemon-mode
2015-02-18 14:21:29 +00:00
Jakub Libosvar 374a612241 Add Process class helper to manage processes with namespace
This class extends Popen class with usage of namespace and root-helper.
Because of usage of root wrapper, this class re-uses get_child_pid() for
killing the child process. get_child_pid() is taken out of AsyncProcess
as a part of this patch.

Change-Id: I856b3ec75f347ecccaf4a1c6fd17b28a33ee1a3f
Related-Bug: 1243216
2015-01-07 11:20:27 +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
Gary Kotton e16b3a8f37 Update i18n translation for neutron.agents log msg's
Don't translate debug level logs and enforce log hints
Our translation policy
(https://wiki.openstack.org/wiki/LoggingStandards#Log_Translation) calls
for not translating debug level logs. This is to help prioritize log
translation. Furthermore translation has a performance overhead, even if
the log isn't used (since neutron doesn't support lazy translation yet).

NOTE: this is done on a directory by directory basis to ensure that we
do not have too many conflicts and rebases.

Add a local hacking rule to enforce this.

This patch set enforces the directory neutron/agents

Partial-bug: #1320867

Change-Id: I4bd562e5138c2d2850072440aa121f27e902463a
2014-11-15 00:08:20 -08:00
liu-sheng b30c47233d Remove the useless vim modelines
Change-Id: I41286e0b8f74c90b7078c3d3fb041b6586d95ab0
Closes-Bug: #1229324
2014-06-21 15:07:31 +08:00
Yong Sheng Gong 9be1664037 remove unused imports
Change-Id: I39c0de99fac423858da8c76f6cfff27b21a65601
Closes-Bug:1279644
2014-02-14 12:05:56 +08:00
Terry Wilson 9d3a07ed04 Remove psutil dependency
The version of psutil that was being required is not hosted on
PyPi which caused some issues. This patch removes the psutil
dependency in favor of using the method that was proposed for
the havana backport of polling minimization.

Closes-bug: #1268711
Change-Id: I5a1672cfd195099d92578321153c42b8bfd09b7d
2014-02-10 12:40:16 -06:00
Nachi Ueno 88148584f2 Fix misspells
Change-Id: I8be38727ca55ebbead9032cf69f10a1006fd004b
Closes-bug:1257424
2013-12-03 15:03:47 -08:00
Terry Wilson 61e9268bd4 Ensure get_pid_to_kill works with rootwrap script
To ensure that correct process is killed when using a rootwrap
script, we must recursively list the children of our top-level
process and kill the last one. This patch uses the psutil python
module which is already used in the heat-cfntools project.

Change-Id: I702bb9dd794c08fcaab637284ee303de1778cbb9
2013-11-20 09:57:23 -06:00
Maru Newby cb0df591a9 Add the option to minimize ovs l2 polling
This change adds the ability to monitor the local ovsdb for
interface changes so that the l2 agent can avoid unnecessary
polling.  Minimal changes are made to the agent so the risk
of breakage should be low.  Future efforts to make the agent
entirely event-based may be able to use OvsdbMonitor as a
starting point.

By default polling minimization is not done, and can only be
enabled by setting 'minimize_polling = True' in the ovs
section of the l2 agent's config file.

Closes-Bug: #1177973

Change-Id: I26c035b48a74df2148696869c5a9affae5ab3d27
2013-10-14 22:24:15 +00:00
Maru Newby acf0209b28 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
2013-10-14 07:20:02 +00:00