Пример #1
0
    def test_structure(self):
        context = mock.MagicMock()
        context.config = {
            'filesystem': {'upload_working_dir': '/a/b/c'},
            'output': {'poll_frequency_in_seconds': 3}
        }
        context.cli = PulpCli(context)

        # create the tree of commands and sections
        pulp_cli.initialize(context)

        # verify that sections exist and have the right commands
        python_section = context.cli.root_section.subsections['python']

        repo_section = python_section.subsections['repo']
        self.assertTrue(isinstance(repo_section.commands['copy'], packages.CopyPackagesCommand))
        self.assertTrue(isinstance(repo_section.commands['create'], CreateRepositoryCommand))
        self.assertTrue(isinstance(repo_section.commands['delete'], DeleteRepositoryCommand))
        self.assertTrue(isinstance(repo_section.commands['update'], UpdateRepositoryCommand))
        self.assertTrue(isinstance(repo_section.commands['list'], ListRepositoriesCommand))
        self.assertTrue(isinstance(repo_section.commands['upload'], upload.UploadPackageCommand))
        self.assertTrue(isinstance(repo_section.commands['remove'], packages.RemovePackagesCommand))
        self.assertTrue(isinstance(repo_section.commands['packages'], packages.ListPackagesCommand))

        section = repo_section.subsections['sync']
        self.assertTrue(isinstance(section.commands['run'], RunSyncRepositoryCommand))

        section = repo_section.subsections['publish']
        self.assertTrue(isinstance(section.commands['status'], PublishStatusCommand))
        self.assertTrue(isinstance(section.commands['run'], RunPublishRepositoryCommand))
Пример #2
0
    def setUp(self):
        super(PulpClientTests, self).setUp()

        self.config = SafeConfigParser()
        config_filename = os.path.join(DATA_DIR, 'test-override-client.conf')
        self.config = Config(config_filename)

        self.server_mock = mock.Mock()
        self.pulp_connection = PulpConnection('',
                                              server_wrapper=self.server_mock)
        self.bindings = Bindings(self.pulp_connection)

        # Disabling color makes it easier to grep results since the character codes aren't there
        self.recorder = okaara.prompt.Recorder()
        self.prompt = PulpPrompt(enable_color=False,
                                 output=self.recorder,
                                 record_tags=True)

        self.logger = logging.getLogger('pulp')
        self.exception_handler = ExceptionHandler(self.prompt, self.config)

        self.context = ClientContext(self.bindings, self.config, self.logger,
                                     self.prompt, self.exception_handler)

        self.cli = PulpCli(self.context)
        self.context.cli = self.cli
Пример #3
0
    def test_structure(self):
        context = mock.MagicMock()
        context.config = {
            'filesystem': {
                'upload_working_dir': '/a/b/c'
            },
            'output': {
                'poll_frequency_in_seconds': 3
            }
        }
        context.cli = PulpCli(context)

        # create the tree of commands and sections
        pulp_cli.initialize(context)

        # verify that sections exist and have the right commands
        openstack_section = context.cli.root_section.subsections['openstack']

        repo_section = openstack_section.subsections['repo']
        self.assertTrue(
            isinstance(repo_section.commands['create'],
                       CreateRepositoryCommand))
        self.assertTrue(
            isinstance(repo_section.commands['delete'],
                       DeleteRepositoryCommand))
        self.assertTrue(
            isinstance(repo_section.commands['list'],
                       ListOpenstackRepositoriesCommand))
        self.assertTrue(
            isinstance(repo_section.commands['copy'], images.ImageCopyCommand))
        self.assertTrue(
            isinstance(repo_section.commands['remove'],
                       images.ImageRemoveCommand))

        upload_section = repo_section.subsections['uploads']
        self.assertTrue(
            isinstance(upload_section.commands['upload'],
                       UploadOpenstackImageCommand))

        section = repo_section.subsections['publish']
        glance_section = section.subsections['http']
        self.assertTrue(
            isinstance(glance_section.commands['status'],
                       PublishStatusCommand))
        self.assertTrue(
            isinstance(glance_section.commands['run'],
                       RunPublishRepositoryCommand))

        section = repo_section.subsections['publish']
        glance_section = section.subsections['glance']
        self.assertTrue(
            isinstance(glance_section.commands['status'],
                       PublishStatusCommand))
        self.assertTrue(
            isinstance(glance_section.commands['run'],
                       RunPublishRepositoryCommand))
