Zack Williams | 41513bf | 2018-07-07 20:08:35 -0700 | [diff] [blame] | 1 | # 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. |
khenaidoo | 08d48d2 | 2017-06-29 19:42:49 -0400 | [diff] [blame] | 14 | from random import randint |
| 15 | from time import time, sleep |
| 16 | |
Rachit Shrivastava | 8f4f9bf | 2017-07-20 11:59:30 -0400 | [diff] [blame] | 17 | from google.protobuf.json_format import MessageToDict, ParseDict |
Stephane Barbarie | cd51f99 | 2017-09-07 16:37:02 -0400 | [diff] [blame] | 18 | from unittest import main, skip |
khenaidoo | 08d48d2 | 2017-06-29 19:42:49 -0400 | [diff] [blame] | 19 | from voltha.protos.device_pb2 import Device |
| 20 | from tests.itests.voltha.rest_base import RestBase |
khenaidoo | d3c335e | 2017-07-05 16:36:59 -0400 | [diff] [blame] | 21 | from common.utils.consulhelpers import get_endpoint_from_consul, \ |
| 22 | get_all_instances_of_service |
khenaidoo | 08d48d2 | 2017-06-29 19:42:49 -0400 | [diff] [blame] | 23 | from common.utils.consulhelpers import verify_all_services_healthy |
Richard Jankowski | 461cb97 | 2018-04-11 15:36:27 -0400 | [diff] [blame] | 24 | from tests.itests.test_utils import \ |
khenaidoo | 08d48d2 | 2017-06-29 19:42:49 -0400 | [diff] [blame] | 25 | run_command_to_completion_with_raw_stdout, \ |
| 26 | run_command_to_completion_with_stdout_in_list |
| 27 | from voltha.protos.voltha_pb2 import AlarmFilter |
khenaidoo | d3c335e | 2017-07-05 16:36:59 -0400 | [diff] [blame] | 28 | from google.protobuf.empty_pb2 import Empty |
| 29 | import grpc |
| 30 | from voltha.protos import third_party |
Scott Baker | d865fa2 | 2018-11-07 11:45:28 -0800 | [diff] [blame] | 31 | from voltha.protos import voltha_pb2, voltha_pb2_grpc |
khenaidoo | d3c335e | 2017-07-05 16:36:59 -0400 | [diff] [blame] | 32 | from voltha.core.flow_decomposer import * |
| 33 | from voltha.protos.openflow_13_pb2 import FlowTableUpdate |
Rachit Shrivastava | 8f4f9bf | 2017-07-20 11:59:30 -0400 | [diff] [blame] | 34 | from voltha.protos import bbf_fiber_base_pb2 as fb |
Richard Jankowski | 461cb97 | 2018-04-11 15:36:27 -0400 | [diff] [blame] | 35 | from tests.itests.voltha.xpon_scenario import scenario as xpon_scenario |
| 36 | from tests.itests.test_utils import get_pod_ip |
| 37 | from tests.itests.orch_environment import get_orch_environment |
| 38 | from testconfig import config |
khenaidoo | 08d48d2 | 2017-06-29 19:42:49 -0400 | [diff] [blame] | 39 | |
| 40 | LOCAL_CONSUL = "localhost:8500" |
khenaidoo | 2a8c633 | 2017-10-10 15:23:49 -0400 | [diff] [blame] | 41 | DOCKER_COMPOSE_FILE = "compose/docker-compose-system-test-dispatcher.yml" |
Richard Jankowski | 461cb97 | 2018-04-11 15:36:27 -0400 | [diff] [blame] | 42 | ENV_DOCKER_COMPOSE = 'docker-compose' |
| 43 | ENV_K8S_SINGLE_NODE = 'k8s-single-node' |
| 44 | |
| 45 | orch_env = ENV_DOCKER_COMPOSE |
| 46 | if 'test_parameters' in config and 'orch_env' in config['test_parameters']: |
| 47 | orch_env = config['test_parameters']['orch_env'] |
| 48 | print 'orchestration-environment: %s' % orch_env |
| 49 | orch = get_orch_environment(orch_env) |
khenaidoo | 08d48d2 | 2017-06-29 19:42:49 -0400 | [diff] [blame] | 50 | |
| 51 | command_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), |
khenaidoo | d3c335e | 2017-07-05 16:36:59 -0400 | [diff] [blame] | 57 | docker_compose_scale_voltha="docker-compose -f {} scale " |
Richard Jankowski | 461cb97 | 2018-04-11 15:36:27 -0400 | [diff] [blame] | 58 | "voltha=".format(DOCKER_COMPOSE_FILE) |
khenaidoo | 08d48d2 | 2017-06-29 19:42:49 -0400 | [diff] [blame] | 59 | ) |
| 60 | |
Richard Jankowski | 461cb97 | 2018-04-11 15:36:27 -0400 | [diff] [blame] | 61 | command_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 | |
| 68 | commands = { |
| 69 | ENV_DOCKER_COMPOSE: command_defs, |
| 70 | ENV_K8S_SINGLE_NODE: command_k8s |
| 71 | } |
| 72 | vcore_svc_name = { |
| 73 | ENV_DOCKER_COMPOSE: 'vcore-grpc', |
| 74 | ENV_K8S_SINGLE_NODE: 'vcore' |
| 75 | } |
| 76 | envoy_svc_name = { |
| 77 | ENV_DOCKER_COMPOSE: 'voltha-grpc', |
| 78 | ENV_K8S_SINGLE_NODE: 'voltha' |
| 79 | } |
Rachit Shrivastava | a182e91 | 2017-07-28 15:18:34 -0400 | [diff] [blame] | 80 | obj_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 Shrivastava | 1b2478e | 2018-03-01 11:53:49 -0500 | [diff] [blame] | 94 | '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 Shrivastava | a182e91 | 2017-07-28 15:18:34 -0400 | [diff] [blame] | 101 | } |
Rachit Shrivastava | 8f4f9bf | 2017-07-20 11:59:30 -0400 | [diff] [blame] | 102 | |
Richard Jankowski | 461cb97 | 2018-04-11 15:36:27 -0400 | [diff] [blame] | 103 | def 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] |
khenaidoo | d3c335e | 2017-07-05 16:36:59 -0400 | [diff] [blame] | 108 | |
khenaidoo | 08d48d2 | 2017-06-29 19:42:49 -0400 | [diff] [blame] | 109 | class DispatcherTest(RestBase): |
khenaidoo | d3c335e | 2017-07-05 16:36:59 -0400 | [diff] [blame] | 110 | def setUp(self): |
| 111 | self.grpc_channels = dict() |
khenaidoo | 08d48d2 | 2017-06-29 19:42:49 -0400 | [diff] [blame] | 112 | |
| 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 | |
khenaidoo | 08d48d2 | 2017-06-29 19:42:49 -0400 | [diff] [blame] | 121 | 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 | |
khenaidoo | d3c335e | 2017-07-05 16:36:59 -0400 | [diff] [blame] | 129 | 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] |
khenaidoo | 08d48d2 | 2017-06-29 19:42:49 -0400 | [diff] [blame] | 134 | |
| 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() |
khenaidoo | 08d48d2 | 2017-06-29 19:42:49 -0400 | [diff] [blame] | 141 | |
Stephane Barbarie | cd51f99 | 2017-09-07 16:37:02 -0400 | [diff] [blame] | 142 | # self._get_root_rest() |
khenaidoo | d3c335e | 2017-07-05 16:36:59 -0400 | [diff] [blame] | 143 | 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() |
khenaidoo | 08d48d2 | 2017-06-29 19:42:49 -0400 | [diff] [blame] | 153 | logical_device_id = ldevices['items'][0]['id'] |
khenaidoo | d3c335e | 2017-07-05 16:36:59 -0400 | [diff] [blame] | 154 | 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() |
khenaidoo | 08d48d2 | 2017-06-29 19:42:49 -0400 | [diff] [blame] | 160 | device_id = devices['items'][0]['id'] |
khenaidoo | d3c335e | 2017-07-05 16:36:59 -0400 | [diff] [blame] | 161 | self._get_device_rest(device_id) |
| 162 | self._list_device_ports_rest(device_id) |
Richard Jankowski | 461cb97 | 2018-04-11 15:36:27 -0400 | [diff] [blame] | 163 | # TODO: Figure out why this test fails |
| 164 | # self._list_device_flows_rest(device_id) |
khenaidoo | d3c335e | 2017-07-05 16:36:59 -0400 | [diff] [blame] | 165 | 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 Shrivastava | a182e91 | 2017-07-28 15:18:34 -0400 | [diff] [blame] | 172 | #for xPON objects |
| 173 | for item in xpon_scenario: |
| 174 | for key,value in item.items(): |
Stephane Barbarie | cd51f99 | 2017-09-07 16:37:02 -0400 | [diff] [blame] | 175 | 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 Shrivastava | a182e91 | 2017-07-28 15:18:34 -0400 | [diff] [blame] | 193 | continue |
Stephane Barbarie | cd51f99 | 2017-09-07 16:37:02 -0400 | [diff] [blame] | 194 | |
khenaidoo | 08d48d2 | 2017-06-29 19:42:49 -0400 | [diff] [blame] | 195 | # TODO: PM APIs test |
| 196 | |
khenaidoo | 2a8c633 | 2017-10-10 15:23:49 -0400 | [diff] [blame] | 197 | # @skip('Test fails due to environment configuration. Need to investigate. Refer to VOL-427') |
khenaidoo | 08d48d2 | 2017-06-29 19:42:49 -0400 | [diff] [blame] | 198 | def test_02_cross_instances_dispatch(self): |
khenaidoo | d3c335e | 2017-07-05 16:36:59 -0400 | [diff] [blame] | 199 | |
| 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() |
khenaidoo | d3c335e | 2017-07-05 16:36:59 -0400 | [diff] [blame] | 212 | |
| 213 | # Scale voltha to 3 instances and setup the voltha grpc assigments |
| 214 | self._scale_voltha(3) |
Richard Jankowski | 461cb97 | 2018-04-11 15:36:27 -0400 | [diff] [blame] | 215 | 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') |
khenaidoo | d3c335e | 2017-07-05 16:36:59 -0400 | [diff] [blame] | 217 | self.assertEqual(len(voltha_instances), 3) |
Scott Baker | d865fa2 | 2018-11-07 11:45:28 -0800 | [diff] [blame] | 218 | self.ponsim_voltha_stub_local = voltha_pb2_grpc.VolthaLocalServiceStub( |
khenaidoo | d3c335e | 2017-07-05 16:36:59 -0400 | [diff] [blame] | 219 | self.get_channel(self._get_grpc_address(voltha_instances[2]))) |
Scott Baker | d865fa2 | 2018-11-07 11:45:28 -0800 | [diff] [blame] | 220 | self.ponsim_voltha_stub_global = voltha_pb2_grpc.VolthaGlobalServiceStub( |
khenaidoo | d3c335e | 2017-07-05 16:36:59 -0400 | [diff] [blame] | 221 | self.get_channel(self._get_grpc_address(voltha_instances[2]))) |
| 222 | |
Scott Baker | d865fa2 | 2018-11-07 11:45:28 -0800 | [diff] [blame] | 223 | self.simulated_voltha_stub_local = voltha_pb2_grpc.VolthaLocalServiceStub( |
khenaidoo | d3c335e | 2017-07-05 16:36:59 -0400 | [diff] [blame] | 224 | self.get_channel(self._get_grpc_address(voltha_instances[1]))) |
Scott Baker | d865fa2 | 2018-11-07 11:45:28 -0800 | [diff] [blame] | 225 | self.simulated_voltha_stub_global = voltha_pb2_grpc.VolthaGlobalServiceStub( |
khenaidoo | d3c335e | 2017-07-05 16:36:59 -0400 | [diff] [blame] | 226 | self.get_channel(self._get_grpc_address(voltha_instances[1]))) |
| 227 | |
Scott Baker | d865fa2 | 2018-11-07 11:45:28 -0800 | [diff] [blame] | 228 | self.empty_voltha_stub_local = voltha_pb2_grpc.VolthaLocalServiceStub( |
khenaidoo | d3c335e | 2017-07-05 16:36:59 -0400 | [diff] [blame] | 229 | self.get_channel(self._get_grpc_address(voltha_instances[0]))) |
Scott Baker | d865fa2 | 2018-11-07 11:45:28 -0800 | [diff] [blame] | 230 | self.empty_voltha_stub_global = voltha_pb2_grpc.VolthaGlobalServiceStub( |
khenaidoo | d3c335e | 2017-07-05 16:36:59 -0400 | [diff] [blame] | 231 | self.get_channel(self._get_grpc_address(voltha_instances[0]))) |
| 232 | |
Richard Jankowski | 461cb97 | 2018-04-11 15:36:27 -0400 | [diff] [blame] | 233 | 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 ...') |
khenaidoo | d3c335e | 2017-07-05 16:36:59 -0400 | [diff] [blame] | 238 | |
Richard Jankowski | 461cb97 | 2018-04-11 15:36:27 -0400 | [diff] [blame] | 239 | prompt(prompt_for_return, |
| 240 | '\nEnsure port forwarding is set on ponmgnt ...') |
khenaidoo | d3c335e | 2017-07-05 16:36:59 -0400 | [diff] [blame] | 241 | |
| 242 | # Test 1: |
khenaidoo | 997edbc | 2017-07-13 10:25:58 -0400 | [diff] [blame] | 243 | # 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: |
khenaidoo | d3c335e | 2017-07-05 16:36:59 -0400 | [diff] [blame] | 251 | # 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) |
khenaidoo | 997edbc | 2017-07-13 10:25:58 -0400 | [diff] [blame] | 262 | # Test 3: |
khenaidoo | d3c335e | 2017-07-05 16:36:59 -0400 | [diff] [blame] | 263 | # 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 | |
khenaidoo | 997edbc | 2017-07-13 10:25:58 -0400 | [diff] [blame] | 273 | # Test 4: |
khenaidoo | d3c335e | 2017-07-05 16:36:59 -0400 | [diff] [blame] | 274 | # 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 | |
khenaidoo | 997edbc | 2017-07-13 10:25:58 -0400 | [diff] [blame] | 281 | # Test 5: |
khenaidoo | d3c335e | 2017-07-05 16:36:59 -0400 | [diff] [blame] | 282 | # 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 | |
khenaidoo | 997edbc | 2017-07-13 10:25:58 -0400 | [diff] [blame] | 298 | # Test 6: |
khenaidoo | d3c335e | 2017-07-05 16:36:59 -0400 | [diff] [blame] | 299 | # 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 | |
khenaidoo | 997edbc | 2017-07-13 10:25:58 -0400 | [diff] [blame] | 314 | # Test 7: |
khenaidoo | d3c335e | 2017-07-05 16:36:59 -0400 | [diff] [blame] | 315 | # 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 Shrivastava | 8f4f9bf | 2017-07-20 11:59:30 -0400 | [diff] [blame] | 324 | # Test 8: |
Rachit Shrivastava | a182e91 | 2017-07-28 15:18:34 -0400 | [diff] [blame] | 325 | # 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 Shrivastava | 1b2478e | 2018-03-01 11:53:49 -0500 | [diff] [blame] | 328 | 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 Shrivastava | 8f4f9bf | 2017-07-20 11:59:30 -0400 | [diff] [blame] | 377 | |
Rachit Shrivastava | 1b2478e | 2018-03-01 11:53:49 -0500 | [diff] [blame] | 378 | #TODO: More tests to be added as new features are added |
khenaidoo | d3c335e | 2017-07-05 16:36:59 -0400 | [diff] [blame] | 379 | |
| 380 | |
| 381 | def _get_grpc_address(self, voltha_instance): |
| 382 | address = '{}:{}'.format(voltha_instance['ServiceAddress'], |
| 383 | voltha_instance['ServicePort']) |
| 384 | return address |
khenaidoo | 08d48d2 | 2017-06-29 19:42:49 -0400 | [diff] [blame] | 385 | |
| 386 | def _stop_and_remove_all_containers(self): |
| 387 | # check if there are any running containers first |
Richard Jankowski | 461cb97 | 2018-04-11 15:36:27 -0400 | [diff] [blame] | 388 | cmd = get_command('docker_ps') |
khenaidoo | 08d48d2 | 2017-06-29 19:42:49 -0400 | [diff] [blame] | 389 | 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 Jankowski | 461cb97 | 2018-04-11 15:36:27 -0400 | [diff] [blame] | 392 | cmd = get_command('docker_stop_and_remove_all_containers') |
khenaidoo | 08d48d2 | 2017-06-29 19:42:49 -0400 | [diff] [blame] | 393 | 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 Jankowski | 461cb97 | 2018-04-11 15:36:27 -0400 | [diff] [blame] | 401 | cmd = get_command('docker_compose_start_all') |
khenaidoo | 08d48d2 | 2017-06-29 19:42:49 -0400 | [diff] [blame] | 402 | out, err, rc = run_command_to_completion_with_raw_stdout(cmd) |
| 403 | self.assertEqual(rc, 0) |
| 404 | |
khenaidoo | 079a776 | 2017-10-26 21:42:05 -0400 | [diff] [blame] | 405 | self.pt("Waiting for voltha container to be ready ...") |
khenaidoo | 08d48d2 | 2017-06-29 19:42:49 -0400 | [diff] [blame] | 406 | self.wait_till('voltha services HEALTHY', |
Richard Jankowski | 461cb97 | 2018-04-11 15:36:27 -0400 | [diff] [blame] | 407 | lambda: orch.verify_all_services_healthy( |
| 408 | service_name=envoy_svc_name[orch_env]) == True, |
khenaidoo | 08d48d2 | 2017-06-29 19:42:49 -0400 | [diff] [blame] | 409 | timeout=10) |
khenaidoo | 08d48d2 | 2017-06-29 19:42:49 -0400 | [diff] [blame] | 410 | sleep(10) |
| 411 | |
| 412 | def set_rest_endpoint(self): |
Richard Jankowski | 461cb97 | 2018-04-11 15:36:27 -0400 | [diff] [blame] | 413 | 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') |
ubuntu | c5c83d7 | 2017-07-01 17:57:19 -0700 | [diff] [blame] | 418 | self.base_url = 'https://' + self.rest_endpoint |
khenaidoo | 08d48d2 | 2017-06-29 19:42:49 -0400 | [diff] [blame] | 419 | |
| 420 | def set_kafka_endpoint(self): |
| 421 | self.kafka_endpoint = get_endpoint_from_consul(LOCAL_CONSUL, 'kafka') |
| 422 | |
khenaidoo | d3c335e | 2017-07-05 16:36:59 -0400 | [diff] [blame] | 423 | def _scale_voltha(self, scale=2): |
| 424 | self.pt("Scaling voltha ...") |
Richard Jankowski | 461cb97 | 2018-04-11 15:36:27 -0400 | [diff] [blame] | 425 | cmd = get_command('docker_compose_scale_voltha') + str(scale) |
khenaidoo | d3c335e | 2017-07-05 16:36:59 -0400 | [diff] [blame] | 426 | out, err, rc = run_command_to_completion_with_raw_stdout(cmd) |
| 427 | self.assertEqual(rc, 0) |
khenaidoo | 08d48d2 | 2017-06-29 19:42:49 -0400 | [diff] [blame] | 428 | |
khenaidoo | d3c335e | 2017-07-05 16:36:59 -0400 | [diff] [blame] | 429 | def _get_root_rest(self): |
khenaidoo | 08d48d2 | 2017-06-29 19:42:49 -0400 | [diff] [blame] | 430 | res = self.get('/', expected_content_type='text/html') |
| 431 | self.assertGreaterEqual(res.find('swagger'), 0) |
| 432 | |
khenaidoo | d3c335e | 2017-07-05 16:36:59 -0400 | [diff] [blame] | 433 | def _get_schema_rest(self): |
khenaidoo | 08d48d2 | 2017-06-29 19:42:49 -0400 | [diff] [blame] | 434 | res = self.get('/schema') |
khenaidoo | d3c335e | 2017-07-05 16:36:59 -0400 | [diff] [blame] | 435 | self.assertEqual(set(res.keys()), |
| 436 | {'protos', 'yang_from', 'swagger_from'}) |
khenaidoo | 08d48d2 | 2017-06-29 19:42:49 -0400 | [diff] [blame] | 437 | |
khenaidoo | d3c335e | 2017-07-05 16:36:59 -0400 | [diff] [blame] | 438 | def _get_health_rest(self): |
khenaidoo | 08d48d2 | 2017-06-29 19:42:49 -0400 | [diff] [blame] | 439 | res = self.get('/health') |
| 440 | self.assertEqual(res['state'], 'HEALTHY') |
| 441 | |
| 442 | # ~~~~~~~~~~~~~~~~~~~~~ TOP LEVEL VOLTHA OPERATIONS ~~~~~~~~~~~~~~~~~~~~~~~ |
| 443 | |
khenaidoo | d3c335e | 2017-07-05 16:36:59 -0400 | [diff] [blame] | 444 | def _get_voltha_rest(self): |
khenaidoo | 08d48d2 | 2017-06-29 19:42:49 -0400 | [diff] [blame] | 445 | res = self.get('/api/v1') |
| 446 | self.assertEqual(res['version'], '0.9.0') |
| 447 | |
khenaidoo | d3c335e | 2017-07-05 16:36:59 -0400 | [diff] [blame] | 448 | def _list_voltha_instances_rest(self): |
khenaidoo | 08d48d2 | 2017-06-29 19:42:49 -0400 | [diff] [blame] | 449 | res = self.get('/api/v1/instances') |
| 450 | self.assertEqual(len(res['items']), 1) |
| 451 | |
khenaidoo | d3c335e | 2017-07-05 16:36:59 -0400 | [diff] [blame] | 452 | def _get_voltha_instance_rest(self): |
khenaidoo | 08d48d2 | 2017-06-29 19:42:49 -0400 | [diff] [blame] | 453 | res = self.get('/api/v1/instances') |
khenaidoo | d3c335e | 2017-07-05 16:36:59 -0400 | [diff] [blame] | 454 | voltha_id = res['items'][0] |
khenaidoo | 08d48d2 | 2017-06-29 19:42:49 -0400 | [diff] [blame] | 455 | res = self.get('/api/v1/instances/{}'.format(voltha_id)) |
| 456 | self.assertEqual(res['version'], '0.9.0') |
| 457 | |
khenaidoo | d3c335e | 2017-07-05 16:36:59 -0400 | [diff] [blame] | 458 | def _add_olt_device_rest(self, grpc=None): |
khenaidoo | 08d48d2 | 2017-06-29 19:42:49 -0400 | [diff] [blame] | 459 | 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 Barbarie | cd51f99 | 2017-09-07 16:37:02 -0400 | [diff] [blame] | 464 | expected_http_code=200) |
khenaidoo | 08d48d2 | 2017-06-29 19:42:49 -0400 | [diff] [blame] | 465 | return device['id'] |
| 466 | |
khenaidoo | d3c335e | 2017-07-05 16:36:59 -0400 | [diff] [blame] | 467 | 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 Jankowski | 461cb97 | 2018-04-11 15:36:27 -0400 | [diff] [blame] | 476 | 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' |
khenaidoo | d3c335e | 2017-07-05 16:36:59 -0400 | [diff] [blame] | 480 | device = Device( |
| 481 | type='ponsim_olt', |
Richard Jankowski | 461cb97 | 2018-04-11 15:36:27 -0400 | [diff] [blame] | 482 | host_and_port=host_and_port |
khenaidoo | d3c335e | 2017-07-05 16:36:59 -0400 | [diff] [blame] | 483 | ) |
| 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 | |
khenaidoo | 997edbc | 2017-07-13 10:25:58 -0400 | [diff] [blame] | 522 | def _get_adapters_grpc(self, stub): |
| 523 | res = stub.ListAdapters(Empty()) |
| 524 | return res.items |
| 525 | |
khenaidoo | d3c335e | 2017-07-05 16:36:59 -0400 | [diff] [blame] | 526 | 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 Jankowski | 461cb97 | 2018-04-11 15:36:27 -0400 | [diff] [blame] | 536 | # |
| 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 | # |
khenaidoo | d3c335e | 2017-07-05 16:36:59 -0400 | [diff] [blame] | 540 | self.wait_till( |
| 541 | 'find ONUs linked to the olt device', |
| 542 | lambda: len(self._find_onus_grpc(stub, olt_id)) >= count, |
Richard Jankowski | 461cb97 | 2018-04-11 15:36:27 -0400 | [diff] [blame] | 543 | interval=2, timeout=10 |
khenaidoo | d3c335e | 2017-07-05 16:36:59 -0400 | [diff] [blame] | 544 | ) |
| 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): |
khenaidoo | 08d48d2 | 2017-06-29 19:42:49 -0400 | [diff] [blame] | 554 | # 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 | |
khenaidoo | d3c335e | 2017-07-05 16:36:59 -0400 | [diff] [blame] | 562 | def _activate_device_rest(self, olt_id): |
khenaidoo | 08d48d2 | 2017-06-29 19:42:49 -0400 | [diff] [blame] | 563 | path = '/api/v1/devices/{}'.format(olt_id) |
Stephane Barbarie | cd51f99 | 2017-09-07 16:37:02 -0400 | [diff] [blame] | 564 | self.post(path + '/enable', expected_http_code=200) |
khenaidoo | 08d48d2 | 2017-06-29 19:42:49 -0400 | [diff] [blame] | 565 | 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 | |
khenaidoo | d3c335e | 2017-07-05 16:36:59 -0400 | [diff] [blame] | 590 | def _wait_for_logical_device_rest(self, olt_id): |
khenaidoo | 08d48d2 | 2017-06-29 19:42:49 -0400 | [diff] [blame] | 591 | # 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 | |
khenaidoo | d3c335e | 2017-07-05 16:36:59 -0400 | [diff] [blame] | 616 | def _list_logical_devices_rest(self): |
khenaidoo | 08d48d2 | 2017-06-29 19:42:49 -0400 | [diff] [blame] | 617 | res = self.get('/api/v1/logical_devices') |
| 618 | self.assertGreaterEqual(len(res['items']), 1) |
| 619 | return res |
| 620 | |
khenaidoo | d3c335e | 2017-07-05 16:36:59 -0400 | [diff] [blame] | 621 | def _get_logical_device_rest(self, id): |
khenaidoo | 08d48d2 | 2017-06-29 19:42:49 -0400 | [diff] [blame] | 622 | res = self.get('/api/v1/logical_devices/{}'.format(id)) |
| 623 | self.assertIsNotNone(res['datapath_id']) |
| 624 | |
khenaidoo | d3c335e | 2017-07-05 16:36:59 -0400 | [diff] [blame] | 625 | def _list_logical_device_ports_rest(self, id): |
khenaidoo | 08d48d2 | 2017-06-29 19:42:49 -0400 | [diff] [blame] | 626 | res = self.get('/api/v1/logical_devices/{}/ports'.format(id)) |
| 627 | self.assertGreaterEqual(len(res['items']), 1) |
| 628 | |
khenaidoo | d3c335e | 2017-07-05 16:36:59 -0400 | [diff] [blame] | 629 | def _list_and_update_logical_device_flows_rest(self, id): |
khenaidoo | 08d48d2 | 2017-06-29 19:42:49 -0400 | [diff] [blame] | 630 | |
| 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 Barbarie | cd51f99 | 2017-09-07 16:37:02 -0400 | [diff] [blame] | 651 | expected_http_code=200) |
khenaidoo | 08d48d2 | 2017-06-29 19:42:49 -0400 | [diff] [blame] | 652 | # 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 | |
khenaidoo | d3c335e | 2017-07-05 16:36:59 -0400 | [diff] [blame] | 658 | def _list_and_update_logical_device_flow_groups_rest(self, id): |
khenaidoo | 08d48d2 | 2017-06-29 19:42:49 -0400 | [diff] [blame] | 659 | |
| 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 Barbarie | cd51f99 | 2017-09-07 16:37:02 -0400 | [diff] [blame] | 687 | expected_http_code=200) |
khenaidoo | 08d48d2 | 2017-06-29 19:42:49 -0400 | [diff] [blame] | 688 | # 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 | |
khenaidoo | d3c335e | 2017-07-05 16:36:59 -0400 | [diff] [blame] | 694 | def _list_devices_rest(self, count=2): |
khenaidoo | 08d48d2 | 2017-06-29 19:42:49 -0400 | [diff] [blame] | 695 | res = self.get('/api/v1/devices') |
khenaidoo | d3c335e | 2017-07-05 16:36:59 -0400 | [diff] [blame] | 696 | self.assertGreaterEqual(len(res['items']), count) |
khenaidoo | 08d48d2 | 2017-06-29 19:42:49 -0400 | [diff] [blame] | 697 | return res |
| 698 | |
khenaidoo | d3c335e | 2017-07-05 16:36:59 -0400 | [diff] [blame] | 699 | def _get_device_rest(self, id): |
khenaidoo | 08d48d2 | 2017-06-29 19:42:49 -0400 | [diff] [blame] | 700 | res = self.get('/api/v1/devices/{}'.format(id)) |
| 701 | # TODO test result |
| 702 | |
khenaidoo | d3c335e | 2017-07-05 16:36:59 -0400 | [diff] [blame] | 703 | def _list_device_ports_rest(self, id, count=2): |
khenaidoo | 08d48d2 | 2017-06-29 19:42:49 -0400 | [diff] [blame] | 704 | res = self.get('/api/v1/devices/{}/ports'.format(id)) |
khenaidoo | d3c335e | 2017-07-05 16:36:59 -0400 | [diff] [blame] | 705 | self.assertGreaterEqual(len(res['items']), count) |
khenaidoo | 08d48d2 | 2017-06-29 19:42:49 -0400 | [diff] [blame] | 706 | |
khenaidoo | d3c335e | 2017-07-05 16:36:59 -0400 | [diff] [blame] | 707 | def _list_device_flows_rest(self, id, count=1): |
khenaidoo | 08d48d2 | 2017-06-29 19:42:49 -0400 | [diff] [blame] | 708 | # pump some flows into the logical device |
| 709 | res = self.get('/api/v1/devices/{}/flows'.format(id)) |
khenaidoo | d3c335e | 2017-07-05 16:36:59 -0400 | [diff] [blame] | 710 | self.assertGreaterEqual(len(res['items']), count) |
khenaidoo | 08d48d2 | 2017-06-29 19:42:49 -0400 | [diff] [blame] | 711 | |
khenaidoo | d3c335e | 2017-07-05 16:36:59 -0400 | [diff] [blame] | 712 | def _list_device_flow_groups_rest(self, id, count=0): |
khenaidoo | 08d48d2 | 2017-06-29 19:42:49 -0400 | [diff] [blame] | 713 | res = self.get('/api/v1/devices/{}/flow_groups'.format(id)) |
khenaidoo | d3c335e | 2017-07-05 16:36:59 -0400 | [diff] [blame] | 714 | self.assertGreaterEqual(len(res['items']), count) |
khenaidoo | 08d48d2 | 2017-06-29 19:42:49 -0400 | [diff] [blame] | 715 | |
khenaidoo | d3c335e | 2017-07-05 16:36:59 -0400 | [diff] [blame] | 716 | def _list_device_types_rest(self, count=2): |
khenaidoo | 08d48d2 | 2017-06-29 19:42:49 -0400 | [diff] [blame] | 717 | res = self.get('/api/v1/device_types') |
khenaidoo | d3c335e | 2017-07-05 16:36:59 -0400 | [diff] [blame] | 718 | self.assertGreaterEqual(len(res['items']), count) |
khenaidoo | 08d48d2 | 2017-06-29 19:42:49 -0400 | [diff] [blame] | 719 | return res |
| 720 | |
khenaidoo | d3c335e | 2017-07-05 16:36:59 -0400 | [diff] [blame] | 721 | def _get_device_type_rest(self, dtype): |
khenaidoo | 08d48d2 | 2017-06-29 19:42:49 -0400 | [diff] [blame] | 722 | 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 | |
khenaidoo | d3c335e | 2017-07-05 16:36:59 -0400 | [diff] [blame] | 736 | def _get_images_rest(self, id): |
khenaidoo | 08d48d2 | 2017-06-29 19:42:49 -0400 | [diff] [blame] | 737 | res = self.get('/api/v1/devices/{}/images'.format(id)) |
| 738 | self.assertIsNotNone(res) |
| 739 | |
khenaidoo | d3c335e | 2017-07-05 16:36:59 -0400 | [diff] [blame] | 740 | def _self_test_rest(self, id): |
khenaidoo | 08d48d2 | 2017-06-29 19:42:49 -0400 | [diff] [blame] | 741 | res = self.post('/api/v1/devices/{}/self_test'.format(id), |
Stephane Barbarie | cd51f99 | 2017-09-07 16:37:02 -0400 | [diff] [blame] | 742 | expected_http_code=200) |
khenaidoo | 08d48d2 | 2017-06-29 19:42:49 -0400 | [diff] [blame] | 743 | self.assertIsNotNone(res) |
| 744 | |
khenaidoo | d3c335e | 2017-07-05 16:36:59 -0400 | [diff] [blame] | 745 | def _create_device_filter_rest(self, device_id): |
khenaidoo | 08d48d2 | 2017-06-29 19:42:49 -0400 | [diff] [blame] | 746 | 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 Barbarie | cd51f99 | 2017-09-07 16:37:02 -0400 | [diff] [blame] | 757 | expected_http_code=200) |
khenaidoo | 08d48d2 | 2017-06-29 19:42:49 -0400 | [diff] [blame] | 758 | self.assertIsNotNone(alarm_filter) |
| 759 | return alarm_filter |
| 760 | |
khenaidoo | d3c335e | 2017-07-05 16:36:59 -0400 | [diff] [blame] | 761 | def _remove_device_filter_rest(self, alarm_filter_id): |
khenaidoo | 08d48d2 | 2017-06-29 19:42:49 -0400 | [diff] [blame] | 762 | path = '/api/v1/alarm_filters/{}'.format(alarm_filter_id) |
Stephane Barbarie | cd51f99 | 2017-09-07 16:37:02 -0400 | [diff] [blame] | 763 | self.delete(path, expected_http_code=200) |
| 764 | alarm_filter = self.get(path, expected_http_code=200, grpc_status=5) |
khenaidoo | 08d48d2 | 2017-06-29 19:42:49 -0400 | [diff] [blame] | 765 | self.assertIsNone(alarm_filter) |
| 766 | |
khenaidoo | d3c335e | 2017-07-05 16:36:59 -0400 | [diff] [blame] | 767 | 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 Jankowski | 461cb97 | 2018-04-11 15:36:27 -0400 | [diff] [blame] | 838 | self.assertEqual(len(flows), 8) |
khenaidoo | d3c335e | 2017-07-05 16:36:59 -0400 | [diff] [blame] | 839 | 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 Shrivastava | a182e91 | 2017-07-28 15:18:34 -0400 | [diff] [blame] | 848 | #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 Shrivastava | 8f4f9bf | 2017-07-20 11:59:30 -0400 | [diff] [blame] | 861 | return res |
| 862 | |
Rachit Shrivastava | a182e91 | 2017-07-28 15:18:34 -0400 | [diff] [blame] | 863 | 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 Shrivastava | 1b2478e | 2018-03-01 11:53:49 -0500 | [diff] [blame] | 879 | 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 Shrivastava | 8f4f9bf | 2017-07-20 11:59:30 -0400 | [diff] [blame] | 885 | return res |
| 886 | |
Rachit Shrivastava | a182e91 | 2017-07-28 15:18:34 -0400 | [diff] [blame] | 887 | def _create_xpon_object_rest(self, obj_type, value, device_id=None): |
Rachit Shrivastava | 8f4f9bf | 2017-07-20 11:59:30 -0400 | [diff] [blame] | 888 | ParseDict(value['rpc'], value['pb2']) |
| 889 | request = value['pb2'] |
Rachit Shrivastava | a182e91 | 2017-07-28 15:18:34 -0400 | [diff] [blame] | 890 | self.post(self._get_path(obj_type["type"], value['rpc']['name'], "", |
| 891 | device_id), |
Rachit Shrivastava | 8f4f9bf | 2017-07-20 11:59:30 -0400 | [diff] [blame] | 892 | MessageToDict(request, preserving_proto_field_name = True), |
Stephane Barbarie | cd51f99 | 2017-09-07 16:37:02 -0400 | [diff] [blame] | 893 | expected_http_code = 200) |
Rachit Shrivastava | 8f4f9bf | 2017-07-20 11:59:30 -0400 | [diff] [blame] | 894 | return request |
| 895 | |
Rachit Shrivastava | a182e91 | 2017-07-28 15:18:34 -0400 | [diff] [blame] | 896 | 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 Barbarie | cd51f99 | 2017-09-07 16:37:02 -0400 | [diff] [blame] | 898 | "/delete", device_id), expected_http_code = 200) |
Rachit Shrivastava | a182e91 | 2017-07-28 15:18:34 -0400 | [diff] [blame] | 899 | |
| 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) |
khenaidoo | 08d48d2 | 2017-06-29 19:42:49 -0400 | [diff] [blame] | 906 | |
| 907 | if __name__ == '__main__': |
| 908 | main() |