示例#1
0
 def __init__(self):
     self.state = State.Instance()
     self.lab_spec = {}
     self.labmgr = LabManager()
     self.vmpoolmgr = VMPoolManager()
     self.git = GitCommands()
     self.deploy_record = Record()
示例#2
0
 def setUp(self):
     self.git = GitCommands()
     self.lab = LabManager()
     lab_src_url = "https://github.com/Virtual-Labs/computer-programming-iiith.git"
     self.lab_spec = self.lab.get_lab_reqs(lab_src_url)
     self.lab_repo_name = self.git.construct_repo_name(lab_src_url)
     self.adapter = CentOSBridgeVZAdapter()
     test_logger.debug("setUp(): lab_src_url = %s, lab_repo_name = %s" % (lab_src_url, self.lab_repo_name))
示例#3
0
 def test_labmgr_test_lab():
     vmmgrurl = "http://172.16.0.2"
     lab_src_url = \
         "https://github.com/Virtual-Labs/computer-programming-iiith.git"
     port = "9089"
     revision_tag = None
     labmgr = LabManager()
     try:
         (ret_val, ret_str) = labmgr.test_lab(vmmgrurl, port, lab_src_url,
                                              revision_tag)
     except Exception, e:
         logger.error("test_lab(); Test failed with error: " + str(e))
示例#4
0
文件: controller.py 项目: vlead/ovpl
 def test_labmgr_test_lab():
     vmmgrurl = "http://172.16.0.2"
     lab_src_url = \
         "https://github.com/Virtual-Labs/computer-programming-iiith.git"
     port = "9089"
     revision_tag = None
     labmgr = LabManager()
     try:
         (ret_val, ret_str) = labmgr.test_lab(vmmgrurl,
                                              port,
                                              lab_src_url,
                                              revision_tag)
     except Exception, e:
         logger.error("test_lab(); Test failed with error: " + str(e))
示例#5
0
文件: controller.py 项目: vlead/ovpl
 def __init__(self):
     self.state = State.Instance()
     self.lab_spec = {}
     self.labmgr = LabManager()
     self.vmpoolmgr = VMPoolManager()
     self.git = GitCommands()
     self.deploy_record = Record()
class TestCentOSVZAdapter(unittest.TestCase):
    base_ip = "10.2.56.230"
    lab_spec = ""
    vm_id = ""
    lab_repo_name = ""

    def setUp(self):
        self.git = GitCommands()
        self.lab = LabManager()
        lab_src_url = "https://github.com/Virtual-Labs/computer-programming-iiith.git"
        self.lab_spec = self.lab.get_lab_reqs(lab_src_url)
        self.lab_repo_name = self.git.construct_repo_name(lab_src_url)
        self.adapter = CentOSVZAdapter()
        test_logger.debug("setUp(): lab_src_url = %s, lab_repo_name = %s" %
                          (lab_src_url, self.lab_repo_name))

    def tearDown(self):
        test_logger.debug("tearDown(), vm_id = %s" % str(self.vm_id))
        self.adapter.destroy_vm(self.vm_id)

    def test_create_vm(self):
        test_logger.debug("test_create_vm()")
        (status, self.vm_id) = self.adapter.create_vm(self.lab_spec)
        test_logger.debug("test_create_vm(): status = %s, vm_id = %s" %
                          (str(status), str(self.vm_id)))
        check_cmd = "ssh root@%s 'vzlist %s'" % (self.base_ip, self.vm_id)
        test_logger.debug("test_create_vm(): check_cmd = %s" % check_cmd)
        (return_code, output) = execute_command(check_cmd)
        test_logger.debug("test_create_vm(): return_code = %s" %
                          str(return_code))
        self.assertEqual(return_code, 0)
        test_logger.debug("test_create_vm(): Test passed")

    def test_init_vm(self):
        test_logger.debug("test_create_vm()")
        (status, self.vm_id) = self.adapter.create_vm(self.lab_spec)
        test_logger.debug("test_init_vm(): vm_id = %s" % str(self.vm_id))
        (status, result) = self.adapter.init_vm(self.vm_id, self.lab_repo_name)
        test_logger.debug("test_init_vm(): status = %s" % status)
        self.assertTrue(status)
        test_logger.debug("test_init_vm(): Test passed")

    def test_vm_mgr_running(self):
        (status, self.vm_id) = self.adapter.create_vm(self.lab_spec)
        (status, result) = self.adapter.init_vm(self.vm_id, self.lab_repo_name)
        vm_ip = result['vm_ip']
        vm_port = result['vm_port']
        url = "http://%s:%s/api/1.0/test-lab" % (vm_ip, str(vm_port))
        test_logger.debug("VMMgr URL: %s" % url)

        for i in (1, 2, 4, 8, 16):
            time.sleep(i)
            try:
                response = requests.get(url)
                test_logger.debug("response = %s for ith time = %d" %
                                  response, i)
            except Exception:
                pass
            self.assertEqual(response.status_code, 200)
            test_logger.debug("test_vm_mgr_running(): Test passed")
