*** Settings *** Documentation Openstack library. This library is useful for tests to create network, subnet, router and vm instances Library SSHLibrary Resource Utils.robot Variables ../variables/Variables.py *** Keywords *** Create Network [Arguments] ${network_name} ${devstack_path}=/opt/stack/new/devstack [Documentation] Create Network with neutron request. ${output}= Write Commands Until Prompt cd ${devstack_path} && cat localrc Log ${output} ${output}= Write Commands Until Prompt source openrc admin admin Log ${output} ${output}= Write Commands Until Prompt neutron -v net-create ${network_name} Log ${output} Should Contain ${output} Created a new network Delete Network [Arguments] ${network_name} [Documentation] Delete Network with neutron request. ${output}= Write Commands Until Prompt neutron -v net-delete ${network_name} Log ${output} Should Contain ${output} Deleted network: ${network_name} Create SubNet [Arguments] ${network_name} ${subnet} ${range_ip} [Documentation] Create SubNet for the Network with neutron request. ${output}= Write Commands Until Prompt neutron -v subnet-create ${network_name} ${range_ip} --name ${subnet} Log ${output} Should Contain ${output} Created a new subnet Verify Gateway Ips [Documentation] Verifies the Gateway Ips with dump flow. ${output}= Write Commands Until Prompt sudo ovs-ofctl -O OpenFlow13 dump-flows br-int Log ${output} : FOR ${GatewayIpElement} IN @{GATEWAY_IPS} \ Should Contain ${output} ${GatewayIpElement} Verify Dhcp Ips [Documentation] Verifies the Dhcp Ips with dump flow. ${output}= Write Commands Until Prompt sudo ovs-ofctl -O OpenFlow13 dump-flows br-int Log ${output} : FOR ${DhcpIpElement} IN @{DHCP_IPS} \ Should Contain ${output} ${DhcpIpElement} Verify No Dhcp Ips [Documentation] Verifies the Dhcp Ips with dump flow. ${output}= Write Commands Until Prompt sudo ovs-ofctl -O OpenFlow13 dump-flows br-int Log ${output} : FOR ${DhcpIpElement} IN @{DHCP_IPS} \ Should Not Contain ${output} ${DhcpIpElement} Delete SubNet [Arguments] ${subnet} [Documentation] Delete SubNet for the Network with neutron request. Log ${subnet} ${output}= Write Commands Until Prompt neutron -v subnet-delete ${subnet} Log ${output} Should Contain ${output} Deleted subnet: ${subnet} Verify No Gateway Ips [Documentation] Verifies the Gateway Ips removed with dump flow. ${output}= Write Commands Until Prompt sudo ovs-ofctl -O OpenFlow13 dump-flows br-int Log ${output} : FOR ${GatewayIpElement} IN @{GATEWAY_IPS} \ Should Not Contain ${output} ${GatewayIpElement} Create Vm Instance [Arguments] ${net_id} ${network_name} [Documentation] Create Vm Instance with the net id of the Netowrk. ${VmElement}= Set Variable If "${network_name}"=="net1_network" MyFirstInstance MySecondInstance ${output}= Write Commands Until Prompt nova boot --image cirros-0.3.4-x86_64-uec --flavor m1.tiny --nic net-id=${net_id} ${VmElement} Log ${output} Delete Vm Instance [Arguments] ${vm_name} [Documentation] Delete Vm instances using instance names. ${output}= Write Commands Until Prompt nova delete ${vm_name} Log ${output} Get Net Id [Arguments] ${network_name} [Documentation] Retrieve the net id for the given network name to create specific vm instance ${output}= Write Commands Until Prompt neutron net-list | grep "${network_name}" | get_field 1 Log ${output} ${splitted_output}= Split String ${output} ${EMPTY} ${net_id}= Get from List ${splitted_output} 0 Log ${net_id} [Return] ${net_id} Create Vm Instances [Arguments] ${net_id} ${vm_instance_names} ${image}=cirros-0.3.4-x86_64-uec ${flavor}=m1.tiny [Documentation] Create Four Vm Instance with the net id of the Netowrk. : FOR ${VmElement} IN @{vm_instance_names} \ ${output}= Write Commands Until Prompt nova boot --image ${image} --flavor ${flavor} --nic net-id=${net_id} ${VmElement} \ Log ${output} View Vm Console [Arguments] ${vm_instance_names} [Documentation] View Console log of the created vm instances using nova show. : FOR ${VmElement} IN @{vm_instance_names} \ ${output}= Write Commands Until Prompt nova show ${VmElement} \ Log ${output} \ ${output}= Write Commands Until Prompt nova console-log ${VmElement} \ Log ${output} Ping Vm From DHCP Namespace [Arguments] ${net_id} ${vm_ip} [Documentation] Reach all Vm Instance with the net id of the Netowrk. Log ${vm_ip} ${output}= Write Commands Until Prompt sudo ip netns exec qdhcp-${net_id} ping -c 3 ${vm_ip} 20s Log ${output} [Return] ${output} Ping From Instance [Arguments] ${dest_vm} [Documentation] Ping to the expected destination ip. ${output}= Write Commands Until Expected Prompt ping -c 3 ${dest_vm} $ Log ${output} [Return] ${output} Curl Metadata Server [Documentation] Ping to the expected destination ip. ${output}= Write Commands Until Expected Prompt curl -i http://169.254.169.254 $ Write Commands Until Prompt exit Should Contain ${output} 200 Close Vm Instance [Documentation] Exit the vm instance. ${output}= Write Commands Until Prompt exit Log ${output} Ssh Vm Instance [Arguments] ${net_id} ${vm_ip} ${user}=cirros ${password}=cubswin:) ${key_file}=test.pem [Documentation] Login to the vm instance using ssh in the network. ${output}= Write Commands Until Expected Prompt sudo ip netns exec qdhcp-${net_id} ssh -i ${key_file} ${user}@${vm_ip} (yes/no)? Log ${output} ${output}= Write Commands Until Expected Prompt yes d: Log ${output} ${output}= Write Commands Until Expected Prompt ${password} $ Log ${output} ${output}= Write Commands Until Expected Prompt ifconfig $ Log ${output} ${output}= Write Commands Until Expected Prompt route $ Log ${output} Create Router [Arguments] ${router_name} [Documentation] Create Router and Add Interface to the subnets. ${output}= Write Commands Until Prompt neutron -v router-create ${router_name} Should Contain ${output} Created a new router Add Router Interface [Arguments] ${router_name} ${interface_name} ${output}= Write Commands Until Prompt neutron -v router-interface-add ${router_name} ${interface_name} Should Contain ${output} Added interface Remove Interface [Arguments] ${router_name} ${interface_name} [Documentation] Remove Interface to the subnets. ${output}= Write Commands Until Prompt neutron -v router-interface-delete ${router_name} ${interface_name} Should Contain ${output} Removed interface from router Delete Router [Arguments] ${router_name} [Documentation] Delete Router and Interface to the subnets. ${output}= Write Commands Until Prompt neutron -v router-delete ${router_name} Should Contain ${output} Deleted router: Show Debugs [Arguments] ${vm_indices} [Documentation] Run these commands for debugging, it can list state of VM instances and ip information in control node ${output}= Write Commands Until Prompt sudo ip netns list Log ${output} : FOR ${index} IN @{vm_indices} \ ${output}= Write Commands Until Prompt nova show ${index} \ Log ${output}