Commit Graph

73 Commits

Author SHA1 Message Date
Max 7f0f786c27 Trap handlers: propagate expected BSC id to command processor
When receiving commands for particular BSC, log BSC id known at the time
when request was made, not the one which is part of the reply.

Change-Id: I6acdfddb9a1132f978f2b55c769559b0c29eb3e8
2018-12-05 17:55:03 +01:00
Max f0f8a352cc Trap handlers: always log to stdout
Since the scripts are intended to be used as systemd services, there's
no need in separate logging via syslog: systemd will take care of
properly collecting and storing script output. Hence we can drop extra
options and function parameters.

Change-Id: Ifcad1877d45d43b3a2e617775a1c9b256e190591
Related: SYS#4399
2018-12-05 15:10:18 +01:00
Max 25a8297fe8 Improve code style
* reorder imports to make pylint3 happy
* drop unused imports
* use proper spacing for list constants
* don't use reserved names for internal variables

The check was run as follows:
pylint3 -d C0103,C0301,C0410,C0326,R0913,R0901 ...
to disable useless warnings.

Change-Id: I5b90ee790f73dc509081401776911f25e43f1801
2018-11-28 12:52:48 +00:00
Max f7255fa7cf Move command processing into shared function
Change-Id: I4e40607a9aa5e03a7b3f5b68e4261828209a5813
2018-11-28 12:52:48 +00:00
Max 2cc29b5ef7 Drop unused Trap() class
Change-Id: Ic2066a66f99a059fc65cf3092170e248288c04d4
2018-11-28 12:52:48 +00:00
Max 1c668f2c47 ctrl: add function to skip TRAP messages
This allows to easy skip TRAP messages when we do not want to process
them (for example when waiting for REPLY to a single command). Update
documentation and version accordingly.

Change-Id: I51ce207c19a1ca96c3e2af7d5efd64f79b02fbb4
2018-11-28 12:37:23 +01:00
Max e18d0661b5 Update trap helper
* add missing import
* update docs
* add helper functions

Change-Id: Ie6dc8808efc76ad96b400913e5caa405bce7d970
Related: SYS#4399
2018-11-27 17:41:02 +01:00
Max ac8de71ac7 Re-apply changes to trap_helper.py
Due to changes getting out of sync, changes from
I44035323b70f04eb8f5dc12123cb708f53eba188 and
I21ff593be420a374a00073953c9254a013c43164 were overwritten by
I7b59f2dbded9074d15f2d2f40bf5a92ed02601e2 moving code to different
file. Fix this by re-applying those changes in new location.

Change-Id: I811f307ded63e7e1544243921ee07dceae81e295
2018-11-27 13:14:20 +01:00
Max 5baba8c078 Move common Trap-related code into separate file
The ctrl2cgi.py is heavily based upon soap.py - let's move all the
shared code into separate file to make further modifications easier.

Change-Id: I7b59f2dbded9074d15f2d2f40bf5a92ed02601e2
Related: SYS#4399
2018-11-27 11:51:37 +00:00
Max 98b993f010 osmo_ipa: update split_combined docs
Change-Id: I1cc6dc314fa0f147ab64ad29d9b892c3637a51c7
2018-11-26 19:30:43 +01:00
Max f0aa41e6a1 osmo_ipa: add extended checks
Make sure we properly handle None objects.

Change-Id: If5ddc04b8a5dc26e56e5f5bbec7f28cf0af4a97b
2018-11-26 19:01:30 +01:00
Max 04e7c64902 ctrl: introduce constant for TRAP id
Use it for TRAP message parsing and generation.

Change-Id: I0381eb60d10e7278b966464add79772a9f7c8118
2018-11-26 16:03:49 +00:00
Harald Welte dbb57eb57d make osmpy IPA code aware of RSPRO
RSPRO (Remote Sim PROtocol) is used by osmo-remsim and basd on the IPA
multiplex.  Let's add knowledge about this stream identifier to osmopy.

Change-Id: I5c0e674390c5672ee1083b1226c206557f6a980b
2018-10-13 13:15:51 +02:00
Neels Hofmeyr e0325b432b osmo_interact/common: ignore trailing empty lines in received results
If the VTY/CTRL output contains trailing newlines, do not cause those to
trigger mismatch errors, rather drop those.