Пример #4
0
 def setUp(self):
     TestCase.setUp(self)
     self.config = SafeConfigParser()
     path = os.path.join(os.path.abspath(os.path.dirname(__file__)), 'data',
                         'client.conf')
     self.config = Config(path)
     self.server_mock = mock.Mock()
     self.pulp_connection = \
         PulpConnection('', server_wrapper=self.server_mock)
     self.bindings = Bindings(self.pulp_connection)
     self.recorder = okaara.prompt.Recorder()
     self.prompt = PulpPrompt(enable_color=False,
                              output=self.recorder,
                              record_tags=True)
     self.logger = logging.getLogger('pulp')
     self.exception_handler = ExceptionHandler(self.prompt, self.config)
     self.context = ClientContext(self.bindings, self.config, self.logger,
                                  self.prompt, self.exception_handler)
     self.cli = PulpCli(self.context)
     self.context.cli = self.cli
Пример #5
0
    def setUp(self):
        super(ExtensionLoaderTests, self).setUp()

        self.prompt = PulpPrompt()
        self.cli = PulpCli(self.prompt)
        self.context = ClientContext(None, None, None, self.prompt, None, cli=self.cli)
Пример #6
0
def main(config_filenames, exception_handler_class=ExceptionHandler):
    """
    Entry point into the launcher. Any extra necessary values will be pulled
    from the given configuration files.

    @param config_filenames: ordered list of files to load configuration from
    @type  config_filenames: list

    @return: exit code suitable to return to the shell launching the client
    """

    # Command line argument handling
    parser = OptionParser()
    parser.disable_interspersed_args()
    parser.add_option(
        '-u',
        '--username',
        dest='username',
        action='store',
        default=None,
        help=
        _('credentials for the Pulp server; if specified will bypass the stored certificate'
          ))
    parser.add_option(
        '-p',
        '--password',
        dest='password',
        action='store',
        default=None,
        help=_(
            'credentials for the Pulp server; must be specified with --username'
        ))
    parser.add_option('--debug',
                      dest='debug',
                      action='store_true',
                      default=False,
                      help=_('enables debug logging'))
    parser.add_option('--config',
                      dest='config',
                      default=None,
                      help=_('absolute path to the configuration file'))
    parser.add_option('--map',
                      dest='print_map',
                      action='store_true',
                      default=False,
                      help=_('prints a map of the CLI sections and commands'))

    options, args = parser.parse_args()

    # Configuration and Logging
    if options.config is not None:
        config_filenames = [options.config]
    config = _load_configuration(config_filenames)
    logger = _initialize_logging(config, debug=options.debug)

    # General UI pieces
    prompt = _create_prompt(config)
    exception_handler = exception_handler_class(prompt, config)

    # REST Bindings
    username = options.username
    password = options.password
    if username and not password:
        prompt_msg = 'Enter password: '******'Login cancelled'))
            sys.exit(os.EX_NOUSER)

    server = _create_bindings(config, logger, username, password)

    # Client context
    context = ClientContext(server, config, logger, prompt, exception_handler)
    cli = PulpCli(context)
    context.cli = cli

    # Load extensions into the UI in the context
    extensions_dir = config['filesystem']['extensions_dir']
    extensions_dir = os.path.expanduser(extensions_dir)

    role = config['client']['role']
    try:
        extensions_loader.load_extensions(extensions_dir, context, role)
    except extensions_loader.LoadFailed, e:
        prompt.write(
            _('The following extensions failed to load: %(f)s' %
              {'f': ', '.join(e.failed_packs)}))
        prompt.write(
            _('More information on the failures can be found in %(l)s' %
              {'l': config['logging']['filename']}))
        return os.EX_OSFILE