class TestCentOSVZAdapter(unittest.TestCase):
    base_ip = "10.2.56.230"
    lab_spec = ""
    vm_id = ""
    lab_repo_name = ""

    def setUp(self):
        self.git = GitCommands()
        self.lab = LabManager()
        lab_src_url = "https://github.com/Virtual-Labs/computer-programming-iiith.git"
        self.lab_spec = self.lab.get_lab_reqs(lab_src_url)
        self.lab_repo_name = self.git.construct_repo_name(lab_src_url)
        self.adapter = CentOSVZAdapter()
        test_logger.debug("setUp(): lab_src_url = %s, lab_repo_name = %s" %
                          (lab_src_url, self.lab_repo_name))

    def tearDown(self):
        test_logger.debug("tearDown(), vm_id = %s" % str(self.vm_id))
        self.adapter.destroy_vm(self.vm_id)

    def test_create_vm(self):
        test_logger.debug("test_create_vm()")
        (status, self.vm_id) = self.adapter.create_vm(self.lab_spec)
        test_logger.debug("test_create_vm(): status = %s, vm_id = %s" %
                          (str(status), str(self.vm_id)))
        check_cmd = "ssh root@%s 'vzlist %s'" % (self.base_ip, self.vm_id)
        test_logger.debug("test_create_vm(): check_cmd = %s" % check_cmd)
        (return_code, output) = execute_command(check_cmd)
        test_logger.debug("test_create_vm(): return_code = %s" %
                          str(return_code))
        self.assertEqual(return_code, 0)
        test_logger.debug("test_create_vm(): Test passed")

    def test_init_vm(self):
        test_logger.debug("test_create_vm()")
        (status, self.vm_id) = self.adapter.create_vm(self.lab_spec)
        test_logger.debug("test_init_vm(): vm_id = %s" % str(self.vm_id))
        (status, result) = self.adapter.init_vm(self.vm_id, self.lab_repo_name)
        test_logger.debug("test_init_vm(): status = %s" % status)
        self.assertTrue(status)
        test_logger.debug("test_init_vm(): Test passed")

    def test_vm_mgr_running(self):
        (status, self.vm_id) = self.adapter.create_vm(self.lab_spec)
        (status, result) = self.adapter.init_vm(self.vm_id, self.lab_repo_name)
        vm_ip = result['vm_ip']
        vm_port = result['vm_port']
        url = "http://%s:%s/api/1.0/test-lab" % (vm_ip, str(vm_port))
        test_logger.debug("VMMgr URL: %s" % url)

        for i in (1, 2, 4, 8, 16):
            time.sleep(i)
            try:
                response = requests.get(url)
                test_logger.debug("response = %s for ith time = %d" % response,
                                  i)
            except Exception:
                pass
            self.assertEqual(response.status_code, 200)
            test_logger.debug("test_vm_mgr_running(): Test passed")
示例#8
0
    def setUp(self):
        # hardcoded paths are not flexible. this will only work if I run it from
        # the top-level of ovpl directory..
        self.lab_spec = json.loads(open("scripts/labspec.json").read())

        self.adapter = AWSAdapter()
        self.lab = LabManager()
        
        # the source code of the lab to be tested for deployment is copied
        # in /root/labs folder. here, ovpl is itself treated as a lab.
        self.repo_name = "ovpl"
        self.lab.get_lab_reqs("https://github.com/vlead/ovpl.git")

        # VM creation is part of setup since this is the requirement for every
        # test case.
        result = self.adapter.create_vm(self.lab_spec)
        self.vm_id = result[1]
        test_logger.debug("setup(): vm_id = %s" % self.vm_id)
