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