def test_mw_no_engine_dc_simple(self):
     '''
         test_mw_no_engine_dc_simple - read in and write out a standard manifest
     '''
     try:
         manifest_parser = ManifestParser("manifest-parser",
             common.MANIFEST_DC,
             validate_from_docinfo=True)
         manifest_parser.parse(doc=self.doc)
         manifest_writer = ManifestWriter("manifest-writer",
             common.MANIFEST_OUT_OK)
         manifest_writer.write(self.doc)
     except ManifestError, err:
         self.fail(str(err))
 def test_mw_no_engine_dc_simple(self):
     '''
         test_mw_no_engine_dc_simple - read in and write out a standard manifest
     '''
     try:
         manifest_parser = ManifestParser("manifest-parser",
                                          common.MANIFEST_DC,
                                          validate_from_docinfo=True)
         manifest_parser.parse(doc=self.doc)
         manifest_writer = ManifestWriter("manifest-writer",
                                          common.MANIFEST_OUT_OK)
         manifest_writer.write(self.doc)
     except ManifestError, err:
         self.fail(str(err))
示例#3
0
 def test_invalid_disk_xml(self):
     try:
         mp = ManifestParser("manifest-parser",
                             INVALID_MANIFEST,
                             validate_from_docinfo=False)
     except ManifestError, err:
         self.fail(str(err))
示例#4
0
def setup_doc_content(manifest_name, media_source):
    '''Loads the content of media manifest into a
       SEPARATE DOC instance.  Then, copy the data into the
       DOC that's used by the application, engine and other checkpoints.
    '''

    # create a separate DOC
    another_doc = DataObjectCache()

    # load the transfer manifest into the separate DOC
    manifest_parser = ManifestParser("manifest-parser",
                                     manifest_name,
                                     validate_from_docinfo=False)
    manifest_parser.parse(doc=another_doc)

    software_nodes = another_doc.get_descendants(class_type=Software)

    if len(software_nodes) != 3:
        raise RuntimeError("3 software nodes expected.  Only %d found" %
                           len(software_nodes))

    # Modify the install target values and the media mountpoint
    for software in software_nodes:
        # get the destination object
        dst_node = software.get_children(class_type=Destination,
                                         not_found_is_err=True)[0]
        dir_node = dst_node.get_children(class_type=Dir,
                                         not_found_is_err=True)[0]
        path = dir_node.dir_path
        path = path.replace(INSTALL_TARGET_VAR, INSTALL_TARGET)
        dir_node.dir_path = path

        # if this is the media transfer software node, also update the
        # value for source
        if software._name == TRANSFER_MEDIA:
            src_node = software.get_children(class_type=Source,
                                             not_found_is_err=True)[0]
            dir_node = src_node.get_children(class_type=Dir,
                                             not_found_is_err=True)[0]
            path = dir_node.dir_path
            path = path.replace(MEDIA_DIR_VAR, media_source)
            dir_node.dir_path = path

    # copy the Software classes into the common DOC
    doc = InstallEngine.get_instance().data_object_cache
    doc.volatile.insert_children(software_nodes)
