]> git.ipfire.org Git - nitsi.git/commitdiff
Merge branch 'master' of ssh://git.ipfire.org/pub/git/people/jschlag/nitsi
authorJonatan Schlag <jonatan.schlag@ipfire.org>
Sun, 13 May 2018 17:17:21 +0000 (19:17 +0200)
committerJonatan Schlag <jonatan.schlag@ipfire.org>
Sun, 13 May 2018 17:17:21 +0000 (19:17 +0200)
16 files changed:
nitsi.in
src/nitsi/recipe.py
src/nitsi/test.py
test/recipe [deleted file]
test/settings [deleted file]
test2/recipe [deleted file]
test2/settings [deleted file]
test3/recipe [deleted file]
test3/settings [deleted file]
virtual-environment/basic/machines/alice/machine.xml [deleted file]
virtual-environment/basic/machines/alice/snapshot.xml [deleted file]
virtual-environment/basic/machines/bob/machine.xml [deleted file]
virtual-environment/basic/machines/bob/snapshot.xml [deleted file]
virtual-environment/basic/network/network1/network.xml [deleted file]
virtual-environment/basic/network/network2/network.xml [deleted file]
virtual-environment/basic/settings [deleted file]

index 2090e0dafd7a928d05588114dcca4c64a7f4ff6c..f45dbe637fcf129aa03298e293cecc0f73851065 100755 (executable)
--- a/nitsi.in
+++ b/nitsi.in
@@ -3,6 +3,11 @@
 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)
@@ -15,36 +20,52 @@ ch.setFormatter(formatter)
 # 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
index b4d3b44d6e436379b94037a05c9d41e249859d1c..394f50b264574ab86335ba8c432599309cb6910d 100644 (file)
@@ -9,7 +9,8 @@ logger = logging.getLogger("nitsi.recipe")
 
 
 class RecipeExeption(Exception):
-    pass
+    def __init__(self, message):
+        self.message = message
 
 
 
@@ -39,13 +40,14 @@ class recipe():
 
         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):
@@ -71,16 +73,16 @@ class recipe():
             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()
 
@@ -96,7 +98,7 @@ class recipe():
                 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)
 
index ecbe5f059795731ab1151520b655eefdcc2c6d96..1f7728f2f3b4747c40e5960b72b64a8e4abe2583 100755 (executable)
@@ -16,6 +16,11 @@ import logging
 
 logger = logging.getLogger("nitsi.test")
 
+
+class TestException(Exception):
+    def __init__(self, message):
+        self.message = message
+
 class test():
     def __init__(self, path, log_path):
         try:
@@ -105,11 +110,9 @@ class test():
             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))
 
diff --git a/test/recipe b/test/recipe
deleted file mode 100644 (file)
index c035b97..0000000
+++ /dev/null
@@ -1,6 +0,0 @@
-alice: echo "Hello World"
-bob: echo "Hello World"
-alice: ls -l
-all: blkid
-alice,bob !: eecho "This is a comma seperated list"
-include: ../test2
diff --git a/test/settings b/test/settings
deleted file mode 100644 (file)
index d390dc0..0000000
+++ /dev/null
@@ -1,12 +0,0 @@
-[DEFAULT]
-Name = Hello World
-Description = This is a
-    short description.
-
-Copy_from =
-Copy_to = /root/
-
-[VIRTUAL_ENVIRONMENT]
-Name = basic
-path = ../virtual-environment/basic
-
diff --git a/test2/recipe b/test2/recipe
deleted file mode 100644 (file)
index 7f96a65..0000000
+++ /dev/null
@@ -1,2 +0,0 @@
-alice: echo "This is test2 on alice"
-include: ../test3
diff --git a/test2/settings b/test2/settings
deleted file mode 100644 (file)
index 616e1a0..0000000
+++ /dev/null
@@ -1,9 +0,0 @@
-[DEFAULT]
-Name = Hello World
-Description = This is a
-    short description.
-
-[VIRTUAL_ENVIRONMENT]
-Name = basic
-path = ../virtual-environment/basic
-
diff --git a/test3/recipe b/test3/recipe
deleted file mode 100644 (file)
index 5382623..0000000
+++ /dev/null
@@ -1,2 +0,0 @@
-alice: echo "This is test3 on alice"
-all: echo "This is test3 on all"
\ No newline at end of file
diff --git a/test3/settings b/test3/settings
deleted file mode 100644 (file)
index 616e1a0..0000000
+++ /dev/null
@@ -1,9 +0,0 @@
-[DEFAULT]
-Name = Hello World
-Description = This is a
-    short description.
-
-[VIRTUAL_ENVIRONMENT]
-Name = basic
-path = ../virtual-environment/basic
-
diff --git a/virtual-environment/basic/machines/alice/machine.xml b/virtual-environment/basic/machines/alice/machine.xml
deleted file mode 100644 (file)
index 2f7d0f5..0000000
+++ /dev/null
@@ -1,111 +0,0 @@
-<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>
-
diff --git a/virtual-environment/basic/machines/alice/snapshot.xml b/virtual-environment/basic/machines/alice/snapshot.xml
deleted file mode 100644 (file)
index e996246..0000000
+++ /dev/null
@@ -1,8 +0,0 @@
-<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>
diff --git a/virtual-environment/basic/machines/bob/machine.xml b/virtual-environment/basic/machines/bob/machine.xml
deleted file mode 100644 (file)
index 0ec99ae..0000000
+++ /dev/null
@@ -1,111 +0,0 @@
-<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>
-
diff --git a/virtual-environment/basic/machines/bob/snapshot.xml b/virtual-environment/basic/machines/bob/snapshot.xml
deleted file mode 100644 (file)
index ec8b1a4..0000000
+++ /dev/null
@@ -1,8 +0,0 @@
-<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>
diff --git a/virtual-environment/basic/network/network1/network.xml b/virtual-environment/basic/network/network1/network.xml
deleted file mode 100644 (file)
index 7495723..0000000
+++ /dev/null
@@ -1,8 +0,0 @@
-<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>
-
diff --git a/virtual-environment/basic/network/network2/network.xml b/virtual-environment/basic/network/network2/network.xml
deleted file mode 100644 (file)
index 366fa74..0000000
+++ /dev/null
@@ -1,8 +0,0 @@
-<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>
-
diff --git a/virtual-environment/basic/settings b/virtual-environment/basic/settings
deleted file mode 100644 (file)
index 37735df..0000000
+++ /dev/null
@@ -1,27 +0,0 @@
-[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