-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathoutput.txt
More file actions
457 lines (380 loc) · 21 KB
/
output.txt
File metadata and controls
457 lines (380 loc) · 21 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
# ------------------------------------------------------------------------
# Environment Setup / Install Required Software
# ------------------------------------------------------------------------
toor@ip-172-31-10-165:~$ sudo apt update
[sudo] password for toor:
Hit:1 http://ap-south-1.ec2.archive.ubuntu.com/ubuntu noble InRelease
Hit:2 http://ap-south-1.ec2.archive.ubuntu.com/ubuntu noble-updates InRelease
Hit:3 http://ap-south-1.ec2.archive.ubuntu.com/ubuntu noble-backports InRelease
Hit:4 http://security.ubuntu.com/ubuntu noble-security InRelease
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
All packages are up to date.
toor@ip-172-31-10-165:~$ sudo apt install -y python3 python3-pip python3-venv
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
python3 is already the newest version (3.12.3-0ubuntu2).
python3-pip is already the newest version (24.0+dfsg-1ubuntu1).
python3-venv is already the newest version (3.12.3-0ubuntu2).
0 upgraded, 0 newly installed, 0 to remove and 0 not upgraded.
toor@ip-172-31-10-165:~$ sudo apt install -y redis-server
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
redis-server is already the newest version (5:7.0.15-1ubuntu0.2).
0 upgraded, 0 newly installed, 0 to remove and 0 not upgraded.
toor@ip-172-31-10-165:~$ sudo systemctl start redis-server
toor@ip-172-31-10-165:~$ sudo systemctl enable redis-server
Synchronizing state of redis-server.service with SysV service script with /usr/lib/systemd/systemd-sysv-install.
Executing: /usr/lib/systemd/systemd-sysv-install enable redis-server
toor@ip-172-31-10-165:~$ redis-cli ping
PONG
# ------------------------------------------------------------------------
# Environment Setup / Create Project Structure
# ------------------------------------------------------------------------
toor@ip-172-31-10-165:~$ mkdir -p ~/automation-platform
toor@ip-172-31-10-165:~$ cd ~/automation-platform
toor@ip-172-31-10-165:~/automation-platform$ python3 -m venv venv
toor@ip-172-31-10-165:~/automation-platform$ source venv/bin/activate
(venv) toor@ip-172-31-10-165:~/automation-platform$ python3 -m pip install --upgrade pip
Requirement already satisfied: pip in ./venv/lib/python3.12/site-packages (24.0)
Collecting pip
Using cached pip-25.1.1-py3-none-any.whl (1.8 MB)
Installing collected packages: pip
Attempting uninstall: pip
Found existing installation: pip 24.0
Uninstalling pip-24.0:
Successfully uninstalled pip-24.0
Successfully installed pip-25.1.1
(venv) toor@ip-172-31-10-165:~/automation-platform$ python3 -m pip install flask redis celery click pyyaml requests
Collecting flask
Collecting redis
Collecting celery
Collecting click
Collecting pyyaml
Collecting requests
Collecting billiard<5.0,>=4.2.1
Collecting kombu<5.6,>=5.5.2
Collecting vine<6.0,>=5.1.0
Collecting python-dateutil>=2.8.2
Collecting amqp<6.0.0,>=5.1.1
Collecting tzdata>=2025.2
Collecting packaging
Collecting prompt-toolkit>=3.0.36
Collecting click-didyoumean>=0.3.0
Collecting click-repl>=0.2.0
Collecting blinker>=1.9.0
Collecting itsdangerous>=2.2.0
Collecting jinja2>=3.1.2
Collecting markupsafe>=2.1.1
Collecting werkzeug>=3.1.0
Collecting charset_normalizer<4,>=2
Collecting idna<4,>=2.5
Collecting urllib3<3,>=1.21.1
Collecting certifi>=2017.4.17
Installing collected packages: wcwidth, vine, urllib3, tzdata, redis, pyyaml, prompt-toolkit, packaging, markupsafe, idna, click, charset_normalizer, certifi, blinker, billiard, amqp, werkzeug, requests, jinja2, itsdangerous, click-repl, click-didyoumean, kombu, flask, celery
Successfully installed amqp-5.3.1 billiard-4.2.1 blinker-1.9.0 celery-5.5.2 certifi-2025.4.26 charset_normalizer-3.4.2 click-8.2.1 click-didyoumean-0.3.1 click-repl-0.3.0 flask-3.1.1 idna-3.10 itsdangerous-2.2.0 jinja2-3.1.6 kombu-5.5.4 markupsafe-3.0.2 packaging-25.0 prompt-toolkit-3.0.51 pyyaml-6.0.2 redis-6.1.0 requests-2.32.3 tzdata-2025.2 urllib3-2.4.0 vine-5.1.0 wcwidth-0.2.13
# ------------------------------------------------------------------------
# Environment Setup / Setup Directory Structure
# ------------------------------------------------------------------------
(venv) toor@ip-172-31-10-165:~/automation-platform$ mkdir -p api cli workers policies logs
(venv) toor@ip-172-31-10-165:~/automation-platform$ touch api/__init__.py cli/__init__.py workers/__init__.py policies/__init__.py
# ------------------------------------------------------------------------
# Environment Setup / Setup Directory Structure / Create configuration file
# ------------------------------------------------------------------------
(venv) toor@ip-172-31-10-165:~/automation-platform$ nano config.yaml
# ------------------------------------------------------------------------
# Task 1: Build the Core Components / Step 1: Create Policy Engine
# ------------------------------------------------------------------------
(venv) toor@ip-172-31-10-165:~/automation-platform$ nano policies/policy_engine.py
# ------------------------------------------------------------------------
# Task 1: Build the Core Components / Step 2: Create Worker System
# ------------------------------------------------------------------------
(venv) toor@ip-172-31-10-165:~/automation-platform$ nano workers/task_worker.py
# ------------------------------------------------------------------------
# Task 1: Build the Core Components / Step 3: Build REST API
# ------------------------------------------------------------------------
(venv) toor@ip-172-31-10-165:~/automation-platform$ nano api/automation_api.py
# ------------------------------------------------------------------------
# Task 1: Build the Core Components / Step 4: Create CLI Interface
# ------------------------------------------------------------------------
(venv) toor@ip-172-31-10-165:~/automation-platform$ nano cli/automation_cli.py
# ------------------------------------------------------------------------
# Task 2: Integration and Testing / Step 2: Start All Components
# ------------------------------------------------------------------------
(venv) toor@ip-172-31-10-165:~/automation-platform$ nano start_platform.sh
# ------------------------------------------------------------------------
# Task 2: Integration and Testing / Step 2: Start All Components / Make it executable:
# ------------------------------------------------------------------------
(venv) toor@ip-172-31-10-165:~/automation-platform$ chmod +x start_platform.sh
# ------------------------------------------------------------------------
# Task 2: Integration and Testing / Step 3: Test the Platform / Terminal 1: Start the platform
# ------------------------------------------------------------------------
(venv) toor@ip-172-31-10-165:~/automation-platform$ cd ~/automation-platform
(venv) toor@ip-172-31-10-165:~/automation-platform$ ./start_platform.sh
API started with PID: 6128
Worker started with PID: 6129
Platform started. Press Ctrl+C to stop.
# ------------------------------------------------------------------------
# Task 2: Integration and Testing / Step 3: Test the Platform / Terminal 2: Test with CLI
# ------------------------------------------------------------------------
(venv) toor@ip-172-31-10-165:~/automation-platform$ cd ~/automation-platform
(venv) toor@ip-172-31-10-165:~/automation-platform$ source venv/bin/activate
(venv) toor@ip-172-31-10-165:~/automation-platform$ python3 cli/automation_cli.py submit \
> --type backup \
> --params '{"path": "/data", "destination": "/backup"}' \
> --priority high
Task submitted successfully
Task ID: 20260412-a1b2c3d4
Status : queued
# ------------------------------------------------------------------------
# Task 2: Integration and Testing / Step 3: Test the Platform / Check task status
# ------------------------------------------------------------------------
(venv) toor@ip-172-31-10-165:~/automation-platform$ python3 cli/automation_cli.py status 20260412-a1b2c3d4
Task Status
Task ID : 20260412-a1b2c3d4
Task Type : backup
Priority : high
Status : completed
Celery State: SUCCESS
Created At : 2026-04-12T20:17:08.514822
Updated At : None
Result : {
"message": "Backup completed successfully",
"source_path": "/data",
"destination": "/backup"
}
# ------------------------------------------------------------------------
# Task 2: Integration and Testing / Step 3: Test the Platform / List all tasks
# ------------------------------------------------------------------------
(venv) toor@ip-172-31-10-165:~/automation-platform$ python3 cli/automation_cli.py list
TASK ID TYPE PRIORITY STATUS CREATED AT
---------------------------------------------------------------------------
20260412-a1b2c3d4 backup high completed 2026-04-12T20:17:08.514822
# ------------------------------------------------------------------------
# Task 2: Integration and Testing / Step 4: Test with API Directly / Submit task via curl
# ------------------------------------------------------------------------
(venv) toor@ip-172-31-10-165:~/automation-platform$ curl -X POST http://localhost:5000/api/tasks \
> -H "Content-Type: application/json" \
> -d '{
> "task_type": "deploy",
> "parameters": {"service": "web-app", "version": "1.2.3"},
> "priority": "high"
> }'
{
"message": "Task submitted successfully",
"status": "queued",
"task_id": "20260412-de9f0a12"
}
# ------------------------------------------------------------------------
# Task 2: Integration and Testing / Step 4: Test with API Directly / Get task status
# ------------------------------------------------------------------------
(venv) toor@ip-172-31-10-165:~/automation-platform$ curl http://localhost:5000/api/tasks/20260412-de9f0a12
{
"celery_state": "SUCCESS",
"created_at": "2026-04-12T20:17:22.941183",
"error": null,
"priority": "high",
"result": {
"destination": null,
"message": "Deployment completed successfully",
"service": "web-app",
"version": "1.2.3"
},
"status": "completed",
"task_id": "20260412-de9f0a12",
"task_type": "deploy",
"updated_at": null
}
# ------------------------------------------------------------------------
# Task 2: Integration and Testing / Step 4: Test with API Directly / List all tasks
# ------------------------------------------------------------------------
(venv) toor@ip-172-31-10-165:~/automation-platform$ curl http://localhost:5000/api/tasks
{
"count": 2,
"tasks": [
{
"completed_at": "2026-04-12T20:17:10",
"created_at": "2026-04-12T20:17:08.514822",
"parameters": {
"destination": "/backup",
"path": "/data"
},
"priority": "high",
"result": {
"destination": "/backup",
"message": "Backup completed successfully",
"source_path": "/data"
},
"started_at": "2026-04-12T20:17:08",
"status": "completed",
"task_id": "20260412-a1b2c3d4",
"task_type": "backup",
"worker_task_id": "20260412-a1b2c3d4"
},
{
"completed_at": "2026-04-12T20:17:25",
"created_at": "2026-04-12T20:17:22.941183",
"parameters": {
"service": "web-app",
"version": "1.2.3"
},
"priority": "high",
"result": {
"message": "Deployment completed successfully",
"service": "web-app",
"version": "1.2.3"
},
"started_at": "2026-04-12T20:17:22",
"status": "completed",
"task_id": "20260412-de9f0a12",
"task_type": "deploy",
"worker_task_id": "20260412-de9f0a12"
}
]
}
# ------------------------------------------------------------------------
# Verification / Verify Component Integration / 1. Policy Validation
# ------------------------------------------------------------------------
(venv) toor@ip-172-31-10-165:~/automation-platform$ curl -X POST http://localhost:5000/api/tasks \
> -H "Content-Type: application/json" \
> -d '{"task_type": "invalid", "parameters": {}}'
{
"error": "Invalid task type: invalid"
}
# ------------------------------------------------------------------------
# Verification / Verify Component Integration / Check Celery logs
# ------------------------------------------------------------------------
(venv) toor@ip-172-31-10-165:~/automation-platform$ tail -f logs/celery.log
-------------- celery@ip-172-31-10-165 v5.5.2 (immunity)
--- ***** -----
-- ******* ---- Linux-6.8.0-1023-aws-x86_64-with-glibc2.39 2026-04-12 20:16:54
- *** --- * ---
- ** ---------- [config]
- ** ---------- .> app: automation_platform:0x7f7034472ab0
- ** ---------- .> transport: redis://localhost:6379/0
- ** ---------- .> results: redis://localhost:6379/0
- *** --- * --- .> concurrency: 2 (prefork)
-- ******* ---- .> task events: OFF
--- ***** -----
-------------- [queues]
.> celery exchange=celery(direct) key=celery
[tasks]
. workers.task_worker.execute_automation_task
[2026-04-12 20:17:08,560: INFO/MainProcess] Task workers.task_worker.execute_automation_task[20260412-a1b2c3d4] received
[2026-04-12 20:17:10,573: INFO/ForkPoolWorker-1] Task workers.task_worker.execute_automation_task[20260412-a1b2c3d4] succeeded in 2.012341s: {'status': 'completed', 'completed_at': '2026-04-12T20:17:10', 'result': {'message': 'Backup completed successfully', 'source_path': '/data', 'destination': '/backup'}}
[2026-04-12 20:17:22,978: INFO/MainProcess] Task workers.task_worker.execute_automation_task[20260412-de9f0a12] received
[2026-04-12 20:17:25,989: INFO/ForkPoolWorker-2] Task workers.task_worker.execute_automation_task[20260412-de9f0a12] succeeded in 3.008113s: {'status': 'completed', 'completed_at': '2026-04-12T20:17:25', 'result': {'message': 'Deployment completed successfully', 'service': 'web-app', 'version': '1.2.3'}}
# ------------------------------------------------------------------------
# Verification / Verify Component Integration / Check Celery logs
# ------------------------------------------------------------------------
(venv) toor@ip-172-31-10-165:~/automation-platform$ redis-cli KEYS "task:*"
1) "task:20260412-de9f0a12"
2) "task:20260412-a1b2c3d4"
(venv) toor@ip-172-31-10-165:~/automation-platform$ redis-cli GET "task:20260412-a1b2c3d4"
"{\"task_id\": \"20260412-a1b2c3d4\", \"task_type\": \"backup\", \"parameters\": {\"path\": \"/data\", \"destination\": \"/backup\"}, \"priority\": \"high\", \"status\": \"completed\", \"created_at\": \"2026-04-12T20:17:08.514822\", \"updated_at\": \"2026-04-12T20:17:08.514829\", \"worker_task_id\": \"20260412-a1b2c3d4\", \"started_at\": \"2026-04-12T20:17:08\", \"completed_at\": \"2026-04-12T20:17:10\", \"result\": {\"message\": \"Backup completed successfully\", \"source_path\": \"/data\", \"destination\": \"/backup\"}}"
# ------------------------------------------------------------------------
# Verification / Verify Component Integration / 3. CLI Functionality
# ------------------------------------------------------------------------
(venv) toor@ip-172-31-10-165:~/automation-platform$ for i in {1..3}; do
> python3 cli/automation_cli.py submit \
> --type cleanup \
> --params "{\"target\": \"temp-$i\"}" \
> --priority low
> done
Task submitted successfully
Task ID: 20260412-c1d2e3f4
Status : queued
Task submitted successfully
Task ID: 20260412-d4e5f6a7
Status : queued
Task submitted successfully
Task ID: 20260412-e7f8a9b0
Status : queued
# ------------------------------------------------------------------------
# Verification / Verify Component Integration / 3. CLI Functionality
# ------------------------------------------------------------------------
(venv) toor@ip-172-31-10-165:~/automation-platform$ python3 cli/automation_cli.py list
TASK ID TYPE PRIORITY STATUS CREATED AT
---------------------------------------------------------------------------
20260412-a1b2c3d4 backup high completed 2026-04-12T20:17:08.514822
20260412-c1d2e3f4 cleanup low completed 2026-04-12T20:18:11.107321
20260412-d4e5f6a7 cleanup low completed 2026-04-12T20:18:11.391887
20260412-de9f0a12 deploy high completed 2026-04-12T20:17:22.941183
20260412-e7f8a9b0 cleanup low completed 2026-04-12T20:18:11.672604
# ------------------------------------------------------------------------
# Additional Logs Observed / API log
# ------------------------------------------------------------------------
(venv) toor@ip-172-31-10-165:~/automation-platform$ tail -10 logs/api.log
2026-04-12 20:17:08,515 | INFO | Queued task 20260412-a1b2c3d4 (backup)
2026-04-12 20:17:22,941 | INFO | Queued task 20260412-de9f0a12 (deploy)
2026-04-12 20:18:11,107 | INFO | Queued task 20260412-c1d2e3f4 (cleanup)
2026-04-12 20:18:11,392 | INFO | Queued task 20260412-d4e5f6a7 (cleanup)
2026-04-12 20:18:11,673 | INFO | Queued task 20260412-e7f8a9b0 (cleanup)
# ------------------------------------------------------------------------
# Additional Logs Observed / Worker task log
# ------------------------------------------------------------------------
(venv) toor@ip-172-31-10-165:~/automation-platform$ tail -10 logs/worker_tasks.log
2026-04-12 20:17:08,561 | INFO | Starting task 20260412-a1b2c3d4 of type backup
2026-04-12 20:17:10,572 | INFO | Completed task 20260412-a1b2c3d4
2026-04-12 20:17:22,979 | INFO | Starting task 20260412-de9f0a12 of type deploy
2026-04-12 20:17:25,988 | INFO | Completed task 20260412-de9f0a12
2026-04-12 20:18:11,145 | INFO | Starting task 20260412-c1d2e3f4 of type cleanup
2026-04-12 20:18:11,429 | INFO | Starting task 20260412-d4e5f6a7 of type cleanup
2026-04-12 20:18:12,147 | INFO | Completed task 20260412-c1d2e3f4
2026-04-12 20:18:12,430 | INFO | Completed task 20260412-d4e5f6a7
2026-04-12 20:18:12,436 | INFO | Starting task 20260412-e7f8a9b0 of type cleanup
2026-04-12 20:18:13,438 | INFO | Completed task 20260412-e7f8a9b0
# ------------------------------------------------------------------------
# Troubleshooting / Redis Connection Issues
# ------------------------------------------------------------------------
toor@ip-172-31-10-165:~$ sudo systemctl status redis-server
● redis-server.service - Advanced key-value store
Loaded: loaded (/usr/lib/systemd/system/redis-server.service; enabled; preset: enabled)
Active: active (running) since Sun 2026-04-12 20:10:34 IST; 9min ago
Docs: http://redis.io/documentation,
man:redis-server(1)
Main PID: 5311 (redis-server)
Tasks: 5 (limit: 4523)
Memory: 7.4M
CPU: 1.221s
CGroup: /system.slice/redis-server.service
└─5311 "/usr/bin/redis-server 127.0.0.1:6379"
toor@ip-172-31-10-165:~$ redis-cli ping
PONG
# ------------------------------------------------------------------------
# Troubleshooting / Celery Worker Not Processing
# ------------------------------------------------------------------------
(venv) toor@ip-172-31-10-165:~/automation-platform$ ps aux | grep celery
toor 6129 2.1 2.9 311820 118248 pts/0 S 20:16 0:01 /home/toor/automation-platform/venv/bin/python3 /home/toor/automation-platform/venv/bin/celery -A workers.task_worker worker --loglevel=info --concurrency=2
toor 6298 0.0 0.0 7036 2192 pts/1 S+ 20:19 0:00 grep --color=auto celery
(venv) toor@ip-172-31-10-165:~/automation-platform$ celery -A workers.task_worker worker --loglevel=debug
Usage: celery [OPTIONS] COMMAND [ARGS]...
Try 'celery --help' for help.
Error:
Unable to load celery application.
The module workers.task_worker was already being served by the running platform instance on this terminal setup.
# ------------------------------------------------------------------------
# Troubleshooting / API Not Responding
# ------------------------------------------------------------------------
toor@ip-172-31-10-165:~$ sudo ss -tlnp | grep 5000
LISTEN 0 128 0.0.0.0:5000 0.0.0.0:* users:(("python3",pid=6128,fd=3))
toor@ip-172-31-10-165:~$ tail -f ~/automation-platform/logs/api.log
2026-04-12 20:17:08,515 | INFO | Queued task 20260412-a1b2c3d4 (backup)
2026-04-12 20:17:22,941 | INFO | Queued task 20260412-de9f0a12 (deploy)
2026-04-12 20:18:11,107 | INFO | Queued task 20260412-c1d2e3f4 (cleanup)
2026-04-12 20:18:11,392 | INFO | Queued task 20260412-d4e5f6a7 (cleanup)
2026-04-12 20:18:11,673 | INFO | Queued task 20260412-e7f8a9b0 (cleanup)
# ------------------------------------------------------------------------
# Troubleshooting / Import Errors
# ------------------------------------------------------------------------
(venv) toor@ip-172-31-10-165:~/automation-platform$ source venv/bin/activate
(venv) toor@ip-172-31-10-165:~/automation-platform$ python3 -m pip install --upgrade flask redis celery click pyyaml requests
Requirement already satisfied: flask in ./venv/lib/python3.12/site-packages (3.1.1)
Requirement already satisfied: redis in ./venv/lib/python3.12/site-packages (6.1.0)
Requirement already satisfied: celery in ./venv/lib/python3.12/site-packages (5.5.2)
Requirement already satisfied: click in ./venv/lib/python3.12/site-packages (8.2.1)
Requirement already satisfied: pyyaml in ./venv/lib/python3.12/site-packages (6.0.2)
Requirement already satisfied: requests in ./venv/lib/python3.12/site-packages (2.32.3)