def RemoveEntry(config, name):
    logging.info("Removing remote named {0}".format(name))
    param = "remote remove {0}".format(name)
    if utility_functions.RunCmd("git", param) == 0:
        config.Remove(name)
    else:
        logging.error("Failed to remove remote for {0}".format(name))
Esempio n. 2
0
    def Runner(env):
        ''' Runs QEMU '''
        VirtualDrive = env.GetValue("VIRTUAL_DRIVE_PATH")
        OutputPath_FV = os.path.join(env.GetValue("BUILD_OUTPUT_BASE"), "FV")

        # Check if QEMU is on the path, if not find it
        executable = "qemu-system-x86_64"

        # write messages to stdio
        args = "-debugcon stdio"
        # debug messages out thru virtual io port
        args += " -global isa-debugcon.iobase=0x402"
        # Turn off S3 support
        args += " -global ICH9-LPC.disable_s3=1"
        # turn off network
        args += " -net none"
        # Mount disk with startup.nsh
        if os.path.isfile(VirtualDrive):
            args += f" -hdd {VirtualDrive}"
        elif os.path.isdir(VirtualDrive):
            args += f" -drive file=fat:rw:{VirtualDrive},format=raw,media=disk"
        else:
            logging.critical("Virtual Drive Path Invalid")

        args += " -machine q35,smm=on"  #,accel=(tcg|kvm)"
        args += " -m 2048"
        args += " -cpu qemu64,+rdrand"  # most compatible x64 CPU model + RDRAND support (not included by default)
        #args += " -smp ..."
        args += " -global driver=cfi.pflash01,property=secure,value=on"
        args += " -drive if=pflash,format=raw,unit=0,file=" + \
            os.path.join(OutputPath_FV, "QEMUQ35_CODE.fd") + ",readonly=on"
        args += " -drive if=pflash,format=raw,unit=1,file=" + \
            os.path.join(OutputPath_FV, "QEMUQ35_VARS.fd")

        # Add XHCI USB controller and mouse
        args += " -device qemu-xhci,id=usb"
        args += " -device usb-mouse,id=input0,bus=usb.0,port=1"  # add a usb mouse
        #args += " -device usb-kbd,id=input1,bus=usb.0,port=2"    # add a usb keyboar
        args += " -smbios type=0,vendor=Palindrome,uefi=on -smbios type=1,manufacturer=Palindrome,product=MuQemuQ35,serial=42-42-42-42"

        if (env.GetValue("QEMU_HEADLESS").upper() == "TRUE"):
            args += " -display none"  # no graphics
        else:
            args += " -vga cirrus"  #std is what the default is

        # Check for gdb server setting
        gdb_port = env.GetValue("GDB_SERVER")
        if (gdb_port != None):
            logging.log(logging.INFO,
                        "Enabling GDB server at port tcp::" + gdb_port + ".")
            args += " -gdb tcp::" + gdb_port

        # Run QEMU
        #ret = QemuRunner.RunCmd(executable, args,  thread_target=QemuRunner.QemuCmdReader)
        ret = utility_functions.RunCmd(executable, args)
        ## TODO: restore the customized RunCmd once unit tests with asserts are figured out
        if ret == 0xc0000005:
            ret = 0

        return ret
def MultiFetch(remotes, tags=False, retries=3):
    '''
    do git operations to fetch the specified entries. Supports fetching in parallel for speed, and supports retries to
    add robustness to transient fetch failures.

    return
        0:          success
        non-zero:   git command line error unresolved by retry.
    '''
    param = "fetch"
    param += " -j {0}".format(len(remotes))
    if (tags):
        # might want to look at something more complex to avoid tag conflicts
        # https://stackoverflow.com/questions/22108391/git-checkout-a-remote-tag-when-two-remotes-have-the-same-tag-name
        # param += "+refs/heads/:refs/remotes/{0}/ +refs/tags/:refs/rtags/{0}/".format(name)
        param += " --tags"
    else:
        param += " --no-tags"
    param += " --multiple " + " ".join(remotes)

    for _ in range(retries):
        ret = utility_functions.RunCmd("git", param)
        if ret == 0:
            break
    return ret