Rationale: in transcript scripts, the amount of empty lines between expected
results is ignored, to allow cosmetically arranging into sections. So trailing
newlines are dropped, and there is no way to preserve those.

Change-Id: I1930868451c5738b17e318a9807590d948210b9a
2018-09-10 17:54:24 +02:00
Neels Hofmeyr b0621451e3 osmo_interact/vty.py: fix parsing of vty logging
Because the VTY logging target currently prints '\n\r' instead of '\r\n', the
python splitlines() separates those as interleaving empty lines. Ignore '\r' to
allow verifying VTY logging output as well.

Change-Id: I8de9cebaa9aad275f65c3672985b7cbca343b5a6
2018-09-10 15:50:08 +02:00
Pau Espin 8739f9c4fc Move twisted_ipa.py to osmopy lib
twisted_ipa is a module expected to be used by other python scripts, so
move it to osmopy dir to be installed as a lib (in python path) so it
can be later used.

twisted_ipa has some features to use it standalone for testing purposes.
This feature can still be used from new installation path.

Change-Id: I33a0c4263297abd9e111bf43e6e9967c06474318
2018-07-11 14:05:28 +02:00
Max c41b751dec Print version before tests
This helps with debugging of import-related issues - we know the version
under test before the test has a chance to hang.

Change-Id: If13cba60a19e9c15885355f85def4d134fa37993
Related: OS#2821
2018-01-15 14:10:27 +01:00
Max cd5a6e419e Fix absolute import issue in py3
As of 577f2a95e4f01c58a0a4f4ccb3b70d9c048b626e in osmo-ci, the
contrib/jenkins.sh isused forinstallation. This causes the issue with
python3 because test coded use absolute import by default.

Fix this by adding relative path and import from ../osmopy to make
sure test code uses the current module and not the one which might be
already installed in the system.

Change-Id: I8ac3c0d45fb2e1d18646048703ac405be1c7e539
2018-01-14 18:33:26 +01:00
Max 99f1c4714c Remove osmotestvty.py from python 3 installation
This script is actually not python 3 compatible yet despite passing
current tests. Let's not install it for python 3 until we can figure out
a way to catch this incompatibility with test code.

Change-Id: Ief11b75acc973dc7aeaac9c2298a21dc5390efe4
Related: OS#2821
2018-01-08 12:15:55 +01:00
Max 566f2a7590 Update ctrl command parsing for python3
* make parse() return command id in addition to variable name and value
* introduce parse_kv() wrapper which ignores that id and use it instead
  of old parse()
* make parse() compatible with python3 where we got bytes, not string
  from the socket so we have to decode it properly before using split()
* expand test_py3.py with simply asyn server which verifies that
  osmo_ctrl.py works properly

Change-Id: I599f9f5a18109929f59386ab4416b8bfd75c74d1
2017-12-28 19:34:48 +01:00
Neels Hofmeyr be76f4d8a8 add cmdline doc to osmo_interact_* and osmo_verify_*
The tools are so far badly under-documented. Alleviate that by comprehensive
description and examples shown by -h option output. Hint at that from the
README.

Change-Id: I94dcad257558b917cb54fc877122594cd164f496
2017-12-20 16:00:32 +00:00
Neels Hofmeyr 56aa4785c0 fix osmo_interact_* and osmo_verify_transcript_* after dir split
After I30cdf0f85b2a60a235960911c9827f4129da40db,
* the osmo_interact_{vty,ctrl}.py can no longer import osmo_interact_common,
  since it was moved to scripts/ in error.
* the osmo_verify_{vty,ctrl} scripts can no longer import osmo_interact_{vty,ctrl},
  since it is also in scripts/. Notably, the osmo_interact_{vty,ctrl}.py also
  served as scripts while being modules at the same time, which is not good.

Fix these issues by adding a new osmopy/osmo_interact/ submodule with
osmopy/osmo_interact/common.py, /vty.py and /ctrl.py as modules, and add in
scripts thin wrappers that invoke the modules' main().

