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