Add client cert to support mTLS
[it/test.git] / test_scripts / O2IMS_Compliance_Test / readme.md
1 # Overview
2
3 This folder includes the ORAN O2 IMS Compliance Automation Test Scripts, which used
4 Robot Framework to simulate SMO to issue API request towards O2IMS.
5
6 The Mock server simulates the SMO to expose API endpoints for O-Clouds to deliver Notifications from O-Cloud to SMO.
7
8 The detailed structure with comments is below.
9
10 ```
11 O2IMS_Compliance_Test
12        |--o2ims_compliance # where all the compliance test cases related are here.
13                      |--schemas   # all the json schema used to validate the O2ims response body are put here.
14                                  |-- xxx.json #The json schema which used by automation test cases to validate the o2ims response body compliance to O-RAN Working Group 6 O2ims Interface Specification.
15                                  |--yyy.json # For example:  Expect Response Body        ${CURDIR}/schemas/alarm_subscription_properties.json
16                                  |-- …..json
17                      |--__init__.robot #helper robot script where put common key words definition used by test cases scripts.
18                      |--oran-helm.robot# same as above.
19                      |--oran-lcm.robot # same as above.
20                      |--smo_server_mock.robot # helper robot script where put smo server mock related common key words together.
21                      |--ssh_helper.robot # ssh helper robot script used by test cases scripts.
22                      |--7.3.2_SMO_succeeds_xxx.robot # The automation test cases which are in compliance to test spec, which you can find in reference doc [9] 
23                      |--7.3.3…  #the same as above one.
24                      |-- …
25                      |--7.3.10  # same as above one.
26        |--mock.sh # The sample script to help input smo mock endpoints in mock server
27        |--readme.md #Overall explaination about this folder mainly about how to compose test env and run robot test cases etc.
28        |--test_configs.yaml # The config file used by robot framework and test cases script with comments.
29
30 ```
31
32 ## Test Environment Preparation
33
34 ### Prepare robot framework with virtualenv
35
36 ```
37 virtualenv .robot
38 source .robot/bin/activate
39 pip3 install --upgrade robotframework
40 pip3 install --upgrade RESTinstance
41 pip3 install --upgrade robotframework-sshlibrary
42
43 robot --version
44
45 ```
46 ### Prepare SMO Mock Server
47
48 Please see reference doc [8] to set up mock server.
49
50 Use the sample shell script to add mock expectations to mock server.
51
52 ```
53 bash sample.sh 127.0.0.1 1080
54 ```
55
56 Use the sample command below to check can get the expected response from mockserver.
57
58 For one example on local test env.
59
60 ```
61
62  curl -v -k -X POST http://127.0.0.1:1080/mock_smo/v1/ocloud_observer
63 *   Trying 127.0.0.1...
64 * Connected to 127.0.0.1 (127.0.0.1) port 1080 (#0)
65 > POST /mock_smo/v1/ocloud_observer HTTP/1.1
66 > Host: 127.0.0.1:1080
67 > User-Agent: curl/7.47.0
68 > Accept: */*
69 >
70 < HTTP/1.1 204 No Content
71 < connection: keep-alive
72 < content-type: application/json; charset=utf-8
73 <
74 * Connection #0 to host 127.0.0.1 left intact
75 ```
76
77 And other test sample expectations are the same way.
78
79 ### Prepare the client certificates for mTLS
80
81 Since mTLS is supported by the O2 IMS API service, you need to add the client certificates when requesting the API.
82
83 Here are the steps to generate client certificates using the MockServer CA certificate:
84
85 * Generate Client Certificates:
86
87 Follow these steps to generate client certificates using the MockServer CA certificate.
88
89 ```bash
90 cd certs
91
92 # Get MockServer CA cert and key
93 wget -O smo-ca-cert.pem https://raw.githubusercontent.com/mock-server/mockserver/master/mockserver-core/src/main/resources/org/mockserver/socket/CertificateAuthorityCertificate.pem
94
95 wget -O smo-ca-key.pem https://raw.githubusercontent.com/mock-server/mockserver/master/mockserver-core/src/main/resources/org/mockserver/socket/CertificateAuthorityPrivateKey.pem
96
97 # Generate client CSR (Certificate Signing Request) and key
98 openssl genrsa -out client-key.pem 2048
99 openssl req -new -key client-key.pem -out client.csr
100
101 # Sign the Client CSR with MockServer's CA
102 openssl x509 -req -in client.csr -CA smo-ca-cert.pem -CAkey smo-ca-key.pem -CAcreateserial -out client-cert.pem -days 365
103
104 # Combine the client cert and private key to one file
105 cat client-cert.pem client-key.pem > client.pem
106 ```
107
108 * Ensure Correct CA Certificate:
109
110 Make sure you are using the MockServer CA certificate (smo_cert) when setting up the O2 application.
111
112 ### Test Configuration File Guide.
113
114 The test_configs.yaml is the configuration file for the test script to get environment variables for issuing requests to O2 IMS service, to
115 install INF O2 Service, please reference doc [10] and [11], after installation and provisioning O2 IMS services, the corresponding O2 IMS parameters
116 should be input into below config files correspondingly before running automation test.
117
118 The sample config file parameters explaination in details as below.
119 ```
120 ocloud: # O Cloud side configuration.
121   ssh: #olcoud ssh info
122     host: 192.168.112.12 # API Host Floating IP.
123     port: 22 #ssh server port
124     username: username
125     password: passwd
126     openrc: /etc/platform/openrc
127   oran_o2_app:
128     g_location_id: testlocation_1 # global location id from SMO.
129     g_ocloud_id: 18f2dc90-b375-47dd-b8dc-ae80072e6cdb # global ocloud id from SMO.
130     smo_token_data: put_smo_token_data_here # smo token, currently generated by o2ims and deliver to SMO side by O-Cloud available notification, refer to doc [0]
131     api:
132       host: 192.168.112.15 # O2 IMS API Host Floating IP.
133       node_port: 30205 # O2 IMS port
134       protocol: https #O2 IMS application protocol.
135
136 smo: #smo mock server ip and callback endpoints
137   service:
138     protocol: https # SMO application protocol.
139     host: 192.168.112.16 # SMO Host IP.
140     port: 1080 # SMO Service Port.
141     verify_endpoint: /mockserver/verify # Test tool verification, refer to [1]
142   ocloud_observer: # Simulate SMO O Cloud Registration callback Endpoint.
143     path: /mock_smo/v1/ocloud_observer
144   o2ims_inventory_observer: #Simulate SMO inventory notification callback endpoint.
145     path: /mock_smo/v1/o2ims_inventory_observer
146   o2ims_alarm_observer: #Simulate SMO alarm notification callback endpoint.
147     path: /mock_smo/v1/o2ims_alarm_observer
148 ```
149 After finish input the parameters, user is ready to run the automation test cases.
150
151 ### Run Test Scripts
152
153 ```
154 robot -L debug -d ./.reports ./o2ims_compliance
155 ```
156
157 ### Debug tips
158
159 Please check the mock server dashboard to help debug your request status.
160
161 http://mockserverip:1081/mockserver/dashboard
162
163 ## Reference
164 0. [https://oranalliance.atlassian.net/wiki/download/attachments/2612854785/O-RAN.WG6.O2IMS-INTERFACE-v03.00.pdf?api=v2]
165 1. [https://mock-server.com/]
166 2. [https://robotframework.org/robotframework/latest/RobotFrameworkUserGuide.html]
167 3. [http://robotframework.org/robotframework/2.6.1/libraries/BuiltIn.html]
168 4. [https://robotframework.org/?tab=1#getting-started]
169 5. [https://asyrjasalo.github.io/RESTinstance]
170 6. [https://pypi.org/project/RESTinstance/]
171 7. [http://robotframework.org/SSHLibrary/]
172 8. [https://www.mock-server.com/where/docker.html]
173 9. [https://oranalliance.atlassian.net/wiki/download/attachments/2505408783/O-RAN.WG6-O-CLOUD_CONF_TEST-R003-v01.00.00.docx?api=v2]
174 10. [https://docs.o-ran-sc.org/projects/o-ran-sc-pti-o2/en/latest/installation-guide.html]
175 11. [https://docs.o-ran-sc.org/projects/o-ran-sc-pti-o2/en/latest/user-guide.html]