Skip to content

Commit b1c7e61

Browse files
committed
add missing integration tests
1 parent cf78b95 commit b1c7e61

4 files changed

Lines changed: 134 additions & 23 deletions

File tree

‎openstackclient/network/v2_0/network.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ def get_parser(self, prog_name):
123123
class RemoveGatewayNetwork(v2_0.RemoveCommand):
124124
"""Remove a gateway from a network"""
125125

126-
clazz = nvpnetworkgateway.ConnectNetworkGateway
126+
clazz = nvpnetworkgateway.DisconnectNetworkGateway
127127
container_name = "network_id"
128128
container_metavar = "<network_id>"
129129
container_help_text = "ID of the internal network"

‎openstackclient/tests/network/v2_0/test_network_integration.py‎

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ class TestNetworkIntegration(common.TestIntegrationBase):
2323
HOSTESS = common.TestIntegrationBase.HOST + common.TestIntegrationBase.VER
2424
SUBNETS_URL = HOSTESS + "/subnets.json"
2525
SUBNETS_ONE = '{ "subnets": [{ "id": "12312311" }]}'
26+
GATEWAY_URL = HOSTESS + "/network-gateways.json"
27+
GATEWAY_ONE = '{ "network_gateways": [{ "id": "88888888" }]}'
2628
CREATE_URL = HOSTESS + "/networks.json"
2729
CREATE = """
2830
{
@@ -62,6 +64,11 @@ class TestNetworkIntegration(common.TestIntegrationBase):
6264
}"""
6365
SHOW_URL = HOSTESS + "/networks/a9254bdb.json"
6466
SHOW = CREATE
67+
CONNECT_URL = HOSTESS + "/network-gateways/88888888/connect_network.json"
68+
CONNECT = "{}"
69+
DISCONNECT_URL = HOSTESS + \
70+
"/network-gateways/88888888/disconnect_network.json"
71+
DISCONNECT = "{}"
6572

6673
@httpretty.activate
6774
def test_create(self):
@@ -155,3 +162,39 @@ def test_show(self):
155162
status="ACTIVE"
156163
tenant_id="33a40233"
157164
""", self.stdout())
165+
166+
@httpretty.activate
167+
def test_add_gateway(self):
168+
pargs = common.FakeParsedArgs()
169+
pargs.network_id = 'gator'
170+
pargs.net_gateway_id = 'way'
171+
pargs.segmentation_type = None
172+
pargs.segmentation_id = None
173+
httpretty.register_uri(httpretty.GET, self.GATEWAY_URL,
174+
body=self.GATEWAY_ONE)
175+
httpretty.register_uri(httpretty.GET, self.LIST_URL,
176+
body=self.LIST_ONE)
177+
httpretty.register_uri(httpretty.PUT, self.CONNECT_URL,
178+
body=self.CONNECT)
179+
self.when_run(network.AddGatewayNetwork, pargs)
180+
self.assertEqual('', self.stderr())
181+
self.assertEqual(u'Connected network to gateway 88888888\n',
182+
self.stdout())
183+
184+
@httpretty.activate
185+
def test_remove_gateway(self):
186+
pargs = common.FakeParsedArgs()
187+
pargs.network_id = 'gator'
188+
pargs.net_gateway_id = 'way'
189+
pargs.segmentation_type = None
190+
pargs.segmentation_id = None
191+
httpretty.register_uri(httpretty.GET, self.GATEWAY_URL,
192+
body=self.GATEWAY_ONE)
193+
httpretty.register_uri(httpretty.GET, self.LIST_URL,
194+
body=self.LIST_ONE)
195+
httpretty.register_uri(httpretty.PUT, self.DISCONNECT_URL,
196+
body=self.DISCONNECT)
197+
self.when_run(network.RemoveGatewayNetwork, pargs)
198+
self.assertEqual('', self.stderr())
199+
self.assertEqual(u'Disconnected network from gateway 88888888\n',
200+
self.stdout())

‎openstackclient/tests/network/v2_0/test_port_integration.py‎

Lines changed: 36 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ class TestPortIntegration(common.TestIntegrationBase):
3131
"port":
3232
{
3333
"status": "ACTIVE",
34-
"name": "gator",
34+
"name": "puerto",
3535
"tenant_id": "33a40233",
3636
"id": "a9254bdb"
3737
}
@@ -45,7 +45,7 @@ class TestPortIntegration(common.TestIntegrationBase):
4545
"ports": [
4646
{
4747
"status": "ACTIVE",
48-
"name": "gator",
48+
"name": "puerto",
4949
"tenant_id": "33a40233",
5050
"id": "a9254bdb"
5151
},
@@ -59,11 +59,13 @@ class TestPortIntegration(common.TestIntegrationBase):
5959
}"""
6060
SHOW_URL = HOSTESS + "/ports/a9254bdb.json"
6161
SHOW = CREATE
62+
ADD_REMOVE_URL = HOSTESS + "/floatingips/127.0.0.1.json"
63+
ADD_REMOVE = "{}"
6264

