Ejemplo n.º 1
0
def after_scenario(context, scenario):
    """Teardown for each scenario
    Kill evolution (in order to make this reliable we send sigkill)
    """
    try:
        # Attach journalctl logs
        if hasattr(context, "embed"):
            os.system(
                "journalctl /usr/bin/gnome-session --no-pager -o cat --since='%s'> /tmp/journal-session.log"
                % context.log_start_time
            )
            data = open("/tmp/journal-session.log", "r").read()
            if data:
                context.embed("text/plain", data)

            context.app_class.kill()

            stdout = non_block_read(context.app_class.process.stdout)
            stderr = non_block_read(context.app_class.process.stderr)

            if stdout:
                context.embed("text/plain", stdout)

            if stderr:
                context.embed("text/plain", stderr)

        # Make some pause after scenario
        sleep(1)
    except Exception as e:
        # Stupid behave simply crashes in case exception has occurred
        print("Error in after_scenario: %s" % e.message)
Ejemplo n.º 2
0
def after_scenario(context, scenario):
    """Teardown for each scenario
    Kill evolution (in order to make this reliable we send sigkill)
    """
    try:
        # Attach journalctl logs
        if hasattr(context, "embed"):
            os.system(
                "journalctl /usr/bin/gnome-session --no-pager -o cat --since='%s'> /tmp/journal-session.log"
                % context.log_start_time)
            data = open("/tmp/journal-session.log", 'r').read()
            if data:
                context.embed('text/plain', data)

            context.app_class.kill()

            stdout = non_block_read(context.app_class.process.stdout)
            stderr = non_block_read(context.app_class.process.stderr)

            if stdout:
                context.embed('text/plain', stdout)

            if stderr:
                context.embed('text/plain', stderr)

        # Make some pause after scenario
        sleep(1)
    except Exception as e:
        # Stupid behave simply crashes in case exception has occurred
        print("Error in after_scenario: %s" % e.message)
Ejemplo n.º 3
0
def after_scenario(context, scenario):
    """Teardown for each scenario
    Kill gnome-boxes (in order to make this reliable we send sigkill)
    """

    try:
        # Remove qemu____system to avoid deleting system broker machines
        for tag in scenario.tags:
            if 'system_broker' in tag:
                call("rm -rf ~/.cache/gnome-boxes/sources/qemu____system", shell=True)
                context.app_class.quit()
                context.app_class = App('gnome-boxes')
                context.app = context.app_class.startViaCommand()

        # Attach journalctl logs
        if hasattr(context, "embed"):
            os.system("journalctl /usr/bin/gnome-session --no-pager -o cat --since='%s'> /tmp/journal-session.log" \
                                                                                            % context.log_start_time)
            data = open("/tmp/journal-session.log", 'r').read()
            if data:
                context.embed('text/plain', data)

            context.app_class.quit()

            stdout = non_block_read(context.app_class.process.stdout)
            stderr = non_block_read(context.app_class.process.stderr)

            if stdout:
                context.embed('text/plain', stdout)

            if stderr:
                context.embed('text/plain', stderr)

        f = open(os.devnull, "w")

        # Shutdown all boxes
        call("for i in $(virsh list --all|tail -n +3|head -n -1|sed -e 's/^ \(-\|[0-9]\+\) *//'|cut -d' ' -f1); do " +
             "    virsh destroy $i || true; done", shell=True, stdout=f, stderr=f)

        # Remove all snapshots
        call("for i in $(virsh list --all|tail -n +3|head -n -1|sed -e 's/^ \(-\|[0-9]\+\) *//'|cut -d' ' -f1); do " +
             "    for j in $(virsh snapshot-list $i|tail -n +3|head -n -1|sed 's/^ //'|cut -d' ' -f1); do " +
             "        virsh snapshot-delete $i $j|| true; done; done", shell=True, stdout=f, stderr=f)

        # Remove all volumes
        call("for i in $(virsh vol-list gnome-boxes|tail -n +3|head -n -1|sed 's/^ //'|cut -d' ' -f1); do " +
             "    virsh vol-delete $i gnome-boxes; done", shell=True, stdout=f)

        # Remove all save states
        call("rm -rf ~/.config/libvirt/qemu/save/*", shell=True, stderr=f)

        # Remove all sources
        call("rm -rf ~/.cache/gnome-boxes/sources/*", shell=True, stderr=f)

        # Undefine all boxes
        call("for i in $(virsh list --all|tail -n +3|head -n -1|sed -e 's/^ \(-\|[0-9]\+\) *//'|cut -d' ' -f1); do " +
             "    virsh undefine --managed-save $i; done", shell=True, stdout=f)

        f.close()

    except Exception as e:
        # Stupid behave simply crashes in case exception has occurred
        print("Error in after_scenario: %s" % e.message)