Change-Id: I40a37b212274cb70ebb1e1d9d1b3743eb2d64d05
2017-12-19 15:11:31 +00:00
Max 6ccd0785d8 Fix python3 compatibility
Use print() function with proper import.

Change-Id: Ib10dfbec18202245031a634fc3f19677fc952e60
2017-12-18 13:12:48 +01:00
Max 120075a6a5 Move scripts to appropriate directory
Having the scripts in the same directory with library code means that
it'll be installed unconditionally regardless of version check in
setup.py which makes it impossible to write separate tests for python 2
and 3. Fix this by moving the scripts into separate directory and
adjusting init and setup files accordingly.

This is necessary for implementing proper CI tests in follow-up patches.

Change-Id: I30cdf0f85b2a60a235960911c9827f4129da40db
2017-12-18 13:12:08 +01:00
Max 7f7c4b4410 Use setuptools for packaging
According to https://docs.python.org/3/library/distutils.html the
setuptools are used in place of distutils anyway. Using it directly
allows us to make packaging more flexible: specify dependencies,
automatically find package name etc.

Change-Id: I39ee53f352001e47c6df055cbec52d638480253d
2017-12-15 20:40:41 +01:00
Pau Espin 1aa0fb4910 osmo_ctrl.py: Set shebang to use python v2
Nowadays bin/python usually points to python3, and this script is written
in python2, which means if run directly from terminal it will fail with
some print syntax errors.

Change-Id: I24a568fc2c3e69e7c9f7b9729bd023fe1f0691c7
2017-12-11 14:02:44 +01:00
Neels Hofmeyr 48b951a7a6 osmo_interact_common: add '... !regex' wildcard
Sometimes it is desirable to match any lines, just make sure that a given regex
does *not* exist in the command reply.

For example, during handover config tests, to verify that no handover config
exists, one would have to match an entire 'show running-config' output, which
is subject to change whenever the VTY changes.

Add a wildcard '... !' which allows passing a regex that must not be
encountered, e.g.:

  OsmoBSC(config-net)# show running-config
  ...
  network
  ... !handover
   bts 0
  ...
    handover 1
  ...

This checks that there is no handover config on the network level while bts 0
does have handover config.

Change-Id: I7c1ebb2e7f059047903a53de26a0ec1ce7fa9b98
2017-11-29 18:21:18 +01:00
Max e732c2ca3b Add *.py from OsmoBSC
Those are generic enough and can be used as advanced example of uzing
CTRL interface from python on top of osmo_ipa.

Change-Id: Ic4e1155d3bd546feaabab34a46e354c69058056e
2017-11-27 14:07:07 +00:00
Neels Hofmeyr 066a95dec5 cosmetic: cmdline arg doc tweaks, comment
Change-Id: I60dc059879dfe15cd3415ce1ed068ded28ff084e
2017-10-18 03:57:27 +02:00
Neels Hofmeyr 6562c085c4 osmo_verify_*: clarify naming to osmo_interact_*
Have common implementations in one place, and expose distinct command line
argument signatures to obtain the separate tasks as separate scripts.

osmo_interact_common.py implements the parts common to all VTY and CTRL
interactions.

osmo_interact_vty.py and osmo_interact_ctrl.py implement commands I/O but only
expose command line args to directly pipe commands and responses.

osmo_verify_transcript_vty.py and osmo_verify_transcript_ctrl.py act as before,
now implemented by importing osmo_interact_{vty,ctrl}.py, only exposing the
verifification command line arguments.

Change-Id: Ie0cbd5db85ebebc893df638a07f5568632563dc9
2017-10-18 03:54:45 +02:00
Neels Hofmeyr 08d645b01d osmo_verify_transcript: allow running/piping commands directly
To retrieve the VTY reference XML from 'show online-help', which we need for
the osmo-gsm-manuals, it is useful to directly print the output of a single VTY
command.

I have also always wanted to be able to just type CTRL commands and get their
results.

Add --command and --output arguments to run specific commands and pipe to
stdout instead of verifying a transcript file, in a way that works generically
for both VTY and CTRL interface.

The scripts' names are now a bit of a misnomer, to be tweaked separately.

