Exemplo n.º 1
0
    def remove(self, **kwargs):
        """
        Handles the remove operation for units of the given type.

        :param type_id: type of unit being removed
        :type  type_id: str
        :param kwargs: CLI options as input by the user and parsed by the framework
        :type  kwargs: dict
        """
        UnitRemoveCommand.ensure_criteria(kwargs)

        repo_id = kwargs.pop(OPTION_REPO_ID.keyword)
        kwargs['type_ids'] = [self.type_id] # so it will be added to the criteria

        response = self.context.server.repo_unit.remove(repo_id, **kwargs)

        progress_msg = _('Progress on this task can be viewed using the '
                         'commands under "repo tasks".')

        if response.response_body.is_postponed():
            d = _('Unit removal postponed due to another operation on the destination '
                  'repository. ')
            d += progress_msg
            self.context.prompt.render_paragraph(d)
            self.context.prompt.render_reasons(response.response_body.reasons)
        else:
            self.context.prompt.render_paragraph(progress_msg)
Exemplo n.º 2
0
    def __init__(self, context, name='remove', description=DESC_REMOVE):
        """
        Initialize remove command.

        See super() for more detail; we just set a few items here
        """
        UnitRemoveCommand.__init__(self, context, name=name, description=description,
                                   type_id=constants.IMAGE_TYPE_ID)
Exemplo n.º 3
0
    def __init__(self, context):
        """
        Initialize the command.

        :param context: The CLI context
        :type  context: pulp.client.extensions.core.ClientContext
        """
        UnitRemoveCommand.__init__(self, context, name='remove', description=DESC_REMOVE,
                                   type_id=constants.PACKAGE_TYPE_ID)
Exemplo n.º 4
0
    def __init__(self, context):
        """
        Initialize the command.

        :param context: The CLI context
        :type  context: pulp.client.extensions.core.ClientContext
        """
        UnitRemoveCommand.__init__(self, context, name='remove', description=DESC_REMOVE,
                                   type_id=constants.PACKAGE_TYPE_ID)
Exemplo n.º 5
0
    def __init__(self, context, name='remove', description=DESC_REMOVE):
        """
        Initialize remove command.

        See super() for more detail; we just set a few items here
        """
        UnitRemoveCommand.__init__(self,
                                   context,
                                   name=name,
                                   description=description,
                                   type_id=constants.IMAGE_TYPE_ID)
Exemplo n.º 6
0
 def __init__(self,
              context,
              name,
              description,
              type_id,
              unit_threshold=DISPLAY_UNITS_THRESHOLD):
     UnitRemoveCommand.__init__(self,
                                context,
                                name=name,
                                description=description,
                                type_id=type_id)
     self.unit_threshold = unit_threshold
Exemplo n.º 7
0
    def __init__(self,
                 context,
                 name='remove',
                 description=DESC_REMOVE,
                 module_count_threshold=constants.DISPLAY_MODULES_THRESHOLD):
        UnitRemoveCommand.__init__(self,
                                   context,
                                   name=name,
                                   description=description,
                                   type_id=constants.TYPE_PUPPET_MODULE)

        self.max_units_displayed = module_count_threshold
Exemplo n.º 8
0
    def setUp(self):
        super(TestUnitRemoveCommand, self).setUp()

        self.command = UnitRemoveCommand(self.context)

        self.mock_poll = mock.MagicMock().poll
        self.command.poll = self.mock_poll

        self.mock_remove_binding = mock.MagicMock().remove
        self.mock_remove_binding.return_value = task_simulator.create_fake_task_response()
        self.bindings.repo_unit.remove = self.mock_remove_binding
Exemplo n.º 9
0
class TestUnitRemoveCommand(unittest.TestCase):
    def setUp(self):
        self.context = mock.MagicMock()
        self.command = UnitRemoveCommand(self.context, 'file')
        self.kwargs = {OPTION_REPO_ID.keyword:'repo1', 'match':'stuff'}

    def test_default_to_remove_method(self):
        self.assertEqual(self.command.method, self.command.remove)

    @mock.patch.object(UnitRemoveCommand, 'add_display_criteria_options', autospec=True)
    def test_no_include_search(self, mock_add):
        # make sure this object does not add options like 'limit' and 'seek'
        command = UnitRemoveCommand(self.context, 'file')
        self.assertEqual(mock_add.call_count, 0)

    def test_remove_postponed(self):
        self.context.server.repo_unit.remove.return_value.response_body.is_postponed.return_value = True

        self.command.remove(**self.kwargs)

        message = self.context.prompt.render_paragraph.call_args[0][0]
        self.assertTrue(message.find('postponed') >= 0)

    def test_remove_not_postponed(self):
        self.context.server.repo_unit.remove.return_value.response_body.is_postponed.return_value = False

        self.command.remove(**self.kwargs)

        message = self.context.prompt.render_paragraph.call_args[0][0]
        self.assertEqual(message.find('postponed'), -1)

    def test_bindings_call(self):
        # mock the binding
        self.context.server.repo_unit.remove = mock.create_autospec(
                RepositoryUnitAPI(self.context).remove)

        # execute
        self.command.remove(**self.kwargs)

        # verify the correct args
        self.context.server.repo_unit.remove.assert_called_once_with(
            'repo1', type_ids=['file'], match='stuff')
Exemplo n.º 10
0
 def __init__(self, context):
     UnitRemoveCommand.__init__(self, context, type_id=TYPE_ID_ISO)
Exemplo n.º 11
0
 def __init__(self, context, name='image', description=DESC_REMOVE):
     UnitRemoveCommand.__init__(self, context, name=name, description=description,
                                type_id=constants.IMAGE_TYPE_ID)
Exemplo n.º 12
0
    def __init__(self, context, name='remove', description=DESC_REMOVE,
                 module_count_threshold=constants.DISPLAY_MODULES_THRESHOLD):
        UnitRemoveCommand.__init__(self, context, name=name, description=description,
                                   type_id=constants.TYPE_PUPPET_MODULE)

        self.max_units_displayed = module_count_threshold
Exemplo n.º 13
0
 def __init__(self, context, name, description, type_id, unit_threshold=DISPLAY_UNITS_THRESHOLD):
     UnitRemoveCommand.__init__(self, context, name=name, description=description, type_id=type_id)
     self.unit_threshold = unit_threshold
Exemplo n.º 14
0
 def setUp(self):
     self.context = mock.MagicMock()
     self.command = UnitRemoveCommand(self.context, 'file')
     self.kwargs = {OPTION_REPO_ID.keyword:'repo1', 'match':'stuff'}
Exemplo n.º 15
0
 def __init__(self, context, name='image', description=DESC_REMOVE):
     UnitRemoveCommand.__init__(self,
                                context,
                                name=name,
                                description=description,
                                type_id=constants.IMAGE_TYPE_ID)
Exemplo n.º 16
0
 def __init__(self, context):
     UnitRemoveCommand.__init__(self, context, type_id=TYPE_ID_ISO)