Skip to content

Commit

Permalink
Added try block
Browse files Browse the repository at this point in the history
  • Loading branch information
nrchandan committed Feb 1, 2014
1 parent 3c2a8db commit b43211d
Showing 1 changed file with 20 additions and 12 deletions.
32 changes: 20 additions & 12 deletions VMManager/VMManager.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@

import os
import subprocess
import logging
import shlex
import json
import logging
from logging.handlers import TimedRotatingFileHandler

from LabActionRunner import LabActionRunner
Expand Down Expand Up @@ -49,7 +49,12 @@ def f(*popenargs, **kwargs):

def execute(command):
# do some validation
return subprocess.check_output(command, shell=True)
try:
VMM_LOGGER.info("Command executed: " + command)
return subprocess.check_output(command, shell=True)
except Exception, e:
VMM_LOGGER.error("Execution failed: " + str(e))
return "Error executing the command: " + str(e)

def running_time():
return execute("uptime")
Expand Down Expand Up @@ -95,8 +100,7 @@ def clone_repo(repo_name):
try:
subprocess.check_call(clone_cmd, stdout=LOG_FD, stderr=LOG_FD)
except Exception, e:
# different logger needs to be implemented here
VMM_LOGGER.error("git clone failed: %s %s" % (repo_name, str(e)))
VMM_LOGGER.error("git clone failed for repo %s: %s" % (repo_name, str(e)))
raise e

def pull_repo(repo_name):
Expand All @@ -105,7 +109,7 @@ def pull_repo(repo_name):
try:
subprocess.check_call(pull_cmd, stdout=LOG_FD, stderr=LOG_FD)
except Exception, e:
VMM_LOGGER.error("git pull failed: %s %s" % (repo_name, str(e)))
VMM_LOGGER.error("git pull failed for repo %s: %s" % (repo_name, str(e)))
raise e

def checkout_version(repo_name):
Expand All @@ -121,7 +125,6 @@ def checkout_version(repo_name):

def get_lab_spec(repo_name):
repo_path = GIT_CLONE_LOC + repo_name + LAB_SPEC_LOC
print repo_path
if not os.path.exists(repo_path):
raise LabSpecInvalid("Lab spec file not found")
try:
Expand All @@ -137,13 +140,18 @@ def get_lab_spec(repo_name):
checkout_version(repo_name)

lab_spec = get_lab_spec(repo_name)
try:
lar = LabActionRunner(get_installer_steps_spec(lab_spec), "")
lar.run_install_source()

lar = LabActionRunner(get_installer_steps_spec(lab_spec), "")
lar.run_install_source()

lar = LabActionRunner(get_build_steps_spec(lab_spec), "")
lar.run_build_steps()
lar = LabActionRunner(get_build_steps_spec(lab_spec), "")
lar.run_build_steps()

return "Success"
except Exception, e:
VMM_LOGGER.error("VMManager.test_lab failed: " + str(e))
return "Test lab failed"


def setup_logging():
VMM_LOGGER.setLevel(logging.DEBUG) # make log level a setting
Expand All @@ -156,7 +164,7 @@ def setup_logging():
datefmt='%Y-%m-%d %I:%M:%S %p')
myhandler.setFormatter(formatter)
VMM_LOGGER.addHandler(myhandler)


setup_logging()
LOG_FD = open(LOG_FILENAME, 'a')
Expand Down

0 comments on commit b43211d

Please sign in to comment.