Skip to content

Commit

Permalink
[antlir2][package] configurable prefix for standard tests
Browse files Browse the repository at this point in the history
Summary:
In advance of supporting incremental sendstreams with the same test setup, we
need to be able to configure a prefix in which to install and inspect the
standard features.

Test Plan:
```
❯ buck2 test fbcode//antlir/antlir2/test_images/package/...
Buck UI: https://www.internalfb.com/buck2/7c92159a-e96e-49b4-9c1e-1d7da11e69c7
Test UI: https://www.internalfb.com/intern/testinfra/testrun/11821949074804378
Network: Up: 2.6GiB  Down: 6.9GiB  (reSessionID-f2577f23-a638-44f6-99c4-13b9438a2013)
Jobs completed: 1045620. Time elapsed: 9:03.0s.
Cache hits: 99%. Commands: 59717 (cached: 59208, remote: 98, local: 411). Fallback: 12/509
Tests finished: Pass 178. Fail 0. Fatal 0. Skip 0. Build failure 0
```

Reviewed By: epilatow

Differential Revision: D64186147

fbshipit-source-id: b8902b5cef81c2ed03a20fe6cd9b78b488fd8f8e
  • Loading branch information
vmagro authored and facebook-github-bot committed Oct 16, 2024
1 parent 9087023 commit a3ff6b3
Show file tree
Hide file tree
Showing 10 changed files with 206 additions and 144 deletions.
64 changes: 2 additions & 62 deletions antlir/antlir2/test_images/package/BUCK
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
load("//antlir/antlir2/bzl/feature:defs.bzl", "feature")
load("//antlir/antlir2/bzl/image:defs.bzl", "image")
load("//antlir/bzl:build_defs.bzl", "buck_genrule", "export_file")
load(":defs.bzl", "package_feature", "test_in_layer")
load(":defs.bzl", "package_feature", "standard_features", "test_in_layer")

oncall("antlir")

