From 6055a62bf2c1f03c2742e6700ae0cf74b331e4f1 Mon Sep 17 00:00:00 2001 From: Jana Cupova Date: May 11 2022 08:17:34 +0000 Subject: Remove deprecated remove-channel/removeChannel Fixes: https://pagure.io/koji/issue/3356 --- diff --git a/cli/koji_cli/commands.py b/cli/koji_cli/commands.py index cf03786..f1c9eb3 100644 --- a/cli/koji_cli/commands.py +++ b/cli/koji_cli/commands.py @@ -330,22 +330,6 @@ def handle_add_channel(goptions, session, args): print("%s added: id %d" % (args[0], channel_id)) -def handle_remove_channel(goptions, session, args): - "[admin] Remove a channel entirely" - usage = "usage: %prog remove-channel [options] " - parser = OptionParser(usage=get_usage_str(usage)) - parser.add_option("--force", action="store_true", help="force removal, if possible") - (options, args) = parser.parse_args(args) - print("remove-channel is deprecated and will be removed in 1.30") - if len(args) != 1: - parser.error("Incorrect number of arguments") - activate_session(session, goptions) - cinfo = session.getChannel(args[0]) - if not cinfo: - error("No such channel: %s" % args[0]) - session.removeChannel(args[0], force=options.force) - - def handle_edit_channel(goptions, session, args): "[admin] Edit a channel" usage = "usage: %prog edit-channel [options] " diff --git a/hub/kojihub.py b/hub/kojihub.py index 73cab9f..06148c5 100644 --- a/hub/kojihub.py +++ b/hub/kojihub.py @@ -2469,39 +2469,6 @@ def edit_channel(channelInfo, **kw): return True -def remove_channel(channel_name, force=False): - """Remove a channel. - - :param str channel_name: channel name - :param bool force: remove channel which has hosts - - Channel must have no hosts, unless force is set to True - If a channel has associated tasks, it cannot be removed - and an exception will be raised. - - Removing channel will remove also remove complete history - for that channel. - """ - logger.warning("removeChannel call is deprecated and will be removed in 1.30") - context.session.assertPerm('admin') - channel_id = get_channel_id(channel_name, strict=True) - # check for task references - query = QueryProcessor(tables=['task'], clauses=['channel_id=%(channel_id)i'], - values=locals(), columns=['id'], opts={'limit': 1}) - # XXX slow query - if query.execute(): - raise koji.GenericError('channel %s has task references' % channel_name) - query = QueryProcessor(tables=['host_channels'], clauses=['channel_id=%(channel_id)i'], - values=locals(), columns=['host_id'], opts={'limit': 1}) - if query.execute(): - if not force: - raise koji.GenericError('channel %s has host references' % channel_name) - delete = """DELETE FROM host_channels WHERE channel_id=%(channel_id)i""" - _dml(delete, locals()) - delete = """DELETE FROM channels WHERE id=%(channel_id)i""" - _dml(delete, locals()) - - def add_channel(channel_name, description=None): """Add a channel. @@ -13226,7 +13193,6 @@ class RootExports(object): removeHostFromChannel = staticmethod(remove_host_from_channel) renameChannel = staticmethod(rename_channel) editChannel = staticmethod(edit_channel) - removeChannel = staticmethod(remove_channel) addChannel = staticmethod(add_channel) def listHosts(self, arches=None, channelID=None, ready=None, enabled=None, userID=None, diff --git a/tests/test_cli/data/list-commands-admin.txt b/tests/test_cli/data/list-commands-admin.txt index 4f7e5df..6e4422a 100644 --- a/tests/test_cli/data/list-commands-admin.txt +++ b/tests/test_cli/data/list-commands-admin.txt @@ -46,7 +46,6 @@ admin commands: make-task Create an arbitrary task prune-signed-copies Prune signed copies regen-repo Force a repo to be regenerated - remove-channel Remove a channel entirely remove-external-repo Remove an external repo from a tag or tags, or remove entirely remove-group Remove group from tag remove-host-from-channel Remove a host from a channel diff --git a/tests/test_cli/data/list-commands.txt b/tests/test_cli/data/list-commands.txt index 329db13..bdcd739 100644 --- a/tests/test_cli/data/list-commands.txt +++ b/tests/test_cli/data/list-commands.txt @@ -46,7 +46,6 @@ admin commands: make-task Create an arbitrary task prune-signed-copies Prune signed copies regen-repo Force a repo to be regenerated - remove-channel Remove a channel entirely remove-external-repo Remove an external repo from a tag or tags, or remove entirely remove-group Remove group from tag remove-host-from-channel Remove a host from a channel diff --git a/tests/test_cli/test_remove_channel.py b/tests/test_cli/test_remove_channel.py deleted file mode 100644 index 785cdc2..0000000 --- a/tests/test_cli/test_remove_channel.py +++ /dev/null @@ -1,93 +0,0 @@ -from __future__ import absolute_import - -import unittest - -import six -import mock - -from koji_cli.commands import handle_remove_channel -from . import utils - - -class TestRemoveChannel(utils.CliTestCase): - - def setUp(self): - self.options = mock.MagicMock() - self.session = mock.MagicMock() - self.channel_name = 'test-channel' - self.description = 'description' - self.channel_info = { - 'id': 123, - 'name': self.channel_name, - 'description': self.description, - } - self.maxDiff = None - - @mock.patch('sys.stdout', new_callable=six.StringIO) - @mock.patch('koji_cli.commands.activate_session') - def test_handle_remove_channel(self, activate_session_mock, stdout): - self.session.getChannel.return_value = self.channel_info - rv = handle_remove_channel(self.options, self.session, [self.channel_name]) - actual = stdout.getvalue() - expected = 'remove-channel is deprecated and will be removed in 1.30\n' - self.assertMultiLineEqual(actual, expected) - activate_session_mock.assert_called_once_with(self.session, self.options) - self.session.getChannel.assert_called_once_with(self.channel_name) - self.session.removeChannel.assert_called_once_with(self.channel_name, force=None) - self.assertNotEqual(rv, 1) - - @mock.patch('sys.stdout', new_callable=six.StringIO) - @mock.patch('koji_cli.commands.activate_session') - def test_handle_remove_channel_force(self, activate_session_mock, stdout): - self.session.getChannel.return_value = self.channel_info - rv = handle_remove_channel(self.options, self.session, ['--force', self.channel_name]) - actual = stdout.getvalue() - expected = 'remove-channel is deprecated and will be removed in 1.30\n' - self.assertMultiLineEqual(actual, expected) - activate_session_mock.assert_called_once_with(self.session, self.options) - self.session.getChannel.assert_called_once_with(self.channel_name) - self.session.removeChannel.assert_called_once_with(self.channel_name, force=True) - self.assertNotEqual(rv, 1) - - @mock.patch('sys.stderr', new_callable=six.StringIO) - @mock.patch('koji_cli.commands.activate_session') - def test_handle_remove_channel_no_channel( - self, activate_session_mock, stderr): - channel_info = None - - self.session.getChannel.return_value = channel_info - with self.assertRaises(SystemExit) as ex: - handle_remove_channel(self.options, self.session, [self.channel_name]) - self.assertExitCode(ex, 1) - actual = stderr.getvalue() - expected = 'No such channel: %s\n' % self.channel_name - self.assertMultiLineEqual(actual, expected) - activate_session_mock.assert_called_once_with(self.session, self.options) - self.session.getChannel.assert_called_once_with(self.channel_name) - self.session.removeChannel.assert_not_called() - - @mock.patch('sys.stdout', new_callable=six.StringIO) - @mock.patch('sys.stderr', new_callable=six.StringIO) - @mock.patch('koji_cli.commands.activate_session') - def test_handle_remove_channel_help( - self, activate_session_mock, stderr, stdout): - with self.assertRaises(SystemExit) as ex: - handle_remove_channel(self.options, self.session, []) - self.assertExitCode(ex, 2) - actual_stdout = stdout.getvalue() - actual_stderr = stderr.getvalue() - expected_stdout = 'remove-channel is deprecated and will be removed in 1.30\n' - expected_stderr = """Usage: %s remove-channel [options] -(Specify the --help global option for a list of other help options) - -%s: error: Incorrect number of arguments -""" % (self.progname, self.progname) - self.assertMultiLineEqual(actual_stdout, expected_stdout) - self.assertMultiLineEqual(actual_stderr, expected_stderr) - activate_session_mock.assert_not_called() - self.session.getChannel.assert_not_called() - self.session.removeChannel.assert_not_called() - - -if __name__ == '__main__': - unittest.main() diff --git a/tests/test_hub/test_remove_channel.py b/tests/test_hub/test_remove_channel.py deleted file mode 100644 index 70cd7f5..0000000 --- a/tests/test_hub/test_remove_channel.py +++ /dev/null @@ -1,38 +0,0 @@ -import unittest - -import mock - -import koji -import kojihub - -UP = kojihub.UpdateProcessor - - -class TestRemoveChannel(unittest.TestCase): - def getUpdate(self, *args, **kwargs): - update = UP(*args, **kwargs) - update.execute = mock.MagicMock() - self.updates.append(update) - return update - - def setUp(self): - self.UpdateProcessor = mock.patch('kojihub.UpdateProcessor', - side_effect=self.getUpdate).start() - self.updates = [] - self.context = mock.patch('kojihub.context').start() - self.context.session.assertPerm = mock.MagicMock() - self.exports = kojihub.RootExports() - self.channel_name = 'test-channel' - - def tearDown(self): - mock.patch.stopall() - - @mock.patch('kojihub.get_channel_id') - def test_non_exist_channel(self, get_channel_id): - get_channel_id.side_effect = koji.GenericError('No such channel: %s' % self.channel_name) - - with self.assertRaises(koji.GenericError): - kojihub.remove_channel(self.channel_name) - - get_channel_id.assert_called_once_with(self.channel_name, strict=True) - self.assertEqual(len(self.updates), 0)