[MERGED] python/osmo-python-tests[master]: fix osmo_interact_* and osmo_verify_transcript_* after dir s...

2017-12-20 Thread Harald Welte
Harald Welte has submitted this change and it was merged.

Change subject: fix osmo_interact_* and osmo_verify_transcript_* after dir split
..


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
---
M osmopy/__init__.py
A osmopy/osmo_interact/__init__.py
R osmopy/osmo_interact/common.py
A osmopy/osmo_interact/ctrl.py
A osmopy/osmo_interact/vty.py
M scripts/osmo_interact_ctrl.py
M scripts/osmo_interact_vty.py
M scripts/osmo_verify_transcript_ctrl.py
M scripts/osmo_verify_transcript_vty.py
9 files changed, 321 insertions(+), 315 deletions(-)

Approvals:
  Harald Welte: Looks good to me, approved
  Jenkins Builder: Verified



diff --git a/osmopy/__init__.py b/osmopy/__init__.py
index 6150ea4..b1b0651 100644
--- a/osmopy/__init__.py
+++ b/osmopy/__init__.py
@@ -1,4 +1,4 @@
 #!/usr/bin/env python
-__version__ = '0.0.5'
+__version__ = '0.0.6'
 
-__all__ = ['obscvty', 'osmoutil', 'osmo_ipa']
+__all__ = ['obscvty', 'osmoutil', 'osmo_ipa', 'osmo_interact']
diff --git a/osmopy/osmo_interact/__init__.py b/osmopy/osmo_interact/__init__.py
new file mode 100644
index 000..4fc4fac
--- /dev/null
+++ b/osmopy/osmo_interact/__init__.py
@@ -0,0 +1,2 @@
+#!/usr/bin/env python
+__all__ = ['common', 'vty', 'ctrl']
diff --git a/scripts/osmo_interact_common.py b/osmopy/osmo_interact/common.py
similarity index 97%
rename from scripts/osmo_interact_common.py
rename to osmopy/osmo_interact/common.py
index 5efc22d..f7070ae 100644
--- a/scripts/osmo_interact_common.py
+++ b/osmopy/osmo_interact/common.py
@@ -24,6 +24,11 @@
 osmo_interact_{vty,ctrl}.py plug VTY and CTRL interface specific bits.
 '''
 
+# Our setup.py currently wants everything to be parsable by both py2 and py3.
+# IMHO that is not a good idea, but until that changes, let's just keep this
+# py2 legacy shim in here so we can syntax-check this py3 module with py2.
+from __future__ import print_function
+
 import argparse
 import sys
 import os
diff --git a/osmopy/osmo_interact/ctrl.py b/osmopy/osmo_interact/ctrl.py
new file mode 100755
index 000..b752351
--- /dev/null
+++ b/osmopy/osmo_interact/ctrl.py
@@ -0,0 +1,114 @@
+#!/usr/bin/env python3
+#
+# (C) 2017 by sysmocom s.f.m.c. GmbH 
+# All rights reserved.
+#
+# Author: Neels Hofmeyr 
+#
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program.  If not, see .
+
+'''
+Run CTRL commands or test transcripts against a given application.  Commandline
+invocation exposes only direct command piping, the transcript verification code
+is exposed as commandline args by osmo_verify_transcript_ctrl.py.
+'''
+
+import re
+
+from .common import *
+from osmopy.osmo_ipa import Ctrl, IPA
+
+class InteractCtrl(Interact):
+next_id = 1
+keep_ids = True
+re_command = re.compile('^(SET|GET) ([^ ]*) (.*)$')
+
+class CtrlStep(Interact.StepBase):
+
+@staticmethod
+def is_next_step(line, interact_instance):
+m = InteractCtrl.re_command.match(line)
+if not m:
+return None
+next_step = InteractCtrl.CtrlStep()
+
+set_get = m.group(1)
+cmd_id = m.group(2)
+var_val = m.group(3)
+if not interact_instance.keep_ids:
+cmd_id = interact_instance.next_id
+interact_instance.next_id += 1
+next_step.command = '%s %s %s' % (set_get, cmd_id, var_val)
+
+return next_step
+
+def __init__(self, port, host, verbose=False, update=False, keep_ids=True):
+if not update:
+keep_ids = True
+self.keep_ids = keep_ids
+super().__init__(InteractCtrl.CtrlStep, port=port, host=host, 
verbose=verbose, 

python/osmo-python-tests[master]: fix osmo_interact_* and osmo_verify_transcript_* after dir s...

2017-12-19 Thread Max

Patch Set 2:

How to reproduce the issues you mention in commit log?

-- 
To view, visit https://gerrit.osmocom.org/5492
To unsubscribe, visit https://gerrit.osmocom.org/settings

Gerrit-MessageType: comment
Gerrit-Change-Id: I40a37b212274cb70ebb1e1d9d1b3743eb2d64d05
Gerrit-PatchSet: 2
Gerrit-Project: python/osmo-python-tests
Gerrit-Branch: master
Gerrit-Owner: Neels Hofmeyr 
Gerrit-Reviewer: Jenkins Builder
Gerrit-Reviewer: Max 
Gerrit-Reviewer: Neels Hofmeyr 
Gerrit-HasComments: No


python/osmo-python-tests[master]: fix osmo_interact_* and osmo_verify_transcript_* after dir s...

2017-12-19 Thread Neels Hofmeyr

Patch Set 2:

(2 comments)

https://gerrit.osmocom.org/#/c/5492/2/osmopy/osmo_interact/ctrl.py
File osmopy/osmo_interact/ctrl.py:

Line 1: #!/usr/bin/env python3
(this is actually mostly a file rename from scripts/osmo_interact_ctrl.py, no 
idea why gerrit doesn't pick up the rename.)


https://gerrit.osmocom.org/#/c/5492/2/osmopy/osmo_interact/vty.py
File osmopy/osmo_interact/vty.py:

Line 1: #!/usr/bin/env python3
(this is actually mostly a file rename from scripts/osmo_interact_vty.py, no 
idea why gerrit doesn't pick up the rename.)


-- 
To view, visit https://gerrit.osmocom.org/5492
To unsubscribe, visit https://gerrit.osmocom.org/settings

Gerrit-MessageType: comment
Gerrit-Change-Id: I40a37b212274cb70ebb1e1d9d1b3743eb2d64d05
Gerrit-PatchSet: 2
Gerrit-Project: python/osmo-python-tests
Gerrit-Branch: master
Gerrit-Owner: Neels Hofmeyr 
Gerrit-Reviewer: Jenkins Builder
Gerrit-Reviewer: Max 
Gerrit-Reviewer: Neels Hofmeyr 
Gerrit-HasComments: Yes


python/osmo-python-tests[master]: fix osmo_interact_* and osmo_verify_transcript_* after dir s...

2017-12-19 Thread Neels Hofmeyr

Patch Set 1:

(1 comment)

https://gerrit.osmocom.org/#/c/5492/1/osmopy/osmo_interact/ctrl.py
File osmopy/osmo_interact/ctrl.py:

Line 101: def main_verify_transcript_ctrl():
> Why this is here and not in actual script?
personal preference. that code was so alone in that file way over there in 
../scripts/


-- 
To view, visit https://gerrit.osmocom.org/5492
To unsubscribe, visit https://gerrit.osmocom.org/settings

Gerrit-MessageType: comment
Gerrit-Change-Id: I40a37b212274cb70ebb1e1d9d1b3743eb2d64d05
Gerrit-PatchSet: 1
Gerrit-Project: python/osmo-python-tests
Gerrit-Branch: master
Gerrit-Owner: Neels Hofmeyr 
Gerrit-Reviewer: Jenkins Builder
Gerrit-Reviewer: Max 
Gerrit-Reviewer: Neels Hofmeyr 
Gerrit-HasComments: Yes


[PATCH] python/osmo-python-tests[master]: fix osmo_interact_* and osmo_verify_transcript_* after dir s...

2017-12-19 Thread Neels Hofmeyr
Hello Max, Jenkins Builder,

I'd like you to reexamine a change.  Please visit

https://gerrit.osmocom.org/5492

to look at the new patch set (#2).

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
---
M osmopy/__init__.py
A osmopy/osmo_interact/__init__.py
R osmopy/osmo_interact/common.py
A osmopy/osmo_interact/ctrl.py
A osmopy/osmo_interact/vty.py
M scripts/osmo_interact_ctrl.py
M scripts/osmo_interact_vty.py
M scripts/osmo_verify_transcript_ctrl.py
M scripts/osmo_verify_transcript_vty.py
9 files changed, 321 insertions(+), 315 deletions(-)


  git pull ssh://gerrit.osmocom.org:29418/python/osmo-python-tests 
refs/changes/92/5492/2

diff --git a/osmopy/__init__.py b/osmopy/__init__.py
index 6150ea4..b1b0651 100644
--- a/osmopy/__init__.py
+++ b/osmopy/__init__.py
@@ -1,4 +1,4 @@
 #!/usr/bin/env python
-__version__ = '0.0.5'
+__version__ = '0.0.6'
 
-__all__ = ['obscvty', 'osmoutil', 'osmo_ipa']
+__all__ = ['obscvty', 'osmoutil', 'osmo_ipa', 'osmo_interact']
diff --git a/osmopy/osmo_interact/__init__.py b/osmopy/osmo_interact/__init__.py
new file mode 100644
index 000..4fc4fac
--- /dev/null
+++ b/osmopy/osmo_interact/__init__.py
@@ -0,0 +1,2 @@
+#!/usr/bin/env python
+__all__ = ['common', 'vty', 'ctrl']
diff --git a/scripts/osmo_interact_common.py b/osmopy/osmo_interact/common.py
similarity index 97%
rename from scripts/osmo_interact_common.py
rename to osmopy/osmo_interact/common.py
index 5efc22d..f7070ae 100644
--- a/scripts/osmo_interact_common.py
+++ b/osmopy/osmo_interact/common.py
@@ -24,6 +24,11 @@
 osmo_interact_{vty,ctrl}.py plug VTY and CTRL interface specific bits.
 '''
 
