Пример #1
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))
Пример #2
0
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")
Пример #3
0
def test_lab(lab_src_url, version=None):
    # check out the source with version provided
        # is repo already exists? if yes, then do a git pull
        # else clone the repo
    # get the labspec from /scripts/lab_spec.json
    # get the appropriate the actions from lab_spec.json
    # run LabAction Runner
        # instantiate the object
    e = EnvSetUp.Instance()
    git = GitCommands()
    logger.info("Environment http_proxy = %s" % os.environ["http_proxy"])
    logger.info("Environment https_proxy = %s" % os.environ["https_proxy"])

    def fill_aptconf():

        try:
            http_proxy = os.environ["http_proxy"]
            https_proxy = os.environ["https_proxy"]
            http_cmd = r'echo "Acquire::http::Proxy \"%s\";"%s' % (http_proxy, '>>/etc/apt/apt.conf')
            https_cmd = r'echo "Acquire::https::Proxy \"%s\";"%s' % (https_proxy, '>>/etc/apt/apt.conf')
            (ret_code, output) = execute_command(http_cmd)
            (ret_code, output) = execute_command(https_cmd)
        except Exception, e:
            logger.error("Writing to /etc/apt/apt.conf failed with error: %s"
                         % (str(e)))
            raise e
Пример #4
0
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")
Пример #5
0
 def __init__(self):
     self.state = State.Instance()
     self.lab_spec = {}
     self.labmgr = LabManager()
     self.vmpoolmgr = VMPoolManager()
     self.git = GitCommands()
     self.deploy_record = Record()
Пример #6
0
    def __init__(self):
        # check if the key_file exists, else throw an error!
        # The key file should not be checked in, but the deployer has to
        # manually copy and configure the correct location
        if not os.path.isfile(self.key_file_path):
            raise AWSKeyFileNotFound("Given key file not found!: %s" %
                                     self.key_file_path)

        # deduce the key file name from the key file path..
        # assuming the key file ends with a .pem extension - otherwise this
        # won't work!
        self.key_name = self.key_file_path.split('/')[-1].split('.pem')[0]

        self.connection = self.create_connection()
        self.env = EnvSetUp.Instance()
        self.git = GitCommands()
        self.time_before_next_retry = 5
Пример #7
0
 def __init__(self):
     self.env = EnvSetUp.Instance()
     self.git = GitCommands()
Пример #8
0
class LabManager:
    env = None
    git = None

    def __init__(self):
        self.env = EnvSetUp.Instance()
        self.git = GitCommands()

    def get_lab_reqs(self, lab_src_url, version=None):
        logger.debug("Will return lab spec")
        try:
            repo_name = self.git.construct_repo_name(lab_src_url)
            if version is None:
                version = "master"
            if self.git.repo_exists(repo_name):
                self.git.reset_repo(repo_name)
                self.git.checkout_version(repo_name, version)
                self.git.pull_repo(repo_name, version)
            else:
                self.git.clone_repo(lab_src_url, repo_name)
                self.git.checkout_version(repo_name, version)

            return self.git.get_lab_spec(repo_name)
        except Exception, e:
            logger.error("Error: %s" % str(e))
            raise e
Пример #9
0
 def __init__(self):
     self.env = EnvSetUp.Instance()
     self.git = GitCommands()
     self.time_before_next_retry = 5
Пример #10
0
 def __init__(self):
     self.git = GitCommands()
     self.time_before_next_retry = 5
Пример #11
0
 def __init__(self):
     self.env = EnvSetUp.Instance()
     self.git = GitCommands()
Пример #12
0
class LabManager:
    env = None
    git = None

    def __init__(self):
        self.env = EnvSetUp.Instance()
        self.git = GitCommands()

    def get_lab_reqs(self, lab_src_url, version=None):
        logger.debug("Will return lab spec")
        try:
            repo_name = self.git.construct_repo_name(lab_src_url)
            if version is None:
                version = "master"
            if self.git.repo_exists(repo_name):
                self.git.reset_repo(repo_name)
                self.git.checkout_version(repo_name, version)
                self.git.pull_repo(repo_name)
            else:
                self.git.clone_repo(lab_src_url, repo_name)
                self.git.checkout_version(repo_name, version)

            return self.git.get_lab_spec(repo_name)
        except Exception, e:
            logger.error("Error: %s" % str(e))
            raise e