[elbe-devel] [PATCH 6/9] finetuning: implement <mount_drive> action

Torben Hohn torben.hohn at linutronix.de
Tue Dec 4 15:06:18 CET 2018


On Fri, Nov 30, 2018 at 03:14:40PM +0100, Manuel Traut wrote:
> On 17:29 Wed 28 Nov     , Torben Hohn wrote:
> > <mount_drive> is an action for <project-finetuning>
> > it nests around other actions, which are ImageFinetuning
> > actions. These have an execute_img() method which adds
> > the name of the loop_device to the parameter list.
> > 
> > example:
> > 
> > <mount_drive img="sda.img">
> >    <extract_partition part="2">sda2.img</extract_partition>
> > </mount_drive>
> > 
> > the extract partition action is implemented in a followup patch.
> > ---
> >  elbepack/finetuning.py | 44 ++++++++++++++++++++++++++++++++++++++++++++
> >  schema/dbsfed.xsd      | 33 +++++++++++++++++++++++++++++++++
> >  2 files changed, 77 insertions(+)
> > 
> > diff --git a/elbepack/finetuning.py b/elbepack/finetuning.py
> > index 1aaeda67..c53b13c6 100644
> > --- a/elbepack/finetuning.py
> > +++ b/elbepack/finetuning.py
> > @@ -44,6 +44,21 @@ class FinetuningAction(object):
> >          self.execute(log, buildenv, target)
> >  
> >  
> > +class ImageFinetuningAction(FinetuningAction):
> > +
> > +    tag = 'image_finetuning'
> > +
> > +    def __init__(self, node):
> > +        FinetuningAction.__init__(self, node)
> > +
> > +    def execute(self, _log, _buildenv, _target):
> > +        raise NotImplementedError("<%s> may only be "
> > +                                  "used in <image-finetuning>" % self.tag)
> > +
> > +    def execute_img(self, _log, _buildenv, _target, _builddir, _loop_dev):
> > +        raise NotImplementedError('execute_img() not implemented')
> > +
> 
> Isn't
>   def execute_prj(self, log, buildenv, target, _builddir):
>         raise NotImplementedError('execute_img() not implemented')
> missing here?
> 
> Also the FinetuningAction class should default to NotImplementedError for all
> execute_* functions?

no. 

FinetuningAction.execute_prj() is implemented.
it calls self.execute() 
ImageFinetuningAction inherits it.




> 
> > +
> >  class RmAction(FinetuningAction):
> >  
> >      tag = 'rm'
> > @@ -525,6 +540,35 @@ class RmArtifactAction(FinetuningAction):
> >  FinetuningAction.register(ArtifactAction)
> >  
> >  
> > +class MountDriveImageAction(FinetuningAction):
> > +
> > +    tag = 'mount_drive'
> > +
> > +    def __init__(self, node):
> > +        FinetuningAction.__init__(self, node)
> 
> than
> > +    def execute(self, _log, _buildenv, _target):
> > +        raise NotImplementedError("<mount_drive> may only be "
> > +                                  "used in <project-finetuning>")
> could be dropped
> 
> > +    def execute_prj(self, log, buildenv, target, builddir):
> > +        imgname = self.node.et.attrib['img']
> > +        imgpath = os.path.join(builddir, imgname)
> > +        cmd = 'losetup --find --show --partscan "%s"' % imgpath
> > +
> > +        loop_dev = log.get_command_out(cmd).strip()
> > +        try:
> > +            for i in self.node:
> > +                action = ImageFinetuningAction(i)
> > +                action.execute_img(log, buildenv, target, builddir, loop_dev)
> > +        finally:
> > +            cmd = 'losetup --detach "%s"' % loop_dev
> > +            log.do(cmd)
> > +
> > +
> > +FinetuningAction.register(MountDriveImageAction)
> > +
> > +
> >  def do_finetuning(xml, log, buildenv, target):
> >  
> >      if not xml.has('target/finetuning'):
> > diff --git a/schema/dbsfed.xsd b/schema/dbsfed.xsd
> > index e0b6eecb..d9317c72 100644
> > --- a/schema/dbsfed.xsd
> > +++ b/schema/dbsfed.xsd
> > @@ -1890,6 +1890,39 @@
> >            </documentation>
> >          </annotation>
> >        </element>
> > +      <element name="mount_drive" type="rfs:mount_drive" minOccurs="0">
> > +        <annotation>
> > +          <documentation>
> > +            Setup the loop device with an image file. This node wraps image_finetuning
> > +	    Actions, which access the loop device then.
> > +          </documentation>
> > +        </annotation>
> > +      </element>
> > +    </choice>
> > +  </group>
> > +
> > +  <complexType name="mount_drive">
> > +    <annotation>
> > +      <documentation>
> > +         container for image_finetuning commands; these commands are executed in the
> > +	 project directory, while a drive image is setup as a loop device.
> > +	 The loop device id is passed to the individual actions.
> > +      </documentation>
> > +    </annotation>
> > +    <sequence>
> > +      <group ref="rfs:image_action" minOccurs="0" maxOccurs="unbounded" />
> > +    </sequence>
> > +    <attribute ref="xml:base"/>
> > +    <attribute name="img" type="string" use="required" />
> > +  </complexType>
> > +
> > +  <group name="image_action">
> > +    <annotation>
> > +      <documentation>
> > +        definition of image finetuning commands
> > +      </documentation>
> > +    </annotation>
> > +    <choice>
> >      </choice>
> >    </group>
> >  
> > -- 
> > 2.11.0
> > 
> > 
> > _______________________________________________
> > elbe-devel mailing list
> > elbe-devel at linutronix.de
> > https://lists.linutronix.de/mailman/listinfo/elbe-devel

-- 
Torben Hohn
Linutronix GmbH | Bahnhofstrasse 3 | D-88690 Uhldingen-Mühlhofen
Phone: +49 7556 25 999 18; Fax.: +49 7556 25 999 99

Hinweise zum Datenschutz finden Sie hier (Informations on data privacy 
can be found here): https://linutronix.de/kontakt/Datenschutz.php

Linutronix GmbH | Firmensitz (Registered Office): Uhldingen-Mühlhofen | 
Registergericht (Registration Court): Amtsgericht Freiburg i.Br., HRB700 
806 | Geschäftsführer (Managing Directors): Heinz Egger, Thomas Gleixner
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 488 bytes
Desc: not available
URL: <http://lists.linutronix.de/pipermail/elbe-devel/attachments/20181204/79045f11/attachment.sig>


More information about the elbe-devel mailing list