@@ -135,21 +135,11 @@ def setup(self, name=None):
135135 ['btrfs' , 'subvolume' , 'create' , root_volume ]
136136 )
137137 if self .custom_args ['root_is_snapshot' ]:
138- snapshot_volume = self .mountpoint + \
139- f'/{ self .root_volume_name } /.snapshots'
140- Command .run (
141- ['btrfs' , 'subvolume' , 'create' , snapshot_volume ]
142- )
143- os .chmod (snapshot_volume , 0o700 )
144- Path .create (snapshot_volume + '/1' )
145- snapshot = self .mountpoint + \
146- f'/{ self .root_volume_name } /.snapshots/1/snapshot'
147- Command .run (
148- ['btrfs' , 'subvolume' , 'create' , snapshot ]
149- )
150- self ._set_default_volume (
151- f'{ self .root_volume_name } /.snapshots/1/snapshot'
152- )
138+ Command .run ([
139+ '/usr/lib/snapper/installation-helper' , '--root-prefix' ,
140+ os .path .join (self .mountpoint , self .root_volume_name ),
141+ '--step' , 'filesystem'
142+ ])
153143 snapshot = self .mountpoint + \
154144 f'/{ self .root_volume_name } /.snapshots/1/snapshot'
155145 # Mount /{some-name}/.snapshots as /.snapshots inside the root
@@ -413,14 +403,12 @@ def sync_data(self, exclude=None):
413403 if self .toplevel_mount :
414404 sync_target = self .get_mountpoint ()
415405 if self .custom_args ['root_is_snapshot' ]:
416- self ._create_snapshot_info (
417- '' .join (
418- [
419- self .mountpoint ,
420- f'/{ self .root_volume_name } /.snapshots/1/info.xml'
421- ]
422- )
423- )
406+ Command .run ([
407+ '/usr/lib/snapper/installation-helper' , '--root-prefix' ,
408+ os .path .join (self .mountpoint , self .root_volume_name ),
409+ '--step' , 'config' , '--description' ,
410+ 'first root filesystem'
411+ ])
424412 data = DataSync (self .root_dir , sync_target )
425413 data .sync_data (
426414 options = Defaults .get_sync_options (), exclude = exclude
@@ -438,6 +426,7 @@ def set_property_readonly_root(self):
438426 root_is_readonly_snapshot = \
439427 self .custom_args ['root_is_readonly_snapshot' ]
440428 if root_is_snapshot and root_is_readonly_snapshot :
429+ # TODO we could call snapper modify here instead
441430 sync_target = self .get_mountpoint ()
442431 Command .run (
443432 ['btrfs' , 'property' , 'set' , sync_target , 'ro' , 'true' ]
@@ -502,75 +491,21 @@ def _set_default_volume(self, default_volume):
502491 'Failed to find btrfs volume: %s' % default_volume
503492 )
504493
505- def _xml_pretty (self , toplevel_element ):
506- xml_data_unformatted = ElementTree .tostring (
507- toplevel_element , 'utf-8'
508- )
509- xml_data_domtree = minidom .parseString (xml_data_unformatted )
510- return xml_data_domtree .toprettyxml (indent = " " )
511-
512494 def _create_snapper_quota_configuration (self ):
513495 root_path = os .sep .join (
514496 [
515497 self .mountpoint ,
516498 f'{ self .root_volume_name } /.snapshots/1/snapshot'
517499 ]
518500 )
519- snapper_default_conf = Defaults .get_snapper_config_template_file (
520- root_path
501+ # snapper requires an extra parent qgroup to operate with quotas
502+ Command .run (
503+ ['btrfs' , 'qgroup' , 'create' , '1/0' , self .mountpoint ]
521504 )
522- if snapper_default_conf :
523- # snapper requires an extra parent qgroup to operate with quotas
524- Command .run (
525- ['btrfs' , 'qgroup' , 'create' , '1/0' , self .mountpoint ]
526- )
527- config_file = self ._set_snapper_sysconfig_file (root_path )
528- if not os .path .exists (config_file ):
529- shutil .copyfile (snapper_default_conf , config_file )
530- Command .run ([
531- 'chroot' , root_path , 'snapper' , '--no-dbus' , 'set-config' ,
532- 'QGROUP=1/0'
533- ])
534-
535- @staticmethod
536- def _set_snapper_sysconfig_file (root_path ):
537- sysconf_file = SysConfig (
538- os .sep .join ([root_path , 'etc/sysconfig/snapper' ])
539- )
540- if not sysconf_file .get ('SNAPPER_CONFIGS' ) or \
541- len (sysconf_file ['SNAPPER_CONFIGS' ].strip ('\" ' )) == 0 :
542-
543- sysconf_file ['SNAPPER_CONFIGS' ] = '"root"'
544- sysconf_file .write ()
545- elif len (sysconf_file ['SNAPPER_CONFIGS' ].split ()) > 1 :
546- raise KiwiVolumeManagerSetupError (
547- 'Unsupported SNAPPER_CONFIGS value: {0}' .format (
548- sysconf_file ['SNAPPER_CONFIGS' ]
549- )
550- )
551- return os .sep .join ([
552- root_path , 'etc/snapper/configs' ,
553- sysconf_file ['SNAPPER_CONFIGS' ].strip ('\" ' )]
554- )
555-
556- def _create_snapshot_info (self , filename ):
557- date_info = datetime .datetime .now ()
558- snapshot = ElementTree .Element ('snapshot' )
559-
560- snapshot_type = ElementTree .SubElement (snapshot , 'type' )
561- snapshot_type .text = 'single'
562-
563- snapshot_number = ElementTree .SubElement (snapshot , 'num' )
564- snapshot_number .text = '1'
565-
566- snapshot_description = ElementTree .SubElement (snapshot , 'description' )
567- snapshot_description .text = 'first root filesystem'
568-
569- snapshot_date = ElementTree .SubElement (snapshot , 'date' )
570- snapshot_date .text = date_info .strftime ("%Y-%m-%d %H:%M:%S" )
571-
572- with open (filename , 'w' ) as snapshot_info_file :
573- snapshot_info_file .write (self ._xml_pretty (snapshot ))
505+ Command .run ([
506+ 'snapper' , '--no-dbus' , "--root" , root_path , 'set-config' ,
507+ 'QGROUP=1/0'
508+ ])
574509
575510 def __exit__ (self , exc_type , exc_value , traceback ):
576511 if self .toplevel_mount :
0 commit comments