Matteo Scandolo | 48d3d2d | 2017-08-08 13:05:27 -0700 | [diff] [blame] | 1 | |
| 2 | # Copyright 2017-present Open Networking Foundation |
| 3 | # |
| 4 | # Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | # you may not use this file except in compliance with the License. |
| 6 | # You may obtain a copy of the License at |
| 7 | # |
| 8 | # http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | # |
| 10 | # Unless required by applicable law or agreed to in writing, software |
| 11 | # distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | # See the License for the specific language governing permissions and |
| 14 | # limitations under the License. |
| 15 | |
| 16 | |
A R Karthick | ed3a2ca | 2017-07-06 15:50:03 -0700 | [diff] [blame] | 17 | import os |
| 18 | import sys |
| 19 | import time |
| 20 | from nose.tools import * |
| 21 | from CordTestUtils import log_test as log |
| 22 | from OnosCtrl import OnosCtrl |
| 23 | |
| 24 | class XosUtils(object): |
| 25 | |
A R Karthick | 705a5bf | 2017-10-27 11:17:04 -0700 | [diff] [blame] | 26 | head_node = os.getenv('HEAD_NODE', 'head1') |
A R Karthick | ed3a2ca | 2017-07-06 15:50:03 -0700 | [diff] [blame] | 27 | HEAD_NODE = head_node + '.cord.lab' if len(head_node.split('.')) == 1 else head_node |
| 28 | CONTROLLER_PORT = '9000' |
| 29 | our_path = os.path.dirname(os.path.realpath(__file__)) |
| 30 | cord_api_path = os.path.join(our_path, '..', 'cord-api') |
| 31 | framework_path = os.path.join(cord_api_path, 'Framework') |
| 32 | utils_path = os.path.join(framework_path, 'utils') |
| 33 | sys.path.append(utils_path) |
| 34 | sys.path.append(framework_path) |
| 35 | |
| 36 | @classmethod |
| 37 | def getCredentials(cls): |
| 38 | onos_cfg = OnosCtrl.get_config() |
| 39 | if onos_cfg is None: |
| 40 | return None |
| 41 | if 'apps' in onos_cfg and \ |
| 42 | 'org.opencord.vtn' in onos_cfg['apps'] and \ |
| 43 | 'cordvtn' in onos_cfg['apps']['org.opencord.vtn'] and \ |
| 44 | 'xos' in onos_cfg['apps']['org.opencord.vtn']['cordvtn']: |
| 45 | xos_cfg = onos_cfg['apps']['org.opencord.vtn']['cordvtn']['xos'] |
| 46 | endpoint = xos_cfg['endpoint'] |
| 47 | user = xos_cfg['user'] |
| 48 | password = xos_cfg['password'] |
| 49 | xos_endpoints = endpoint.split(':') |
A R Karthick | 3eef13c | 2017-11-06 18:47:25 -0800 | [diff] [blame] | 50 | xos_host = xos_endpoints[0] |
| 51 | xos_port = xos_endpoints[1] |
A R Karthick | ed3a2ca | 2017-07-06 15:50:03 -0700 | [diff] [blame] | 52 | #log.info('xos_host: %s, port: %s, user: %s, password: %s' %(xos_host, xos_port, user, password)) |
| 53 | return dict(host = xos_host, port = xos_port, user = user, password = password) |
| 54 | |
| 55 | return None |
| 56 | |
| 57 | @classmethod |
| 58 | def getRestApi(cls): |
| 59 | try: |
| 60 | from restApi import restApi |
| 61 | restApiXos = restApi() |
| 62 | xos_credentials = cls.getCredentials() |
| 63 | if xos_credentials is None: |
| 64 | restApiXos.controllerIP = cls.HEAD_NODE |
| 65 | restApiXos.controllerPort = cls.CONTROLLER_PORT |
| 66 | else: |
| 67 | restApiXos.controllerIP = xos_credentials['host'] |
| 68 | restApiXos.controllerPort = xos_credentials['port'] |
| 69 | restApiXos.user = xos_credentials['user'] |
| 70 | restApiXos.password = xos_credentials['password'] |
| 71 | |
| 72 | return restApiXos |
| 73 | except: |
| 74 | return None |
| 75 | |
| 76 | def __init__(self): |
| 77 | self.restApi = self.getRestApi() |
A R Karthick | dfdcb90 | 2017-11-06 18:23:46 -0800 | [diff] [blame] | 78 | |
| 79 | ''' |
| 80 | @method search_dictionary |
| 81 | @Description: Searches for a key in the provided nested dictionary |
| 82 | @params: input_dict = dictionary to be searched |
| 83 | search_key = name of the key to be searched for |
| 84 | returns two values: search_key value and status of the search. |
| 85 | True if found (False when not found) |
| 86 | |
| 87 | ''' |
| 88 | def search_dictionary(self, input_dict, search_key): |
| 89 | input_keys = input_dict.keys() |
| 90 | key_value = '' |
| 91 | found = False |
| 92 | for key in input_keys: |
| 93 | if key == search_key: |
| 94 | key_value = input_dict[key] |
| 95 | found = True |
| 96 | break |
| 97 | elif type(input_dict[key]) == dict: |
| 98 | key_value, found = self.search_dictionary(input_dict[key],search_key) |
| 99 | if found == True: |
| 100 | break |
| 101 | elif type(input_dict[key]) == list: |
| 102 | if not input_dict[key]: |
| 103 | found = False |
| 104 | break |
| 105 | for item in input_dict[key]: |
| 106 | if isinstance(item, dict): |
| 107 | key_value, found = self.search_dictionary(item, search_key) |
| 108 | if found == True: |
| 109 | break |
| 110 | return key_value,found |
| 111 | |
| 112 | ''' |
| 113 | @method getFieldValueFromDict |
| 114 | @params : search_dict - Dictionary to be searched |
| 115 | field - Key to be searched for (ex: account_num) |
| 116 | @Returns: Returns the value of the Key that was provided |
| 117 | ''' |
| 118 | def getFieldValueFromDict(self,search_dict, field): |
| 119 | results = '' |
| 120 | found = False |
| 121 | input_keys = search_dict.keys() |
| 122 | for key in input_keys: |
| 123 | print "key...", key |
| 124 | if key == field: |
| 125 | results = search_dict[key] |
| 126 | if not results: |
| 127 | found = True |
| 128 | break |
| 129 | elif type(search_dict[key]) == dict: |
| 130 | results, found = self.search_dictionary(search_dict[key],field) |
| 131 | if found == True: |
| 132 | break |
| 133 | elif type(search_dict[key]) == list: |
| 134 | if not search_dict[key]: |
| 135 | found = False |
| 136 | continue |
| 137 | for item in search_dict[key]: |
| 138 | if isinstance(item, dict): |
| 139 | results, found = self.search_dictionary(item, field) |
| 140 | if found == True: |
| 141 | break |
| 142 | if results: |
| 143 | break |
| 144 | |
| 145 | return results |
A R Karthick | 028edaf | 2017-11-06 16:34:57 -0800 | [diff] [blame] | 146 | |
| 147 | def getSubscriberId(self, subscriberList, account_num): |
| 148 | subscriberId = 0 |
| 149 | subscriberInfo = None |
| 150 | for subscriber in subscriberList: |
| 151 | if str(subscriber['service_specific_id']) == str(account_num): |
A R Karthick | dfdcb90 | 2017-11-06 18:23:46 -0800 | [diff] [blame] | 152 | subscriberId = self.getFieldValueFromDict(subscriber, 'id') |
A R Karthick | 028edaf | 2017-11-06 16:34:57 -0800 | [diff] [blame] | 153 | subscriberInfo = subscriber |
| 154 | break |
| 155 | return subscriberInfo, subscriberId |
| 156 | |
A R Karthick | 30c2d68 | 2017-11-07 10:39:23 -0800 | [diff] [blame] | 157 | def getVoltId(self, result, subInfo, s_tag = None, c_tag = None): |
A R Karthick | dfdcb90 | 2017-11-06 18:23:46 -0800 | [diff] [blame] | 158 | subscribed_link_ids_list = self.getFieldValueFromDict(subInfo, |
A R Karthick | 699f5c5 | 2017-11-06 19:02:47 -0800 | [diff] [blame] | 159 | 'subscribed_links_ids') |
A R Karthick | 30c2d68 | 2017-11-07 10:39:23 -0800 | [diff] [blame] | 160 | if len(subscribed_link_ids_list) > 0: |
| 161 | subscribed_link_ids = subscribed_link_ids_list[0] |
| 162 | service_link = self.restApi.ApiChameleonGet('CH_CORE_SERVICELINK', |
| 163 | subscribed_link_ids) |
| 164 | assert_not_equal(service_link, None) |
| 165 | provider_service_instance_id = service_link.get('provider_service_instance_id', |
| 166 | None) |
| 167 | assert_not_equal(provider_service_instance_id, None) |
| 168 | return provider_service_instance_id |
| 169 | |
| 170 | #find the tenant for the s_tag/c_tag |
| 171 | if s_tag is None or c_tag is None: |
| 172 | return None |
| 173 | |
| 174 | if result is None: |
| 175 | result = self.restApi.ApiGet('VOLT_TENANT') |
| 176 | result = result['items'] |
| 177 | |
| 178 | tenant = filter(lambda t: int(t['s_tag']) == int(s_tag) and \ |
| 179 | int(t['c_tag']) == int(c_tag), result) |
| 180 | if not tenant: |
| 181 | return None |
| 182 | |
| 183 | return tenant[0]['id'] |
A R Karthick | 028edaf | 2017-11-06 16:34:57 -0800 | [diff] [blame] | 184 | |
| 185 | def getProviderInstance(self, info): |
A R Karthick | 30c2d68 | 2017-11-07 10:39:23 -0800 | [diff] [blame] | 186 | return info['id'] |
A R Karthick | dfdcb90 | 2017-11-06 18:23:46 -0800 | [diff] [blame] | 187 | provided_link_ids_list = self.getFieldValueFromDict(info, |
A R Karthick | 699f5c5 | 2017-11-06 19:02:47 -0800 | [diff] [blame] | 188 | 'provided_links_ids') |
A R Karthick | 028edaf | 2017-11-06 16:34:57 -0800 | [diff] [blame] | 189 | assert_not_equal(provided_link_ids_list, None) |
| 190 | assert_not_equal(len(provided_link_ids_list), 0) |
| 191 | provided_link_ids = provided_link_ids_list[0] |
| 192 | service_link = self.restApi.ApiChameleonGet('CH_CORE_SERVICELINK', |
| 193 | provided_link_ids) |
| 194 | if service_link is None: |
| 195 | return None |
| 196 | provider_service_instance_id = service_link.get('provider_service_instance_id', |
| 197 | None) |
| 198 | assert_not_equal(provider_service_instance_id, None) |
| 199 | return provider_service_instance_id |
| 200 | |
| 201 | def linkTenant(self, subId, tenant_info): |
A R Karthick | 699f5c5 | 2017-11-06 19:02:47 -0800 | [diff] [blame] | 202 | result = self.restApi.ApiGet('VOLT_TENANT')['items'] |
A R Karthick | 028edaf | 2017-11-06 16:34:57 -0800 | [diff] [blame] | 203 | tenant = None |
| 204 | for volt in result: |
| 205 | if str(volt['c_tag']) == str(tenant_info['c_tag']): |
| 206 | tenant = volt |
| 207 | break |
| 208 | assert_not_equal(tenant, None) |
A R Karthick | dfdcb90 | 2017-11-06 18:23:46 -0800 | [diff] [blame] | 209 | volt_id = self.getFieldValueFromDict(tenant, 'id') |
| 210 | provided_links_ids_list = self.getFieldValueFromDict(tenant, |
A R Karthick | 699f5c5 | 2017-11-06 19:02:47 -0800 | [diff] [blame] | 211 | 'provided_links_ids') |
A R Karthick | 028edaf | 2017-11-06 16:34:57 -0800 | [diff] [blame] | 212 | assert_not_equal( len(provided_link_ids_list), 0) |
| 213 | provided_link_ids = provided_link_ids_list[0] |
A R Karthick | dfdcb90 | 2017-11-06 18:23:46 -0800 | [diff] [blame] | 214 | subscribed_link_ids_list = self.getFieldValueFromDict(tenant, |
A R Karthick | 699f5c5 | 2017-11-06 19:02:47 -0800 | [diff] [blame] | 215 | 'subscribed_links_ids') |
A R Karthick | 028edaf | 2017-11-06 16:34:57 -0800 | [diff] [blame] | 216 | assert_not_equal(len(subscribed_link_ids_list), 0) |
| 217 | subscribed_link_ids = subscribed_link_ids_list[0] |
| 218 | service_link = self.restApi.ApiChameleonGet('CH_CORE_SERVICELINK', |
| 219 | provided_link_ids) |
| 220 | assert_not_equal(service_link, None) |
| 221 | provider_service_instance_id = service_link.get('provider_service_instance_id', |
| 222 | None) |
| 223 | assert_not_equal(provider_service_instance_id, None) |
| 224 | service_dict = dict(subscriber_service_instance_id = subId) |
| 225 | result = self.restApi.ApiChameleonPut('CH_CORE_SERVICELINK', |
| 226 | service_dict, |
| 227 | provided_link_ids) |
| 228 | assert_equal(result, True) |
| 229 | return provider_service_instance_id |
| 230 | # service_link_dict = self.restApi.ApiChameleonGet('CH_CORE_SERVICELINK', |
| 231 | # subscribed_link_ids) |
| 232 | # assert_not_equal(service_link_dict, None) |
| 233 | # vsg_tenant = service_link_dict.get('provider_service_instance_id', None) |
| 234 | # assert_not_equal(vsg_tenant, None) |
| 235 | # vsg_result = self.restApi.ApiChameleonGet('VSG_TENANT', |
| 236 | # vsg_tenant) |
| 237 | # assert_not_equal(vsg_result, None) |
| 238 | # vsg_instance = vsg_result.get('instance_id', None) |
| 239 | # assert_not_equal(vsg_instance, None) |
| 240 | # instance_result = self.restApi.ApiChameleonGet('CH_CORE_INSTANCES', |
| 241 | # vsg_instance) |
| 242 | # assert_equal(instance_result, True) |
A R Karthick | ed3a2ca | 2017-07-06 15:50:03 -0700 | [diff] [blame] | 243 | |
| 244 | def subscriberCreate(self, subscriber_info, volt_subscriber_info): |
| 245 | subId = '' |
| 246 | try: |
A R Karthick | 028edaf | 2017-11-06 16:34:57 -0800 | [diff] [blame] | 247 | result = self.restApi.ApiPost('VOLT_SUBSCRIBER', subscriber_info) |
A R Karthick | ed3a2ca | 2017-07-06 15:50:03 -0700 | [diff] [blame] | 248 | assert_equal(result, True) |
A R Karthick | 028edaf | 2017-11-06 16:34:57 -0800 | [diff] [blame] | 249 | result = self.restApi.ApiGet('VOLT_SUBSCRIBER') |
A R Karthick | ed3a2ca | 2017-07-06 15:50:03 -0700 | [diff] [blame] | 250 | assert_not_equal(result, None) |
A R Karthick | 699f5c5 | 2017-11-06 19:02:47 -0800 | [diff] [blame] | 251 | result = result['items'] |
A R Karthick | 028edaf | 2017-11-06 16:34:57 -0800 | [diff] [blame] | 252 | _, subId = self.getSubscriberId(result, |
| 253 | volt_subscriber_info['service_specific_id']) |
A R Karthick | ed3a2ca | 2017-07-06 15:50:03 -0700 | [diff] [blame] | 254 | assert_not_equal(subId, '0') |
A R Karthick | 028edaf | 2017-11-06 16:34:57 -0800 | [diff] [blame] | 255 | log.info('Subscriber ID for account num %s = %s' %(str(volt_subscriber_info['service_specific_id']), subId)) |
A R Karthick | ed3a2ca | 2017-07-06 15:50:03 -0700 | [diff] [blame] | 256 | volt_tenant = volt_subscriber_info['voltTenant'] |
A R Karthick | 028edaf | 2017-11-06 16:34:57 -0800 | [diff] [blame] | 257 | result = self.restApi.ApiPost('VOLT_TENANT', volt_tenant) |
A R Karthick | ed3a2ca | 2017-07-06 15:50:03 -0700 | [diff] [blame] | 258 | assert_equal(result, True) |
A R Karthick | 028edaf | 2017-11-06 16:34:57 -0800 | [diff] [blame] | 259 | volt_id = self.linkTenant(subId, volt_tenant) |
| 260 | log.info('Subscriber create with ctag %s, stag %s, volt id %s' %(str(volt_tenant['c_tag']), |
| 261 | str(volt_tenant['s_tag']), |
| 262 | str(volt_id))) |
A R Karthick | ed3a2ca | 2017-07-06 15:50:03 -0700 | [diff] [blame] | 263 | finally: |
| 264 | return subId |
| 265 | |
A R Karthick | 30c2d68 | 2017-11-07 10:39:23 -0800 | [diff] [blame] | 266 | def subscriberDelete(self, account_num, s_tag = None, c_tag = None, subId = '', voltId = ''): |
A R Karthick | 028edaf | 2017-11-06 16:34:57 -0800 | [diff] [blame] | 267 | result = self.restApi.ApiGet('VOLT_SUBSCRIBER') |
| 268 | assert_not_equal(result, None) |
A R Karthick | 699f5c5 | 2017-11-06 19:02:47 -0800 | [diff] [blame] | 269 | result = result['items'] |
A R Karthick | ed3a2ca | 2017-07-06 15:50:03 -0700 | [diff] [blame] | 270 | if not subId: |
| 271 | #get the subscriber id first |
A R Karthick | 028edaf | 2017-11-06 16:34:57 -0800 | [diff] [blame] | 272 | subInfo, subId = self.getSubscriberId(result, account_num) |
A R Karthick | ed3a2ca | 2017-07-06 15:50:03 -0700 | [diff] [blame] | 273 | assert_not_equal(subId, '0') |
A R Karthick | 028edaf | 2017-11-06 16:34:57 -0800 | [diff] [blame] | 274 | else: |
| 275 | subInfo, currentSubId = self.getSubscriberId(result, account_num) |
| 276 | assert_not_equal(currentSubId, '0') |
| 277 | #assert_equal(subId, currentSubId) |
A R Karthick | dfdcb90 | 2017-11-06 18:23:46 -0800 | [diff] [blame] | 278 | subId = self.getFieldValueFromDict(subInfo, 'id') |
A R Karthick | ed3a2ca | 2017-07-06 15:50:03 -0700 | [diff] [blame] | 279 | if not voltId: |
| 280 | #get the volt id for the subscriber |
A R Karthick | 028edaf | 2017-11-06 16:34:57 -0800 | [diff] [blame] | 281 | result = self.restApi.ApiGet('VOLT_TENANT') |
A R Karthick | ed3a2ca | 2017-07-06 15:50:03 -0700 | [diff] [blame] | 282 | assert_not_equal(result, None) |
A R Karthick | 699f5c5 | 2017-11-06 19:02:47 -0800 | [diff] [blame] | 283 | result = result['items'] |
A R Karthick | 30c2d68 | 2017-11-07 10:39:23 -0800 | [diff] [blame] | 284 | voltId = self.getVoltId(result, subInfo, s_tag = s_tag, c_tag = c_tag) |
A R Karthick | ed3a2ca | 2017-07-06 15:50:03 -0700 | [diff] [blame] | 285 | assert_not_equal(voltId, None) |
A R Karthick | ed3a2ca | 2017-07-06 15:50:03 -0700 | [diff] [blame] | 286 | log.info('Deleting VOLT Tenant ID %s for subscriber %s' %(voltId, subId)) |
A R Karthick | 028edaf | 2017-11-06 16:34:57 -0800 | [diff] [blame] | 287 | status = self.restApi.ApiChameleonDelete('VOLT_TENANT', voltId) |
| 288 | assert_equal(status, True) |
| 289 | log.info('Deleting subscriber ID %s for account num %s' %(subId, str(account_num))) |
| 290 | status = self.restApi.ApiChameleonDelete('VOLT_SUBSCRIBER', subId) |
| 291 | assert_equal(status, True) |
A R Karthick | ed3a2ca | 2017-07-06 15:50:03 -0700 | [diff] [blame] | 292 | |
| 293 | def subscriberId(self, account_num): |
A R Karthick | 028edaf | 2017-11-06 16:34:57 -0800 | [diff] [blame] | 294 | result = self.restApi.ApiGet('VOLT_SUBSCRIBER') |
A R Karthick | ed3a2ca | 2017-07-06 15:50:03 -0700 | [diff] [blame] | 295 | assert_not_equal(result, None) |
A R Karthick | 699f5c5 | 2017-11-06 19:02:47 -0800 | [diff] [blame] | 296 | result = result['items'] |
A R Karthick | 028edaf | 2017-11-06 16:34:57 -0800 | [diff] [blame] | 297 | _, subId = self.getSubscriberId(result, account_num) |
A R Karthick | ed3a2ca | 2017-07-06 15:50:03 -0700 | [diff] [blame] | 298 | return subId |
| 299 | |
| 300 | class CordSubscriberUtils(object): |
| 301 | |
| 302 | SUBSCRIBER_ACCOUNT_NUM = 100 |
| 303 | SUBSCRIBER_S_TAG = 500 |
| 304 | SUBSCRIBER_C_TAG = 500 |
| 305 | SUBSCRIBERS_PER_S_TAG = 8 |
| 306 | |
| 307 | def __init__(self, |
| 308 | num_subscribers, |
| 309 | account_num = SUBSCRIBER_ACCOUNT_NUM, |
| 310 | s_tag = SUBSCRIBER_S_TAG, |
| 311 | c_tag = SUBSCRIBER_C_TAG, |
| 312 | subscribers_per_s_tag = SUBSCRIBERS_PER_S_TAG): |
| 313 | self.num_subscribers = num_subscribers |
| 314 | self.account_num = account_num |
| 315 | self.s_tag = s_tag |
| 316 | self.c_tag = c_tag |
| 317 | self.subscribers_per_s_tag = subscribers_per_s_tag |
| 318 | self.subscriber_map = {} |
A R Karthick | 30c2d68 | 2017-11-07 10:39:23 -0800 | [diff] [blame] | 319 | self.tenant_map = {} |
A R Karthick | ed3a2ca | 2017-07-06 15:50:03 -0700 | [diff] [blame] | 320 | self.subscriber_info = self.getConfig() |
| 321 | self.volt_subscriber_info = self.getVoltConfig() |
| 322 | self.xos = XosUtils() |
| 323 | |
| 324 | def getCredentials(self, subId): |
| 325 | """Generate our own account num, s_tag and c_tags""" |
| 326 | if subId in self.subscriber_map: |
| 327 | return self.subscriber_map[subId] |
| 328 | account_num = self.account_num |
| 329 | self.account_num += 1 |
| 330 | s_tag, c_tag = self.s_tag, self.c_tag |
| 331 | self.c_tag += 1 |
| 332 | if self.c_tag % self.subscribers_per_s_tag == 0: |
| 333 | self.s_tag += 1 |
| 334 | self.subscriber_map[subId] = account_num, s_tag, c_tag |
A R Karthick | 30c2d68 | 2017-11-07 10:39:23 -0800 | [diff] [blame] | 335 | self.tenant_map[account_num] = (s_tag, c_tag) |
A R Karthick | ed3a2ca | 2017-07-06 15:50:03 -0700 | [diff] [blame] | 336 | return self.subscriber_map[subId] |
| 337 | |
| 338 | def getConfig(self): |
| 339 | features = { |
A R Karthick | 3eef13c | 2017-11-06 18:47:25 -0800 | [diff] [blame] | 340 | 'cdn_enable': True, |
A R Karthick | ed3a2ca | 2017-07-06 15:50:03 -0700 | [diff] [blame] | 341 | 'uplink_speed': 1000000000, |
| 342 | 'downlink_speed': 1000000000, |
A R Karthick | 028edaf | 2017-11-06 16:34:57 -0800 | [diff] [blame] | 343 | 'enable_uverse': True, |
A R Karthick | ed3a2ca | 2017-07-06 15:50:03 -0700 | [diff] [blame] | 344 | 'status': 'enabled' |
| 345 | } |
| 346 | subscriber_map = [] |
| 347 | for i in xrange(self.num_subscribers): |
| 348 | subId = 'sub{}'.format(i) |
| 349 | account_num, _, _ = self.getCredentials(subId) |
A R Karthick | 028edaf | 2017-11-06 16:34:57 -0800 | [diff] [blame] | 350 | identity = { 'service_specific_id' : str(account_num), |
A R Karthick | ed3a2ca | 2017-07-06 15:50:03 -0700 | [diff] [blame] | 351 | 'name' : 'My House {}'.format(i) |
| 352 | } |
A R Karthick | 028edaf | 2017-11-06 16:34:57 -0800 | [diff] [blame] | 353 | sub_data = [ (k, v) for d in (features, identity) \ |
| 354 | for k, v in d.iteritems() ] |
| 355 | sub_info = dict(sub_data) |
A R Karthick | ed3a2ca | 2017-07-06 15:50:03 -0700 | [diff] [blame] | 356 | subscriber_map.append(sub_info) |
| 357 | |
| 358 | return subscriber_map |
| 359 | |
A R Karthick | 30c2d68 | 2017-11-07 10:39:23 -0800 | [diff] [blame] | 360 | def getVoltInfo(self, account_num): |
| 361 | num = int(account_num) |
| 362 | if num in self.tenant_map: |
| 363 | return self.tenant_map[num] |
| 364 | return None, None |
| 365 | |
A R Karthick | ed3a2ca | 2017-07-06 15:50:03 -0700 | [diff] [blame] | 366 | def getVoltConfig(self): |
| 367 | voltSubscriberMap = [] |
| 368 | for i in xrange(self.num_subscribers): |
| 369 | subId = 'sub{}'.format(i) |
| 370 | account_num, s_tag, c_tag = self.getCredentials(subId) |
| 371 | voltSubscriberInfo = {} |
| 372 | voltSubscriberInfo['voltTenant'] = dict(s_tag = str(s_tag), |
A R Karthick | 028edaf | 2017-11-06 16:34:57 -0800 | [diff] [blame] | 373 | c_tag = str(c_tag)) |
| 374 | voltSubscriberInfo['service_specific_id'] = account_num |
A R Karthick | ed3a2ca | 2017-07-06 15:50:03 -0700 | [diff] [blame] | 375 | voltSubscriberMap.append(voltSubscriberInfo) |
| 376 | |
| 377 | return voltSubscriberMap |
| 378 | |
A R Karthick | 028edaf | 2017-11-06 16:34:57 -0800 | [diff] [blame] | 379 | def getVoltId(self, subInfo): |
A R Karthick | 30c2d68 | 2017-11-07 10:39:23 -0800 | [diff] [blame] | 380 | s_tag, c_tag = self.getVoltInfo(subInfo['service_specific_id']) |
| 381 | return self.xos.getVoltId(None, subInfo, s_tag = s_tag, c_tag = c_tag) |
A R Karthick | 028edaf | 2017-11-06 16:34:57 -0800 | [diff] [blame] | 382 | |
| 383 | def getProviderInstance(self, tenant_info): |
| 384 | return self.xos.getProviderInstance(tenant_info) |
A R Karthick | ed3a2ca | 2017-07-06 15:50:03 -0700 | [diff] [blame] | 385 | |
| 386 | def subscriberCreate(self, index, subscriber_info = None, volt_subscriber_info = None): |
| 387 | if subscriber_info is None: |
| 388 | subscriber_info = self.subscriber_info[index] |
| 389 | if volt_subscriber_info is None: |
| 390 | volt_subscriber_info = self.volt_subscriber_info[index] |
| 391 | s_tag = int(volt_subscriber_info['voltTenant']['s_tag']) |
| 392 | c_tag = int(volt_subscriber_info['voltTenant']['c_tag']) |
| 393 | log.info('Creating tenant with s_tag: %d, c_tag: %d' %(s_tag, c_tag)) |
| 394 | subId = self.xos.subscriberCreate(subscriber_info, volt_subscriber_info) |
| 395 | return subId |
| 396 | |
| 397 | def subscriberDelete(self, index, subId = '', voltId = '', subscriber_info = None, volt_subscriber_info = None): |
| 398 | if subscriber_info is None: |
| 399 | subscriber_info = self.subscriber_info[index] |
| 400 | if volt_subscriber_info is None: |
| 401 | volt_subscriber_info = self.volt_subscriber_info[index] |
| 402 | s_tag = int(volt_subscriber_info['voltTenant']['s_tag']) |
| 403 | c_tag = int(volt_subscriber_info['voltTenant']['c_tag']) |
| 404 | log.info('Deleting tenant with s_tag: %d, c_tag: %d' %(s_tag, c_tag)) |
A R Karthick | 30c2d68 | 2017-11-07 10:39:23 -0800 | [diff] [blame] | 405 | self.xos.subscriberDelete(volt_subscriber_info['service_specific_id'], s_tag = s_tag, c_tag = c_tag, subId = subId, voltId = voltId) |
A R Karthick | ed3a2ca | 2017-07-06 15:50:03 -0700 | [diff] [blame] | 406 | |
| 407 | def subscriberId(self, index): |
| 408 | volt_subscriber_info = self.volt_subscriber_info[index] |
A R Karthick | 028edaf | 2017-11-06 16:34:57 -0800 | [diff] [blame] | 409 | return self.xos.subscriberId(volt_subscriber_info['service_specific_id']) |