示例#9
0
文件: controller.py 项目: vlead/ovpl
class Controller:
    state = None
    lab_spec = None
    lab_deployment_record = None
    labmgr = None
    vmpoolmgr = None
    git = None
    deploy_recod = None

    def __init__(self):
        self.state = State.Instance()
        self.lab_spec = {}
        self.labmgr = LabManager()
        self.vmpoolmgr = VMPoolManager()
        self.git = GitCommands()
        self.deploy_record = Record()

    def test_lab(self, current_user, lab_id, lab_src_url, revision_tag=None):
        logger.debug("test_lab() for lab ID %s, git url %s, current user %s"
                     % (lab_id, lab_src_url, current_user))
        try:
            '''
            record_list = self.state.read_record(lab_src_url)
            if record_list:
                msg = "Lab with the url = %s is already deployed" % lab_src_url
                logger.debug(msg)
                return msg
            '''
            # Get lab sources and from it the deployment specification
            # of the lab
            self.lab_spec = self.labmgr.get_lab_reqs(lab_src_url,
                                                     revision_tag)
            self.update_lab_spec(lab_id, lab_src_url, revision_tag)

            # create a VM to deploy the lab
            logger.debug("test_lab(); invoking create_vm() on vmpoolmgr")
            self.deploy_record.record = self.vmpoolmgr.create_vm(self.lab_spec)

            logger.debug("test_lab(): Returned from VMPool = %s" %
                         (str(self.deploy_record.record)))
            ip = self.deploy_record.record['vm_info']['vm_ip']
            port = self.deploy_record.record['vm_info']['vm_port']
            vmmgrurl = "http://" + ip
            lab_id = self.deploy_record.record['lab_spec']['lab_id']
            logger.debug("test_lab(): vmmgrurl = %s" % (vmmgrurl))

            # deploy the lab on the newly created container.
            try:
                (ret_val, ret_str) = self.labmgr.test_lab(vmmgrurl,
                                                          port,
                                                          lab_src_url,
                                                          revision_tag)
                if(ret_val):
                    self.update_deploy_record(current_user)
                    self.state.save(self.deploy_record.record)
                    logger.info("test_lab(): test succcessful, ip = %s" % ip)

                    if(base_config.ADS_USING_HOOKS):
                        domain_name = self.register_lab(lab_id, ip)
                        return domain_name + "\n" + "(Note : Very soon you will be allowed to access lab using given domain name)"
                    else:
                        return ip
                else:
                    logger.error("test_lab(); Test failed with error:" +
                                 str(ret_str))
                    return "Test failed: See log file for errors"
            except Exception, e:
                logger.error("test_lab(); Test failed with error: %s" % str(e))
                return "Test failed: See log file for errors"
        except Exception, e:
            logger.error("test_lab(): Test failed with error: %s" % str(e))
            return "Test failed: See log file for errors"
