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 pynginxconfig import NginxConfig
from ee.core.services import EEService from ee.core.services import EEService
from ee.core.variables import EEVariables from ee.core.variables import EEVariables
from ee.core.gpgkeyfix import gpgkeyfix
import random import random
import string import string
import configparser import configparser
@ -1584,16 +1583,7 @@ class EEStackController(CementBaseController):
if len(apt_packages): if len(apt_packages):
EESwap.add(self) EESwap.add(self)
Log.info(self, "Updating apt-cache, please wait...") Log.info(self, "Updating apt-cache, please wait...")
EEAptGet.update(self)
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!!!")
Log.info(self, "Installing packages, please wait...") Log.info(self, "Installing packages, please wait...")
EEAptGet.install(self, apt_packages) EEAptGet.install(self, apt_packages)
if len(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.shellexec import EEShellExec
from ee.core.apt_repo import EERepo from ee.core.apt_repo import EERepo
from ee.core.services import EEService from ee.core.services import EEService
from ee.core.gpgkeyfix import gpgkeyfix
import configparser import configparser
import os import os
@ -89,15 +88,7 @@ class EEStackMigrateController(CementBaseController):
"libclass-dbi-mysql-perl"] "libclass-dbi-mysql-perl"]
Log.info(self, "Updating apt-cache, please wait...") Log.info(self, "Updating apt-cache, please wait...")
EEAptGet.update(self)
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!!!")
Log.info(self, "Installing MariaDB, please wait...") Log.info(self, "Installing MariaDB, please wait...")
EEAptGet.remove(self, ["mysql-common", "libmysqlclient18"]) EEAptGet.remove(self, ["mysql-common", "libmysqlclient18"])
EEAptGet.auto_remove(self) 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.services import EEService
from ee.core.fileutils import EEFileUtils from ee.core.fileutils import EEFileUtils
from ee.core.shellexec import EEShellExec from ee.core.shellexec import EEShellExec
from ee.core.gpgkeyfix import gpgkeyfix
import configparser import configparser
import os import os
@ -77,14 +76,7 @@ class EEStackUpgradeController(CementBaseController):
"php55", "php56") "php55", "php56")
Log.info(self, "Updating apt-cache, please wait...") Log.info(self, "Updating apt-cache, please wait...")
if not EEAptGet.update(self): 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!!!")
Log.info(self, "Installing packages, please wait ...") Log.info(self, "Installing packages, please wait ...")
EEAptGet.install(self, EEVariables.ee_php) EEAptGet.install(self, EEVariables.ee_php)

56
ee/core/aptget.py

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

8
ee/core/gpgkeyfix.py

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

Loading…
Cancel
Save