+# Our setup.py currently wants everything to be parsable by both py2 and py3.
+# IMHO that is not a good idea, but until that changes, let's just keep this
+# py2 legacy shim in here so we can syntax-check this py3 module with py2.
+from __future__ import print_function
+
 import argparse
 import sys
 import os
diff --git a/osmopy/osmo_interact/ctrl.py b/osmopy/osmo_interact/ctrl.py
new file mode 100755
index 000..b752351
--- /dev/null
+++ b/osmopy/osmo_interact/ctrl.py
@@ -0,0 +1,114 @@
+#!/usr/bin/env python3
+#
+# (C) 2017 by sysmocom s.f.m.c. GmbH 
+# All rights reserved.
+#
+# Author: Neels Hofmeyr 
+#
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program.  If not, see .
+
+'''
+Run CTRL commands or test transcripts against a given application.  Commandline
+invocation exposes only direct command piping, the transcript verification code
+is exposed as commandline args by osmo_verify_transcript_ctrl.py.
+'''
+
+import re
+
+from .common import *
+from osmopy.osmo_ipa import Ctrl, IPA
+
+class InteractCtrl(Interact):
+next_id = 1
+keep_ids = True
+re_command = re.compile('^(SET|GET) ([^ ]*) (.*)$')
+
+class CtrlStep(Interact.StepBase):
+
+@staticmethod
+def is_next_step(line, interact_instance):
+m = InteractCtrl.re_command.match(line)
+if not m:
+return None
+next_step = InteractCtrl.CtrlStep()
+
+set_get = m.group(1)
+cmd_id = m.group(2)
+var_val = m.group(3)
+if not interact_instance.keep_ids:
+cmd_id = interact_instance.next_id
+interact_instance.next_id += 1
+next_step.command = '%s %s %s' % (set_get, cmd_id, var_val)
+
+return next_step
+
+def __init__(self, port, host, verbose=False, update=False, keep_ids=True):
+if not update:
+keep_ids = True
+self.keep_ids = keep_ids
+super().__init__(InteractCtrl.CtrlStep, port=port, host=host, 
verbose=verbose, update=update)
+
+def connect(self):
+

