aboutsummaryrefslogtreecommitdiffstats
path: root/resources/libraries/python/VppConfigGenerator.py
diff options
context:
space:
mode:
authorPeter Mikus <pmikus@cisco.com>2017-08-21 11:01:24 +0200
committerPeter Mikus <pmikus@cisco.com>2017-10-09 09:35:05 +0000
commitdf5ed0d9317e2a1d4a7248459cc6aec39f80a052 (patch)
tree7478e6273ef87b81c536c978e30e3435e4ceee2d /resources/libraries/python/VppConfigGenerator.py
parent08e35e37f7ad3394cea86c22ab7ffd990651c112 (diff)
CSIT-768: Refactor Python container libraries
CSIT-769: Implement L2 RF keywords for container orchestration Change-Id: I7637d1ecc3a45111522b8d6c578b3f88369aff6b Signed-off-by: Peter Mikus <pmikus@cisco.com>
Diffstat (limited to 'resources/libraries/python/VppConfigGenerator.py')
-rw-r--r--resources/libraries/python/VppConfigGenerator.py75
1 files changed, 17 insertions, 58 deletions
diff --git a/resources/libraries/python/VppConfigGenerator.py b/resources/libraries/python/VppConfigGenerator.py
index dac8bae6bb..7bd0175b3d 100644
--- a/resources/libraries/python/VppConfigGenerator.py
+++ b/resources/libraries/python/VppConfigGenerator.py
@@ -61,6 +61,23 @@ class VppConfigGenerator(object):
"""
self._vpp_config_filename = filename
+ def get_config_filename(self):
+ """Get startup configuration filename.
+
+ :returns: Startup configuration filename.
+ :rtype: str
+ """
+ return self._vpp_config_filename
+
+ def get_config_str(self):
+ """Get dumped startup configuration in VPP config format.
+
+ :returns: Startup configuration in VPP config format.
+ :rtype: str
+ """
+ self.dump_config(self._nodeconfig)
+ return self._vpp_config
+
def add_config_item(self, config, value, path):
"""Add startup configuration item.
@@ -349,61 +366,3 @@ class VppConfigGenerator(object):
else:
raise RuntimeError('VPP failed to restart on node {}'.
format(self._hostname))
-
- def apply_config_lxc(self, lxc_name, waittime=5, retries=12):
- """Generate and apply VPP configuration for node in a container.
-
- Use data from calls to this class to form a startup.conf file and
- replace /etc/vpp/startup.conf with it on node inside a container.
-
- :param lxc_name: LXC container name.
- :param waittime: Time to wait for VPP to restart (default 5 seconds).
- :param retries: Number of times (default 12) to re-try waiting.
- :type lxc_name: str
- :type waittime: int
- :type retries: int
- :raises RuntimeError: If writing config file failed, or restarting of
- VPP failed.
- """
- self.dump_config(self._nodeconfig)
-
- ssh = SSH()
- ssh.connect(self._node)
-
- # We're using this "| sudo tee" construct because redirecting
- # a sudo's output ("sudo echo xxx > /path/to/file") does not
- # work on most platforms...
- (ret, _, _) = \
- ssh.exec_command_lxc('echo "{0}" | sudo tee {1}'.
- format(self._vpp_config,
- self._vpp_config_filename), lxc_name)
-
- if ret != 0:
- raise RuntimeError('Writing config file failed in {0} to node {1}'.
- format(lxc_name, self._hostname))
-
- # Instead of restarting, we'll do separate start and stop
- # actions. This way we don't care whether VPP was running
- # to begin with.
- ssh.exec_command_lxc('service {0} stop'.
- format(self._vpp_service_name), lxc_name)
- (ret, _, _) = \
- ssh.exec_command_lxc('service {0} start'.
- format(self._vpp_service_name), lxc_name)
- if ret != 0:
- raise RuntimeError('Restarting VPP failed in {0} on node {1}'.
- format(lxc_name, self._hostname))
-
- # Sleep <waittime> seconds, up to <retry> times,
- # and verify if VPP is running.
- for _ in range(retries):
- time.sleep(waittime)
- (ret, _, _) = \
- ssh.exec_command_lxc('echo show hardware-interfaces | '
- 'nc 0 5002 || echo "VPP not yet running"',
- lxc_name)
- if ret == 0:
- break
- else:
- raise RuntimeError('VPP failed to restart in {0} on node {1}'.
- format(lxc_name, self._hostname))