adam | 6142bef | 2018-10-01 10:34:19 +0200 | [diff] [blame] | 1 | import ast |
| 2 | |
| 3 | import requests |
| 4 | from assertpy import assert_that |
| 5 | from robot.api import logger |
| 6 | from robot.api.deco import keyword |
| 7 | |
| 8 | JSESSIONID_COOKIE = "JSESSIONID" |
| 9 | |
| 10 | _vid_to_so_request_details = { |
| 11 | "requestDetails": { |
| 12 | "cloudConfiguration": { |
| 13 | "lcpCloudRegionId": "RegionOne", |
| 14 | "tenantId": "982c540f6e69488eb6be5664255e00c0" |
| 15 | }, |
| 16 | "modelInfo": { |
| 17 | "modelInvariantId": "41b3c314-dfab-4501-9c5e-1c9fe5d8e151", |
| 18 | "modelName": "SoWs1..base_ws..module-0", |
| 19 | "modelType": "vfModule", |
| 20 | "modelVersion": "1", |
| 21 | "modelVersionId": "7ea96ae9-9eac-4eaa-882e-077478a6c44a" |
| 22 | }, |
| 23 | "relatedInstanceList": [{ |
| 24 | "relatedInstance": { |
| 25 | "instanceId": "0d8a98d8-d7ca-4c26-b7ab-81d3729e3b6c", |
| 26 | "modelInfo": { |
| 27 | "modelInvariantId": "a4413616-cf96-4615-a94e-0dc5a6a65430", |
| 28 | "modelName": "SC_WS_SW_2", |
| 29 | "modelType": "service", |
| 30 | "modelVersion": "3.0", |
| 31 | "modelVersionId": "0fdaaf44-3c6c-4d81-9c57-b2ce7224dbb9" |
| 32 | } |
| 33 | } |
| 34 | }, |
| 35 | { |
| 36 | "relatedInstance": { |
| 37 | "instanceId": "61c19619-2714-46f8-90c9-39734e4f545f", |
| 38 | "modelInfo": { |
| 39 | "modelCustomizationName": "SO_WS_1 0", |
| 40 | "modelInvariantId": "3b2c9dcb-6ef8-4c3c-8d5b-43d5776f7110", |
| 41 | "modelName": "SO_WS_1", |
| 42 | "modelType": "vnf", |
| 43 | "modelVersion": "1.0", |
| 44 | "modelVersionId": "0fdaaf44-3c6c-4d81-9c57-b2ce7224dbb9" |
| 45 | } |
| 46 | } |
| 47 | } |
| 48 | ], |
| 49 | "requestInfo": { |
| 50 | "source": "VID", |
| 51 | "suppressRollback": False, |
| 52 | "requestorId": "az2016", |
| 53 | "instanceName": "SC_WS_VNF_1_2" |
| 54 | }, |
| 55 | "requestParameters": { |
| 56 | "controllerType": "SDNC", |
| 57 | "userParams": [] |
| 58 | } |
| 59 | |
| 60 | } |
| 61 | } |
| 62 | |
| 63 | _expected_so_response = { |
| 64 | "status": 202, |
| 65 | "entity": { |
| 66 | "requestReferences": { |
| 67 | "instanceId": "fffcbb6c-1983-42df-9ca8-89ae8b3a46c1", |
| 68 | "requestId": "b2197d7e-3a7d-410e-82ba-7b7e8191bc46" |
| 69 | } |
| 70 | } |
| 71 | } |
| 72 | |
| 73 | |
| 74 | def _extract_cookie_from_headers(headers): |
| 75 | for i in headers["Set-Cookie"].split(";"): |
| 76 | if JSESSIONID_COOKIE in i: |
| 77 | return i |
| 78 | raise RuntimeError("No cookie when logging in to VID") |
| 79 | |
| 80 | |
| 81 | def _log_request(response): |
| 82 | logger.console( |
| 83 | "\n=========\n" |
| 84 | "Performing request to : {} \nBODY: {}\nHEADERS: {}" |
| 85 | .format(str(response.request.url), str(response.request.body), str(response.request.headers))) |
| 86 | logger.console( |
| 87 | "---------\n" |
| 88 | "Got response\n BODY: {} \n HEADERS: {}" |
| 89 | "\n=========\n".format(str(response.headers), str(response.content))) |
| 90 | |
| 91 | |
| 92 | @keyword('Login To VID') |
| 93 | def login_to_vid(): |
| 94 | headers = {'User-Agent': 'Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:61.0) Gecko/20100101 Firefox/61.0', |
| 95 | 'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8', |
| 96 | 'Accept-Language': 'pl,en-US;q=0.7,en;q=0.3', |
| 97 | 'Accept-Encoding': 'gzip, deflate', 'Referer': 'http://localhost:8080/vid/login.htm', |
| 98 | 'Content-Type': 'application/x-www-form-urlencoded', |
| 99 | 'Content-Length': '36', |
| 100 | 'Cookie': 'JSESSIONID=1B4AF817AA4BCB87C07BB5B49EFE8526', |
| 101 | 'Connection': 'keep-alive', |
| 102 | 'Upgrade-Insecure-Requests': '1'} |
| 103 | response = requests.post("https://localhost:8443/vid/login_external", data="loginId=demo&password=Kp8bJ4SXszM0WX", |
| 104 | headers=headers, allow_redirects=False, verify=False) |
| 105 | logger.console("Performing login") |
| 106 | _log_request(response) |
| 107 | return _extract_cookie_from_headers(response.headers) |
| 108 | |
| 109 | |
| 110 | @keyword('Send create VF module instance request to VID') |
| 111 | def send_create_vfmodule_instance_request_to_vid(jsession_cookie): |
| 112 | response = requests.post( |
| 113 | "https://localhost:8443/vid/mso/mso_create_vfmodule_instance/0d8a98d8-d7ca-4c26-b7ab-81d3729e3b6c/vnfs/61c19619-2714-46f8-90c9-39734e4f545f ", |
| 114 | headers={"Cookie": jsession_cookie}, json=_vid_to_so_request_details, verify=False) |
| 115 | content = ast.literal_eval(response.content) |
| 116 | logger.console("Triggering VF module instance creation") |
| 117 | _log_request(response) |
| 118 | return content |
| 119 | |
| 120 | |
| 121 | @keyword('Response should contain valid entity') |
| 122 | def expect_response_from_so_was_correctly_propageted(content): |
| 123 | logger.console("\nActual entity" + str(content['entity'])) |
| 124 | logger.console("Expected entity" + str(_expected_so_response)) |
| 125 | assert_that(content['entity']).is_equal_to(_expected_so_response) |