Repository: certbot/certbot

Issue:
apache reverter can fail due to module dependency order
Running on Ubuntu 12 with the wrong augeas version, and a only default vhosts present, I hit this interesting error:

```
No vhost exists with servername or alias of: maybe.isnot.org. No     │  
                                               │ vhost was selected. Please specify servernames in the Apache config  │  
                                               │ Error while running a2dismod socache_shmcb.                          │  
                                               │ ERROR: The following modules depend on socache_shmcb and need to be  │  
                                               │ disabled first: ssl                                                  │  
                                               │ Unable to run undo command: a2dismod socache_shmcb                   │  
                                               │ Error while running a2dismod mime.                                   │  
                                               │ WARNING: The following essential module will be disabled.            │  
                                               │ This might result in unexpected behavior and should NOT be done      │  
                                               │ unless you know exactly what you are doing!                          │  
                                               │  mime                                                                │  
                                               │ To continue type in the phrase 'Yes, do as I say!' or retry by       │  
                                               │ passing '-f': Aborting                                               │  
                                               │ Unable to run undo command: a2dismod mime 
```

Probably we shouldn't freak out so much in this case...



Discussion:

Resolving patch:
diff --git a/letsencrypt-apache/letsencrypt_apache/configurator.py b/letsencrypt-apache/letsencrypt_apache/configurator.py
--- a/letsencrypt-apache/letsencrypt_apache/configurator.py
+++ b/letsencrypt-apache/letsencrypt_apache/configurator.py
@@ -644,11 +644,11 @@ def prepare_https_modules(self, temp):
         """
 
         if self.conf("handle-modules"):
-            if "ssl_module" not in self.parser.modules:
-                self.enable_mod("ssl", temp=temp)
             if self.version >= (2, 4) and ("socache_shmcb_module" not in
                                            self.parser.modules):
                 self.enable_mod("socache_shmcb", temp=temp)
+            if "ssl_module" not in self.parser.modules:
+                self.enable_mod("ssl", temp=temp)
 
     def make_addrs_sni_ready(self, addrs):
         """Checks to see if the server is ready for SNI challenges.


Test patch:
diff --git a/letsencrypt-apache/letsencrypt_apache/tests/configurator_test.py b/letsencrypt-apache/letsencrypt_apache/tests/configurator_test.py
--- a/letsencrypt-apache/letsencrypt_apache/tests/configurator_test.py
+++ b/letsencrypt-apache/letsencrypt_apache/tests/configurator_test.py
@@ -429,9 +429,15 @@ def test_prepare_server_https(self):
         self.config.parser.add_dir_to_ifmodssl = mock_add_dir
 
         self.config.prepare_server_https("443")
+        # Changing the order these modules are enabled breaks the reverter
+        self.assertEqual(mock_enable.call_args_list[0][0][0], "socache_shmcb")
+        self.assertEqual(mock_enable.call_args[0][0], "ssl")
         self.assertEqual(mock_enable.call_args[1], {"temp": False})
 
         self.config.prepare_server_https("8080", temp=True)
+        # Changing the order these modules are enabled breaks the reverter
+        self.assertEqual(mock_enable.call_args_list[2][0][0], "socache_shmcb")
+        self.assertEqual(mock_enable.call_args[0][0], "ssl")
         # Enable mod is temporary
         self.assertEqual(mock_enable.call_args[1], {"temp": True})