Browse Source

Improved logic for GPG key fix

bugfixes
gau1991 10 years ago
parent
commit
a6cecb9fdf
  1. 12
      ee/cli/plugins/stack.py
  2. 11
      ee/cli/plugins/stack_migrate.py
  3. 10
      ee/cli/plugins/stack_upgrade.py
  4. 56
      ee/core/aptget.py
  5. 8
      ee/core/gpgkeyfix.py

12
ee/cli/plugins/stack.py

@ -16,7 +16,6 @@ from ee.core.checkfqdn import check_fqdn
from pynginxconfig import NginxConfig
from ee.core.services import EEService
from ee.core.variables import EEVariables
from ee.core.gpgkeyfix import gpgkeyfix
import random
import string
import configparser
@ -1584,16 +1583,7 @@ class EEStackController(CementBaseController):
if len(apt_packages):
EESwap.add(self)
Log.info(self, "Updating apt-cache, please wait...")
if not EEAptGet.update(self):
Log.info(self, "Fixing mixing GPG keys, please wait...")
gpgkeyfix(self)
if not EEAptGet.update(self):
Log.info(self, Log.FAIL + "Oops Something went "
"wrong!!")
Log.error(self, "Check logs for reason "
"`tail /var/log/ee/ee.log` & Try Again!!!")
EEAptGet.update(self)
Log.info(self, "Installing packages, please wait...")
EEAptGet.install(self, apt_packages)
if len(packages):

11
ee/cli/plugins/stack_migrate.py

@ -7,7 +7,6 @@ from ee.core.aptget import EEAptGet
from ee.core.shellexec import EEShellExec
from ee.core.apt_repo import EERepo
from ee.core.services import EEService
from ee.core.gpgkeyfix import gpgkeyfix
import configparser
import os
@ -89,15 +88,7 @@ class EEStackMigrateController(CementBaseController):
"libclass-dbi-mysql-perl"]
Log.info(self, "Updating apt-cache, please wait...")
if not EEAptGet.update(self):
Log.info(self, "Fixing mixing GPG keys, please wait...")
gpgkeyfix(self)
if not EEAptGet.update(self):
Log.info(self, Log.FAIL + "Oops Something went wrong!!")
Log.error(self, "Check logs for reason "
"`tail /var/log/ee/ee.log` & Try Again!!!")
EEAptGet.update(self)
Log.info(self, "Installing MariaDB, please wait...")
EEAptGet.remove(self, ["mysql-common", "libmysqlclient18"])
EEAptGet.auto_remove(self)

10
ee/cli/plugins/stack_upgrade.py

@ -7,7 +7,6 @@ from ee.core.apt_repo import EERepo
from ee.core.services import EEService
from ee.core.fileutils import EEFileUtils
from ee.core.shellexec import EEShellExec
from ee.core.gpgkeyfix import gpgkeyfix
import configparser
import os
@ -77,14 +76,7 @@ class EEStackUpgradeController(CementBaseController):
"php55", "php56")
Log.info(self, "Updating apt-cache, please wait...")
if not EEAptGet.update(self):
Log.info(self, "Fixing mixing GPG keys, please wait...")
gpgkeyfix(self)
if not EEAptGet.update(self):
Log.info(self, Log.FAIL + "Oops Something went wrong!!")
Log.error(self, "Check logs for reason "
"`tail /var/log/ee/ee.log` & Try Again!!!")
EEAptGet.update(self)
Log.info(self, "Installing packages, please wait ...")
EEAptGet.install(self, EEVariables.ee_php)

56
ee/core/aptget.py

@ -4,6 +4,7 @@ import apt_pkg
import sys
import subprocess
from ee.core.logging import Log
from ee.core.apt_repo import EERepo
from sh import apt_get
from sh import ErrorReturnCode
@ -19,18 +20,38 @@ class EEAptGet():
with open('/var/log/ee/ee.log', 'a') as f:
proc = subprocess.Popen('apt-get update',
shell=True,
stdin=None, stdout=f, stderr=f,
stdin=None, stdout=f,
stderr=subprocess.PIPE,
executable="/bin/bash")
proc.wait()
output, error_output = proc.communicate()
if proc.returncode == 0:
return True
else:
return False
# Check what is error in error_output
if "NO_PUBKEY" in str(error_output):
# Split the output
error_list = str(error_output).split("\\n")
# Use a loop to add misising keys
for single_error in error_list:
if "NO_PUBKEY" in single_error:
key = single_error.rsplit(None, 1)[-1]
EERepo.add_key(self, key)
proc = subprocess.Popen('apt-get update',
shell=True,
stdin=None, stdout=f, stderr=f,
executable="/bin/bash")
proc.wait()
if proc.returncode == 0:
return True
else:
Log.info(self, Log.FAIL + "Oops Something went wrong!!")
Log.error(self, "Check logs for reason "
"`tail /var/log/ee/ee.log` & Try Again!!!")
except Exception as e:
Log.error(self, "Error while installing packages, "
"apt-get exited with error")
Log.error(self, "apt-get update exited with error")
def check_upgrade(self):
"""
@ -71,7 +92,10 @@ class EEAptGet():
if proc.returncode == 0:
return True
else:
Log.error(self, "Unable to run apt-get dist_upgrade")
Log.info(self, Log.FAIL + "Oops Something went "
"wrong!!")
Log.error(self, "Check logs for reason "
"`tail /var/log/ee/ee.log` & Try Again!!!")
except Exception as e:
Log.error(self, "Error while installing packages, "
"apt-get exited with error")
@ -94,11 +118,16 @@ class EEAptGet():
if proc.returncode == 0:
return True
else:
Log.error(self, "Unable to run apt-get install")
Log.info(self, Log.FAIL + "Oops Something went "
"wrong!!")
Log.error(self, "Check logs for reason "
"`tail /var/log/ee/ee.log` & Try Again!!!")
except Exception as e:
Log.error(self, "Error while installing packages, "
"apt-get exited with error")
Log.info(self, Log.FAIL + "Oops Something went "
"wrong!!")
Log.error(self, "Check logs for reason "
"`tail /var/log/ee/ee.log` & Try Again!!!")
def remove(self, packages, auto=False, purge=False):
all_packages = ' '.join(packages)
@ -118,7 +147,10 @@ class EEAptGet():
if proc.returncode == 0:
return True
else:
Log.error(self, "Unable to run apt-get remove/purge")
Log.info(self, Log.FAIL + "Oops Something went "
"wrong!!")
Log.error(self, "Check logs for reason "
"`tail /var/log/ee/ee.log` & Try Again!!!")
except Exception as e:
Log.error(self, "Error while installing packages, "

8
ee/core/gpgkeyfix.py

@ -1,17 +1,23 @@
"""EasyEngine apt-get update GPG Key fix module"""
import os
from ee.core.apt_repo import EERepo
import subprocess
def gpgkeyfix(self):
try:
# Run apt-get update
sub = subprocess.Popen('apt-get update', stdout=subprocess.PIPE,
stderr=subprocess.PIPE, shell=True)
sub.wait()
output, error_output = sub.communicate()
# Check what is error in error_output
if "NO_PUBKEY" in str(error_output):
# Split the output
error_list = str(error_output).split("\\n")
# Use a loop to add misising keys
for single_error in error_list:
if "NO_PUBKEY" in single_error:
key = single_error.rsplit(None, 1)[-1]

Loading…
Cancel
Save