def test_get_auth(self): auth_lines = [ """id = a1; type = InfrastructureManager; username = someuser; password = somepass """, """id = ''; type = VMRC; username = someuser; password = somepass; """ ] auth = Authentication(Authentication.read_auth_data(auth_lines)) auth_data = auth.getAuthInfoByID("a1") self.assertEqual(auth_data, [{ 'id': 'a1', 'password': "******", 'type': 'InfrastructureManager', 'username': '******' }]) auth_data = auth.getAuthInfo("VMRC") self.assertEqual(auth_data, [{ 'id': '', 'password': "******", 'type': 'VMRC', 'username': '******' }]) auth_lines = [ """id = 1a; type = InfrastructureManager; username = someuser; password = somepass """ ] with self.assertRaises(Exception) as ex: auth = Authentication(Authentication.read_auth_data(auth_lines)) self.assertEqual("Incorrect value in auth item id: 1a", str(ex.exception))
def setUpClass(cls): cls.server = xmlrpclib.ServerProxy( "http://" + HOSTNAME + ":" + str(TEST_PORT), allow_none=True) tests_path = os.path.dirname(os.path.realpath(__file__)) auth_file = tests_path + '/../auth.dat' cls.auth_data = Authentication.read_auth_data(auth_file) cls.inf_id = 0
def setUpClass(cls): cls.server = xmlrpclib.ServerProxy("http://" + HOSTNAME + ":" + str(TEST_PORT), allow_none=True) tests_path = os.path.dirname(os.path.realpath(__file__)) auth_file = tests_path + '/../auth.dat' cls.auth_data = Authentication.read_auth_data(auth_file)
def get_auth_header(): """ Get the Authentication object from the AUTHORIZATION header replacing the new line chars. """ auth_data = bottle.request.headers[ 'AUTHORIZATION'].replace(AUTH_NEW_LINE_SEPARATOR, "\n") auth_data = auth_data.split(AUTH_LINE_SEPARATOR) return Authentication(Authentication.read_auth_data(auth_data))
def get_credentials(): if AUTH_FILE is None: logging.error("The authentication file is mandatory") auth_data = Authentication.read_auth_data(AUTH_FILE) if auth_data is None: logging.error("The authentication file has incorrect format.") return auth_data
def test_auth_read(self): auth_lines = [ """id = a1; type = InfrastructureManager; username = someuser; password = somepass """, """id = a2; type = VMRC; username = someuser; password = somepass; """, """id = a3; type = OpenNebula; username = someuser; password = "******" """, """id = a4; type = EC2; username = someuser; password = '******' """ ] auth = Authentication.read_auth_data(auth_lines) self.assertEqual(auth, [{ 'id': 'a1', 'password': "******", 'type': 'InfrastructureManager', 'username': '******' }, { 'id': 'a2', 'password': "******", 'type': 'VMRC', 'username': '******' }, { 'id': 'a3', 'password': "******", 'type': 'OpenNebula', 'username': '******' }, { 'id': 'a4', 'password': '******', 'type': 'EC2', 'username': '******' }]) tests_path = os.path.dirname(os.path.abspath(__file__)) shutil.copyfile(os.path.join(tests_path, "../files/privatekey.pem"), "/tmp/privatekey.pem") auth = Authentication( Authentication.read_auth_data( os.path.join(tests_path, "../files/auth.dat"))) auth_data = auth.getAuthInfoByID("occi") self.assertEqual(auth_data[0]['proxy'][:37], "-----BEGIN RSA PRIVATE KEY-----\nMIIEo") os.unlink("/tmp/privatekey.pem")
def get_auth_header(): """ Get the Authentication object from the AUTHORIZATION header replacing the new line chars. """ # Initialize REST_URL global REST_URL if REST_URL is None: REST_URL = get_full_url("") auth_header = bottle.request.headers['AUTHORIZATION'] if Config.SINGLE_SITE: if auth_header.startswith("Basic "): auth_data = base64.b64decode(auth_header[6:]) user_pass = auth_data.split(":") im_auth = { "type": "InfrastructureManager", "username": user_pass[0], "password": user_pass[1] } single_site_auth = { "type": Config.SINGLE_SITE_TYPE, "host": Config.SINGLE_SITE_AUTH_HOST, "username": user_pass[0], "password": user_pass[1] } return Authentication([im_auth, single_site_auth]) elif auth_header.startswith("Bearer "): token = auth_header[7:].strip() im_auth = { "type": "InfrastructureManager", "username": "******", "token": token } if Config.SINGLE_SITE_TYPE == "OpenStack": single_site_auth = { "type": Config.SINGLE_SITE_TYPE, "host": Config.SINGLE_SITE_AUTH_HOST, "username": "******", "tenant": "oidc", "password": token } else: single_site_auth = { "type": Config.SINGLE_SITE_TYPE, "host": Config.SINGLE_SITE_AUTH_HOST, "token": token } return Authentication([im_auth, single_site_auth]) auth_data = auth_header.replace(AUTH_NEW_LINE_SEPARATOR, "\n") auth_data = auth_data.split(AUTH_LINE_SEPARATOR) return Authentication(Authentication.read_auth_data(auth_data))
def connect(): if AUTH_FILE is None: logging.error("The authentication file is mandatory") auth_data = Authentication.read_auth_data(AUTH_FILE) if auth_data is None: logging.error("The authentication file has incorrect format.") if XMLRCP_SSL: logging.debug("Client safely connecting with: " + IM_URL) from springpython.remoting.xmlrpc import SSLClient server = SSLClient(IM_URL, XMLRCP_SSL_CA_CERTS) else: logging.debug("Client connecting with: " + IM_URL) server = xmlrpclib.ServerProxy(IM_URL,allow_none=True) return auth_data, server
def test_get_auth(self): auth_lines = [ """id = 1; type = InfrastructureManager; username = someuser; password = somepass """, """id = 2; type = VMRC; username = someuser; password = somepass; """ ] auth = Authentication(Authentication.read_auth_data(auth_lines)) auth_data = auth.getAuthInfoByID("1") self.assertEqual(auth_data, [{ 'id': '1', 'password': "******", 'type': 'InfrastructureManager', 'username': '******' }]) auth_data = auth.getAuthInfo("VMRC") self.assertEqual(auth_data, [{ 'id': '2', 'password': "******", 'type': 'VMRC', 'username': '******' }])
def setUpClass(cls): cls.server = ServerProxy("http://" + HOSTNAME + ":" + str(TEST_PORT), allow_none=True) cls.auth_data = Authentication.read_auth_data(AUTH_FILE) cls.inf_id = 0
def setUpClass(cls): cls.server = xmlrpclib.ServerProxy( "http://" + HOSTNAME + ":" + str(TEST_PORT), allow_none=True) cls.auth_data = Authentication.read_auth_data(AUTH_FILE) cls.inf_id = 0
import time import logging import logging.config sys.path.append("..") from IM.CloudInfo import CloudInfo from IM.auth import Authentication from radl import radl_parse from IM.VirtualMachine import VirtualMachine from IM.VMRC import VMRC from IM.InfrastructureInfo import InfrastructureInfo TESTS_PATH = '/home/micafer/codigo/git_im/im/test' AUTH_FILE = TESTS_PATH + '/auth.dat' auth = Authentication(Authentication.read_auth_data(AUTH_FILE)) cloud_list = dict([(c.id, c.getCloudConnector()) for c in CloudInfo.get_cloud_list(auth)]) class TestConnectors(unittest.TestCase): """ Class to test the IM connectors """ vm_list = [] """ List of VMs launched in the test """ # connectors_to_test = "all" connectors_to_test = ["fogbow"] """ Specify the connectors to test: "all": All the connectors specified in the auth file or a list with the IDs"""
import unittest, time import logging, logging.config from IM.CloudInfo import CloudInfo from IM.auth import Authentication from IM.radl import radl_parse from IM.VirtualMachine import VirtualMachine from IM.VMRC import VMRC from IM.InfrastructureInfo import InfrastructureInfo TESTS_PATH = '/home/micafer/codigo/git_im/im/test' AUTH_FILE = TESTS_PATH + '/auth.dat' auth = Authentication(Authentication.read_auth_data(AUTH_FILE)) cloud_list = dict([ (c.id, c.getCloudConnector()) for c in CloudInfo.get_cloud_list(auth) ]) class TestConnectors(unittest.TestCase): """ Class to test the IM connectors """ vm_list = [] """ List of VMs launched in the test """ #connectors_to_test = "all" connectors_to_test = ["kub"] """ Specify the connectors to test: "all": All the connectors specified in the auth file or a list with the IDs""" @classmethod