@@ -1297,3 +1297,175 @@ func TestDivideChangelogsIntoEachPackages(t *testing.T) {
1297
1297
}
1298
1298
1299
1299
}
1300
+
1301
+ func TestParseYumPS (t * testing.T ) {
1302
+ r := newRedhat (config.ServerInfo {})
1303
+ r .Distro = config.Distro {Family : "centos" }
1304
+ r .Packages = models .NewPackages (
1305
+ models.Package {
1306
+ Name : "python" ,
1307
+ Version : "2.7.5" ,
1308
+ Release : "34.el7" ,
1309
+ Arch : "x86_64" ,
1310
+ },
1311
+ models.Package {
1312
+ Name : "util-linux" ,
1313
+ Version : "2.23.2" ,
1314
+ Release : "26.el7" ,
1315
+ Arch : "x86_64" ,
1316
+ },
1317
+ models.Package {
1318
+ Name : "wpa_supplicant" ,
1319
+ Version : "1:2.0" ,
1320
+ Release : "17.el7_1" ,
1321
+ Arch : "x86_64" ,
1322
+ },
1323
+ models.Package {
1324
+ Name : "yum" ,
1325
+ Version : "3.4.3" ,
1326
+ Release : "150.el7.centos" ,
1327
+ Arch : "noarch" ,
1328
+ },
1329
+ )
1330
+
1331
+ var tests = []struct {
1332
+ in string
1333
+ out models.Packages
1334
+ }{
1335
+ {
1336
+ ` pid proc CPU RSS State uptime
1337
+ python-2.7.5-34.el7.x86_64 Upgrade 2.7.5-48.el7.x86_64
1338
+ 741 tuned 1:54 16 MB Sleeping: 14 day(s) 21:52:32
1339
+ 38755 yum 0:00 42 MB Running: 00:00
1340
+ util-linux-2.23.2-26.el7.x86_64 Upgrade 2.23.2-33.el7_3.2.x86_64
1341
+ 626 agetty 0:00 848 kB Sleeping: 14 day(s) 21:52:37
1342
+ 628 agetty 0:00 848 kB Sleeping: 14 day(s) 21:52:37
1343
+ 1:wpa_supplicant-2.0-17.el7_1.x86_64 Upgrade 1:2.0-21.el7_3.x86_64
1344
+ 638 wpa_supplicant 0:00 2.6 MB Sleeping: 14 day(s) 21:52:37
1345
+ yum-3.4.3-150.el7.centos.noarch
1346
+ 38755 yum 0:00 42 MB Running: 00:00
1347
+ ps
1348
+ ` ,
1349
+ models .NewPackages (
1350
+ models.Package {
1351
+ Name : "python" ,
1352
+ Version : "2.7.5" ,
1353
+ Release : "34.el7" ,
1354
+ Arch : "x86_64" ,
1355
+ // NewVersion: "2.7.5-",
1356
+ // NewRelease: "48.el7.x86_64",
1357
+ AffectedProcs : []models.AffectedProc {
1358
+ {
1359
+ PID : "741" ,
1360
+ ProcName : "tuned" ,
1361
+ CPU : "1:54" ,
1362
+ RSS : "16 MB" ,
1363
+ State : "Sleeping" ,
1364
+ Uptime : "14 day(s) 21:52:32" ,
1365
+ },
1366
+ {
1367
+ PID : "38755" ,
1368
+ ProcName : "yum" ,
1369
+ CPU : "0:00" ,
1370
+ RSS : "42 MB" ,
1371
+ State : "Running" ,
1372
+ Uptime : "00:00" ,
1373
+ },
1374
+ },
1375
+ },
1376
+ models.Package {
1377
+ Name : "util-linux" ,
1378
+ Version : "2.23.2" ,
1379
+ Release : "26.el7" ,
1380
+ Arch : "x86_64" ,
1381
+ // NewVersion: "2.7.5",
1382
+ // NewRelease: "48.el7.x86_64",
1383
+ AffectedProcs : []models.AffectedProc {
1384
+ {
1385
+ PID : "626" ,
1386
+ ProcName : "agetty" ,
1387
+ CPU : "0:00" ,
1388
+ RSS : "848 kB" ,
1389
+ State : "Sleeping" ,
1390
+ Uptime : "14 day(s) 21:52:37" ,
1391
+ },
1392
+ {
1393
+ PID : "628" ,
1394
+ ProcName : "agetty" ,
1395
+ CPU : "0:00" ,
1396
+ RSS : "848 kB" ,
1397
+ State : "Sleeping" ,
1398
+ Uptime : "14 day(s) 21:52:37" ,
1399
+ },
1400
+ },
1401
+ },
1402
+ models.Package {
1403
+ Name : "wpa_supplicant" ,
1404
+ Version : "1:2.0" ,
1405
+ Release : "17.el7_1" ,
1406
+ Arch : "x86_64" ,
1407
+ // NewVersion: "1:2.0",
1408
+ // NewRelease: "21.el7_3.x86_64",
1409
+ AffectedProcs : []models.AffectedProc {
1410
+ {
1411
+ PID : "638" ,
1412
+ ProcName : "wpa_supplicant" ,
1413
+ CPU : "0:00" ,
1414
+ RSS : "2.6 MB" ,
1415
+ State : "Sleeping" ,
1416
+ Uptime : "14 day(s) 21:52:37" ,
1417
+ },
1418
+ },
1419
+ },
1420
+ ),
1421
+ },
1422
+ {
1423
+ ` pid proc CPU RSS State uptime
1424
+ acpid-2.0.19-6.7.amzn1.x86_64
1425
+ 2388 acpid 0:00 1.4 MB Sleeping: 21:08
1426
+ at-3.1.10-48.15.amzn1.x86_64
1427
+ 2546 atd 0:00 164 kB Sleeping: 21:06
1428
+ cronie-anacron-1.4.4-15.8.amzn1.x86_64
1429
+ 2637 anacron 0:00 1.5 MB Sleeping: 13:14
1430
+ 12:dhclient-4.1.1-51.P1.26.amzn1.x86_64
1431
+ 2061 dhclient 0:00 1.4 MB Sleeping: 21:10
1432
+ 2193 dhclient 0:00 2.1 MB Sleeping: 21:08
1433
+ mingetty-1.08-5.9.amzn1.x86_64
1434
+ 2572 mingetty 0:00 1.4 MB Sleeping: 21:06
1435
+ 2575 mingetty 0:00 1.4 MB Sleeping: 21:06
1436
+ 2578 mingetty 0:00 1.5 MB Sleeping: 21:06
1437
+ 2580 mingetty 0:00 1.4 MB Sleeping: 21:06
1438
+ 2582 mingetty 0:00 1.4 MB Sleeping: 21:06
1439
+ 2584 mingetty 0:00 1.4 MB Sleeping: 21:06
1440
+ openssh-server-6.6.1p1-33.66.amzn1.x86_64
1441
+ 2481 sshd 0:00 2.6 MB Sleeping: 21:07
1442
+ python27-2.7.12-2.120.amzn1.x86_64
1443
+ 2649 yum 0:00 35 MB Running: 00:01
1444
+ rsyslog-5.8.10-9.26.amzn1.x86_64
1445
+ 2261 rsyslogd 0:00 2.6 MB Sleeping: 21:08
1446
+ udev-173-4.13.amzn1.x86_64
1447
+ 1528 udevd 0:00 2.5 MB Sleeping: 21:12
1448
+ 1652 udevd 0:00 2.1 MB Sleeping: 21:12
1449
+ 1653 udevd 0:00 2.0 MB Sleeping: 21:12
1450
+ upstart-0.6.5-13.3.13.amzn1.x86_64
1451
+ 1 init 0:00 2.5 MB Sleeping: 21:13
1452
+ util-linux-2.23.2-33.28.amzn1.x86_64
1453
+ 2569 agetty 0:00 1.6 MB Sleeping: 21:06
1454
+ yum-3.4.3-150.70.amzn1.noarch
1455
+ 2649 yum 0:00 35 MB Running: 00:01
1456
+ ` ,
1457
+ models.Packages {},
1458
+ },
1459
+ }
1460
+
1461
+ for _ , tt := range tests {
1462
+ packages := r .parseYumPS (tt .in )
1463
+ for name , ePack := range tt .out {
1464
+ if ! reflect .DeepEqual (ePack , packages [name ]) {
1465
+ e := pp .Sprintf ("%v" , ePack )
1466
+ a := pp .Sprintf ("%v" , packages [name ])
1467
+ t .Errorf ("expected %s, actual %s" , e , a )
1468
+ }
1469
+ }
1470
+ }
1471
+ }
0 commit comments