python/osmo-python-tests[master]: fix osmo_interact_* and osmo_verify_transcript_* after dir s...

2017-12-19 Thread Max

Patch Set 1: Code-Review-1

(3 comments)

https://gerrit.osmocom.org/#/c/5492/1/osmopy/__init__.py
File osmopy/__init__.py:

Line 2: __version__ = '0.0.5'
Please bump the version to avoid confusion


https://gerrit.osmocom.org/#/c/5492/1/osmopy/osmo_interact/ctrl.py
File osmopy/osmo_interact/ctrl.py:

Line 101: def main_verify_transcript_ctrl():
Why this is here and not in actual script?


https://gerrit.osmocom.org/#/c/5492/1/scripts/osmo_interact_ctrl.py
File scripts/osmo_interact_ctrl.py:

Line 23: main_interact_ctrl()
Why not just use the function body directly? Is it used someplace else as well?


-- 
To view, visit https://gerrit.osmocom.org/5492
To unsubscribe, visit https://gerrit.osmocom.org/settings

Gerrit-MessageType: comment
Gerrit-Change-Id: I40a37b212274cb70ebb1e1d9d1b3743eb2d64d05
Gerrit-PatchSet: 1
Gerrit-Project: python/osmo-python-tests
Gerrit-Branch: master
Gerrit-Owner: Neels Hofmeyr 
Gerrit-Reviewer: Jenkins Builder
Gerrit-Reviewer: Max 
Gerrit-HasComments: Yes


