Docs: keep rules of name in the same way
[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 helm repo update\r
136 helm pull chartmuseum/chartmuseum # download chartmuseum-3.4.0.tgz to local\r
137 tar zxvf chartmuseum-3.4.0.tgz\r
138 \r
139 export NODE_IP=<INF OAM IP>\r
140 \r
141 cat <<EOF>chartmuseum-override.yaml\r
142 env:\r
143   open:\r
144     DISABLE_API: false\r
145 service:\r
146   type: NodePort\r
147   nodePort: 30330\r
148 EOF\r
149 \r
150 helm install chartmuseumrepo chartmuseum/chartmuseum -f chartmuseum-override.yaml\r
151 kubectl get pods\r
152 Kubectl get services\r
153 \r
154 helm repo add o2imsrepo http://${NODE_IP}:30330\r
155 helm repo update\r
156 \r
157 helm repo add bitnami https://charts.bitnami.com/bitnami\r
158 helm repo update\r
159 \r
160 helm pull bitnami/mysql\r
161 helm push mysql-8.8.16.tgz o2imsrepo\r
162 helm repo update\r
163 \r
164 helm install my-release o2imsrepo/mysql\r
165 kubectl get pods\r
166 helm del my-release\r
167 \r
168 ```\r
169 \r
170 \r
171 \r
172 ## Verify CFW over INF: Test with cnf firewall-host-netdevice\r
173 \r
174 ## Setup host netdevice over INF\r
175 \r
176 ```sh\r
177 ssh sysadmin@<inf oam IP>\r
178 sudo ip link add name veth11 type veth peer name veth12\r
179 sudo ip link add name veth21 type veth peer name veth22\r
180 sudo ip link |grep veth\r
181 exit\r
182 ```\r
183 \r
184 \r
185 ## verify CNF over INF\r
186 ```sh\r
187 git clone https://github.com/biny993/firewall-host-netdevice.git\r
188 \r
189 cat <<EOF> cfw-hostdev-override.yaml\r
190 \r
191 image:\r
192   repository: ubuntu\r
193   tag: 18.04\r
194   pullPolicy: IfNotPresent\r
195 \r
196 resources:\r
197   cpu: 2\r
198   memory: 2Gi\r
199   hugepage: 256Mi\r
200 \r
201 #global vars for parent and subcharts.\r
202 \r
203 \r
204   unprotectedNetPortVpg: veth11\r
205   unprotectedNetPortVfw: veth12\r
206   unprotectedNetCidr: 10.10.1.0/24\r
207   unprotectedNetGwIp: 10.10.1.1\r
208 \r
209   protectedNetPortVfw: veth21\r
210   protectedNetPortVsn: veth22\r
211   protectedNetCidr: 10.10.2.0/24\r
212   protectedNetGwIp: 10.10.2.1\r
213 \r
214   vfwPrivateIp0: 10.10.1.1\r
215   vfwPrivateIp1: 10.10.2.1\r
216 \r
217   vpgPrivateIp0: 10.10.1.2\r
218 \r
219   vsnPrivateIp0: 10.10.2.2\r
220 \r
221 EOF\r
222 \r
223 helm install cfw1 firewall-host-netdevice -f cfw-hostdev-override.yaml\r
224 kubectl get pods\r
225 helm del cfw1\r
226 ```\r
227 \r
228 ## push repo to o2imsrepo\r
229 \r
230 ```sh\r
231 tar -zcvf firewall-host-netdevice-1.0.0.tgz firewall-host-netdevice/\r
232 helm push firewall-host-netdevice-1.0.0.tgz o2imsrepo\r
233 helm repo update\r
234 helm search repo firewall\r
235 \r
236 helm install cfw1 o2imsrepo/firewall-host-netdevice -f cfw-hostdev-override.yaml\r
237 kubectl get pods\r
238 helm del cfw1\r
239 ```\r
240 \r
241 ## build docker image for o2 services\r
242 ```sh\r
243 cd o2\r
244 docker-compose build\r
245 \r
246 ```\r
247 \r
248 ## bootstrap o2 service with docker-compose\r
249 ```sh\r
250 \r
251 mkdir -p temp/kubeconfig/\r
252 cp <your .kube/config> temp/kubeconfig/\r
253 \r
254 source ./admin_openrc.sh\r
255 export K8S_KUBECONFIG=/etc/kubeconfig/config\r
256 docker-compose up -d\r
257 docker logs -f o2_redis_pubsub_1\r
258 \r
259 ```\r
260 \r
261 ## simiulate SMO to deploy CFW\r
262 \r
263 ```sh\r
264 \r
265 curl --location --request GET 'http://localhost:5005/o2ims_infrastructureInventory/v1/deploymentManagers'\r
266 export dmsId=<DMS ID>\r
267 curl --location --request POST 'http://localhost:5005/o2dms/${dmsId}/O2dms_DeploymentLifecycle/NfDeploymentDescriptor' \\r
268 --header 'Content-Type: application/json' \\r
269 --data-raw '{\r
270   "name": "cfwdesc1",\r
271   "description": "demo nf deployment descriptor",\r
272   "artifactRepoUrl": "http://128.224.115.15:30330",\r
273   "artifactName": "firewall-host-netdevice",\r
274   "inputParams": \r
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}",\r
276   "outputParams": "{\"output1\": 100}"\r
277 }'\r
278 \r
279 curl --location --request GET 'http://localhost:5005/o2dms/${dmsId}/O2dms_DeploymentLifecycle/NfDeploymentDescriptor'\r
280 \r
281 curl --location --request POST 'http://localhost:5005/o2dms/${dmsId}/O2dms_DeploymentLifecycle/NfDeployment' \\r
282 --header 'Content-Type: application/json' \\r
283 --data-raw '{\r
284   "name": "cfw100",\r
285   "description": "demo nf deployment",\r
286   "descriptorId": "<NfDeploymentDescriptorId>",\r
287   "parentDeploymentId": ""\r
288 }'\r
289 \r
290 curl --location --request GET 'http://localhost:5005/o2dms/${dmsId}/O2dms_DeploymentLifecycle/NfDeployment'\r
291 \r
292 export NfDeploymentId=<NfDeployment Id>\r
293 \r
294 ```\r
295 \r
296 ## check logs\r
297 \r
298 ```sh\r
299 docker logs -f o2_redis_pubsub_1\r
300 kubectl get pods\r
301 kubectl logs -f cfw100-sink-host-netdevice-59bf6fbd4b-845p4\r
302 ```\r
303 \r
304 ## watch traffic stats\r
305 \r
306 open browswer with url: http://<NODE_IP>:30667\r
307 \r
308 \r
309 ## bring down CFW\r
310 \r
311 ```sh\r
312 curl --location --request DELETE 'http://localhost:5005/o2dms/${dmsId}/O2dms_DeploymentLifecycle/NfDeployment/${NfDeploymentId}'\r
313 ```\r