mirror of
https://github.com/Telecominfraproject/OpenNetworkLinux.git
synced 2025-12-26 17:57:01 +00:00
Add installer support for using onie-sysinfo instead of /etc/machine.conf
This commit is contained in:
@@ -17,7 +17,7 @@ import time
|
||||
from InstallUtils import InitrdContext
|
||||
from InstallUtils import SubprocessMixin
|
||||
from InstallUtils import ProcMountsParser
|
||||
from ShellApp import OnieBootContext
|
||||
from ShellApp import OnieBootContext, OnieSysinfo
|
||||
import ConfUtils, BaseInstall
|
||||
|
||||
class App(SubprocessMixin, object):
|
||||
@@ -129,7 +129,7 @@ class App(SubprocessMixin, object):
|
||||
def runLocalOrChroot(self):
|
||||
|
||||
if self.machineConf is None:
|
||||
self.log.error("missing machine.conf")
|
||||
self.log.error("missing onie-sysinfo or machine.conf")
|
||||
return 1
|
||||
if self.installerConf is None:
|
||||
self.log.error("missing installer.conf")
|
||||
@@ -230,10 +230,17 @@ class App(SubprocessMixin, object):
|
||||
def runLocal(self):
|
||||
|
||||
self.log.info("getting installer configuration")
|
||||
if os.path.exists(ConfUtils.MachineConf.PATH):
|
||||
osi = OnieSysinfo(log=self.log.getChild("onie-sysinfo"))
|
||||
try:
|
||||
halp = osi.help
|
||||
except AttributeError:
|
||||
halp = None
|
||||
if halp is not None:
|
||||
self.machineConf = osi
|
||||
elif os.path.exists(ConfUtils.MachineConf.PATH):
|
||||
self.machineConf = ConfUtils.MachineConf()
|
||||
else:
|
||||
self.log.warn("missing /etc/machine.conf from ONIE runtime")
|
||||
self.log.warn("missing onie-sysinfo or /etc/machine.conf from ONIE runtime")
|
||||
self.machineConf = ConfUtils.MachineConf(path='/dev/null')
|
||||
|
||||
self.installerConf = ConfUtils.InstallerConf()
|
||||
@@ -243,7 +250,7 @@ class App(SubprocessMixin, object):
|
||||
def findPlatform(self):
|
||||
|
||||
plat = arch = None
|
||||
if os.path.exists(ConfUtils.MachineConf.PATH):
|
||||
if self.machineConf is not None:
|
||||
plat = getattr(self.machineConf, 'onie_platform', None)
|
||||
arch = getattr(self.machineConf, 'onie_arch', None)
|
||||
if plat and arch:
|
||||
|
||||
@@ -15,9 +15,6 @@ from InstallUtils import ProcMountsParser, ProcMtdParser
|
||||
from InstallUtils import BlkidParser
|
||||
from InstallUtils import UbootInitrdContext
|
||||
|
||||
import onl.platform.current
|
||||
from onl.sysconfig import sysconfig
|
||||
|
||||
class AppBase(SubprocessMixin, object):
|
||||
|
||||
@property
|
||||
@@ -228,6 +225,105 @@ class Onie(AppBase):
|
||||
with OnieBootContext(log=self.log) as ctx:
|
||||
return self._runInitrdShell(ctx.initrd)
|
||||
|
||||
class OnieSysinfoApp(SubprocessMixin, object):
|
||||
|
||||
PROG = "onie-sysinfo"
|
||||
|
||||
def __init__(self, args=[], log=None):
|
||||
|
||||
if log is not None:
|
||||
self.log = log
|
||||
else:
|
||||
self.log = logging.getLogger(self.__class__.__name__)
|
||||
self.args = args or ['-p',]
|
||||
self.output = None
|
||||
|
||||
def _runInitrdShell(self, initrd):
|
||||
with InitrdContext(initrd=initrd, log=self.log) as ctx:
|
||||
cmd = ['onie-sysinfo',]
|
||||
cmd.extend(self.args)
|
||||
cmd = ('chroot', ctx.dir,
|
||||
'/bin/sh', '-c', 'IFS=;' + " ".join(cmd))
|
||||
try:
|
||||
self.output = self.check_output(cmd)
|
||||
ret = 0
|
||||
except subprocess.CalledProcessError, what:
|
||||
self.log.error("failed command: %s", " ".join(what.cmd))
|
||||
for line in (what.output or "").splitlines():
|
||||
self.log.error(">>> %s", line)
|
||||
ret = what.returncode
|
||||
return ret
|
||||
|
||||
def run(self):
|
||||
with OnieBootContext(log=self.log) as ctx:
|
||||
ret = self._runInitrdShell(ctx.initrd)
|
||||
if self.output is not None:
|
||||
sys.stdout.write(self.output)
|
||||
return ret
|
||||
|
||||
def shutdown(self):
|
||||
pass
|
||||
|
||||
@classmethod
|
||||
def main(cls):
|
||||
|
||||
logging.basicConfig()
|
||||
logger = logging.getLogger(cls.PROG)
|
||||
logger.setLevel(logging.INFO)
|
||||
|
||||
args = list(sys.argv[1:])
|
||||
sysinfoArgs = []
|
||||
while args:
|
||||
|
||||
if args[0] in ('-v', '--verbose',):
|
||||
logger.setLevel(logging.DEBUG)
|
||||
args.pop(0)
|
||||
continue
|
||||
|
||||
if args[0] in ('-q', '--quiet',):
|
||||
logger.setLevel(logging.ERROR)
|
||||
args.pop(0)
|
||||
continue
|
||||
|
||||
sysinfoArgs.append(args.pop(0))
|
||||
|
||||
app = cls(args=sysinfoArgs, log=logger)
|
||||
try:
|
||||
code = app.run()
|
||||
except:
|
||||
logger.exception("runner failed")
|
||||
code = 1
|
||||
app.shutdown()
|
||||
sys.exit(code)
|
||||
|
||||
class OnieSysinfo(OnieSysinfoApp):
|
||||
|
||||
def _runArgs(self, *args):
|
||||
self.args = args
|
||||
with OnieBootContext(log=self.log) as ctx:
|
||||
ret = self._runInitrdShell(ctx.initrd)
|
||||
if self.output is not None:
|
||||
return self.output.rstrip()
|
||||
raise AttributeError("cannot retrieve onie-sysinfo attribute via %s" % str(args))
|
||||
|
||||
@property
|
||||
def help(self):
|
||||
return self._runArgs('-h')
|
||||
|
||||
@property
|
||||
def onie_platform(self):
|
||||
return self._runArgs('-p')
|
||||
|
||||
@property
|
||||
def onie_arch(self):
|
||||
return self._runArgs('-c')
|
||||
|
||||
@property
|
||||
def onie_version(self):
|
||||
return self._runArgs('-v')
|
||||
|
||||
# XXX roth other switches too
|
||||
|
||||
class Loader(AppBase):
|
||||
"""Application shell that uses the (installed) loader runtime."""
|
||||
|
||||
@@ -331,6 +427,7 @@ class Loader(AppBase):
|
||||
|
||||
def run(self):
|
||||
|
||||
import onl.platform.current
|
||||
self.platform = onl.platform.current.OnlPlatform()
|
||||
self.pc = self.platform.platform_config
|
||||
|
||||
@@ -353,6 +450,7 @@ class Upgrader(AppBase):
|
||||
|
||||
def runGrub(self):
|
||||
|
||||
from onl.sysconfig import sysconfig
|
||||
d = sysconfig.upgrade.loader.package.dir
|
||||
for b in sysconfig.upgrade.loader.package.grub:
|
||||
p = os.path.join(d, b)
|
||||
@@ -365,6 +463,7 @@ class Upgrader(AppBase):
|
||||
|
||||
def runUboot(self):
|
||||
|
||||
from onl.sysconfig import sysconfig
|
||||
d = sysconfig.upgrade.loader.package.dir
|
||||
for b in sysconfig.upgrade.loader.package.fit:
|
||||
p = os.path.join(d, b)
|
||||
@@ -377,6 +476,7 @@ class Upgrader(AppBase):
|
||||
|
||||
def run(self):
|
||||
|
||||
import onl.platform.current
|
||||
self.platform = onl.platform.current.OnlPlatform()
|
||||
self.pc = self.platform.platform_config
|
||||
|
||||
|
||||
@@ -60,8 +60,9 @@ class App(SubprocessMixin):
|
||||
|
||||
src = os.path.join(octx.initrdDir, "etc/machine.conf")
|
||||
dst = os.path.join(ctx.dir, "etc/machine.conf")
|
||||
self.log.debug("+ /bin/cp %s %s", src, dst)
|
||||
shutil.copy2(src, dst)
|
||||
if os.path.exists(src):
|
||||
self.log.debug("+ /bin/cp %s %s", src, dst)
|
||||
shutil.copy2(src, dst)
|
||||
|
||||
src = "/etc/fw_env.config"
|
||||
if os.path.exists(src):
|
||||
|
||||
Reference in New Issue
Block a user