Repository: certbot/certbot

Issue:
--configurator and _set_by_cli problems
Running `letsencrypt renew` with a value for `configurator` set on the CLI or in a configfile leads to errors like this:

```
2016-03-15 13:12:28,832:WARNING:letsencrypt.cli:An error occured while parsing /etc/letsencrypt/renewal/example.com.conf. The error was Too many flags setting configurators/installers/authenticators 'apache' -> ''. Skipping the file.
```

This problem is also causing the errors in #2663, where `letsencrypt-nginx/tests/boulder-integration.sh` is calling `letsencrypt` with `--configurator nginx` which causes `_set_by_cli` to raise an exception when creating a new lineage.



Discussion:

Resolving patch:
diff --git a/letsencrypt/cli.py b/letsencrypt/cli.py
--- a/letsencrypt/cli.py
+++ b/letsencrypt/cli.py
@@ -168,7 +168,7 @@ def set_configurator(previously, now):
     :param str previously: previously identified request for the installer/authenticator
     :param str requested: the request currently being processed
     """
-    if now is None:
+    if not now:
         # we're not actually setting anything
         return previously
     if previously:


Test patch:
diff --git a/letsencrypt/tests/cli_test.py b/letsencrypt/tests/cli_test.py
--- a/letsencrypt/tests/cli_test.py
+++ b/letsencrypt/tests/cli_test.py
@@ -52,6 +52,9 @@ def setUp(self):
 
     def tearDown(self):
         shutil.rmtree(self.tmp_dir)
+        # Reset globals in cli
+        # pylint: disable=protected-access
+        cli._parser = cli._set_by_cli.detector = None
 
     def _call(self, args):
         "Run the cli with output streams and actual client mocked out"
@@ -135,7 +138,6 @@ def test_help(self):
         out = self._help_output(['-h'])
         self.assertTrue(cli.usage_strings(plugins)[0] in out)
 
-
     def _cli_missing_flag(self, args, message):
         "Ensure that a particular error raises a missing cli flag error containing message"
         exc = None
@@ -682,8 +684,8 @@ def _make_dummy_renewal_config(self):
         with open(os.path.join(renewer_configs_dir, 'test.conf'), 'w') as f:
             f.write("My contents don't matter")
 
-    def _test_renew_common(self, renewalparams=None, error_expected=False,
-                           names=None, assert_oc_called=None):
+    def _test_renew_common(self, renewalparams=None, names=None,
+                           assert_oc_called=None, **kwargs):
         self._make_dummy_renewal_config()
         with mock.patch('letsencrypt.storage.RenewableCert') as mock_rc:
             mock_lineage = mock.MagicMock()
@@ -694,8 +696,9 @@ def _test_renew_common(self, renewalparams=None, error_expected=False,
                 mock_lineage.names.return_value = names
             mock_rc.return_value = mock_lineage
             with mock.patch('letsencrypt.main.obtain_cert') as mock_obtain_cert:
-                self._test_renewal_common(True, None, error_expected=error_expected,
-                                          args=['renew'], renew=False)
+                kwargs.setdefault('args', ['renew'])
+                self._test_renewal_common(True, None, renew=False, **kwargs)
+
             if assert_oc_called is not None:
                 if assert_oc_called:
                     self.assertTrue(mock_obtain_cert.called)
@@ -718,7 +721,7 @@ def test_renew_with_bad_int(self):
     def test_renew_with_nonetype_http01(self):
         renewalparams = {'authenticator': 'webroot',
                          'http01_port': 'None'}
-        self._test_renew_common(renewalparams=renewalparams, error_expected=False,
+        self._test_renew_common(renewalparams=renewalparams,
                                 assert_oc_called=True)
 
     def test_renew_with_bad_domain(self):
@@ -727,6 +730,12 @@ def test_renew_with_bad_domain(self):
         self._test_renew_common(renewalparams=renewalparams, error_expected=True,
                                 names=names, assert_oc_called=False)
 
+    def test_renew_with_configurator(self):
+        renewalparams = {'authenticator': 'webroot'}
+        self._test_renew_common(
+            renewalparams=renewalparams, assert_oc_called=True,
+            args='renew --configurator apache'.split())
+
     def test_renew_plugin_config_restoration(self):
         renewalparams = {'authenticator': 'webroot',
                          'webroot_path': 'None',