6365
@httpretty.activate
6466
def test_create(self):
6567
pargs = common.FakeParsedArgs()
66-
pargs.name = 'gator'
68+
pargs.name = 'puerto'
6769
pargs.network_id = '44444448'
6870
pargs.admin_state = 'UP'
6971
pargs.mac_address = '1231233212'
@@ -82,22 +84,22 @@ def test_create(self):
8284
self.assertEqual(u"""\
8385
Created a new port:
8486
id="a9254bdb"
85-
name="gator"
87+
name="puerto"
8688
status="ACTIVE"
8789
tenant_id="33a40233"
8890
""", self.stdout())
8991

9092
@httpretty.activate
9193
def test_delete(self):
9294
pargs = common.FakeParsedArgs()
93-
pargs.id = 'gator'
95+
pargs.id = 'puerto'
9496
httpretty.register_uri(httpretty.GET, self.LIST_URL,
9597
body=self.LIST_ONE)
9698
httpretty.register_uri(httpretty.DELETE, self.DELETE_URL,
9799
body=self.DELETE)
98100
self.when_run(port.DeletePort, pargs)
99101
self.assertEqual('', self.stderr())
100-
self.assertEqual(u'Deleted port: gator\n',
102+
self.assertEqual(u'Deleted port: puerto\n',
101103
self.stdout())
102104

103105
@httpretty.activate
@@ -116,14 +118,14 @@ def test_list(self):
116118
self.assertEqual('', self.stderr())
117119
self.assertEqual("""\
118120
id,name
119-
a9254bdb,gator
121+
a9254bdb,puerto
120122
b8408dgd,croc
121123
""", self.stdout())
122124

123125
@httpretty.activate
124126
def test_set(self):
125127
pargs = common.FakeParsedArgs()
126-
pargs.name = 'gator'
128+
pargs.name = 'puerto'
127129
httpretty.register_uri(httpretty.GET, self.LIST_URL,
128130
body=self.LIST_ONE)
129131
self.when_run(port.SetPort, pargs)
@@ -133,7 +135,7 @@ def test_set(self):
133135
@httpretty.activate
134136
def test_show(self):
135137
pargs = common.FakeParsedArgs()
136-
pargs.id = 'gator'
138+
pargs.id = 'puerto'
137139
httpretty.register_uri(httpretty.GET, self.LIST_URL,
138140
body=self.LIST_ONE)
139141
httpretty.register_uri(httpretty.GET, self.SHOW_URL,
@@ -142,7 +144,31 @@ def test_show(self):
142144
self.assertEqual('', self.stderr())
143145
self.assertEqual(u"""\
144146
id="a9254bdb"
145-
name="gator"
147+
name="puerto"
146148
status="ACTIVE"
147149
tenant_id="33a40233"
148150
""", self.stdout())
151+
152+
@httpretty.activate
153+
def test_add(self):
154+
pargs = common.FakeParsedArgs()
155+
pargs.port_id = 'puerto'
156+
pargs.floatingip_id = '127.0.0.1'
157+
pargs.fixed_ip_address = None
158+
httpretty.register_uri(httpretty.PUT, self.ADD_REMOVE_URL,
159+
body=self.ADD_REMOVE)
160+
self.when_run(port.AddPort, pargs)
161+
self.assertEqual('', self.stderr())
162+
self.assertEqual(u'Associated floatingip 127.0.0.1\n', self.stdout())
163+
164+
@httpretty.activate
165+
def test_remove(self):
166+
pargs = common.FakeParsedArgs()
167+
pargs.port_id = 'puerto'
168+
pargs.floatingip_id = '127.0.0.1'
169+
httpretty.register_uri(httpretty.PUT, self.ADD_REMOVE_URL,
170+
body=self.ADD_REMOVE)
171+
self.when_run(port.RemovePort, pargs)
172+
self.assertEqual('', self.stderr())
173+
self.assertEqual(u'Disassociated floatingip 127.0.0.1\n',
174+
self.stdout())

‎openstackclient/tests/network/v2_0/test_router_integration.py‎

Lines changed: 54 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,15 @@
2121

2222
class TestShowRouterIntegration(common.TestIntegrationBase):
2323
HOSTESS = common.TestIntegrationBase.HOST + common.TestIntegrationBase.VER
24+
SUBNET_URL = HOSTESS + "/subnets.json"
25+
SUBNET_ONE = '{ "subnets": [{ "id": "45456777" }] }'
2426
CREATE_URL = HOSTESS + "/routers.json"
2527
CREATE = """
2628
{
2729
"router":
2830
{
2931
"status": "ACTIVE",
30-
"name": "gator",
32+
"name": "rooty",
3133
"tenant_id": "33a40233",
3234
"id": "a9254bdb"
3335
}
@@ -41,7 +43,7 @@ class TestShowRouterIntegration(common.TestIntegrationBase):
4143
"routers": [
4244
{
4345
"status": "ACTIVE",
44-
"name": "gator",
46+
"name": "rooty",
4547
"tenant_id": "33a40233",
4648
"id": "a9254bdb"
4749
},
@@ -60,7 +62,7 @@ class TestShowRouterIntegration(common.TestIntegrationBase):
6062
{
6163
"status": "ACTIVE",
6264
"external_gateway_info": {},
63-
"name": "gator",
65+
"name": "rooty",
6466
"admin_state_up": true,
6567
"tenant_id": "3671f46ec35e4bbca6ef92ab7975e463",
6668
"routes": [],
@@ -70,11 +72,19 @@ class TestShowRouterIntegration(common.TestIntegrationBase):
7072
}"""
7173
SHOW_URL = HOSTESS + "/routers/a9254bdb.json"
7274
SHOW = CREATE
75+
ADD_URL = HOSTESS + "/routers/a9254bdb/add_router_interface.json"
76+
ADD = """
77+
{
78+
"subnet_id": "45456777",
79+
"port_id": "93939392"
80+
}"""
81+
REMOVE_URL = HOSTESS + "/routers/a9254bdb/remove_router_interface.json"
82+
REMOVE = "{}"
7383

7484
@httpretty.activate
7585
def test_create(self):
7686
pargs = common.FakeParsedArgs()
77-
pargs.name = 'gator'
87+
pargs.name = 'rooty'
7888
pargs.admin_state = 'ACTIVE'
7989
pargs.tenant_id = '33a40233'
8090
httpretty.register_uri(httpretty.POST, self.CREATE_URL,
@@ -84,22 +94,22 @@ def test_create(self):
8494
self.assertEqual(u"""\
8595
Created a new router:
8696
id="a9254bdb"
87-
name="gator"
97+
name="rooty"
8898
status="ACTIVE"
8999
tenant_id="33a40233"
90100
""", self.stdout())
91101

92102
@httpretty.activate
93103
def test_delete(self):
94104
pargs = common.FakeParsedArgs()
95-
pargs.id = 'gator'
105+
pargs.id = 'rooty'
96106
httpretty.register_uri(httpretty.GET, self.LIST_URL,
97107
body=self.LIST_ONE)
98108
httpretty.register_uri(httpretty.DELETE, self.DELETE_URL,
99109
body=self.DELETE)
100110
self.when_run(router.DeleteRouter, pargs)
101111
self.assertEqual('', self.stderr())
102-
self.assertEqual(u'Deleted router: gator\n',
112+
self.assertEqual(u'Deleted router: rooty\n',
103113
self.stdout())
104114

105115
@httpretty.activate
@@ -113,7 +123,7 @@ def test_list(self):
113123
self.assertEqual('', self.stderr())
114124
self.assertEqual("""\
115125
id,name
116-
a9254bdb,gator
126+
a9254bdb,rooty
117127
b8408dgd,croc
118128
""", self.stdout())
119129

@@ -128,13 +138,13 @@ def test_list_l3(self):
128138
self.assertEqual('', self.stderr())
129139
self.assertEqual("""\
130140
id,name,external_gateway_info
131-
8eef2388,gator,{}
141+
8eef2388,rooty,{}
132142
""", self.stdout())
133143

134144
@httpretty.activate
135145
def test_set(self):
136146
pargs = common.FakeParsedArgs()
137-
pargs.name = 'gator'
147+
pargs.name = 'rooty'
138148
pargs.router_id = '88888823'
139149
pargs.no_gateway = True
140150
httpretty.register_uri(httpretty.GET, self.LIST_URL,
@@ -149,7 +159,7 @@ def test_set(self):
149159
@httpretty.activate
150160
def test_show(self):
151161
pargs = common.FakeParsedArgs()
152-
pargs.id = 'gator'
162+
pargs.id = 'rooty'
153163
httpretty.register_uri(httpretty.GET, self.LIST_URL,
154164
body=self.LIST_ONE)
155165
httpretty.register_uri(httpretty.GET, self.SHOW_URL,
@@ -158,7 +168,39 @@ def test_show(self):
158168
self.assertEqual('', self.stderr())
159169
self.assertEqual(u"""\
160170
id="a9254bdb"
161-
name="gator"
171+
name="rooty"
162172
status="ACTIVE"
163173
tenant_id="33a40233"
164174
""", self.stdout())
175+
176+
@httpretty.activate
177+
def test_add(self):
178+
pargs = common.FakeParsedArgs()
179+
pargs.router_id = 'rooty'
180+
pargs.interface = 'subby'
181+
httpretty.register_uri(httpretty.GET, self.LIST_URL,
182+
body=self.LIST_ONE)
183+
httpretty.register_uri(httpretty.GET, self.SUBNET_URL,
184+
body=self.SUBNET_ONE)
185+
httpretty.register_uri(httpretty.PUT, self.ADD_URL,
186+
body=self.ADD)
187+
self.when_run(router.AddInterfaceRouter, pargs)
188+
self.assertEqual('', self.stderr())
189+
self.assertEqual(u'Added interface 93939392 to router rooty.\n',
190+
self.stdout())
191+
192+
@httpretty.activate
193+
def test_remove(self):
194+
pargs = common.FakeParsedArgs()
195+
pargs.router_id = 'rooty'
196+
pargs.interface = 'subby'
197+
httpretty.register_uri(httpretty.GET, self.LIST_URL,
198+
body=self.LIST_ONE)
199+
httpretty.register_uri(httpretty.GET, self.SUBNET_URL,
200+
body=self.SUBNET_ONE)
201+
httpretty.register_uri(httpretty.PUT, self.REMOVE_URL,
202+
body=self.REMOVE)
203+
self.when_run(router.RemoveInterfaceRouter, pargs)
204+
self.assertEqual('', self.stderr())
205+
self.assertEqual(u'Removed interface from router rooty.\n',
206+
self.stdout())

0 commit comments

Comments
 (0)