예제 #1
0
파일: admin.py 프로젝트: sambacha/sprawl
def do_admin(args):
    if args.subcommand == 'genesis':
        do_genesis(args)
    elif args.subcommand == 'keygen':
        do_keygen(args)
    else:
        raise AssertionError("invalid command: {}".format(args.subcommand))
예제 #2
0
def do_admin(args):
    data_dir = ensure_directory('data', '/var/lib/sawtooth')

    if args.admin_cmd == 'genesis':
        do_genesis(args, data_dir)
    elif args.admin_cmd == 'keygen':
        do_keygen(args)
    else:
        raise AssertionError("invalid command: {}".format(args.admin_cmd))
예제 #3
0
    def test_validate_with_default_output(self):
        """Tests that the genesis batch is created and placed in the data dir,
        which is the default location, when no output file is specified in the
        command args..
        """
        args = self._parse_command([], with_default_output=True)
        genesis.do_genesis(args, self._temp_data_dir)

        output = self._result_data(target_dir=self._temp_data_dir)
        self.assertEqual(0, len(output.batches))
예제 #4
0
    def test_validation_fails_missing_dep(self):
        batches = [
            self.make_batch('batch1', transaction('id1', []),
                            transaction('id2', []), transaction('id3', [])),
            self.make_batch('batch2', transaction('id4', ['id11']))
        ]

        args = self._parse_command(batches)
        with self.assertRaises(CliException):
            genesis.do_genesis(args, self._temp_data_dir)
예제 #5
0
    def test_validation_fails_out_of_order(self):
        batches = [self.make_batch('batch1',
                                   transaction('id1', []),
                                   transaction('id2', ['id4']),
                                   transaction('id3', [])),
                   self.make_batch('batch2',
                                   transaction('id4', ['id1']))]

        args = self._parse_command(batches)
        with self.assertRaises(CliException):
            genesis.do_genesis(args, self._temp_data_dir)
예제 #6
0
    def test_validation_fails_missing_dep(self):
        batches = [self.make_batch('batch1',
                                   transaction('id1', []),
                                   transaction('id2', []),
                                   transaction('id3', [])),
                   self.make_batch('batch2',
                                   transaction('id4', ['id11']))]

        args = self._parse_command(batches)
        with self.assertRaises(CliException):
            genesis.do_genesis(args)
예제 #7
0
    def test_validation_fails_out_of_order(self):
        batches = [
            self.make_batch('batch1', transaction('id1', []),
                            transaction('id2', ['id4']),
                            transaction('id3', [])),
            self.make_batch('batch2', transaction('id4', ['id1']))
        ]

        args = self._parse_command(batches)
        with self.assertRaises(CliException):
            genesis.do_genesis(args)
예제 #8
0
    def test_validate_with_no_deps(self):
        batches = [
            self.make_batch('batch1', transaction('id1', []),
                            transaction('id2', []), transaction('id3', [])),
            self.make_batch('batch2', transaction('id4', []))
        ]

        args = self._parse_command(batches)
        genesis.do_genesis(args, self._temp_data_dir)

        output = self._result_data()
        self.assertEqual(2, len(output.batches))
예제 #9
0
    def test_validate_with_deps_in_same_batch(self):
        batches = [
            self.make_batch('batch1', transaction('id1', []),
                            transaction('id2', ['id1'])),
            self.make_batch('batch2', transaction('id3', [])),
            self.make_batch('batch3', transaction('id4', []))
        ]

        args = self._parse_command(batches)
        genesis.do_genesis(args)

        output = self._result_data()
        self.assertEqual(3, len(output.batches))
    def do_test_do_genesis():
        batches = [
            TestBenchmarkCliGenesis.make_batch(
                'batch1', TestBenchmarkCliGenesis.transaction('id1', []),
                TestBenchmarkCliGenesis.transaction('id2', []),
                TestBenchmarkCliGenesis.transaction('id3', [])),
            TestBenchmarkCliGenesis.make_batch(
                'batch2',
                TestBenchmarkCliGenesis.transaction('id4', ['id1', 'id2']))
        ]

        args = TestBenchmarkCliGenesis.parse_command(batches)
        genesis.do_genesis(args=args, data_dir=TMP_DATA_DIR)