Ejemplo n.º 4
0
def after_scenario(context, scenario):
    """Teardown for each scenario
    Kill gnome-boxes (in order to make this reliable we send sigkill)
    """

    try:
        # Remove qemu____system to avoid deleting system broker machines
        for tag in scenario.tags:
            if 'system_broker' in tag:
                call("rm -rf ~/.cache/gnome-boxes/sources/qemu____system", shell=True)


        if call('pidof gnome-boxes > /dev/null' , shell=True) == 0:
            if "quit_via_panel" not in scenario.tags and "quit_via_shortcut" not in scenario.tags:
                if "open_in_new_window" in scenario.tags \
                or "poweroff_in_new_window" in scenario.tags \
                or "open_three_new_windows"  in scenario.tags:
                    context.execute_steps(u"""* Focus "main" window""")
                else:
                    context.execute_steps(u"""
                        * Hit "Esc"
                        * Hit "Esc"
                         """)

                backs = []
                backs = context.app.findChildren(lambda x: x.name == 'Back' and x.showing)
                if len(backs) != 0:
                    if backs[0].showing:
                        backs[0].click()

                if context.app.child(roleName='layered pane').children != []:
                    context.execute_steps(u"""
                        * Press "Select Items"
                        * Press "(Click on items to select them)"
                        * Press "Select All"
                        * Press "Delete"
                        * Close warning""")
                #context.execute_steps(u"""* Quit Boxes""")

                context.app_class.quit()

        if hasattr(context, "embed"):

            # Attach stdout
            stdout = non_block_read(context.app_class.process.stdout)
            if stdout:
                context.embed('text/plain', stdout, caption="Stdout")

            stderr = non_block_read(context.app_class.process.stderr)
            if stderr:
                context.embed('text/plain', stderr, caption="Stderr")

            if hasattr(context, "app_class") and context.app_class.recordVideo:
                videos_dir = os.path.expanduser('~/Videos')
                onlyfiles = [f for f in os.listdir(videos_dir) if os.path.isfile(os.path.join(videos_dir, f))]
                onlyfiles.sort()
                if onlyfiles != []:
                    video = os.path.join(videos_dir, onlyfiles[-1])
                    if hasattr(context, "embed"):
                        context.embed('video/webm', open(video, 'r').read(), caption="Video")


        f = open(os.devnull, "w")

        # Shutdown all boxes
        call("for i in $(virsh list --all|tail -n +3|head -n -1|sed -e 's/^ \(-\|[0-9]\+\) *//'|cut -d' ' -f1); do " +
             "    virsh destroy $i || true; done", shell=True, stdout=f, stderr=f)

        # Remove all snapshots
        call("for i in $(virsh list --all|tail -n +3|head -n -1|sed -e 's/^ \(-\|[0-9]\+\) *//'|cut -d' ' -f1); do " +
             "    for j in $(virsh snapshot-list $i|tail -n +3|head -n -1|sed 's/^ //'|cut -d' ' -f1); do " +
             "        virsh snapshot-delete $i $j|| true; done; done", shell=True, stdout=f, stderr=f)

        # Remove all volumes
        call("for i in $(virsh vol-list gnome-boxes|tail -n +3|head -n -1|sed 's/^ //'|cut -d' ' -f1); do " +
             "    virsh vol-delete $i gnome-boxes; done", shell=True, stdout=f)

        # Remove all save states
        call("rm -rf ~/.config/libvirt/qemu/save/*", shell=True, stderr=f)

        # Remove all sources
        call("rm -rf ~/.cache/gnome-boxes/sources/*", shell=True, stderr=f)

        # Undefine all boxes
        call("for i in $(virsh list --all|tail -n +3|head -n -1|sed -e 's/^ \(-\|[0-9]\+\) *//'|cut -d' ' -f1); do " +
             "    virsh undefine --managed-save $i; done", shell=True, stdout=f)

        f.close()

    except Exception as e:
        # Stupid behave simply crashes in case exception has occurred
        print("Error in after_scenario: %s" % e.message)
