|
| 1 | +# Copyright 2013 OpenStack, LLC. |
| 2 | +# |
| 3 | +# Licensed under the Apache License, Version 2.0 (the "License"); you may |
| 4 | +# not use this file except in compliance with the License. You may obtain |
| 5 | +# a copy of the License at |
| 6 | +# |
| 7 | +# http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | +# |
| 9 | +# Unless required by applicable law or agreed to in writing, software |
| 10 | +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT |
| 11 | +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the |
| 12 | +# License for the specific language governing permissions and limitations |
| 13 | +# under the License. |
| 14 | +# |
| 15 | + |
| 16 | +import httpretty |
| 17 | + |
| 18 | +from openstackclient.network.v2_0 import port |
| 19 | +from openstackclient.tests.network.v2_0 import common |
| 20 | + |
| 21 | + |
| 22 | +class TestPortIntegration(common.TestIntegrationBase): |
| 23 | + HOSTESS = common.TestIntegrationBase.HOST + common.TestIntegrationBase.VER |
| 24 | + NETWORK_URL = HOSTESS + "/networks.json" |
| 25 | + NETWORK = '{ "networks": [{ "id": "1111111" }] }' |
| 26 | + ROUTER_URL = HOSTESS + "/routers.json" |
| 27 | + ROUTER = '{ "routers": [{ "id": "22222222" }] }' |
| 28 | + CREATE_URL = HOSTESS + "/ports.json" |
| 29 | + CREATE = """ |
| 30 | +{ |
| 31 | + "port": |
| 32 | + { |
| 33 | + "status": "ACTIVE", |
| 34 | + "name": "gator", |
| 35 | + "tenant_id": "33a40233", |
| 36 | + "id": "a9254bdb" |
| 37 | + } |
| 38 | +}""" |
| 39 | + DELETE_URL = HOSTESS + "/ports/a9254bdb.json" |
| 40 | + DELETE = "{}" |
| 41 | + LIST_URL = HOSTESS + "/ports.json" |
| 42 | + LIST_ONE = '{ "ports": [{ "id": "a9254bdb" }] }' |
| 43 | + LIST = """ |
| 44 | +{ |
| 45 | + "ports": [ |
| 46 | + { |
| 47 | + "status": "ACTIVE", |
| 48 | + "name": "gator", |
| 49 | + "tenant_id": "33a40233", |
| 50 | + "id": "a9254bdb" |
| 51 | + }, |
| 52 | + { |
| 53 | + "status": "ACTIVE", |
| 54 | + "name": "croc", |
| 55 | + "tenant_id": "33a40233", |
| 56 | + "id": "b8408dgd" |
| 57 | + } |
| 58 | + ] |
| 59 | +}""" |
| 60 | + SHOW_URL = HOSTESS + "/ports/a9254bdb.json" |
| 61 | + SHOW = CREATE |
| 62 | + |
| 63 | + @httpretty.activate |
| 64 | + def test_create(self): |
| 65 | + pargs = common.FakeParsedArgs() |
| 66 | + pargs.name = 'gator' |
| 67 | + pargs.network_id = '44444448' |
| 68 | + pargs.admin_state = 'UP' |
| 69 | + pargs.mac_address = '1231233212' |
| 70 | + pargs.device_id = '1231231237' |
| 71 | + pargs.fixed_ip = None |
| 72 | + pargs.security_groups = None |
| 73 | + pargs.no_security_groups = False |
| 74 | + pargs.extra_dhcp_opts = None |
| 75 | + pargs.tenant_id = '33a40233' |
| 76 | + httpretty.register_uri(httpretty.GET, self.NETWORK_URL, |
| 77 | + body=self.NETWORK) |
| 78 | + httpretty.register_uri(httpretty.POST, self.CREATE_URL, |
| 79 | + body=self.CREATE) |
| 80 | + self.when_run(port.CreatePort, pargs) |
| 81 | + self.assertEqual('', self.stderr()) |
| 82 | + self.assertEqual(u"""\ |
| 83 | +Created a new port: |
| 84 | +id="a9254bdb" |
| 85 | +name="gator" |
| 86 | +status="ACTIVE" |
| 87 | +tenant_id="33a40233" |
| 88 | +""", self.stdout()) |
| 89 | + |
| 90 | + @httpretty.activate |
| 91 | + def test_delete(self): |
| 92 | + pargs = common.FakeParsedArgs() |
| 93 | + pargs.id = 'gator' |
| 94 | + httpretty.register_uri(httpretty.GET, self.LIST_URL, |
| 95 | + body=self.LIST_ONE) |
| 96 | + httpretty.register_uri(httpretty.DELETE, self.DELETE_URL, |
| 97 | + body=self.DELETE) |
| 98 | + self.when_run(port.DeletePort, pargs) |
| 99 | + self.assertEqual('', self.stderr()) |
| 100 | + self.assertEqual(u'Deleted port: gator\n', |
| 101 | + self.stdout()) |
| 102 | + |
| 103 | + @httpretty.activate |
| 104 | + def test_list(self): |
| 105 | + pargs = common.FakeParsedArgs() |
| 106 | + pargs.router = 'roo' |
| 107 | + pargs.page_size = None |
| 108 | + pargs.sort_key = [] |
| 109 | + pargs.sort_dir = [] |
| 110 | + pargs.formatter = 'csv' |
| 111 | + httpretty.register_uri(httpretty.GET, self.ROUTER_URL, |
| 112 | + body=self.ROUTER) |
| 113 | + httpretty.register_uri(httpretty.GET, self.LIST_URL, |
| 114 | + body=self.LIST) |
| 115 | + self.when_run(port.ListPort, pargs) |
| 116 | + self.assertEqual('', self.stderr()) |
| 117 | + self.assertEqual("""\ |
| 118 | +id,name |
| 119 | +a9254bdb,gator |
| 120 | +b8408dgd,croc |
| 121 | +""", self.stdout()) |
| 122 | + |
| 123 | + @httpretty.activate |
| 124 | + def test_set(self): |
| 125 | + pargs = common.FakeParsedArgs() |
| 126 | + pargs.name = 'gator' |
| 127 | + httpretty.register_uri(httpretty.GET, self.LIST_URL, |
| 128 | + body=self.LIST_ONE) |
| 129 | + self.when_run(port.SetPort, pargs) |
| 130 | + self.assertEqual('', self.stderr()) |
| 131 | + self.assertEqual('', self.stdout()) |
| 132 | + |
| 133 | + @httpretty.activate |
| 134 | + def test_show(self): |
| 135 | + pargs = common.FakeParsedArgs() |
| 136 | + pargs.id = 'gator' |
| 137 | + httpretty.register_uri(httpretty.GET, self.LIST_URL, |
| 138 | + body=self.LIST_ONE) |
| 139 | + httpretty.register_uri(httpretty.GET, self.SHOW_URL, |
| 140 | + body=self.SHOW) |
| 141 | + self.when_run(port.ShowPort, pargs) |
| 142 | + self.assertEqual('', self.stderr()) |
| 143 | + self.assertEqual(u"""\ |
| 144 | +id="a9254bdb" |
| 145 | +name="gator" |
| 146 | +status="ACTIVE" |
| 147 | +tenant_id="33a40233" |
| 148 | +""", self.stdout()) |
0 commit comments