def setup_doc_content(manifest_name, media_source):
    '''Loads the content of media manifest into a
       SEPARATE DOC instance.  Then, copy the data into the
       DOC that's used by the application, engine and other checkpoints.
    '''

    # create a separate DOC
    another_doc = DataObjectCache()

    # load the transfer manifest into the separate DOC
    manifest_parser = ManifestParser("manifest-parser", manifest_name,
                                     validate_from_docinfo=False)
    manifest_parser.parse(doc=another_doc)

    software_nodes = another_doc.get_descendants(class_type=Software)

    if len(software_nodes) != 3:
        raise RuntimeError("3 software nodes expected.  Only %d found" %
                           len(software_nodes))

    # Modify the install target values and the media mountpoint
    for software in software_nodes:
        # get the destination object
        dst_node = software.get_children(class_type=Destination,
                                         not_found_is_err=True)[0]
        dir_node = dst_node.get_children(class_type=Dir,
                                         not_found_is_err=True)[0]
        path = dir_node.dir_path
        path = path.replace(INSTALL_TARGET_VAR, INSTALL_TARGET)
        dir_node.dir_path = path

        # if this is the media transfer software node, also update the
        # value for source
        if software._name == TRANSFER_MEDIA:
            src_node = software.get_children(class_type=Source,
                                             not_found_is_err=True)[0]
            dir_node = src_node.get_children(class_type=Dir,
                                             not_found_is_err=True)[0]
            path = dir_node.dir_path
            path = path.replace(MEDIA_DIR_VAR, media_source)
            dir_node.dir_path = path

    # copy the Software classes into the common DOC
    doc = InstallEngine.get_instance().data_object_cache
    doc.volatile.insert_children(software_nodes)
示例#6
0
 def test_mp_no_engine_doc(self):
     '''
         test_mp_no_engine_doc - parse standard manifest and import to DOC
     '''
     try:
         mp_cp = ManifestParser("manifest-parser",
                                common.MANIFEST_DC,
                                validate_from_docinfo=True)
     except ManifestError, err:
         self.fail(str(err))
示例#7
0
    def test_mp_no_engine_dtd_error(self):
        '''
            test_mp_no_engine_dtd_error - DTDParseError raised if DTD contains invalid syntax
        '''

        try:
            mp_cp = ManifestParser("manifest-parser",
                                   common.MANIFEST_DC,
                                   dtd_file=common.DTD_INVALID)
        except ManifestError, err:
            self.fail(str(err))
示例#8
0
    def test_mp_no_engine_parse_error(self):
        '''
            test_mp_no_engine_parse_error - ParsingError raised when import to DOC fails
        '''

        try:
            mp_cp = ManifestParser("manifest-parser",
                                   common.MANIFEST_PARSE_ERROR,
                                   validate_from_docinfo=False)
        except ManifestError, err:
            self.fail(str(err))
    def test_mw_no_engine_with_xslt(self):
        '''
            test_mw_no_engine_with_xslt - read a manifest, then transform it and write it out
        '''

        try:
            manifest_parser = ManifestParser("manifest-parser",
                                             common.MANIFEST_DC,
                                             validate_from_docinfo=True)
            manifest_parser.parse(doc=self.doc)

            # We cannot test validate_from_docinfo=True on the output
            # until the to_xml() methods of the relevant classes in
            # other modules return XML that conforms to the schema

            manifest_writer = ManifestWriter("manifest-writer",
                                             common.MANIFEST_OUT_OK,
                                             xslt_file=common.XSLT_DOC_TO_DC,
                                             validate_from_docinfo=False)
            manifest_writer.write(self.doc)
        except ManifestError, err:
            self.fail(str(err))
    def test_mw_no_engine_with_xslt(self):
        '''
            test_mw_no_engine_with_xslt - read a manifest, then transform it and write it out
        '''

        try:
            manifest_parser = ManifestParser("manifest-parser",
                common.MANIFEST_DC,
                validate_from_docinfo=True)
            manifest_parser.parse(doc=self.doc)

            # We cannot test validate_from_docinfo=True on the output
            # until the to_xml() methods of the relevant classes in
            # other modules return XML that conforms to the schema

            manifest_writer = ManifestWriter("manifest-writer",
                common.MANIFEST_OUT_OK,
                xslt_file=common.XSLT_DOC_TO_DC,
                validate_from_docinfo=False)
            manifest_writer.write(self.doc)
        except ManifestError, err:
            self.fail(str(err))