Ejemplo n.º 5
0
def after_scenario(context, scenario):
    """Teardown for each scenario
    Kill gnome-boxes (in order to make this reliable we send sigkill)
    """

    try:
        # Remove qemu____system to avoid deleting system broker machines
        for tag in scenario.tags:
            if 'system_broker' in tag:
                call("rm -rf ~/.cache/gnome-boxes/sources/qemu____system",
                     shell=True)
                context.app_class.quit()
                context.app_class = App('gnome-boxes')
                context.app = context.app_class.startViaCommand()

        # Attach journalctl logs
        if hasattr(context, "embed"):
            os.system("journalctl /usr/bin/gnome-session --no-pager -o cat --since='%s'> /tmp/journal-session.log" \
                                                                                            % context.log_start_time)
            data = open("/tmp/journal-session.log", 'r').read()
            if data:
                context.embed('text/plain', data)

            context.app_class.quit()

            stdout = non_block_read(context.app_class.process.stdout)
            stderr = non_block_read(context.app_class.process.stderr)

            if stdout:
                context.embed('text/plain', stdout)

            if stderr:
                context.embed('text/plain', stderr)

        f = open(os.devnull, "w")

        # Shutdown all boxes
        call(
            "for i in $(virsh list --all|tail -n +3|head -n -1|sed -e 's/^ \(-\|[0-9]\+\) *//'|cut -d' ' -f1); do "
            + "    virsh destroy $i || true; done",
            shell=True,
            stdout=f,
            stderr=f)

        # Remove all snapshots
        call(
            "for i in $(virsh list --all|tail -n +3|head -n -1|sed -e 's/^ \(-\|[0-9]\+\) *//'|cut -d' ' -f1); do "
            +
            "    for j in $(virsh snapshot-list $i|tail -n +3|head -n -1|sed 's/^ //'|cut -d' ' -f1); do "
            + "        virsh snapshot-delete $i $j|| true; done; done",
            shell=True,
            stdout=f,
            stderr=f)

        # Remove all volumes
        call(
            "for i in $(virsh vol-list gnome-boxes|tail -n +3|head -n -1|sed 's/^ //'|cut -d' ' -f1); do "
            + "    virsh vol-delete $i gnome-boxes; done",
            shell=True,
            stdout=f)

        # Remove all save states
        call("rm -rf ~/.config/libvirt/qemu/save/*", shell=True, stderr=f)

        # Remove all sources
        call("rm -rf ~/.cache/gnome-boxes/sources/*", shell=True, stderr=f)

        # Undefine all boxes
        call(
            "for i in $(virsh list --all|tail -n +3|head -n -1|sed -e 's/^ \(-\|[0-9]\+\) *//'|cut -d' ' -f1); do "
            + "    virsh undefine --managed-save $i; done",
            shell=True,
            stdout=f)

        f.close()

    except Exception as e:
        # Stupid behave simply crashes in case exception has occurred
        print("Error in after_scenario: %s" % e.message)