Skip to content

Commit

Permalink
refactor: Refactor bazel binaries to only include main.py (magma#12154)
Browse files Browse the repository at this point in the history
* refactor(redirectd): split bazel python binary

Signed-off-by: Lars Kreutzer <lars.kreutzer@tngtech.com>

* refactor(policydb): split bazel python binary

Signed-off-by: Lars Kreutzer <lars.kreutzer@tngtech.com>

* refactor(eventd): split bazel python binary

Signed-off-by: Lars Kreutzer <lars.kreutzer@tngtech.com>

* refactor(mobilityd): split bazel python binary

Signed-off-by: Lars Kreutzer <lars.kreutzer@tngtech.com>
  • Loading branch information
LKreutzer authored and vikramgreddy committed Mar 23, 2022
1 parent 3b3dd6e commit 4bd7881
Show file tree
Hide file tree
Showing 11 changed files with 203 additions and 80 deletions.
1 change: 1 addition & 0 deletions bazel/external/requirements.in
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ pycryptodome
spyne
aiohttp
lxml==4.7.1
typing_extensions

# bazelbase container requirements
hiredis
Expand Down
6 changes: 5 additions & 1 deletion bazel/external/requirements.txt

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

39 changes: 26 additions & 13 deletions lte/gateway/python/magma/mobilityd/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
# limitations under the License.

load("@python_deps//:requirements.bzl", "requirement")
load("@rules_python//python:defs.bzl", "py_binary")
load("@rules_python//python:defs.bzl", "py_binary", "py_library")

MAGMA_ROOT = "../../../../../"

Expand All @@ -20,6 +20,28 @@ LTE_ROOT = "{}lte/gateway/python".format(MAGMA_ROOT)

py_binary(
name = "mobilityd",
srcs = ["main.py"],
imports = [
LTE_ROOT,
ORC8R_ROOT,
],
# legacy_create_init = False is required to fix issues in module import, see https://github.com/rules-proto-grpc/rules_proto_grpc/issues/145
legacy_create_init = False,
main = "main.py",
python_version = "PY3",
visibility = ["//visibility:private"],
deps = [
":mobilityd_lib",
"//lte/protos:mconfigs_python_proto",
"//lte/protos:subscriberdb_python_grpc",
"//orc8r/gateway/python/magma/common:sentry",
"//orc8r/gateway/python/magma/common:service",
"//orc8r/gateway/python/magma/common/redis:client",
],
)

py_library(
name = "mobilityd_lib",
srcs = [
"dhcp_client.py",
"dhcp_desc.py",
Expand All @@ -33,7 +55,6 @@ py_binary(
"ip_descriptor_map.py",
"ipv6_allocator_pool.py",
"mac.py",
"main.py",
"metrics.py",
"mobility_store.py",
"rpc_servicer.py",
Expand All @@ -42,26 +63,18 @@ py_binary(
"uplink_gw.py",
"utils.py",
],
imports = [
LTE_ROOT,
ORC8R_ROOT,
],
# legacy_create_init = False is required to fix issues in module import, see https://github.com/rules-proto-grpc/rules_proto_grpc/issues/145
legacy_create_init = False,
main = "main.py",
python_version = "PY3",
visibility = ["//visibility:public"],
deps = [
"//lte/gateway/python/magma/subscriberdb:sid",
"//lte/protos:keyval_python_proto",
"//lte/protos:mconfigs_python_proto",
"//lte/protos:mobilityd_python_grpc",
"//lte/protos:mobilityd_python_proto",
"//lte/protos:subscriberdb_python_grpc",
"//orc8r/gateway/python/magma/common:rpc_utils",
"//orc8r/gateway/python/magma/common:sentry",
"//orc8r/gateway/python/magma/common:service",
"//orc8r/gateway/python/magma/common/redis:client",
requirement("netifaces"),
requirement("scapy"),
requirement("typing_extensions"),
requirement("prometheus_client"),
],
)
50 changes: 39 additions & 11 deletions lte/gateway/python/magma/mobilityd/tests/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -13,84 +13,112 @@ load("@python_deps//:requirements.bzl", "requirement")
load("//bazel:python_test.bzl", "pytest_test")
load("//bazel:test_constants.bzl", "TAG_SUDO_TEST")

MAGMA_ROOT = "../../../../../../"

ORC8R_ROOT = "{}orc8r/gateway/python".format(MAGMA_ROOT)

LTE_ROOT = "{}lte/gateway/python".format(MAGMA_ROOT)

pytest_test(
name = "ip_alloc_dhcp_test",
srcs = ["ip_alloc_dhcp_test.py"],
imports = [
LTE_ROOT,
ORC8R_ROOT,
],
tags = TAG_SUDO_TEST,
deps = [
"//lte/gateway/python/magma/mobilityd",
requirement("fakeredis"),
"//lte/gateway/python/magma/mobilityd:mobilityd_lib",
"//lte/gateway/python/magma/pipelined:bridge_util",
"//orc8r/gateway/python/magma/common/redis:client",
requirement("fakeredis"),
],
)

pytest_test(
name = "ip_allocator_dhcp_mac_addr_test",
srcs = ["ip_allocator_dhcp_mac_addr_test.py"],
imports = [LTE_ROOT],
deps = [
"//lte/gateway/python/magma/mobilityd",
"//lte/gateway/python/magma/mobilityd:mobilityd_lib",
requirement("fakeredis"),
],
)

pytest_test(
name = "test_dhcp_client",
srcs = ["test_dhcp_client.py"],
imports = [LTE_ROOT],
tags = TAG_SUDO_TEST,
deps = [
"//lte/gateway/python/magma/mobilityd",
requirement("freezegun"),
"//lte/gateway/python/magma/mobilityd:mobilityd_lib",
"//lte/gateway/python/magma/pipelined:bridge_util",
requirement("freezegun"),
],
)

pytest_test(
name = "test_ipv6_allocator",
srcs = ["test_ipv6_allocator.py"],
imports = [
LTE_ROOT,
ORC8R_ROOT,
],
deps = [
"//lte/gateway/python/magma/mobilityd",
"//lte/gateway/python/magma/mobilityd:mobilityd_lib",
requirement("fakeredis"),
],
)

pytest_test(
name = "test_multi_apn_ip_alloc",
srcs = ["test_multi_apn_ip_alloc.py"],
imports = [
LTE_ROOT,
ORC8R_ROOT,
],
deps = [
"//lte/gateway/python/magma/mobilityd",
"//lte/gateway/python/magma/mobilityd:mobilityd_lib",
requirement("fakeredis"),
],
)

pytest_test(
name = "test_static_ip_alloc",
srcs = ["test_static_ip_alloc.py"],
imports = [LTE_ROOT],
deps = [
":test_multi_apn_ip_alloc",
"//lte/gateway/python/magma/mobilityd",
"//lte/gateway/python/magma/mobilityd:mobilityd_lib",
],
)

pytest_test(
name = "test_static_ipv6_alloc",
srcs = ["test_static_ipv6_alloc.py"],
imports = [LTE_ROOT],
deps = [
":test_multi_apn_ip_alloc",
"//lte/gateway/python/magma/mobilityd",
"//lte/gateway/python/magma/mobilityd:mobilityd_lib",
],
)

pytest_test(
name = "test_uplink_gw",
srcs = ["test_uplink_gw.py"],
deps = ["//lte/gateway/python/magma/mobilityd"],
imports = [LTE_ROOT],
deps = ["//lte/gateway/python/magma/mobilityd:mobilityd_lib"],
)

pytest_test(
name = "ip_allocator_tests",
srcs = ["ip_allocator_tests.py"],
imports = [
LTE_ROOT,
ORC8R_ROOT,
],
deps = [
"//lte/gateway/python/magma/mobilityd:mobilityd_lib",
requirement("fakeredis"),
"//lte/gateway/python/magma/mobilityd",
],
)
35 changes: 24 additions & 11 deletions lte/gateway/python/magma/policydb/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,7 @@ LTE_ROOT = "{}lte/gateway/python".format(MAGMA_ROOT)

py_binary(
name = "policydb",
srcs = [
"apn_rule_map_store.py",
"basename_store.py",
"main.py",
"rating_group_store.py",
"reauth_handler.py",
"rule_map_store.py",
"rule_store.py",
"streamer_callback.py",
],
srcs = ["main.py"],
imports = [
LTE_ROOT,
ORC8R_ROOT,
Expand All @@ -37,15 +28,37 @@ py_binary(
legacy_create_init = False,
main = "main.py",
python_version = "PY3",
visibility = ["//visibility:public"],
visibility = ["//visibility:private"],
deps = [
":policydb_lib",
"//lte/gateway/python/magma/policydb/servicers:policy_servicer",
"//lte/gateway/python/magma/policydb/servicers:session_servicer",
"//lte/protos:mconfigs_python_proto",
"//lte/protos:policydb_python_grpc",
"//lte/protos:session_manager_python_grpc",
"//orc8r/gateway/python/magma/common:sentry",
"//orc8r/gateway/python/magma/common:service",
"//orc8r/gateway/python/magma/common:streamer",
],
)

py_library(
name = "policydb_lib",
srcs = [
"apn_rule_map_store.py",
"basename_store.py",
"rating_group_store.py",
"reauth_handler.py",
"rule_map_store.py",
"rule_store.py",
"streamer_callback.py",
],
visibility = ["//visibility:public"],
deps = [
":default_rules",
"//orc8r/gateway/python/magma/common:rpc_utils",
"//orc8r/gateway/python/magma/common:sentry",
"//orc8r/gateway/python/magma/common:serialization_utils",
"//orc8r/gateway/python/magma/common:service",
"//orc8r/gateway/python/magma/common:streamer",
"//orc8r/gateway/python/magma/common/redis:client",
Expand Down
44 changes: 40 additions & 4 deletions lte/gateway/python/magma/policydb/tests/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -13,33 +13,69 @@ load("@python_deps//:requirements.bzl", "requirement")
load("@rules_python//python:defs.bzl", "py_library")
load("//bazel:python_test.bzl", "pytest_test")

MAGMA_ROOT = "../../../../../../"

ORC8R_ROOT = "{}orc8r/gateway/python".format(MAGMA_ROOT)

LTE_ROOT = "{}lte/gateway/python".format(MAGMA_ROOT)

pytest_test(
name = "test_policy_servicer",
srcs = ["test_policy_servicer.py"],
imports = [
LTE_ROOT,
ORC8R_ROOT,
],
deps = [
"//lte/gateway/python/magma/policydb",
"//lte/gateway/python/magma/policydb:policydb_lib",
"//lte/gateway/python/magma/policydb/servicers:policy_servicer",
"//lte/protos:policydb_python_grpc",
"//lte/protos:session_manager_python_grpc",
requirement("grpcio"),
],
)

pytest_test(
name = "test_reauth_handler",
srcs = ["test_reauth_handler.py"],
deps = ["//lte/gateway/python/magma/policydb"],
imports = [
LTE_ROOT,
ORC8R_ROOT,
],
deps = [
"//lte/gateway/python/magma/policydb:policydb_lib",
"//lte/protos:policydb_python_grpc",
"//lte/protos:session_manager_python_grpc",
],
)

pytest_test(
name = "test_session_servicer",
srcs = ["test_session_servicer.py"],
deps = ["//lte/gateway/python/magma/policydb"],
imports = [
LTE_ROOT,
ORC8R_ROOT,
],
deps = [
"//lte/gateway/python/magma/policydb:policydb_lib",
"//lte/gateway/python/magma/policydb/servicers:session_servicer",
"//lte/protos:policydb_python_grpc",
"//lte/protos:session_manager_python_grpc",
],
)

pytest_test(
name = "test_streamer_callback",
srcs = ["test_streamer_callback.py"],
imports = [
LTE_ROOT,
ORC8R_ROOT,
],
deps = [
":mock_stubs",
"//lte/gateway/python/magma/policydb",
"//lte/gateway/python/magma/policydb:policydb_lib",
"//lte/protos:policydb_python_grpc",
"//lte/protos:session_manager_python_grpc",
],
)

Expand Down

0 comments on commit 4bd7881

Please sign in to comment.