Change-Id: I2c31a87fa255092bcd06da239651cc50174c8faa
2017-10-18 03:43:21 +02:00
Neels Hofmeyr 32cbce1a16 osmo_verify_transcript_vty: automatically obtain the prompt string
If -n is omitted, retrieve the proper prompt name from the initial VTY opening
prompt.

Change-Id: Id5d953156023fcbfc8867c1c3634d787d0b3ac57
2017-10-18 03:42:13 +02:00
Neels Hofmeyr 7b5203f6aa osmo_verify_transcript: add error handling for missing port
Change-Id: I1627c36cfb627e7f3a9b4d9f087bf10875ae0690
2017-10-18 02:09:08 +02:00
Neels Hofmeyr 726b58dcfb add osmo_verify_transcript_{vty,ctrl}.py for easier vty and ctrl testing
While adding VTY and CTRL tests to new programs like OsmoHLR, I wanted to have
a simple way to translate a VTY interaction transcript to a VTY python test. It
is fairly trivial to simply read in a transcript, extract both the commands to
send as well as the expected results, and to verify these without having to
write one line of application-specific code. From there it was just a little
step to allow the same for CTRL interaction.

With osmo_verify_transcript_vty.py and osmo_verify_transcript_ctrl.py, it is
possible to have a simple text file of a telnet VTY or CTRL interface
interaction and run it against a given application. With the --update option,
the scripts run the given command and rewrite the transcript file to whatever
the application currently produces as response. Backed by version control, it
is super easy to tweak commands, --update the test results and verify that only
the desired bits changed. A '...' wildcard can skip any number of lines in the
expected result and is usually preserved during --update.

This python3 implementation is independent from the previous obscvty
implementations.

Take the opportunity to clarify/fix a few aspects: for example, it is now
possible to verify the hints that the interactive VTY displays when the user
enters '?' in various places, and to evaluate the prompt character '>'/'#'.

Unitl now, code is duplicated/scattered across various vty_test_runner.py
scripts in different git repositories. Now, a VTY or CTRL transcript is enough
to put a complete test in place.

The simplest invocation is directly from the Makefile, feeding an application
commandline, the proper port number to contact it and e.g. a VTY prompt name.
This new code is also usable as python modules, to be able to build more
complex tests that require specialized intermediate actions, possibly
coordinating launch of applications or data manipulation.

The first repository to employ this is osmo-hlr.git. See change-ids
I42b3b70a0439a8f2e4964d7cc31e593c1f0d7537 for VTY and
Iff93abe370b8f3ecf42082d1d0eaa1fbeca5b122 for CTRL.

Change-Id: Id47331009910e651372b9c9c76e12f2e8964cc2c
2017-10-17 02:11:58 +02:00
Neels Hofmeyr 92f310500c add osmo_ipa.py, from originally openbsc.git/contrib/ipa.py
At least now that openbsc.git has been split, the IPA and Ctrl API offered by
this file are used across multiple git repositories for python tests. Instead
of having a separate copy of ipa.py in each, have one here.

Rename to osmo_ipa.py to avoid any confusion between old and new files that
might be lying around in the python path.

Change-Id: Iaef955f04b97e8f266339b37b46d2523d1247cb9
2017-10-15 02:57:10 +02:00
Neels Hofmeyr d2e793a58a osmodumpdoc: print generated path
Change-Id: Ie39316f0b51ee518b9dce8d5f98b53f748db573b
2017-09-18 16:30:33 +02:00
Neels Hofmeyr a784f2407b osmodumpdoc: print called commands and OSError messages
Change-Id: Ib044cbb8a1b8e02cbe6852f785c75b5c7aae6174
2017-09-18 16:30:33 +02:00
Neels Hofmeyr 8e4806c5f2 osmodumpdoc: fix finding cfg when not calling from source tree
When the binary has not been built in the source tree, it was impossible to
call osmodumpdoc.py despite the -p <config-path> option. Look for config files
in that config-path.

Make sure a relative config-path is adjusted when changing to the workdir.

