Skip to content

Commit c9160e7

Browse files
[Nexthop] Add basic utilities for FBOSS Image Builder
Provide basic tools and utiulities for the distro_cli build system. - Add custom exception classes for structured error handling - Define shared constants for Docker configuration and build settings - Implement path resolution utilities for components - Define test data fixture for image manifest validation These core utilities provide the base infrastructure required by all downstream components including Docker integration, artifact handling, and build orchestration.
1 parent 13ebe18 commit c9160e7

File tree

4 files changed

+140
-8
lines changed

4 files changed

+140
-8
lines changed
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# Copyright (c) 2004-present, Facebook, Inc.
2+
# All rights reserved.
3+
#
4+
# This source code is licensed under the BSD-style license found in the
5+
# LICENSE file in the root directory of this source tree. An additional grant
6+
# of patent rights can be found in the PATENTS file in the same directory.
7+
8+
"""Constants for FBOSS image builder."""
9+
10+
# Docker image names
11+
FBOSS_BUILDER_IMAGE = "fboss_builder"
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
# Copyright (c) 2004-present, Facebook, Inc.
2+
# All rights reserved.
3+
#
4+
# This source code is licensed under the BSD-style license found in the
5+
# LICENSE file in the root directory of this source tree. An additional grant
6+
# of patent rights can be found in the PATENTS file in the same directory.
7+
8+
"""Exception definitions for FBOSS image builder."""
9+
10+
11+
class FbossImageError(Exception):
12+
"""Base exception for all fboss-image errors.
13+
14+
All custom exceptions in the fboss-image tool should inherit from this.
15+
This allows the top-level CLI handler to catch and format errors appropriately
16+
before returning a non-zero exit code.
17+
"""
18+
19+
20+
class BuildError(FbossImageError):
21+
"""Build command failed.
22+
23+
Raised when a component build fails, including:
24+
- Build script/command not found
25+
- Build process returned non-zero exit code
26+
- Build output validation failed
27+
"""
28+
29+
30+
class ManifestError(FbossImageError):
31+
"""Manifest parsing or validation failed.
32+
33+
Raised when:
34+
- Manifest file not found or invalid JSON
35+
- Required fields missing
36+
- Invalid manifest structure
37+
"""
38+
39+
40+
class ArtifactError(FbossImageError):
41+
"""Artifact operation failed.
42+
43+
Raised when:
44+
- Expected artifact not found after build
45+
- Artifact download failed
46+
- Artifact cache operation failed
47+
"""
48+
49+
50+
class ComponentError(FbossImageError):
51+
"""Component-specific error.
52+
53+
Raised when:
54+
- Component not found in manifest
55+
- Component configuration invalid
56+
- Component builder not implemented
57+
"""
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
# Copyright (c) 2004-present, Facebook, Inc.
2+
# All rights reserved.
3+
#
4+
# This source code is licensed under the BSD-style license found in the
5+
# LICENSE file in the root directory of this source tree. An additional grant
6+
# of patent rights can be found in the PATENTS file in the same directory.
7+
8+
"""Path resolution utilities for FBOSS image builder."""
9+
10+
from functools import lru_cache
11+
from pathlib import Path
12+
13+
14+
@lru_cache(maxsize=1)
15+
def get_root_dir() -> Path:
16+
"""Find the repository root directory.
17+
18+
This works by walking up from the current file until we find
19+
the 'fboss-image' directory, then returning its parent.
20+
21+
Additionally verifies that both 'fboss-image' and 'fboss' directories
22+
exist at the root to ensure we're in the correct repository structure.
23+
24+
The result is cached after the first call for performance.
25+
26+
Returns:
27+
Path to repository root directory
28+
29+
Raises:
30+
RuntimeError: If the root directory cannot be determined
31+
"""
32+
current = Path(__file__).resolve()
33+
34+
# Walk up the directory tree looking for fboss-image
35+
for parent in current.parents:
36+
if (parent / "fboss-image").is_dir() and (parent / "fboss").is_dir():
37+
return parent
38+
39+
raise RuntimeError(
40+
f"Could not find repository root from {current}. "
41+
f"Expected to find 'fboss-image' and 'fboss' directories in parent path."
42+
)
43+
44+
45+
def get_abs_path(path_parts: str | list[str]) -> Path:
46+
"""Get absolute path by joining the parent of 'fboss-image' with provided path parts.
47+
48+
Args:
49+
path_parts: Either a string like "fboss-image/distro_cli/tools" or
50+
a list like ["fboss-image", "distro_cli", "tools"]
51+
52+
Returns:
53+
Absolute path
54+
55+
Examples:
56+
get_abs_path("fboss-image/distro_cli/tools")
57+
get_abs_path(["fboss-image", "distro_cli", "tools"])
58+
get_abs_path("fboss/oss/scripts")
59+
"""
60+
root = get_root_dir()
61+
62+
if isinstance(path_parts, str):
63+
return root / path_parts
64+
return root.joinpath(*path_parts)

fboss-image/distro_cli/tests/dev_image.json

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,27 @@
11
{
22
"distribution_formats": {
3-
"onie": "FBOSS-k6.4.3.bin",
4-
"usb": "FBOSS-k6.4.3.iso"
3+
"onie": "FBOSS-k6.11.1.bin",
4+
"usb": "FBOSS-k6.11.1iso"
55
},
66
"kernel": {
7-
"download": "https://artifact.github.com/nexthop-ai/fboss/fboss-oss_kernel_v6.4.3.tar"
7+
"download": "https://artifact.github.com/nexthop-ai/fboss/fboss-oss_kernel_v6.11.1.tar"
88
},
99
"other_dependencies": [
1010
{"download": "https://artifact.github.com/nexthop-ai/fsdb/fsdb.rpm"},
1111
{"download": "file:vendor_debug_tools/tools.rpm"}
1212
],
1313
"fboss-platform-stack": {
14-
"execute": ["fboss/fboss/oss/scripts/build.py", "platformstack"]
14+
"execute": ["../../../../fboss/fboss/oss/scripts/build.py", "platformstack"]
1515
},
1616
"bsps": [
17-
{"execute": "vendor_bsp/build.make"},
18-
{"execute": "fboss/oss/reference_bsp/build.py"}
17+
{"execute": ["../../../../vendor_bsp/build.make"]},
18+
{"execute": ["../../../../fboss/oss/reference_bsp/build.py"]}
1919
],
2020
"sai": {
21-
"execute": "fboss_brcm_sai/build.sh"
21+
"execute": ["../../../../fboss_brcm_sai/build.sh"]
2222
},
2323
"fboss-forwarding-stack": {
24-
"execute": ["fboss/fboss/oss/scripts/build.py", "forwardingstack"]
24+
"execute": ["../../../../fboss/fboss/oss/scripts/build.py", "forwardingstack"]
2525
},
2626
"image_build_hooks": {
2727
"after_pkgs": "additional_os_pkgs.xml"

0 commit comments

Comments
 (0)