コード例 #1
0
ファイル: test_sync_test.py プロジェクト: stubevan/SyncStatus
    def test_good_file_test2(self) :
        """
            First call - empty file
        """
        self.parser.read(TEST_CONFIG_PATH + '/config_test_2')
        
        test_dir = load_test_dir(self.parser)

        self.assertEquals(len(test_dir), 1)
コード例 #2
0
ファイル: test_sync_test.py プロジェクト: stubevan/SyncStatus
    def test_2_entries_test5(self) :
        """
            Extra Attribute
        """
        self.parser.read(TEST_CONFIG_PATH + '/config_test_5')
        
        test_dir = load_test_dir(self.parser)

        self.assertEquals(len(test_dir), 2)
コード例 #3
0
ファイル: sync_status.py プロジェクト: stubevan/SyncStatus
def main():
    """
        Entry point for application.  Script can run as:
        - client
        - server

        both use the same config file

        All alerting is done using prowl and growl

    """

    # Get the command line arguments
    p = optparse.OptionParser()
    p.add_option("-d", action="store_true", dest="debug")
    p.add_option("--debug", action="store_true", dest="debug")
    p.add_option("--config_file", action="store", dest="config_file")
    p.add_option("--log_dir", action="store", dest="log_dir")
    p.add_option("--data_dir", action="store", dest="data_dir")
    p.add_option("--mode", action="store", dest="mode")
    # @todo update Config Class

    p.set_defaults(debug=False)

    opts, source_file_args = p.parse_args()  # pylint: disable-msg=W0612

    try:
        # Config File is mandatory
        if not opts.config_file:
            raise ValueError("No Config file specified")

        if not opts.log_dir:
            raise ValueError("No Log directory specified")

        if not opts.data_dir:
            raise ValueError("No Data directory specified")

        if opts.mode != "source" and opts.mode != "validate":
            raise ValueError('Invalid mode "{0}" - must be one of source' " | validate")

        # Set up Logging - new file each day
        loglevel = logging.INFO
        if opts.debug:
            loglevel = logging.DEBUG
        logging.basicConfig(
            filename=opts.log_dir + "/" + datetime.now().strftime("%Y%m%d") + "-runSyncStatus.log",
            format="%(levelname)-10s %(asctime)s %(message)s",
            level=loglevel,
        )

        hostname = socket.gethostname().split(".")[0]
        logging.info("SyncStatus on %s mode -> %s.  Config -> %s", hostname, opts.mode, opts.config_file)

        parser = SafeConfigParser()
        try:
            parser.read(opts.config_file)
            # @todo put a check in for non existent config file
        except ParsingError as error:
            logging.fatal("Config File not parsable -> %s", str(error))
            raise error

        # load the tests up
        test_dir = load_test_dir(parser)

        # set up Growl
        alert_initialise()

        # Run the tests
        if opts.mode == "source":
            run_originator_tests(hostname, test_dir)
        else:
            run_destination_tests(hostname, opts.data_dir, test_dir, alert_function)

        logging.info("SyncStatus - completed")

    except ValueError as value_error:
        print "SyncStatus Failed -> {0}".format(str(value_error))