forked from LiXi-storage/barreleye
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild_barrele.py
905 lines (812 loc) · 35.6 KB
/
build_barrele.py
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
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
"""
Library for building Barreleye
"""
import os
import stat
from pycoral import ssh_host
from pycoral import clog
from pycoral import cmd_general
from pybuild import build_common
from pybarreleye import barrele_constant
PACAKGE_URL_DICT = {}
# The URL of Collectd tarball
COLLECTD_URL = ("https://github.com/LiXi-storage/collectd/releases/download/"
"collectd-5.12.0.brl2/collectd-5.12.0.brl2.tar.bz2")
# The sha1sum of Collectd tarball. Need to update together with
# COLLECTD_URL
COLLECTD_SHA1SUM = "9fb8be9d7c0bf7c84b93ef5bf441d393b081e7d9"
PACAKGE_URL_DICT["collectd"] = COLLECTD_URL
# The RPM names of Collectd to check
COLLECTD_RPM_NAMES = ["collectd", "collectd-disk", "collectd-filedata",
"collectd-sensors", "collectd-ssh",
"libcollectdclient"]
# The URL of Influxdb RPM for x86_64
INFLUXDB_RPM_URL_X86_64 = "https://dl.influxdata.com/influxdb/releases/influxdb-1.8.4.x86_64.rpm"
# The sha1sum of Influxdb RPM for x86_64. Need to update together with
# INFLUXDB_RPM_URL_X86_64
INFLUXDB_RPM_SHA1SUM_X86_64 = "26832ce558b8a79beb3bfda1799eb7394d5c13cd"
PACAKGE_URL_DICT["influxdb"] = INFLUXDB_RPM_URL_X86_64
# The URL of Grafana RPM for x86_64
GRAFANA_RPM_URL_X86_64 = "https://dl.grafana.com/oss/release/grafana-7.3.7-1.x86_64.rpm"
# The sha1sum of Grafana RPM for x86_64. Need to update together with
# GRAFANA_RPM_URL_X86_64
GRAFANA_RPM_SHA1SUM_X86_64 = "bf5814ac0c756fbe85611bd355acce49ff8d5f44"
# The URL of Grafana RPM for x86_64
GRAFANA_RPM_URL_AARCH64 = "https://dl.grafana.com/oss/release/grafana-7.3.7-1.aarch64.rpm"
# The sha1sum of Grafana RPM for ARM. Need to update together with
# GRAFANA_RPM_URL_X86_64
GRAFANA_RPM_SHA1SUM_AARCH64 = "8356a324acefcd788cb0711b9bc5bd8689774be1"
PACAKGE_URL_DICT["grafana"] = GRAFANA_RPM_URL_X86_64
# The URL of Grafana status panel plugin
GRAFANA_STATUS_PANEL_URL = ("https://github.com/Vonage/Grafana_Status_panel/"
"archive/v1.0.10.zip")
# URL does not have expected fname, specify explictly here.
GRAFANA_STATUS_PANEL_FNAME = barrele_constant.GRAFANA_STATUS_PANEL + ".zip"
# The unzipped file name is not GRAFANA_STATUS_PANEL, need to rename to
# GRAFANA_STATUS_PANEL
GRAFANA_STATUS_PANEL_UNZIPPED_FNAME = "Grafana_Status_panel-1.0.10"
# The sha1sum of Grafana status panel plugin. Need to update together with
# GRAFANA_STATUS_PANEL_URL
GRAFANASTATUS_PANEL_SHA1SUM = "e46fb5cb8f30d9ea743e0fda67402c0504a39690"
PACAKGE_URL_DICT["grafana_status_panel"] = GRAFANA_STATUS_PANEL_URL
# The URL of Grafana piechart panel plugin
GRAFANA_PIECHART_PANEL_URL = ("https://github.com/grafana/piechart-panel/"
"releases/download/v1.6.1/"
"grafana-piechart-panel-1.6.1.zip")
# The sha1sum of Grafana piechart panel plugin. Need to update together with
# GRAFANA_PIECHART_PANEL_URL
GRAFANA_PIECHART_PANEL_SHA1SUM = "2b3c33afd865af4575d87a83e3d45e61acf8273a"
PACAKGE_URL_DICT["grafana_piechart_panel"] = GRAFANA_PIECHART_PANEL_URL
# RPMs needed by building collectd
COLLECTD_BUILD_DEPENDENT_RPMS = ["curl-devel",
"ganglia-devel",
"gtk2-devel",
"iptables-devel",
"iproute-devel",
"libatasmart-devel",
"libdbi-devel",
"libcap-devel",
"libesmtp-devel",
"libgcrypt-devel",
"libmemcached-devel",
"libmicrohttpd-devel",
"libmnl-devel",
"libnotify-devel",
"libpcap-devel",
"libssh2-devel",
"libxml2-devel",
"libvirt-devel",
"lm_sensors-devel",
"lua-devel",
"mosquitto-devel",
"net-snmp-devel",
"OpenIPMI-devel",
"openldap-devel",
"perl-ExtUtils-Embed",
"postgresql-devel",
"python2-devel",
"qpid-proton-c-devel",
"riemann-c-client-devel",
"rrdtool-devel",
"systemd-devel", # libudev.h
"uthash-devel",
"xfsprogs-devel",
"yajl-devel",
"zeromq-devel"]
# RPMs needed by building barreleye
BARRELEYE_BUILD_DEPENDENT_RPMS = COLLECTD_BUILD_DEPENDENT_RPMS
BARRELEYE_BUILD_DEPENDENT_PIPS = ["requests", "python-slugify"]
def get_collectd_rpm_suffix(distro_number, target_cpu,
collectd_version_release):
"""
Return the suffix of Collectd RPMs.
The suffix starts from "-", e.g.
"-5.11.0.gadf6f83.lustre-1.el7.x86_64.rpm"
"""
return ("-%s.el%s.%s.rpm" %
(collectd_version_release, distro_number, target_cpu))
def check_collectd_rpms_integrity(log, rpm_fnames, distro_number, target_cpu,
collectd_version_release, quiet=True):
"""
Check whether the existing RPMs has all expected Collectd RPMs
"""
suffix = get_collectd_rpm_suffix(distro_number, target_cpu,
collectd_version_release)
for collect_rpm_name in COLLECTD_RPM_NAMES:
collect_rpm_full = collect_rpm_name + suffix
if collect_rpm_full not in rpm_fnames:
if not quiet:
log.cl_error("RPM [%s] does not exist",
collect_rpm_full)
else:
log.cl_debug("RPM [%s] does not exist",
collect_rpm_full)
return -1
return 0
def get_and_clean_collectd_rpms(log, host, packages_dir,
rpm_fnames, distro_number, target_cpu,
collectd_version_release,
expect_clean=False):
"""
Return a list of Collectd RPMs under a directory.
If there are other version of Collectd RPMs, remove them.
"""
# pylint: disable=too-many-locals
suffix = get_collectd_rpm_suffix(distro_number, target_cpu,
collectd_version_release)
prefixes = ["collectd", "libcollectdclient"]
collectd_fnames = []
for rpm_fname in rpm_fnames:
found = False
for prefix in prefixes:
if rpm_fname.startswith(prefix):
found = True
if not found:
continue
if not rpm_fname.endswith(suffix):
if expect_clean:
log.cl_error("Collectd RPM [%s] has different suffix, "
"expected [%s]",
rpm_fname, suffix)
return None
log.cl_info("Collectd RPM [%s] has different suffix, "
"expected [%s], removing",
rpm_fname, suffix)
fpath = packages_dir + "/" + rpm_fname
command = ("rm -f %s" % (fpath))
retval = host.sh_run(command)
if retval.cr_exit_status:
log.cl_error("failed to run command [%s] on host [%s], "
"ret = [%d], stdout = [%s], stderr = [%s]",
command,
host.sh_hostname,
retval.cr_exit_status,
retval.cr_stdout,
retval.cr_stderr)
return None
continue
collectd_fnames.append(rpm_fname)
return collectd_fnames
def remove_collectd_rpms(log, host, packages_dir):
"""
Remove old Collectd RPMs
"""
patterns = ["collectd-*", "libcollectdclient-*"]
for pattern in patterns:
command = "rm -f %s/%s" % (packages_dir, pattern)
retval = host.sh_run(log, command)
if retval.cr_exit_status:
log.cl_error("failed to run command [%s] on host [%s], "
"ret = [%d], stdout = [%s], stderr = [%s]",
command,
host.sh_hostname,
retval.cr_exit_status,
retval.cr_stdout,
retval.cr_stderr)
return -1
return 0
def get_collectd_version(log, host, collectd_src_dir):
"""
Return the Collectd version.
This assumes the collectd.spec has following line:
Version: {?rev}
"""
command = (r"cd %s && grep Version contrib/redhat/collectd.spec | "
r"grep -v \# | awk '{print $2}'" %
collectd_src_dir)
retval = host.sh_run(log, command)
if retval.cr_exit_status:
log.cl_error("failed to run command [%s] on host [%s], "
"ret = [%d], stdout = [%s], stderr = [%s]",
command,
host.sh_hostname,
retval.cr_exit_status,
retval.cr_stdout,
retval.cr_stderr)
return None
collectd_version_string = retval.cr_stdout.strip()
if collectd_version_string != "%{?rev}":
log.cl_error("version string [%s] in dir [%s] on host [%s] is "
"unexpected", collectd_version_string, collectd_src_dir,
host.sh_hostname)
log.cl_error("dir [%s] on host is not a Barreleye release of Collectd")
return None
command = "cd %s && ./version-gen.sh" % collectd_src_dir
retval = host.sh_run(log, command)
if retval.cr_exit_status:
log.cl_error("failed to run command [%s] on host [%s], "
"ret = [%d], stdout = [%s], stderr = [%s]",
command,
host.sh_hostname,
retval.cr_exit_status,
retval.cr_stdout,
retval.cr_stderr)
return None
collectd_version = retval.cr_stdout.strip()
return collectd_version
def get_collectd_version_release(log, host, collectd_src_dir,
collectd_version):
"""
Return the Collectd version
"""
command = (r"cd %s && grep Release contrib/redhat/collectd.spec | "
r"grep -v \# | awk '{print $2}'" %
collectd_src_dir)
retval = host.sh_run(log, command)
if retval.cr_exit_status:
log.cl_error("failed to run command [%s] on host [%s], "
"ret = [%d], stdout = [%s], stderr = [%s]",
command,
host.sh_hostname,
retval.cr_exit_status,
retval.cr_stdout,
retval.cr_stderr)
return None
collectd_release_string = retval.cr_stdout.strip()
collectd_release = collectd_release_string.replace('%{?dist}', '')
collectd_version_release = collectd_version + "-" + collectd_release
return collectd_version_release
def build_collectd_rpms(log, host, target_cpu, packages_dir,
collectd_src_dir, tarball_fpath, distro_number,
collectd_version):
"""
Build Collectd RPMs on a host
"""
command = ("cd %s && mkdir {BUILD,RPMS,SOURCES,SRPMS} && "
"cp %s SOURCES" %
(collectd_src_dir, tarball_fpath))
retval = host.sh_run(log, command)
if retval.cr_exit_status:
log.cl_error("failed to run command [%s] on host [%s], "
"ret = [%d], stdout = [%s], stderr = [%s]",
command,
host.sh_hostname,
retval.cr_exit_status,
retval.cr_stdout,
retval.cr_stderr)
return -1
command = ('cd %s && '
'rpmbuild -ba --with write_tsdb --with nfs --without java '
'--without amqp --without gmond --without nut --without pinba '
'--without ping --without varnish --without dpdkstat '
'--without turbostat --without redis --without write_redis '
'--without gps --without lvm --without modbus --without mysql '
'--without ime '
'--define "_topdir %s" '
'--define="rev %s" '
'--define="dist .el%s" '
'contrib/redhat/collectd.spec' %
(collectd_src_dir, collectd_src_dir,
collectd_version, distro_number))
log.cl_info("running command [%s] on host [%s]",
command, host.sh_hostname)
retval = host.sh_run(log, command)
if retval.cr_exit_status:
log.cl_error("failed to run command [%s] on host [%s], "
"ret = [%d], stdout = [%s], stderr = [%s]",
command,
host.sh_hostname,
retval.cr_exit_status,
retval.cr_stdout,
retval.cr_stderr)
return -1
generated_collectd_rpm_dir = ("%s/RPMS/%s" %
(collectd_src_dir, target_cpu))
command = ("mv %s/* %s" %
(generated_collectd_rpm_dir, packages_dir))
retval = host.sh_run(log, command)
if retval.cr_exit_status:
log.cl_error("failed to run command [%s] on host [%s], "
"ret = [%d], stdout = [%s], stderr = [%s]",
command,
host.sh_hostname,
retval.cr_exit_status,
retval.cr_stdout,
retval.cr_stderr)
return -1
return 0
def collectd_build_and_check(log, host, target_cpu, packages_dir,
collectd_src_dir, collectd_version,
collectd_version_release,
tarball_fpath, extra_package_fnames):
"""
Check and build Collectd RPMs
"""
existing_rpm_fnames = host.sh_get_dir_fnames(log, packages_dir)
if existing_rpm_fnames is None:
log.cl_error("failed to get fnames under dir [%s] on host [%s]",
packages_dir,
host.sh_hostname)
return -1
distro = host.sh_distro(log)
if distro == ssh_host.DISTRO_RHEL7:
distro_number = "7"
elif distro == ssh_host.DISTRO_RHEL8:
distro_number = "8"
else:
log.cl_error("build on distro [%s] is not supported yet", distro)
return -1
ret = check_collectd_rpms_integrity(log, existing_rpm_fnames,
distro_number, target_cpu,
collectd_version_release)
if ret == 0:
log.cl_debug("Collectd RPMs already exist")
collectd_rpm_fnames = get_and_clean_collectd_rpms(log, host,
packages_dir,
existing_rpm_fnames,
distro_number,
target_cpu,
collectd_version_release)
if collectd_rpm_fnames is None:
log.cl_error("failed to get the Collectd RPM names")
return -1
extra_package_fnames += collectd_rpm_fnames
return 0
log.cl_debug("building Collectd RPMs")
ret = remove_collectd_rpms(log, host, packages_dir)
if ret:
log.cl_error("failed to remove old Collectd RPMs")
return -1
ret = build_collectd_rpms(log, host, target_cpu, packages_dir,
collectd_src_dir, tarball_fpath, distro_number,
collectd_version)
if ret:
log.cl_error("failed to build Collectd RPMs from src [%s]",
collectd_src_dir)
return -1
existing_rpm_fnames = host.sh_get_dir_fnames(log, packages_dir)
if existing_rpm_fnames is None:
log.cl_error("failed to get fnames under dir [%s] on host [%s]",
packages_dir,
host.sh_hostname)
return -1
ret = check_collectd_rpms_integrity(log, existing_rpm_fnames,
distro_number, target_cpu,
collectd_version_release,
quiet=False)
if ret:
log.cl_error("generated Collectd RPMs is not complete")
return -1
collectd_rpm_fnames = get_and_clean_collectd_rpms(log, host,
packages_dir,
existing_rpm_fnames,
distro_number,
target_cpu,
collectd_version_release,
expect_clean=True)
if collectd_rpm_fnames is None:
log.cl_error("failed to get the Collectd RPM names")
return -1
extra_package_fnames += collectd_rpm_fnames
return 0
def build_collectd_tarball(log, workspace, host, target_cpu, packages_dir,
tarball_fpath, extra_package_fnames,
known_collectd_version=None):
"""
Untar the tarball, check the target version, check the cache, and build
if cache is invalid.
"""
# pylint: disable=too-many-locals
if not tarball_fpath.endswith(".tar.bz2"):
log.cl_error("Collectd tarball [%s] does not end with [.tar.bz2]",
tarball_fpath)
return -1
fname = os.path.basename(tarball_fpath)
dirname = fname[:-8]
collectd_build_dir = workspace + "/collectd_build"
command = "mkdir -p %s" % collectd_build_dir
retval = host.sh_run(log, command)
if retval.cr_exit_status:
log.cl_error("failed to run command [%s] on host [%s], "
"ret = [%d], stdout = [%s], stderr = [%s]",
command,
host.sh_hostname,
retval.cr_exit_status,
retval.cr_stdout,
retval.cr_stderr)
return -1
command = "tar xfj %s -C %s" % (tarball_fpath, collectd_build_dir)
retval = host.sh_run(log, command)
if retval.cr_exit_status:
log.cl_error("failed to run command [%s] on host [%s], "
"ret = [%d], stdout = [%s], stderr = [%s]",
command,
host.sh_hostname,
retval.cr_exit_status,
retval.cr_stdout,
retval.cr_stderr)
return -1
collectd_src_dir = collectd_build_dir + "/" + dirname
ret = host.sh_path_isdir(log, collectd_src_dir)
if ret < 0:
log.cl_error("failed to check whether path [%s] is a dir on host [%s]",
collectd_src_dir, host.sh_hostname)
return -1
if ret == 0:
log.cl_error("path [%s] is not a Collectd source dir on host [%s]",
collectd_src_dir, host.sh_hostname)
return -1
if known_collectd_version is None:
collectd_version = get_collectd_version(log, host, collectd_src_dir)
if collectd_version is None:
log.cl_error("failed to get Collectd version of src dir [%s] on "
"host [%s]", collectd_src_dir, host.sh_hostname)
return -1
else:
collectd_version = known_collectd_version
collectd_version_release = get_collectd_version_release(log, host,
collectd_src_dir,
collectd_version)
if collectd_version_release is None:
log.cl_error("failed to get Collectd version release from Collectd "
"source dir")
return -1
ret = collectd_build_and_check(log, host, target_cpu, packages_dir,
collectd_src_dir, collectd_version,
collectd_version_release,
tarball_fpath, extra_package_fnames)
if ret:
log.cl_error("failed to build and check Collectd RPMs")
return -1
return 0
def download_and_build_collectd(log, workspace, host, type_cache, target_cpu,
packages_dir, collectd_url, expected_sha1sum,
extra_package_fnames):
"""
Download Collectd source code tarball and build
"""
log.cl_info("building Collectd RPMs from URL [%s] on host [%s]",
collectd_url, host.sh_hostname)
tarball_fname = os.path.basename(collectd_url)
tarball_fpath = type_cache + "/" + tarball_fname
ret = host.sh_download_file(log, collectd_url, tarball_fpath,
expected_sha1sum)
if ret:
log.cl_error("failed to download Collectd sourcecode tarball")
return -1
ret = build_collectd_tarball(log, workspace, host, target_cpu,
packages_dir, tarball_fpath,
extra_package_fnames)
if ret:
log.cl_error("failed to build Collectd tarball [%s]",
tarball_fpath)
return -1
return 0
def build_collectd_dir(log, workspace, host, target_cpu, packages_dir,
origin_collectd_dir, extra_package_fnames):
"""
Build Collectd from src dir
"""
# pylint: disable=too-many-locals
basename = os.path.basename(origin_collectd_dir)
collectd_dir = workspace + "/" + basename
# Get the Collectd version from the origin Collectd dir. If we get it
# from the tarball generated later, some info like Git tag might be lost.
collectd_version = get_collectd_version(log, host, origin_collectd_dir)
if collectd_version is None:
log.cl_error("failed to get Collectd version of src dir [%s] on "
"host [%s]", origin_collectd_dir, host.sh_hostname)
return -1
command = "cp -a %s %s" % (origin_collectd_dir, workspace)
retval = host.sh_run(log, command)
if retval.cr_exit_status:
log.cl_error("failed to run command [%s] on host [%s], "
"ret = [%d], stdout = [%s], stderr = [%s]",
command,
host.sh_hostname,
retval.cr_exit_status,
retval.cr_stdout,
retval.cr_stderr)
return -1
command = "rm -f %s/collectd-*.tar.bz2" % (collectd_dir)
retval = host.sh_run(log, command)
if retval.cr_exit_status:
log.cl_error("failed to run command [%s] on host [%s], "
"ret = [%d], stdout = [%s], stderr = [%s]",
command,
host.sh_hostname,
retval.cr_exit_status,
retval.cr_stdout,
retval.cr_stderr)
return -1
command = ("cd %s && mkdir -p libltdl/config && sh ./build.sh && "
"./configure && make dist-bzip2" % (collectd_dir))
retval = host.sh_run(log, command)
if retval.cr_exit_status:
log.cl_error("failed to run command [%s] on host [%s], "
"ret = [%d], stdout = [%s], stderr = [%s]",
command,
host.sh_hostname,
retval.cr_exit_status,
retval.cr_stdout,
retval.cr_stderr)
return -1
command = ("cd %s && ls collectd-*.tar.bz2" % (collectd_dir))
retval = host.sh_run(log, command)
if retval.cr_exit_status:
log.cl_error("failed to run command [%s] on host [%s], "
"ret = [%d], stdout = [%s], stderr = [%s]",
command,
host.sh_hostname,
retval.cr_exit_status,
retval.cr_stdout,
retval.cr_stderr)
return -1
collectd_tarballs = retval.cr_stdout.split()
if len(collectd_tarballs) != 1:
log.cl_error("unexpected output of Collectd tarball: [%s]",
retval.cr_stdout)
return -1
collectd_tarball_fname = collectd_tarballs[0]
if (not collectd_tarball_fname.endswith(".tar.bz2") or
len(collectd_tarball_fname) <= 8):
log.cl_error("unexpected Collectd tarball fname [%s] generated "
"from [%s]", collectd_tarball_fname,
origin_collectd_dir)
return -1
collectd_tarball_fpath = collectd_dir + "/" + collectd_tarball_fname
ret = build_collectd_tarball(log, workspace, host, target_cpu, packages_dir,
collectd_tarball_fpath, extra_package_fnames,
known_collectd_version=collectd_version)
if ret:
log.cl_error("failed to build Collectd tarball [%s] on host",
collectd_tarball_fpath)
return -1
return 0
def build_collectd(log, workspace, host, type_cache, target_cpu, packages_dir,
collectd, extra_package_fnames):
"""
Build Collectd
"""
if collectd is None:
return download_and_build_collectd(log, workspace, host, type_cache,
target_cpu, packages_dir, COLLECTD_URL,
COLLECTD_SHA1SUM,
extra_package_fnames)
stat_result = host.sh_stat(log, collectd)
if stat_result is not None:
if stat.S_ISREG(stat_result.st_mode):
log.cl_info("building Collectd RPMs from tarball [%s] on host [%s]",
collectd, host.sh_hostname)
ret = build_collectd_tarball(log, workspace, host, target_cpu,
packages_dir, collectd,
extra_package_fnames)
if ret:
log.cl_error("failed to build Collectd tarball [%s] on host",
collectd)
return -1
elif stat.S_ISDIR(stat_result.st_mode):
log.cl_info("building Collectd RPMs from dir [%s] on host [%s]",
collectd, host.sh_hostname)
ret = build_collectd_dir(log, workspace, host, target_cpu,
packages_dir, collectd,
extra_package_fnames)
if ret:
log.cl_error("failed to build Collectd dir [%s] on host [%s]",
collectd, host.sh_hostname)
return -1
else:
log.cl_error("unexpected file type of Collectd [%s] on host [%s]",
collectd, host.sh_hostname)
return -1
return 0
return download_and_build_collectd(log, workspace, host, type_cache,
target_cpu, packages_dir, collectd, None,
extra_package_fnames)
def download_influxdb_x86_64(log, host, packages_dir, extra_package_fnames):
"""
Build Influxdb for x86_64 platform
"""
url = INFLUXDB_RPM_URL_X86_64
expected_sha1sum = INFLUXDB_RPM_SHA1SUM_X86_64
fname = os.path.basename(url)
fpath = packages_dir + "/" + fname
log.cl_info("downloading Influxdb RPM")
ret = host.sh_download_file(log, url, fpath, expected_sha1sum)
if ret:
log.cl_error("failed to download RPM of Influxdb")
return -1
extra_package_fnames.append(fname)
return 0
def build_influxdb(log, host, target_cpu, packages_dir, extra_package_fnames):
"""
Build Influxdb
"""
if target_cpu == "x86_64":
rc = download_influxdb_x86_64(log, host, packages_dir,
extra_package_fnames)
if rc:
return rc
else:
log.cl_error("unsupported CPU type [%s]", target_cpu)
return -1
return 0
def build_grafana(log, host, target_cpu, packages_dir, extra_package_fnames):
"""
Build Grafana
"""
if target_cpu == "x86_64":
url = GRAFANA_RPM_URL_X86_64
expected_sha1sum = GRAFANA_RPM_SHA1SUM_X86_64
elif target_cpu == "aarch64":
url = GRAFANA_RPM_URL_AARCH64
expected_sha1sum = GRAFANA_RPM_SHA1SUM_AARCH64
else:
log.cl_error("unsupported CPU type [%s]", target_cpu)
return -1
fname = os.path.basename(url)
fpath = packages_dir + "/" + fname
log.cl_info("downloading Grafana RPM")
ret = host.sh_download_file(log, url, fpath, expected_sha1sum)
if ret:
log.cl_error("failed to download RPM of Grafana")
return -1
extra_package_fnames.append(fname)
return 0
def download_grafana_status_panel_plugin(log, host, type_cache, iso_cache,
extra_iso_fnames):
"""
Download and untar Grafana Status Panel plugin
"""
tarball_url = GRAFANA_STATUS_PANEL_URL
tarball_fname = GRAFANA_STATUS_PANEL_FNAME
tarball_fpath = type_cache + "/" + tarball_fname
expected_sha1sum = GRAFANASTATUS_PANEL_SHA1SUM
log.cl_info("downloading Grafana Status Panel plugin")
ret = host.sh_download_file(log, tarball_url, tarball_fpath,
expected_sha1sum,
output_fname=tarball_fname)
if ret:
log.cl_error("failed to download Grafana Status Panel plugin")
return -1
command = ("rm -fr %s/%s && unzip %s -d %s" %
(iso_cache, GRAFANA_STATUS_PANEL_UNZIPPED_FNAME,
tarball_fpath, iso_cache))
retval = host.sh_run(log, command)
if retval.cr_exit_status:
log.cl_error("failed to run command [%s] on host [%s], "
"ret = [%d], stdout = [%s], stderr = [%s]",
command,
host.sh_hostname,
retval.cr_exit_status,
retval.cr_stdout,
retval.cr_stderr)
return -1
# Need to rename
command = ("rm -fr %s/%s && mv %s/%s %s/%s" %
(iso_cache, barrele_constant.GRAFANA_STATUS_PANEL,
iso_cache, GRAFANA_STATUS_PANEL_UNZIPPED_FNAME,
iso_cache, barrele_constant.GRAFANA_STATUS_PANEL))
retval = host.sh_run(log, command)
if retval.cr_exit_status:
log.cl_error("failed to run command [%s] on host [%s], "
"ret = [%d], stdout = [%s], stderr = [%s]",
command,
host.sh_hostname,
retval.cr_exit_status,
retval.cr_stdout,
retval.cr_stderr)
return -1
extra_iso_fnames.append(barrele_constant.GRAFANA_STATUS_PANEL)
return 0
def download_grafana_piechart_panel_plugin(log, host, type_cache, iso_cache,
extra_iso_fnames):
"""
Download and untar Grafana Piechart plugin
"""
tarball_url = GRAFANA_PIECHART_PANEL_URL
tarball_fname = os.path.basename(tarball_url)
tarball_fpath = type_cache + "/" + tarball_fname
expected_sha1sum = GRAFANA_PIECHART_PANEL_SHA1SUM
log.cl_info("downloading Grafana Piechart panel")
ret = host.sh_download_file(log, tarball_url, tarball_fpath,
expected_sha1sum)
if ret:
log.cl_error("failed to download Grafana Piechart panel plugin")
return -1
command = ("rm -fr %s/%s && unzip %s -d %s" %
(iso_cache, barrele_constant.GRAFANA_PIECHART_PANEL,
tarball_fpath, iso_cache))
retval = host.sh_run(log, command)
if retval.cr_exit_status:
log.cl_error("failed to run command [%s] on host [%s], "
"ret = [%d], stdout = [%s], stderr = [%s]",
command,
host.sh_hostname,
retval.cr_exit_status,
retval.cr_stdout,
retval.cr_stderr)
return -1
extra_iso_fnames.append(barrele_constant.GRAFANA_PIECHART_PANEL)
return 0
def build_grafana_plugins(log, host, type_cache, iso_cache, extra_iso_fnames):
"""
Build Grafana plugins
"""
ret = download_grafana_piechart_panel_plugin(log, host, type_cache,
iso_cache, extra_iso_fnames)
if ret:
log.cl_error("failed to download Grafana Piechart Panel plugin")
return -1
ret = download_grafana_status_panel_plugin(log, host, type_cache,
iso_cache, extra_iso_fnames)
if ret:
log.cl_error("failed to download Grafana Status Panel plugin")
return -1
return 0
def build_barreleye(log, workspace, host, type_cache, target_cpu, iso_cache,
packages_dir, collectd, extra_iso_fnames,
extra_package_fnames, extra_rpm_names):
"""
Build barreleye
"""
rc = build_collectd(log, workspace, host, type_cache, target_cpu,
packages_dir, collectd, extra_package_fnames)
if rc:
log.cl_error("failed to build Collectd RPMs")
return -1
rc = build_grafana_plugins(log, host, type_cache, iso_cache,
extra_iso_fnames)
if rc:
log.cl_error("failed to download Grafana")
return -1
rc = build_grafana(log, host, target_cpu, packages_dir, extra_package_fnames)
if rc:
log.cl_error("failed to download Grafana")
return -1
rc = build_influxdb(log, host, target_cpu, packages_dir,
extra_package_fnames)
if rc:
log.cl_error("failed to download Influxdb")
return -1
extra_rpm_names += barrele_constant.BARRELE_DOWNLOAD_DEPENDENT_RPMS
return 0
class CoralBarrelePlugin(build_common.CoralPluginType):
"""
Barrele Plugin
"""
# pylint: disable=too-few-public-methods
def __init__(self):
super().__init__("barrele",
BARRELEYE_BUILD_DEPENDENT_PIPS,
is_devel=False,
need_collectd=True)
def cpt_build_dependent_rpms(self, distro):
"""
Return the RPMs needed to install before building
"""
return BARRELEYE_BUILD_DEPENDENT_RPMS
def cpt_build(self, log, workspace, local_host, source_dir, target_cpu,
type_cache, iso_cache, packages_dir, extra_iso_fnames,
extra_package_fnames, extra_rpm_names, collectd):
"""
Build the plugin
"""
# pylint: disable=unused-argument,no-self-use
ret = build_barreleye(log, workspace, local_host, type_cache,
target_cpu, iso_cache, packages_dir, collectd,
extra_iso_fnames, extra_package_fnames,
extra_rpm_names)
if ret:
log.cl_error("failed to build Barreleye")
return -1
return 0
class CoralBarreleCommand():
"""
Commands to for building Barreleye plugin.
"""
# pylint: disable=too-few-public-methods
def _init(self, log_to_file):
# pylint: disable=attribute-defined-outside-init
self._cbc_log_to_file = log_to_file
def urls(self):
"""
Print the URLs to download dependency packages.
"""
# pylint: disable=no-self-use
log = clog.get_log(console_format=clog.FMT_NORMAL, overwrite=True)
for package, url in PACAKGE_URL_DICT.items():
log.cl_stdout("%s: %s", package, url)
cmd_general.cmd_exit(log, 0)
build_common.coral_command_register("barrele", CoralBarreleCommand())
build_common.coral_plugin_register(CoralBarrelePlugin())