X-Git-Url: https://gerrit.fd.io/r/gitweb?p=csit.git;a=blobdiff_plain;f=resources%2Flibraries%2Fpython%2FDUTSetup.py;h=1f87f03cb915998e9faab5e3c25f94a861538f2b;hp=d5ebf9a0695b43375680e59be0ffea2ec318345e;hb=a060d519d0a89574f5e75d4e8d4c142fa5687555;hpb=05eba892c7d2a778e78a950966fb1a6e0d68aa60 diff --git a/resources/libraries/python/DUTSetup.py b/resources/libraries/python/DUTSetup.py index d5ebf9a069..1f87f03cb9 100644 --- a/resources/libraries/python/DUTSetup.py +++ b/resources/libraries/python/DUTSetup.py @@ -11,45 +11,135 @@ # See the License for the specific language governing permissions and # limitations under the License. +"""DUT setup library.""" + from robot.api import logger -from topology import NodeType -from ssh import SSH -from constants import Constants +from resources.libraries.python.topology import NodeType +from resources.libraries.python.ssh import SSH +from resources.libraries.python.constants import Constants +from resources.libraries.python.VatExecutor import VatExecutor -class DUTSetup(object): - def start_vpp_service_on_all_duts(self, nodes): +class DUTSetup(object): + """Contains methods for setting up DUTs.""" + @staticmethod + def start_vpp_service_on_all_duts(nodes): """Start up the VPP service on all nodes.""" ssh = SSH() for node in nodes.values(): if node['type'] == NodeType.DUT: ssh.connect(node) (ret_code, stdout, stderr) = \ - ssh.exec_command_sudo('service vpp restart') - if 0 != int(ret_code): + ssh.exec_command_sudo('service vpp restart', timeout=120) + if int(ret_code) != 0: logger.debug('stdout: {0}'.format(stdout)) logger.debug('stderr: {0}'.format(stderr)) raise Exception('DUT {0} failed to start VPP service'. - format(node['host'])) + format(node['host'])) + + @staticmethod + def vpp_show_version_verbose(node): + """Run "show version verbose" CLI command. + + :param node: Node to run command on. + :type node: dict + """ + vat = VatExecutor() + vat.execute_script("show_version_verbose.vat", node, json_out=False) + + @staticmethod + def vpp_api_trace_save(node): + """Run "api trace save" CLI command. - def setup_all_duts(self, nodes): + :param node: Node to run command on. + :type node: dict + """ + vat = VatExecutor() + vat.execute_script("api_trace_save.vat", node, json_out=False) + + @staticmethod + def vpp_api_trace_dump(node): + """Run "api trace custom-dump" CLI command. + + :param node: Node to run command on. + :type node: dict + """ + vat = VatExecutor() + vat.execute_script("api_trace_dump.vat", node, json_out=False) + + @staticmethod + def setup_all_duts(nodes): """Prepare all DUTs in given topology for test execution.""" for node in nodes.values(): if node['type'] == NodeType.DUT: - self.setup_dut(node) + DUTSetup.setup_dut(node) + + @staticmethod + def setup_dut(node): + """Run script over SSH to setup the DUT node. - def setup_dut(self, node): + :param node: DUT node to set up. + :type node: dict + + :raises Exception: If the DUT setup fails. + """ ssh = SSH() ssh.connect(node) (ret_code, stdout, stderr) = \ - ssh.exec_command('sudo -Sn bash {0}/{1}/dut_setup.sh'.format( - Constants.REMOTE_FW_DIR, Constants.RESOURCES_LIB_SH)) + ssh.exec_command('sudo -Sn bash {0}/{1}/dut_setup.sh'. + format(Constants.REMOTE_FW_DIR, + Constants.RESOURCES_LIB_SH), timeout=120) logger.trace(stdout) logger.trace(stderr) - if 0 != int(ret_code): + if int(ret_code) != 0: logger.debug('DUT {0} setup script failed: "{1}"'. - format(node['host'], stdout + stderr)) + format(node['host'], stdout + stderr)) raise Exception('DUT test setup script failed at node {}'. - format(node['host'])) + format(node['host'])) + + @staticmethod + def get_vpp_pid(node): + """Get PID of running VPP process. + + :param node: DUT node. + :type node: dict + :return: PID + :rtype: int + :raises RuntimeError if it is not possible to get the PID. + """ + + ssh = SSH() + ssh.connect(node) + ret_code, stdout, stderr = ssh.exec_command('pidof vpp') + + logger.trace(stdout) + logger.trace(stderr) + + if int(ret_code) != 0: + logger.debug('Not possible to get PID of VPP process on node: ' + '{0}\n {1}'.format(node['host'], stdout + stderr)) + raise RuntimeError('Not possible to get PID of VPP process on node:' + ' {}'.format(node['host'])) + + if len(stdout.splitlines()) != 1: + raise RuntimeError("More then one VPP PID found on node {0}". + format(node['host'])) + return int(stdout) + + @staticmethod + def get_vpp_pids(nodes): + """Get PID of running VPP process on all DUTs. + + :param nodes: DUT nodes. + :type nodes: dict + :return: PIDs + :rtype: dict + """ + + pids = dict() + for node in nodes.values(): + if node['type'] == NodeType.DUT: + pids[node['host']] = DUTSetup.get_vpp_pid(node) + return pids