def setUpClass(cls): super(UITestCase, cls).setUpClass() keystone_client = ksclient.Client(username=cfg.common.user, password=cfg.common.password, tenant_name=cfg.common.tenant, auth_url=cfg.common.keystone_url) cls.murano_client = mclient('1', endpoint=cfg.common.murano_url, token=keystone_client.auth_token) glance_endpoint = keystone_client.service_catalog.url_for( service_type='image', endpoint_type='publicURL') glance = gclient('1', endpoint=glance_endpoint, token=keystone_client.auth_token) image_list = [] for i in glance.images.list(): image_list.append(i) cls.demo_image = cls.get_image_name('demo', image_list) cls.linux_image = cls.get_image_name('linux', image_list) cls.windows_image = cls.get_image_name('windows', image_list) cls.keypair = cfg.common.keypair_name cls.asp_git_repository = cfg.common.asp_git_repository cls.elements = ConfigParser.RawConfigParser() cls.elements.read('common.ini') cls.logger = logging.getLogger(__name__)
def setUpClass(cls): super(MuranoDeploy, cls).setUpClass() if not cfg.murano.deploy: raise cls.skipException("Murano deployment tests are disabled") glance_endpoint = cls.auth.service_catalog.url_for(service_type="image", endpoint_type="publicURL") glance = gclient("1", endpoint=glance_endpoint, token=cls.auth.auth_token) image_list = [] for i in glance.images.list(): image_list.append(i) cls.demo_image = cls.get_image_name("demo", image_list) cls.linux_image = cls.get_image_name("linux", image_list) cls.windows_image = cls.get_image_name("windows", image_list)
def _get_glanceclient(self, sess, version='2'): return gclient(version, session=sess)
def setUpClass(cls): super(UITestCase, cls).setUpClass() keystone_client = ksclient.Client(username=cfg.common.user, password=cfg.common.password, tenant_name=cfg.common.tenant, auth_url=cfg.common.keystone_url) cls.murano_client = mclient('1', endpoint=cfg.common.murano_url, token=keystone_client.auth_token) glance_endpoint = keystone_client.service_catalog.url_for( service_type='image', endpoint_type='publicURL') glance = gclient('1', endpoint=glance_endpoint, token=keystone_client.auth_token) cls.headers = {'X-Auth-Token': keystone_client.auth_token} image_list = [] for i in glance.images.list(): image_list.append(i) cls.demo_image = cls.get_image_name('demo', image_list) cls.linux_image = cls.get_image_name('linux', image_list) cls.windows_image = cls.get_image_name('windows', image_list) cls.keypair = cfg.common.keypair_name cls.asp_git_repository = cfg.common.asp_git_repository cls.tomcat_repository = cfg.common.tomcat_repository cls.elements = ConfigParser.RawConfigParser() cls.elements.read('common.ini') cls.logger = logging.getLogger(__name__) cls.location = os.path.realpath( os.path.join(os.getcwd(), os.path.dirname(__file__))) def archive_app(app_name): __folderpath__ = os.path.join(cls.location, "{0}".format(app_name)) __rootlen__ = len(__folderpath__) + 1 with zipfile.ZipFile(os.path.join( cls.location, "{0}.zip".format(app_name)), "w") as zf: for dirname, _, files in os.walk(__folderpath__): for filename in files: fn = os.path.join(dirname, filename) zf.write(fn, fn[__rootlen__:]) archive_app('PostgreSQL') archive_app('AppForUploadTest') def upload_package(package_name, body): files = {'%s' % package_name: open( os.path.join(cls.location, 'PostgreSQL.zip'), 'rb')} post_body = {'JsonString': json.dumps(body)} request_url = '{endpoint}{url}'.format( endpoint=cfg.common.murano_url, url='/v1/catalog/packages') return requests.post(request_url, files=files, data=post_body, headers=cls.headers).json()['id'] cls.postgre_id = upload_package( 'PostgreSQL', {"categories": ["Web"], "tags": ["tag"]})
def config(pwd, path_to_file): ################################################# # Authentication info collection # ################################################# # It opens the chosen file as F with open("{}".format(path_to_file), 'rt') as F: # It read the file line by line lines = F.readlines() # It declares an empty dict for the authentication info auth_dict = {} for line in lines: # For every line if "export" is in it it saves the line differentiating between key and value if "export" in line: splitted_line = line.split("export ")[1] # If the password is present it saves it and split it accordingly if "export OS_PASSWORD="******"OS_PASSWORD" try: value = line.split("'")[1] auth_dict[key] = value except: print( ">> Run 'htv -s' or 'htv --shadow' first because the application requires the openstack" " password in order to run") sys.exit() # For all the other values it just splits it by "=" and add the keys, values to the auth dict else: key = splitted_line.split("=")[0] value = splitted_line.split("=")[1] auth_dict[key] = value # It deletes the '\n' and the ' " ' for key, value in auth_dict.items(): value = value.strip('\n').replace('"', '') auth_dict[key] = value # It changes and saves these variables that can be different depending on the openrc version (V3 or V2) if 'USER_DOMAIN_NAME' not in auth_dict: auth_dict['USER_DOMAIN_NAME'] = "Default" if 'OS_PROJECT_ID' not in auth_dict: auth_dict['OS_PROJECT_ID'] = auth_dict['OS_TENANT_ID'] if 'PROJECT_DOMAIN_NAME' not in auth_dict: auth_dict['PROJECT_DOMAIN_NAME'] = "Default" auth_dict['OS_IDENTITY_API_VERSION'] = int(auth_dict['OS_IDENTITY_API_VERSION']) ################################################# # Password decryption # ################################################# # It gets the key for the decryption e_key = get_key() fernet = Fernet(e_key) # It takes the password variable from the auth_dict or from 'pwd' variable if it exists password = pwd if pwd else (auth_dict['OS_PASSWORD']).encode() # It decrypts it using the key try: decrypted_pwd = fernet.decrypt(password) password = decrypted_pwd.decode() except: keygen() password = input(">> Insert the password for the openrc file '{}': ".format(path_to_file)) pwd = password.encode() e_key = get_key() fernet = Fernet(e_key) pwd = fernet.encrypt(pwd) password_line = "export OS_PASSWORD={}".format(pwd) write_pwd(password_line, path_to_file) # It saves the decrypted openstack password auth_dict['OS_PASSWORD'] = password ################################################# # Authentication # ################################################# # Necessary authentication info loader = loading.get_plugin_loader('password') auth = loader.load_from_options( auth_url=auth_dict['OS_AUTH_URL'], username=auth_dict['OS_USERNAME'], password=auth_dict['OS_PASSWORD'], project_id=auth_dict['OS_PROJECT_ID'], user_domain_name=auth_dict['USER_DOMAIN_NAME'], project_domain_name=auth_dict['PROJECT_DOMAIN_NAME']) # Session authentication sess = session.Session(auth=auth) ################################################# # Openstack Clients # ################################################# try: # GLANCE client try: glance = gclient(auth_dict['OS_IDENTITY_API_VERSION'], session=sess) except: glance = gclient(str(int(auth_dict['OS_IDENTITY_API_VERSION']) - 1), session=sess) # NOVA client try: nova = novclient.Client(auth_dict['OS_IDENTITY_API_VERSION'], session=sess) except: nova = novclient.Client(str(int(auth_dict['OS_IDENTITY_API_VERSION']) - 1), session=sess) # KEYSTONE client keystone = kclient.Client(session=sess, include_metadata=True) # NEUTRON client neutron = neuclient.Client(session=sess) # CINDER client cinder = cinclient.Client(auth_dict['OS_IDENTITY_API_VERSION'], session=sess) clients = [glance, nova, neutron, cinder, keystone] return clients except: printout(">> The Openstack server is down, the program will now exit", RED) sys.exit()