Transformer to disable cloud-init and walinuxagent so that an exported VHD can boot in a lab environment.
This commit is contained in:
Kameron Carr 2024-02-07 14:28:22 -08:00 коммит произвёл Chi Song
Родитель 518306e21f
Коммит da43877331
2 изменённых файлов: 63 добавлений и 0 удалений

Просмотреть файл

@ -62,6 +62,7 @@ if platform.system() == "Linux":
except ModuleNotFoundError as e:
print(f"libvirt package is not installed. [{e}]")
import lisa.transformers.disable_cloud_components # noqa: F401
import lisa.transformers.dom0_kernel_installer # noqa: F401
import lisa.transformers.dump_variables # noqa: F401
import lisa.transformers.file_uploader # noqa: F401

Просмотреть файл

@ -0,0 +1,62 @@
from dataclasses import dataclass
from pathlib import PurePosixPath
from typing import Any, Dict, List, Type
from dataclasses_json import dataclass_json
from lisa import schema
from lisa.operating_system import Posix
from lisa.sut_orchestrator.azure.tools import Waagent
from lisa.tools import Ls, Sed
from lisa.transformers.deployment_transformer import (
DeploymentTransformer,
DeploymentTransformerSchema,
)
@dataclass_json()
@dataclass
class DisableCloudComponentsTransformerSchema(DeploymentTransformerSchema):
pass
class DisableCloudComponentsTransformer(DeploymentTransformer):
"""
This Transformer prepares a marketplace image for lab testing.
"""
@classmethod
def type_name(cls) -> str:
return "disable_cloud_components"
@classmethod
def type_schema(cls) -> Type[schema.TypedSchema]:
return DisableCloudComponentsTransformerSchema
@property
def _output_names(self) -> List[str]:
return []
def _internal_run(self) -> Dict[str, Any]:
runbook: DisableCloudComponentsTransformerSchema = self.runbook
assert isinstance(runbook, DisableCloudComponentsTransformerSchema)
node = self._node
sed = node.tools[Sed]
ls = node.tools[Ls]
node.tools[Waagent].deprovision()
if isinstance(node.os, Posix):
node.os.uninstall_packages(["walinuxagent"])
node.execute("touch /var/lib/waagent/diable_agent", sudo=True)
node.execute("touch /var/lib/waagent/provisioned", sudo=True)
node.execute("touch /etc/cloud/cloud-init.disabled", sudo=True)
if ls.path_exists("/etc/netplan/50-cloud-init.yaml"):
sed.delete_lines(
"macaddress",
PurePosixPath("/etc/netplan/50-cloud-init.yaml"),
sudo=True,
)
return {}