Ejemplo n.º 1
0
    def __init__(self, case_root=None, infile="env_archive.xml"):
        """
        initialize an object interface to file env_archive.xml in the case directory
        """
        logger.debug("Case_root = %s", case_root)

        # Check/Build path to env_archive.xml
        if case_root is None:
            case_root = os.getcwd()

        if os.path.isabs(infile):
            fullpath = infile
        else:
            fullpath = os.path.join(case_root, infile)

        # Initialize self
        # If env_archive.xml file does not exists in case directory read default from config
        GenericXML.__init__(self, fullpath)

        # The following creates the CASEROOT/env_archive.xml contents in self.root
        if not os.path.isfile(fullpath):
            headerobj = Headers()
            headernode = headerobj.get_header_node(os.path.basename(fullpath))
            self.root.append(headernode)
            archive = Archive()
            self.root.append(archive.root)
Ejemplo n.º 2
0
def test_st_archive(self, testdir="st_archive_test"):
    archive = Archive()
    files = Files()
    components = []
    #    expect(not self.get_value("MULTI_DRIVER"),"Test not configured for multi-driver cases")

    config_archive_files = archive.get_all_config_archive_files(files)
    # create the run directory testdir and populate it with rest_file and hist_file from
    # config_archive.xml test_file_names
    if os.path.exists(testdir):
        logger.info("Removing existing test directory {}".format(testdir))
        shutil.rmtree(testdir)
    dout_s_root = os.path.join(testdir, "archive")
    archive = Archive()
    schema = files.get_schema("ARCHIVE_SPEC_FILE")
    for config_archive_file in config_archive_files:
        archive.read(config_archive_file, schema)
    comp_archive_specs = archive.get_children("comp_archive_spec")
    for comp_archive_spec in comp_archive_specs:
        components.append(archive.get(comp_archive_spec, 'compname'))
        test_file_names = archive.get_optional_child("test_file_names",
                                                     root=comp_archive_spec)
        if test_file_names is not None:
            if not os.path.exists(testdir):
                os.makedirs(os.path.join(testdir, "archive"))

            for file_node in archive.get_children("tfile",
                                                  root=test_file_names):
                fname = os.path.join(testdir, archive.text(file_node))
                disposition = archive.get(file_node, "disposition")
                logger.info("Create file {} with disposition {}".format(
                    fname, disposition))
                with open(fname, 'w') as fd:
                    fd.write(disposition + "\n")

    logger.info("testing components: {} ".format(list(set(components))))
    _archive_process(self,
                     archive,
                     None,
                     False,
                     False,
                     components=list(set(components)),
                     dout_s_root=dout_s_root,
                     casename="casename",
                     rundir=testdir,
                     testonly=True)

    _check_disposition(testdir)

    # Now test the restore capability
    testdir2 = os.path.join(testdir, "run2")
    os.makedirs(testdir2)

    restore_from_archive(self, rundir=testdir2, dout_s_root=dout_s_root)

    restfiles = [
        f for f in os.listdir(
            os.path.join(testdir, "archive", "rest", "1976-01-01-00000"))
    ]
    for _file in restfiles:
        expect(os.path.isfile(os.path.join(testdir2, _file)),
               "Expected file {} to be restored from rest dir".format(_file))

    return True
Ejemplo n.º 3
0
def test_st_archive(self, testdir="st_archive_test"):
    archive = Archive()
    files = Files()
    components = []
#    expect(not self.get_value("MULTI_DRIVER"),"Test not configured for multi-driver cases")

    config_archive_files = archive.get_all_config_archive_files(files)
    # create the run directory testdir and populate it with rest_file and hist_file from
    # config_archive.xml test_file_names
    if os.path.exists(testdir):
        logger.info("Removing existing test directory {}".format(testdir))
        shutil.rmtree(testdir)
    dout_s_root=os.path.join(testdir,"archive")
    archive = Archive()
    schema = files.get_schema("ARCHIVE_SPEC_FILE")
    for config_archive_file in config_archive_files:
        archive.read(config_archive_file, schema)
    comp_archive_specs = archive.get_children("comp_archive_spec")
    for comp_archive_spec in comp_archive_specs:
        components.append(archive.get(comp_archive_spec, 'compname'))
        test_file_names = archive.get_optional_child("test_file_names", root=comp_archive_spec)
        if test_file_names is not None:
            if not os.path.exists(testdir):
                os.makedirs(os.path.join(testdir,"archive"))

            for file_node in archive.get_children("tfile", root=test_file_names):
                fname = os.path.join(testdir,archive.text(file_node))
                disposition = archive.get(file_node, "disposition")
                logger.info("Create file {} with disposition {}".
                            format(fname, disposition))
                with open(fname, 'w') as fd:
                    fd.write(disposition+"\n")

    logger.info("testing components: {} ".format(list(set(components))))
    _archive_process(self, archive, None, False, False,components=list(set(components)),
                     dout_s_root=dout_s_root,
                     casename="casename", rundir=testdir, testonly=True)

    _check_disposition(testdir)

    # Now test the restore capability
    testdir2 = os.path.join(testdir,"run2")
    os.makedirs(testdir2)

    restore_from_archive(self, rundir=testdir2, dout_s_root=dout_s_root)

    restfiles = [f for f in os.listdir(os.path.join(testdir,"archive","rest","1976-01-01-00000"))]
    for _file in restfiles:
        expect(os.path.isfile(os.path.join(testdir2,_file)), "Expected file {} to be restored from rest dir".format(_file))

    return True