920d415344593be6447e894e854785f1d5d654c4
[neutron.git] / integration / test / src / test / java / org / opendaylight / neutron / e2etest / NeutronPortTests.java
1 /*
2  * Copyright (C) 2015 IBM, Inc.
3  *
4  * This program and the accompanying materials are made available under the
5  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6  * and is available at http://www.eclipse.org/legal/epl-v10.html
7  */
8
9 package org.opendaylight.neutron.e2etest;
10
11 import java.io.OutputStreamWriter;
12
13 import java.lang.Thread;
14
15 import java.net.HttpURLConnection;
16 import java.net.URL;
17
18 import org.junit.Assert;
19
20 public class NeutronPortTests {
21     String base;
22
23     public NeutronPortTests(String base) {
24         this.base = base;
25     }
26
27     public void port_collection_get_test() {
28         String url = base + "/ports";
29         ITNeutronE2E.test_fetch(url, "Ports Collection GET failed");
30     }
31
32     //TODO handle SB check
33     public void singleton_port_create_test() {
34         String url = base + "/ports";
35         String content = "{ \"port\": { \"status\": \"DOWN\","+
36             "\"binding:host_id\": \"\","+
37             "\"name\": \"private-port\","+
38             "\"allowed_address_pairs\": [],"+
39             "\"admin_state_up\": true,"+
40             "\"network_id\": \"4e8e5957-649f-477b-9e5b-f1f75b21c03c\","+
41             "\"tenant_id\": \"9bacb3c5d39d41a79512987f338cf177\","+
42             "\"binding:vif_details\": {},"+
43             "\"binding:vnic_type\": \"normal\","+
44             "\"binding:vif_type\": \"unbound\","+
45             "\"device_owner\": \"\","+
46             "\"mac_address\": \"fa:16:3e:c9:cb:f0\","+
47             "\"binding:profile\": {},"+
48             "\"fixed_ips\": [ {"+
49                 "\"subnet_id\": \"3b80198d-4f7b-4f77-9ef5-774d54e17126\","+
50                 "\"ip_address\": \"10.0.0.2\" } ],"+
51             "\"id\": \"65c0ee9f-d634-4522-8954-51021b570b0d\","+
52             "\"security_groups\": [] ,"+
53             "\"device_id\": \"\" } }";
54         ITNeutronE2E.test_create(url, content,"Singleton Port Post Failed NB");
55     }
56
57     //TODO handle SB check
58     public void router_interface_port_create_test() {
59         String url = base + "/ports";
60         String content = "{\"ports\": [ {\"status\": \"DOWN\", \"binding:host_id\": \"\", \"allowed_address_pairs\": [], \"device_owner\": \"network:router_gateway\", \"binding:profile\": {}, \"fixed_ips\": [{\"subnet_id\": \"3b80198d-4f7b-4f77-9ef5-774d54e17126\", \"ip_address\": \"10.0.0.1\"}], \"id\": \"d8a4cc85-ad78-46ac-b5a1-8e04f16fa51e\", \"security_groups\": [], \"device_id\": \"8604a0de-7f6b-409a-a47c-a1cc7bc77b2e\", \"name\": \"\", \"admin_state_up\": true, \"network_id\": \"4e8e5957-649f-477b-9e5b-f1f75b21c03c\", \"tenant_id\": \"9bacb3c5d39d41a79512987f338cf177\", \"binding:vif_details\": {}, \"binding:vnic_type\": \"normal\", \"binding:vif_type\": \"unbound\", \"mac_address\": \"fa:16:3e:dc:1d:8d\"}, "
61             + " {\"status\": \"DOWN\", \"binding:host_id\": \"\", \"allowed_address_pairs\": [], \"device_owner\": \"network:router_gateway\", \"binding:profile\": {}, \"fixed_ips\": [{\"subnet_id\": \"3b80198d-4f7b-4f77-9ef5-774d54e17126\", \"ip_address\": \"10.0.0.2\"}], \"id\": \"d8a4cc85-ad78-46ac-b5a1-8e04f16fa51f\", \"security_groups\": [], \"device_id\": \"8604a0de-7f6b-409a-a47c-a1cc7bc77b2f\", \"name\": \"\", \"admin_state_up\": true, \"network_id\": \"4e8e5957-649f-477b-9e5b-f1f75b21c03c\", \"tenant_id\": \"9bacb3c5d39d41a79512987f338cf177\", \"binding:vif_details\": {}, \"binding:vnic_type\": \"normal\", \"binding:vif_type\": \"unbound\", \"mac_address\": \"fa:16:3e:dc:1d:8e\"} ] }";
62         ITNeutronE2E.test_create(url, content, "Router Interface Port Post Failed NB");
63     }
64
65     public void bulk_port_create_test() {
66         String url = base + "/ports";
67         String content = "{ \"ports\": [ { "
68             + " \"status\": \"DOWN\", "
69             + " \"name\": \"sample_port_1\", "
70             + " \"allowed_address_pairs\": [], "
71             + " \"admin_state_up\": false, "
72             + " \"network_id\": \"4e8e5957-649f-477b-9e5b-f1f75b21c03c\", "
73             + " \"tenant_id\": \"d6700c0c9ffa4f1cb322cd4a1f3906fa\", "
74             + " \"device_owner\": \"\", "
75             + " \"mac_address\": \"fa:16:3e:48:b8:9f\", "
76             + " \"fixed_ips\": [ { "
77             + "\"subnet_id\": \"3b80198d-4f7b-4f77-9ef5-774d54e17126\","
78             + " \"ip_address\": \"10.0.0.5\" } ], "
79             + " \"id\": \"94225baa-9d3f-4b93-bf12-b41e7ce49cdb\", "
80             + " \"security_groups\": [], "
81             + " \"device_id\": \"\" }, { "
82             + " \"status\": \"DOWN\", "
83             + " \"name\": \"sample_port_2\", "
84             + " \"allowed_address_pairs\": [], "
85             + " \"admin_state_up\": false, "
86             + " \"network_id\": \"4e8e5957-649f-477b-9e5b-f1f75b21c03c\", "
87             + " \"tenant_id\": \"d6700c0c9ffa4f1cb322cd4a1f3906fa\", "
88             + " \"device_owner\": \"\", "
89             + " \"mac_address\": \"fa:16:3e:f4:73:df\", "
90             + " \"fixed_ips\": [ { "
91             + "\"subnet_id\": \"3b80198d-4f7b-4f77-9ef5-774d54e17126\","
92             + " \"ip_address\": \"10.0.0.6\" } ], "
93             + " \"id\": \"43c831e0-19ce-4a76-9a49-57b57e69428b\", "
94             + " \"security_groups\": [], "
95             + " \"device_id\": \"\" } ] } ";
96         ITNeutronE2E.test_create(url, content, "Bulk Port Post Failed");
97     }
98
99     public void port_update_test() {
100         String url = base + "/ports/43c831e0-19ce-4a76-9a49-57b57e69428b";
101         String content = " { \"port\": { "
102         + " \"status\": \"DOWN\", "
103         + " \"binding:host_id\": \"00000000-1111-2222-3333-444444444444\", "
104         + " \"allowed_address_pairs\": [], "
105         + " \"extra_dhcp_opts\": [], "
106         + " \"device_owner\": \"compute:nova\", "
107         + " \"binding:profile\": {}, "
108         + " \"fixed_ips\": [ { "
109         + "\"subnet_id\": \"3b80198d-4f7b-4f77-9ef5-774d54e17126\","
110         + " \"ip_address\": \"10.0.0.7\" } ], "
111         + " \"id\": \"43c831e0-19ce-4a76-9a49-57b57e69428b\", "
112         + " \"security_groups\": [], "
113         + " \"device_id\": \"\", "
114         + " \"name\": \"test-for-port-update\", "
115         + " \"admin_state_up\": true, "
116         + " \"network_id\": \"4e8e5957-649f-477b-9e5b-f1f75b21c03c\", "
117         + " \"tenant_id\": \"522eda8d23124b25bf03fe44f1986b74\", "
118         + " \"binding:vif_details\": {}, "
119         + " \"binding:vnic_type\": \"normal\", "
120         + " \"binding:vif_type\": \"binding_failed\", "
121         + " \"mac_address\": \"fa:16:3e:11:11:5e\" } } ";
122         ITNeutronE2E.test_modify(url, content,"Port Put Failed");
123     }
124
125     public void port_element_get_test() {
126         String url = base + "/ports/43c831e0-19ce-4a76-9a49-57b57e69428b";
127         ITNeutronE2E.test_fetch(url, true, "Port Element Get Failed");
128     }
129
130     public void port_delete_test() {
131         String url = base + "/ports/43c831e0-19ce-4a76-9a49-57b57e69428b";
132         ITNeutronE2E.test_delete(url, "Port Element Delete Failed");
133     }
134
135     public void port_element_negative_get_test() {
136         String url = base + "/ports/43c831e0-19ce-4a76-9a49-57b57e69428b";
137         ITNeutronE2E.test_fetch(url, false, "Port Element Get Failed");
138     }
139
140     public static void runTests(String base) {
141         NeutronPortTests port_tester = new NeutronPortTests(base);
142         port_tester.port_collection_get_test();
143         port_tester.singleton_port_create_test();
144         port_tester.router_interface_port_create_test(); //needed for router test
145         port_tester.bulk_port_create_test();
146         port_tester.port_update_test();
147         port_tester.port_element_get_test();
148         port_tester.port_delete_test();
149         port_tester.port_element_negative_get_test();
150     }
151 }