Merge "Integrate md-sal port model and add more port E2E tests"
[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 = "{\"port\": {\"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         ITNeutronE2E.test_create(url, content, "Router Interface Port Post Failed NB");
62     }
63
64     public void bulk_port_create_test() {
65         String url = base + "/ports";
66         String content = "{ \"ports\": [ { "
67             + " \"status\": \"DOWN\", "
68             + " \"name\": \"sample_port_1\", "
69             + " \"allowed_address_pairs\": [], "
70             + " \"admin_state_up\": false, "
71             + " \"network_id\": \"4e8e5957-649f-477b-9e5b-f1f75b21c03c\", "
72             + " \"tenant_id\": \"d6700c0c9ffa4f1cb322cd4a1f3906fa\", "
73             + " \"device_owner\": \"\", "
74             + " \"mac_address\": \"fa:16:3e:48:b8:9f\", "
75             + " \"fixed_ips\": [ { "
76             + "\"subnet_id\": \"3b80198d-4f7b-4f77-9ef5-774d54e17126\","
77             + " \"ip_address\": \"10.0.0.5\" } ], "
78             + " \"id\": \"94225baa-9d3f-4b93-bf12-b41e7ce49cdb\", "
79             + " \"security_groups\": [], "
80             + " \"device_id\": \"\" }, { "
81             + " \"status\": \"DOWN\", "
82             + " \"name\": \"sample_port_2\", "
83             + " \"allowed_address_pairs\": [], "
84             + " \"admin_state_up\": false, "
85             + " \"network_id\": \"4e8e5957-649f-477b-9e5b-f1f75b21c03c\", "
86             + " \"tenant_id\": \"d6700c0c9ffa4f1cb322cd4a1f3906fa\", "
87             + " \"device_owner\": \"\", "
88             + " \"mac_address\": \"fa:16:3e:f4:73:df\", "
89             + " \"fixed_ips\": [ { "
90             + "\"subnet_id\": \"3b80198d-4f7b-4f77-9ef5-774d54e17126\","
91             + " \"ip_address\": \"10.0.0.6\" } ], "
92             + " \"id\": \"43c831e0-19ce-4a76-9a49-57b57e69428b\", "
93             + " \"security_groups\": [], "
94             + " \"device_id\": \"\" } ] } ";
95         ITNeutronE2E.test_create(url, content, "Bulk Subnet Post Failed");
96     }
97
98     public void port_update_test() {
99         String url = base + "/ports/43c831e0-19ce-4a76-9a49-57b57e69428b";
100         String content = " { \"port\": { "
101         + " \"status\": \"DOWN\", "
102         + " \"binding:host_id\": \"test_for_port_update_host\", "
103         + " \"allowed_address_pairs\": [], "
104         + " \"extra_dhcp_opts\": [], "
105         + " \"device_owner\": \"compute:nova\", "
106         + " \"binding:profile\": {}, "
107         + " \"fixed_ips\": [ { "
108         + "\"subnet_id\": \"3b80198d-4f7b-4f77-9ef5-774d54e17126\","
109         + " \"ip_address\": \"10.0.0.7\" } ], "
110         + " \"id\": \"43c831e0-19ce-4a76-9a49-57b57e69428b\", "
111         + " \"security_groups\": [], "
112         + " \"device_id\": \"\", "
113         + " \"name\": \"test-for-port-update\", "
114         + " \"admin_state_up\": true, "
115         + " \"network_id\": \"4e8e5957-649f-477b-9e5b-f1f75b21c03c\", "
116         + " \"tenant_id\": \"522eda8d23124b25bf03fe44f1986b74\", "
117         + " \"binding:vif_details\": {}, "
118         + " \"binding:vnic_type\": \"normal\", "
119         + " \"binding:vif_type\": \"binding_failed\", "
120         + " \"mac_address\": \"fa:16:3e:11:11:5e\" } } ";
121         ITNeutronE2E.test_modify(url, content,"Subnet Put Failed");
122     }
123
124     public void port_element_get_test() {
125         String url = base + "/ports/43c831e0-19ce-4a76-9a49-57b57e69428b";
126         ITNeutronE2E.test_fetch(url, true, "Subnet Element Get Failed");
127     }
128
129     public void port_delete_test() {
130         String url = base + "/ports/43c831e0-19ce-4a76-9a49-57b57e69428b";
131         ITNeutronE2E.test_delete(url, "Subnet Element Delete Failed");
132     }
133
134     public void port_element_negative_get_test() {
135         String url = base + "/ports/43c831e0-19ce-4a76-9a49-57b57e69428b";
136         ITNeutronE2E.test_fetch(url, false, "Subnet Element Get Failed");
137     }
138 }