Repository: fedora-infra/bodhi

Issue:
Creating an update with --autokarma and without the --stable and --unstable-karma flags sets autokarma off
Today I created an update with the CLI like this:

```
$ bodhi updates new --user bowlofeggs --type bugfix --notes "The bodhi-client package no longer depends on yum." --bugs 1135681 --close-bugs --autokarma bodhi-2.4.0-3.fc26
Password:
================================================================================
     bodhi-2.4.0-3.fc26
================================================================================
  Update ID: FEDORA-2017-e2e877073e
    Release: Fedora 26
     Status: pending
       Type: bugfix
      Karma: 0
  Autokarma: False  [-3, 3]
    Request: testing
       Bugs: 1135681 - None
      Notes: The bodhi-client package no longer depends on yum.
  Submitter: bowlofeggs
  Submitted: 2017-03-22 22:30:16
   Comments: bodhi - 2017-03-22 22:30:16 (karma 0)
             This update has been submitted for testing by
             bowlofeggs.

  https://bodhi.fedoraproject.org/updates/FEDORA-2017-e2e877073e
```

Note that the Autokarma is False in the resulting text, and if I go to that update Autokarma is displayed as being off there as well. I would expect that the ```--autokarma``` flag would set it to be on.

#1298 may be related to this (and may even be the same underlying problem) - it reports that setting ```--stable-karma``` without specifying ```--autokarma``` sets autokarma to be on. Given this, my guess is that something is using the karma thresholds to determine whether to enable autokarma instead of the ```--autokarma``` flag.


Discussion:
@bowlofeggs `autokarma` by default is always enabled if we do not specify. There are similar testcases in [test_updates.py](https://github.com/fedora-infra/bodhi/blob/develop/bodhi/tests/server/services/test_updates.py) where we haven't set `autokarma = True`. 
Based on that #1298 should not be considered as a bug. 
But disabling autopush with flag `--autokarma` is worth investigating. 
I had a quick look at this one, as @trishnaguha said by default the autokarma is enabled (True), when you use the --autokarma option it will set the autokarma to False 🐒 .

I think we can go in 2 direction either make autokarma Flase by default, then you would need to add --autokarma to enable it, or either change the name of autokarma to noautokarma or something like that.

I am more for the first option.

edit
-----
There could be a 3rd option and use click Boolean flags (http://click.pocoo.org/5/options/#boolean-flags) and have something like

@click.option('--autokarma/--no-autokarma', default=True)

This would default to True, and still be True when you use --autokarma.

It looks like a nice solution
On Fri, 2017-06-02 at 10:57 -0700, Clement Verna wrote:
> I think we can go in 2 direction either make autokarma Flase by
> default, then you would need to add --autokarma to enable it, or
> either change the name of autokarma to noautokarma or something like
> that.
> I am more for the first option.

I also am in favor of the first option. The CLI already documents that
behavior (even though it doesn't follow it) so it would be best if we
stick to it.

Hopefully we can fix this only in the bindings/CLI code without
disrupting the API.

Resolving patch:
diff --git a/bodhi/client/__init__.py b/bodhi/client/__init__.py
--- a/bodhi/client/__init__.py
+++ b/bodhi/client/__init__.py
@@ -60,7 +60,7 @@ def _warn_if_url_and_staging_set(ctx, param, value):
     click.option('--close-bugs', default=True, is_flag=True, help='Automatically close bugs'),
     click.option('--request', help='Requested repository',
                  type=click.Choice(['testing', 'stable', 'unpush'])),
-    click.option('--autokarma', default=True, is_flag=True, help='Enable karma automatism'),
+    click.option('--autokarma', is_flag=True, help='Enable karma automatism'),
     click.option('--stable-karma', type=click.INT, help='Stable karma threshold'),
     click.option('--unstable-karma', type=click.INT, help='Unstable karma threshold'),
     click.option('--suggest', help='Post-update user suggestion',


Test patch:
diff --git a/bodhi/tests/client/test___init__.py b/bodhi/tests/client/test___init__.py
--- a/bodhi/tests/client/test___init__.py
+++ b/bodhi/tests/client/test___init__.py
@@ -109,7 +109,7 @@ def test_url_flag(self, send_request):
 
         result = runner.invoke(
             client.new,
-            ['--user', 'bowlofeggs', '--password', 's3kr3t', 'bodhi-2.2.4-1.el7',
+            ['--user', 'bowlofeggs', '--password', 's3kr3t', '--autokarma', 'bodhi-2.2.4-1.el7',
              '--url', 'http://localhost:6543'])
 
         self.assertEqual(result.exit_code, 0)
@@ -388,7 +388,7 @@ def test_url_flag(self, send_request, query):
             bindings_client, 'updates/', auth=True, verb='POST',
             data={
                 'close_bugs': True, 'stable_karma': None, 'csrf_token': 'a_csrf_token',
-                'staging': False, 'builds': u'nodejs-grunt-wrap-0.3.0-2.fc25', 'autokarma': True,
+                'staging': False, 'builds': u'nodejs-grunt-wrap-0.3.0-2.fc25', 'autokarma': False,
                 'edited': u'nodejs-grunt-wrap-0.3.0-2.fc25', 'suggest': None,
                 'notes': u'this is an edited note', 'notes_file': None,
                 'request': None, 'bugs': u'', 'unstable_karma': None, 'type': 'bugfix'})
@@ -425,7 +425,7 @@ def test_notes_file(self, send_request, query):
                 data={
                     'close_bugs': True, 'stable_karma': None, 'csrf_token': 'a_csrf_token',
                     'staging': False, 'builds': u'nodejs-grunt-wrap-0.3.0-2.fc25',
-                    'autokarma': True, 'edited': u'nodejs-grunt-wrap-0.3.0-2.fc25',
+                    'autokarma': False, 'edited': u'nodejs-grunt-wrap-0.3.0-2.fc25',
                     'suggest': None, 'notes': 'This is a --notes-file note!',
                     'notes_file': 'notefile.txt', 'request': None, 'bugs': u'',
                     'unstable_karma': None, 'type': 'bugfix'})
@@ -470,7 +470,7 @@ def test_update_title(self, send_request):
             bindings_client, 'updates/', auth=True, verb='POST',
             data={
                 'close_bugs': True, 'stable_karma': None, 'csrf_token': 'a_csrf_token',
-                'staging': False, 'builds': u'drupal7-i18n-1.17-1.fc26', 'autokarma': True,
+                'staging': False, 'builds': u'drupal7-i18n-1.17-1.fc26', 'autokarma': False,
                 'edited': u'drupal7-i18n-1.17-1.fc26', 'suggest': None,
                 'notes': u'this is an edited note', 'notes_file': None,
                 'request': None, 'bugs': u'', 'unstable_karma': None, 'type': 'bugfix'})