Skip to content

Commit

Permalink
few more bug fixes 😌
Browse files Browse the repository at this point in the history
  • Loading branch information
avinassh committed Jan 31, 2014
1 parent c1cd0b6 commit c31d78c
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 15 deletions.
2 changes: 1 addition & 1 deletion CentOSVZAdapter.py
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@ def find_os_template(os, os_version):
os_version = OS_VERSION if os_version == "" else os_version.strip()
if os == "UBUNTU":
if os_version == "12.04" or os_version == "12":
return "ubuntu-12.04-custom1-x86_64"
return "ubuntu-12.04-custom-x86_64"
elif os_version == "11.10" or os_version == "11":
return "ubuntu-11.10-x86_64"
elif os == "CENTOS":
Expand Down
9 changes: 6 additions & 3 deletions Controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,11 @@ def test_lab(self, lab_id, lab_src_url, version=None):
lab_spec = LabManager.get_lab_reqs(lab_id, lab_src_url, version)
vmpoolmgr = VMPoolManager.VMPoolManager()
(ip, port) = vmpoolmgr.create_vm(lab_spec)
print 'created vm ', ip, port
LabManager.test_lab(ip, port, lab_src_url, version)
#print 'created vm ', ip, port
if LabManager.test_lab(ip, port, lab_src_url, version):
return ip
else:
return "Test failed"
except Exception, e:
# This should return an error json when Controller is a web service
print e
Expand All @@ -32,4 +35,4 @@ def test_lab(self, lab_id, lab_src_url, version=None):
if __name__ == '__main__':
c = Controller()
#c.test_lab("asdf", "asdf")
c.test_lab("asdf", "https://github.com/vlead/simo.git")
print c.test_lab("ovpl01", "https://github.com/nrchandan/vlab-computer-programming")
3 changes: 2 additions & 1 deletion LabManager.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ def checkout_version(repo_name):
raise e

def get_lab_spec(repo_name):
# Allow no lab spec but not an invalid json as a lab spec
spec_path = GIT_CLONE_LOC + repo_name + LAB_SPEC_LOC
if not os.path.exists(spec_path):
raise LabSpecInvalid("Lab spec file not found")
Expand Down Expand Up @@ -89,7 +90,7 @@ def test_lab(ip, port, lab_src_url, version=None):
payload = {"lab_src_url": lab_src_url, "version": version}
url = '%s:%s%s' % (ip, port, TEST_LAB_API_URI)
response = requests.post(url=url, data=payload)
print response.text
return response.text


def setup_logging():
Expand Down
36 changes: 26 additions & 10 deletions VMManager/VMManager.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,24 @@

# to do : handle exceptions

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

from LabActionsRunner import LabActionsRunner
from LabActionRunner import LabActionRunner

GIT_CLONE_LOC = "./"
VMM_LOGGER = logging.getLogger('VMM')
LOG_FILENAME = 'log/vmmanager.log' # make log name a setting
LOG_FD = open(LOG_FILENAME, 'a')
LOG_FILENAME = '/root/VMManager/log/vmmanager.log' # make log name a setting
LAB_SPEC_LOC = "/scripts/labspec.json"

class LabSpecInvalid(Exception):
def __init__(self, msg):
Exception(self, msg)


# UGLY DUCK PUNCHING: Backporting check_output from 2.7 to 2.6
if "check_output" not in dir(subprocess):
Expand Down Expand Up @@ -65,7 +75,7 @@ def test_lab(lab_src_url, version=None):
# run LabAction Runner
# instantiate the object

def get_build_spec(lab_spec):
def get_build_steps_spec(lab_spec):
return {"build_steps": lab_spec['lab'][u'build_requirements']['platform']['build_steps']}

def get_installer_steps_spec(lab_spec):
Expand All @@ -81,6 +91,7 @@ def repo_exists(repo_name):

def clone_repo(repo_name):
clone_cmd = shlex.split("git clone %s" % lab_src_url)
VMM_LOGGER.debug(clone_cmd)
try:
subprocess.check_call(clone_cmd, stdout=LOG_FD, stderr=LOG_FD)
except Exception, e:
Expand All @@ -89,7 +100,7 @@ def clone_repo(repo_name):
raise e

def pull_repo(repo_name):
pull_cmd = shlex.split("git --git-dir=%s pull" % \
pull_cmd = shlex.split("git --git-dir=%s/.git pull" % \
(GIT_CLONE_LOC + repo_name))
try:
subprocess.check_call(pull_cmd, stdout=LOG_FD, stderr=LOG_FD)
Expand All @@ -110,6 +121,7 @@ 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 @@ -126,26 +138,30 @@ def get_lab_spec(repo_name):

lab_spec = get_lab_spec(repo_name)

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

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


def setup_logging():
VMM_LOGGER.setLevel(logging.DEBUG) # make log level a setting
# Add the log message handler to the logger
handler = logging.handlers.TimedRotatingFileHandler(
myhandler = TimedRotatingFileHandler(
LOG_FILENAME, when='midnight', backupCount=5)

formatter = logging.Formatter(
'%(asctime)s - %(name)s - %(levelname)s - %(message)s',
datefmt='%Y-%m-%d %I:%M:%S %p')
handler.setFormatter(formatter)
VMM_LOGGER.addHandler(handler)
myhandler.setFormatter(formatter)
VMM_LOGGER.addHandler(myhandler)


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

if __name__ == "__main__":
test_lab("https://github.com/nrchandan/vlab-computer-programming")
print cpu_load()
print mem_usage()
2 changes: 2 additions & 0 deletions VMUtils.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ def get_disk_space(disk_soft):
return (disk_soft, disk_hard)

def convert_to_megs(value):
if not value:
return 0
m = re.match(r'([0-9]+)\s*([a-zA-Z]+)', value)
if m == None:
return 0
Expand Down

0 comments on commit c31d78c

Please sign in to comment.