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