def ConsistencyCheckCacheConfig(config):
    '''
    Check the git remote list vs what is in the config file
    Add remote to git for anything only in config
    Add git remote from git into the config file (tags will be false)

    return
        0:          success
        non-zero:   indicates an error
    '''

    logging.debug("start consistency check between git and omnicache config")
    out = StringIO()
    param = "remote -v"
    gitnames = []  # list of git remote names as found in git repo
    gitret = utility_functions.RunCmd("git", param, outstream=out)

    if gitret != 0:
        logging.critical("Could not list git remotes")
        return gitret

    lines = out.getvalue().split('\n')
    out.close()
    for line in lines:
        line = line.strip()
        if len(line) == 0:
            # empty line
            continue
        git = line.split()
        gitnames.append(git[0])  # save for later
        if (not config.Contains(git[0])):
            logging.warning(
                "Found entry in git not in config.  Name: {0} Url: {1}".format(
                    git[0], git[1]))
            config.Add(git[0], git[1])
            config.Save()

    gitnames = set(gitnames)
    for remote in config.remotes.values():
        if (remote["name"] not in gitnames):
            logging.warning(
                "Found entry in config not in git. Name: {0} Url: {1}".format(
                    remote["name"], remote["url"]))
            param = "remote add {0} {1}".format(remote["name"], remote["url"])
            utility_functions.RunCmd("git", param)

    return 0
def AddEntry(config, name, url, tags=False):
    logging.info("Adding remote ({0} : {1}) to Omnicache".format(name, url))

    if config.Contains(name):
        logging.info("Updating remote ({0} : {1}) in Omnicache".format(
            name, url))
        param = "remote set-url {0} {1}".format(name, url)
    else:
        logging.info("Adding remote ({0} : {1}) to Omnicache".format(
            name, url))
        param = "remote add {0} {1}".format(name, url)

    if (utility_functions.RunCmd("git", param) == 0):
        config.Add(name, url, tags)
    else:
        logging.error("Failed to add remote for {0}".format(name))
def FetchEntry(name, tags=False):
    '''
    do git operation to fetch a single entry

    return
        0:          success
        non-zero:   git command line error
    '''

    param = "fetch {0}".format(name)
    if not tags:
        param += " --no-tags"
    else:
        param += " --tags"
        # might want to look at something more complex to avoid tag conflicts
        # https://stackoverflow.com/questions/22108391/git-checkout-a-remote-tag-when-two-remotes-have-the-same-tag-name
        # param += "+refs/heads/:refs/remotes/{0}/ +refs/tags/:refs/rtags/{0}/".format(name)
    return utility_functions.RunCmd("git", param)
Esempio n. 7
0
    def test_omnicache_init(self):
        testcache = os.path.join(os.path.abspath(os.getcwd()), test_dir,
                                 "testcache")
        testconfigs = [{
            "cfgfile":
            os.path.join(os.path.abspath(os.getcwd()), test_dir,
                         "testcfg.yaml"),
            "name":
            "openssl",
            "url":
            "https://github.com/openssl/openssl.git",
            "tag":
            "true"
        }, {
            "cfgfile":
            os.path.join(os.path.abspath(os.getcwd()), test_dir,
                         "testcfg2.yaml"),
            "name":
            "openssl",
            "url":
            "https://foobar.com/openssl/openssl.git",
            "tag":
            "true"
        }]

        for testconfig in testconfigs:
            currentdir = os.path.abspath(os.getcwd())
            with open(testconfig["cfgfile"], "w") as configyaml:
                configyaml.write("remotes:\n")
                configyaml.write("- name: {0}\n".format(testconfig["name"]))
                configyaml.write("  url: {0}\n".format(testconfig["url"]))
                configyaml.write("  tag: {0}\n".format(testconfig["tag"]))

            omnicache_config_file = os.path.join(testcache,
                                                 omnicache.OMNICACHE_FILENAME)
            if (os.path.isdir(testcache)):
                if (os.path.isfile(omnicache_config_file)):
                    logging.debug(
                        "OMNICACHE already exists.  No need to initialize")
            else:
                omnicache.InitOmnicache(testcache)

            omnicache_config = omnicache.OmniCacheConfig(omnicache_config_file)
            os.chdir(testcache)

            (count, input_config_remotes) = omnicache.AddEntriesFromConfig(
                omnicache_config, testconfig["cfgfile"])

            assert (count == 1)
            assert (input_config_remotes is not None)
            assert (input_config_remotes[0]["name"] == testconfig["name"])
            assert (input_config_remotes[0]["url"] == testconfig["url"])

            omnicache_config.Save()

            # check that cache properly initialized/updated
            out = StringIO()
            param = "remote -v"
            gitret = utility_functions.RunCmd("git", param, outstream=out)
            assert (gitret == 0)

            lines = out.getvalue().split('\n')
            out.close()
            assert (len(lines) > 0)
            for line in lines:
                line = line.strip()
                if (len(line) == 0):
                    # empty line
                    continue
                git = line.split()
                assert (git[0] == input_config_remotes[0]["name"])
                assert (git[1] == input_config_remotes[0]["url"])

            os.chdir(currentdir)
def InitOmnicache(path):
    logging.critical("Initialize Omnicache to {0}".format(path))
    os.makedirs(path)
    return utility_functions.RunCmd("git", "--bare init", workingdir=path)