From 07e7c53b1471bfc2e45c82d5975433848d7f1e83 Mon Sep 17 00:00:00 2001
From: Dominik Rumian <drumian@redhat.com>
Date: Apr 11 2022 09:49:54 +0000
Subject: fedpkg update --suggest-logout option added


Option --suggest-logout was not implemented although it
is supported by Bodhi. This commit adds this option.

Jira: RHELCMP-8704
Fixes: https://pagure.io/fedpkg/issue/472

Signed-off-by: Dominik Rumian <drumian@redhat.com>

---

diff --git a/fedpkg/__init__.py b/fedpkg/__init__.py
index a52c70d..60a8193 100644
--- a/fedpkg/__init__.py
+++ b/fedpkg/__init__.py
@@ -62,6 +62,7 @@ if _BodhiClient is not None:
 
         UPDATE_TYPES = ['bugfix', 'security', 'enhancement', 'newpackage']
         REQUEST_TYPES = ['testing', 'stable']
+        SUGGEST_TYPES = ['unspecified', 'reboot', 'logout']
 
         @clear_csrf_and_retry
         def save(self, *args, **kwargs):
@@ -359,6 +360,9 @@ class Commands(pyrpkg.Commands):
             if detail['request'] not in BodhiClient.REQUEST_TYPES:
                 raise ValueError(
                     'Incorrect request type {0}'.format(detail['request']))
+            if detail['suggest'] not in BodhiClient.SUGGEST_TYPES:
+                raise ValueError(
+                    'Incorrect suggest type {0}'.format(detail['suggest']))
 
             try:
                 self.log.info(bodhi.update_str(bodhi.save(**detail), minimal=False))
diff --git a/fedpkg/cli.py b/fedpkg/cli.py
index 58fabbe..8fc8f8d 100644
--- a/fedpkg/cli.py
+++ b/fedpkg/cli.py
@@ -78,8 +78,10 @@ unstable_karma=%(unstable_karma)s
 # Automatically close bugs when this marked as stable
 close_bugs=%(close_bugs)s
 
-# Suggest that users restart after update
-suggest_reboot=%(suggest_reboot)s
+# Suggest that users performs one of the following actions after the update:
+# unspecified, restart, logout
+# The default value is unspecified
+suggest=%(suggest)s
 
 # A boolean to require that all of the bugs in your update have been confirmed by testers.
 require_bugs=%(require_bugs)s
@@ -245,12 +247,6 @@ class fedpkgClient(cliClient):
                  ' automatically. If this is what you do not want, use this '
                  'option to disable the default behavior.')
         update_parser.add_argument(
-            '--suggest-reboot',
-            action='store_true',
-            default=False,
-            dest='suggest_reboot',
-            help='Suggest user to reboot after update. Default is False.')
-        update_parser.add_argument(
             '--no-require-bugs',
             action='store_false',
             default=True,
@@ -264,6 +260,21 @@ class fedpkgClient(cliClient):
             dest='require_testcases',
             help='Disables the requirement that this update passes all test cases '
                  'before reaching stable. Default is True.')
+
+        group = update_parser.add_mutually_exclusive_group()
+        group.add_argument(
+            '--suggest-reboot',
+            action='store_true',
+            default=False,
+            dest='suggest_reboot',
+            help='Suggest user to reboot after update. Default is False.')
+        group.add_argument(
+            '--suggest-logout',
+            action='store_true',
+            default=False,
+            dest='suggest_logout',
+            help='Suggest user to logout after update. Default is False.')
+
         update_parser.set_defaults(command=self.update)
 
     def get_distgit_namespaces(self):
@@ -810,11 +821,16 @@ class fedpkgClient(cliClient):
             'stable_karma': self.args.stable_karma,
             'unstable_karma': self.args.unstable_karma,
             'close_bugs': str(self.args.close_bugs),
-            'suggest_reboot': str(self.args.suggest_reboot),
+            'suggest': 'unspecified',
             'require_bugs': str(self.args.require_bugs),
             'require_testcases': str(self.args.require_testcases),
         }
 
+        if self.args.suggest_reboot:
+            bodhi_args['suggest'] = 'reboot'
+        elif self.args.suggest_logout:
+            bodhi_args['suggest'] = 'logout'
+
         if self.args.update_type:
             bodhi_args['type_'] = self.args.update_type
         else:
diff --git a/test/test_cli.py b/test/test_cli.py
index 957cefe..6a9864d 100644
--- a/test/test_cli.py
+++ b/test/test_cli.py
@@ -169,7 +169,8 @@ class TestUpdate(CliTestCase):
     @patch('fedora.client.OpenIdBaseClient._load_cookies')
     def assert_bodhi_update(self, cli, _load_cookies, send_request, csrf,
                             update_type=None, request_type=None, notes=None,
-                            stable_karma=None, unstable_karma=None):
+                            stable_karma=None, unstable_karma=None,
+                            suggest=None):
         csrf.return_value = '123456'
 
         def run_command_side_effect(command, shell):
@@ -189,6 +190,10 @@ class TestUpdate(CliTestCase):
                     content = re.sub('request=[a-z]+\n',
                                      'request={0}\n'.format(request_type),
                                      content)
+                if suggest:
+                    content = re.sub('suggest=[a-z]+\n',
+                                     'suggest={0}\n'.format(suggest),
+                                     content)
                 f.write(content)
 
         self.mock_run_command.side_effect = run_command_side_effect
@@ -327,6 +332,14 @@ class TestUpdate(CliTestCase):
                               update_type='enhancement',
                               request_type='xxx')
 
+    def test_incorrect_suggest_type_in_template(self):
+        cli_cmd = ['fedpkg-stage', '--path', self.cloned_repo_path, 'update']
+        cli = self.get_cli(cli_cmd)
+        six.assertRaisesRegex(self, rpkgError, 'Incorrect suggest type',
+                              self.assert_bodhi_update, cli,
+                              update_type='enhancement',
+                              suggest='123')
+
     def test_create_with_cli_options(self):
         cli_cmd = [
             'fedpkg-stage', '--path', self.cloned_repo_path,

