from nitsi.test import test
from nitsi.logger import init_logging
import logging
+import argparse
+
+from nitsi.recipe import RecipeExeption
+
+from nitsi.test import TestException
logger = logging.getLogger("nitsi")
logger.setLevel(logging.DEBUG)
# add the handlers to the logger
logger.addHandler(ch)
-if __name__ == "__main__":
- import argparse
-
+def main():
parser = argparse.ArgumentParser()
parser.add_argument("-d", "--directory", dest="dir")
- parser.add_argument("-v" "--version", help="Display version and exit",
+ parser.add_argument("-v", "--version", help="Display version and exit",
action="store_true", dest="version")
args = parser.parse_args()
+ # We just log the version and exit
if args.version:
logger.info("nitsi version: {}".format("@PACKAGE_VERSION@"))
- else:
- log_dir = init_logging(args.dir)
- # We now going to log everything to log_dir/genaral.log
- fh = logging.FileHandler("{}/general.log".format(log_dir))
- fh.setLevel(logging.DEBUG)
- logger.addHandler(fh)
- logger.debug("We now logging everything to {}/general.log".format(log_dir))
+ return 0
+
+ # For all other stuff we need logging to a file
+ log_dir = init_logging(args.dir)
+ # We now going to log everything to log_dir/genaral.log
+ fh = logging.FileHandler("{}/general.log".format(log_dir))
+ fh.setLevel(logging.DEBUG)
+ logger.addHandler(fh)
+ logger.debug("We now logging everything to {}/general.log".format(log_dir))
+ # here we run a test
+ try:
currenttest = test(args.dir, log_dir)
currenttest.read_settings()
currenttest.virtual_environ_setup()
currenttest.load_recipe()
- try:
- currenttest.virtual_environ_start()
- currenttest.run_recipe()
- except BaseException as e:
- print(e)
- finally:
- currenttest.virtual_environ_stop()
\ No newline at end of file
+ except RecipeExeption as e:
+ logger.exception(e)
+ exit(2)
+
+ try:
+ currenttest.virtual_environ_start()
+ currenttest.run_recipe()
+ except TestException as e:
+ logger.exception(e)
+ return 1
+ except BaseException as e:
+ logger.exception(e)
+ return 3
+ finally:
+ currenttest.virtual_environ_stop()
+
+ return 0
+
+if __name__ == "__main__":
+ main()
\ No newline at end of file
class RecipeExeption(Exception):
- pass
+ def __init__(self, message):
+ self.message = message
if not os.path.isfile(self.recipe_file):
self.log.error("{} is not a file".format(self.recipe_file))
- raise RecipeExeption
+ raise RecipeExeption("{} is not a file".format(self.recipe_file)())
try:
with open(self.recipe_file) as fobj:
self.raw_recipe = fobj.readlines()
except FileNotFoundError as error:
self.log.error("No such file: {}".format(vm_xml_file))
+ raise error
@property
def recipe(self):
raw_line = line.split(":", 1)
if len(raw_line) < 2:
self.log.error("Error parsing the recipe in line {}".format(i))
- raise RecipeExeption
+ raise RecipeExeption("Error parsing the recipe in line {}".format(i))
cmd = raw_line[1].strip()
raw_line = raw_line[0].strip().split(" ")
if len(raw_line) == 0:
self.log.error("Failed to parse the recipe in line {}".format(i))
- raise RecipeExeption
+ raise RecipeExeption("Failed to parse the recipe in line {}".format(i))
if raw_line[0].strip() == "":
self.log.error("Failed to parse the recipe in line {}".format(i))
- raise RecipeExeption
+ raise RecipeExeption("Failed to parse the recipe in line {}".format(i))
machine = raw_line[0].strip()
path = path + "/recipe"
if path in self.circle:
self.log.error("Detect import loop!")
- raise RecipeExeption
+ raise RecipeExeption("Detect import loop!")
self.circle.append(path)
recipe_to_include = recipe(path, circle=self.circle)
logger = logging.getLogger("nitsi.test")
+
+class TestException(Exception):
+ def __init__(self, message):
+ self.message = message
+
class test():
def __init__(self, path, log_path):
try:
return_value = self.virtual_machines[line[0]].cmd(line[2])
self.log.debug("Return value is: {}".format(return_value))
if return_value != "0" and line[1] == "":
- self.log.error("Failed to execute command '{}' on {}, return code: {}".format(line[2],line[0], return_value))
- return False
+ raise TestException("Failed to execute command '{}' on {}, return code: {}".format(line[2],line[0], return_value))
elif return_value == "0" and line[1] == "!":
- self.log.error("Succeded to execute command '{}' on {}, return code: {}".format(line[2],line[0],return_value))
- return False
+ raise TestException("Succeded to execute command '{}' on {}, return code: {}".format(line[2],line[0],return_value))
else:
self.log.debug("Command '{}' on {} returned with: {}".format(line[2],line[0],return_value))
+++ /dev/null
-alice: echo "Hello World"
-bob: echo "Hello World"
-alice: ls -l
-all: blkid
-alice,bob !: eecho "This is a comma seperated list"
-include: ../test2
+++ /dev/null
-[DEFAULT]
-Name = Hello World
-Description = This is a
- short description.
-
-Copy_from =
-Copy_to = /root/
-
-[VIRTUAL_ENVIRONMENT]
-Name = basic
-path = ../virtual-environment/basic
-
+++ /dev/null
-alice: echo "This is test2 on alice"
-include: ../test3
+++ /dev/null
-[DEFAULT]
-Name = Hello World
-Description = This is a
- short description.
-
-[VIRTUAL_ENVIRONMENT]
-Name = basic
-path = ../virtual-environment/basic
-
+++ /dev/null
-alice: echo "This is test3 on alice"
-all: echo "This is test3 on all"
\ No newline at end of file
+++ /dev/null
-[DEFAULT]
-Name = Hello World
-Description = This is a
- short description.
-
-[VIRTUAL_ENVIRONMENT]
-Name = basic
-path = ../virtual-environment/basic
-
+++ /dev/null
-<domain type='kvm'>
- <name>alice</name>
- <uuid>76eb4b45-158b-435d-84eb-0bdc0aafd1f8</uuid>
- <memory unit='KiB'>1048576</memory>
- <currentMemory unit='KiB'>1048576</currentMemory>
- <vcpu placement='static'>1</vcpu>
- <os>
- <type arch='x86_64' machine='pc-i440fx-2.8'>hvm</type>
- <boot dev='hd'/>
- </os>
- <features>
- <acpi/>
- <apic/>
- <vmport state='off'/>
- </features>
- <cpu mode='custom' match='exact'>
- <model fallback='allow'>Broadwell-noTSX</model>
- </cpu>
- <clock offset='utc'>
- <timer name='rtc' tickpolicy='catchup'/>
- <timer name='pit' tickpolicy='delay'/>
- <timer name='hpet' present='no'/>
- </clock>
- <on_poweroff>destroy</on_poweroff>
- <on_reboot>restart</on_reboot>
- <on_crash>restart</on_crash>
- <pm>
- <suspend-to-mem enabled='no'/>
- <suspend-to-disk enabled='no'/>
- </pm>
- <devices>
- <emulator>/usr/bin/kvm</emulator>
- <disk type='file' device='disk'>
- <driver name='qemu' type='qcow2'/>
- <source file='/var/lib/libvirt/images/alice.qcow2'/>
- <target dev='vda' bus='virtio'/>
- <address type='pci' domain='0x0000' bus='0x00' slot='0x08' function='0x0'/>
- </disk>
- <controller type='usb' index='0' model='ich9-ehci1'>
- <address type='pci' domain='0x0000' bus='0x00' slot='0x06' function='0x7'/>
- </controller>
- <controller type='usb' index='0' model='ich9-uhci1'>
- <master startport='0'/>
- <address type='pci' domain='0x0000' bus='0x00' slot='0x06' function='0x0' multifunction='on'/>
- </controller>
- <controller type='usb' index='0' model='ich9-uhci2'>
- <master startport='2'/>
- <address type='pci' domain='0x0000' bus='0x00' slot='0x06' function='0x1'/>
- </controller>
- <controller type='usb' index='0' model='ich9-uhci3'>
- <master startport='4'/>
- <address type='pci' domain='0x0000' bus='0x00' slot='0x06' function='0x2'/>
- </controller>
- <controller type='pci' index='0' model='pci-root'/>
- <controller type='virtio-serial' index='0'>
- <address type='pci' domain='0x0000' bus='0x00' slot='0x07' function='0x0'/>
- </controller>
- <interface type='network'>
- <mac address='52:54:00:8a:b8:b5'/>
- <source network='net1'/>
- <model type='virtio'/>
- <address type='pci' domain='0x0000' bus='0x00' slot='0x03' function='0x0'/>
- </interface>
- <interface type='network'>
- <mac address='52:54:00:ea:62:65'/>
- <source network='net2'/>
- <model type='rtl8139'/>
- <address type='pci' domain='0x0000' bus='0x00' slot='0x04' function='0x0'/>
- </interface>
- <serial type='pty'>
- <target port='0'/>
- </serial>
- <console type='pty'>
- <target type='serial' port='0'/>
- </console>
- <channel type='unix'>
- <target type='virtio' name='org.qemu.guest_agent.0'/>
- <address type='virtio-serial' controller='0' bus='0' port='1'/>
- </channel>
- <channel type='spicevmc'>
- <target type='virtio' name='com.redhat.spice.0'/>
- <address type='virtio-serial' controller='0' bus='0' port='2'/>
- </channel>
- <input type='tablet' bus='usb'>
- <address type='usb' bus='0' port='1'/>
- </input>
- <input type='mouse' bus='ps2'/>
- <input type='keyboard' bus='ps2'/>
- <graphics type='spice' autoport='yes'>
- <listen type='address'/>
- <image compression='off'/>
- </graphics>
- <sound model='ich6'>
- <address type='pci' domain='0x0000' bus='0x00' slot='0x05' function='0x0'/>
- </sound>
- <video>
- <model type='qxl' ram='65536' vram='65536' vgamem='16384' heads='1' primary='yes'/>
- <address type='pci' domain='0x0000' bus='0x00' slot='0x02' function='0x0'/>
- </video>
- <redirdev bus='usb' type='spicevmc'>
- <address type='usb' bus='0' port='2'/>
- </redirdev>
- <redirdev bus='usb' type='spicevmc'>
- <address type='usb' bus='0' port='3'/>
- </redirdev>
- <memballoon model='virtio'>
- <address type='pci' domain='0x0000' bus='0x00' slot='0x09' function='0x0'/>
- </memballoon>
- </devices>
-</domain>
-
+++ /dev/null
-<domainsnapshot>
- <description>Snapshot to undo all changes from this test</description>
- <memory>no</memory>
- <disks>
- <disk name='/var/lib/libvirt/images/alice.qcow2'>
- </disk>
- </disks>
-</domainsnapshot>
+++ /dev/null
-<domain type='kvm'>
- <name>bob</name>
- <uuid>b411a615-d6af-41cb-9b30-aaf9a8c52d51</uuid>
- <memory unit='KiB'>1048576</memory>
- <currentMemory unit='KiB'>1048576</currentMemory>
- <vcpu placement='static'>1</vcpu>
- <os>
- <type arch='x86_64' machine='pc-i440fx-2.8'>hvm</type>
- <boot dev='hd'/>
- </os>
- <features>
- <acpi/>
- <apic/>
- <vmport state='off'/>
- </features>
- <cpu mode='custom' match='exact'>
- <model fallback='allow'>Broadwell-noTSX</model>
- </cpu>
- <clock offset='utc'>
- <timer name='rtc' tickpolicy='catchup'/>
- <timer name='pit' tickpolicy='delay'/>
- <timer name='hpet' present='no'/>
- </clock>
- <on_poweroff>destroy</on_poweroff>
- <on_reboot>restart</on_reboot>
- <on_crash>restart</on_crash>
- <pm>
- <suspend-to-mem enabled='no'/>
- <suspend-to-disk enabled='no'/>
- </pm>
- <devices>
- <emulator>/usr/bin/kvm</emulator>
- <disk type='file' device='disk'>
- <driver name='qemu' type='qcow2'/>
- <source file='/var/lib/libvirt/images/bob.qcow2'/>
- <target dev='vda' bus='virtio'/>
- <address type='pci' domain='0x0000' bus='0x00' slot='0x08' function='0x0'/>
- </disk>
- <controller type='usb' index='0' model='ich9-ehci1'>
- <address type='pci' domain='0x0000' bus='0x00' slot='0x06' function='0x7'/>
- </controller>
- <controller type='usb' index='0' model='ich9-uhci1'>
- <master startport='0'/>
- <address type='pci' domain='0x0000' bus='0x00' slot='0x06' function='0x0' multifunction='on'/>
- </controller>
- <controller type='usb' index='0' model='ich9-uhci2'>
- <master startport='2'/>
- <address type='pci' domain='0x0000' bus='0x00' slot='0x06' function='0x1'/>
- </controller>
- <controller type='usb' index='0' model='ich9-uhci3'>
- <master startport='4'/>
- <address type='pci' domain='0x0000' bus='0x00' slot='0x06' function='0x2'/>
- </controller>
- <controller type='pci' index='0' model='pci-root'/>
- <controller type='virtio-serial' index='0'>
- <address type='pci' domain='0x0000' bus='0x00' slot='0x07' function='0x0'/>
- </controller>
- <interface type='network'>
- <mac address='52:54:00:36:ba:7d'/>
- <source network='net1'/>
- <model type='virtio'/>
- <address type='pci' domain='0x0000' bus='0x00' slot='0x03' function='0x0'/>
- </interface>
- <interface type='network'>
- <mac address='52:54:00:e3:cb:28'/>
- <source network='net2'/>
- <model type='rtl8139'/>
- <address type='pci' domain='0x0000' bus='0x00' slot='0x04' function='0x0'/>
- </interface>
- <serial type='pty'>
- <target port='0'/>
- </serial>
- <console type='pty'>
- <target type='serial' port='0'/>
- </console>
- <channel type='unix'>
- <target type='virtio' name='org.qemu.guest_agent.0'/>
- <address type='virtio-serial' controller='0' bus='0' port='1'/>
- </channel>
- <channel type='spicevmc'>
- <target type='virtio' name='com.redhat.spice.0'/>
- <address type='virtio-serial' controller='0' bus='0' port='2'/>
- </channel>
- <input type='tablet' bus='usb'>
- <address type='usb' bus='0' port='1'/>
- </input>
- <input type='mouse' bus='ps2'/>
- <input type='keyboard' bus='ps2'/>
- <graphics type='spice' autoport='yes'>
- <listen type='address'/>
- <image compression='off'/>
- </graphics>
- <sound model='ich6'>
- <address type='pci' domain='0x0000' bus='0x00' slot='0x05' function='0x0'/>
- </sound>
- <video>
- <model type='qxl' ram='65536' vram='65536' vgamem='16384' heads='1' primary='yes'/>
- <address type='pci' domain='0x0000' bus='0x00' slot='0x02' function='0x0'/>
- </video>
- <redirdev bus='usb' type='spicevmc'>
- <address type='usb' bus='0' port='2'/>
- </redirdev>
- <redirdev bus='usb' type='spicevmc'>
- <address type='usb' bus='0' port='3'/>
- </redirdev>
- <memballoon model='virtio'>
- <address type='pci' domain='0x0000' bus='0x00' slot='0x09' function='0x0'/>
- </memballoon>
- </devices>
-</domain>
-
+++ /dev/null
-<domainsnapshot>
- <description>Snapshot to undo all changes from this test</description>
- <memory>no</memory>
- <disks>
- <disk name='/var/lib/libvirt/images/bob.qcow2'>
- </disk>
- </disks>
-</domainsnapshot>
+++ /dev/null
-<network>
- <name>net1</name>
- <uuid>c2c82218-4aff-466a-bc20-57f723d6ce3d</uuid>
- <bridge name='virbr4' stp='on' delay='0'/>
- <mac address='52:54:00:c4:0c:3b'/>
- <domain name='net1'/>
-</network>
-
+++ /dev/null
-<network>
- <name>net2</name>
- <uuid>36d10800-09f3-43a7-b99f-3200722393eb</uuid>
- <bridge name='virbr5' stp='on' delay='0'/>
- <mac address='52:54:00:28:54:45'/>
- <domain name='net2'/>
-</network>
-
+++ /dev/null
-[DEFAULT]
-name = Basic
-machines = alice, bob
-networks = network1, network2
-uri = qemu:///system
-
-[alice]
-xml_file = machines/alice/machine.xml
-snapshot_xml_file = machines/alice/snapshot.xml
-image = /var/lib/libvirt/images/alice.qcow2
-root_uid = 45598e92-3487-4a1b-961d-79aa3dd42a7d
-username = root
-password = 25814@root
-
-[bob]
-xml_file = machines/bob/machine.xml
-snapshot_xml_file = machines/bob/snapshot.xml
-image = /var/lib/libvirt/images/bob.qcow2
-root_uid = 45598e92-3487-4a1b-961d-79aa3dd42a7d
-username = root
-password = 25814@root
-
-[network1]
-xml_file = network/network1/network.xml
-
-[network2]
-xml_file = network/network2/network.xml
\ No newline at end of file