Matteo Scandolo | 48d3d2d | 2017-08-08 13:05:27 -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. |
| 14 | |
Zack Williams | c6722d5 | 2020-01-13 16:34:33 -0700 | [diff] [blame] | 15 | from __future__ import absolute_import, print_function |
Matteo Scandolo | 48d3d2d | 2017-08-08 13:05:27 -0700 | [diff] [blame] | 16 | |
Suchitra.Vemuri | fdb220a | 2016-10-19 14:09:53 -0700 | [diff] [blame] | 17 | import json |
Kailash Khalasi | b6e87fc | 2017-04-18 15:08:19 -0700 | [diff] [blame] | 18 | import uuid |
Kailash Khalasi | 2adbad8 | 2017-05-15 14:53:40 -0700 | [diff] [blame] | 19 | import random |
Kailash Khalasi | 86e231e | 2017-06-06 13:13:43 -0700 | [diff] [blame] | 20 | import yaml |
You Wang | aabb283 | 2017-11-16 17:24:09 -0800 | [diff] [blame] | 21 | import glob |
Kailash Khalasi | 8416bfe | 2017-12-20 13:06:37 -0800 | [diff] [blame] | 22 | import string |
Suchitra.Vemuri | fdb220a | 2016-10-19 14:09:53 -0700 | [diff] [blame] | 23 | |
Suchitra.Vemuri | fdb220a | 2016-10-19 14:09:53 -0700 | [diff] [blame] | 24 | |
Zack Williams | 821c502 | 2020-01-15 15:11:46 -0700 | [diff] [blame] | 25 | class CORDDictUtils(object): |
Suchitra.Vemuri | fdb220a | 2016-10-19 14:09:53 -0700 | [diff] [blame] | 26 | @staticmethod |
| 27 | def listToDict(alist, intListIndex): |
| 28 | dictInfo = alist[int(intListIndex)] |
| 29 | return dictInfo |
| 30 | |
| 31 | @staticmethod |
| 32 | def jsonToList(strFile, strListName): |
| 33 | data = json.loads(open(strFile).read()) |
Zack Williams | c6722d5 | 2020-01-13 16:34:33 -0700 | [diff] [blame] | 34 | # print "data...",data |
Suchitra.Vemuri | fdb220a | 2016-10-19 14:09:53 -0700 | [diff] [blame] | 35 | dataList = data[strListName] |
| 36 | return dataList |
| 37 | |
You Wang | aabb283 | 2017-11-16 17:24:09 -0800 | [diff] [blame] | 38 | def readFile(self, path, single=True): |
| 39 | dataDict = {} |
| 40 | for fileName in glob.glob(path): |
Zack Williams | c6722d5 | 2020-01-13 16:34:33 -0700 | [diff] [blame] | 41 | print("Reading ", fileName) |
You Wang | aabb283 | 2017-11-16 17:24:09 -0800 | [diff] [blame] | 42 | data = open(fileName).read() |
| 43 | dataDict[fileName] = data |
| 44 | if bool(single): |
| 45 | return data |
You Wang | f35df4a | 2018-01-24 11:00:58 -0800 | [diff] [blame] | 46 | if not dataDict: |
Zack Williams | c6722d5 | 2020-01-13 16:34:33 -0700 | [diff] [blame] | 47 | print("Failed to find the file!") |
You Wang | f35df4a | 2018-01-24 11:00:58 -0800 | [diff] [blame] | 48 | return None |
You Wang | aabb283 | 2017-11-16 17:24:09 -0800 | [diff] [blame] | 49 | return dataDict |
| 50 | |
| 51 | def readFiles(self, path): |
| 52 | return self.readFile(path, single=False) |
| 53 | |
Zack Williams | c6722d5 | 2020-01-13 16:34:33 -0700 | [diff] [blame] | 54 | """ |
Suchitra.Vemuri | 8522006 | 2016-10-25 10:44:11 -0700 | [diff] [blame] | 55 | @method compare_dict |
| 56 | @Description: validates if contents of dict1 exists in dict2 |
| 57 | @params: dict1 = input_data entered through api |
| 58 | dict2 = retrieved data from GET method |
| 59 | returns True if contents of dict1 exists in dict2 |
Zack Williams | c6722d5 | 2020-01-13 16:34:33 -0700 | [diff] [blame] | 60 | """ |
| 61 | |
You Wang | 507c456 | 2016-11-23 13:36:09 -0800 | [diff] [blame] | 62 | def compare_dict(self, dict1, dict2): |
Zack Williams | c6722d5 | 2020-01-13 16:34:33 -0700 | [diff] [blame] | 63 | print("input data", dict1) |
| 64 | print("get data", dict2) |
| 65 | if dict1 is None or dict2 is None: |
| 66 | return False |
| 67 | if not isinstance(dict1, dict) or not isinstance(dict2, dict): |
| 68 | return False |
You Wang | 507c456 | 2016-11-23 13:36:09 -0800 | [diff] [blame] | 69 | if dict1 == {}: |
| 70 | return True |
| 71 | return self.compare_dict_recursive(dict1, dict2) |
Suchitra.Vemuri | 8522006 | 2016-10-25 10:44:11 -0700 | [diff] [blame] | 72 | |
Zack Williams | c6722d5 | 2020-01-13 16:34:33 -0700 | [diff] [blame] | 73 | """ |
You Wang | 507c456 | 2016-11-23 13:36:09 -0800 | [diff] [blame] | 74 | @method compare_dict_recursive |
| 75 | @Description: recursive function to validate if dict1 is a subset of dict2 |
| 76 | returns True if contents of dict1 exists in dict2 |
Zack Williams | c6722d5 | 2020-01-13 16:34:33 -0700 | [diff] [blame] | 77 | """ |
| 78 | |
You Wang | 507c456 | 2016-11-23 13:36:09 -0800 | [diff] [blame] | 79 | def compare_dict_recursive(self, dict1, dict2): |
Zack Williams | c6722d5 | 2020-01-13 16:34:33 -0700 | [diff] [blame] | 80 | for key1, value1 in dict1.items(): |
You Wang | 507c456 | 2016-11-23 13:36:09 -0800 | [diff] [blame] | 81 | if key1 not in dict2.keys(): |
Zack Williams | c6722d5 | 2020-01-13 16:34:33 -0700 | [diff] [blame] | 82 | print("Missing key", key1, "in dict2") |
You Wang | 507c456 | 2016-11-23 13:36:09 -0800 | [diff] [blame] | 83 | return False |
| 84 | value2 = dict2[key1] |
Zack Williams | c6722d5 | 2020-01-13 16:34:33 -0700 | [diff] [blame] | 85 | if isinstance(value1, dict) and isinstance(value2, dict): |
You Wang | 507c456 | 2016-11-23 13:36:09 -0800 | [diff] [blame] | 86 | if not self.compare_dict_recursive(value1, value2): |
| 87 | return False |
| 88 | else: |
| 89 | if value2 != value1: |
Zack Williams | c6722d5 | 2020-01-13 16:34:33 -0700 | [diff] [blame] | 90 | print("Values of key", key1, "in two dicts are not equal") |
You Wang | 507c456 | 2016-11-23 13:36:09 -0800 | [diff] [blame] | 91 | return False |
Suchitra.Vemuri | 8522006 | 2016-10-25 10:44:11 -0700 | [diff] [blame] | 92 | return True |
| 93 | |
Zack Williams | c6722d5 | 2020-01-13 16:34:33 -0700 | [diff] [blame] | 94 | """ |
You Wang | 3964e84 | 2016-12-09 12:04:32 -0800 | [diff] [blame] | 95 | @method compare_list_of_dicts |
| 96 | @Description: validates if contents of dicts in list1 exists in dicts of list2 |
| 97 | returns True if for each dict in list1, there's a dict in list2 that contains its content |
Zack Williams | c6722d5 | 2020-01-13 16:34:33 -0700 | [diff] [blame] | 98 | """ |
| 99 | |
You Wang | 3964e84 | 2016-12-09 12:04:32 -0800 | [diff] [blame] | 100 | def compare_list_of_dicts(self, list1, list2): |
| 101 | for dict1 in list1: |
| 102 | if dict1 == {}: |
| 103 | continue |
Scott Baker | 3545ca1 | 2020-04-23 17:29:07 -0700 | [diff] [blame] | 104 | key = list(dict1.keys())[0] |
You Wang | 3964e84 | 2016-12-09 12:04:32 -0800 | [diff] [blame] | 105 | value = dict1[key] |
| 106 | dict2 = self.getDictFromListOfDict(list2, key, value) |
| 107 | if dict2 == {}: |
Zack Williams | c6722d5 | 2020-01-13 16:34:33 -0700 | [diff] [blame] | 108 | print( |
| 109 | "Comparison failed: no dictionaries found in list2 with key", |
| 110 | key, |
| 111 | "and value", |
| 112 | value, |
| 113 | ) |
You Wang | 3964e84 | 2016-12-09 12:04:32 -0800 | [diff] [blame] | 114 | return False |
Zack Williams | c6722d5 | 2020-01-13 16:34:33 -0700 | [diff] [blame] | 115 | if not self.compare_dict(dict1, dict2): |
| 116 | print( |
| 117 | "Comparison failed: dictionary", |
| 118 | dict1, |
| 119 | "is not a subset of dictionary", |
| 120 | dict2, |
| 121 | ) |
You Wang | 3964e84 | 2016-12-09 12:04:32 -0800 | [diff] [blame] | 122 | return False |
| 123 | return True |
| 124 | |
Zack Williams | c6722d5 | 2020-01-13 16:34:33 -0700 | [diff] [blame] | 125 | """ |
Suchitra.Vemuri | 32e03c2 | 2016-11-03 11:57:53 -0700 | [diff] [blame] | 126 | @method search_dictionary |
| 127 | @Description: Searches for a key in the provided nested dictionary |
| 128 | @params: input_dict = dictionary to be searched |
| 129 | search_key = name of the key to be searched for |
| 130 | returns two values: search_key value and status of the search. |
| 131 | True if found (False when not found) |
| 132 | |
Zack Williams | c6722d5 | 2020-01-13 16:34:33 -0700 | [diff] [blame] | 133 | """ |
| 134 | |
| 135 | def search_dictionary(self, input_dict, search_key): |
Suchitra.Vemuri | 32e03c2 | 2016-11-03 11:57:53 -0700 | [diff] [blame] | 136 | input_keys = input_dict.keys() |
Zack Williams | c6722d5 | 2020-01-13 16:34:33 -0700 | [diff] [blame] | 137 | key_value = "" |
Suchitra.Vemuri | 32e03c2 | 2016-11-03 11:57:53 -0700 | [diff] [blame] | 138 | found = False |
| 139 | for key in input_keys: |
| 140 | if key == search_key: |
Zack Williams | c6722d5 | 2020-01-13 16:34:33 -0700 | [diff] [blame] | 141 | key_value = input_dict[key] |
| 142 | found = True |
| 143 | break |
| 144 | elif isinstance(input_dict[key], dict): |
| 145 | key_value, found = self.search_dictionary( |
| 146 | input_dict[key], search_key) |
| 147 | if found: |
Suchitra.Vemuri | 32e03c2 | 2016-11-03 11:57:53 -0700 | [diff] [blame] | 148 | break |
Zack Williams | c6722d5 | 2020-01-13 16:34:33 -0700 | [diff] [blame] | 149 | elif isinstance(input_dict[key], list): |
| 150 | if not input_dict[key]: |
Suchitra.Vemuri | 8be1880 | 2016-11-16 16:59:54 -0800 | [diff] [blame] | 151 | found = False |
| 152 | break |
Zack Williams | c6722d5 | 2020-01-13 16:34:33 -0700 | [diff] [blame] | 153 | for item in input_dict[key]: |
| 154 | if isinstance(item, dict): |
| 155 | key_value, found = self.search_dictionary( |
| 156 | item, search_key) |
| 157 | if found: |
| 158 | break |
| 159 | return key_value, found |
| 160 | |
| 161 | """ |
Suchitra.Vemuri | 8be1880 | 2016-11-16 16:59:54 -0800 | [diff] [blame] | 162 | @method getDictFromListOfDict |
| 163 | return key_value,found |
Suchitra.Vemuri | 32e03c2 | 2016-11-03 11:57:53 -0700 | [diff] [blame] | 164 | @Description: Searches for the dictionary in the provided list of dictionaries |
| 165 | that matches the value of the key provided |
| 166 | @params : List of dictionaries(getResponse Data from the URL), |
| 167 | SearchKey - Key that needs to be searched for (ex: account_num) |
| 168 | searchKeyValue - Value of the searchKey (ex: 21) |
| 169 | @Returns: Dictionary returned when match found for searchKey with the corresponding |
| 170 | searchKeyValue provided |
Zack Williams | c6722d5 | 2020-01-13 16:34:33 -0700 | [diff] [blame] | 171 | """ |
Suchitra.Vemuri | 32e03c2 | 2016-11-03 11:57:53 -0700 | [diff] [blame] | 172 | |
Zack Williams | c6722d5 | 2020-01-13 16:34:33 -0700 | [diff] [blame] | 173 | def getDictFromListOfDict(self, getJsonDataList, |
| 174 | searchKey, searchKeyValue): |
Suchitra.Vemuri | 32e03c2 | 2016-11-03 11:57:53 -0700 | [diff] [blame] | 175 | return_dict = {} |
Zack Williams | c6722d5 | 2020-01-13 16:34:33 -0700 | [diff] [blame] | 176 | result = "" |
Suchitra.Vemuri | 32e03c2 | 2016-11-03 11:57:53 -0700 | [diff] [blame] | 177 | for data in getJsonDataList: |
Zack Williams | c6722d5 | 2020-01-13 16:34:33 -0700 | [diff] [blame] | 178 | print("data", data) |
Suchitra.Vemuri | 32e03c2 | 2016-11-03 11:57:53 -0700 | [diff] [blame] | 179 | return_dict = {} |
| 180 | found = False |
| 181 | input_keys = data.keys() |
| 182 | for key in input_keys: |
| 183 | if key == searchKey and str(data[key]) == str(searchKeyValue): |
Zack Williams | c6722d5 | 2020-01-13 16:34:33 -0700 | [diff] [blame] | 184 | found = True |
| 185 | return_dict = data |
| 186 | print("return_dict", return_dict) |
| 187 | break |
| 188 | elif isinstance(data[key], dict): |
| 189 | result, found = self.search_dictionary( |
| 190 | data[key], searchKey) |
| 191 | if found and str(result) == str(searchKeyValue): |
Suchitra.Vemuri | 32e03c2 | 2016-11-03 11:57:53 -0700 | [diff] [blame] | 192 | return_dict = data |
| 193 | break |
Zack Williams | c6722d5 | 2020-01-13 16:34:33 -0700 | [diff] [blame] | 194 | elif isinstance(data[key], list): |
| 195 | for item in data[key]: |
| 196 | if isinstance(item, dict): |
| 197 | result, found = self.search_dictionary( |
| 198 | data[key], searchKey) |
| 199 | if found and str( |
| 200 | result) == str(searchKeyValue): |
| 201 | return_dict = data |
| 202 | break |
Suchitra.Vemuri | 32e03c2 | 2016-11-03 11:57:53 -0700 | [diff] [blame] | 203 | if return_dict: |
Zack Williams | c6722d5 | 2020-01-13 16:34:33 -0700 | [diff] [blame] | 204 | break |
Suchitra.Vemuri | 32e03c2 | 2016-11-03 11:57:53 -0700 | [diff] [blame] | 205 | return return_dict |
| 206 | |
Zack Williams | c6722d5 | 2020-01-13 16:34:33 -0700 | [diff] [blame] | 207 | """ |
Suchitra.Vemuri | 32e03c2 | 2016-11-03 11:57:53 -0700 | [diff] [blame] | 208 | @method getFieldValueFromDict |
| 209 | @params : search_dict - Dictionary to be searched |
| 210 | field - Key to be searched for (ex: account_num) |
| 211 | @Returns: Returns the value of the Key that was provided |
Zack Williams | c6722d5 | 2020-01-13 16:34:33 -0700 | [diff] [blame] | 212 | """ |
| 213 | |
| 214 | def getFieldValueFromDict(self, search_dict, field): |
| 215 | results = "" |
Suchitra.Vemuri | 32e03c2 | 2016-11-03 11:57:53 -0700 | [diff] [blame] | 216 | found = False |
| 217 | input_keys = search_dict.keys() |
| 218 | for key in input_keys: |
Zack Williams | c6722d5 | 2020-01-13 16:34:33 -0700 | [diff] [blame] | 219 | print("key...", key) |
Suchitra.Vemuri | 32e03c2 | 2016-11-03 11:57:53 -0700 | [diff] [blame] | 220 | if key == field: |
Zack Williams | c6722d5 | 2020-01-13 16:34:33 -0700 | [diff] [blame] | 221 | results = search_dict[key] |
| 222 | if not results: |
| 223 | found = True |
Suchitra.Vemuri | 32e03c2 | 2016-11-03 11:57:53 -0700 | [diff] [blame] | 224 | break |
Zack Williams | c6722d5 | 2020-01-13 16:34:33 -0700 | [diff] [blame] | 225 | elif isinstance(search_dict[key], dict): |
| 226 | results, found = self.search_dictionary( |
| 227 | search_dict[key], field) |
| 228 | if found: |
| 229 | break |
| 230 | elif isinstance(search_dict[key], list): |
| 231 | if not search_dict[key]: |
Suchitra.Vemuri | 8be1880 | 2016-11-16 16:59:54 -0800 | [diff] [blame] | 232 | found = False |
You Wang | f462ee9 | 2016-12-16 13:11:43 -0800 | [diff] [blame] | 233 | continue |
Zack Williams | c6722d5 | 2020-01-13 16:34:33 -0700 | [diff] [blame] | 234 | for item in search_dict[key]: |
| 235 | if isinstance(item, dict): |
Suchitra.Vemuri | 32e03c2 | 2016-11-03 11:57:53 -0700 | [diff] [blame] | 236 | results, found = self.search_dictionary(item, field) |
Zack Williams | c6722d5 | 2020-01-13 16:34:33 -0700 | [diff] [blame] | 237 | if found: |
| 238 | break |
Suchitra.Vemuri | d203534 | 2016-11-22 17:44:40 -0800 | [diff] [blame] | 239 | if results: |
Zack Williams | c6722d5 | 2020-01-13 16:34:33 -0700 | [diff] [blame] | 240 | break |
Suchitra.Vemuri | 32e03c2 | 2016-11-03 11:57:53 -0700 | [diff] [blame] | 241 | |
| 242 | return results |
| 243 | |
Zack Williams | c6722d5 | 2020-01-13 16:34:33 -0700 | [diff] [blame] | 244 | def setFieldValueInDict(self, input_dict, field, field_value): |
| 245 | input_dict[field] = field_value |
Suchitra.Vemuri | d203534 | 2016-11-22 17:44:40 -0800 | [diff] [blame] | 246 | return input_dict |
| 247 | |
Zack Williams | c6722d5 | 2020-01-13 16:34:33 -0700 | [diff] [blame] | 248 | """ |
Suchitra.Vemuri | 0c8024a | 2016-12-07 16:31:21 -0800 | [diff] [blame] | 249 | @method getAllFieldValues |
| 250 | @params : getJsonDataDictList - List of dictionaries to be searched |
| 251 | fieldName - Key to be searched for (ex: instance_id) |
| 252 | @Returns: Returns the unique value of the Key that was provided |
Zack Williams | c6722d5 | 2020-01-13 16:34:33 -0700 | [diff] [blame] | 253 | """ |
Suchitra.Vemuri | 0c8024a | 2016-12-07 16:31:21 -0800 | [diff] [blame] | 254 | |
| 255 | def getAllFieldValues(self, getJsonDataDictList, fieldName): |
| 256 | value_list = [] |
Zack Williams | 821c502 | 2020-01-15 15:11:46 -0700 | [diff] [blame] | 257 | # uniqValue = "" - this is unused, commented out |
Suchitra.Vemuri | 0c8024a | 2016-12-07 16:31:21 -0800 | [diff] [blame] | 258 | uniq_list = [] |
| 259 | for data in getJsonDataDictList: |
Zack Williams | c6722d5 | 2020-01-13 16:34:33 -0700 | [diff] [blame] | 260 | fieldValue = "" |
Suchitra.Vemuri | 0c8024a | 2016-12-07 16:31:21 -0800 | [diff] [blame] | 261 | fieldValue = self.getFieldValueFromDict(data, fieldName) |
| 262 | value_list.append(fieldValue) |
| 263 | uniq_list = sorted(set(value_list)) |
| 264 | if len(uniq_list) == 1: |
Zack Williams | 821c502 | 2020-01-15 15:11:46 -0700 | [diff] [blame] | 265 | pass # see above, unused? |
| 266 | # uniqValue = uniq_list[0] |
Suchitra.Vemuri | 0c8024a | 2016-12-07 16:31:21 -0800 | [diff] [blame] | 267 | else: |
Zack Williams | c6722d5 | 2020-01-13 16:34:33 -0700 | [diff] [blame] | 268 | print("list of values found for ", fieldName, ";", uniq_list) |
Suchitra.Vemuri | 0c8024a | 2016-12-07 16:31:21 -0800 | [diff] [blame] | 269 | return fieldValue |
You Wang | f462ee9 | 2016-12-16 13:11:43 -0800 | [diff] [blame] | 270 | |
Kailash Khalasi | b6e87fc | 2017-04-18 15:08:19 -0700 | [diff] [blame] | 271 | def generate_uuid(self): |
| 272 | return uuid.uuid4() |
| 273 | |
Zack Williams | c6722d5 | 2020-01-13 16:34:33 -0700 | [diff] [blame] | 274 | def generate_random_number_from_blacklist( |
| 275 | self, blacklist, min=100, max=500, typeTag=False |
| 276 | ): |
Kailash Khalasi | 2adbad8 | 2017-05-15 14:53:40 -0700 | [diff] [blame] | 277 | num = None |
| 278 | while num in blacklist or num is None: |
| 279 | num = random.randrange(int(min), int(max)) |
| 280 | if typeTag: |
| 281 | return num |
| 282 | else: |
| 283 | return str(num) |
| 284 | |
Kailash Khalasi | 86e231e | 2017-06-06 13:13:43 -0700 | [diff] [blame] | 285 | def get_dynamic_resources(self, inputfile, resource): |
| 286 | resourceNames = [] |
| 287 | names = {} |
| 288 | dnames = [] |
Zack Williams | c6722d5 | 2020-01-13 16:34:33 -0700 | [diff] [blame] | 289 | with open(inputfile, "r") as f: |
Kailash Khalasi | 86e231e | 2017-06-06 13:13:43 -0700 | [diff] [blame] | 290 | contents = yaml.load(f) |
| 291 | resources = contents[resource] |
| 292 | for i in resources: |
| 293 | resourceNames.append(i["name"]) |
| 294 | for i in resourceNames: |
Zack Williams | c6722d5 | 2020-01-13 16:34:33 -0700 | [diff] [blame] | 295 | names["name"] = i |
Kailash Khalasi | 86e231e | 2017-06-06 13:13:43 -0700 | [diff] [blame] | 296 | dnames.append(names.copy()) |
| 297 | return dnames |
Kailash Khalasi | 8416bfe | 2017-12-20 13:06:37 -0800 | [diff] [blame] | 298 | |
Zack Williams | c6722d5 | 2020-01-13 16:34:33 -0700 | [diff] [blame] | 299 | def generate_random_value( |
| 300 | self, value, max_length=10, min_int=1, max_int=10000): |
| 301 | if value == "string": |
| 302 | return "".join( |
| 303 | random.choice(string.ascii_lowercase + string.digits) |
| 304 | for _ in range(max_length) |
| 305 | ) |
| 306 | if value == "bool": |
| 307 | return random.choice([True, False]) |
| 308 | if value == "int32" or value == "uint32": |
| 309 | return random.randint(min_int, max_int) |
| 310 | if value == "float": |
| 311 | return random.uniform(1, 10) |
| 312 | if value == "role": |
| 313 | return "admin" |
| 314 | if value == "direction": |
| 315 | return random.choice(["in", "out"]) |
| 316 | if value == "flavor": |
| 317 | return random.choice(["m1.large", "m1.medium", "m1.small"]) |
| 318 | if value == "vlan_tag": |
| 319 | return random.choice(["555", "1-4096", "ANY"]) |
| 320 | if value == "ip_address": |
Kailash | bc5245f | 2019-03-26 13:40:19 -0700 | [diff] [blame] | 321 | return ".".join(str(random.randint(0, 255)) for _ in range(4)) |
Kailash Khalasi | 8416bfe | 2017-12-20 13:06:37 -0800 | [diff] [blame] | 322 | else: |
Kailash Khalasi | cceec83 | 2018-08-10 15:46:50 -0700 | [diff] [blame] | 323 | return None |
Kailash Khalasi | 8416bfe | 2017-12-20 13:06:37 -0800 | [diff] [blame] | 324 | |
| 325 | def generate_random_slice_name(self): |
Zack Williams | c6722d5 | 2020-01-13 16:34:33 -0700 | [diff] [blame] | 326 | random_name = "".join( |
| 327 | random.choice( |
| 328 | string.ascii_lowercase + |
| 329 | string.digits) for _ in range(10)) |
| 330 | return "testloginbase" + random_name |