aboutsummaryrefslogtreecommitdiffstats
path: root/resources/libraries/python
diff options
context:
space:
mode:
authorPeter Mikus <pmikus@cisco.com>2017-06-06 07:15:29 +0200
committerPeter Mikus <pmikus@cisco.com>2017-07-04 04:54:16 +0000
commitd166ae0881c29dfd05ed61b9a12156f17981bb6d (patch)
treea4d0c939dc99d55d12ba85fedffb33fef9475be2 /resources/libraries/python
parent036e5a85bab081bfa94b8c025c06aee0addb94cb (diff)
CSIT-651 Add keywords and template for memif
Add keywords and template for memif Change-Id: I8bd5cfe345260750a74930c8ef55690be5f2dd5e Signed-off-by: Peter Mikus <pmikus@cisco.com>
Diffstat (limited to 'resources/libraries/python')
-rw-r--r--resources/libraries/python/Memif.py80
-rw-r--r--resources/libraries/python/VatExecutor.py2
2 files changed, 82 insertions, 0 deletions
diff --git a/resources/libraries/python/Memif.py b/resources/libraries/python/Memif.py
new file mode 100644
index 0000000000..09fa2a8c3e
--- /dev/null
+++ b/resources/libraries/python/Memif.py
@@ -0,0 +1,80 @@
+# Copyright (c) 2017 Cisco and/or its affiliates.
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at:
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+"""Memif interface library."""
+
+from resources.libraries.python.ssh import SSH
+from resources.libraries.python.VatExecutor import VatExecutor, VatTerminal
+
+
+class Memif(object):
+ """Memif interface class."""
+
+ def __init__(self):
+ pass
+
+ @staticmethod
+ def create_memif_interface(node, socket, mid, role="master"):
+ """Create Memif interface on the given node.
+
+ :param node: Given node to create Memif interface on.
+ :param socket: Memif interface socket path.
+ :param mid: Memif interface ID.
+ :param role: Memif interface role [master|slave]. Default is master.
+ :type node: dict
+ :type socket: str
+ :type mid: str
+ :type role: str
+ :returns: SW interface index.
+ :rtype: int
+ :raises ValueError: If command 'create memif' fails.
+ """
+
+ with VatTerminal(node, json_param=False) as vat:
+ vat.vat_terminal_exec_cmd_from_template(
+ 'memif_create.vat',
+ socket=socket, id=mid, role=role)
+ if 'sw_if_index' in vat.vat_stdout:
+ try:
+ return int(vat.vat_stdout.split()[4])
+ except KeyError:
+ raise ValueError('Create Memif interface failed on node '
+ '{}"'.format(node['host']))
+ else:
+ raise ValueError('Create Memif interface failed on node '
+ '{}"'.format(node['host']))
+
+ @staticmethod
+ def show_memif(node):
+ """Show Memif data for the given node.
+
+ :param node: Given node to show Memif data on.
+ :type node: dict
+ """
+ vat = VatExecutor()
+ vat.execute_script("memif_dump.vat", node, json_out=False)
+
+ @staticmethod
+ def clear_memif_socks(node, *socks):
+ """Clear Memif sockets for the given node.
+
+ :param node: Given node to clear Memif sockets on.
+ :param socks: Memif sockets.
+ :type node: dict
+ :type socks: list
+ """
+ ssh = SSH()
+ ssh.connect(node)
+
+ for sock in socks:
+ ssh.exec_command_sudo('rm -f {}'.format(sock))
diff --git a/resources/libraries/python/VatExecutor.py b/resources/libraries/python/VatExecutor.py
index bfb7fce4e4..a3f12bf46f 100644
--- a/resources/libraries/python/VatExecutor.py
+++ b/resources/libraries/python/VatExecutor.py
@@ -245,6 +245,7 @@ class VatTerminal(object):
'sudo -S {}{}'.format(Constants.VAT_BIN_NAME, json_text),
self.__VAT_PROMPT)
self._exec_failure = False
+ self.vat_stdout = None
def __enter__(self):
return self
@@ -265,6 +266,7 @@ class VatTerminal(object):
try:
out = self._ssh.interactive_terminal_exec_command(self._tty, cmd,
self.__VAT_PROMPT)
+ self.vat_stdout = out
except:
self._exec_failure = True
raise