예제 #11
0
    def test_validate_with_no_deps(self):
        batches = [self.make_batch('batch1',
                                   transaction('id1', []),
                                   transaction('id2', []),
                                   transaction('id3', [])),
                   self.make_batch('batch2',
                                   transaction('id4', []))]

        args = self._parse_command(batches)
        genesis.do_genesis(args, self._temp_data_dir)

        output = self._result_data()
        self.assertEqual(2, len(output.batches))
예제 #12
0
    def test_validate_with_deps_in_same_batch(self):
        batches = [self.make_batch('batch1',
                                   transaction('id1', []),
                                   transaction('id2', ['id1'])),
                   self.make_batch('batch2',
                                   transaction('id3', [])),
                   self.make_batch('batch3',
                                   transaction('id4', []))]

        args = self._parse_command(batches)
        genesis.do_genesis(args)

        output = self._result_data()
        self.assertEqual(3, len(output.batches))
예제 #13
0
    def test_validate_with_deps_in_across_batches(self):
        batches = [self._required_settings_batch,
                   self.make_batch('batch1',
                                   transaction('id1', []),
                                   transaction('id2', []),
                                   transaction('id3', [])),
                   self.make_batch('batch2',
                                   transaction('id4', ['id1', 'id2']))]

        args = self._parse_command(batches)
        genesis.do_genesis(args, self._temp_data_dir)

        output = self._result_data()
        self.assertEqual(3, len(output.batches))
예제 #14
0
def do_admin(args):
    if 'SAWTOOTH_HOME' in os.environ:
        data_dir = os.path.join(os.environ['SAWTOOTH_HOME'], 'data')
    else:
        data_dir = '/var/lib/sawtooth'

    try:
        os.makedirs(data_dir, exist_ok=True)
    except OSError as e:
        print('Unable to create {}: {}'.format(data_dir, e), file=sys.stderr)
        return

    if args.admin_cmd == 'genesis':
        do_genesis(args, data_dir)
    else:
        raise CliException("invalid command: {}".format(args.command))
예제 #15
0
def main(prog_name=os.path.basename(sys.argv[0]), args=None,
         with_loggers=True):
    parser = create_parser(prog_name)
    if args is None:
        args = sys.argv[1:]
    args = parser.parse_args(args)

    if with_loggers is True:
        if args.verbose is None:
            verbose_level = 0
        else:
            verbose_level = args.verbose
        setup_loggers(verbose_level=verbose_level)

    if args.subcommand == 'genesis':
        do_genesis(args)
    elif args.subcommand == 'keygen':
        do_keygen(args)
    else:
        raise CliException('Invalid command: {}'.format(args.subcommand))
예제 #16
0
def main(prog_name=os.path.basename(sys.argv[0]), args=None,
         with_loggers=True):
    parser = create_parser(prog_name)
    if args is None:
        args = sys.argv[1:]
    args = parser.parse_args(args)

    if with_loggers is True:
        if args.verbose is None:
            verbose_level = 0
        else:
            verbose_level = args.verbose
        setup_loggers(verbose_level=verbose_level)

    if args.subcommand == 'genesis':
        do_genesis(args)
    elif args.subcommand == 'keygen':
        do_keygen(args)
    else:
        raise CliException('Invalid command: {}'.format(args.subcommand))
예제 #17
0
 def test_validation_fails_with_no_input_batches(self):
     args = self._parse_command([])
     with self.assertRaises(CliException):
         genesis.do_genesis(args, self._temp_data_dir)
예제 #18
0
def do_admin(args):
    if args.admin_cmd == 'genesis':
        do_genesis(args)
    else:
        raise CliException("invalid command: {}".format(args.command))
예제 #19
0
    def test_validate_with_no_input_batches(self):
        args = self._parse_command([])
        genesis.do_genesis(args, self._temp_data_dir)

        output = self._result_data()
        self.assertEqual(0, len(output.batches))