test/automated-pytest-suite/utils/guest_scripts/scripts.py
Yang Liu 33756ac899 Initial submission for starlingx pytest framework.
Include:
- util modules. such as table_parser, ssh/localhost clients, cli module,
exception, logger, etc. Util modules are mostly used by keywords.
- keywords modules. These are helper functions that are used directly by
test functions.
- platform (with platform or platform_sanity marker) and stx-openstack
(with sanity, sx_sanity, cpe_sanity, or storage_sanity marker) sanity
testcases
- pytest config conftest, and test fixture modules
- test config file template/example

Required packages:
- python3.4 or python3.5
- pytest >=3.10,<4.0
- pexpect
- requests
- pyyaml
- selenium (firefox, ffmpeg, pyvirtualdisplay, Xvfb or Xephyr or Xvnc)

Limitations:
- Anything that requires copying from Test File Server will not work until
a public share is configured to shared test files. Tests skipped for now.

Co-Authored-By: Maria Yousaf <maria.yousaf@windriver.com>
Co-Authored-By: Marvin Huang <marvin.huang@windriver.com>
Co-Authored-By: Yosief Gebremariam <yosief.gebremariam@windriver.com>
Co-Authored-By: Paul Warner <paul.warner@windriver.com>
Co-Authored-By: Xueguang Ma <Xueguang.Ma@windriver.com>
Co-Authored-By: Charles Chen <charles.chen@windriver.com>
Co-Authored-By: Daniel Graziano <Daniel.Graziano@windriver.com>
Co-Authored-By: Jordan Li <jordan.li@windriver.com>
Co-Authored-By: Nimalini Rasa <nimalini.rasa@windriver.com>
Co-Authored-By: Senthil Mukundakumar <senthil.mukundakumar@windriver.com>
Co-Authored-By: Anuejyan Manokeran <anujeyan.manokeran@windriver.com>
Co-Authored-By: Peng Peng <peng.peng@windriver.com>
Co-Authored-By: Chris Winnicki <chris.winnicki@windriver.com>
Co-Authored-By: Joe Vimar <Joe.Vimar@windriver.com>
Co-Authored-By: Alex Kozyrev <alex.kozyrev@windriver.com>
Co-Authored-By: Jack Ding <jack.ding@windriver.com>
Co-Authored-By: Ming Lei <ming.lei@windriver.com>
Co-Authored-By: Ankit Jain <ankit.jain@windriver.com>
Co-Authored-By: Eric Barrett <eric.barrett@windriver.com>
Co-Authored-By: William Jia <william.jia@windriver.com>
Co-Authored-By: Joseph Richard <Joseph.Richard@windriver.com>
Co-Authored-By: Aldo Mcfarlane <aldo.mcfarlane@windriver.com>

Story: 2005892
Task: 33750
Signed-off-by: Yang Liu <yang.liu@windriver.com>

Change-Id: I7a88a47e09733d39f024144530f5abb9aee8cad2
2019-07-15 15:30:00 -04:00

112 lines
3.3 KiB
Python

import os
class TisInitServiceScript(object):
script_path = "/etc/init.d/tis_automation_init.sh"
configuration_path = "/etc/init.d/tis_automation_init.config"
service_name = "tis_automation_init.service"
service_path = "/etc/systemd/system/{}".format(service_name)
service = """
[Unit]
Description=TiS Automation Initialization
After=NetworkManager.service network.service wrs-guest-setup.service
[Service]
Type=simple
RemainAfterExit=yes
ExecStart=/bin/bash {} start
ExecStop=/bin/bash {} stop
[Install]
WantedBy=multi-user.target
""".format(script_path, script_path)
@classmethod
def configure(cls, vm_ssh, **kwargs):
cfg = "\n".join(["{}={}".format(*kv) for kv in kwargs.items()])
vm_ssh.exec_sudo_cmd(
"cat > {} << 'EOT'\n{}\nEOT".format(cls.configuration_path, cfg),
fail_ok=False)
vm_ssh.exec_sudo_cmd(
"cat > %s << 'EOT'\n%s\nEOT" % (cls.service_path, cls.service),
fail_ok=False)
@classmethod
def enable(cls, vm_ssh):
vm_ssh.exec_sudo_cmd(
"systemctl daemon-reload", fail_ok=False)
vm_ssh.exec_sudo_cmd(
"systemctl enable %s" % cls.service_name, fail_ok=False)
@classmethod
def start(cls, vm_ssh):
vm_ssh.exec_sudo_cmd(
"systemctl daemon-reload", fail_ok=False)
vm_ssh.exec_sudo_cmd(
"systemctl start %s" % cls.service_name, fail_ok=False)
@classmethod
def src(cls):
return os.path.join(os.path.dirname(os.path.abspath(__file__)),
"tis_automation_init.sh")
@classmethod
def dst(cls):
return cls.script_path
class KPktgen(object):
script_path = "/root/kpktgen.sh"
configuration_path = "/root/kpktgen.config"
@classmethod
def src(cls):
return os.path.join(os.path.dirname(os.path.abspath(__file__)),
"kpktgen.sh")
@classmethod
def dst(cls):
return cls.script_path
@classmethod
def configure(cls, vm_ssh, **kwargs):
cfg = "\n".join(["{}={}".format(*kv) for kv in kwargs.items()])
vm_ssh.exec_sudo_cmd(
"cat > {} << 'EOT'\n{}\nEOT".format(cls.configuration_path, cfg),
fail_ok=False)
@classmethod
def start(cls, vm_ssh):
vm_ssh.exec_sudo_cmd("nohup bash {} &>/dev/null &".format(
cls.script_path))
class DPDKPktgen(object):
script_path = "/root/dpdk_pktgen.sh"
configuration_path = "/root/dpdk_pktgen.config"
@classmethod
def src(cls):
return os.path.join(os.path.dirname(os.path.abspath(__file__)),
"dpdk_pktgen.sh")
@classmethod
def dst(cls):
return cls.script_path
@classmethod
def configure(cls, vm_ssh, *cmds):
cfg = "\n".join(cmds)
vm_ssh.exec_sudo_cmd(
"cat > {} << 'EOT'\n{}\nEOT".format(cls.configuration_path, cfg),
fail_ok=False)
@classmethod
def start(cls, vm_ssh):
# dpdk pktgen REQUIRES a tty (fails during initialization otherwise)
# echo-ing 'quit' will not work, use 'kill' with 'ps aux | grep nohup'
# to terminate
vm_ssh.exec_sudo_cmd(
"nohup socat EXEC:{},pty PTY,link=pktgen.pty,echo=0,icanon=0 "
"&>/dev/null &".format(cls.script_path))