def the_networks_are_connected_to_instance(step): # Get Server list from Nova raw_response = world.nova_request.get_server_list() assert_equal(raw_response.status, 200, "Error to obtain Server list. HTTP status code is not the expected") server_list = raw_httplib_request_to_python_dic(raw_response) # For each tier, check Networks for tier in world.tiers: # Get Server id sub_instance_name = "{}-{}".format(world.instance_name, tier.name) server_id = get_server_id_by_partial_name(server_list, sub_instance_name) # Get Server details raw_response = world.nova_request.get_server_details(server_id) assert_equal(raw_response.status, 200, "Error to obtain Server details. HTTP status code is not the expected") server_details = raw_httplib_request_to_python_dic(raw_response) connected_networks_list = get_network_name_list(server_details) if tier.networks is None or tier.networks == []: assert_equal(len(connected_networks_list), 1, "The number of connected networks is not the expected one") assert_equal(connected_networks_list[0], world.config[PAAS][REGION_DEFAULT_SHAREDNET_PROPERTY], "The connected network is not the configured as Shared-Net") else: assert_equal(len(connected_networks_list), len(tier.networks), "The number of connected networks is not the expected one") for network in tier.networks: assert_in(network.network_name, connected_networks_list, "The network '%s' is not connected to the instance".format(network.network_name))
def _check_metadata_for_tier_in_nova(tier_name, metadata_key, metadata_value): # Request the list of servers to Nova raw_response = world.nova_request.get_server_list() assert_equal( raw_response.status, 200, "Error to obtain the server list. HTTP status code is not the expected" ) body_response = raw_httplib_request_to_python_dic(raw_response) print body_response sub_instance_name = "{}-{}".format(world.instance_name, tier_name) server_id = get_server_id_by_partial_name(body_response, sub_instance_name) assert_is_not_none( server_id, "Server has not been found with sub-name " + sub_instance_name) # Request the server details by server_id raw_response = world.nova_request.get_server_details(server_id) assert_equal( raw_response.status, 200, "Error to obtain server details. HTTP status code is not the expected") body_response = raw_httplib_request_to_python_dic(raw_response) print body_response nid_metadata_value = get_metadata_value(body_response, metadata_key) assert_equals(str(nid_metadata_value), str(metadata_value))
def the_product_is_installed(step, product_name, product_version, tier_name, installator): tier = None for tier_world in world.tiers: if tier_world.name == tier_name: tier = tier_world assert_is_not_none(tier, "Tier with name '{}' not found in created tier list.".format(tier_name)) # > Get from Nova the IP of the Floating VM # >> Get Server list from Nova raw_response = world.nova_request.get_server_list() assert_equal(raw_response.status, 200, "Error to obtain Server list. HTTP status code is not the expected") server_list = raw_httplib_request_to_python_dic(raw_response) sub_instance_name = "{}-{}".format(world.instance_name, tier.name) server_id = get_server_id_by_partial_name(server_list, sub_instance_name) # Get Server details raw_response = world.nova_request.get_server_details(server_id) assert_equal(raw_response.status, 200, "Error to obtain Server details. HTTP status code is not the expected") server_details = raw_httplib_request_to_python_dic(raw_response) connected_networks_list = get_network_name_list(server_details) shared_net = world.config[PAAS][REGION_DEFAULT_SHAREDNET_PROPERTY] assert_in(shared_net, connected_networks_list, "The connected network is not the configured as Shared-Net") ip_internet = get_floating_ip(server_details, shared_net) assert_is_not_none(ip_internet, "Floating IP not found Shared-Net. Is the Internet network added to tier conf?") # Create new Fabric connection fabric_client = FabricUtils(host_name=ip_internet, host_username=world.config[PAAS][CONFIG_SUPPORT_USER], host_password="******", host_ssh_key=world.config[PAAS][CONFIG_SUPPORT_KEY_FILE]) file_name = PRODUCT_FILE_NAME_FORMAT.format(product_name=product_name, product_version=product_version, installator=installator) # Wait for software installation. time.sleep(SLEEP_TIME_CHECKS) # Retry SSH 5 times response = False for i in range(MAX_CHECKS_SSH_CONNECTION): try: response = fabric_client.file_exist(INSTALLATION_PRODUCT_DIR, file_name) print "Connected!" break except Exception as e: print "SSH Connection #%d: %s" % (i, e.message) time.sleep(SLEEP_TIME_CHECKS) assert_true(response, "Softwer is not installed. File not found: '{}/{}".format(INSTALLATION_PRODUCT_DIR, file_name))
def a_list_of_tiers_has_been_defined_with_data(step): """ Create and add tiers to the environment """ world.tiers = [] for row in step.hashes: data = dataset_utils.prepare_data(row) tier = Tier(data.get(NAME), world.image_sdc_aware_id, tier_flavour=world.flavor_id, tier_region=world.region_name) tier.parse_and_add_products(data.get(PRODUCTS)) if NETWORKS in data: # Is Neutron available? i_retrieve_the_service_catalog(step) body_response = raw_httplib_request_to_python_dic(world.response) nova_public_url = get_public_endpoint_url_by_type( body_response, 'network', world.region_name) if nova_public_url is None: raise Exception( "Networks are not available. Region: {}".format( world.region_name)) tier.parse_and_add_networks(data.get(NETWORKS)) world.env_requests.add_tier_environment(world.environment_name, tier)
def the_region_has_at_least_one_flavor(step): """ Check if the flavors list retrieved is not empty and save in World var the first one """ assert_equal( world.response.status, 200, "Error to obtain the images list. HTTP status code is not the expected" ) world.body_nova_response = raw_httplib_request_to_python_dic( world.response) # Check if there are flavors (list > 0) number_of_flavors = get_number_of_flavors(world.body_nova_response) assert_not_equal( number_of_flavors, 0, "There are not flavors in the region " + world.region_name) # Get a image from the list. First, try to get the first 'small' flavor world.flavor_id = get_first_flavor_in_list(world.body_nova_response, 'small') if world.flavor_id is None: # If no 'small' flavor found, get the first in list whatever its type is print "WARNING: No 'small' flavor found. It will get the first one found whatever its type is" world.flavor_id = get_first_flavor_in_list(world.body_nova_response, 'small') assert_not_equal(world.flavor_id, None, "Error to obtain a flavor from the list")
def a_token_requested_by_other_user(step): #Request new token for 'alternate' user keystone_request = KeystoneRequest(world.config[PAAS][KEYSTONE_URL], world.config[PAAS][TENANT_ALT], world.config[PAAS][USER_ALT], world.config[PAAS][PASSWORD_ALT]) token = get_token_value(raw_httplib_request_to_python_dic(keystone_request.get_token())) world.headers.update({'X-Auth-Token': token}) world.headers.update({'Tenant-Id': world.config[PAAS][VDC_ALT]})
def _check_metadata_for_tier_in_nova(tier_name, metadata_key, metadata_value): # Request the list of servers to Nova raw_response = world.nova_request.get_server_list() assert_equal(raw_response.status, 200, "Error to obtain the server list. HTTP status code is not the expected") body_response = raw_httplib_request_to_python_dic(raw_response) sub_instance_name = "{}-{}".format(world.instance_name, tier_name) server_id = get_server_id_by_partial_name(body_response, sub_instance_name) assert_is_not_none(server_id, "Server has not been found with sub-name " + sub_instance_name) # Request the server details by server_id raw_response = world.nova_request.get_server_details(server_id) assert_equal(raw_response.status, 200, "Error to obtain server details. HTTP status code is not the expected") body_response = raw_httplib_request_to_python_dic(raw_response) nid_metadata_value = get_metadata_value(body_response, metadata_key) assert_equals(str(nid_metadata_value), str(metadata_value))
def a_token_requested_by_other_user(step): #Request new token for 'alternate' user keystone_request = KeystoneRequest(world.config[PAAS][KEYSTONE_URL], world.config[PAAS][TENANT_ALT], world.config[PAAS][USER_ALT], world.config[PAAS][PASSWORD_ALT]) token = get_token_value( raw_httplib_request_to_python_dic(keystone_request.get_token())) world.headers.update({'X-Auth-Token': token}) world.headers.update({'Tenant-Id': world.config[PAAS][TENANT_ALT]})
def endpoints_from_service_catalog(step): """ Configure endpoints to be used from service catalog urls instead of config file """ response = world.keystone_request.get_token() body_keystone_response = raw_httplib_request_to_python_dic(response) world.glance_request.glance_url = get_public_endpoint_url_by_type( body_keystone_response, 'image', world.region_name) world.nova_request.nova_url = get_public_endpoint_url_by_type( body_keystone_response, 'compute', world.region_name) world.env_requests.paasmanager_url = get_public_endpoint_url_by_type( body_keystone_response, 'paas', world.region_name) world.inst_requests.paasmanager_url = world.env_requests.paasmanager_url
def endpoints_from_service_catalog(step): """ Configure endpoints to be used from service catalog urls instead of config file """ response = world.keystone_request.get_token() body_keystone_response = raw_httplib_request_to_python_dic(response) world.glance_request.glance_url = get_public_endpoint_url_by_type(body_keystone_response, 'image', world.region_name) world.nova_request.nova_url = get_public_endpoint_url_by_type(body_keystone_response, 'compute', world.region_name) world.env_requests.paasmanager_url = get_public_endpoint_url_by_type(body_keystone_response, 'paas', world.region_name) world.inst_requests.paasmanager_url = world.env_requests.paasmanager_url
def the_region_is_in_image_endpoints_list(step): """ Check if region is in keystone (image service) """ assert_equal(world.response.status, 200, "Error to obtain the token. HTTP status code is not the expected") world.body_keystone_response = raw_httplib_request_to_python_dic(world.response) # Get img list from response (service catalog) if world.region_list is None: world.region_list = get_images_regions(world.body_keystone_response) found = False for region in world.region_list: if world.region_name == region['region']: found = True break assert_true(found, "Region {} not found in services catalog (images)".format(world.region_name))
def the_region_has_sdc_aware_images(step): """ Check if the list retrieved has a SDC-aware image at least and save in World var the first one """ assert_equal(world.response.status, 200, "Error to obtain the images list. HTTP status code is not the expected") world.body_response = raw_httplib_request_to_python_dic(world.response) # Check if there are images (list > 0) number_of_images = get_number_of_images(world.body_response) assert_not_equal(number_of_images, 0, "There are not images in the region " + world.region_name) # Get a image from the list. First, try to get the first Centos img world.image_sdc_aware_id = get_first_image_in_list(world.body_response, name_filter='Cent') if world.image_sdc_aware_id is None: # If no centOS images found, get the first in list whatever its type is print "WARNING: No 'Cent' images found. It will get the first image found whatever its type is" world.image_sdc_aware_id = get_first_image_in_list(world.body_response) assert_not_equal(world.image_sdc_aware_id, None, "Error to obtain a image from the list")
def the_region_has_at_least_one_flavor(step): """ Check if the flavors list retrieved is not empty and save in World var the first one """ assert_equal(world.response.status, 200, "Error to obtain the images list. HTTP status code is not the expected") world.body_nova_response = raw_httplib_request_to_python_dic(world.response) # Check if there are flavors (list > 0) number_of_flavors = get_number_of_flavors(world.body_nova_response) assert_not_equal(number_of_flavors, 0, "There are not flavors in the region " + world.region_name) # Get a image from the list. First, try to get the first 'small' flavor world.flavor_id = get_first_flavor_in_list(world.body_nova_response, 'small') if world.flavor_id is None: # If no 'small' flavor found, get the first in list whatever its type is print "WARNING: No 'small' flavor found. It will get the first one found whatever its type is" world.flavor_id = get_first_flavor_in_list(world.body_nova_response, 'small') assert_not_equal(world.flavor_id, None, "Error to obtain a flavor from the list")
def before_outline(param1, param2, param3, param4): """ Hook: Will be executed before each Scenario Outline. Same behaviour as 'before_each_scenario'""" try: test_files_dir = world.config[ENVIRONMENT][ENVIRONMENT_TESTFILES] print "Writing instance {} details to dir {}".format(world.instance_name, test_files_dir) world.inst_requests.get_instance(world.instance_name) body_env_response = raw_httplib_request_to_python_dic(world.response) if not os.path.exists(test_files_dir): os.makedirs(test_files_dir) file = open(os.path.join(test_files_dir, world.instance_name+"_instance"), 'w') file.write(str(body_env_response)) file.close() except Exception as e: print "WARNING: Instance data cannot be written to test file. {}".format(e.message)
def i_request_the_creation_of_an_instance_using_data(step): """ Create a product instance for the created environment and tiers """ # First, send the request to get the environment on which the instance will be based world.env_requests.get_environment(world.environment_name) body_env_response = raw_httplib_request_to_python_dic(world.response) assert_equal(world.response.status, 200, "Wrong status code received getting environment: %d. Expected: %d. Body content: %s" % (world.response.status, 200, body_env_response)) target_environment = process_environment(body_env_response) # Then, create the instance env_data = dataset_utils.prepare_data(step.hashes[0]) world.instance_name = env_data.get(NAME)+world.region_name.replace("_", "") environment_instance = EnvironmentInstance(world.instance_name, env_data.get(DESCRIPTION), target_environment) world.inst_requests.add_instance(environment_instance)
def the_created_sec_group_has_rules(step, protocol, open_ports): open_ports_list = [] if "" != open_ports: open_ports_list = open_ports.split(' ') # Add default port '22' if protocol == 'TCP': open_ports_list.append('22') # Get Sec. Group from Nova raw_response = world.nova_request.get_security_group_list() assert_equal(raw_response.status, 200, "Error to obtain Sec. Groups list. HTTP status code is not the expected") body_response = raw_httplib_request_to_python_dic(raw_response) rules_tcp_ports_list = get_ports_from_rules(body_response, world.instance_name, protocol=protocol) # Check expected ports assert_equals(len(open_ports_list), len(rules_tcp_ports_list)) for expected_port in open_ports_list: assert_in(expected_port, rules_tcp_ports_list)
def the_region_is_in_image_endpoints_list(step): """ Check if region is in keystone (image service) """ assert_equal( world.response.status, 200, "Error to obtain the token. HTTP status code is not the expected") world.body_keystone_response = raw_httplib_request_to_python_dic( world.response) # Get img list from response (service catalog) if world.region_list is None: world.region_list = get_images_regions(world.body_keystone_response) found = False for region in world.region_list: if world.region_name == region['region']: found = True break assert_true( found, "Region {} not found in services catalog (images)".format( world.region_name))
def i_request_the_creation_of_an_instance_using_data(step): """ Create a product instance for the created environment and tiers """ # First, send the request to get the environment on which the instance will be based world.env_requests.get_environment(world.environment_name) body_env_response = raw_httplib_request_to_python_dic(world.response) assert_equal( world.response.status, 200, "Wrong status code received getting environment: %d. Expected: %d. Body content: %s" % (world.response.status, 200, body_env_response)) target_environment = process_environment(body_env_response) # Then, create the instance env_data = dataset_utils.prepare_data(step.hashes[0]) world.instance_name = env_data.get(NAME) + world.region_name.replace( "_", "") environment_instance = EnvironmentInstance(world.instance_name, env_data.get(DESCRIPTION), target_environment) world.inst_requests.add_instance(environment_instance)
def before_outline(param1, param2, param3, param4): """ Hook: Will be executed before each Scenario Outline. Same behaviour as 'before_each_scenario'""" try: test_files_dir = world.config[ENVIRONMENT][ENVIRONMENT_TESTFILES] print "Writing instance {} details to dir {}".format( world.instance_name, test_files_dir) world.inst_requests.get_instance(world.instance_name) body_env_response = raw_httplib_request_to_python_dic(world.response) if not os.path.exists(test_files_dir): os.makedirs(test_files_dir) file = open( os.path.join(test_files_dir, world.instance_name + "_instance"), 'w') file.write(str(body_env_response)) file.close() except Exception as e: print "WARNING: Instance data cannot be written to test file. {}".format( e.message)
def a_list_of_tiers_has_been_defined_with_data(step): """ Create and add tiers to the environment """ world.tiers = [] for row in step.hashes: data = dataset_utils.prepare_data(row) tier = Tier(data.get(NAME), world.image_sdc_aware_id, tier_flavour=world.flavor_id, tier_region=world.region_name) tier.parse_and_add_products(data.get(PRODUCTS)) if NETWORKS in data: # Is Neutron available? i_retrieve_the_service_catalog(step) body_response = raw_httplib_request_to_python_dic(world.response) nova_public_url = get_public_endpoint_url_by_type(body_response, 'network', world.region_name) if nova_public_url is None: raise Exception("Networks are not available. Region: {}".format(world.region_name)) tier.parse_and_add_networks(data.get(NETWORKS)) world.env_requests.add_tier_environment(world.environment_name, tier)
def the_region_has_sdc_aware_images(step): """ Check if the list retrieved has a SDC-aware image at least and save in World var the first one """ assert_equal( world.response.status, 200, "Error to obtain the images list. HTTP status code is not the expected" ) world.body_response = raw_httplib_request_to_python_dic(world.response) # Check if there are images (list > 0) number_of_images = get_number_of_images(world.body_response) assert_not_equal(number_of_images, 0, "There are not images in the region " + world.region_name) # Get a image from the list. First, try to get the first Centos img world.image_sdc_aware_id = get_first_image_in_list(world.body_response, name_filter='Cent') if world.image_sdc_aware_id is None: # If no centOS images found, get the first in list whatever its type is print "WARNING: No 'Cent' images found. It will get the first image found whatever its type is" world.image_sdc_aware_id = get_first_image_in_list(world.body_response) assert_not_equal(world.image_sdc_aware_id, None, "Error to obtain a image from the list")