def create_router_interface(cls, router_link, subnet_name, subnet_ip): """ Function for creating a router interface :param router_link: link of router details for specified router :param subnet_name: name of subnet :param subnet_ip: ip of subnet """ print "Create Router Interface (Admin -> System -> Routers)----------------------------------------------------" print subnet_name # Get driver driver = DriverUtils.get_driver() # Get URL text from class url = DriverUtils.get_url() # Append to end of URL driver.get( DriverUtils.set_url(router_link + constants.ROUTER_INTERFACE_TAB)) # Navigate to newly appended URL driver.get(DriverUtils.get_url()) # Wait for elements on page to load DriverUtils.wait_for_elements(settings.DEFAULT_ELEMENT_LOAD_TIME) create_button = driver.find_element_by_id("interfaces__action_create") create_button.click() subnet_name_input = Select(driver.find_element_by_id("id_subnet_id")) subnet_name_input.select_by_visible_text(subnet_name) subnet_ip_input = driver.find_element_by_id("id_ip_address") subnet_ip_input.send_keys(subnet_ip) subnet_ip_input.submit() # Reset URL to home page in Horizon DriverUtils.set_url(settings.DEFAULT_URL) time.sleep(settings.DEFAULT_SLEEP_TIME)
def create_mem_profile(cls, host_name, mem_profile_name): """ Function for creating a memory profile for specified host :param host_name: name of host in Hosts table :param mem_profile_name: name of memory profile for specified host """ # Check if profile already exists return_value = cls.check_profile_exists( mem_profile_name, "?tab=inventory__memoryprofiles") if (return_value == 1): # Reset URL to home page in Horizon DriverUtils.set_url(settings.DEFAULT_URL) time.sleep(settings.DEFAULT_SLEEP_TIME) return else: pass print "Create Memory Profile (Admin -> System -> Inventory)----------------------------------------------------" host_link = "" print host_name print mem_profile_name # Get driver driver = DriverUtils.get_driver() # Get URL text from class url = DriverUtils.get_url() # Append to end of URL driver.get( DriverUtils.set_url(url + "/admin/inventory/?tab=inventory__hosts")) # Navigate to newly appended URL driver.get(DriverUtils.get_url()) # Wait for elements on page to load DriverUtils.wait_for_elements(settings.DEFAULT_ELEMENT_LOAD_TIME) # Get URL of compute passed to function # Get link from partial text in table (Host Name column) links = driver.find_elements_by_partial_link_text('') for link in links: host_local = link.get_attribute("text") # Match host_to_lock with link if (host_name in host_local): host_link = link.get_attribute("href") # Append to end of URL driver.get(DriverUtils.set_url(host_link + constants.HOST_MEMORY_TAB)) # Navigate to newly appended URL driver.get(DriverUtils.get_url()) # Wait for elements on page to load DriverUtils.wait_for_elements(settings.DEFAULT_ELEMENT_LOAD_TIME) create_button = driver.find_element_by_id( "memorys__action_createMemoryProfile") create_button.click() mem_profile_name_input = driver.find_element_by_id("id_hostname") mem_profile_name_input.send_keys(mem_profile_name) mem_profile_name_input.submit() # Reset URL to home page in Horizon DriverUtils.set_url(settings.DEFAULT_URL) time.sleep(settings.DEFAULT_SLEEP_TIME)
def quotas(cls, project_name, quota_dict): """ Function for initializing modify quotas class :param project_name: name of project in Horizon :param quota_dict: dictionary of all quotas to modify [example (input_id_name: value)] """ # Get driver driver = DriverUtils.get_driver() # Get URL text from class url = DriverUtils.get_url() # Append to end of URL driver.get(DriverUtils.set_url(url + "/identity/")) # Navigate to newly appended URL driver.get(DriverUtils.get_url()) # Wait for elements on page to load DriverUtils.wait_for_elements(settings.DEFAULT_ELEMENT_LOAD_TIME) # Call Functions below project_id = cls.get_project_id(project_name) if(project_id == -1): print "Test: FAIL - Error finding project name" return cls.modify_quotas(project_id, quota_dict) # Reset URL to home page in Horizon DriverUtils.set_url(settings.DEFAULT_URL) time.sleep(settings.DEFAULT_SLEEP_TIME)
def volumes(cls, volume_name, volume_source, image_source, availability_zone): """ Function for initializing volumes class :param volume_name: name of volume :param volume_source: source of volume [image] :param image_source: image name :param availability_zone: [any or nova] """ # Get driver driver = DriverUtils.get_driver() # Get URL text from class url = DriverUtils.get_url() # Append to end of URL driver.get( DriverUtils.set_url( url + "/project/volumes/?tab=volumes_and_snapshots__volumes_tab")) # Navigate to newly appended URL driver.get(DriverUtils.get_url()) # Wait for elements on page to load DriverUtils.wait_for_elements(settings.DEFAULT_ELEMENT_LOAD_TIME) # Call Functions below cls.create_volume(volume_name, volume_source, image_source, availability_zone) # Reset URL to home page in Horizon DriverUtils.set_url(settings.DEFAULT_URL) time.sleep(settings.DEFAULT_SLEEP_TIME)
def key_pairs(cls, key_pair_name): """ Function for initializing key pairs class :param key_pair_name: name of key pair """ # Get driver driver = DriverUtils.get_driver() # Get URL text from class url = DriverUtils.get_url() # Append to end of URL driver.get( DriverUtils.set_url( url + "/project/access_and_security/?tab=access_security_tabs__keypairs_tab" )) # Navigate to newly appended URL driver.get(DriverUtils.get_url()) # Wait for elements on page to load DriverUtils.wait_for_elements(settings.DEFAULT_ELEMENT_LOAD_TIME) # Call Functions below return_value = cls.check_key_pair(key_pair_name) if (return_value == 1): # Reset URL to home page in Horizon DriverUtils.set_url(settings.DEFAULT_URL) time.sleep(settings.DEFAULT_SLEEP_TIME) return else: pass cls.create_key_pair(key_pair_name) # Reset URL to home page in Horizon DriverUtils.set_url(settings.DEFAULT_URL) time.sleep(settings.DEFAULT_SLEEP_TIME)
def hosts(cls): """ Function for initializing hosts class :return host_list: list of hosts in host table """ print "Check Hosts (Admin -> System -> Inventory)--------------------------------------------------------------" # Get driver driver = DriverUtils.get_driver() # Get URL text from class url = DriverUtils.get_url() # Append to end of URL driver.get( DriverUtils.set_url(url + "/admin/inventory/?tab=inventory__hosts")) # Navigate to newly appended URL driver.get(DriverUtils.get_url()) # Wait for elements on page to load DriverUtils.wait_for_elements(settings.DEFAULT_ELEMENT_LOAD_TIME) # Call Functions below host_list = cls.get_hosts() # Reset URL to home page in Horizon DriverUtils.set_url(settings.DEFAULT_URL) time.sleep(settings.DEFAULT_SLEEP_TIME) return host_list
def networks(cls, network_provider_name, network_provider_type, mtu, vlan_transparent): """ Function for initializing networks class :param network_provider_name: provider network name for network :param network_provider_type: type of network [flat, vlan, vxlan] :param mtu: maximum transfer units :param vlan_transparent: True or False :return provider_net_link: link to provider net details to specified provider network """ # Get driver driver = DriverUtils.get_driver() # Get URL text from class url = DriverUtils.get_url() # Append to end of URL driver.get(DriverUtils.set_url(url + "/admin/networks/")) # Navigate to newly appended URL driver.get(DriverUtils.get_url()) # Wait for elements on page to load DriverUtils.wait_for_elements(settings.DEFAULT_ELEMENT_LOAD_TIME) # Call Functions below cls.create_provider_net(network_provider_name, network_provider_type, mtu, vlan_transparent) time.sleep(5) provider_net_link = cls.get_provider_net(network_provider_name) if(provider_net_link == -1): print "Test: FAIL - Error finding provider net name" return # Reset URL to home page in Horizon DriverUtils.set_url(settings.DEFAULT_URL) time.sleep(settings.DEFAULT_SLEEP_TIME) return provider_net_link
def flavors(cls, flavor_name, vcpus, ram, root_disk, ephemeral_disk, swap_disk): """ Function for initializing flavors class :param flavor_name: name of flavor :param vcpus: number of vcpus :param ram: amount of RAM (MB) :param root_disk: size of root disk (GB) :param ephemeral_disk: size of ephemeral disk (GB) :param swap_disk: size of swap disk (MB) """ # Get driver driver = DriverUtils.get_driver() # Get URL text from class url = DriverUtils.get_url() # Append to end of URL driver.get(DriverUtils.set_url(url + "/admin/flavors/")) # Navigate to newly appended URL driver.get(DriverUtils.get_url()) # Wait for elements on page to load DriverUtils.wait_for_elements(settings.DEFAULT_ELEMENT_LOAD_TIME) # Call Functions below cls.create_flavor(flavor_name, vcpus, ram, root_disk, ephemeral_disk, swap_disk) time.sleep(settings.DEFAULT_SLEEP_TIME) flavor_full_link = cls.get_flavor_link(flavor_name) if(flavor_full_link == -1): print "Test: FAIL - Error finding flavor name" return # Reset URL to home page in Horizon DriverUtils.set_url(settings.DEFAULT_URL) time.sleep(settings.DEFAULT_SLEEP_TIME) return flavor_full_link
def tenants(cls, username, password, email, project_name): """ Function for initializing tenants class :param username: username of tenant :param password: password of tenant :param email: email of tenant :param project_name: name of project """ # Get driver driver = DriverUtils.get_driver() # Get URL text from class url = DriverUtils.get_url() # Append to end of URL driver.get(DriverUtils.set_url(url + "/identity/users/")) # Navigate to newly appended URL driver.get(DriverUtils.get_url()) # Wait for elements on page to load DriverUtils.wait_for_elements(settings.DEFAULT_ELEMENT_LOAD_TIME) # Call Functions below return_value = cls.check_tenants(username) if (return_value == 1): # Reset URL to home page in Horizon DriverUtils.set_url(settings.DEFAULT_URL) time.sleep(settings.DEFAULT_SLEEP_TIME) return else: pass cls.create_tenant(username, password, email, project_name) # Reset URL to home page in Horizon DriverUtils.set_url(settings.DEFAULT_URL) time.sleep(settings.DEFAULT_SLEEP_TIME)
def images(cls, image_name, image_location, format, copy_data, timeout, downtime, public, instance_auto_recovery): """ Function for initializing images class :param image_name: name of image :param image_location: URL of image location :param format: format of image :param copy_data: copy image data to service [True or False] :param timeout: timeout for live migration :param downtime: downtime for live migration :param public: is the image public [True or False] :param instance_auto_recovery: [True or False] """ print "Create Image (Admin -> System -> Images)----------------------------------------------------------------" print image_name # Get driver driver = DriverUtils.get_driver() # Get URL text from class url = DriverUtils.get_url() # Append to end of URL driver.get(DriverUtils.set_url(url + "/admin/images/")) # Navigate to newly appended URL driver.get(DriverUtils.get_url()) # Wait for elements on page to load DriverUtils.wait_for_elements(settings.DEFAULT_ELEMENT_LOAD_TIME) # Call Functions below cls.create_images(image_name, image_location, format, copy_data, timeout, downtime, public, instance_auto_recovery) # Reset URL to home page in Horizon DriverUtils.set_url(settings.DEFAULT_URL) time.sleep(settings.DEFAULT_SLEEP_TIME)
def routers(cls, router_name, external_network_name): """ Function for initializing routers class :param router_name: name of router :param external_network_name: name of external network :return router_full_link: link of router details for specified router """ # Get driver driver = DriverUtils.get_driver() # Get URL text from class url = DriverUtils.get_url() # Append to end of URL driver.get(DriverUtils.set_url(url + "/project/routers/")) # Navigate to newly appended URL driver.get(DriverUtils.get_url()) # Wait for elements on page to load DriverUtils.wait_for_elements(settings.DEFAULT_ELEMENT_LOAD_TIME) # Call Functions below cls.create_router(router_name, external_network_name) time.sleep(settings.DEFAULT_SLEEP_TIME) router_full_link = cls.get_router_link(router_name) if (router_full_link == -1): print "Test: FAIL - Error finding flavor name" return # Reset URL to home page in Horizon DriverUtils.set_url(settings.DEFAULT_URL) time.sleep(settings.DEFAULT_SLEEP_TIME) return router_full_link
def check_profile_exists(cls, profile_name, url_tab): """ Function to check if profile exists :param profile_name: name of profile to check :return return_value """ return_value = -1 # Get driver driver = DriverUtils.get_driver() # Get URL text from class url = DriverUtils.get_url() # Append to end of URL driver.get(DriverUtils.set_url(url + "/admin/inventory/" + url_tab)) # Navigate to newly appended URL driver.get(DriverUtils.get_url()) # Wait for elements on page to load DriverUtils.wait_for_elements(settings.DEFAULT_ELEMENT_LOAD_TIME) # Check if profile already exists words_on_page = driver.find_element_by_xpath("//*[contains(text()," + profile_name + ")]") if (profile_name in words_on_page.text): return 1 else: return_value = 0 return return_value
def create_provider_net(cls, network_provider_name, network_provider_type, mtu, vlan_transparent): """ Function for creating a provider network :param network_provider_name: provider network name for network :param network_provider_type: type of network [flat, vlan, vxlan] :param mtu: maximum transfer units :param vlan_transparent: True or False """ print "Create Provider Network (Admin -> System -> Networks)---------------------------------------------------" print network_provider_name driver = DriverUtils.get_driver() # Get URL text from class url = DriverUtils.get_url() # Append to end of URL driver.get(DriverUtils.set_url(url + "?tab=networks__provider_networks")) # Navigate to newly appended URL driver.get(DriverUtils.get_url()) # Wait for elements on page to load DriverUtils.wait_for_elements(settings.DEFAULT_ELEMENT_LOAD_TIME) create_button = driver.find_element_by_id("provider_networks__action_create") create_button.click() name_input = driver.find_element_by_id("id_name") name_input.send_keys(network_provider_name) type_input = Select(driver.find_element_by_id("id_type")) # Consider changing 'flat' 'vlan' 'vxlan' to constants? if(network_provider_type == "flat"): type_input.select_by_visible_text("flat") if(network_provider_type == "vlan"): type_input.select_by_visible_text("vlan") if(network_provider_type == "vxlan"): type_input.select_by_visible_text("vxlan") mtu_input = driver.find_element_by_id("id_mtu") mtu_input.send_keys(Keys.BACKSPACE) mtu_input.send_keys(Keys.BACKSPACE) mtu_input.send_keys(Keys.BACKSPACE) mtu_input.send_keys(Keys.BACKSPACE) mtu_input.send_keys(mtu) vlan_input = driver.find_element_by_id("id_vlan_transparent") if(vlan_transparent == True): vlan_input.click() if(vlan_transparent == False): pass vlan_input.submit()
def get_flavor_link(cls, flavor_name): """ Function for getting flavor details link :param flavor_name: name of flavor :return flavor_id_link: link for details page of flavor name sent """ flavor_id_link = -1 # Get driver driver = DriverUtils.get_driver() # Get link from partial text in table (Host Name column) links = driver.find_elements_by_partial_link_text('') for link in links: host_local = link.get_attribute("text") # Match host_to_lock with link if(flavor_name in host_local): flavor_id_link = link.get_attribute("href") # Append to end of URL driver.get(DriverUtils.set_url(flavor_id_link + constants.FLAVOR_EXTRA_SPEC_TAB)) # Navigate to newly appended URL driver.get(DriverUtils.get_url()) # Wait for elements on page to load DriverUtils.wait_for_elements(settings.DEFAULT_ELEMENT_LOAD_TIME) return flavor_id_link
def get_sensors(cls, host_name): # Get driver driver = DriverUtils.get_driver() # Get URL text from class url = DriverUtils.get_url() cls.base_url = url # Append to end of URL driver.get(url + "/admin/inventory/") driver.find_element_by_link_text("Inventory").click() driver.find_element_by_link_text("Hosts").click() driver.find_element_by_link_text("controller-0").click() #driver.find_element_by_link_text(host_name).click() driver.find_element_by_link_text("Sensors").click() # Wait for elements on page to load DriverUtils.wait_for_elements(settings.DEFAULT_ELEMENT_LOAD_TIME) # Confirm sensor present time.sleep(10) check_return_value = cls.check_sensor_exists() if (check_return_value == 1): print "Configured alarms found" return True else: print "No configured alarms found" return False
def login(cls, username, password): """ Function for logging into Horizon :param username: username for Horizon login :param password: password for Horizon login """ # Get driver driver = DriverUtils.get_driver() driver.get(DriverUtils.get_url()) # Check username and password are NOT empty if(username != ""): if(password != ""): # Perform login # Find HTML element for username input field username_element = driver.find_element_by_name("username") # Type in the input for username username_element.send_keys(username) # Find HTML element for password input field password_element = driver.find_element_by_name("password") # Type in the input for password password_element.send_keys(password) # Submit HTML form password_element.submit() time.sleep(settings.DEFAULT_SLEEP_TIME) else: print "Test: FAIL - Username or Password is missing/invalid" exit(1)
def router_distributed(cls, router_link, distributed): """ Function for changing router distribution :param router_link: link of router details for specified router :param distributed: True or False """ if (distributed == False): pass else: # Get driver driver = DriverUtils.get_driver() # Get URL text from class url = DriverUtils.get_url() # Append to end of URL driver.get(DriverUtils.set_url(router_link)) # Navigate to newly appended URL driver.get(DriverUtils.get_url()) # Wait for elements on page to load DriverUtils.wait_for_elements(settings.DEFAULT_ELEMENT_LOAD_TIME) # Parse router link parse = router_link.split("/") router_id = parse[5] # Edit router button edit_dropdown_button = driver.find_element_by_css_selector( constants.ROUTER_EDIT_INTERFACE_DROPDOWN) edit_dropdown_button.click() edit_button = constants.ROUTER_EDIT_INTERFACE_FIRST_HALF + router_id + constants.ROUTER_EDIT_INTERFACE_SECOND_HALF edit_button_input = driver.find_element_by_id(edit_button) edit_button_input.click() distributed_input = Select(driver.find_element_by_id("id_mode")) distributed_input.select_by_visible_text("Distributed") # Get name for form submission name_input = driver.find_element_by_id("id_name") name_input.submit() # Reset URL to home page in Horizon DriverUtils.set_url(settings.DEFAULT_URL) time.sleep(settings.DEFAULT_SLEEP_TIME)
def swact_host(cls, host_name): print "Swact Host Information------------------------------------------" # Get driver driver = DriverUtils.get_driver() # Get URL text from class url = DriverUtils.get_url() # Append to end of URL driver.get(DriverUtils.set_url(url + "/admin/inventory/?tab=inventory__hosts")) # Navigate to newly appended URL driver.get(DriverUtils.get_url()) # Wait for elements on page to load DriverUtils.wait_for_elements(settings.DEFAULT_ELEMENT_LOAD_TIME) # Call function to get list of all hosts cls.get_hosts(host_name) # Reset URL to home page in Horizon DriverUtils.set_url(settings.DEFAULT_URL)
def create_qos_policy(cls, policy_name, description, weight, project_name): """ Function for creating a QoS policy :param policy_name: name of QoS policy :param description: description of QoS policy :param weight: scheduler weight :param project_name: name of project """ print "Create Network QoS Policy (Admin -> System -> Networks)-------------------------------------------------" print policy_name # Get driver driver = DriverUtils.get_driver() # Get URL text from class url = DriverUtils.get_url() # Append to end of URL driver.get(DriverUtils.set_url(url + "/admin/networks/?tab=networks__qos")) # Navigate to newly appended URL driver.get(DriverUtils.get_url()) # Wait for elements on page to load DriverUtils.wait_for_elements(settings.DEFAULT_ELEMENT_LOAD_TIME) create_button = driver.find_element_by_id("qos__action_create") create_button.click() policy_name_input = driver.find_element_by_id("id_name") policy_name_input.send_keys(policy_name) description_input = driver.find_element_by_id("id_description") description_input.send_keys(description) weight_input = driver.find_element_by_id("id_weight") weight_input.send_keys(weight) if(project_name == None): pass else: project_input = Select(driver.find_element_by_id("id_tenant_id")) project_input.select_by_visible_text(project_name) policy_name_input.submit() # Reset URL to home page in Horizon DriverUtils.set_url(settings.DEFAULT_URL) time.sleep(settings.DEFAULT_SLEEP_TIME)
def create_extra_spec(cls, flavor_full_link, first_input, second_input): """ Function for creating flavor extra spec :param flavor_full_link: link to flavor details section in Horizon :param first_input: extra spec type [example (CPU Policy)] :param second_input: extra spec type details [example (Dedicated)] """ print "Flavors: Create Extra Spec (Admin -> System -> Flavors)-------------------------------------------------" # Get driver driver = DriverUtils.get_driver() # Get URL text from class url = DriverUtils.get_url() # Append to end of URL driver.get(DriverUtils.set_url(flavor_full_link + constants.FLAVOR_EXTRA_SPEC_TAB)) # Navigate to newly appended URL driver.get(DriverUtils.get_url()) # Wait for elements on page to load DriverUtils.wait_for_elements(settings.DEFAULT_ELEMENT_LOAD_TIME) create_button = driver.find_element_by_id("extras__action_create") create_button.click() # Select extra spec extra_spec_first_input = Select(driver.find_element_by_id("id_type")) if(first_input in constants.FLAVOR_EXTRA_SPEC_TYPE_CPU_POLICY): extra_spec_first_input.select_by_visible_text(constants.FLAVOR_EXTRA_SPEC_TYPE_CPU_POLICY) if(second_input in constants.FLAVOR_EXTRA_SPEC_TYPE_CPU_POLICY_DEDICATED): extra_spec_second_input = Select(driver.find_element_by_id("id_cpu_policy")) extra_spec_second_input.select_by_visible_text(constants.FLAVOR_EXTRA_SPEC_TYPE_CPU_POLICY_DEDICATED) if(first_input in constants.FLAVOR_EXTRA_SPEC_TYPE_MEMORY_PAGE_SIZE): extra_spec_first_input.select_by_visible_text(constants.FLAVOR_EXTRA_SPEC_TYPE_MEMORY_PAGE_SIZE) if(second_input in constants.FLAVOR_EXTRA_SPEC_TYPE_MEMORY_PAGE_SIZE_2048): extra_spec_second_input = Select(driver.find_element_by_id("id_mem_page_size")) extra_spec_second_input.select_by_visible_text(constants.FLAVOR_EXTRA_SPEC_TYPE_MEMORY_PAGE_SIZE_2048) if(first_input in constants.FLAVOR_EXTRA_SPEC_TYPE_VCPU_MODEL): extra_spec_first_input.select_by_visible_text(constants.FLAVOR_EXTRA_SPEC_TYPE_VCPU_MODEL) if(second_input in constants.FLAVOR_EXTRA_SPEC_TYPE_VCPU_MODEL_INTEL_9XX): extra_spec_second_input = Select(driver.find_element_by_id("id_cpu_model")) extra_spec_second_input.select_by_visible_text(constants.FLAVOR_EXTRA_SPEC_TYPE_VCPU_MODEL_INTEL_9XX) submit_form = driver.find_element_by_id("id_type") submit_form.submit() # Reset URL to home page in Horizon DriverUtils.set_url(settings.DEFAULT_URL) time.sleep(settings.DEFAULT_SLEEP_TIME)
def check_alarms(cls): """ Function for checking alarms in Fault Management """ print "Fault Alarm Management Information----------------------------------------------------------------------" # Get driver driver = DriverUtils.get_driver() # Get URL text from class url = DriverUtils.get_url() # Append to end of URL driver.get( DriverUtils.set_url( url + "/admin/fault_management/?tab=alarms_tabs__alarms")) # Navigate to newly appended URL driver.get(DriverUtils.get_url()) # Wait for elements on page to load DriverUtils.wait_for_elements(settings.DEFAULT_ELEMENT_LOAD_TIME) # Call function to get fault names cls.get_fault_names() # Reset URL to home page in Horizon DriverUtils.set_url(settings.DEFAULT_URL)
def logout(cls): """ Function for logging out of Horizon """ # Get driver logout_link = "" driver = DriverUtils.get_driver() # Navigate to newly appended URL driver.get(DriverUtils.get_url()) # Get link from partial text in table (Host Name column) links = driver.find_elements_by_partial_link_text('') for link in links: host_local = link.get_attribute("text") # Match host_to_lock with link if("Sign Out" in host_local): logout_link = link.get_attribute("href") driver.get(DriverUtils.set_url(logout_link)) # Navigate to newly appended URL driver.get(DriverUtils.get_url()) # Reset URL to home page in Horizon DriverUtils.set_url(settings.DEFAULT_URL) time.sleep(settings.DEFAULT_SLEEP_TIME)
def set_sensor_action(cls, host_name, action, severity='critical', alarm_name='server power'): # Get driver driver = DriverUtils.get_driver() # Get URL text from class url = DriverUtils.get_url() cls.base_url = url # Append to end of URL driver.get( DriverUtils.set_url(url + "/admin/inventory/?tab=inventory__hosts")) # Navigate to newly appended URL driver.get(DriverUtils.get_url()) # Wait for elements on page to load DriverUtils.wait_for_elements(settings.DEFAULT_ELEMENT_LOAD_TIME) # Call function to set action cls.set_host_alarms(host_name, action, severity, alarm_name) # Reset URL to home page in Horizon DriverUtils.set_url(cls.base_url)
def provider_net_range_create(cls, provider_net_link, provider_name, shared, project_name, min_range, max_range): """ Function for creating a net range in specified provider network :param provider_net_link: link to provider net details :param provider_name: name of provider net :param shared: True or False :param project_name: name of project :param min_range: minimum segmentation range :param max_range: maximum segmentation range """ print "Create Provider Network: Range (Admin -> System -> Networks)--------------------------------------------" # Get driver driver = DriverUtils.get_driver() DriverUtils.set_url(provider_net_link) # Navigate to newly appended URL driver.get(DriverUtils.get_url()) # Wait for elements on page to load DriverUtils.wait_for_elements(settings.DEFAULT_ELEMENT_LOAD_TIME) create_button = driver.find_element_by_id("provider_network_ranges__action_create") create_button.click() name_input = driver.find_element_by_id("id_name") name_input.send_keys(provider_name) if(shared == True): shared_input = driver.find_element_by_id("id_shared") shared_input.click() else: pass if(project_name == None): pass else: project_input = Select(driver.find_element_by_id("id_tenant_id")) project_input.select_by_visible_text(project_name) min_range_input = driver.find_element_by_id("id_minimum") min_range_input.send_keys(min_range) max_range_input = driver.find_element_by_id("id_maximum") max_range_input.send_keys(max_range) max_range_input.submit() # Reset URL to home page in Horizon DriverUtils.set_url(settings.DEFAULT_URL) time.sleep(settings.DEFAULT_SLEEP_TIME)
def add_local_storage(cls, host_name, lvm_size): """ Function for creating local storage on a host :param host_name: name of host in Hosts table :param lvm_size: local volume size """ print "Add Local Storage (Admin -> System -> Inventory)--------------------------------------------------------" print host_name print lvm_size # Get driver driver = DriverUtils.get_driver() # Get URL text from class url = DriverUtils.get_url() # Append to end of URL DriverUtils.set_url(url + "/admin/inventory/?tab=inventory__hosts") # Navigate to newly appended URL driver.get(DriverUtils.get_url()) # Wait for elements on page to load DriverUtils.wait_for_elements(settings.DEFAULT_ELEMENT_LOAD_TIME) # Get URL of compute passed to function # Get link from partial text in table (Host Name column) links = driver.find_elements_by_partial_link_text('') for link in links: host_local = link.get_attribute("text") # Match host_name with link if (host_name in host_local): host_link = link.get_attribute("href") # Append to end of URL DriverUtils.set_url(host_link + constants.HOST_STORAGE_TAB) # Navigate to newly appended URL driver.get(DriverUtils.get_url()) # Wait for elements on page to load DriverUtils.wait_for_elements(settings.DEFAULT_ELEMENT_LOAD_TIME) # Save current URL save_url = DriverUtils.get_url() # Find create button create_button = driver.find_element_by_id( "localvolumegroups__action_addlocalvolumegroup") create_button.click() # Find element and submit form submit_element = driver.find_element_by_id("id_lvm_vg_name") submit_element.submit() time.sleep(settings.DEFAULT_SLEEP_TIME) DriverUtils.set_url(save_url) driver.get(DriverUtils.get_url()) # Find create button add_pv_button = driver.find_element_by_id( "physicalvolumes__action_addphysicalvolume") add_pv_button.click() # Find element and submit form submit_element_pv = driver.find_element_by_id("id_disks") submit_element_pv.submit() time.sleep(settings.DEFAULT_SLEEP_TIME) driver.get(DriverUtils.get_url()) # Wait for elements on page to load DriverUtils.wait_for_elements(settings.DEFAULT_ELEMENT_LOAD_TIME) # Get URL of compute passed to function # Get link from partial text in table (Host Name column) links = driver.find_elements_by_partial_link_text('') for link in links: host_local = link.get_attribute("text") # Match nova-local with link if ("nova-local" in host_local): host_link = link.get_attribute("href") # Append to end of URL driver.get( DriverUtils.set_url( host_link + constants.HOST_STORAGE_LOCAL_VOLUME_GROUP_PARAM_TAB)) # Navigate to newly appended URL driver.get(DriverUtils.get_url()) # Wait for elements on page to load DriverUtils.wait_for_elements(settings.DEFAULT_ELEMENT_LOAD_TIME) # TODO: Find edit size button edit_button = driver.find_element_by_id( "params__row_instances_lv_size_mib__action_edit") edit_button.click() # TODO: Find size input lvm_size_input = driver.find_element_by_id("id_instances_lv_size_mib") lvm_size_input.send_keys(Keys.BACKSPACE) lvm_size_input.send_keys(Keys.BACKSPACE) lvm_size_input.send_keys(lvm_size) # TODO: Submit form lvm_size_input.submit() # Reset URL to home page in Horizon DriverUtils.set_url(settings.DEFAULT_URL) time.sleep(settings.DEFAULT_SLEEP_TIME)
def create_network(cls, network_name, project_name, network_type, physical_network, \ segmentation_id, qos_policy, shared, external_network, vlan_transparent): """ Function for creating a network :param network_name: name of network :param project_name: name of project :param network_type: type of network [flat, vlan, vxlan] :param physical_network: name of provider network(s) :param segmentation_id: [int] :param qos_policy: name of QoS policy :param shared: True or False :param external_network: True or False :param vlan_transparent: True or False :return network_name: name of network """ print "Create Network (Admin -> System -> Networks)------------------------------------------------------------" print network_name # Get driver driver = DriverUtils.get_driver() # Get URL text from class url = DriverUtils.get_url() # Append to end of URL driver.get(DriverUtils.set_url(url + "/admin/networks/?tab=networks__networks")) # Navigate to newly appended URL driver.get(DriverUtils.get_url()) # Wait for elements on page to load DriverUtils.wait_for_elements(settings.DEFAULT_ELEMENT_LOAD_TIME) create_button = driver.find_element_by_id("networks__action_create") create_button.click() network_name_input = driver.find_element_by_id("id_name") network_name_input.send_keys(network_name) project_input = Select(driver.find_element_by_id("id_tenant_id")) project_input.select_by_visible_text(project_name) network_type_input = Select(driver.find_element_by_id("id_network_type")) network_type_input.select_by_visible_text(network_type) physical_network_input = Select(driver.find_element_by_id("id_physical_network_vlan")) physical_network_input.select_by_visible_text(physical_network) if(segmentation_id == None): pass else: segmentation_id_input = driver.find_element_by_id("id_segmentation_id") segmentation_id_input.send_keys(segmentation_id) if(qos_policy == None): pass else: qos_policy_input = Select(driver.find_element_by_id("id_qos")) qos_policy_input.select_by_visible_text(qos_policy) if(shared == True): shared_input = driver.find_element_by_id("id_shared") shared_input.click() else: pass if(external_network == True): external_network_input = driver.find_element_by_id("id_external") external_network_input.click() else: pass if(vlan_transparent == True): vlan_transparent_input = driver.find_element_by_id("id_vlan_transparent") vlan_transparent_input.click() else: pass # Submit create network form network_name_input.submit() time.sleep(settings.DEFAULT_SLEEP_TIME) return network_name
def create_project_subnet(cls, network_name, subnet_name, network_address, gateway_ip, disable_gateway, system_managed_subnet, dhcp, allocation_pools, dns_name_servers, host_routes, vlan): """ Function for creating a project network subnet :param network_name: name of network :param subnet_name: name of subnet :param network_address: network address in CIDR format :param gateway_ip: ip address of gateway :param disable_gateway: True or False :param system_managed_subnet: True or False :param dhcp: True or False :param allocation_pools: ip address allocation pools :param dns_name_servers: ip address list of DNS name servers :param host_routes: additional routes announced to the hosts :param vlan: vlan id of subnet """ print "Create Project Network Subnet (Project -> Network -> Networks)------------------------------------------" print subnet_name network_link = -1 print network_name # Get driver driver = DriverUtils.get_driver() # Get URL text from class url = DriverUtils.get_url() # Append to end of URL DriverUtils.set_url(url + "/project/networks/?tab=networks__networks") # Navigate to newly appended URL driver.get(DriverUtils.get_url()) # Wait for elements on page to load DriverUtils.wait_for_elements(settings.DEFAULT_ELEMENT_LOAD_TIME) # Get link from partial text in table (Host Name column) links = driver.find_elements_by_partial_link_text('') for link in links: host_local = link.get_attribute("text") # Match host_to_lock with link if(network_name in host_local): network_link = link.get_attribute("href") # Append to end of URL driver.get(DriverUtils.set_url(network_link)) time.sleep(settings.DEFAULT_SLEEP_TIME) # Navigate to newly appended URL driver.get(DriverUtils.get_url()) # Wait for elements on page to load DriverUtils.wait_for_elements(settings.DEFAULT_ELEMENT_LOAD_TIME) create_button = driver.find_element_by_id("subnets__action_create") create_button.click() subnet_name_input = driver.find_element_by_id("id_subnet_name") subnet_name_input.send_keys(subnet_name) network_address_input = driver.find_element_by_id("id_cidr") network_address_input.send_keys(network_address) if(gateway_ip == None): pass else: gateway_ip_input = driver.find_element_by_id("id_gateway_ip") gateway_ip_input.send_keys(gateway_ip) if(disable_gateway == False): pass else: disable_gateway_input = driver.find_element_by_id("id_no_gateway") disable_gateway_input.click() next_button = driver.find_element_by_css_selector("button.btn-primary:nth-child(1)") next_button.click() if(system_managed_subnet == False): system_managed_subnet_input = driver.find_element_by_id("id_managed") system_managed_subnet_input.click() else: pass if(dhcp == False): dhcp_input = driver.find_element_by_id("id_enable_dhcp") dhcp_input.click() else: pass if(allocation_pools == None): pass else: allocation_pools_input = driver.find_element_by_id("id_allocation_pools") allocation_pools_input.send_keys(allocation_pools) if(dns_name_servers == None): pass else: dns_name_servers_input = driver.find_element_by_id("id_dns_nameservers") dns_name_servers_input.send_keys(dns_name_servers) if(host_routes == None): pass else: host_routes_input = driver.find_element_by_id("id_host_routes") host_routes_input.send_keys(host_routes) if(vlan == None): pass else: vlan_input = driver.find_element_by_id("id_vlan_id") vlan_input.send_keys(vlan) vlan_input = driver.find_element_by_id("id_vlan_id") vlan_input.submit() # Reset URL to home page in Horizon DriverUtils.set_url(settings.DEFAULT_URL) time.sleep(settings.DEFAULT_SLEEP_TIME)
def modify_interface(cls, host_name, iface_name, network_type, port, mtu, provider_networks): """ Function for creating an interface for specified host :param host_name: name of host in Hosts table :param iface_name: name of interface :param network_type: type of network [mgmt, oam, data, infra, pxeboot] :param iface_type: type of interface [aggregated or vlan] :param eth_mode: aggregated ethernet mode :param ports: network adapter? :param mtu: maximum transmit unit :param provider_networks: list of provider networks """ print "Modify Interface (Admin -> System -> Inventory)---------------------------------------------------------" host_link = "" row_number = -1 numbers = [] print host_name print iface_name # Get driver driver = DriverUtils.get_driver() # Get URL text from class url = DriverUtils.get_url() # Append to end of URL driver.get( DriverUtils.set_url(url + "/admin/inventory/?tab=inventory__hosts")) # Navigate to newly appended URL driver.get(DriverUtils.get_url()) # Wait for elements on page to load DriverUtils.wait_for_elements(settings.DEFAULT_ELEMENT_LOAD_TIME) # Get link from partial text in table (Host Name column) links = driver.find_elements_by_partial_link_text('') for link in links: host_local = link.get_attribute("text") # Match host_name with link if (host_name in host_local): host_link = link.get_attribute("href") # Append to end of URL DriverUtils.set_url(host_link + constants.HOST_INTERFACE_TAB) # Navigate to newly appended URL driver.get(DriverUtils.get_url()) # Wait for elements on page to load DriverUtils.wait_for_elements(settings.DEFAULT_ELEMENT_LOAD_TIME) # Get link from partial text in host table (Host Name column) links = driver.find_elements_by_partial_link_text('') for link in links: host_interface = link.get_attribute("text") # Match host_local link name with compute if (port in host_interface): parse = link.get_attribute("href") # Parse number from link parse = parse.split("/") # Get row number in table row_number = parse[7] # TODO - Possible Enhancement: Add proper check for existing interfaces # Note: This a workaround because lab_cleanup.sh does not remove interface from con-1 # Interface check for con-1 is currently hard-coded as 'oam0' if (host_interface == "oam0"): # Reset URL to home page in Horizon DriverUtils.set_url(settings.DEFAULT_URL) time.sleep(settings.DEFAULT_SLEEP_TIME) return else: continue # Get Edit Interface button edit_interface_button = constants.HOST_INTERFACE_EDIT_FIRST_HALF + str( row_number) + constants.HOST_INTERFACE_EDIT_SECOND_HALF edit_button = driver.find_element_by_id(edit_interface_button) edit_button.click() iface_name_input = driver.find_element_by_id("id_ifname") iface_name_input.send_keys(Keys.DELETE) iface_name_input.send_keys(Keys.DELETE) iface_name_input.send_keys(Keys.DELETE) iface_name_input.send_keys(Keys.DELETE) iface_name_input.send_keys(Keys.DELETE) iface_name_input.send_keys(iface_name) print network_type if (network_type == "data"): network_type_input = driver.find_element_by_id("id_networktype_5") network_type_input.click() if (network_type == "oam"): network_type_input = driver.find_element_by_id("id_networktype_2") network_type_input.click() time.sleep(2) # Provider Networks if (not provider_networks): pass else: if ("group0-data0" in provider_networks): provider_networks_input1 = driver.find_element_by_id( "id_providernetworks_data_1") provider_networks_input1.click() if ("group0-data0b" in provider_networks): provider_networks_input2 = driver.find_element_by_id( "id_providernetworks_data_2") provider_networks_input2.click() if ("group0-ext0" in provider_networks): provider_networks_input3 = driver.find_element_by_id( "id_providernetworks_data_0") provider_networks_input3.click() if ("group0-data1" in provider_networks): provider_networks_input4 = driver.find_element_by_id( "id_providernetworks_data_3") provider_networks_input4.click() mtu_input = driver.find_element_by_id("id_imtu") mtu_input.send_keys(Keys.BACKSPACE) mtu_input.send_keys(Keys.BACKSPACE) mtu_input.send_keys(Keys.BACKSPACE) mtu_input.send_keys(Keys.BACKSPACE) mtu_input.send_keys(Keys.BACKSPACE) mtu_input.send_keys(mtu) time.sleep(2) # Submit interface form mtu_input.submit() # Reset URL to home page in Horizon DriverUtils.set_url(settings.DEFAULT_URL) time.sleep(settings.DEFAULT_SLEEP_TIME)
def create_cinder_device(cls, host_name): """ Function for creating a cinder device on a host :param host_name: name of host in Hosts table """ print "Create Cinder Device (Admin -> System -> Inventory)-----------------------------------------------------" print host_name host_link = "" # Get driver driver = DriverUtils.get_driver() # Get URL text from class url = DriverUtils.get_url() # Append to end of URL DriverUtils.set_url(url + "/admin/inventory/?tab=inventory__hosts") # Navigate to newly appended URL driver.get(DriverUtils.get_url()) # Wait for elements on page to load DriverUtils.wait_for_elements(settings.DEFAULT_ELEMENT_LOAD_TIME) # Get URL of compute passed to function time.sleep(settings.DEFAULT_SLEEP_TIME) # Get link from partial text in table (Host Name column) links = driver.find_elements_by_partial_link_text('') for link in links: host_local = link.get_attribute("text") # Match host_to_lock with link if (host_name in host_local): host_link = link.get_attribute("href") # If controller-1 does not exist skip if (host_link == ""): DriverUtils.set_url(settings.DEFAULT_URL) time.sleep(settings.DEFAULT_SLEEP_TIME) return # Append to end of URL driver.get(DriverUtils.set_url(host_link + constants.HOST_STORAGE_TAB)) # Navigate to newly appended URL driver.get(DriverUtils.get_url()) # Wait for elements on page to load DriverUtils.wait_for_elements(settings.DEFAULT_ELEMENT_LOAD_TIME) words_on_page = driver.find_element_by_xpath( "//*[contains(text(),/dev/sdb)]") if ("/dev/sdb" in words_on_page.text): # Reset URL to home page in Horizon DriverUtils.set_url(settings.DEFAULT_URL) time.sleep(settings.DEFAULT_SLEEP_TIME) return else: pass # TODO: Find create button create_button = driver.find_element_by_id() create_button.click() # TODO: Find element and submit form submit_element = driver.find_element_by_id() submit_element.submit() # Reset URL to home page in Horizon DriverUtils.set_url(settings.DEFAULT_URL) time.sleep(settings.DEFAULT_SLEEP_TIME)