示例#11
0
    def test_mp_load_manifest_defaults(self):
        '''
            test_mp_load_manifest_defaults - load a standard manifest with attribute defaults
        '''

        validate_from_docinfo = False
        load_defaults = True
        call_xinclude = False

        try:
            mp_cp = ManifestParser("manifest-parser",
                                   common.MANIFEST_DC,
                                   validate_from_docinfo=validate_from_docinfo,
                                   load_defaults=load_defaults,
                                   call_xinclude=call_xinclude)
        except ManifestError, err:
            self.fail(str(err))
示例#12
0
    def test_mp_load_manifest_syntax(self):
        '''
            test_mp_load_manifest_syntax - ensure XMLSyntaxError raised for bad manifest
        '''

        validate_from_docinfo = False
        load_defaults = False
        call_xinclude = False

        try:
            mp_cp = ManifestParser("manifest-parser",
                                   common.MANIFEST_SYNTAX_ERROR,
                                   validate_from_docinfo=validate_from_docinfo,
                                   load_defaults=load_defaults,
                                   call_xinclude=call_xinclude)
        except ManifestError, err:
            self.fail(str(err))
示例#13
0
    def test_mp_load_manifest_valid(self):
        '''
            test_mp_load_manifest_valid - load and validate standard manifest
        '''

        validate_from_docinfo = True
        load_defaults = False
        call_xinclude = False
        path = "/dc/distro"
        attribute = "http_proxy"
        attribute_value = "http://example.com"

        try:
            mp_cp = ManifestParser("manifest-parser",
                                   common.MANIFEST_DC,
                                   validate_from_docinfo=validate_from_docinfo,
                                   load_defaults=load_defaults,
                                   call_xinclude=call_xinclude)
        except ManifestError, err:
            self.fail(str(err))
示例#14
0
    def test_mp_load_manifest_xinclude(self):
        '''
            test_mp_load_manifest_xinclude - load a manifest with XInclude statements
        '''

        validate_from_docinfo = False
        load_defaults = False
        call_xinclude = True
        path = "/dc/distro/target/target_device/swap/zvol"
        attribute = "name"
        attribute_value = "swap"

        try:
            mp_cp = ManifestParser("manifest-parser",
                                   common.MANIFEST_XINCLUDE,
                                   validate_from_docinfo=validate_from_docinfo,
                                   load_defaults=load_defaults,
                                   call_xinclude=call_xinclude)
        except ManifestError, err:
            self.fail(str(err))
示例#15
0
def validate(profile_name, manifest_path, manifest_filename, dtd_filename,
             conversion_report, verbose):
    """Validate the generated manifest/profile based on the specified dtd"""
    is_valid = True

    if verbose:
        print _("Validating %(manifest)s" % \
              {"manifest": manifest_filename})
    try:
        # set up then parse the manifest and the allow the manifest
        # parser to validate the generated manifest based on the default dtd.
        if os.access(manifest_path, os.F_OK):
            manifest = os.path.join(manifest_path, manifest_filename)
            mani_parser = ManifestParser("manifest-parser",
                                         manifest,
                                         validate_from_docinfo=False,
                                         dtd_file=dtd_filename)
            logging.raiseExceptions = False
            mani_parser.parse(doc=None)
            logging.raiseExceptions = True
        else:
            raise IOError(_("file does not exist: %s\n") % manifest_filename)

    except ManifestError, err_msg:
        is_valid = False
        log_name, _ending = manifest_filename.rsplit(".", 1)
        log_name += "_validation" + ".log"
        log_file = os.path.join(manifest_path, log_name)
        err_lines = str(err_msg).split(" : ")
        try:
            if os.access(log_file, os.F_OK):
                os.remove(log_file)
            with open(log_file, "w+") as f_handle:
                f_handle.write(_("NOTE: The errors outputed in this file must "
                                 "be manually corrected before the resulting "
                                 "file can be used by the OmniOS "
                                 "automated installer. For information on the "
                                 "generated errors see installadm(1M) man "
                                 "page.\n\nOnce the errors have been corrected"
                                 " you can validate your changes via:\n\n"
                                 "# js2ai -V %(manifest_file)s\n\n") % \
                                 {"manifest_file": manifest})
                f_handle.write(_("Validation Errors:\n"))
                for line in err_lines:
                    conversion_report.add_validation_error()
                    f_handle.write(("%s\n") % line)
        except IOError:
            # We failed to create the log file, print the errors to the screen
            err(_("failed to create log file: %(logfile)s" % \
                 {"logfile": log_file}))
            sys.stderr.write(_("Validation failed:\n"))
            for line in err_lines:
                sys.stderr.write(line)

        if not is_valid:
            # Store the error information in the error service
            error_info = errsvc.ErrorInfo(ERR_VAL_MODID, liberrsvc.ES_ERR)
            error_info.set_error_data(liberrsvc.ES_DATA_FAILED_AT,
                                      "ManifestParser")
            error_info.set_error_data(liberrsvc.ES_DATA_FAILED_STR,
                                     (_("%(profile)s: validation of "
                                        "%(manifest)s failed. For details see "
                                        "%(logf)s\n") % \
                                        {"profile": profile_name,
                                         "manifest": manifest,
                                         "logf": log_file}))