Change-Id: I5427d354c289ec4602411c7059c8d80e2b451f7c
2017-09-18 16:30:31 +02:00
Holger Hans Peter Freyther f41db1e337 vty: Follow links to see what is a file and what is a socket
Change-Id: I3d94cde8523a2ed26a66b8b8b3f651606aa17a9d
2017-09-13 15:42:15 +08:00
Holger Hans Peter Freyther 562bfea593 vty: Print open file descriptors of the VTY test runner
/proc/self/fd refers to the process opening the file. In this case
self will be "ls". Maybe it is better to look at the FDs open in
the test runner itself.

Change-Id: I638e94f16f4019a7b6026d1fae69e677870fb253
2017-09-13 15:38:48 +08:00
Neels Hofmeyr baa6f12260 test_all_apps: actually count nr of errors
Each test run returns 1 on error, so instead of |=, why not count the number of
errors with +=. Also print the final error count.

Change-Id: I690dde3711555a3447e5ad4cc0a04a7a869a8296
2017-03-06 15:31:08 +01:00
Neels Hofmeyr cebe8f5b00 on Exception during test, also print the actual config
When a test run encounters an Exception, the test config file name is printed,
but that may already be gone when done, so also print the complete actual test
config file contents, making it easy to reproduce the failure manually.

Change-Id: I9b00f170fb0cdceb35b9231eb1f2c545ba079d1d
2017-03-06 15:31:08 +01:00
Neels Hofmeyr 9b0a51fb87 osmoutil: end_proc: wait for term in a loop
Recent commit b59b677c9b called proc.terminate()
instead of killing right away, with a .1 second sleep. Reduce this sleep to
a minuscule first wait_time, remaining tolerant for processes that take longer.

Actually all of our current processes are very fast to terminate. This patch
was created while looking for a different problem, now that it's there we might
as well keep it.

Change-Id: I98849e4550116c5666fdf6f5d4cbb576ffa3e14a
2017-03-06 15:31:08 +01:00
Neels Hofmeyr 119bed52fa osmoutil: add pick_test() to pick unittest tests by name
Change-Id: I92f90c334169f31920c63dd5c5ac8dac215065e6
2017-03-06 15:31:08 +01:00
Neels Hofmeyr abd4b7d705 speed up python tests more than 10 fold by sleeping less
The VTYInteract tests gave a constant sleep(1) grace period for the process to
startup. This caused the test to take minutes for no reason at all.

Add code to VTYInteract._connect_socket() to try and connect right away,
retrying up to three seconds in .1 second intervals. This flies through most
tests without any sleep() at all.

When TCP socket debugging is switched on, also print how many connection tries
it took to connect the VTY socket.

Note that the openbsc python tests also add some sleep()s that also need to be
removed to benefit from this.

Change-Id: Icc337f52a93d5fe31fc4ff235ccaf4e0fe75fa39
2017-03-06 15:31:08 +01:00
Neels Hofmeyr 4e64b8821d cosmetic: put socket connection code in separate function
Prepare for upcoming patch that adds connection retries to speed up tests.

Change-Id: I2dddf8794b4241898373178c8a1aa2e98b01095c
2017-03-06 15:31:08 +01:00
Neels Hofmeyr 8e9f30f3e1 tcp_debug: don't abort when socket can't be removed
It appears that during some error conditions, the socket will not be in the tcp
socket debug tracking list, and on top of an exception this barfs as well.
Let's not care about the tcp debug list and avoid confusing error messages.

Change-Id: I8daa317fed8fc7e720dccb70fd5f7fc74fde423f
2017-03-06 15:31:08 +01:00
Neels Hofmeyr e349320992 cosmetic: early exit instead of if-cascade
It appears that during some error conditions, the socket will not be in the tcp
socket debug tracking list, and on top of an exception this barfs as well.
Let's not care about the tcp debug list and avoid confusing error messages.

Change-Id: Ib7b0e45fa1f5551da2fc81b71dcc227eee533f44
2017-03-06 15:31:08 +01:00
Neels Hofmeyr cb320b8ddf debug_tcp_sockets: clearly mark as global var
Change-Id: I56e26590ea380c7deab7ce132d688b37eb2d11a3
2017-03-06 15:31:08 +01:00
Neels Hofmeyr ac0b59d93a debug: also output nr of open file descriptors for 'tcp debug'
Change-Id: I8a583df549f3e2b79068fd8cd32b75473539410d
2017-03-06 15:31:08 +01:00