minikube: better error handling
* stx control stop: don't auto-start minikube * return non-zero to shell when minikube profile is stopped Closes-Bug: 2083862 Signed-off-by: Davlet Panech <davlet.panech@windriver.com> Change-Id: Idd8dcc382c189fa36d40eb9b544e83a84a7ce1d5
This commit is contained in:
parent
71604e5dfb
commit
db26697886
@ -167,6 +167,13 @@ class MinikubeCtl(object):
|
||||
)
|
||||
return False
|
||||
|
||||
def require_started(self):
|
||||
"""
|
||||
Throw an exception if profile is not started
|
||||
"""
|
||||
if not self.is_started():
|
||||
raise MinikubeProfileNotRunning(self.minikube_profile)
|
||||
|
||||
def start(self):
|
||||
"""
|
||||
Starts the Minikube profile if it's not already started.
|
||||
|
@ -24,7 +24,6 @@ import time
|
||||
from stx.k8s import KubeHelper
|
||||
from stx.minikube import MinikubeCtl
|
||||
from stx.minikube import MinikubeProfileNotFoundError
|
||||
from stx.minikube import MinikubeProfileNotRunning
|
||||
|
||||
from stx import helper # pylint: disable=E0611
|
||||
from stx import stx_shell
|
||||
@ -295,7 +294,7 @@ stx-pkgbuilder/configmap/')
|
||||
timeout = 5 * 60
|
||||
deadline = time.time() + timeout
|
||||
if self.config.use_minikube:
|
||||
self.minikube_ctl.start()
|
||||
self.minikube_ctl.require_started()
|
||||
|
||||
helm_status = self.k8s.helm_release_exists(self.projectname)
|
||||
if helm_status:
|
||||
@ -343,19 +342,11 @@ stx-pkgbuilder/configmap/')
|
||||
self.shell.cmd_control_enter(args)
|
||||
|
||||
def handleStatusTask(self):
|
||||
try:
|
||||
if self.config.use_minikube:
|
||||
if not self.minikube_ctl.is_started():
|
||||
raise MinikubeProfileNotRunning(self.config.minikube_profile)
|
||||
|
||||
self.k8s.get_helm_info()
|
||||
self.k8s.get_deployment_info()
|
||||
self.k8s.get_pods_info()
|
||||
|
||||
except Exception as e:
|
||||
self.logger.error(
|
||||
"Error starting minikube_ctl: %s", str(e),
|
||||
)
|
||||
if self.config.use_minikube:
|
||||
self.minikube_ctl.require_started()
|
||||
self.k8s.get_helm_info()
|
||||
self.k8s.get_deployment_info()
|
||||
self.k8s.get_pods_info()
|
||||
|
||||
def run_pod_cmd(self, podname, maincmd, remotecmd):
|
||||
# Run command on pod in this format: kubectl+maincmd+podname+remotecmd
|
||||
@ -456,7 +447,9 @@ no lat container is available!')
|
||||
self.logger.error(helper.help_control())
|
||||
except MinikubeProfileNotFoundError as e:
|
||||
self.logger.error(str(e), exc_info=True)
|
||||
sys.exit(1)
|
||||
except Exception as e:
|
||||
self.logger.error(
|
||||
'Error executing control task: %s', str(e), exc_info=True
|
||||
)
|
||||
sys.exit(1)
|
||||
|
@ -19,7 +19,6 @@ import sys
|
||||
|
||||
from stx.k8s import KubeHelper
|
||||
from stx.minikube import MinikubeCtl
|
||||
from stx.minikube import MinikubeProfileNotRunning
|
||||
|
||||
from stx import utils # pylint: disable=E0611
|
||||
|
||||
@ -109,23 +108,23 @@ class HandleShellTask(object):
|
||||
if container not in self.all_container_names:
|
||||
self.logger.error("--%s must be one of: %s",
|
||||
container_arg, self.all_container_names)
|
||||
sys.exit(1)
|
||||
sys.exit(125)
|
||||
try:
|
||||
if self.config.use_minikube:
|
||||
if not self.minikube_ctl.is_started():
|
||||
raise MinikubeProfileNotRunning(self.config.minikube_profile)
|
||||
self.minikube_ctl.require_started()
|
||||
|
||||
shell_command = self.create_shell_command(container, command, no_tty)
|
||||
self.logger.debug('Running command: %s', shell_command)
|
||||
shell_status = subprocess.call(shell_command, shell=True)
|
||||
print(shell_status)
|
||||
sys.exit(shell_status)
|
||||
except RuntimeError as e:
|
||||
self.logger.error(str(e))
|
||||
self.logger.error("To check the status of the pods, run: 'stx control status'.")
|
||||
self.logger.error("To start the build pod, run: 'stx control start --wait'.")
|
||||
sys.exit(125)
|
||||
except Exception as e:
|
||||
self.logger.error(str(e), exc_info=True)
|
||||
sys.exit(125)
|
||||
|
||||
def cmd_shell(self, args):
|
||||
self.logger.setLevel(args.loglevel)
|
||||
|
Loading…
x
Reference in New Issue
Block a user