Пример #7
0
def main(config, exception_handler_class=ExceptionHandler):
    """
    Entry point into the launcher. Any extra necessary values will be pulled
    from the given configuration files.

    @param config: The CLI configuration.
    @type  config: Config

    @return: exit code suitable to return to the shell launching the client
    """
    ensure_user_pulp_dir()

    # Command line argument handling
    parser = OptionParser()
    parser.disable_interspersed_args()
    parser.add_option('-u', '--username', dest='username', action='store', default=None,
                      help=_('username for the Pulp server; if used will bypass the stored '
                             'certificate and override a username specified in ~/.pulp/admin.conf'))
    parser.add_option('-p', '--password', dest='password', action='store', default=None,
                      help=_('password for the Pulp server; must be used with --username. '
                             'if used will bypass the stored certificate and override a password '
                             'specified in ~/.pulp/admin.conf'))
    parser.add_option('--config', dest='config', default=None,
                      help=_('absolute path to the configuration file'))
    parser.add_option('--map', dest='print_map', action='store_true', default=False,
                      help=_('prints a map of the CLI sections and commands'))
    parser.add_option(
        '-v', dest='verbose', action='count',
        help=_('enables verbose output; use twice for increased verbosity with debug information'))

    options, args = parser.parse_args()

    # Configuration and Logging
    if options.config is not None:
        config.update(Config(options.config))
    logger = _initialize_logging(verbose=options.verbose)

    # General UI pieces
    prompt = _create_prompt(config)
    exception_handler = exception_handler_class(prompt, config)

    # REST Bindings
    username = options.username
    password = options.password

    if not username and not password:
        # Try to get username/password from config if not explicitly set. username and password are
        # not included by default so we need to catch KeyError Exceptions.
        try:
            username = config['auth']['username']
            password = config['auth']['password']
        except KeyError:
            pass

    if username and not password:
        prompt_msg = 'Enter password: '******'Login canceled'))
            sys.exit(os.EX_NOUSER)

    server = _create_bindings(config, logger, username, password, verbose=options.verbose)

    # Client context
    context = ClientContext(server, config, logger, prompt, exception_handler)
    cli = PulpCli(context)
    context.cli = cli

    # Load extensions into the UI in the context
    extensions_dir = config['filesystem']['extensions_dir']
    extensions_dir = os.path.expanduser(extensions_dir)

    role = config['client']['role']
    try:
        extensions_loader.load_extensions(extensions_dir, context, role)
    except extensions_loader.LoadFailed, e:
        prompt.write(
            _('The following extensions failed to load: %(f)s' % {'f': ', '.join(e.failed_packs)}))
        prompt.write(_('More information on the failures may be found by using -v option one or '
                       'more times'))
        return os.EX_OSFILE
Пример #8
0
    def test_structure(self):
        context = mock.MagicMock()
        context.config = {
            'filesystem': {
                'upload_working_dir': '/a/b/c'
            },
            'output': {
                'poll_frequency_in_seconds': 3
            }
        }
        context.cli = PulpCli(context)

        # create the tree of commands and sections
        pulp_cli.initialize(context)

        # verify that sections exist and have the right commands and subsections
        docker_section = context.cli.root_section.subsections['docker']

        repo_section = docker_section.subsections['repo']
        self.assertTrue(
            isinstance(repo_section.commands['create'],
                       CreateRepositoryCommand))
        self.assertTrue(
            isinstance(repo_section.commands['delete'],
                       DeleteRepositoryCommand))
        self.assertTrue(
            isinstance(repo_section.commands['update'],
                       UpdateRepositoryCommand))
        self.assertTrue(
            isinstance(repo_section.commands['list'],
                       ListDockerRepositoriesCommand))
        self.assertTrue(
            isinstance(repo_section.subsections['search'], PulpCliSection))
        self.assertTrue(
            isinstance(repo_section.subsections['copy'], PulpCliSection))
        self.assertTrue(
            isinstance(repo_section.subsections['remove'], PulpCliSection))

        upload_section = repo_section.subsections['uploads']
        self.assertTrue(
            isinstance(upload_section.commands['upload'], UploadCommand))

        section = repo_section.subsections['sync']
        self.assertTrue(
            isinstance(section.commands['run'], RunSyncRepositoryCommand))

        section = repo_section.subsections['publish']
        self.assertTrue(
            isinstance(section.commands['status'], PublishStatusCommand))
        self.assertTrue(
            isinstance(section.commands['run'], RunPublishRepositoryCommand))

        section = repo_section.subsections['export']
        self.assertTrue(
            isinstance(section.commands['status'], PublishStatusCommand))
        self.assertTrue(
            isinstance(section.commands['run'], RunPublishRepositoryCommand))

        section = repo_section.subsections['search']
        self.assertTrue(
            isinstance(section.commands['image'], images.ImageSearchCommand))
        self.assertTrue(
            isinstance(section.commands['manifest'],
                       content.ManifestSearchCommand))

        section = repo_section.subsections['copy']
        self.assertTrue(
            isinstance(section.commands['image'], images.ImageCopyCommand))
        self.assertTrue(
            isinstance(section.commands['manifest'],
                       content.ManifestCopyCommand))

        section = repo_section.subsections['remove']
        self.assertTrue(
            isinstance(section.commands['image'], images.ImageRemoveCommand))
        self.assertTrue(
            isinstance(section.commands['manifest'],
                       content.ManifestRemoveCommand))