- (ret, _, _) = \
- ssh.exec_command('sudo cp {0} {1}'.
- format(self._vpp_startup_conf,
- self._vpp_startup_conf_backup))
- if ret != 0:
- raise RuntimeError('Backup of config file failed on node {}'.
- format(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 {}'.
- format(self._hostname))
-
- if restart_vpp:
- # 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('sudo service {} stop'
- .format(self._vpp_service_name))
- (ret, _, _) = \
- ssh.exec_command('sudo service {} start'
- .format(self._vpp_service_name))
- if ret != 0:
- raise RuntimeError('Restarting VPP failed on node {}'.
- format(self._hostname))
-
- # 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 hardware-interfaces | '
- '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 {}'.
- format(self._hostname))
+ cmd = ('cp {src} {dest}'.format(
+ src=self._vpp_startup_conf, dest=self._vpp_startup_conf_backup))
+ exec_cmd_no_error(
+ self._node, cmd, sudo=True, message='Copy config file failed!')