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