def validate(profile_name, manifest_path, manifest_filename, dtd_filename,
             conversion_report, verbose):
    """Validate the generated manifest/profile based on the specified dtd"""
    is_valid = True

    if verbose:
        print _("Validating %(manifest)s" % \
              {"manifest": manifest_filename})
    try:
        # set up then parse the manifest and the allow the manifest
        # parser to validate the generated manifest based on the default dtd.
        if os.access(manifest_path, os.F_OK):
            manifest = os.path.join(manifest_path, manifest_filename)
            mani_parser = ManifestParser("manifest-parser", manifest,
                                         validate_from_docinfo=False,
                                         dtd_file=dtd_filename)
            logging.raiseExceptions = False
            mani_parser.parse(doc=None)
            logging.raiseExceptions = True
        else:
            raise IOError(
                _("file does not exist: %s\n") % manifest_filename)

    except ManifestError, err_msg:
        is_valid = False
        log_name, _ending = manifest_filename.rsplit(".", 1)
        log_name += "_validation" + ".log"
        log_file = os.path.join(manifest_path, log_name)
        err_lines = str(err_msg).split(" : ")
        try:
            if os.access(log_file, os.F_OK):
                os.remove(log_file)
            with open(log_file, "w+") as f_handle:
                f_handle.write(_("NOTE: The errors outputed in this file must "
                                 "be manually corrected before the resulting "
                                 "file can be used by the OmniOS "
                                 "automated installer. For information on the "
                                 "generated errors see installadm(1M) man "
                                 "page.\n\nOnce the errors have been corrected"
                                 " you can validate your changes via:\n\n"
                                 "# js2ai -V %(manifest_file)s\n\n") % \
                                 {"manifest_file": manifest})
                f_handle.write(_("Validation Errors:\n"))
                for line in err_lines:
                    conversion_report.add_validation_error()
                    f_handle.write(("%s\n") % line)
        except IOError:
            # We failed to create the log file, print the errors to the screen
            err(_("failed to create log file: %(logfile)s" % \
                 {"logfile": log_file}))
            sys.stderr.write(_("Validation failed:\n"))
            for line in err_lines:
                sys.stderr.write(line)

        if not is_valid:
            # Store the error information in the error service
            error_info = errsvc.ErrorInfo(ERR_VAL_MODID, liberrsvc.ES_ERR)
            error_info.set_error_data(liberrsvc.ES_DATA_FAILED_AT,
                                      "ManifestParser")
            error_info.set_error_data(liberrsvc.ES_DATA_FAILED_STR,
                                     (_("%(profile)s: validation of "
                                        "%(manifest)s failed. For details see "
                                        "%(logf)s\n") % \
                                        {"profile": profile_name,
                                         "manifest": manifest,
                                         "logf": log_file}))