示例#10
0
class TestAWSAdapter(unittest.TestCase):
    # common setup for all test cases
    def setUp(self):
        # hardcoded paths are not flexible. this will only work if I run it from
        # the top-level of ovpl directory..
        self.lab_spec = json.loads(open("scripts/labspec.json").read())

        self.adapter = AWSAdapter()
        self.lab = LabManager()
        
        # the source code of the lab to be tested for deployment is copied
        # in /root/labs folder. here, ovpl is itself treated as a lab.
        self.repo_name = "ovpl"
        self.lab.get_lab_reqs("https://github.com/vlead/ovpl.git")

        # VM creation is part of setup since this is the requirement for every
        # test case.
        result = self.adapter.create_vm(self.lab_spec)
        self.vm_id = result[1]
        test_logger.debug("setup(): vm_id = %s" % self.vm_id)

    # set up for testing VMManager service running
    def setup_test_vm_mgr_running(self):
        #  two test cases are dependent on running init_vm() and since
        #  tearDown() happens after every test case, this ensures
        #  that init_vm() is available when required.
        test_logger.debug("inside setup for test_vm_mgr_running()")

        result = self.adapter.init_vm(self.vm_id, self.repo_name)
        return result

    def tearDown(self):
        test_logger.debug("tearDown(): destroying vm : %s" % self.vm_id)
        self.adapter.destroy_vm(self.vm_id)

    def test_create_vm(self):
        vm_ip = self.adapter.get_vm_ip(self.vm_id)
        instance = self.adapter.get_instance(self.vm_id)
        test_logger.debug("test_create_vm(): vm_ip : %s for new VM" % vm_ip)

        # after an instance is created, it should be in one of the following
        # states:
        # 0: instance creation pending, 16: instance running
        self.assertIn(instance.state_code, (0, 16))

    def test_init_vm(self):
        test_logger.debug("in init_vm")

        result = self.setup_test_vm_mgr_running()
        test_logger.debug("test_init_vm(): result : %s" % result[0])

        self.assertTrue(result[0])

    def test_vm_mgr_running(self):
        test_logger.debug("running third test case")
        #
        result = self.setup_test_vm_mgr_running()

        vm_ip = result[1]['vm_ip']
        test_logger.debug("test_vm_mgr_running(): vm ip : %s" % vm_ip)

        vm_mgr_port = result[1]['vm_port']
        test_logger.debug("test_vm_mgr_running(): vm manager port : %s" %
                          vm_mgr_port)

        vm_mgr_url = "http://{0}:{1}/api/1.0/test-lab".\
            format(vm_ip, vm_mgr_port)

        response = requests.get(vm_mgr_url)
        self.assertEqual(response.status_code, 200)
示例#11
0
class Controller:
    state = None
    lab_spec = None
    lab_deployment_record = None
    labmgr = None
    vmpoolmgr = None
    git = None
    deploy_recod = None

    def __init__(self):
        self.state = State.Instance()
        self.lab_spec = {}
        self.labmgr = LabManager()
        self.vmpoolmgr = VMPoolManager()
        self.git = GitCommands()
        self.deploy_record = Record()

    def test_lab(self, current_user, lab_id, lab_src_url, revision_tag=None):
        logger.debug("test_lab() for lab ID %s, git url %s, current user %s" %
                     (lab_id, lab_src_url, current_user))
        try:
            '''
            record_list = self.state.read_record(lab_src_url)
            if record_list:
                msg = "Lab with the url = %s is already deployed" % lab_src_url
                logger.debug(msg)
                return msg
            '''
            # Get lab sources and from it the deployment specification
            # of the lab
            self.lab_spec = self.labmgr.get_lab_reqs(lab_src_url, revision_tag)
            self.update_lab_spec(lab_id, lab_src_url, revision_tag)

            # create a VM to deploy the lab
            logger.debug("test_lab(); invoking create_vm() on vmpoolmgr")
            self.deploy_record.record = self.vmpoolmgr.create_vm(self.lab_spec)

            logger.debug("test_lab(): Returned from VMPool = %s" %
                         (str(self.deploy_record.record)))
            ip = self.deploy_record.record['vm_info']['vm_ip']
            port = self.deploy_record.record['vm_info']['vm_port']
            vmmgrurl = "http://" + ip
            lab_id = self.deploy_record.record['lab_spec']['lab_id']
            logger.debug("test_lab(): vmmgrurl = %s" % (vmmgrurl))

            # deploy the lab on the newly created container.
            try:
                (ret_val,
                 ret_str) = self.labmgr.test_lab(vmmgrurl, port, lab_src_url,
                                                 revision_tag)
                if (ret_val):
                    self.update_deploy_record(current_user)
                    self.state.save(self.deploy_record.record)
                    logger.info("test_lab(): test succcessful, ip = %s" % ip)

                    if (base_config.ADS_USING_HOOKS):
                        domain_name = self.register_lab(lab_id, ip)
                        return domain_name + "\n" + "(Note : Very soon you will be allowed to access lab using given domain name)"
                    else:
                        return ip
                else:
                    logger.error("test_lab(); Test failed with error:" +
                                 str(ret_str))
                    return "Test failed: See log file for errors"
            except Exception, e:
                logger.error("test_lab(); Test failed with error: %s" % str(e))
                return "Test failed: See log file for errors"
        except Exception, e:
            logger.error("test_lab(): Test failed with error: %s" % str(e))
            return "Test failed: See log file for errors"