blob: 087b87a35e750e0c1a3889931755bed4ae707f98 [file] [log] [blame]
ZhiQiang Fan39f97222013-09-20 04:49:44 +08001# Copyright 2012 OpenStack Foundation
Jay Pipesf4dad392012-06-05 16:03:58 -04002# All Rights Reserved.
3#
4# Licensed under the Apache License, Version 2.0 (the "License"); you may
5# not use this file except in compliance with the License. You may obtain
6# a copy of the License at
7#
8# http://www.apache.org/licenses/LICENSE-2.0
9#
10# Unless required by applicable law or agreed to in writing, software
11# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13# License for the specific language governing permissions and limitations
14# under the License.
15
Miguel Lavallecc939612013-02-22 17:27:20 -060016import netaddr
Jay Pipesf4dad392012-06-05 16:03:58 -040017
Matthew Treinish481466b2012-12-20 17:16:01 -050018from tempest import clients
Masayuki Igawa259c1132013-10-31 17:48:44 +090019from tempest.common.utils import data_utils
Matthew Treinish03b48df2014-01-29 16:59:49 +000020from tempest import config
Miguel Lavallecc939612013-02-22 17:27:20 -060021from tempest import exceptions
Anju Tiwari860097d2013-10-17 11:10:39 +053022from tempest.openstack.common import log as logging
Attila Fazekasdc216422013-01-29 15:12:14 +010023import tempest.test
Jay Pipesf4dad392012-06-05 16:03:58 -040024
Matthew Treinish03b48df2014-01-29 16:59:49 +000025CONF = config.CONF
26
Anju Tiwari860097d2013-10-17 11:10:39 +053027LOG = logging.getLogger(__name__)
28
Jay Pipesf4dad392012-06-05 16:03:58 -040029
Attila Fazekasdc216422013-01-29 15:12:14 +010030class BaseNetworkTest(tempest.test.BaseTestCase):
Jay Pipesf4dad392012-06-05 16:03:58 -040031
Miguel Lavallecc939612013-02-22 17:27:20 -060032 """
Mark McClainf2982e82013-07-06 17:48:03 -040033 Base class for the Neutron tests that use the Tempest Neutron REST client
Miguel Lavallecc939612013-02-22 17:27:20 -060034
Mark McClainf2982e82013-07-06 17:48:03 -040035 Per the Neutron API Guide, API v1.x was removed from the source code tree
Miguel Lavallecc939612013-02-22 17:27:20 -060036 (docs.openstack.org/api/openstack-network/2.0/content/Overview-d1e71.html)
Mark McClainf2982e82013-07-06 17:48:03 -040037 Therefore, v2.x of the Neutron API is assumed. It is also assumed that the
Miguel Lavallecc939612013-02-22 17:27:20 -060038 following options are defined in the [network] section of etc/tempest.conf:
39
40 tenant_network_cidr with a block of cidr's from which smaller blocks
41 can be allocated for tenant networks
42
43 tenant_network_mask_bits with the mask bits to be used to partition the
44 block defined by tenant-network_cidr
Miguel Lavalle2492d782013-06-16 15:04:15 -050045
46 Finally, it is assumed that the following option is defined in the
47 [service_available] section of etc/tempest.conf
48
49 neutron as True
Miguel Lavallecc939612013-02-22 17:27:20 -060050 """
51
Matthew Treinish2f6628c2013-10-21 21:06:27 +000052 force_tenant_isolation = False
53
Henry Gessauffda37a2014-01-16 11:17:55 -050054 # Default to ipv4.
55 _ip_version = 4
Henry Gessauffda37a2014-01-16 11:17:55 -050056
Jay Pipesf4dad392012-06-05 16:03:58 -040057 @classmethod
58 def setUpClass(cls):
Salvatore Orlando5a337242014-01-15 22:49:22 +000059 # Create no network resources for these test.
60 cls.set_network_resources()
Attila Fazekasf86fa312013-07-30 19:56:39 +020061 super(BaseNetworkTest, cls).setUpClass()
Matthew Treinish03b48df2014-01-29 16:59:49 +000062 if not CONF.service_available.neutron:
Mark McClainf2982e82013-07-06 17:48:03 -040063 raise cls.skipException("Neutron support is required")
Matthew Treinish2f6628c2013-10-21 21:06:27 +000064
65 os = cls.get_client_manager()
66
67 cls.network_cfg = CONF.network
Miguel Lavallecc939612013-02-22 17:27:20 -060068 cls.client = os.network_client
69 cls.networks = []
70 cls.subnets = []
raiesmh08e1aad982013-08-05 14:19:36 +053071 cls.ports = []
Salvatore Orlandoa85e8fe2013-09-20 03:48:02 -070072 cls.routers = []
raiesmh080fe76852013-09-13 11:52:56 +053073 cls.pools = []
74 cls.vips = []
raiesmh08f8437ed2013-09-17 10:59:38 +053075 cls.members = []
raiesmh0832580d02013-09-17 13:11:34 +053076 cls.health_monitors = []
Anju Tiwari860097d2013-10-17 11:10:39 +053077 cls.vpnservices = []
raiesmh08bd6070d2013-12-06 15:13:38 +053078 cls.ikepolicies = []
rosselladd68b232013-11-13 10:21:59 +010079 cls.floating_ips = []
Emilien Macchi0d0b7cc2014-01-11 12:30:21 -050080 cls.metering_labels = []
81 cls.metering_label_rules = []
Mh Raies96594fc2014-03-26 16:34:18 +053082 cls.fw_rules = []
83 cls.fw_policies = []
raiesmh08df3fac42014-06-02 15:42:18 +053084 cls.ipsecpolicies = []
Jay Pipesf4dad392012-06-05 16:03:58 -040085
86 @classmethod
87 def tearDownClass(cls):
raiesmh08df3fac42014-06-02 15:42:18 +053088 # Clean up ipsec policies
89 for ipsecpolicy in cls.ipsecpolicies:
90 cls.client.delete_ipsecpolicy(ipsecpolicy['id'])
Mh Raies96594fc2014-03-26 16:34:18 +053091 # Clean up firewall policies
92 for fw_policy in cls.fw_policies:
93 cls.client.delete_firewall_policy(fw_policy['id'])
94 # Clean up firewall rules
95 for fw_rule in cls.fw_rules:
96 cls.client.delete_firewall_rule(fw_rule['id'])
raiesmh08bd6070d2013-12-06 15:13:38 +053097 # Clean up ike policies
98 for ikepolicy in cls.ikepolicies:
Eugene Nikanorov909ded12013-12-15 17:45:37 +040099 cls.client.delete_ikepolicy(ikepolicy['id'])
Matthew Treinishec3489c2013-10-25 17:26:50 +0000100 # Clean up vpn services
Anju Tiwari860097d2013-10-17 11:10:39 +0530101 for vpnservice in cls.vpnservices:
Eugene Nikanorov909ded12013-12-15 17:45:37 +0400102 cls.client.delete_vpnservice(vpnservice['id'])
rosselladd68b232013-11-13 10:21:59 +0100103 # Clean up floating IPs
104 for floating_ip in cls.floating_ips:
Ann Kamyshnikova47a4ff82014-03-17 12:48:57 +0400105 cls.client.delete_floatingip(floating_ip['id'])
Matthew Treinishec3489c2013-10-25 17:26:50 +0000106 # Clean up routers
Salvatore Orlandoa85e8fe2013-09-20 03:48:02 -0700107 for router in cls.routers:
Adam Gandelman3e9d12b2014-04-02 17:04:19 -0700108 cls.delete_router(router)
109
Matthew Treinishec3489c2013-10-25 17:26:50 +0000110 # Clean up health monitors
Anju Tiwari860097d2013-10-17 11:10:39 +0530111 for health_monitor in cls.health_monitors:
Matthew Treinishec3489c2013-10-25 17:26:50 +0000112 cls.client.delete_health_monitor(health_monitor['id'])
113 # Clean up members
Anju Tiwari860097d2013-10-17 11:10:39 +0530114 for member in cls.members:
Matthew Treinishec3489c2013-10-25 17:26:50 +0000115 cls.client.delete_member(member['id'])
116 # Clean up vips
Anju Tiwari860097d2013-10-17 11:10:39 +0530117 for vip in cls.vips:
Matthew Treinishec3489c2013-10-25 17:26:50 +0000118 cls.client.delete_vip(vip['id'])
119 # Clean up pools
Anju Tiwari860097d2013-10-17 11:10:39 +0530120 for pool in cls.pools:
Matthew Treinishec3489c2013-10-25 17:26:50 +0000121 cls.client.delete_pool(pool['id'])
Emilien Macchi0d0b7cc2014-01-11 12:30:21 -0500122 # Clean up metering label rules
123 for metering_label_rule in cls.metering_label_rules:
124 cls.admin_client.delete_metering_label_rule(
125 metering_label_rule['id'])
126 # Clean up metering labels
127 for metering_label in cls.metering_labels:
128 cls.admin_client.delete_metering_label(metering_label['id'])
Matthew Treinishec3489c2013-10-25 17:26:50 +0000129 # Clean up ports
Anju Tiwari860097d2013-10-17 11:10:39 +0530130 for port in cls.ports:
Matthew Treinishec3489c2013-10-25 17:26:50 +0000131 cls.client.delete_port(port['id'])
132 # Clean up subnets
Miguel Lavallecc939612013-02-22 17:27:20 -0600133 for subnet in cls.subnets:
Matthew Treinishec3489c2013-10-25 17:26:50 +0000134 cls.client.delete_subnet(subnet['id'])
135 # Clean up networks
Jay Pipesf4dad392012-06-05 16:03:58 -0400136 for network in cls.networks:
Matthew Treinishec3489c2013-10-25 17:26:50 +0000137 cls.client.delete_network(network['id'])
Matthew Treinish2f6628c2013-10-21 21:06:27 +0000138 cls.clear_isolated_creds()
Attila Fazekasf86fa312013-07-30 19:56:39 +0200139 super(BaseNetworkTest, cls).tearDownClass()
Jay Pipesf4dad392012-06-05 16:03:58 -0400140
Miguel Lavallecc939612013-02-22 17:27:20 -0600141 @classmethod
142 def create_network(cls, network_name=None):
Sean Daguef237ccb2013-01-04 15:19:14 -0500143 """Wrapper utility that returns a test network."""
Masayuki Igawa259c1132013-10-31 17:48:44 +0900144 network_name = network_name or data_utils.rand_name('test-network-')
Jay Pipesf4dad392012-06-05 16:03:58 -0400145
Eugene Nikanorove9d255a2013-12-18 16:31:42 +0400146 resp, body = cls.client.create_network(name=network_name)
Jay Pipesf4dad392012-06-05 16:03:58 -0400147 network = body['network']
Miguel Lavallecc939612013-02-22 17:27:20 -0600148 cls.networks.append(network)
Jay Pipesf4dad392012-06-05 16:03:58 -0400149 return network
Miguel Lavallecc939612013-02-22 17:27:20 -0600150
151 @classmethod
Sean M. Collinsdd27a4d2014-05-13 10:33:15 -0400152 def create_subnet(cls, network, gateway=None, cidr=None, mask_bits=None,
153 **kwargs):
Miguel Lavallecc939612013-02-22 17:27:20 -0600154 """Wrapper utility that returns a test subnet."""
Henry Gessauffda37a2014-01-16 11:17:55 -0500155 # The cidr and mask_bits depend on the ip version.
Matthew Treinish2fab8af2014-03-01 13:05:02 -0500156 if cls._ip_version == 4:
armando-migliaccioee90a4d2014-05-06 11:54:07 -0700157 cidr = cidr or netaddr.IPNetwork(CONF.network.tenant_network_cidr)
158 mask_bits = mask_bits or CONF.network.tenant_network_mask_bits
Matthew Treinish2fab8af2014-03-01 13:05:02 -0500159 elif cls._ip_version == 6:
armando-migliaccioee90a4d2014-05-06 11:54:07 -0700160 cidr = (
161 cidr or netaddr.IPNetwork(CONF.network.tenant_network_v6_cidr))
162 mask_bits = mask_bits or CONF.network.tenant_network_v6_mask_bits
Miguel Lavallecc939612013-02-22 17:27:20 -0600163 # Find a cidr that is not in use yet and create a subnet with it
164 for subnet_cidr in cidr.subnet(mask_bits):
Edgar Magana6a9ac342014-01-16 13:52:49 -0800165 if not gateway:
166 gateway = str(netaddr.IPAddress(subnet_cidr) + 1)
Miguel Lavallecc939612013-02-22 17:27:20 -0600167 try:
Eugene Nikanorove9d255a2013-12-18 16:31:42 +0400168 resp, body = cls.client.create_subnet(
169 network_id=network['id'],
170 cidr=str(subnet_cidr),
Edgar Magana6a9ac342014-01-16 13:52:49 -0800171 ip_version=cls._ip_version,
Sean M. Collinsdd27a4d2014-05-13 10:33:15 -0400172 gateway_ip=gateway,
173 **kwargs)
Miguel Lavallecc939612013-02-22 17:27:20 -0600174 break
175 except exceptions.BadRequest as e:
176 is_overlapping_cidr = 'overlaps with another subnet' in str(e)
Edgar Magana6a9ac342014-01-16 13:52:49 -0800177 # Unset gateway value if there is an overlapping subnet
178 gateway = None
Miguel Lavallecc939612013-02-22 17:27:20 -0600179 if not is_overlapping_cidr:
180 raise
Matthew Treinish6b8cd2a2014-03-03 20:45:56 +0000181 else:
182 message = 'Available CIDR for subnet creation could not be found'
183 raise exceptions.BuildErrorException(message)
Miguel Lavallecc939612013-02-22 17:27:20 -0600184 subnet = body['subnet']
185 cls.subnets.append(subnet)
186 return subnet
raiesmh08e1aad982013-08-05 14:19:36 +0530187
188 @classmethod
Dane LeBlanccbc4bc52014-03-19 16:03:23 -0400189 def create_port(cls, network, **kwargs):
raiesmh08e1aad982013-08-05 14:19:36 +0530190 """Wrapper utility that returns a test port."""
Dane LeBlanccbc4bc52014-03-19 16:03:23 -0400191 resp, body = cls.client.create_port(network_id=network['id'],
192 **kwargs)
raiesmh08e1aad982013-08-05 14:19:36 +0530193 port = body['port']
194 cls.ports.append(port)
195 return port
raiesmh080fe76852013-09-13 11:52:56 +0530196
197 @classmethod
Dane LeBlanccbc4bc52014-03-19 16:03:23 -0400198 def update_port(cls, port, **kwargs):
199 """Wrapper utility that updates a test port."""
200 resp, body = cls.client.update_port(port['id'],
201 **kwargs)
202 return body['port']
203
204 @classmethod
Salvatore Orlandoa85e8fe2013-09-20 03:48:02 -0700205 def create_router(cls, router_name=None, admin_state_up=False,
206 external_network_id=None, enable_snat=None):
207 ext_gw_info = {}
208 if external_network_id:
209 ext_gw_info['network_id'] = external_network_id
210 if enable_snat:
211 ext_gw_info['enable_snat'] = enable_snat
212 resp, body = cls.client.create_router(
213 router_name, external_gateway_info=ext_gw_info,
214 admin_state_up=admin_state_up)
215 router = body['router']
216 cls.routers.append(router)
217 return router
218
219 @classmethod
Ann Kamyshnikova47a4ff82014-03-17 12:48:57 +0400220 def create_floatingip(cls, external_network_id):
rosselladd68b232013-11-13 10:21:59 +0100221 """Wrapper utility that returns a test floating IP."""
Ann Kamyshnikova47a4ff82014-03-17 12:48:57 +0400222 resp, body = cls.client.create_floatingip(
223 floating_network_id=external_network_id)
rosselladd68b232013-11-13 10:21:59 +0100224 fip = body['floatingip']
225 cls.floating_ips.append(fip)
226 return fip
227
228 @classmethod
raiesmh080fe76852013-09-13 11:52:56 +0530229 def create_pool(cls, name, lb_method, protocol, subnet):
230 """Wrapper utility that returns a test pool."""
Eugene Nikanorov431e04a2013-12-17 15:44:27 +0400231 resp, body = cls.client.create_pool(
232 name=name,
233 lb_method=lb_method,
234 protocol=protocol,
235 subnet_id=subnet['id'])
raiesmh080fe76852013-09-13 11:52:56 +0530236 pool = body['pool']
237 cls.pools.append(pool)
238 return pool
239
240 @classmethod
Eugene Nikanorov431e04a2013-12-17 15:44:27 +0400241 def update_pool(cls, name):
242 """Wrapper utility that returns a test pool."""
243 resp, body = cls.client.update_pool(name=name)
244 pool = body['pool']
245 return pool
246
247 @classmethod
raiesmh080fe76852013-09-13 11:52:56 +0530248 def create_vip(cls, name, protocol, protocol_port, subnet, pool):
249 """Wrapper utility that returns a test vip."""
Elena Ezhova43c70a22014-01-14 12:42:51 +0400250 resp, body = cls.client.create_vip(name=name,
251 protocol=protocol,
252 protocol_port=protocol_port,
253 subnet_id=subnet['id'],
254 pool_id=pool['id'])
raiesmh080fe76852013-09-13 11:52:56 +0530255 vip = body['vip']
256 cls.vips.append(vip)
257 return vip
raiesmh08f8437ed2013-09-17 10:59:38 +0530258
259 @classmethod
Elena Ezhova43c70a22014-01-14 12:42:51 +0400260 def update_vip(cls, name):
261 resp, body = cls.client.update_vip(name=name)
262 vip = body['vip']
263 return vip
264
265 @classmethod
raiesmh08f8437ed2013-09-17 10:59:38 +0530266 def create_member(cls, protocol_port, pool):
267 """Wrapper utility that returns a test member."""
Ann Kamyshnikova2bc1c432013-12-10 17:31:50 +0400268 resp, body = cls.client.create_member(address="10.0.9.46",
269 protocol_port=protocol_port,
270 pool_id=pool['id'])
raiesmh08f8437ed2013-09-17 10:59:38 +0530271 member = body['member']
272 cls.members.append(member)
273 return member
raiesmh0832580d02013-09-17 13:11:34 +0530274
275 @classmethod
Ann Kamyshnikova2bc1c432013-12-10 17:31:50 +0400276 def update_member(cls, admin_state_up):
277 resp, body = cls.client.update_member(admin_state_up=admin_state_up)
278 member = body['member']
279 return member
280
281 @classmethod
raiesmh0832580d02013-09-17 13:11:34 +0530282 def create_health_monitor(cls, delay, max_retries, Type, timeout):
283 """Wrapper utility that returns a test health monitor."""
Elena Ezhova43c70a22014-01-14 12:42:51 +0400284 resp, body = cls.client.create_health_monitor(delay=delay,
285 max_retries=max_retries,
286 type=Type,
287 timeout=timeout)
raiesmh0832580d02013-09-17 13:11:34 +0530288 health_monitor = body['health_monitor']
289 cls.health_monitors.append(health_monitor)
290 return health_monitor
Anju Tiwari860097d2013-10-17 11:10:39 +0530291
292 @classmethod
Elena Ezhova43c70a22014-01-14 12:42:51 +0400293 def update_health_monitor(cls, admin_state_up):
294 resp, body = cls.client.update_vip(admin_state_up=admin_state_up)
295 health_monitor = body['health_monitor']
296 return health_monitor
297
298 @classmethod
Anju Tiwari860097d2013-10-17 11:10:39 +0530299 def create_router_interface(cls, router_id, subnet_id):
300 """Wrapper utility that returns a router interface."""
301 resp, interface = cls.client.add_router_interface_with_subnet_id(
302 router_id, subnet_id)
wanglianmin5e4b47a2014-03-12 18:16:18 +0800303 return interface
Anju Tiwari860097d2013-10-17 11:10:39 +0530304
305 @classmethod
306 def create_vpnservice(cls, subnet_id, router_id):
307 """Wrapper utility that returns a test vpn service."""
Eugene Nikanorov909ded12013-12-15 17:45:37 +0400308 resp, body = cls.client.create_vpnservice(
Eugene Nikanorovf7e2fa42014-04-17 00:05:36 +0400309 subnet_id=subnet_id, router_id=router_id, admin_state_up=True,
Masayuki Igawa259c1132013-10-31 17:48:44 +0900310 name=data_utils.rand_name("vpnservice-"))
Anju Tiwari860097d2013-10-17 11:10:39 +0530311 vpnservice = body['vpnservice']
312 cls.vpnservices.append(vpnservice)
313 return vpnservice
Salvatore Orlandoce22b492013-09-20 04:04:11 -0700314
raiesmh08bd6070d2013-12-06 15:13:38 +0530315 @classmethod
Eugene Nikanorov909ded12013-12-15 17:45:37 +0400316 def create_ikepolicy(cls, name):
raiesmh08bd6070d2013-12-06 15:13:38 +0530317 """Wrapper utility that returns a test ike policy."""
Eugene Nikanorovf7e2fa42014-04-17 00:05:36 +0400318 resp, body = cls.client.create_ikepolicy(name=name)
raiesmh08bd6070d2013-12-06 15:13:38 +0530319 ikepolicy = body['ikepolicy']
320 cls.ikepolicies.append(ikepolicy)
321 return ikepolicy
322
Mh Raies96594fc2014-03-26 16:34:18 +0530323 @classmethod
324 def create_firewall_rule(cls, action, protocol):
325 """Wrapper utility that returns a test firewall rule."""
326 resp, body = cls.client.create_firewall_rule(
327 name=data_utils.rand_name("fw-rule"),
328 action=action,
329 protocol=protocol)
330 fw_rule = body['firewall_rule']
331 cls.fw_rules.append(fw_rule)
332 return fw_rule
333
334 @classmethod
335 def create_firewall_policy(cls):
336 """Wrapper utility that returns a test firewall policy."""
337 resp, body = cls.client.create_firewall_policy(
338 name=data_utils.rand_name("fw-policy"))
339 fw_policy = body['firewall_policy']
340 cls.fw_policies.append(fw_policy)
341 return fw_policy
342
Adam Gandelman3e9d12b2014-04-02 17:04:19 -0700343 @classmethod
344 def delete_router(cls, router):
345 resp, body = cls.client.list_router_interfaces(router['id'])
346 interfaces = body['ports']
347 for i in interfaces:
348 cls.client.remove_router_interface_with_subnet_id(
349 router['id'], i['fixed_ips'][0]['subnet_id'])
350 cls.client.delete_router(router['id'])
351
raiesmh08df3fac42014-06-02 15:42:18 +0530352 @classmethod
353 def create_ipsecpolicy(cls, name):
354 """Wrapper utility that returns a test ipsec policy."""
355 _, body = cls.client.create_ipsecpolicy(name=name)
356 ipsecpolicy = body['ipsecpolicy']
357 cls.ipsecpolicies.append(ipsecpolicy)
358 return ipsecpolicy
359
Salvatore Orlandoce22b492013-09-20 04:04:11 -0700360
361class BaseAdminNetworkTest(BaseNetworkTest):
362
363 @classmethod
364 def setUpClass(cls):
365 super(BaseAdminNetworkTest, cls).setUpClass()
Matthew Treinish03b48df2014-01-29 16:59:49 +0000366 admin_username = CONF.compute_admin.username
367 admin_password = CONF.compute_admin.password
368 admin_tenant = CONF.compute_admin.tenant_name
Salvatore Orlandoce22b492013-09-20 04:04:11 -0700369 if not (admin_username and admin_password and admin_tenant):
370 msg = ("Missing Administrative Network API credentials "
371 "in configuration.")
372 raise cls.skipException(msg)
Matthew Treinish2f6628c2013-10-21 21:06:27 +0000373 if (CONF.compute.allow_tenant_isolation or
374 cls.force_tenant_isolation is True):
Andrea Frittoli422fbdf2014-03-20 10:05:18 +0000375 cls.os_adm = clients.Manager(cls.isolated_creds.get_admin_creds(),
Matthew Treinish2f6628c2013-10-21 21:06:27 +0000376 interface=cls._interface)
377 else:
378 cls.os_adm = clients.ComputeAdminManager(interface=cls._interface)
379 cls.admin_client = cls.os_adm.network_client
Emilien Macchi0d0b7cc2014-01-11 12:30:21 -0500380
381 @classmethod
382 def create_metering_label(cls, name, description):
383 """Wrapper utility that returns a test metering label."""
384 resp, body = cls.admin_client.create_metering_label(
385 description=description,
386 name=data_utils.rand_name("metering-label"))
387 metering_label = body['metering_label']
388 cls.metering_labels.append(metering_label)
389 return metering_label
390
391 @classmethod
392 def create_metering_label_rule(cls, remote_ip_prefix, direction,
393 metering_label_id):
394 """Wrapper utility that returns a test metering label rule."""
395 resp, body = cls.admin_client.create_metering_label_rule(
396 remote_ip_prefix=remote_ip_prefix, direction=direction,
397 metering_label_id=metering_label_id)
398 metering_label_rule = body['metering_label_rule']
399 cls.metering_label_rules.append(metering_label_rule)
400 return metering_label_rule