class DTDManifest(unittest.TestCase): '''Tests for DTD Manifests''' def setUp(self): # Create a ManifestServ for the default Manifest, default.xml. self.man_serv = ManifestServ("%s/default" % XML_DIR, full_init=False) def test_create(self): '''ManifestServ: can be instantiated with manifest default.xml''' instance_names = self.man_serv.get_values( "auto_install/ai_instance/name") print "instance_names = [%s]" % instance_names self.assertEquals(len(instance_names), 1) self.assertEquals(instance_names[0], "default") def test_validate_fails_if_dtd_schema_is_false(self): '''ManifestServ: validate fails if dtd_schema is False''' self.assertRaises(ManifestProcError, self.man_serv.schema_validate, schema_name="%s/ai.dtd" % XML_DIR, dtd_schema=False) def test_validate_succeeds_if_dtd_schema_is_true(self): '''ManifestServ: validate succeeds if dtd_schema is True''' try: self.man_serv.schema_validate(schema_name="%s/ai.dtd" % XML_DIR, dtd_schema=True) except ManifestProcError, err: self.fail("schema_validate unexpectedly failed: [%s]" % str(err))
def get_manifest_server_obj(cp): #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ """Read the manifest file name from the command line and create an object to read information from the file. Inputs: cp: checkpointing object Returns: A manifest server object which allows access to the manifest file. """ dc_log = logging.getLogger(DC_LOGGER_NAME) if len(sys.argv) < 3: usage() subcommand = sys.argv[1] if subcommand != "build": dc_log.error("Invalid or missing subcommand") usage() # Read the manifest file from the command line try: pargs2 = getopt.getopt(sys.argv[2:], "r:p:hRl?")[1] except getopt.GetoptError: usage() if len(pargs2) == 0: usage() manifest_file = pargs2[0] err = dc_ckp.verify_manifest_filename(manifest_file) if err != 0: raise Exception, "" cp.set_manifest(manifest_file) return ManifestServ(manifest_file, DC_MANIFEST_DATA)
def ai_create_manifestserv(manifest_file): #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ """ Create an unvalidated manifest object. Args: manifest_file: file containing the data to read into memory. Returns ManifestServ object on success None on error Raises: None """ try: manifest_obj = ManifestServ(manifest_file, full_init=False, dtd_schema=True) except StandardError, err: print "Error creating in-memory copy of Manifest data." print str(err) return None
def setUp(self): # Create a ManifestServ for the default Manifest, default.xml. self.man_serv = ManifestServ("%s/default" % XML_DIR, full_init=False)
elif (opt == "-t"): t_flag = True elif (opt == "-v"): v_flag = True elif (opt == "--dtd"): dtd_flag = True # Must have the project data manifest. # Also check for mismatching options. if ((len(other_args) != 1) or (d_flag and not s_flag)): usage(sys.stderr) sys.exit (errno.EINVAL) try: # Create the object used to extract the data. mfest_obj = ManifestServ(other_args[0], valfile_root, out_manifest, v_flag, t_flag, dtd_schema=dtd_flag) # Start the socket server if requested. if (s_flag): mfest_obj.start_socket_server(d_flag) print "Connect to socket with name " + mfest_obj.get_sockname() # Set up to shut down the socket server at exit. atexit.register(exit_handler, mfest_obj) # Enable querying from this process as well. This method will # block to hold the socket server open for remote queries as # well (if enabled). query_local(mfest_obj) except (SystemExit, KeyboardInterrupt): print >> sys.stderr, "Caught SystemExit exception"
def main(): # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ """ Main Args: None. (Use sys.argv[] to get args) Returns: N/A Raises: None """ # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ # Initialize option flags. d_flag = s_flag = t_flag = v_flag = dtd_flag = False mfest_obj = None err = None ret = 0 # Options come first in the commandline. # See usage method for option explanations. try: (opt_pairs, other_args) = getopt.getopt(sys.argv[1:], "df:ho:stv?", "dtd") except getopt.GetoptError as err: print("ManifestServ: " + str(err), file=sys.stderr) except IndexError as err: print("ManifestServ: Insufficient arguments", file=sys.stderr) if (err): usage(sys.stderr) sys.exit(errno.EINVAL) valfile_root = None out_manifest = None for (opt, optarg) in opt_pairs: if (opt == "-d"): d_flag = True if (opt == "-f"): valfile_root = optarg if ((opt == "-h") or (opt == "-?")): usage(sys.stdout) sys.exit(0) if (opt == "-o"): out_manifest = optarg if (opt == "-s"): s_flag = True elif (opt == "-t"): t_flag = True elif (opt == "-v"): v_flag = True elif (opt == "--dtd"): dtd_flag = True # Must have the project data manifest. # Also check for mismatching options. if ((len(other_args) != 1) or (d_flag and not s_flag)): usage(sys.stderr) sys.exit(errno.EINVAL) try: # Create the object used to extract the data. mfest_obj = ManifestServ(other_args[0], valfile_root, out_manifest, v_flag, t_flag, dtd_schema=dtd_flag, socket_debug=d_flag) # Start the socket server if requested. if (s_flag): mfest_obj.start_socket_server() print("Connect to socket with name " + mfest_obj.get_sockname()) # Set up to shut down the socket server at exit. atexit.register(exit_handler, mfest_obj) # Enable querying from this process as well. This method will # block to hold the socket server open for remote queries as # well (if enabled). query_local(mfest_obj) except (SystemExit, KeyboardInterrupt): print("Caught SystemExit exception", file=sys.stderr) except Exception as err: print("Error running Manifest Server", file=sys.stderr) if (err is not None): ret = err.args[0] sys.exit(ret)