blob: f7ade381a304a2b0345bf3c38d170c6d055c02e1 [file] [log] [blame]
Zack Williams41513bf2018-07-07 20:08:35 -07001# Copyright 2017-present Open Networking Foundation
2#
3# Licensed under the Apache License, Version 2.0 (the "License");
4# you may not use this file except in compliance with the License.
5# You may obtain 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,
11# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12# See the License for the specific language governing permissions and
13# limitations under the License.
khenaidoo08d48d22017-06-29 19:42:49 -040014from random import randint
15from time import time, sleep
16
Rachit Shrivastava8f4f9bf2017-07-20 11:59:30 -040017from google.protobuf.json_format import MessageToDict, ParseDict
Stephane Barbariecd51f992017-09-07 16:37:02 -040018from unittest import main, skip
khenaidoo08d48d22017-06-29 19:42:49 -040019from voltha.protos.device_pb2 import Device
20from tests.itests.voltha.rest_base import RestBase
khenaidood3c335e2017-07-05 16:36:59 -040021from common.utils.consulhelpers import get_endpoint_from_consul, \
22 get_all_instances_of_service
khenaidoo08d48d22017-06-29 19:42:49 -040023from common.utils.consulhelpers import verify_all_services_healthy
Richard Jankowski461cb972018-04-11 15:36:27 -040024from tests.itests.test_utils import \
khenaidoo08d48d22017-06-29 19:42:49 -040025 run_command_to_completion_with_raw_stdout, \
26 run_command_to_completion_with_stdout_in_list
27from voltha.protos.voltha_pb2 import AlarmFilter
khenaidood3c335e2017-07-05 16:36:59 -040028from google.protobuf.empty_pb2 import Empty
29import grpc
30from voltha.protos import third_party
Scott Bakerd865fa22018-11-07 11:45:28 -080031from voltha.protos import voltha_pb2, voltha_pb2_grpc
khenaidood3c335e2017-07-05 16:36:59 -040032from voltha.core.flow_decomposer import *
33from voltha.protos.openflow_13_pb2 import FlowTableUpdate
Rachit Shrivastava8f4f9bf2017-07-20 11:59:30 -040034from voltha.protos import bbf_fiber_base_pb2 as fb
Richard Jankowski461cb972018-04-11 15:36:27 -040035from tests.itests.voltha.xpon_scenario import scenario as xpon_scenario
36from tests.itests.test_utils import get_pod_ip
37from tests.itests.orch_environment import get_orch_environment
38from testconfig import config
khenaidoo08d48d22017-06-29 19:42:49 -040039
40LOCAL_CONSUL = "localhost:8500"
khenaidoo2a8c6332017-10-10 15:23:49 -040041DOCKER_COMPOSE_FILE = "compose/docker-compose-system-test-dispatcher.yml"
Richard Jankowski461cb972018-04-11 15:36:27 -040042ENV_DOCKER_COMPOSE = 'docker-compose'
43ENV_K8S_SINGLE_NODE = 'k8s-single-node'
44
45orch_env = ENV_DOCKER_COMPOSE
46if 'test_parameters' in config and 'orch_env' in config['test_parameters']:
47 orch_env = config['test_parameters']['orch_env']
48print 'orchestration-environment: %s' % orch_env
49orch = get_orch_environment(orch_env)
khenaidoo08d48d22017-06-29 19:42:49 -040050
51command_defs = dict(
52 docker_ps="docker ps",
53 docker_compose_start_all="docker-compose -f {} up -d "
54 .format(DOCKER_COMPOSE_FILE),
55 docker_stop_and_remove_all_containers="docker-compose -f {} down"
56 .format(DOCKER_COMPOSE_FILE),
khenaidood3c335e2017-07-05 16:36:59 -040057 docker_compose_scale_voltha="docker-compose -f {} scale "
Richard Jankowski461cb972018-04-11 15:36:27 -040058 "voltha=".format(DOCKER_COMPOSE_FILE)
khenaidoo08d48d22017-06-29 19:42:49 -040059)
60
Richard Jankowski461cb972018-04-11 15:36:27 -040061command_k8s = dict(
62 docker_ps = "kubectl -n voltha get pods",
63 docker_compose_start_all = "./tests/itests/env/voltha-ponsim-k8s-start.sh",
64 docker_stop_and_remove_all_containers = "./tests/itests/env/voltha-ponsim-k8s-stop.sh",
65 docker_compose_scale_voltha = "kubectl -n voltha scale deployment vcore --replicas="
66)
67
68commands = {
69 ENV_DOCKER_COMPOSE: command_defs,
70 ENV_K8S_SINGLE_NODE: command_k8s
71}
72vcore_svc_name = {
73 ENV_DOCKER_COMPOSE: 'vcore-grpc',
74 ENV_K8S_SINGLE_NODE: 'vcore'
75}
76envoy_svc_name = {
77 ENV_DOCKER_COMPOSE: 'voltha-grpc',
78 ENV_K8S_SINGLE_NODE: 'voltha'
79}
Rachit Shrivastavaa182e912017-07-28 15:18:34 -040080obj_type_config = {
81 'cg': {'type':'channel_groups',
82 'config':'channelgroup_config'},
83 'cpart': {'type':'channel_partitions',
84 'config':'channelpartition_config'},
85 'cpair': {'type':'channel_pairs',
86 'config':'channelpair_config'},
87 'cterm': {'type':'channel_terminations',
88 'config':'channeltermination_config'},
89 'vontani':{'type':'v_ont_anis',
90 'config':'v_ontani_config'},
91 'ontani': {'type':'ont_anis',
92 'config':'ontani_config'},
93 'venet': {'type':'v_enets',
Rachit Shrivastava1b2478e2018-03-01 11:53:49 -050094 'config':'v_enet_config'},
95 'gemport':{'type':'gemports',
96 'config':'gemports_config'},
97 'tcont': {'type':'tconts',
98 'config':'tconts_config'},
99 'tdp': {'type':'traffic_descriptor_profiles',
100 'config':'traffic_descriptor_profiles'}
Rachit Shrivastavaa182e912017-07-28 15:18:34 -0400101}
Rachit Shrivastava8f4f9bf2017-07-20 11:59:30 -0400102
Richard Jankowski461cb972018-04-11 15:36:27 -0400103def get_command(cmd):
104 if orch_env == ENV_K8S_SINGLE_NODE and cmd in commands[ENV_K8S_SINGLE_NODE]:
105 return commands[ENV_K8S_SINGLE_NODE][cmd]
106 else:
107 return commands[ENV_DOCKER_COMPOSE][cmd]
khenaidood3c335e2017-07-05 16:36:59 -0400108
khenaidoo08d48d22017-06-29 19:42:49 -0400109class DispatcherTest(RestBase):
khenaidood3c335e2017-07-05 16:36:59 -0400110 def setUp(self):
111 self.grpc_channels = dict()
khenaidoo08d48d22017-06-29 19:42:49 -0400112
113 t0 = [time()]
114
115 def pt(self, msg=''):
116 t1 = time()
117 print '%20.8f ms - %s' % (1000 * (t1 - DispatcherTest.t0[0]),
118 msg)
119 DispatcherTest.t0[0] = t1
120
khenaidoo08d48d22017-06-29 19:42:49 -0400121 def wait_till(self, msg, predicate, interval=0.1, timeout=5.0):
122 deadline = time() + timeout
123 while time() < deadline:
124 if predicate():
125 return
126 sleep(interval)
127 self.fail('Timed out while waiting for condition: {}'.format(msg))
128
khenaidood3c335e2017-07-05 16:36:59 -0400129 def get_channel(self, voltha_grpc):
130 if voltha_grpc not in self.grpc_channels:
131 self.grpc_channels[voltha_grpc] = grpc.insecure_channel(
132 voltha_grpc)
133 return self.grpc_channels[voltha_grpc]
khenaidoo08d48d22017-06-29 19:42:49 -0400134
135 def test_01_global_rest_apis(self):
136 # Start the voltha ensemble with a single voltha instance
137 self._stop_and_remove_all_containers()
138 sleep(5) # A small wait for the system to settle down
139 self.start_all_containers()
140 self.set_rest_endpoint()
khenaidoo08d48d22017-06-29 19:42:49 -0400141
Stephane Barbariecd51f992017-09-07 16:37:02 -0400142 # self._get_root_rest()
khenaidood3c335e2017-07-05 16:36:59 -0400143 self._get_schema_rest()
144 self._get_health_rest()
145 self._get_voltha_rest()
146 self._list_voltha_instances_rest()
147 self._get_voltha_instance_rest()
148 olt_id = self._add_olt_device_rest()
149 self._verify_device_preprovisioned_state_rest(olt_id)
150 self._activate_device_rest(olt_id)
151 ldev_id = self._wait_for_logical_device_rest(olt_id)
152 ldevices = self._list_logical_devices_rest()
khenaidoo08d48d22017-06-29 19:42:49 -0400153 logical_device_id = ldevices['items'][0]['id']
khenaidood3c335e2017-07-05 16:36:59 -0400154 self._get_logical_device_rest(logical_device_id)
155 self._list_logical_device_ports_rest(logical_device_id)
156 self._list_and_update_logical_device_flows_rest(logical_device_id)
157 self._list_and_update_logical_device_flow_groups_rest(
158 logical_device_id)
159 devices = self._list_devices_rest()
khenaidoo08d48d22017-06-29 19:42:49 -0400160 device_id = devices['items'][0]['id']
khenaidood3c335e2017-07-05 16:36:59 -0400161 self._get_device_rest(device_id)
162 self._list_device_ports_rest(device_id)
Richard Jankowski461cb972018-04-11 15:36:27 -0400163# TODO: Figure out why this test fails
164# self._list_device_flows_rest(device_id)
khenaidood3c335e2017-07-05 16:36:59 -0400165 self._list_device_flow_groups_rest(device_id)
166 self._get_images_rest(device_id)
167 self._self_test_rest(device_id)
168 dtypes = self._list_device_types_rest()
169 self._get_device_type_rest(dtypes['items'][0]['id'])
170 alarm_filter = self._create_device_filter_rest(olt_id)
171 self._remove_device_filter_rest(alarm_filter['id'])
Rachit Shrivastavaa182e912017-07-28 15:18:34 -0400172 #for xPON objects
173 for item in xpon_scenario:
174 for key,value in item.items():
Stephane Barbariecd51f992017-09-07 16:37:02 -0400175 try:
176 _device_id = None
177 _obj_action = [val for val in key.split('-')]
178 _type_config = obj_type_config[_obj_action[0]]
179 if _obj_action[0] == "cterm":
180 _device_id = olt_id
181 if _obj_action[1] == "mod":
182 continue
183 elif _obj_action[1] == "add":
184 _xpon_obj = self._create_xpon_object_rest(_type_config,
185 value,
186 _device_id)
187 elif _obj_action[1] == "del":
188 self._delete_xpon_object_rest(_type_config,
189 value,
190 _device_id)
191 except Exception, e:
192 print 'An error occurred', e
Rachit Shrivastavaa182e912017-07-28 15:18:34 -0400193 continue
Stephane Barbariecd51f992017-09-07 16:37:02 -0400194
khenaidoo08d48d22017-06-29 19:42:49 -0400195 # TODO: PM APIs test
196
khenaidoo2a8c6332017-10-10 15:23:49 -0400197 # @skip('Test fails due to environment configuration. Need to investigate. Refer to VOL-427')
khenaidoo08d48d22017-06-29 19:42:49 -0400198 def test_02_cross_instances_dispatch(self):
khenaidood3c335e2017-07-05 16:36:59 -0400199
200 def prompt(input_func, text):
201 val = input_func(text)
202 return val
203
204 def prompt_for_return(text):
205 return raw_input(text)
206
207 # Start the voltha ensemble with a single voltha instance
208 self._stop_and_remove_all_containers()
209 sleep(5) # A small wait for the system to settle down
210 self.start_all_containers()
211 self.set_rest_endpoint()
khenaidood3c335e2017-07-05 16:36:59 -0400212
213 # Scale voltha to 3 instances and setup the voltha grpc assigments
214 self._scale_voltha(3)
Richard Jankowski461cb972018-04-11 15:36:27 -0400215 sleep(20) # A small wait for the system to settle down
216 voltha_instances = orch.get_all_instances_of_service(vcore_svc_name[orch_env], port_name='grpc')
khenaidood3c335e2017-07-05 16:36:59 -0400217 self.assertEqual(len(voltha_instances), 3)
Scott Bakerd865fa22018-11-07 11:45:28 -0800218 self.ponsim_voltha_stub_local = voltha_pb2_grpc.VolthaLocalServiceStub(
khenaidood3c335e2017-07-05 16:36:59 -0400219 self.get_channel(self._get_grpc_address(voltha_instances[2])))
Scott Bakerd865fa22018-11-07 11:45:28 -0800220 self.ponsim_voltha_stub_global = voltha_pb2_grpc.VolthaGlobalServiceStub(
khenaidood3c335e2017-07-05 16:36:59 -0400221 self.get_channel(self._get_grpc_address(voltha_instances[2])))
222
Scott Bakerd865fa22018-11-07 11:45:28 -0800223 self.simulated_voltha_stub_local = voltha_pb2_grpc.VolthaLocalServiceStub(
khenaidood3c335e2017-07-05 16:36:59 -0400224 self.get_channel(self._get_grpc_address(voltha_instances[1])))
Scott Bakerd865fa22018-11-07 11:45:28 -0800225 self.simulated_voltha_stub_global = voltha_pb2_grpc.VolthaGlobalServiceStub(
khenaidood3c335e2017-07-05 16:36:59 -0400226 self.get_channel(self._get_grpc_address(voltha_instances[1])))
227
Scott Bakerd865fa22018-11-07 11:45:28 -0800228 self.empty_voltha_stub_local = voltha_pb2_grpc.VolthaLocalServiceStub(
khenaidood3c335e2017-07-05 16:36:59 -0400229 self.get_channel(self._get_grpc_address(voltha_instances[0])))
Scott Bakerd865fa22018-11-07 11:45:28 -0800230 self.empty_voltha_stub_global = voltha_pb2_grpc.VolthaGlobalServiceStub(
khenaidood3c335e2017-07-05 16:36:59 -0400231 self.get_channel(self._get_grpc_address(voltha_instances[0])))
232
Richard Jankowski461cb972018-04-11 15:36:27 -0400233 if orch_env == ENV_DOCKER_COMPOSE:
234 # Prompt the user to start ponsim
235 # Get the user to start PONSIM as root
236 prompt(prompt_for_return,
237 '\nStart PONSIM as root in another window ...')
khenaidood3c335e2017-07-05 16:36:59 -0400238
Richard Jankowski461cb972018-04-11 15:36:27 -0400239 prompt(prompt_for_return,
240 '\nEnsure port forwarding is set on ponmgnt ...')
khenaidood3c335e2017-07-05 16:36:59 -0400241
242 # Test 1:
khenaidoo997edbc2017-07-13 10:25:58 -0400243 # A. Get the list of adapters using a global stub
244 # B. Get the list of adapters using a local stub
245 # C. Verify that the two lists are the same
246 adapters_g = self._get_adapters_grpc(self.ponsim_voltha_stub_global)
247 adapters_l = self._get_adapters_grpc(self.empty_voltha_stub_local)
248 assert adapters_g == adapters_l
249
250 # Test 2:
khenaidood3c335e2017-07-05 16:36:59 -0400251 # A. Provision a pomsim olt using the ponsim_voltha_stub
252 # B. Enable the posim olt using the simulated_voltha_stub
253 # C. Wait for onu discovery using the empty_voltha_stub
254 ponsim_olt = self._provision_ponsim_olt_grpc(
255 self.ponsim_voltha_stub_local)
256 ponsim_logical_device_id = self._enable_device_grpc(
257 self.simulated_voltha_stub_global,
258 ponsim_olt.id)
259 self._wait_for_onu_discovery_grpc(self.empty_voltha_stub_global,
260 ponsim_olt.id,
261 count=4)
khenaidoo997edbc2017-07-13 10:25:58 -0400262 # Test 3:
khenaidood3c335e2017-07-05 16:36:59 -0400263 # A. Provision a simulated olt using the simulated_voltha_stub
264 # B. Enable the simulated olt using the ponsim_voltha_stub
265 # C. Wait for onu discovery using the empty_voltha_stub
266 simulated_olt = self._provision_simulated_olt_grpc(
267 self.simulated_voltha_stub_local)
268 simulated_logical_device_id = self._enable_device_grpc(
269 self.ponsim_voltha_stub_global, simulated_olt.id)
270 self._wait_for_onu_discovery_grpc(self.empty_voltha_stub_global,
271 simulated_olt.id, count=4)
272
khenaidoo997edbc2017-07-13 10:25:58 -0400273 # Test 4:
khenaidood3c335e2017-07-05 16:36:59 -0400274 # Verify that we have at least 8 devices created using the global
275 # REST and also via direct grpc in the empty stub
276 devices_via_rest = self._list_devices_rest(8)['items']
277 devices_via_global_grpc = self._get_devices_grpc(
278 self.empty_voltha_stub_global)
279 assert len(devices_via_rest) == len(devices_via_global_grpc)
280
khenaidoo997edbc2017-07-13 10:25:58 -0400281 # Test 5:
khenaidood3c335e2017-07-05 16:36:59 -0400282 # A. Create 2 Alarms filters using REST
283 # B. Ensure it is present across all instances
284 # C. Ensure when requesting the alarm filters we do not get
285 # duplicate results
286 alarm_filter1 = self._create_device_filter_rest(ponsim_olt.id)
287 alarm_filter2 = self._create_device_filter_rest(simulated_olt.id)
288 global_filters = self._get_alarm_filters_rest()
289 filter = self._get_alarm_filters_grpc(self.simulated_voltha_stub_local)
290 assert global_filters == MessageToDict(filter)
291 filter = self._get_alarm_filters_grpc(self.ponsim_voltha_stub_local)
292 assert global_filters == MessageToDict(filter)
293 filter = self._get_alarm_filters_grpc(self.empty_voltha_stub_local)
294 assert global_filters == MessageToDict(filter)
295 filter = self._get_alarm_filters_grpc(self.empty_voltha_stub_global)
296 assert global_filters == MessageToDict(filter)
297
khenaidoo997edbc2017-07-13 10:25:58 -0400298 # Test 6:
khenaidood3c335e2017-07-05 16:36:59 -0400299 # A. Delete an alarm filter
300 # B. Ensure that filter is deleted from all instances
301 self._remove_device_filter_rest(alarm_filter1['id'])
302 previous_filters = global_filters
303 global_filters = self._get_alarm_filters_rest()
304 assert global_filters != previous_filters
305 filter = self._get_alarm_filters_grpc(self.simulated_voltha_stub_local)
306 assert global_filters == MessageToDict(filter)
307 filter = self._get_alarm_filters_grpc(self.ponsim_voltha_stub_local)
308 assert global_filters == MessageToDict(filter)
309 filter = self._get_alarm_filters_grpc(self.empty_voltha_stub_local)
310 assert global_filters == MessageToDict(filter)
311 filter = self._get_alarm_filters_grpc(self.empty_voltha_stub_global)
312 assert global_filters == MessageToDict(filter)
313
khenaidoo997edbc2017-07-13 10:25:58 -0400314 # Test 7:
khenaidood3c335e2017-07-05 16:36:59 -0400315 # A. Simulate EAPOL install on ponsim instance using grpc
316 # B. Validate the flows using global REST
317 # C. Retrieve the flows from global grpc using empty voltha instance
318 self._install_eapol_flow_grpc(self.ponsim_voltha_stub_local,
319 ponsim_logical_device_id)
320 self._verify_olt_eapol_flow_rest(ponsim_olt.id)
321 res = self._get_olt_flows_grpc(self.empty_voltha_stub_global,
322 ponsim_logical_device_id)
323
Rachit Shrivastava8f4f9bf2017-07-20 11:59:30 -0400324 # Test 8:
Rachit Shrivastavaa182e912017-07-28 15:18:34 -0400325 # A. Create xPON objects instance using REST
326 # B. Ensuring that Channeltermination is present on specific instances
327 # C. Ensuring that other xPON objects are present in all instances
Rachit Shrivastava1b2478e2018-03-01 11:53:49 -0500328 for item in xpon_scenario:
329 for key,value in item.items():
330 _obj_action = [val for val in key.split('-')]
331 _type_config = obj_type_config[_obj_action[0]]
332 if _obj_action[1] == "mod":
333 continue
334 if _obj_action[0] == "cterm":
335 if _obj_action[1] == "add":
336 #Ponsim OLT
337 self._create_xpon_object_rest(_type_config,
338 value,
339 ponsim_olt.id)
340 self._verify_xpon_object_on_device(
341 _type_config,
342 self.ponsim_voltha_stub_global,
343 ponsim_olt.id)
344 self._delete_xpon_object_rest(_type_config,
345 value,
346 ponsim_olt.id)
347 #Simulated OLT
348 self._create_xpon_object_rest(_type_config,
349 value,
350 simulated_olt.id)
351 self._verify_xpon_object_on_device(
352 _type_config,
353 self.simulated_voltha_stub_global,
354 simulated_olt.id)
355 self._delete_xpon_object_rest(_type_config,
356 value,
357 simulated_olt.id)
358 elif _obj_action[1] == "del":
359 continue
360 else:
361 if _obj_action[1] == "add":
362 self._create_xpon_object_rest(_type_config, value)
363 #Checking with Ponsim OLT
364 self._verify_xpon_object_on_device(
365 _type_config,
366 self.ponsim_voltha_stub_global)
367 #Checking with empty instance
368 self._verify_xpon_object_on_device(
369 _type_config,
370 self.empty_voltha_stub_global)
371 #Checking with Simulated OLT
372 self._verify_xpon_object_on_device(
373 _type_config,
374 self.simulated_voltha_stub_global)
375 elif _obj_action[1] == "del":
376 self._delete_xpon_object_rest(_type_config, value)
Rachit Shrivastava8f4f9bf2017-07-20 11:59:30 -0400377
Rachit Shrivastava1b2478e2018-03-01 11:53:49 -0500378 #TODO: More tests to be added as new features are added
khenaidood3c335e2017-07-05 16:36:59 -0400379
380
381 def _get_grpc_address(self, voltha_instance):
382 address = '{}:{}'.format(voltha_instance['ServiceAddress'],
383 voltha_instance['ServicePort'])
384 return address
khenaidoo08d48d22017-06-29 19:42:49 -0400385
386 def _stop_and_remove_all_containers(self):
387 # check if there are any running containers first
Richard Jankowski461cb972018-04-11 15:36:27 -0400388 cmd = get_command('docker_ps')
khenaidoo08d48d22017-06-29 19:42:49 -0400389 out, err, rc = run_command_to_completion_with_stdout_in_list(cmd)
390 self.assertEqual(rc, 0)
391 if len(out) > 1: # not counting docker ps header
Richard Jankowski461cb972018-04-11 15:36:27 -0400392 cmd = get_command('docker_stop_and_remove_all_containers')
khenaidoo08d48d22017-06-29 19:42:49 -0400393 out, err, rc = run_command_to_completion_with_raw_stdout(cmd)
394 self.assertEqual(rc, 0)
395
396 def start_all_containers(self):
397 t0 = time()
398
399 # start all the containers
400 self.pt("Starting all containers ...")
Richard Jankowski461cb972018-04-11 15:36:27 -0400401 cmd = get_command('docker_compose_start_all')
khenaidoo08d48d22017-06-29 19:42:49 -0400402 out, err, rc = run_command_to_completion_with_raw_stdout(cmd)
403 self.assertEqual(rc, 0)
404
khenaidoo079a7762017-10-26 21:42:05 -0400405 self.pt("Waiting for voltha container to be ready ...")
khenaidoo08d48d22017-06-29 19:42:49 -0400406 self.wait_till('voltha services HEALTHY',
Richard Jankowski461cb972018-04-11 15:36:27 -0400407 lambda: orch.verify_all_services_healthy(
408 service_name=envoy_svc_name[orch_env]) == True,
khenaidoo08d48d22017-06-29 19:42:49 -0400409 timeout=10)
khenaidoo08d48d22017-06-29 19:42:49 -0400410 sleep(10)
411
412 def set_rest_endpoint(self):
Richard Jankowski461cb972018-04-11 15:36:27 -0400413 if orch_env == ENV_K8S_SINGLE_NODE:
414 self.rest_endpoint = get_pod_ip('voltha') + ':8443'
415 else:
416 self.rest_endpoint = get_endpoint_from_consul(LOCAL_CONSUL,
417 'voltha-envoy-8443')
ubuntuc5c83d72017-07-01 17:57:19 -0700418 self.base_url = 'https://' + self.rest_endpoint
khenaidoo08d48d22017-06-29 19:42:49 -0400419
420 def set_kafka_endpoint(self):
421 self.kafka_endpoint = get_endpoint_from_consul(LOCAL_CONSUL, 'kafka')
422
khenaidood3c335e2017-07-05 16:36:59 -0400423 def _scale_voltha(self, scale=2):
424 self.pt("Scaling voltha ...")
Richard Jankowski461cb972018-04-11 15:36:27 -0400425 cmd = get_command('docker_compose_scale_voltha') + str(scale)
khenaidood3c335e2017-07-05 16:36:59 -0400426 out, err, rc = run_command_to_completion_with_raw_stdout(cmd)
427 self.assertEqual(rc, 0)
khenaidoo08d48d22017-06-29 19:42:49 -0400428
khenaidood3c335e2017-07-05 16:36:59 -0400429 def _get_root_rest(self):
khenaidoo08d48d22017-06-29 19:42:49 -0400430 res = self.get('/', expected_content_type='text/html')
431 self.assertGreaterEqual(res.find('swagger'), 0)
432
khenaidood3c335e2017-07-05 16:36:59 -0400433 def _get_schema_rest(self):
khenaidoo08d48d22017-06-29 19:42:49 -0400434 res = self.get('/schema')
khenaidood3c335e2017-07-05 16:36:59 -0400435 self.assertEqual(set(res.keys()),
436 {'protos', 'yang_from', 'swagger_from'})
khenaidoo08d48d22017-06-29 19:42:49 -0400437
khenaidood3c335e2017-07-05 16:36:59 -0400438 def _get_health_rest(self):
khenaidoo08d48d22017-06-29 19:42:49 -0400439 res = self.get('/health')
440 self.assertEqual(res['state'], 'HEALTHY')
441
442 # ~~~~~~~~~~~~~~~~~~~~~ TOP LEVEL VOLTHA OPERATIONS ~~~~~~~~~~~~~~~~~~~~~~~
443
khenaidood3c335e2017-07-05 16:36:59 -0400444 def _get_voltha_rest(self):
khenaidoo08d48d22017-06-29 19:42:49 -0400445 res = self.get('/api/v1')
446 self.assertEqual(res['version'], '0.9.0')
447
khenaidood3c335e2017-07-05 16:36:59 -0400448 def _list_voltha_instances_rest(self):
khenaidoo08d48d22017-06-29 19:42:49 -0400449 res = self.get('/api/v1/instances')
450 self.assertEqual(len(res['items']), 1)
451
khenaidood3c335e2017-07-05 16:36:59 -0400452 def _get_voltha_instance_rest(self):
khenaidoo08d48d22017-06-29 19:42:49 -0400453 res = self.get('/api/v1/instances')
khenaidood3c335e2017-07-05 16:36:59 -0400454 voltha_id = res['items'][0]
khenaidoo08d48d22017-06-29 19:42:49 -0400455 res = self.get('/api/v1/instances/{}'.format(voltha_id))
456 self.assertEqual(res['version'], '0.9.0')
457
khenaidood3c335e2017-07-05 16:36:59 -0400458 def _add_olt_device_rest(self, grpc=None):
khenaidoo08d48d22017-06-29 19:42:49 -0400459 device = Device(
460 type='simulated_olt',
461 mac_address='00:00:00:00:00:01'
462 )
463 device = self.post('/api/v1/devices', MessageToDict(device),
Stephane Barbariecd51f992017-09-07 16:37:02 -0400464 expected_http_code=200)
khenaidoo08d48d22017-06-29 19:42:49 -0400465 return device['id']
466
khenaidood3c335e2017-07-05 16:36:59 -0400467 def _provision_simulated_olt_grpc(self, stub):
468 device = Device(
469 type='simulated_olt',
470 mac_address='00:00:00:00:00:01'
471 )
472 device = stub.CreateDevice(device)
473 return device
474
475 def _provision_ponsim_olt_grpc(self, stub):
Richard Jankowski461cb972018-04-11 15:36:27 -0400476 if orch_env == ENV_K8S_SINGLE_NODE:
477 host_and_port = get_pod_ip('olt') + ':50060'
478 else:
479 host_and_port = '172.17.0.1:50060'
khenaidood3c335e2017-07-05 16:36:59 -0400480 device = Device(
481 type='ponsim_olt',
Richard Jankowski461cb972018-04-11 15:36:27 -0400482 host_and_port=host_and_port
khenaidood3c335e2017-07-05 16:36:59 -0400483 )
484 device = stub.CreateDevice(device)
485 return device
486
487 def _enable_device_grpc(self, stub, device_id):
488 logical_device_id = None
489 try:
490 stub.EnableDevice(voltha_pb2.ID(id=device_id))
491 while True:
492 device = stub.GetDevice(voltha_pb2.ID(id=device_id))
493 # If this is an OLT then acquire logical device id
494 if device.oper_status == voltha_pb2.OperStatus.ACTIVE:
495 if device.type.endswith('_olt'):
496 assert device.parent_id
497 logical_device_id = device.parent_id
498 self.pt('success (logical device id = {})'.format(
499 logical_device_id))
500 else:
501 self.pt('success (device id = {})'.format(device.id))
502 break
503 self.pt('waiting for device to be enabled...')
504 sleep(.5)
505 except Exception, e:
506 self.pt('Error enabling {}. Error:{}'.format(device_id, e))
507 return logical_device_id
508
509 def _delete_device_grpc(self, stub, device_id):
510 try:
511 stub.DeleteDevice(voltha_pb2.ID(id=device_id))
512 while True:
513 device = stub.GetDevice(voltha_pb2.ID(id=device_id))
514 assert not device
515 except Exception, e:
516 self.pt('deleting device {}. Error:{}'.format(device_id, e))
517
518 def _get_devices_grpc(self, stub):
519 res = stub.ListDevices(Empty())
520 return res.items
521
khenaidoo997edbc2017-07-13 10:25:58 -0400522 def _get_adapters_grpc(self, stub):
523 res = stub.ListAdapters(Empty())
524 return res.items
525
khenaidood3c335e2017-07-05 16:36:59 -0400526 def _find_onus_grpc(self, stub, olt_id):
527 devices = self._get_devices_grpc(stub)
528 return [
529 d for d in devices
530 if d.parent_id == olt_id
531 ]
532
533 def _wait_for_onu_discovery_grpc(self, stub, olt_id, count=4):
534 # shortly after we shall see the discovery of four new onus, linked to
535 # the olt device
Richard Jankowski461cb972018-04-11 15:36:27 -0400536 #
537 # NOTE: The success of the wait_till invocation below appears to be very
538 # sensitive to the values of the interval and timeout parameters.
539 #
khenaidood3c335e2017-07-05 16:36:59 -0400540 self.wait_till(
541 'find ONUs linked to the olt device',
542 lambda: len(self._find_onus_grpc(stub, olt_id)) >= count,
Richard Jankowski461cb972018-04-11 15:36:27 -0400543 interval=2, timeout=10
khenaidood3c335e2017-07-05 16:36:59 -0400544 )
545 # verify that they are properly set
546 onus = self._find_onus_grpc(stub, olt_id)
547 for onu in onus:
548 self.assertEqual(onu.admin_state, 3) # ENABLED
549 self.assertEqual(onu.oper_status, 4) # ACTIVE
550
551 return [onu.id for onu in onus]
552
553 def _verify_device_preprovisioned_state_rest(self, olt_id):
khenaidoo08d48d22017-06-29 19:42:49 -0400554 # we also check that so far what we read back is same as what we get
555 # back on create
556 device = self.get('/api/v1/devices/{}'.format(olt_id))
557 self.assertNotEqual(device['id'], '')
558 self.assertEqual(device['adapter'], 'simulated_olt')
559 self.assertEqual(device['admin_state'], 'PREPROVISIONED')
560 self.assertEqual(device['oper_status'], 'UNKNOWN')
561
khenaidood3c335e2017-07-05 16:36:59 -0400562 def _activate_device_rest(self, olt_id):
khenaidoo08d48d22017-06-29 19:42:49 -0400563 path = '/api/v1/devices/{}'.format(olt_id)
Stephane Barbariecd51f992017-09-07 16:37:02 -0400564 self.post(path + '/enable', expected_http_code=200)
khenaidoo08d48d22017-06-29 19:42:49 -0400565 device = self.get(path)
566 self.assertEqual(device['admin_state'], 'ENABLED')
567
568 self.wait_till(
569 'admin state moves to ACTIVATING or ACTIVE',
570 lambda: self.get(path)['oper_status'] in ('ACTIVATING', 'ACTIVE'),
571 timeout=0.5)
572
573 # eventually, it shall move to active state and by then we shall have
574 # device details filled, connect_state set, and device ports created
575 self.wait_till(
576 'admin state ACTIVE',
577 lambda: self.get(path)['oper_status'] == 'ACTIVE',
578 timeout=0.5)
579 device = self.get(path)
580 images = device['images']
581 image = images['image']
582 image_1 = image[0]
583 version = image_1['version']
584 self.assertNotEqual(version, '')
585 self.assertEqual(device['connect_status'], 'REACHABLE')
586
587 ports = self.get(path + '/ports')['items']
588 self.assertEqual(len(ports), 2)
589
khenaidood3c335e2017-07-05 16:36:59 -0400590 def _wait_for_logical_device_rest(self, olt_id):
khenaidoo08d48d22017-06-29 19:42:49 -0400591 # we shall find the logical device id from the parent_id of the olt
592 # (root) device
593 device = self.get(
594 '/api/v1/devices/{}'.format(olt_id))
595 self.assertNotEqual(device['parent_id'], '')
596 logical_device = self.get(
597 '/api/v1/logical_devices/{}'.format(device['parent_id']))
598
599 # the logical device shall be linked back to the hard device,
600 # its ports too
601 self.assertEqual(logical_device['root_device_id'], device['id'])
602
603 logical_ports = self.get(
604 '/api/v1/logical_devices/{}/ports'.format(
605 logical_device['id'])
606 )['items']
607 self.assertGreaterEqual(len(logical_ports), 1)
608 logical_port = logical_ports[0]
609 self.assertEqual(logical_port['id'], 'nni')
610 self.assertEqual(logical_port['ofp_port']['name'], 'nni')
611 self.assertEqual(logical_port['ofp_port']['port_no'], 129)
612 self.assertEqual(logical_port['device_id'], device['id'])
613 self.assertEqual(logical_port['device_port_no'], 2)
614 return logical_device['id']
615
khenaidood3c335e2017-07-05 16:36:59 -0400616 def _list_logical_devices_rest(self):
khenaidoo08d48d22017-06-29 19:42:49 -0400617 res = self.get('/api/v1/logical_devices')
618 self.assertGreaterEqual(len(res['items']), 1)
619 return res
620
khenaidood3c335e2017-07-05 16:36:59 -0400621 def _get_logical_device_rest(self, id):
khenaidoo08d48d22017-06-29 19:42:49 -0400622 res = self.get('/api/v1/logical_devices/{}'.format(id))
623 self.assertIsNotNone(res['datapath_id'])
624
khenaidood3c335e2017-07-05 16:36:59 -0400625 def _list_logical_device_ports_rest(self, id):
khenaidoo08d48d22017-06-29 19:42:49 -0400626 res = self.get('/api/v1/logical_devices/{}/ports'.format(id))
627 self.assertGreaterEqual(len(res['items']), 1)
628
khenaidood3c335e2017-07-05 16:36:59 -0400629 def _list_and_update_logical_device_flows_rest(self, id):
khenaidoo08d48d22017-06-29 19:42:49 -0400630
631 # retrieve flow list
632 res = self.get('/api/v1/logical_devices/{}/flows'.format(id))
633 len_before = len(res['items'])
634
635 # add some flows
636 req = ofp.FlowTableUpdate(
637 id=id,
638 flow_mod=mk_simple_flow_mod(
639 cookie=randint(1, 10000000000),
640 priority=len_before,
641 match_fields=[
642 in_port(129)
643 ],
644 actions=[
645 output(1)
646 ]
647 )
648 )
649 res = self.post('/api/v1/logical_devices/{}/flows'.format(id),
650 MessageToDict(req, preserving_proto_field_name=True),
Stephane Barbariecd51f992017-09-07 16:37:02 -0400651 expected_http_code=200)
khenaidoo08d48d22017-06-29 19:42:49 -0400652 # TODO check some stuff on res
653
654 res = self.get('/api/v1/logical_devices/{}/flows'.format(id))
655 len_after = len(res['items'])
656 self.assertGreater(len_after, len_before)
657
khenaidood3c335e2017-07-05 16:36:59 -0400658 def _list_and_update_logical_device_flow_groups_rest(self, id):
khenaidoo08d48d22017-06-29 19:42:49 -0400659
660 # retrieve flow list
661 res = self.get('/api/v1/logical_devices/{}/flow_groups'.format(id))
662 len_before = len(res['items'])
663
664 # add some flows
665 req = ofp.FlowGroupTableUpdate(
666 id=id,
667 group_mod=ofp.ofp_group_mod(
668 command=ofp.OFPGC_ADD,
669 type=ofp.OFPGT_ALL,
670 group_id=len_before + 1,
671 buckets=[
672 ofp.ofp_bucket(
673 actions=[
674 ofp.ofp_action(
675 type=ofp.OFPAT_OUTPUT,
676 output=ofp.ofp_action_output(
677 port=1
678 )
679 )
680 ]
681 )
682 ]
683 )
684 )
685 res = self.post('/api/v1/logical_devices/{}/flow_groups'.format(id),
686 MessageToDict(req, preserving_proto_field_name=True),
Stephane Barbariecd51f992017-09-07 16:37:02 -0400687 expected_http_code=200)
khenaidoo08d48d22017-06-29 19:42:49 -0400688 # TODO check some stuff on res
689
690 res = self.get('/api/v1/logical_devices/{}/flow_groups'.format(id))
691 len_after = len(res['items'])
692 self.assertGreater(len_after, len_before)
693
khenaidood3c335e2017-07-05 16:36:59 -0400694 def _list_devices_rest(self, count=2):
khenaidoo08d48d22017-06-29 19:42:49 -0400695 res = self.get('/api/v1/devices')
khenaidood3c335e2017-07-05 16:36:59 -0400696 self.assertGreaterEqual(len(res['items']), count)
khenaidoo08d48d22017-06-29 19:42:49 -0400697 return res
698
khenaidood3c335e2017-07-05 16:36:59 -0400699 def _get_device_rest(self, id):
khenaidoo08d48d22017-06-29 19:42:49 -0400700 res = self.get('/api/v1/devices/{}'.format(id))
701 # TODO test result
702
khenaidood3c335e2017-07-05 16:36:59 -0400703 def _list_device_ports_rest(self, id, count=2):
khenaidoo08d48d22017-06-29 19:42:49 -0400704 res = self.get('/api/v1/devices/{}/ports'.format(id))
khenaidood3c335e2017-07-05 16:36:59 -0400705 self.assertGreaterEqual(len(res['items']), count)
khenaidoo08d48d22017-06-29 19:42:49 -0400706
khenaidood3c335e2017-07-05 16:36:59 -0400707 def _list_device_flows_rest(self, id, count=1):
khenaidoo08d48d22017-06-29 19:42:49 -0400708 # pump some flows into the logical device
709 res = self.get('/api/v1/devices/{}/flows'.format(id))
khenaidood3c335e2017-07-05 16:36:59 -0400710 self.assertGreaterEqual(len(res['items']), count)
khenaidoo08d48d22017-06-29 19:42:49 -0400711
khenaidood3c335e2017-07-05 16:36:59 -0400712 def _list_device_flow_groups_rest(self, id, count=0):
khenaidoo08d48d22017-06-29 19:42:49 -0400713 res = self.get('/api/v1/devices/{}/flow_groups'.format(id))
khenaidood3c335e2017-07-05 16:36:59 -0400714 self.assertGreaterEqual(len(res['items']), count)
khenaidoo08d48d22017-06-29 19:42:49 -0400715
khenaidood3c335e2017-07-05 16:36:59 -0400716 def _list_device_types_rest(self, count=2):
khenaidoo08d48d22017-06-29 19:42:49 -0400717 res = self.get('/api/v1/device_types')
khenaidood3c335e2017-07-05 16:36:59 -0400718 self.assertGreaterEqual(len(res['items']), count)
khenaidoo08d48d22017-06-29 19:42:49 -0400719 return res
720
khenaidood3c335e2017-07-05 16:36:59 -0400721 def _get_device_type_rest(self, dtype):
khenaidoo08d48d22017-06-29 19:42:49 -0400722 res = self.get('/api/v1/device_types/{}'.format(dtype))
723 self.assertIsNotNone(res)
724 # TODO test the result
725
726 def _list_device_groups(self):
727 pass
728 # res = self.get('/api/v1/device_groups')
729 # self.assertGreaterEqual(len(res['items']), 1)
730
731 def _get_device_group(self):
732 pass
733 # res = self.get('/api/v1/device_groups/1')
734 # # TODO test the result
735
khenaidood3c335e2017-07-05 16:36:59 -0400736 def _get_images_rest(self, id):
khenaidoo08d48d22017-06-29 19:42:49 -0400737 res = self.get('/api/v1/devices/{}/images'.format(id))
738 self.assertIsNotNone(res)
739
khenaidood3c335e2017-07-05 16:36:59 -0400740 def _self_test_rest(self, id):
khenaidoo08d48d22017-06-29 19:42:49 -0400741 res = self.post('/api/v1/devices/{}/self_test'.format(id),
Stephane Barbariecd51f992017-09-07 16:37:02 -0400742 expected_http_code=200)
khenaidoo08d48d22017-06-29 19:42:49 -0400743 self.assertIsNotNone(res)
744
khenaidood3c335e2017-07-05 16:36:59 -0400745 def _create_device_filter_rest(self, device_id):
khenaidoo08d48d22017-06-29 19:42:49 -0400746 rules = list()
747 rule = dict()
748
749 # Create a filter with a single rule
750 rule['key'] = 'device_id'
751 rule['value'] = device_id
752 rules.append(rule)
753
754 alarm_filter = AlarmFilter(rules=rules)
755 alarm_filter = self.post('/api/v1/alarm_filters',
756 MessageToDict(alarm_filter),
Stephane Barbariecd51f992017-09-07 16:37:02 -0400757 expected_http_code=200)
khenaidoo08d48d22017-06-29 19:42:49 -0400758 self.assertIsNotNone(alarm_filter)
759 return alarm_filter
760
khenaidood3c335e2017-07-05 16:36:59 -0400761 def _remove_device_filter_rest(self, alarm_filter_id):
khenaidoo08d48d22017-06-29 19:42:49 -0400762 path = '/api/v1/alarm_filters/{}'.format(alarm_filter_id)
Stephane Barbariecd51f992017-09-07 16:37:02 -0400763 self.delete(path, expected_http_code=200)
764 alarm_filter = self.get(path, expected_http_code=200, grpc_status=5)
khenaidoo08d48d22017-06-29 19:42:49 -0400765 self.assertIsNone(alarm_filter)
766
khenaidood3c335e2017-07-05 16:36:59 -0400767 def _get_alarm_filter_grpc(self, stub, alarm_filter_id):
768 res = stub.GetAlarmFilter(voltha_pb2.ID(id=alarm_filter_id))
769 return res
770
771 def _get_alarm_filters_grpc(self, stub):
772 res = stub.ListAlarmFilters(Empty())
773 return res
774
775 def _get_alarm_filters_rest(self):
776 res = self.get('/api/v1/alarm_filters')
777 return res
778
779 def _install_eapol_flow_grpc(self, stub, logical_device_id):
780 """
781 Install an EAPOL flow on the given logical device. If device is not
782 given, it will be applied to logical device of the last pre-provisioned
783 OLT device.
784 """
785
786 # gather NNI and UNI port IDs
787 nni_port_no, unis = self._get_logical_ports(stub, logical_device_id)
788
789 # construct and push flow rule
790 for uni_port_no, _ in unis:
791 update = FlowTableUpdate(
792 id=logical_device_id,
793 flow_mod=mk_simple_flow_mod(
794 priority=2000,
795 match_fields=[in_port(uni_port_no), eth_type(0x888e)],
796 actions=[
797 # push_vlan(0x8100),
798 # set_field(vlan_vid(4096 + 4000)),
799 output(ofp.OFPP_CONTROLLER)
800 ]
801 )
802 )
803 res = stub.UpdateLogicalDeviceFlowTable(update)
804 self.pt('success for uni {} ({})'.format(uni_port_no, res))
805
806 def _get_logical_ports(self, stub, logical_device_id):
807 """
808 Return the NNI port number and the first usable UNI port of logical
809 device, and the vlan associated with the latter.
810 """
811 ports = stub.ListLogicalDevicePorts(
812 voltha_pb2.ID(id=logical_device_id)).items
813 nni = None
814 unis = []
815 for port in ports:
816 if port.root_port:
817 assert nni is None, "There shall be only one root port"
818 nni = port.ofp_port.port_no
819 else:
820 uni = port.ofp_port.port_no
821 uni_device = self._get_device_grpc(stub, port.device_id)
822 vlan = uni_device.vlan
823 unis.append((uni, vlan))
824
825 assert nni is not None, "No NNI port found"
826 assert unis, "Not a single UNI?"
827
828 return nni, unis
829
830 def _get_device_grpc(self, stub, device_id, depth=0):
831 res = stub.GetDevice(voltha_pb2.ID(id=device_id),
832 metadata=(('get-depth', str(depth)),))
833 return res
834
835 def _verify_olt_eapol_flow_rest(self, logical_device_id):
836 flows = self.get('/api/v1/devices/{}/flows'.format(logical_device_id))[
837 'items']
Richard Jankowski461cb972018-04-11 15:36:27 -0400838 self.assertEqual(len(flows), 8)
khenaidood3c335e2017-07-05 16:36:59 -0400839 flow = flows[1]
840 self.assertEqual(flow['table_id'], 0)
841 self.assertEqual(flow['priority'], 2000)
842
843
844 def _get_olt_flows_grpc(self, stub, logical_device_id):
845 res = stub.ListLogicalDeviceFlows(voltha_pb2.ID(id=logical_device_id))
846 return res
847
Rachit Shrivastavaa182e912017-07-28 15:18:34 -0400848 #For xPON objects
849 def _get_path(self, type, name, operation, device_id=None):
850 if(type == 'channel_terminations'):
851 return '/api/v1/devices/{}/{}/{}{}'.format(device_id, type, name,
852 operation)
853 return '/api/v1/{}/{}{}'.format(type, name, operation)
854
855 def _get_xpon_object_rest(self, obj_type, device_id=None):
856 if obj_type["type"] == "channel_terminations":
857 res = self.get('/api/v1/devices/{}/{}'.format(device_id,
858 obj_type["type"]))
859 else:
860 res = self.get('/api/v1/{}'.format(obj_type["type"]))
Rachit Shrivastava8f4f9bf2017-07-20 11:59:30 -0400861 return res
862
Rachit Shrivastavaa182e912017-07-28 15:18:34 -0400863 def _get_xpon_object_grpc(self, stub, obj_type, device_id=None):
864 if obj_type["type"] == "channel_groups":
865 res = stub.GetAllChannelgroupConfig(Empty())
866 elif obj_type["type"] == "channel_partitions":
867 res = stub.GetAllChannelpartitionConfig(Empty())
868 elif obj_type["type"] == "channel_pairs":
869 res = stub.GetAllChannelpairConfig(Empty())
870 elif obj_type["type"] == "channel_terminations":
871 res = stub.GetAllChannelterminationConfig(
872 voltha_pb2.ID(id=device_id))
873 elif obj_type["type"] == "v_ont_anis":
874 res = stub.GetAllVOntaniConfig(Empty())
875 elif obj_type["type"] == "ont_anis":
876 res = stub.GetAllOntaniConfig(Empty())
877 elif obj_type["type"] == "v_enets":
878 res = stub.GetAllVEnetConfig(Empty())
Rachit Shrivastava1b2478e2018-03-01 11:53:49 -0500879 elif obj_type["type"] == "gemports":
880 res = stub.GetAllGemportsConfigData(Empty())
881 elif obj_type["type"] == "tconts":
882 res = stub.GetAllTcontsConfigData(Empty())
883 elif obj_type["type"] == "traffic_descriptor_profiles":
884 res = stub.GetAllTrafficDescriptorProfileData(Empty())
Rachit Shrivastava8f4f9bf2017-07-20 11:59:30 -0400885 return res
886
Rachit Shrivastavaa182e912017-07-28 15:18:34 -0400887 def _create_xpon_object_rest(self, obj_type, value, device_id=None):
Rachit Shrivastava8f4f9bf2017-07-20 11:59:30 -0400888 ParseDict(value['rpc'], value['pb2'])
889 request = value['pb2']
Rachit Shrivastavaa182e912017-07-28 15:18:34 -0400890 self.post(self._get_path(obj_type["type"], value['rpc']['name'], "",
891 device_id),
Rachit Shrivastava8f4f9bf2017-07-20 11:59:30 -0400892 MessageToDict(request, preserving_proto_field_name = True),
Stephane Barbariecd51f992017-09-07 16:37:02 -0400893 expected_http_code = 200)
Rachit Shrivastava8f4f9bf2017-07-20 11:59:30 -0400894 return request
895
Rachit Shrivastavaa182e912017-07-28 15:18:34 -0400896 def _delete_xpon_object_rest(self, obj_type, value, device_id=None):
897 self.delete(self._get_path(obj_type["type"], value['rpc']['name'],
Stephane Barbariecd51f992017-09-07 16:37:02 -0400898 "/delete", device_id), expected_http_code = 200)
Rachit Shrivastavaa182e912017-07-28 15:18:34 -0400899
900 def _verify_xpon_object_on_device(self, type_config, stub, device_id=None):
901 global_xpon_obj = self._get_xpon_object_rest(type_config, device_id)
902 xpon_obj = self._get_xpon_object_grpc(stub, type_config, device_id)
903 assert global_xpon_obj == MessageToDict(xpon_obj,
904 including_default_value_fields = True,
905 preserving_proto_field_name = True)
khenaidoo08d48d22017-06-29 19:42:49 -0400906
907if __name__ == '__main__':
908 main()