2 Documentation Robot keyword library (Resource) for runtime changes to config subsystem state using restconf calls.
4 ... Copyright (c) 2015 Cisco Systems, Inc. and others. All rights reserved.
6 ... This program and the accompanying materials are made available under the
7 ... terms of the Eclipse Public License v1.0 which accompanies this distribution,
8 ... and is available at http://www.eclipse.org/legal/epl-v10.html
9 Library OperatingSystem
10 Library RequestsLibrary
12 Variables ${CURDIR}/../variables/Variables.py
15 # TODO: Make the following list more narrow when Bug 2594 is fixed.
16 @{allowed_status_codes} ${200} ${201} ${204} # List of integers, not strings. Used by both PUT and DELETE.
19 Setup_Config_Via_Restconf
20 [Documentation] Creates Requests session to be used by subsequent keywords.
21 # Do not append slash at the end uf URL, Requests would add another, resulting in error.
22 RequestsLibrary.Create_Session cvr_session http://${CONTROLLER}:${RESTCONFPORT}${CONTROLLER_CONFIG_MOUNT} headers=${HEADERS_XML} auth=${AUTH}
24 Teardown_Config_Via_Restconf
25 [Documentation] Teardown to pair with Setup (otherwise no-op).
26 BuiltIn.Comment TODO: The following line does not seem to be implemented by RequestsLibrary. Look for a workaround.
27 BuiltIn.Comment Delete_Session cvr_session
29 Put_Xml_Template_Folder_Config_Via_Restconf
30 [Arguments] ${folder} ${mapping_as_string}={}
31 [Documentation] Resolve URI and data from folder, PUT to controller config.
32 ${uri_part}= Resolve_URI_From_Template_Folder ${folder} ${mapping_as_string}
33 ${xml_data}= Resolve_Xml_Data_From_Template_Folder ${folder} ${mapping_as_string}
34 Put_Xml_Config_Via_Restconf ${uri_part} ${xml_data}
36 Delete_Xml_Template_Folder_Config_Via_Restconf
37 [Arguments] ${folder} ${mapping_as_string}={}
38 [Documentation] Resolve URI from folder, DELETE from controller config.
39 ${uri_part}= Resolve_URI_From_Template_Folder ${folder} ${mapping_as_string}
40 Delete_Config_Via_Restconf ${uri_part}
42 Resolve_URI_From_Template_Folder
43 [Arguments] ${folder} ${mapping_as_string}
44 [Documentation] Read URI template from folder, strip endline, make changes according to mapping, return the result.
45 ${uri_template}= OperatingSystem.Get_File ${folder}${/}config.uri
46 BuiltIn.Log ${uri_template}
47 ${uri_part}= Strip_Endline_And_Apply_Substitutions_From_Mapping ${uri_template} ${mapping_as_string}
50 Resolve_Xml_Data_From_Template_Folder
51 [Arguments] ${folder} ${mapping_as_string}
52 [Documentation] Read data template from folder, strip endline, make changes according to mapping, return the result.
53 ${data_template}= OperatingSystem.Get_File ${folder}${/}data.xml
54 BuiltIn.Log ${data_template}
55 ${xml_data}= Strip_Endline_And_Apply_Substitutions_From_Mapping ${data_template} ${mapping_as_string}
58 Strip_Endline_And_Apply_Substitutions_From_Mapping
59 [Arguments] ${template_as_string} ${mapping_as_string}
60 [Documentation] Strip endline, apply substitutions, Log and return the result.
61 # Robot Framework does not understand dictionaries well, so resort to Evaluate.
62 # Needs python module "string", and since the template string is expected to contain newline, it has to be enclosed in triple quotes.
63 # Using rstrip() removes all trailing whitespace, which is what we want if there is something more than an endline.
64 ${final_text}= BuiltIn.Evaluate string.Template('''${template_as_string}'''.rstrip()).substitute(${mapping_as_string}) modules=string
65 BuiltIn.Log ${final_text}
66 [Return] ${final_text}
68 Put_Xml_Config_Module_Via_Restconf
69 [Arguments] ${xml_data} ${type} ${name}
70 [Documentation] Put new XML configuration to config:modules URI based on given module type and name.
72 Put_Xml_Config_Via_Restconf config:modules/module/${type}/${name} ${xml_data}
74 Put_Xml_Config_Service_Via_Restconf
75 [Arguments] ${xml_data} ${type} ${name}
76 [Documentation] Put new XML configuration to config:services URI based on given service type and instance name.
77 Put_Xml_Config_Via_Restconf config:services/service/${type}/config:instance/${name} ${xml_data}
79 Put_Xml_Config_Via_Restconf
80 [Arguments] ${uri_part} ${xml_data}
81 [Documentation] Put XML data to given controller-config URI, check reponse text is empty and status_code is one of allowed ones.
82 BuiltIn.Log ${uri_part}
83 BuiltIn.Log ${xml_data}
84 ${response}= RequestsLibrary.Put cvr_session ${uri_part} data=${xml_data}
85 BuiltIn.Log ${response.text}
86 BuiltIn.Log ${response.status_code}
87 BuiltIn.Should_Be_Empty ${response.text}
88 BuiltIn.Should_Contain ${allowed_status_codes} ${response.status_code}
90 Delete_Config_Via_Restconf
91 [Arguments] ${uri_part}
92 [Documentation] Delete resource at controller-config URI, check reponse text is empty and status_code is 204.
93 BuiltIn.Log ${uri_part}
94 ${response}= RequestsLibrary.Delete cvr_session ${uri_part}
95 BuiltIn.Log ${response.text}
96 BuiltIn.Should_Be_Empty ${response.text}
97 BuiltIn.Should_Contain ${allowed_status_codes} ${response.status_code}
99 Post_Xml_Config_Module_Via_Restconf
100 [Arguments] ${xml_data}
101 [Documentation] Post new XML configuration to config:modules.
103 Post_Xml_Config_Via_Restconf config:modules ${xml_data}
105 Post_Xml_Config_Service_Via_Restconf
106 [Arguments] ${xml_data}
107 [Documentation] Post new XML configuration to config:services.
108 Post_Xml_Config_Via_Restconf config:services ${xml_data}
110 Post_Xml_Config_Via_Restconf
111 [Arguments] ${uri_part} ${xml_data}
112 [Documentation] Post XML data to given controller-config URI, check reponse text is empty and status_code is 204.
113 # As seen in previous two Keywords, Post does not need long specific URI.
114 # But during Lithium development, Post ceased to do merge, so those Keywords do not work anymore.
115 # This Keyword can still be used with specific URI to create a new container and fail if a container was already present.
116 ${response}= RequestsLibrary.Post_Request cvr_session ${uri_part} data=${xml_data}
117 BuiltIn.Log ${response.text}
118 BuiltIn.Should_Be_Empty ${response.text}
119 BuiltIn.Should_Be_Equal_As_Strings ${response.status_code} 204