- if self._vpp_startup_conf_backup is not None:
- ret, _, _ = \
- ssh.exec_command('sudo cp {src} {dest}'.
- format(src=self._vpp_startup_conf,
- dest=self._vpp_startup_conf_backup))
- if ret != 0:
- raise RuntimeError('Backup of config file failed on node '
- '{name}'.format(name=self._hostname))
-
- ret, _, _ = \
- ssh.exec_command('echo "{config}" | sudo tee {filename}'.
- format(config=self._vpp_config,
- filename=filename))
-
- if ret != 0:
- raise RuntimeError('Writing config file failed to node {name}'.
- format(name=self._hostname))
-
- if restart_vpp:
- DUTSetup.start_service(self._node, Constants.VPP_UNIT)
-
- # Sleep <waittime> seconds, up to <retry> times,
- # and verify if VPP is running.
- for _ in range(retries):
- time.sleep(1)
- ret, stdout, _ = \
- ssh.exec_command('echo show pci | nc 0 5002 || '
- 'echo "VPP not yet running"')
- if ret == 0 and 'VPP not yet running' not in stdout:
- break
- else:
- raise RuntimeError('VPP failed to restart on node {name}'.
- format(name=self._hostname))
-
- def restore_config(self):
- """Restore VPP startup.conf from backup.
-
- :raises RuntimeError: When restoration of startup.conf file failed.
- """
-
- ssh = SSH()
- ssh.connect(self._node)
-
- ret, _, _ = ssh.exec_command('sudo cp {src} {dest}'.
- format(src=self._vpp_startup_conf_backup,
- dest=self._vpp_startup_conf))
- if ret != 0:
- raise RuntimeError('Restoration of config file failed on node '
- '{name}'.format(name=self._hostname))
+ cmd = f"echo \"{self._vpp_config}\" | sudo tee {filename}"
+ exec_cmd_no_error(
+ self._node, cmd, message=u"Writing config file failed!"
+ )
+
+ def apply_config(self, filename=None, verify_vpp=True):
+ """Generate and write VPP startup configuration to file and restart VPP.
+
+ Use data from calls to this class to form a startup.conf file and
+ replace /etc/vpp/startup.conf with it on topology node.
+
+ :param filename: Startup configuration file name.
+ :param verify_vpp: Verify VPP is running after restart.
+ :type filename: str
+ :type verify_vpp: bool
+ """
+ self.write_config(filename=filename)
+
+ VPPUtil.restart_vpp_service(self._node, self._node_key)
+ if verify_vpp:
+ VPPUtil.verify_vpp(self._node)