Merge pull request #1882 from Chris-Peterson444/link2doc-ai-user-data-FR-5802
This commit is contained in:
commit
e3a0f6d215
|
@ -28,6 +28,7 @@ switch.
|
|||
"""
|
||||
|
||||
import argparse
|
||||
import io
|
||||
import json
|
||||
|
||||
import jsonschema
|
||||
|
@ -53,13 +54,28 @@ def main() -> None:
|
|||
|
||||
args = vars(parser.parse_args())
|
||||
|
||||
if args["expect-cloudconfig"]:
|
||||
assert args["input"].readline() == "#cloud-config\n"
|
||||
get_autoinstall_data = lambda data: data["autoinstall"]
|
||||
else:
|
||||
get_autoinstall_data = lambda data: data
|
||||
user_data: io.TextIOWrapper = args["input"]
|
||||
|
||||
data = yaml.safe_load(args["input"])
|
||||
if args["expect-cloudconfig"]:
|
||||
assert user_data.readline() == "#cloud-config\n"
|
||||
def get_autoinstall_data(data): return data["autoinstall"]
|
||||
else:
|
||||
def get_autoinstall_data(data): return data
|
||||
|
||||
# Verify autoinstall doc link is in the file
|
||||
|
||||
stream_pos: int = user_data.tell()
|
||||
|
||||
data: str = user_data.read()
|
||||
|
||||
link: str = "https://canonical-subiquity.readthedocs-hosted.com/en/latest/reference/autoinstall-reference.html" # noqa: E501
|
||||
|
||||
assert link in data
|
||||
|
||||
# Verify autoinstall schema
|
||||
user_data.seek(stream_pos)
|
||||
|
||||
data = yaml.safe_load(user_data)
|
||||
|
||||
jsonschema.validate(get_autoinstall_data(data),
|
||||
json.load(args["json_schema"]))
|
||||
|
|
|
@ -166,6 +166,20 @@ class InstallController(SubiquityController):
|
|||
and self.model.source.current.variant != "core"
|
||||
)
|
||||
|
||||
def write_autoinstall_config(self) -> None:
|
||||
autoinstall_path = os.path.join(
|
||||
self.app.root, "var/log/installer/autoinstall-user-data"
|
||||
)
|
||||
autoinstall_config = (
|
||||
"#cloud-config\n"
|
||||
"# See the auto install documentation at:"
|
||||
"# https://canonical-subiquity.readthedocs-hosted.com/en/latest/reference/autoinstall-reference.html\n" # noqa: E501
|
||||
+ yaml.dump({"autoinstall": self.app.make_autoinstall()})
|
||||
)
|
||||
# As autoinstall-user-data contains a password hash, we want this file
|
||||
# to have a very restrictive mode and ownership.
|
||||
write_file(autoinstall_path, autoinstall_config, mode=0o400, group="root")
|
||||
|
||||
@with_context(description="configuring apt", level="INFO", childlevel="DEBUG")
|
||||
async def configure_apt(self, *, context):
|
||||
mirror = self.app.controllers.Mirror
|
||||
|
@ -683,15 +697,7 @@ class InstallController(SubiquityController):
|
|||
description="final system configuration", level="INFO", childlevel="DEBUG"
|
||||
)
|
||||
async def postinstall(self, *, context):
|
||||
autoinstall_path = os.path.join(
|
||||
self.app.root, "var/log/installer/autoinstall-user-data"
|
||||
)
|
||||
autoinstall_config = "#cloud-config\n" + yaml.dump(
|
||||
{"autoinstall": self.app.make_autoinstall()}
|
||||
)
|
||||
# As autoinstall-user-data contains a password hash, we want this file
|
||||
# to have a very restrictive mode and ownership.
|
||||
write_file(autoinstall_path, autoinstall_config, mode=0o400, group="root")
|
||||
self.write_autoinstall_config()
|
||||
try:
|
||||
if self.supports_apt():
|
||||
packages = await self.get_target_packages(context=context)
|
||||
|
|
|
@ -198,6 +198,7 @@ class TestInstallController(unittest.IsolatedAsyncioTestCase):
|
|||
def setUp(self):
|
||||
self.controller = InstallController(make_app())
|
||||
self.controller.model.target = tempfile.mkdtemp()
|
||||
self.controller.app.root = tempfile.mkdtemp()
|
||||
os.makedirs(os.path.join(self.controller.model.target, "etc/grub.d"))
|
||||
self.addCleanup(shutil.rmtree, self.controller.model.target)
|
||||
|
||||
|
@ -384,3 +385,15 @@ class TestInstallController(unittest.IsolatedAsyncioTestCase):
|
|||
async def test_postinstall_platform_amd64(self, arun, machine):
|
||||
await self.controller.platform_postinstall()
|
||||
arun.assert_not_called()
|
||||
|
||||
async def test_write_autoinstall_config(self):
|
||||
self.controller.write_autoinstall_config()
|
||||
user_data = (
|
||||
self.controller.app.root + "/var/log/installer/autoinstall-user-data"
|
||||
)
|
||||
with open(user_data) as file:
|
||||
data = file.read()
|
||||
self.assertIn(
|
||||
"https://canonical-subiquity.readthedocs-hosted.com/en/latest/reference/autoinstall-reference.html", # noqa: E501
|
||||
data,
|
||||
)
|
||||
|
|
|
@ -25,6 +25,9 @@ class MockedApplication:
|
|||
answers = {}
|
||||
opts = None
|
||||
|
||||
def make_autoinstall(self):
|
||||
return {"mock_key": "mock_data"}
|
||||
|
||||
|
||||
def make_app(model=None):
|
||||
app = MockedApplication()
|
||||
|
|
Loading…
Reference in New Issue