Tidied updated test suites
[integration/test.git] / csit / libraries / OpenStackOperations.robot
1 *** Settings ***
2 Documentation     Netvirt library. This library is useful for tests to create network, subnet, router and vm instances
3 Library           SSHLibrary
4 Resource          Utils.robot
5 Variables         ../variables/Variables.py
6
7 *** Keywords ***
8 Create Network
9     [Arguments]    ${network_name}
10     [Documentation]    Create Network with neutron request.
11     ${output}=    Write Commands Until Prompt    cd /opt/stack/new/devstack && cat localrc
12     Log    ${output}
13     ${output}=    Write Commands Until Prompt    source openrc admin admin
14     Log    ${output}
15     ${output}=    Write Commands Until Prompt    neutron -v net-create ${network_name}
16     Log    ${output}
17     Should Contain    ${output}    Created a new network
18
19 Delete Network
20     [Arguments]    ${network_name}
21     [Documentation]    Delete Network with neutron request.
22     ${output}=    Write Commands Until Prompt    neutron -v net-delete ${network_name}
23     Log    ${output}
24     Should Contain    ${output}    Deleted network: ${network_name}
25
26 Create SubNet
27     [Arguments]    ${network_name}
28     [Documentation]    Create SubNet for the Network with neutron request.
29     ${subnet}=    Set Variable If    "${network_name}"=="net1_network"    subnet1    subnet2
30     ${range_ip}=    Set Variable If    "${network_name}"=="net1_network"    10.0.0.0/24    20.0.0.0/24
31     ${output}=    Write Commands Until Prompt    neutron -v subnet-create ${network_name} ${range_ip} --name ${subnet}
32     Log    ${output}
33     Should Contain    ${output}    Created a new subnet
34
35 Verify Gateway Ips
36     [Documentation]    Verifies the Gateway Ips with dump flow.
37     ${output}=    Write Commands Until Prompt    sudo ovs-ofctl -O OpenFlow13 dump-flows br-int
38     Log    ${output}
39     : FOR    ${GatewayIpElement}    IN    @{GATEWAY_IPS}
40     \    Should Contain    ${output}    ${GatewayIpElement}
41
42 Verify Dhcp Ips
43     [Documentation]    Verifies the Dhcp Ips with dump flow.
44     ${output}=    Write Commands Until Prompt    sudo ovs-ofctl -O OpenFlow13 dump-flows br-int
45     Log    ${output}
46     : FOR    ${DhcpIpElement}    IN    @{DHCP_IPS}
47     \    Should Contain    ${output}    ${DhcpIpElement}
48
49 Verify No Dhcp Ips
50     [Documentation]    Verifies the Dhcp Ips with dump flow.
51     ${output}=    Write Commands Until Prompt    sudo ovs-ofctl -O OpenFlow13 dump-flows br-int
52     Log    ${output}
53     : FOR    ${DhcpIpElement}    IN    @{DHCP_IPS}
54     \    Should Not Contain    ${output}    ${DhcpIpElement}
55
56 Delete SubNet
57     [Arguments]    ${network_name}
58     [Documentation]    Delete SubNet for the Network with neutron request.
59     ${subnet}=    Set Variable If    "${network_name}"=="net1_network"    subnet1    subnet2
60     ${output}=    Write Commands Until Prompt    neutron -v subnet-delete ${subnet}
61     Log    ${output}
62     Should Contain    ${output}    Deleted subnet: ${subnet}
63
64 Verify No Gateway Ips
65     [Documentation]    Verifies the Gateway Ips removed with dump flow.
66     ${output}=    Write Commands Until Prompt    sudo ovs-ofctl -O OpenFlow13 dump-flows br-int
67     Log    ${output}
68     : FOR    ${GatewayIpElement}    IN    @{GATEWAY_IPS}
69     \    Should Not Contain    ${output}    ${GatewayIpElement}
70
71 Create Vm Instance
72     [Arguments]    ${net_id}    ${network_name}
73     [Documentation]    Create Vm Instance with the net id of the Netowrk.
74     ${VmElement}=    Set Variable If    "${network_name}"=="net1_network"    MyFirstInstance    MySecondInstance
75     ${output}=    Write Commands Until Prompt    nova boot --image cirros-0.3.4-x86_64-uec --flavor m1.tiny --nic net-id=${net_id} ${VmElement}
76     Log    ${output}
77
78 Delete Vm Instance
79     [Arguments]    ${vm_name}
80     [Documentation]    Delete Vm instances using instance names.
81     ${output}=    Write Commands Until Prompt    nova delete ${vm_name}
82     Log    ${output}
83
84 Get Net Id
85     [Arguments]    ${network_name}
86     [Documentation]    Retrieve the net id for the given network name to create specific vm instance
87     ${output}=    Write Commands Until Prompt    neutron net-list | grep "${network_name}" | get_field 1
88     Log    ${output}
89     ${splitted_output}=    Split String    ${output}    ${EMPTY}
90     ${net_id}=    Get from List    ${splitted_output}    0
91     Log    ${net_id}
92     [Return]    ${net_id}
93
94 Create Router
95     [Documentation]    Create Router and Add Interface to the subnets.
96     ${output}=    Write Commands Until Prompt    neutron -v router-create router_1
97     Log    ${output}
98     : FOR    ${SubnetElement}    IN    @{SUBNETS_NAME}
99     \    ${output}=    Write Commands Until Prompt    neutron -v router-interface-add router_1 ${SubnetElement}
100     Log    ${output}
101
102 Remove Interface
103     [Documentation]    Remove Interface to the subnets.
104     : FOR    ${SubnetElement}    IN    @{SUBNETS_NAME}
105     \    ${output}=    Write Commands Until Prompt    neutron -v router-interface-delete router_1 ${SubnetElement}
106     \    Log    ${output}
107
108 Delete Router
109     [Documentation]    Delete Router and Interface to the subnets.
110     ${output}=    Write Commands Until Prompt    neutron -v router-delete router_1
111     Log    ${output}