[PATCH] python/osmo-python-tests[master]: fix osmo_interact_* and osmo_verify_transcript_* after dir s...

2017-12-19 Thread Neels Hofmeyr

Review at  https://gerrit.osmocom.org/5492

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
---
M osmopy/__init__.py
A osmopy/osmo_interact/__init__.py
R osmopy/osmo_interact/common.py
A osmopy/osmo_interact/ctrl.py
A osmopy/osmo_interact/vty.py
M scripts/osmo_interact_ctrl.py
M scripts/osmo_interact_vty.py
M scripts/osmo_verify_transcript_ctrl.py
M scripts/osmo_verify_transcript_vty.py
9 files changed, 320 insertions(+), 314 deletions(-)


  git pull ssh://gerrit.osmocom.org:29418/python/osmo-python-tests 
refs/changes/92/5492/1

diff --git a/osmopy/__init__.py b/osmopy/__init__.py
index 6150ea4..35ee9d6 100644
--- a/osmopy/__init__.py
+++ b/osmopy/__init__.py
@@ -1,4 +1,4 @@
 #!/usr/bin/env python
 __version__ = '0.0.5'
 
-__all__ = ['obscvty', 'osmoutil', 'osmo_ipa']
+__all__ = ['obscvty', 'osmoutil', 'osmo_ipa', 'osmo_interact']
diff --git a/osmopy/osmo_interact/__init__.py b/osmopy/osmo_interact/__init__.py
new file mode 100644
index 000..4fc4fac
--- /dev/null
+++ b/osmopy/osmo_interact/__init__.py
@@ -0,0 +1,2 @@
+#!/usr/bin/env python
+__all__ = ['common', 'vty', 'ctrl']
diff --git a/scripts/osmo_interact_common.py b/osmopy/osmo_interact/common.py
similarity index 97%
rename from scripts/osmo_interact_common.py
rename to osmopy/osmo_interact/common.py
index 5efc22d..f7070ae 100644
--- a/scripts/osmo_interact_common.py
+++ b/osmopy/osmo_interact/common.py
@@ -24,6 +24,11 @@
 osmo_interact_{vty,ctrl}.py plug VTY and CTRL interface specific bits.
 '''
 
+# Our setup.py currently wants everything to be parsable by both py2 and py3.
+# IMHO that is not a good idea, but until that changes, let's just keep this
+# py2 legacy shim in here so we can syntax-check this py3 module with py2.
+from __future__ import print_function
+
 import argparse
 import sys
 import os
diff --git a/osmopy/osmo_interact/ctrl.py b/osmopy/osmo_interact/ctrl.py
new file mode 100755
index 000..b752351
--- /dev/null
+++ b/osmopy/osmo_interact/ctrl.py
@@ -0,0 +1,114 @@
+#!/usr/bin/env python3
+#
+# (C) 2017 by sysmocom s.f.m.c. GmbH 
+# All rights reserved.
+#
+# Author: Neels Hofmeyr 
+#
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program.  If not, see .
+
+'''
+Run CTRL commands or test transcripts against a given application.  Commandline
+invocation exposes only direct command piping, the transcript verification code
+is exposed as commandline args by osmo_verify_transcript_ctrl.py.
+'''
+
+import re
+
+from .common import *
+from osmopy.osmo_ipa import Ctrl, IPA
+
+class InteractCtrl(Interact):
+next_id = 1
+keep_ids = True
+re_command = re.compile('^(SET|GET) ([^ ]*) (.*)$')
+
+class CtrlStep(Interact.StepBase):
+
+@staticmethod
+def is_next_step(line, interact_instance):
+m = InteractCtrl.re_command.match(line)
+if not m:
+return None
+next_step = InteractCtrl.CtrlStep()
+
+set_get = m.group(1)
+cmd_id = m.group(2)
+var_val = m.group(3)
+if not interact_instance.keep_ids:
+cmd_id = interact_instance.next_id
+interact_instance.next_id += 1
+next_step.command = '%s %s %s' % (set_get, cmd_id, var_val)
+
+return next_step
+
+def __init__(self, port, host, verbose=False, update=False, keep_ids=True):
+if not update:
+keep_ids = True
+self.keep_ids = keep_ids
+super().__init__(InteractCtrl.CtrlStep, port=port, host=host, 
verbose=verbose, update=update)
+
+def connect(self):
+self.next_id = 1
+super().connect()
+
+def send(self, data):
+data = Ctrl().add_header(data)
+return