CI: Add non voting tox verify GHA workflow call
[pti/o2.git] / README.md
1 ## Building containers
2
3 To accommodate the git repo access issue, the cgts-client and distributed client are
4 cloned into temp before docker building
5
6 ```sh
7 mkdir -p temp
8 cd temp
9 git clone --branch r/stx.7.0 https://opendev.org/starlingx/config.git
10 git clone --branch master https://opendev.org/starlingx/distcloud-client.git
11 (cd distcloud-client && git reset --hard eb4e7eeeb09bdf2e1b80984b378c5a8ea9930f04)
12 git clone --depth 1 --branch r/stx.7.0 https://opendev.org/starlingx/fault.git
13 cd config
14 git checkout bca406d1
15 patch -p1 < ../../cgtsclient-insecure.patch
16 cd -
17 ```
18
19 ```sh
20 docker-compose build
21 ```
22
23 ## Running the tests
24
25
26 ```sh
27 source ./admin_openrc.sh
28 export |grep OS_AUTH_URL
29 export |grep OS_USERNAME
30 export |grep OS_PASSWORD
31 docker-compose up -d
32 docker-compose run --rm --no-deps --entrypoint=pytest api /tests/unit /tests/integration
33 ```
34
35 ## Running the tests with a O-Cloud
36
37 Prerequisite: in case of testing against real ocloud, download openrc file from ocloud dashboard, e.g. 
38
39 ```sh
40 admin_openrc.sh
41 docker-compose run --rm --no-deps --entrypoint=pytest api /tests/unit /tests/integration-ocloud
42
43 docker-compose run --rm --no-deps --entrypoint=pytest api /tests/integration-ocloud --log-level=DEBUG --log-file=/test
44 s/debug.log
45 ```
46
47 ## Tear down containers
48
49 ```sh
50 docker-compose down --remove-orphans
51 ```
52
53 ## Test with local virtualenv
54
55 ```sh
56 python3.8 -m venv .venv && source .venv/bin/activate
57 pip install -r requirements.txt -c constraints.txt
58 pip install -r requirements-test.txt
59 pip install -e o2ims
60 # pip install -e o2dms -e o2common
61 pytest tests/unit
62 pytest tests/integration
63 pytest tests/e2e
64 ```
65
66
67 Test O2DMS with docker-compose
68 ==============================
69
70 ## setup account over INF and get token
71
72 ```sh
73 USER="admin-user"
74 NAMESPACE="kube-system"
75
76 cat <<EOF > admin-login.yaml
77 apiVersion: v1
78 kind: ServiceAccount
79 metadata:
80   name: ${USER}
81   namespace: kube-system
82 ---
83 apiVersion: rbac.authorization.k8s.io/v1
84 kind: ClusterRoleBinding
85 metadata:
86   name: ${USER}
87 roleRef:
88   apiGroup: rbac.authorization.k8s.io
89   kind: ClusterRole
90   name: cluster-admin
91 subjects:
92 - kind: ServiceAccount
93   name: ${USER}
94   namespace: kube-system
95 EOF
96 kubectl apply -f admin-login.yaml
97 TOKEN_DATA=$(kubectl -n kube-system describe secret $(kubectl -n kube-system get secret | grep ${USER} | awk '{print $1}') | grep "token:" | awk '{print $2}')
98
99 ```
100
101 ## setup remote cli to access kubenetes cluster over INF
102
103 ```sh
104 sudo apt-get install -y apt-transport-https
105 echo "deb http://mirrors.ustc.edu.cn/kubernetes/apt kubernetes-xenial main" | \
106 sudo tee -a /etc/apt/sources.list.d/kubernetes.list
107 sudo apt-get update
108 sudo apt-get install -y kubectl
109
110 source <(kubectl completion bash) # setup autocomplete in bash into the current shell, bash-completion package should be installed first.
111 echo "source <(kubectl completion bash)" >> ~/.bashrc # add autocomplete permanently to your bash shell.
112
113 https://get.helm.sh/helm-v3.5.3-linux-amd64.tar.gz
114 tar xvf helm-v3.5.3-linux-amd64.tar.gz
115 sudo cp linux-amd64/helm /usr/local/bin
116
117 source <(helm completion bash)
118 echo "source <(helm completion bash)" >> ~/.bashrc
119
120 OAM_IP=<INF OAM IP>
121 NAMESPACE=default
122 TOKEN_DATA=<TOKEN_DATA from INF>
123
124 USER="admin-user"
125
126 kubectl config set-cluster inf-cluster --server=https://${OAM_IP}:6443 --insecure-skip-tls-verify
127 kubectl config set-credentials ${USER} --token=$TOKEN_DATA
128 kubectl config  set-context ${USER}@inf-cluster --cluster=inf-cluster --user ${USER} --namespace=${NAMESPACE}
129 kubectl config use-context ${USER}@inf-cluster
130
131 kubectl get pods -A
132
133 ```
134
135
136 ## setup local repo: o2imsrepo
137
138 ```sh
139 helm repo add chartmuseum https://chartmuseum.github.io/charts
140 helm repo update
141 helm pull chartmuseum/chartmuseum # download chartmuseum-3.4.0.tgz to local
142 tar zxvf chartmuseum-3.4.0.tgz
143
144 export NODE_IP=<INF OAM IP>
145
146 cat <<EOF>chartmuseum-override.yaml
147 env:
148   open:
149     DISABLE_API: false
150 service:
151   type: NodePort
152   nodePort: 30330
153 EOF
154
155 helm install chartmuseumrepo chartmuseum/chartmuseum -f chartmuseum-override.yaml
156 kubectl get pods
157 Kubectl get services
158
159 helm repo add o2imsrepo http://${NODE_IP}:30330
160 helm repo update
161
162 helm repo add bitnami https://charts.bitnami.com/bitnami
163 helm repo update
164
165 helm pull bitnami/mysql
166 helm push mysql-8.8.16.tgz o2imsrepo
167 helm repo update
168
169 helm install my-release o2imsrepo/mysql
170 kubectl get pods
171 helm del my-release
172
173 ```
174
175
176
177 ## Verify CFW over INF: Test with cnf firewall-host-netdevice
178
179 ## Setup host netdevice over INF
180
181 ```sh
182 ssh sysadmin@<inf oam IP>
183 sudo ip link add name veth11 type veth peer name veth12
184 sudo ip link add name veth21 type veth peer name veth22
185 sudo ip link |grep veth
186 exit
187 ```
188
189
190 ## verify CNF over INF
191 ```sh
192 git clone https://github.com/biny993/firewall-host-netdevice.git
193
194 cat <<EOF> cfw-hostdev-override.yaml
195
196 image:
197   repository: ubuntu
198   tag: 18.04
199   pullPolicy: IfNotPresent
200
201 resources:
202   cpu: 2
203   memory: 2Gi
204   hugepage: 256Mi
205
206 #global vars for parent and subcharts.
207
208
209   unprotectedNetPortVpg: veth11
210   unprotectedNetPortVfw: veth12
211   unprotectedNetCidr: 10.10.1.0/24
212   unprotectedNetGwIp: 10.10.1.1
213
214   protectedNetPortVfw: veth21
215   protectedNetPortVsn: veth22
216   protectedNetCidr: 10.10.2.0/24
217   protectedNetGwIp: 10.10.2.1
218
219   vfwPrivateIp0: 10.10.1.1
220   vfwPrivateIp1: 10.10.2.1
221
222   vpgPrivateIp0: 10.10.1.2
223
224   vsnPrivateIp0: 10.10.2.2
225
226 EOF
227
228 helm install cfw1 firewall-host-netdevice -f cfw-hostdev-override.yaml
229 kubectl get pods
230 helm del cfw1
231 ```
232
233 ## push repo to o2imsrepo
234
235 ```sh
236 tar -zcvf firewall-host-netdevice-1.0.0.tgz firewall-host-netdevice/
237 helm push firewall-host-netdevice-1.0.0.tgz o2imsrepo
238 helm repo update
239 helm search repo firewall
240
241 helm install cfw1 o2imsrepo/firewall-host-netdevice -f cfw-hostdev-override.yaml
242 kubectl get pods
243 helm del cfw1
244 ```
245
246 ## build docker image for o2 services
247 ```sh
248 cd o2
249 docker-compose build
250
251 ```
252
253 ## bootstrap o2 service with docker-compose
254 ```sh
255
256 mkdir -p temp/kubeconfig/
257 cp <your .kube/config> temp/kubeconfig/
258
259 source ./admin_openrc.sh
260 export K8S_KUBECONFIG=/etc/kubeconfig/config
261 docker-compose up -d
262 docker logs -f o2_redis_pubsub_1
263
264 ```
265
266 ## simiulate SMO to deploy CFW
267
268 ```sh
269
270 curl --location --request GET 'http://localhost:5005/o2ims_infrastructureInventory/v1/deploymentManagers'
271 export dmsId=<DMS ID>
272 curl --location --request POST 'http://localhost:5005/o2dms/v1/${dmsId}/O2dms_DeploymentLifecycle/NfDeploymentDescriptor' \
273 --header 'Content-Type: application/json' \
274 --data-raw '{
275   "name": "cfwdesc1",
276   "description": "demo nf deployment descriptor",
277   "artifactRepoUrl": "http://128.224.115.15:30330",
278   "artifactName": "firewall-host-netdevice",
279   "inputParams": 
280   "{\n  \"image\": {\n    \"repository\": \"ubuntu\",\n    \"tag\": 18.04,\n    \"pullPolicy\": \"IfNotPresent\"\n  },\n  \"resources\": {\n    \"cpu\": 2,\n    \"memory\": \"2Gi\",\n    \"hugepage\": \"256Mi\",\n    \"unprotectedNetPortVpg\": \"veth11\",\n    \"unprotectedNetPortVfw\": \"veth12\",\n    \"unprotectedNetCidr\": \"10.10.1.0/24\",\n    \"unprotectedNetGwIp\": \"10.10.1.1\",\n    \"protectedNetPortVfw\": \"veth21\",\n    \"protectedNetPortVsn\": \"veth22\",\n    \"protectedNetCidr\": \"10.10.2.0/24\",\n    \"protectedNetGwIp\": \"10.10.2.1\",\n    \"vfwPrivateIp0\": \"10.10.1.1\",\n    \"vfwPrivateIp1\": \"10.10.2.1\",\n    \"vpgPrivateIp0\": \"10.10.1.2\",\n    \"vsnPrivateIp0\": \"10.10.2.2\"\n  }\n}",
281   "outputParams": "{\"output1\": 100}"
282 }'
283
284 curl --location --request GET 'http://localhost:5005/o2dms/v1/${dmsId}/O2dms_DeploymentLifecycle/NfDeploymentDescriptor'
285
286 curl --location --request POST 'http://localhost:5005/o2dms/v1/${dmsId}/O2dms_DeploymentLifecycle/NfDeployment' \
287 --header 'Content-Type: application/json' \
288 --data-raw '{
289   "name": "cfw100",
290   "description": "demo nf deployment",
291   "descriptorId": "<NfDeploymentDescriptorId>",
292   "parentDeploymentId": ""
293 }'
294
295 curl --location --request GET 'http://localhost:5005/o2dms/v1/${dmsId}/O2dms_DeploymentLifecycle/NfDeployment'
296
297 export NfDeploymentId=<NfDeployment Id>
298
299 ```
300
301 ## check logs
302
303 ```sh
304 docker logs -f o2_redis_pubsub_1
305 kubectl get pods
306 kubectl logs -f cfw100-sink-host-netdevice-59bf6fbd4b-845p4
307 ```
308
309 ## watch traffic stats
310
311 open browswer with url: http://<NODE_IP>:30667
312
313
314 ## bring down CFW
315
316 ```sh
317 curl --location --request DELETE 'http://localhost:5005/o2dms/v1/${dmsId}/O2dms_DeploymentLifecycle/NfDeployment/${NfDeploymentId}'
318 ```