[DMAAP] fix the references to the dmaap interface files
[testsuite.git] / robot / resources / dmaap / mr_interface.robot
1 *** Settings ***
2 Documentation     The main interface for interacting with Message router. It handles low level stuff like managing the http request library and message router required fields
3 Library           RequestsLibrary
4 Library           DateTime
5 Library           Process
6 Library           ONAPLibrary.JSON
7 Library           ONAPLibrary.Utilities
8 Library           ONAPLibrary.Templating    WITH NAME    Templating
9
10 Resource          ../global_properties.robot
11
12 *** Variables ***
13 ${MR_HEALTH_CHECK_PATH}        /topics
14 ${MR_PUB_HEALTH_CHECK_PATH}        /events/TEST_TOPIC
15 ${MR_SUB_HEALTH_CHECK_PATH}        /events/TEST_TOPIC/g1/c4?timeout=5000
16 ${MR_CREATE_TOPIC_PATH}        /topics/create
17 ${MR_UPDATE_ACL_TOPIC_PATH}        /topics/TEST_TOPIC_ACL/producers
18 ${MR_ENDPOINT}     ${GLOBAL_MR_SERVER_PROTOCOL}://${GLOBAL_INJECTED_MR_IP_ADDR}:${GLOBAL_MR_SERVER_PORT}
19 ${MR_PUBLISH_TEMPLATE}     mr/mr_publish.jinja
20 ${MR_PUT_ACL_TEMPLATE}    mr/mr_put_acl.jinja
21
22
23 *** Keywords ***
24 Run MR Health Check
25      [Documentation]    Runs MR Health check
26      ${resp}=    Run MR Get Request    ${MR_HEALTH_CHECK_PATH}
27      Should Be Equal As Strings        ${resp.status_code}     200
28      Should Contain    ${resp.json()}    topics
29
30 Run MR PubSub Health Check
31      [Documentation]    Runs MR PubSub Health check
32      #${resp}=    Run MR Get Request    ${MR_SUB_HEALTH_CHECK_PATH}
33      # topic may not be created which is a 400 error
34
35      ${resp}=    Run MR Post Request    ${MR_PUB_HEALTH_CHECK_PATH}
36      Should Be Equal As Strings         ${resp.status_code}     200
37      Should Contain    ${resp.json()}    serverTimeMs    Failed to Write Data
38      ${resp}=    Run MR Get Request    ${MR_SUB_HEALTH_CHECK_PATH}
39      # Always Write twice to catch lost first message
40      ${resp}=    Run MR Post Request    ${MR_PUB_HEALTH_CHECK_PATH}
41      ${resp}=    Run MR Get Request    ${MR_SUB_HEALTH_CHECK_PATH}
42      # ${resp} is an array
43      Should Be Equal As Strings         ${resp.status_code}     200
44      Should Contain    ${resp.json()[0]}    timestamp    Failed to Read Data
45
46
47 Run MR Update Topic Acl
48      [Documentation]    Runs MR create topic and update producer credentials
49      #
50      #   Testing to Delete a Topic:
51      #           /opt/kafka/bin/kafka-topics.sh --zookeeper message-router-zookeeper:2181 --delete --topic <topic_name>
52      #           /opt/kafka/bin/kafka-topics.sh --zookeeper message-router-zookeeper:2181 --delete --topic TEST_TOPIC_ACL
53      #
54      #   Appears to not care if topic already exists with the POST / PUT method
55      #
56      ${dict}=    Create Dictionary    TOPIC_NAME=TEST_TOPIC_ACL
57      Templating.Create Environment    mr    ${GLOBAL_TEMPLATE_FOLDER}
58      ${data}=   Templating.Apply Template    mr    ${MR_PUT_ACL_TEMPLATE}    ${dict}
59      ${resp}=    Run MR Auth Post Request    ${MR_CREATE_TOPIC_PATH}   iPIxkpAMI8qTcQj8  Ehq3WyT4bkif4zwgEbvshGal   ${data}
60      #Log    Update Owner for TEST_TOPIC_ACL
61      ${resp}=    Run MR Auth Put Request    ${MR_UPDATE_ACL_TOPIC_PATH}/iPIxkpAMI8qTcQj8  iPIxkpAMI8qTcQj8    Ehq3WyT4bkif4zwgEbvshGal    ${data}
62      Should Be Equal As Strings         ${resp.status_code}     200
63
64 Run MR Auth Post Request
65      [Documentation]    Runs MR Authenticated Post Request
66      [Arguments]     ${data_path}     ${id_key}   ${secret_key}    ${data}
67      ${current_time}=   Get Time
68      ${time}=    Evaluate    datetime.datetime.today().replace(tzinfo=pytz.UTC).replace(microsecond=0).isoformat()    modules=datetime,pytz
69      ${command}=  Set Variable    /bin/echo -n "${time}" | /usr/bin/openssl sha1 -hmac "${secret_key}" -binary | /usr/bin/openssl base64
70      ${result}=    Run Process    ${command}   shell=True
71      ${signature}=   Set Variable    ${result.stdout}
72      ${xAuth}=    Set Variable    ${id_key}:${signature}
73      ${headers}=  Create Dictionary     Content-Type=application/json    X-CambriaAuth=${xAuth}    X-CambriaDate=${time}
74      ${session}=    Create Session      mr      ${MR_ENDPOINT}
75      ${resp}=   Post Request     mr      ${data_path}     headers=${headers}   data=${data}
76      ${status_string}=    Convert To String    ${resp.status_code}
77      Should Match Regexp    ${status_string}    ^(204|200)$
78      Log    Received response from message router ${resp.text}
79      [Return]    ${resp}
80
81
82 Run MR Auth Put Request
83      [Documentation]    Runs MR Authenticated Put Request
84      [Arguments]     ${data_path}     ${id_key}   ${secret_key}    ${data}
85      ${current_time}=   Get Time
86      ${time}=    Evaluate    datetime.datetime.today().replace(tzinfo=pytz.UTC).replace(microsecond=0).isoformat()    modules=datetime,pytz
87      ${command}=  Set Variable    /bin/echo -n "${time}" | /usr/bin/openssl sha1 -hmac "${secret_key}" -binary | /usr/bin/openssl base64
88      ${result}=    Run Process    ${command}   shell=True
89      ${signature}=   Set Variable    ${result.stdout}
90      ${xAuth}=    Set Variable    ${id_key}:${signature}
91      ${headers}=  Create Dictionary     Content-Type=application/json    X-CambriaAuth=${xAuth}    X-CambriaDate=${time}
92      ${session}=    Create Session      mr      ${MR_ENDPOINT}
93      ${resp}=   Put Request     mr      ${data_path}     headers=${headers}   data=${data}
94      Should Be Equal As Strings         ${resp.status_code}     200
95      Log    Received response from message router ${resp.text}
96      [Return]    ${resp}
97
98 Run MR Auth Get Request
99      [Documentation]    Runs MR Authenticated Put Request
100      [Arguments]     ${data_path}     ${username}   ${password}
101      ${auth}=            Create List              ${username}      ${password}
102      ${session}=    Create Session      mr      ${MR_ENDPOINT}     auth=${auth}
103      ${uuid}=    Generate UUID4
104      ${headers}=  Create Dictionary     Accept=application/json    Content-Type=application/json    X-TransactionId=${GLOBAL_APPLICATION_ID}-${uuid}    X-FromAppId=${GLOBAL_APPLICATION_ID}
105      ${resp}=   Get Request     mr      ${data_path}     headers=${headers}
106      Log    Received response from message router ${resp.text}
107      [Return]    ${resp}
108
109 Run MR Auth Post Request (User And Pass)
110      [Documentation]    Runs MR Authenticated Post Request
111      [Arguments]     ${data_path}     ${username}   ${password}   ${data}
112      ${auth}=            Create List              ${username}      ${password}
113      ${session}=    Create Session      mr      ${MR_ENDPOINT}     auth=${auth}
114      ${uuid}=    Generate UUID4
115      ${headers}=  Create Dictionary     Accept=application/json    Content-Type=application/json    X-TransactionId=${GLOBAL_APPLICATION_ID}-${uuid}
116      ${resp}=   Post Request     mr      ${data_path}     headers=${headers}   data=${data}
117      ${status_string}=    Convert To String    ${resp.status_code}
118      Should Match Regexp    ${status_string}    ^(204|200)$
119      Log    Received response from message router ${resp.text}
120      [Return]    ${resp}
121
122 Run MR Get Request
123      [Documentation]    Runs MR Get request
124      [Arguments]    ${data_path}
125      ${session}=    Create Session      mr      ${MR_ENDPOINT}
126      ${uuid}=    Generate UUID4
127      ${headers}=  Create Dictionary     Accept=application/json    Content-Type=application/json    X-TransactionId=${GLOBAL_APPLICATION_ID}-${uuid}    X-FromAppId=${GLOBAL_APPLICATION_ID}
128      ${resp}=   Get Request     mr      ${data_path}     headers=${headers}
129      Log    Received response from message router ${resp.text}
130      [Return]    ${resp}
131
132 Run MR Post Request
133      [Documentation]    Runs MR Post request
134      [Arguments]    ${data_path}
135      ${session}=    Create Session      mr      ${MR_ENDPOINT}
136      ${timestamp}=   Get Current Date
137      ${dict}=    Create Dictionary    timestamp=${timestamp}
138      Templating.Create Environment    mr    ${GLOBAL_TEMPLATE_FOLDER}
139      ${data}=   Templating.Apply Template    mr    ${MR_PUBLISH_TEMPLATE}    ${dict}
140      ${uuid}=    Generate UUID4
141      ${headers}=  Create Dictionary     Accept=application/json    Content-Type=application/json    X-TransactionId=${GLOBAL_APPLICATION_ID}-${uuid}    X-FromAppId=${GLOBAL_APPLICATION_ID}
142      ${resp}=   Post Request    mr      ${data_path}     data=${data}    headers=${headers}
143      Log    Received response from message router ${resp.text}
144      [Return]    ${resp}
145
146 Run MR Delete Request
147      [Documentation]    Runs MR Delete request
148      [Arguments]    ${data_path}
149      ${session}=    Create Session      mr      ${MR_ENDPOINT}
150      ${uuid}=    Generate UUID4
151      ${headers}=  Create Dictionary     Accept=application/json    Content-Type=application/json    X-TransactionId=${GLOBAL_APPLICATION_ID}-${uuid}    X-FromAppId=${GLOBAL_APPLICATION_ID}
152      ${resp}=   Delete Request     mr      ${data_path}     headers=${headers}
153      Log    Received response from message router ${resp.status_code}
154      [Return]    ${resp}