Expand All @@ -14,67 +14,7 @@ buck_genrule(
image.layer(
name = "standard",
features = [
feature.install(
src = ":antlir2-large-file-256M",
dst = "/antlir2-large-file-256M",
),
feature.ensure_dirs_exist(dirs = "/default-dir"),
feature.install_text(
dst = "/only-readable-by-root",
mode = 0o000,
text = "Only readable by root",
),
feature.install_text(
dst = "/default-dir/executable",
mode = "a+rx",
text = "#!/bin/bash\necho hello",
),
feature.install_text(
dst = "/i-am-owned-by-nonstandard",
group = 43,
text = "42:43",
user = 42,
),
feature.install_text(
dst = "/i-have-xattrs",
text = "xattrs are cool",
xattrs = {
"user.baz": "qux",
"user.foo": "bar",
},
),
feature.install(
src = "antlir//antlir:empty",
dst = "/i-have-caps",
xattrs = {
"security.capability": "0sAQAAAoAAAAAAAAAAAAAAAAAAAAA=",
},
),
feature.ensure_file_symlink(
link = "/absolute-file-symlink",
target = "/default-dir/executable",
),
feature.ensure_file_symlink(
link = "/default-dir/relative-file-symlink",
target = "executable",
),
feature.ensure_dir_symlink(
link = "/absolute-dir-symlink",
target = "/default-dir",
),
feature.ensure_dir_symlink(
link = "/relative-dir-symlink",
target = "default-dir",
),
feature.ensure_dirs_exist(dirs = "/hardlink"),
feature.install_text(
dst = "/hardlink/hello",
text = "Hello world\n",
),
feature.hardlink(
link = "/hardlink/aloha",
target = "/hardlink/hello",
),
standard_features(prefix = "/"),
],
)

Expand Down
34 changes: 19 additions & 15 deletions antlir/antlir2/test_images/package/cpio/stub.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,19 +10,23 @@ use std::process::Command;

use cap_std::fs::Dir;

pub(crate) fn open() -> Dir {
let archive = File::open("/package.cpio").expect("could not open /package.cpio");
let out = Command::new("cpio")
.arg("-idmv")
.current_dir("/package")
.stdin(archive)
.output()
.expect("failed to run cpio");
assert!(
out.status.success(),
"cpio failed:{}",
String::from_utf8_lossy(&out.stderr)
);
Dir::open_ambient_dir("/package", cap_std::ambient_authority())
.expect("could not open /package")
pub(crate) struct StubImpl;

impl crate::Stub for StubImpl {
fn open() -> Dir {
let archive = File::open("/package.cpio").expect("could not open /package.cpio");
let out = Command::new("cpio")
.arg("-idmv")
.current_dir("/package")
.stdin(archive)
.output()
.expect("failed to run cpio");
assert!(
out.status.success(),
"cpio failed:{}",
String::from_utf8_lossy(&out.stderr)
);
Dir::open_ambient_dir("/package", cap_std::ambient_authority())
.expect("could not open /package")
}
}
68 changes: 68 additions & 0 deletions antlir/antlir2/test_images/package/defs.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
# This source code is licensed under the MIT license found in the
# LICENSE file in the root directory of this source tree.

load("@prelude//:paths.bzl", "paths")
load("//antlir/antlir2/bzl/feature:defs.bzl", "feature")
load("//antlir/antlir2/bzl/image:defs.bzl", "image")
load("//antlir/antlir2/testing:image_test.bzl", "image_rust_test")
Expand Down Expand Up @@ -68,3 +69,70 @@ def test_in_layer(
omit_features = omit_package_features,
)
)

def standard_features(
*,
prefix: str):
return [
feature.install(
src = "//antlir/antlir2/test_images/package:antlir2-large-file-256M",
dst = paths.join(prefix, "antlir2-large-file-256M"),
),
feature.ensure_dirs_exist(dirs = paths.join(prefix, "default-dir")),
feature.install_text(
dst = paths.join(prefix, "only-readable-by-root"),
mode = 0o000,
text = "Only readable by root",
),
feature.install_text(
dst = paths.join(prefix, "default-dir/executable"),
mode = "a+rx",
text = "#!/bin/bash\necho hello",
),
feature.install_text(
dst = paths.join(prefix, "i-am-owned-by-nonstandard"),
group = 43,
text = "42:43",
user = 42,
),
feature.install_text(
dst = paths.join(prefix, "i-have-xattrs"),
text = "xattrs are cool",
xattrs = {
"user.baz": "qux",
"user.foo": "bar",
},
),
feature.install(
src = "antlir//antlir:empty",
dst = paths.join(prefix, "i-have-caps"),
xattrs = {
"security.capability": "0sAQAAAoAAAAAAAAAAAAAAAAAAAAA=",
},
),
feature.ensure_file_symlink(
link = paths.join(prefix, "absolute-file-symlink"),
target = paths.join(prefix, "default-dir/executable"),
),
feature.ensure_file_symlink(
link = paths.join(prefix, "default-dir/relative-file-symlink"),
target = "executable",
),
feature.ensure_dir_symlink(
link = paths.join(prefix, "absolute-dir-symlink"),
target = paths.join(prefix, "default-dir"),
),
feature.ensure_dir_symlink(
link = paths.join(prefix, "relative-dir-symlink"),
target = "default-dir",
),
feature.ensure_dirs_exist(dirs = paths.join(prefix, "hardlink")),
feature.install_text(
dst = paths.join(prefix, "hardlink/hello"),
text = "Hello world\n",
),
feature.hardlink(
link = paths.join(prefix, "hardlink/aloha"),
target = paths.join(prefix, "hardlink/hello"),
),
]
30 changes: 17 additions & 13 deletions antlir/antlir2/test_images/package/erofs/stub.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,21 @@ use std::process::Command;

use cap_std::fs::Dir;

pub(crate) fn open() -> Dir {
let out = Command::new("erofsfuse")
.arg("/package.erofs")
.arg("/package")
.output()
.expect("failed to run erofsfuse");
assert!(
out.status.success(),
"erofsfuse failed:{}",
String::from_utf8_lossy(&out.stderr)
);
Dir::open_ambient_dir("/package", cap_std::ambient_authority())
.expect("could not open /package")
pub(crate) struct StubImpl;

impl crate::Stub for StubImpl {
fn open() -> Dir {
let out = Command::new("erofsfuse")
.arg("/package.erofs")
.arg("/package")
.output()
.expect("failed to run erofsfuse");
assert!(
out.status.success(),
"erofsfuse failed:{}",
String::from_utf8_lossy(&out.stderr)
);
Dir::open_ambient_dir("/package", cap_std::ambient_authority())
.expect("could not open /package")
}
}
30 changes: 17 additions & 13 deletions antlir/antlir2/test_images/package/ext3/stub.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,21 @@ use std::process::Command;

use cap_std::fs::Dir;

pub(crate) fn open() -> Dir {
let out = Command::new("fuse2fs")
.arg("/package.ext3")
.arg("/package")
.output()
.expect("failed to run fuse2fs");
assert!(
out.status.success(),
"fuse2fs failed:{}",
String::from_utf8_lossy(&out.stderr)
);
Dir::open_ambient_dir("/package", cap_std::ambient_authority())
.expect("could not open /package")
pub(crate) struct StubImpl;

impl crate::Stub for StubImpl {
fn open() -> Dir {
let out = Command::new("fuse2fs")
.arg("/package.ext3")
.arg("/package")
.output()
.expect("failed to run fuse2fs");
assert!(
out.status.success(),
"fuse2fs failed:{}",
String::from_utf8_lossy(&out.stderr)
);
Dir::open_ambient_dir("/package", cap_std::ambient_authority())
.expect("could not open /package")
}
}
9 changes: 7 additions & 2 deletions antlir/antlir2/test_images/package/raw_layer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,11 @@

use cap_std::fs::Dir;

pub(crate) fn open() -> Dir {
Dir::open_ambient_dir("/layer", cap_std::ambient_authority()).expect("could not open /layer")
pub(crate) struct StubImpl;

impl crate::Stub for StubImpl {
fn open() -> Dir {
Dir::open_ambient_dir("/layer", cap_std::ambient_authority())
.expect("could not open /layer")
}
}
12 changes: 10 additions & 2 deletions antlir/antlir2/test_images/package/sendstream/BUCK
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
load("//antlir/antlir2/bzl/feature:defs.bzl", "feature")
load("//antlir/antlir2/bzl/image:defs.bzl", "image")
load("//antlir/antlir2/bzl/package:defs.bzl", "package")
load("//antlir/antlir2/test_images/package:defs.bzl", "package_feature", "test_in_layer")
load("//antlir/antlir2/test_images/package:defs.bzl", "package_feature", "standard_features", "test_in_layer")
load("//antlir/bzl:build_defs.bzl", "rust_unittest")

oncall("antlir")
Expand All @@ -20,11 +20,19 @@ VARIANTS = {
},
}

image.layer(
name = "standard",
features = [
feature.ensure_dirs_exist(dirs = "/standard"),
standard_features(prefix = "/standard"),
],
)

[
[
package.sendstream_v2(
name = name + ".sendstream.v2",
layer = "//antlir/antlir2/test_images/package:standard",
layer = ":standard",
rootless = args.get("rootless", None),
volume_name = args.get("volume_name", None),
),
Expand Down
16 changes: 13 additions & 3 deletions antlir/antlir2/test_images/package/sendstream/stub.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,19 @@
* LICENSE file in the root directory of this source tree.
*/

use std::path::Path;

use cap_std::fs::Dir;

pub(crate) fn open() -> Dir {
Dir::open_ambient_dir("/package", cap_std::ambient_authority())
.expect("could not open /package")
pub(crate) struct StubImpl;

impl crate::Stub for StubImpl {
fn open() -> Dir {
Dir::open_ambient_dir("/package/standard", cap_std::ambient_authority())
.expect("could not open /package")
}

fn absolute_symlink_root() -> &'static Path {
Path::new("/standard")
}
}
Loading

0 comments on commit a3ff6b3

Please sign in to comment.