Mount boot partition into container on Supervisor start

As the Supervisor is a privileged container, it has access to host /dev, and therefore has access
to boot, data, and state balenaOS partitions. This commit sets up the framework for the following:

- Finds the /dev partition that corresponds to each partition based on partition label
- Mounts the partitions into set mountpoints in the device
- Removes reliance on env vars and mountpoints provided by host's start-balena-supervisor script
- Simplifies host path querying by centralizing these queries through methods in lib/host-utils.ts

This particular changes env vars for and mounts the boot partition.

Since the Supervisor would no longer rely on container `run` arguments provided by a host script,
this change moves Supervisor closer to being able to start itself (Supervisor-as-an-app).

Change-type: minor
Signed-off-by: Christina Ying Wang <christina@balena.io>
This commit is contained in:
Christina Ying Wang
2023-02-20 22:11:27 -08:00
committed by Christina W
parent 9522c15ecd
commit 49ee1042a8
31 changed files with 285 additions and 290 deletions

View File

@ -5,13 +5,13 @@ import { spy, SinonSpy } from 'sinon';
import mock = require('mock-fs');
import * as fsUtils from '~/lib/fs-utils';
import { rootMountPoint } from '~/lib/constants';
import { pathOnRoot } from '~/lib/host-utils';
describe('lib/fs-utils', () => {
const testFileName1 = 'file.1';
const testFileName2 = 'file.2';
const testFile1 = path.join(rootMountPoint, testFileName1);
const testFile2 = path.join(rootMountPoint, testFileName2);
const testFile1 = pathOnRoot(testFileName1);
const testFile2 = pathOnRoot(testFileName2);
const mockFs = () => {
mock({
@ -75,7 +75,7 @@ describe('lib/fs-utils', () => {
it('should rename a file', async () => {
await fsUtils.safeRename(testFile1, testFile1 + 'rename');
const dirContents = await fs.readdir(rootMountPoint);
const dirContents = await fs.readdir(pathOnRoot());
expect(dirContents).to.have.length(2);
expect(dirContents).to.not.include(testFileName1);
expect(dirContents).to.include(testFileName1 + 'rename');
@ -83,7 +83,7 @@ describe('lib/fs-utils', () => {
it('should replace an existing file', async () => {
await fsUtils.safeRename(testFile1, testFile2);
const dirContents = await fs.readdir(rootMountPoint);
const dirContents = await fs.readdir(pathOnRoot());
expect(dirContents).to.have.length(1);
expect(dirContents).to.include(testFileName2);
expect(dirContents).to.not.include(testFileName1);
@ -103,28 +103,14 @@ describe('lib/fs-utils', () => {
});
});
describe('pathExistsOnHost', () => {
before(mockFs);
after(unmockFs);
it('should return whether a file exists in host OS fs', async () => {
expect(await fsUtils.pathExistsOnHost(testFileName1)).to.be.true;
await fs.unlink(testFile1);
expect(await fsUtils.pathExistsOnHost(testFileName1)).to.be.false;
});
});
describe('mkdirp', () => {
before(mockFs);
after(unmockFs);
it('should recursively create directories', async () => {
await fsUtils.mkdirp(
path.join(rootMountPoint, 'test1', 'test2', 'test3'),
);
expect(() =>
fs.readdir(path.join(rootMountPoint, 'test1', 'test2', 'test3')),
).to.not.throw();
const directory = path.join(pathOnRoot('test1'), 'test2', 'test3');
await fsUtils.mkdirp(directory);
expect(() => fs.readdir(directory)).to.not.throw();
});
});
@ -134,24 +120,12 @@ describe('lib/fs-utils', () => {
it('should unlink a single file', async () => {
await fsUtils.unlinkAll(testFile1);
expect(await fs.readdir(rootMountPoint)).to.not.include(testFileName1);
expect(await fs.readdir(pathOnRoot())).to.not.include(testFileName1);
});
it('should unlink multiple files', async () => {
await fsUtils.unlinkAll(testFile1, testFile2);
expect(await fs.readdir(rootMountPoint)).to.have.length(0);
});
});
describe('getPathOnHost', () => {
before(mockFs);
after(unmockFs);
it("should return the paths of one or more files as they exist on host OS's root", async () => {
expect(fsUtils.getPathOnHost(testFileName1)).to.deep.equal(testFile1);
expect(fsUtils.getPathOnHost(testFileName1, testFileName2)).to.deep.equal(
[testFile1, testFile2],
);
expect(await fs.readdir(pathOnRoot())).to.have.length(0);
});
});