Repository: freedomofpress/securedrop

Issue:
[QA] Problems running securedrop_init handler via tailsconfig
# Bug

## Description
Recently failed to run the network hook via handler as part of `./securedrop-admin tailsconfig`. 

## Steps to Reproduce

Admittedly I haven't actually reproduced it yet, but here's the procedure:

1. Fire up Admin Workstation to provision prod VMs.
2. Ensure HTTPS is enabled via `sdconfig`. 
3. Provision prod VMs via `install`.
4. After successful reboot at end of install flow, run `./securedrop-admin tailsconfig`.
5. Observe error on handler to run the securedrop_init.py script.

## Expected Behavior
Handler fires without issue.

## Actual Behavior
Handler raises an error. 

<details><summary>Error output from Ansible</summary>

```
RUNNING HANDLER [tails-config : run securedrop network hook] ***************************************************
fatal: [localhost]: FAILED! => {"changed": true, "cmd": ["/usr/bin/python", "/home/amnesia/Persistent/.securedrop/securedrop_init.py"], "delta": "0:00:06.858216", "end": "2018-05-01 21:08:06.529290", "msg": "non-zero return code", "rc": 1, "start": "2018-05-01 21:07:59.671074", "stderr": "Cannot parse integer value 'If' for --expire-time\nFrom https://github.com/freedomofpress/securedrop\n * [new branch]        3329-test-gzip-mtime -> origin/3329-test-gzip-mtime\n * [new branch]        ask_all_three        -> origin/ask_all_three\n * [new branch]        backport-3332-0.7.0  -> origin/backport-3332-0.7.0\n   095d08a2..cfaa82e7  develop              -> origin/develop\n(True, '0.6')\nTraceback (most recent call last):\n  File \"/home/amnesia/Persistent/.securedrop/securedrop_init.py\", line 109, in <module>\n  File \"/usr/lib/python2.7/subprocess.py\", line 219, in check_output\n    raise CalledProcessError(retcode, cmd, output=output)\nsubprocess.CalledProcessError: Command '['/home/amnesia/Persistent/securedrop/admin/.venv/bin/python', '/home/amnesia/Persistent/securedrop/admin/securedrop_admin/__init__.py', '--root', '/home/amnesia/Persistent/securedrop', 'check_for_updates']' returned non-zero exit status 1", "stderr_lines": ["Cannot parse integer value 'If' for --expire-time", "From https://github.com/freedomofpress/securedrop", " * [new branch]        3329-test-gzip-mtime -> origin/3329-test-gzip-mtime", " * [new branch]        ask_all_three        -> origin/ask_all_three", " * [new branch]        backport-3332-0.7.0  -> origin/backport-3332-0.7.0", "   095d08a2..cfaa82e7  develop              -> origin/develop", "(True, '0.6')", "Traceback (most recent call last):", "  File \"/home/amnesia/Persistent/.securedrop/securedrop_init.py\", line 109, in <module>", "  File \"/usr/lib/python2.7/subprocess.py\", line 219, in check_output", "    raise CalledProcessError(retcode, cmd, output=output)", "subprocess.CalledProcessError: Command '['/home/amnesia/Persistent/securedrop/admin/.venv/bin/python', '/home/amnesia/Persistent/securedrop/admin/securedrop_admin/__init__.py', '--root', '/home/amnesia/Persistent/securedrop', 'check_for_updates']' returned non-zero exit status 1"], "stdout": "", "stdout_lines": []}
```
</details>



<details><summary>Error output from manual invocation</summary>

```
amnesia@amnesia:~/Persistent/securedrop/install_files/ansible-base$ sudo !!
sudo python /home/amnesia/Persistent/.securedrop/securedrop_init.py
[sudo] password for amnesia: 
Cannot parse integer value 'If' for --expire-time
(True, '0.6')
Traceback (most recent call last):
  File "/home/amnesia/Persistent/.securedrop/securedrop_init.py", line 109, in <module>
  File "/usr/lib/python2.7/subprocess.py", line 219, in check_output
    raise CalledProcessError(retcode, cmd, output=output)
subprocess.CalledProcessError: Command '['/home/amnesia/Persistent/securedrop/admin/.venv/bin/python', '/home/amnesia/Persistent/securedrop/admin/securedrop_admin/__init__.py', '--root', '/home/amnesia/Persistent/securedrop', 'check_for_updates']' returned non-zero exit status 1
```

</details>


Was working on #3299 when this happened, so I could have broken something. I'm able to see the error when running from `release/0.7`, as well.


Discussion:
It's possible that a regression snuck in with #3327

Resolving patch:
diff --git a/admin/securedrop_admin/__init__.py b/admin/securedrop_admin/__init__.py
--- a/admin/securedrop_admin/__init__.py
+++ b/admin/securedrop_admin/__init__.py
@@ -550,6 +550,12 @@ def run_tails_config(args):
                                  cwd=args.ansible_path)
 
 
+def check_for_updates_wrapper(args):
+    res, tag = check_for_updates(args)
+    # Because the command worked properly exit with 0.
+    return 0
+
+
 def check_for_updates(args):
     """Check for SecureDrop updates"""
     sdlog.info("Checking for SecureDrop updates...")
@@ -702,7 +708,7 @@ class ArgParseFormatterCombo(argparse.ArgumentDefaultsHelpFormatter,
 
     parse_check_updates = subparsers.add_parser('check_for_updates',
                                                 help=check_for_updates.__doc__)
-    parse_check_updates.set_defaults(func=check_for_updates)
+    parse_check_updates.set_defaults(func=check_for_updates_wrapper)
 
     parse_logs = subparsers.add_parser('logs',
                                        help=get_logs.__doc__)


Test patch: