openubmc-bingo 0.5.240__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

Potentially problematic release.


This version of openubmc-bingo might be problematic. Click here for more details.

Files changed (242) hide show
  1. bmcgo/__init__.py +12 -0
  2. bmcgo/bmcgo.py +22 -0
  3. bmcgo/bmcgo_config.py +176 -0
  4. bmcgo/cli/__init__.py +10 -0
  5. bmcgo/cli/cli.py +584 -0
  6. bmcgo/codegen/__init__.py +14 -0
  7. bmcgo/codegen/c/__init__.py +9 -0
  8. bmcgo/codegen/c/annotation.py +52 -0
  9. bmcgo/codegen/c/argument.py +42 -0
  10. bmcgo/codegen/c/codegen.py +153 -0
  11. bmcgo/codegen/c/comment.py +22 -0
  12. bmcgo/codegen/c/ctype_defination.py +353 -0
  13. bmcgo/codegen/c/helper.py +87 -0
  14. bmcgo/codegen/c/interface.py +63 -0
  15. bmcgo/codegen/c/method.py +82 -0
  16. bmcgo/codegen/c/property.py +180 -0
  17. bmcgo/codegen/c/renderer.py +21 -0
  18. bmcgo/codegen/c/signal.py +64 -0
  19. bmcgo/codegen/c/template/client.c.mako +145 -0
  20. bmcgo/codegen/c/template/client.h.mako +36 -0
  21. bmcgo/codegen/c/template/interface.c.mako +0 -0
  22. bmcgo/codegen/c/template/interface.introspect.xml.mako +99 -0
  23. bmcgo/codegen/c/template/micro_component.c.mako +32 -0
  24. bmcgo/codegen/c/template/public.c.mako +228 -0
  25. bmcgo/codegen/c/template/public.h.mako +128 -0
  26. bmcgo/codegen/c/template/server.c.mako +104 -0
  27. bmcgo/codegen/c/template/server.h.mako +36 -0
  28. bmcgo/codegen/lua/.lua-format +7 -0
  29. bmcgo/codegen/lua/Makefile +101 -0
  30. bmcgo/codegen/lua/__init__.py +9 -0
  31. bmcgo/codegen/lua/codegen.py +171 -0
  32. bmcgo/codegen/lua/proto/Makefile +87 -0
  33. bmcgo/codegen/lua/proto/ipmi_types.proto +17 -0
  34. bmcgo/codegen/lua/proto/types.proto +52 -0
  35. bmcgo/codegen/lua/script/check_intfs.py +161 -0
  36. bmcgo/codegen/lua/script/dto/__init__.py +11 -0
  37. bmcgo/codegen/lua/script/dto/exception.py +53 -0
  38. bmcgo/codegen/lua/script/dto/kepler_abstract.py +47 -0
  39. bmcgo/codegen/lua/script/dto/options.py +33 -0
  40. bmcgo/codegen/lua/script/dto/print_simple.py +19 -0
  41. bmcgo/codegen/lua/script/dto/redfish_api.py +241 -0
  42. bmcgo/codegen/lua/script/dto/url_route.py +195 -0
  43. bmcgo/codegen/lua/script/gen_db_json.py +444 -0
  44. bmcgo/codegen/lua/script/gen_depends.py +89 -0
  45. bmcgo/codegen/lua/script/gen_entry.py +263 -0
  46. bmcgo/codegen/lua/script/gen_feature_json.py +156 -0
  47. bmcgo/codegen/lua/script/gen_historical_local_db_json.py +88 -0
  48. bmcgo/codegen/lua/script/gen_intf_json.py +261 -0
  49. bmcgo/codegen/lua/script/gen_intf_rpc_json.py +575 -0
  50. bmcgo/codegen/lua/script/gen_ipmi_json.py +485 -0
  51. bmcgo/codegen/lua/script/gen_mdb_json.py +117 -0
  52. bmcgo/codegen/lua/script/gen_rpc_msg_json.py +487 -0
  53. bmcgo/codegen/lua/script/gen_schema.py +302 -0
  54. bmcgo/codegen/lua/script/ipmi_types_pb2.py +135 -0
  55. bmcgo/codegen/lua/script/loader/__init__.py +11 -0
  56. bmcgo/codegen/lua/script/loader/file_utils.py +33 -0
  57. bmcgo/codegen/lua/script/loader/kepler_abstract_collect.py +79 -0
  58. bmcgo/codegen/lua/script/loader/kepler_abstract_loader.py +47 -0
  59. bmcgo/codegen/lua/script/loader/redfish_loader.py +127 -0
  60. bmcgo/codegen/lua/script/lua_format.py +62 -0
  61. bmcgo/codegen/lua/script/mds_util.py +385 -0
  62. bmcgo/codegen/lua/script/merge_model.py +330 -0
  63. bmcgo/codegen/lua/script/merge_proto_algo.py +85 -0
  64. bmcgo/codegen/lua/script/proto_loader.py +47 -0
  65. bmcgo/codegen/lua/script/proto_plugin.py +140 -0
  66. bmcgo/codegen/lua/script/redfish_source_tree.py +118 -0
  67. bmcgo/codegen/lua/script/render_utils/__init__.py +38 -0
  68. bmcgo/codegen/lua/script/render_utils/base.py +25 -0
  69. bmcgo/codegen/lua/script/render_utils/client_lua.py +98 -0
  70. bmcgo/codegen/lua/script/render_utils/controller_lua.py +71 -0
  71. bmcgo/codegen/lua/script/render_utils/db_lua.py +224 -0
  72. bmcgo/codegen/lua/script/render_utils/error_lua.py +185 -0
  73. bmcgo/codegen/lua/script/render_utils/factory.py +52 -0
  74. bmcgo/codegen/lua/script/render_utils/ipmi_lua.py +159 -0
  75. bmcgo/codegen/lua/script/render_utils/ipmi_message_lua.py +24 -0
  76. bmcgo/codegen/lua/script/render_utils/mdb_lua.py +177 -0
  77. bmcgo/codegen/lua/script/render_utils/mdb_register.py +215 -0
  78. bmcgo/codegen/lua/script/render_utils/message_lua.py +26 -0
  79. bmcgo/codegen/lua/script/render_utils/messages_lua.py +156 -0
  80. bmcgo/codegen/lua/script/render_utils/model_lua.py +485 -0
  81. bmcgo/codegen/lua/script/render_utils/old_model_lua.py +429 -0
  82. bmcgo/codegen/lua/script/render_utils/plugin_lua.py +38 -0
  83. bmcgo/codegen/lua/script/render_utils/redfish_proto.py +86 -0
  84. bmcgo/codegen/lua/script/render_utils/request_lua.py +76 -0
  85. bmcgo/codegen/lua/script/render_utils/service_lua.py +130 -0
  86. bmcgo/codegen/lua/script/render_utils/utils_message_lua.py +125 -0
  87. bmcgo/codegen/lua/script/render_utils/validate_lua.py +221 -0
  88. bmcgo/codegen/lua/script/sep_ipmi_message_cmds.py +217 -0
  89. bmcgo/codegen/lua/script/template.py +166 -0
  90. bmcgo/codegen/lua/script/types_pb2.py +516 -0
  91. bmcgo/codegen/lua/script/utils.py +663 -0
  92. bmcgo/codegen/lua/script/validate.py +80 -0
  93. bmcgo/codegen/lua/script/yaml_to_json.py +73 -0
  94. bmcgo/codegen/lua/templates/Makefile +114 -0
  95. bmcgo/codegen/lua/templates/apps/Makefile +261 -0
  96. bmcgo/codegen/lua/templates/apps/Makefile.mdb.mk +64 -0
  97. bmcgo/codegen/lua/templates/apps/app.lua.mako +19 -0
  98. bmcgo/codegen/lua/templates/apps/class.lua.mako +35 -0
  99. bmcgo/codegen/lua/templates/apps/client.lua.mako +429 -0
  100. bmcgo/codegen/lua/templates/apps/controller.lua.mako +276 -0
  101. bmcgo/codegen/lua/templates/apps/datas.lua.mako +8 -0
  102. bmcgo/codegen/lua/templates/apps/db.lua.mako +89 -0
  103. bmcgo/codegen/lua/templates/apps/entry.lua.mako +128 -0
  104. bmcgo/codegen/lua/templates/apps/feature.lua.mako +37 -0
  105. bmcgo/codegen/lua/templates/apps/generate_route.mako +25 -0
  106. bmcgo/codegen/lua/templates/apps/impl_feature.lua.mako +72 -0
  107. bmcgo/codegen/lua/templates/apps/ipmi.lua.mako +97 -0
  108. bmcgo/codegen/lua/templates/apps/ipmi_cmd.lua.mako +18 -0
  109. bmcgo/codegen/lua/templates/apps/ipmi_message.lua.mako +36 -0
  110. bmcgo/codegen/lua/templates/apps/local_db.lua.mako +263 -0
  111. bmcgo/codegen/lua/templates/apps/main.lua.mako +25 -0
  112. bmcgo/codegen/lua/templates/apps/mc.lua.mako +77 -0
  113. bmcgo/codegen/lua/templates/apps/mdb.lua.mako +45 -0
  114. bmcgo/codegen/lua/templates/apps/mdb_interface.lua.mako +73 -0
  115. bmcgo/codegen/lua/templates/apps/message.lua.mako +38 -0
  116. bmcgo/codegen/lua/templates/apps/model.lua.mako +239 -0
  117. bmcgo/codegen/lua/templates/apps/orm_classes.lua.mako +16 -0
  118. bmcgo/codegen/lua/templates/apps/plugin.lua.mako +8 -0
  119. bmcgo/codegen/lua/templates/apps/redfish.proto.mako +47 -0
  120. bmcgo/codegen/lua/templates/apps/service.lua.mako +440 -0
  121. bmcgo/codegen/lua/templates/apps/signal_listen.lua.mako +19 -0
  122. bmcgo/codegen/lua/templates/apps/utils/default_intf.lua.mako +41 -0
  123. bmcgo/codegen/lua/templates/apps/utils/enum.mako +10 -0
  124. bmcgo/codegen/lua/templates/apps/utils/imports.mako +13 -0
  125. bmcgo/codegen/lua/templates/apps/utils/mdb_intf.lua.mako +25 -0
  126. bmcgo/codegen/lua/templates/apps/utils/mdb_obj.lua.mako +23 -0
  127. bmcgo/codegen/lua/templates/apps/utils/message.mako +160 -0
  128. bmcgo/codegen/lua/templates/apps/utils/request.lua.mako +59 -0
  129. bmcgo/codegen/lua/templates/apps/utils/validate.mako +83 -0
  130. bmcgo/codegen/lua/templates/errors.lua.mako +36 -0
  131. bmcgo/codegen/lua/templates/messages.lua.mako +32 -0
  132. bmcgo/codegen/lua/templates/new_app/.clang-format.mako +170 -0
  133. bmcgo/codegen/lua/templates/new_app/.gitignore.mako +26 -0
  134. bmcgo/codegen/lua/templates/new_app/CHANGELOG.md.mako +0 -0
  135. bmcgo/codegen/lua/templates/new_app/CMakeLists.txt.mako +29 -0
  136. bmcgo/codegen/lua/templates/new_app/Makefile.mako +25 -0
  137. bmcgo/codegen/lua/templates/new_app/README.md.mako +0 -0
  138. bmcgo/codegen/lua/templates/new_app/conanfile.py.mako +7 -0
  139. bmcgo/codegen/lua/templates/new_app/config.cfg.mako +6 -0
  140. bmcgo/codegen/lua/templates/new_app/mds/model.json.mako +3 -0
  141. bmcgo/codegen/lua/templates/new_app/mds/service.json.mako +21 -0
  142. bmcgo/codegen/lua/templates/new_app/permissions.ini.mako +16 -0
  143. bmcgo/codegen/lua/templates/new_app/src/lualib/${project_name}_app.lua.mako +16 -0
  144. bmcgo/codegen/lua/templates/new_app/src/service/main.lua.mako +25 -0
  145. bmcgo/codegen/lua/templates/new_app/test/integration/test_${project_name}.conf.mako +9 -0
  146. bmcgo/codegen/lua/templates/new_app/test/integration/test_${project_name}.lua.mako +47 -0
  147. bmcgo/codegen/lua/templates/new_app/test/unit/test.lua.mako +23 -0
  148. bmcgo/codegen/lua/templates/new_app/user_conf/rootfs/etc/systemd/system/${project_name}.service.mako +18 -0
  149. bmcgo/codegen/lua/templates/new_app/user_conf/rootfs/etc/systemd/system/multi-user.target.wants/${project_name}.service.link +1 -0
  150. bmcgo/component/__init__.py +10 -0
  151. bmcgo/component/analysis/analysis.py +183 -0
  152. bmcgo/component/analysis/build_deps.py +165 -0
  153. bmcgo/component/analysis/data_deps.py +333 -0
  154. bmcgo/component/analysis/dep-rules.json +912 -0
  155. bmcgo/component/analysis/dep_node.py +110 -0
  156. bmcgo/component/analysis/intf_deps.py +163 -0
  157. bmcgo/component/analysis/intf_validation.py +254 -0
  158. bmcgo/component/analysis/rule.py +211 -0
  159. bmcgo/component/analysis/smc_dfx_whitelist.json +11 -0
  160. bmcgo/component/analysis/sr_validation.py +391 -0
  161. bmcgo/component/build.py +222 -0
  162. bmcgo/component/component_dt_version_parse.py +348 -0
  163. bmcgo/component/component_helper.py +114 -0
  164. bmcgo/component/coverage/__init__.py +11 -0
  165. bmcgo/component/coverage/c_incremental_cov_report.template +53 -0
  166. bmcgo/component/coverage/incremental_cov.py +464 -0
  167. bmcgo/component/deploy.py +110 -0
  168. bmcgo/component/gen.py +169 -0
  169. bmcgo/component/package_info.py +236 -0
  170. bmcgo/component/template/conanbase.py.mako +278 -0
  171. bmcgo/component/template/conanfile.deploy.py.mako +40 -0
  172. bmcgo/component/test.py +947 -0
  173. bmcgo/errors.py +119 -0
  174. bmcgo/frame.py +217 -0
  175. bmcgo/functional/__init__.py +10 -0
  176. bmcgo/functional/analysis.py +96 -0
  177. bmcgo/functional/bmc_studio_action.py +98 -0
  178. bmcgo/functional/check.py +185 -0
  179. bmcgo/functional/conan_index_build.py +251 -0
  180. bmcgo/functional/config.py +332 -0
  181. bmcgo/functional/csr_build.py +724 -0
  182. bmcgo/functional/deploy.py +263 -0
  183. bmcgo/functional/diff.py +235 -0
  184. bmcgo/functional/fetch.py +235 -0
  185. bmcgo/functional/full_component.py +391 -0
  186. bmcgo/functional/maintain.py +381 -0
  187. bmcgo/functional/new.py +166 -0
  188. bmcgo/functional/schema_valid.py +111 -0
  189. bmcgo/functional/simple_sign.py +104 -0
  190. bmcgo/functional/upgrade.py +78 -0
  191. bmcgo/ipmigen/__init__.py +13 -0
  192. bmcgo/ipmigen/ctype_defination.py +82 -0
  193. bmcgo/ipmigen/ipmigen.py +309 -0
  194. bmcgo/ipmigen/template/cmd.c.mako +366 -0
  195. bmcgo/ipmigen/template/ipmi.c.mako +25 -0
  196. bmcgo/ipmigen/template/ipmi.h.mako +51 -0
  197. bmcgo/logger.py +176 -0
  198. bmcgo/misc.py +117 -0
  199. bmcgo/target/app.yml +17 -0
  200. bmcgo/target/install_sdk.yml +15 -0
  201. bmcgo/target/personal.yml +53 -0
  202. bmcgo/target/publish.yml +45 -0
  203. bmcgo/tasks/__init__.py +11 -0
  204. bmcgo/tasks/download_buildtools_hm.py +124 -0
  205. bmcgo/tasks/misc.py +15 -0
  206. bmcgo/tasks/task.py +354 -0
  207. bmcgo/tasks/task_build_conan.py +714 -0
  208. bmcgo/tasks/task_build_rootfs_img.py +595 -0
  209. bmcgo/tasks/task_buildgppbin.py +88 -0
  210. bmcgo/tasks/task_buildhpm_ext4.py +82 -0
  211. bmcgo/tasks/task_create_interface_config.py +122 -0
  212. bmcgo/tasks/task_download_buildtools.py +99 -0
  213. bmcgo/tasks/task_download_dependency.py +72 -0
  214. bmcgo/tasks/task_hpm_envir_prepare.py +112 -0
  215. bmcgo/tasks/task_packet_to_supporte.py +87 -0
  216. bmcgo/tasks/task_prepare.py +105 -0
  217. bmcgo/tasks/task_sign_and_pack_hpm.py +42 -0
  218. bmcgo/utils/__init__.py +10 -0
  219. bmcgo/utils/buffer.py +128 -0
  220. bmcgo/utils/combine_json_schemas.py +170 -0
  221. bmcgo/utils/component_post.py +54 -0
  222. bmcgo/utils/component_version_check.py +86 -0
  223. bmcgo/utils/config.py +1067 -0
  224. bmcgo/utils/fetch_component_code.py +232 -0
  225. bmcgo/utils/install_manager.py +61 -0
  226. bmcgo/utils/installations/__init__.py +10 -0
  227. bmcgo/utils/installations/base_installer.py +70 -0
  228. bmcgo/utils/installations/install_consts.py +30 -0
  229. bmcgo/utils/installations/install_plans/bingo.yml +11 -0
  230. bmcgo/utils/installations/install_workflow.py +50 -0
  231. bmcgo/utils/installations/installers/apt_installer.py +177 -0
  232. bmcgo/utils/installations/installers/pip_installer.py +46 -0
  233. bmcgo/utils/installations/version_util.py +100 -0
  234. bmcgo/utils/mapping_config_patch.py +443 -0
  235. bmcgo/utils/perf_analysis.py +114 -0
  236. bmcgo/utils/tools.py +704 -0
  237. bmcgo/worker.py +417 -0
  238. openubmc_bingo-0.5.240.dist-info/METADATA +30 -0
  239. openubmc_bingo-0.5.240.dist-info/RECORD +242 -0
  240. openubmc_bingo-0.5.240.dist-info/WHEEL +5 -0
  241. openubmc_bingo-0.5.240.dist-info/entry_points.txt +2 -0
  242. openubmc_bingo-0.5.240.dist-info/top_level.txt +1 -0
@@ -0,0 +1,16 @@
1
+ # syntax documentation
2
+ # format: name type mode uid gid
3
+ # name is the path to the file you want to create/modify
4
+ # type is the type of the file, being one of:
5
+ # f: a regular file
6
+ # d: a directory
7
+ # r: a directory recursively
8
+ # mode are the usual permissions settings (only numerical values are allowed)
9
+ # name is the path to the file you want to create/modify
10
+ opt/bmc/apps/${project_name} d 550 0 0
11
+ opt/bmc/apps/${project_name} r 440 0 0
12
+ opt/bmc/apps/${project_name} rd 550 0 0
13
+ opt/bmc/apps/${project_name}/config.cfg f 640 0 0
14
+ opt/bmc/apps/${project_name}/mds d 750 0 0
15
+ opt/bmc/apps/${project_name}/mds r 640 0 0
16
+ etc/systemd/system/${project_name}.service f 640 0 0
@@ -0,0 +1,16 @@
1
+ ${make_header('lua')}
2
+
3
+ local class = require 'mc.class'
4
+ local service = require '${project_name}.service'
5
+
6
+ local ${project_name} = class(service)
7
+
8
+ function ${project_name}:ctor()
9
+
10
+ end
11
+
12
+ function ${project_name}:init()
13
+ self.super.init(self)
14
+ end
15
+
16
+ return ${project_name}
@@ -0,0 +1,25 @@
1
+ ${make_header('lua')}
2
+
3
+ require 'skynet.manager'
4
+ local skynet = require 'skynet'
5
+ local logging = require 'mc.logging'
6
+ local ${project_name}_app = require '${project_name}_app'
7
+
8
+ local CMD = {}
9
+
10
+ function CMD.exit()
11
+ logging:notice('${project_name} service exit')
12
+ end
13
+
14
+ skynet.start(function()
15
+ skynet.uniqueservice('sd_bus')
16
+ skynet.register('${project_name}')
17
+ local ok, err = pcall(${project_name}_app.new)
18
+ if not ok then
19
+ logging:error('${project_name} start failed, err: %s', err)
20
+ end
21
+ skynet.dispatch('lua', function(_, _, cmd, ...)
22
+ local f = assert(CMD[cmd])
23
+ skynet.ret(skynet.pack(f(...)))
24
+ end)
25
+ end)
@@ -0,0 +1,9 @@
1
+ include("$CONFIG_FILE")
2
+
3
+ config:init_integration_test_dirs()
4
+ config:set_start("test_${project_name}")
5
+ config:include_app('${project_name}')
6
+ config:done()
7
+
8
+ TEST_DATA_DIR = 'test/integration/.test_temp_data/'
9
+ test_apps_root = 'test/integration/apps/'
@@ -0,0 +1,47 @@
1
+ ${make_header('lua')}
2
+ local skynet = require 'skynet'
3
+ require 'skynet.manager'
4
+ local log = require 'mc.logging'
5
+ local utils = require 'mc.utils'
6
+ local test_common = require 'test_common.utils'
7
+
8
+ local function prepare_test_data()
9
+ local test_data_dir = skynet.getenv('TEST_DATA_DIR')
10
+ os.execute('mkdir -p ' .. test_data_dir)
11
+ os.execute('mkdir -p ' .. '/tmp/test_dump')
12
+ end
13
+
14
+ local function clear_test_data(exit_test)
15
+ log:info('clear test data')
16
+ local test_data_dir = skynet.getenv('TEST_DATA_DIR')
17
+ if not exit_test then
18
+ return utils.remove_file(test_data_dir)
19
+ end
20
+
21
+ skynet.timeout(0, function()
22
+ skynet.sleep(20)
23
+ skynet.abort()
24
+ utils.remove_file(test_data_dir)
25
+ utils.remove_file('/tmp/test_dump')
26
+ end)
27
+ end
28
+
29
+ local function test_${project_name}()
30
+ log:info('================ test start ================')
31
+
32
+ log:info('================ test complete ================')
33
+ end
34
+
35
+ skynet.start(function()
36
+ clear_test_data(false)
37
+ prepare_test_data()
38
+ test_common.dbus_launch()
39
+ skynet.uniqueservice('main')
40
+ skynet.fork(function()
41
+ local ok, err = pcall(test_${project_name})
42
+ clear_test_data(true)
43
+ if not ok then
44
+ error(err)
45
+ end
46
+ end)
47
+ end)
@@ -0,0 +1,23 @@
1
+ ${make_header('lua')}
2
+ <% camel_name=''.join(word.title() for word in project_name.split('_')) %>
3
+ loadfile(os.getenv('CONFIG_FILE'), 't', {package = package, os = os})()
4
+
5
+ local lu = require('luaunit')
6
+ local utils = require 'utils.core'
7
+ local logging = require 'mc.logging'
8
+
9
+ local current_file_dir = debug.getinfo(1).source:match('@?(.*)/')
10
+
11
+ utils.chdir(current_file_dir)
12
+ logging:setPrint(nil)
13
+ logging:setLevel(logging.INFO)
14
+
15
+ Test${camel_name}Cfg = {}
16
+
17
+ function Test${camel_name}Cfg:setupClass()
18
+ end
19
+
20
+ function Test${camel_name}Cfg:teardownClass()
21
+ end
22
+
23
+ os.exit(lu.LuaUnit.run())
@@ -0,0 +1,18 @@
1
+ [Unit]
2
+ Description=${project_name} service
3
+ After=dbus.service
4
+ Requires=dbus.service
5
+
6
+ [Service]
7
+ User=root
8
+ Restart=always
9
+ RestartSec=1
10
+ StartLimitInterval=0
11
+ EnvironmentFile=/dev/shm/dbus/.dbus
12
+ Environment="ROOT_DIR="
13
+ Environment="PROJECT_DIR="
14
+ WorkingDirectory=/opt/bmc/apps/${project_name}
15
+ ExecStart=/opt/bmc/skynet/skynet /opt/bmc/apps/${project_name}/config.cfg
16
+
17
+ [Install]
18
+ WantedBy=multi-user.target
@@ -0,0 +1,10 @@
1
+ # coding: utf-8
2
+ # Copyright (c) 2024 Huawei Technologies Co., Ltd.
3
+ # openUBMC is licensed under Mulan PSL v2.
4
+ # You can use this software according to the terms and conditions of the Mulan PSL v2.
5
+ # You may obtain a copy of Mulan PSL v2 at:
6
+ # http://license.coscl.org.cn/MulanPSL2
7
+ # THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
8
+ # EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
9
+ # MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
10
+ # See the Mulan PSL v2 for more details.
@@ -0,0 +1,183 @@
1
+ #!/usr/bin/python3
2
+ # coding: utf-8
3
+ # Copyright (c) 2024 Huawei Technologies Co., Ltd.
4
+ # openUBMC is licensed under Mulan PSL v2.
5
+ # You can use this software according to the terms and conditions of the Mulan PSL v2.
6
+ # You may obtain a copy of Mulan PSL v2 at:
7
+ # http://license.coscl.org.cn/MulanPSL2
8
+ # THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
9
+ # EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
10
+ # MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
11
+ # See the Mulan PSL v2 for more details.
12
+
13
+ import json
14
+ import os
15
+
16
+ from bmcgo import misc
17
+ from bmcgo.component.analysis.build_deps import BuildDependenciesAnalysis
18
+ from bmcgo.component.analysis.dep_node import DepNode
19
+ from bmcgo.component.analysis.intf_deps import InterfaceDependenciesAnalysis
20
+ from bmcgo.component.analysis.data_deps import DataDependenciesAnalysis
21
+ from bmcgo.component.analysis.rule import SubSys, Rules
22
+ from bmcgo.logger import Logger
23
+
24
+ global log
25
+ log = Logger()
26
+
27
+ script_dir = os.path.split(os.path.realpath(__file__))[0]
28
+ TABLE_CONFLICT_WHITE_LIST = {
29
+ "nsm": ["t_snmp_config", set(["Id", "Enabled"])],
30
+ "event_policy": ["t_snmp_config", set(["Id", "Enabled"])]
31
+ }
32
+
33
+
34
+ class AnalysisComp():
35
+ def __init__(self, board_name, artifact_dir, lock_file, custom_sr_dir):
36
+ self.board_name = board_name
37
+ self.artifact_dir = artifact_dir
38
+ self.lock_file = lock_file
39
+ self.custom_sr_dir = custom_sr_dir
40
+ if not self.artifact_dir:
41
+ self.artifact_dir = os.path.join(os.getcwd(), "..", "output/packet/inner")
42
+ if not lock_file:
43
+ self.lock_file = os.path.join(os.getcwd(), "..", "output/package.lock")
44
+ self.nodes: list[DepNode] = []
45
+ self.subsystems = {}
46
+ self.rules: list[Rules] = []
47
+
48
+ def read_rules(self):
49
+ rule_file = os.path.join(script_dir, "dep-rules.json")
50
+ if not os.path.isfile(rule_file):
51
+ raise Exception(f"依赖规则文件 {rule_file} 不存在")
52
+ with open(rule_file) as file_descriptor:
53
+ rules = json.load(file_descriptor)
54
+ data = rules.get("Subsystems", [])
55
+ for sub in data:
56
+ sys_data = data[sub]
57
+ level = sys_data.get("Level", 0)
58
+ subsys = SubSys(int(level))
59
+ apps = sys_data.get("Apps", [])
60
+ for app in apps:
61
+ subsys.apps.append(app)
62
+ libs = sys_data.get("Libraries", [])
63
+ for lib in libs:
64
+ subsys.libraries.append(lib)
65
+ tools = sys_data.get("Tools", [])
66
+ for tool in tools:
67
+ subsys.tools.append(tool)
68
+ configurations = sys_data.get("Configurations", [])
69
+ for config in configurations:
70
+ subsys.configurations.append(config)
71
+ commands = sys_data.get("Commands", [])
72
+ for cmd in commands:
73
+ subsys.commands.append(cmd)
74
+ self.subsystems[sub] = subsys
75
+ self.rules.append(Rules(rules.get("Allowed", []), True))
76
+ self.rules.append(Rules(rules.get("UnAllowed", []), False))
77
+
78
+ def set_node_subsys(self, node: DepNode):
79
+ for key, subsys in self.subsystems.items():
80
+ if node.package_name in subsys.apps:
81
+ node.set_subsys(key, subsys.level)
82
+ node.set_package_type("App")
83
+ if node.package_name in subsys.libraries:
84
+ node.set_subsys(key, subsys.level)
85
+ node.set_package_type("Library")
86
+ if node.package_name in subsys.tools:
87
+ node.set_subsys(key, subsys.level)
88
+ node.set_package_type("Tool")
89
+ if node.package_name in subsys.configurations:
90
+ node.set_subsys(key, subsys.level)
91
+ node.set_package_type("Configuration")
92
+ if node.package_name in subsys.commands:
93
+ node.set_subsys(key, subsys.level)
94
+ node.set_package_type("Command")
95
+ log.debug("app 名字: %s,类型: (%s), 子系统: %s", node.package_name, ", ".join(node.package_type),
96
+ node.subsys_name)
97
+
98
+ def read_package_lock(self):
99
+ if not os.path.isfile(self.lock_file):
100
+ raise Exception(f"无法找到 {self.lock_file} 构建信息用于分析")
101
+ with open(self.lock_file) as file_descriptor:
102
+ lock = json.load(file_descriptor)
103
+ requires: dict = {}
104
+ packages = {}
105
+ for i in range(0, 10000):
106
+ node_data = lock.get("graph_lock", {}).get("nodes", {}).get(str(i), None)
107
+ if not node_data:
108
+ break
109
+ node = DepNode(node_data, i)
110
+ # busybox是调测包,当dev包引入时忽略架构治理分析(由schema模型看护)
111
+ user_stage = f"{misc.ConanUserEnum.CONAN_USER_DEV.value}/{misc.StageEnum.STAGE_DEV.value}"
112
+ if node.package_name == "busybox" and user_stage in node.ref:
113
+ continue
114
+ packages[node.index] = node
115
+ requires[node.index] = node_data.get("requires", [])
116
+ for index, pkg in packages.items():
117
+ if not pkg.name.startswith("openubmc"):
118
+ self.set_node_subsys(pkg)
119
+ for require_id in requires.get(index, []):
120
+ pkg.requires.append(packages.get(int(require_id), None))
121
+ if not pkg.name.startswith("openubmc"):
122
+ self.nodes.append(pkg)
123
+
124
+ def run(self):
125
+ self.read_rules()
126
+ self.read_package_lock()
127
+
128
+ table_valid = self._check_table_conflict()
129
+
130
+ build_deps_alys = BuildDependenciesAnalysis(self.nodes, self.rules)
131
+ all_deps_valid = build_deps_alys.is_dependency_allowed()
132
+ build_deps_alys.visualize_graph(
133
+ os.path.join(self.artifact_dir, "build_dependencies_graph_{}.html".format(self.board_name)))
134
+ build_deps_alys.assemble_deps_json_desc(
135
+ os.path.join(self.artifact_dir, "build_dependencies_graph_{}.json".format(self.board_name)))
136
+
137
+ intf_deps_alys = InterfaceDependenciesAnalysis(self.nodes, self.rules)
138
+ all_deps_valid = intf_deps_alys.is_dependency_allowed() and all_deps_valid
139
+ intf_deps_alys.visualize_graph(
140
+ os.path.join(self.artifact_dir, "interface_dependencies_graph_{}.html".format(self.board_name)))
141
+ intf_deps_alys.assemble_deps_json_desc(
142
+ os.path.join(self.artifact_dir, "interface_dependencies_graph_{}.json".format(self.board_name)))
143
+
144
+ data_deps_alys = DataDependenciesAnalysis(self.nodes, self.rules, self.custom_sr_dir)
145
+ data_deps_valid = data_deps_alys.run(
146
+ os.path.join(self.artifact_dir, "data_dependencies_graph_{}.html".format(self.board_name)),
147
+ os.path.join(self.artifact_dir, "data_dependencies_graph_{}.json".format(self.board_name)),
148
+ os.path.join(self.artifact_dir, "data_dependencies_issues_{}.log".format(self.board_name))
149
+ )
150
+ all_deps_valid = table_valid and data_deps_valid and all_deps_valid
151
+
152
+ if all_deps_valid:
153
+ log.info("依赖检查通过")
154
+ else:
155
+ log.error("依赖检查不通过")
156
+ return all_deps_valid
157
+
158
+ def _check_table_conflict(self):
159
+ result = True
160
+ remote_table_map = {}
161
+ for node in self.nodes:
162
+ if node.table_conflict:
163
+ result = False
164
+ for remote_table, value in node.remote_tables.items():
165
+ if remote_table not in remote_table_map:
166
+ remote_table_map[remote_table] = [node.package_name, value]
167
+ continue
168
+
169
+ hit_package_name = remote_table_map[remote_table][0]
170
+ hit_info = remote_table_map[remote_table][1]
171
+ if node.package_name not in TABLE_CONFLICT_WHITE_LIST \
172
+ or remote_table != TABLE_CONFLICT_WHITE_LIST[node.package_name][0] \
173
+ or hit_package_name not in TABLE_CONFLICT_WHITE_LIST:
174
+ log.error("%s与%s远程持久化表名冲突: %s", node.package_name, hit_package_name, remote_table)
175
+ result = False
176
+ continue
177
+
178
+ intersection = hit_info.intersection(value) - TABLE_CONFLICT_WHITE_LIST[hit_package_name][1]
179
+ if intersection:
180
+ log.error("%s与%s的远程持久化表%s存在历史冲突, 不允许再添加新的冲突字段%s", node.package_name, hit_package_name, remote_table,
181
+ intersection)
182
+ result = False
183
+ return result
@@ -0,0 +1,165 @@
1
+ #!/usr/bin/env python
2
+ # coding: utf-8
3
+ # Copyright (c) 2024 Huawei Technologies Co., Ltd.
4
+ # openUBMC is licensed under Mulan PSL v2.
5
+ # You can use this software according to the terms and conditions of the Mulan PSL v2.
6
+ # You may obtain a copy of Mulan PSL v2 at:
7
+ # http://license.coscl.org.cn/MulanPSL2
8
+ # THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
9
+ # EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
10
+ # MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
11
+ # See the Mulan PSL v2 for more details.
12
+
13
+ from collections import defaultdict
14
+ from typing import Dict, List, Set
15
+
16
+ import json
17
+ import os
18
+ import stat
19
+
20
+ from pyecharts import options as opts
21
+ from pyecharts.charts import Graph
22
+ from pyecharts.options import GraphLink, GraphNode
23
+
24
+ from bmcgo.component.analysis.dep_node import DepNode
25
+ from bmcgo.component.analysis.rule import Rules
26
+ from bmcgo.logger import Logger
27
+ from bmcgo import misc
28
+
29
+ global log
30
+ log = Logger()
31
+ TARGET_COMPONENTS = "targetComponents"
32
+
33
+
34
+ class BuildDependenciesAnalysis():
35
+ def __init__(self, nodes: List[DepNode], rules: List[Rules]):
36
+ self._nodes = nodes
37
+ self._rules = rules
38
+ self.build_deps_graph: Dict[str, Set[str]] = defaultdict(set)
39
+ self.build_deps_unallowed_graph: Dict[str, Set[str]] = defaultdict(set)
40
+ self.isolated_packages: Set[str] = set()
41
+ self._node_build_relation()
42
+ self._get_isolated_packages()
43
+
44
+ def is_dependency_allowed(self):
45
+ is_allowed = True
46
+ for pkg in self._nodes:
47
+ if pkg.subsys_name == "unknown":
48
+ is_allowed = False
49
+ log.error("发现一个不在子系统中的包, 包名为: %s", pkg.name)
50
+ if pkg.package_name in self.isolated_packages and "Library" in pkg.package_type:
51
+ if pkg.subsys_name != "opensource" and pkg.subsys_name != "public":
52
+ is_allowed = False
53
+ log.error("找到一个孤立的库, 库名为: %s", pkg.name)
54
+ else:
55
+ log.warning("找到一个孤立的开源/平台公共库, 库名为: %s", pkg.name)
56
+ return is_allowed and not bool(self.build_deps_unallowed_graph)
57
+
58
+ def assemble_deps_json_desc(self, path):
59
+ node_name_map = dict()
60
+ for node in self._nodes:
61
+ node_name_map[node.package_name] = {
62
+ misc.NAME: node.package_name,
63
+ "version": node.package_version,
64
+ "subsystem": node.subsys_name,
65
+ "type": node.package_type
66
+ }
67
+
68
+ json_dict = {"AllBuildDependencyGraph": [], "IllegalBuildDependencyGraph": []}
69
+ for src in self.build_deps_graph:
70
+ entry = {"sourceComponent": node_name_map.get(src), TARGET_COMPONENTS: []}
71
+ for tgt in self.build_deps_graph[src]:
72
+ entry[TARGET_COMPONENTS].append(node_name_map.get(tgt))
73
+ json_dict["AllBuildDependencyGraph"].append(entry)
74
+
75
+ for src in self.build_deps_unallowed_graph:
76
+ entry = {"sourceComponent": node_name_map.get(src), TARGET_COMPONENTS: []}
77
+ for tgt in self.build_deps_unallowed_graph[src]:
78
+ entry[TARGET_COMPONENTS].append(node_name_map.get(tgt))
79
+ json_dict["IllegalBuildDependencyGraph"].append(entry)
80
+
81
+ log.info("保存 BMC 组件构建依赖信息到: %s", path)
82
+ flags = os.O_WRONLY | os.O_CREAT | os.O_TRUNC
83
+ modes = stat.S_IWUSR | stat.S_IRUSR
84
+ with os.fdopen(os.open(path, flags, modes), 'w') as file_descriptor:
85
+ file_descriptor.write(json.dumps(json_dict, indent=4))
86
+
87
+ def visualize_graph(self, path):
88
+ subsystems = set()
89
+ for pkg in self._nodes:
90
+ subsystems.add(pkg.subsys_name)
91
+ categories = []
92
+ for subsys in subsystems:
93
+ categories.append({misc.NAME: subsys, "symbolSize": 100})
94
+ categories.append({misc.NAME: "unknown", "symbolSize": 100})
95
+ category_id_map: Dict[str, int] = dict()
96
+ for index, category in enumerate(categories):
97
+ category_id_map[category[misc.NAME]] = index
98
+
99
+ graph_nodes: List[GraphNode] = []
100
+ for pkg in self._nodes:
101
+ label_opts = None
102
+ if pkg.subsys_name == "unknown":
103
+ label_opts = opts.LabelOpts(color=misc.COLOR_RED)
104
+ if pkg.package_name in self.isolated_packages and "Library" in pkg.package_type:
105
+ label_opts = opts.LabelOpts(color=misc.COLOR_RED)
106
+ graph_nodes.append(GraphNode(
107
+ name=pkg.package_name,
108
+ symbol_size=5,
109
+ category=category_id_map.get(pkg.subsys_name, len(categories)),
110
+ label_opts=label_opts))
111
+
112
+ links: list[GraphLink] = []
113
+ for src in self.build_deps_graph:
114
+ for dest in self.build_deps_graph[src]:
115
+ if src in self.build_deps_unallowed_graph and dest in self.build_deps_unallowed_graph[src]:
116
+ links.append(GraphLink(source=src, target=dest,
117
+ linestyle_opts=opts.LineStyleOpts(color=misc.COLOR_RED, width=1.5)))
118
+ else:
119
+ links.append(GraphLink(source=src, target=dest))
120
+
121
+ log.info("保存 BMC 组件构建依赖图到 %s", path)
122
+ (Graph(init_opts=opts.InitOpts(width="100%", height="1200px", page_title="BMC构建依赖关系图"))
123
+ .add("", graph_nodes, links, categories,
124
+ repulsion=100,
125
+ is_draggable=False,
126
+ edge_symbol="arrow",
127
+ edge_symbol_size=[0, 5],
128
+ is_layout_animation=False,
129
+ label_opts=opts.LabelOpts(position="right", formatter="{b}"))
130
+ .set_global_opts(
131
+ title_opts=opts.TitleOpts(title="Graph-BMC构建依赖关系图"),
132
+ legend_opts=opts.LegendOpts(orient="vertical", pos_left="2%", pos_top="20%"))
133
+ .render(path))
134
+
135
+ def _node_build_relation(self):
136
+ for src in self._nodes:
137
+ for dest in src.requires:
138
+ self.build_deps_graph[src.package_name].add(dest.package_name)
139
+ if not self._check_build_dependency(src, dest):
140
+ self.build_dependency_allowed = False
141
+ self.build_deps_unallowed_graph[src.package_name].add(dest.package_name)
142
+
143
+ def _check_build_dependency(self, src: DepNode, tgt: DepNode):
144
+ if src.subsys_level < tgt.subsys_level:
145
+ log.error("发现不被允许的构建依赖. 源包: %s, 目标包: %s",
146
+ src.name, tgt.name)
147
+ return False
148
+ for rules in self._rules:
149
+ if rules.build_dep_check(src, tgt):
150
+ log.debug("源名: %s, 目标: %s", src.name, tgt.name)
151
+ return True
152
+ log.error("发现不被允许的构建依赖. 源包: %s, 目标包: %s", src.name, tgt.name)
153
+ return False
154
+
155
+ def _get_isolated_packages(self):
156
+ indegree: Dict[str, int] = dict()
157
+ for node in self._nodes:
158
+ indegree[node.package_name] = 0
159
+ for src in self.build_deps_graph:
160
+ for dest in self.build_deps_graph[src]:
161
+ indegree[dest] += 1
162
+
163
+ for pkg, degree in indegree.items():
164
+ if degree == 0:
165
+ self.isolated_packages.add(pkg)