#164 update runroot cli test case
Closed 7 years ago by mikem. Opened 7 years ago by mikem.
https://github.com/mikem23/koji-playground.git feature/runroot-newchroot-option  into  master

update runroot cli test case
Mike McLean • 7 years ago  
Slight improvement to new-chroot to make the cli change less likely to confuse older builders
Ian McLeod • 7 years ago  
A stab at --new-chroot support for rhe runroot plugin
Ian McLeod • 7 years ago  
cli/koji
file modified
+14 -6
@@ -6853,6 +6853,8 @@

              help=_("Print the ID of the runroot task"))

      parser.add_option("--use-shell", action="store_true", default=False,

              help=_("Run command through a shell, otherwise uses exec"))

+     parser.add_option("--new-chroot", action="store_true", default=False,

+             help=_("Run command with the --new-chroot (systemd-nspawn) option to mock"))

      parser.add_option("--repo-id", type="int", help=_("ID of the repo to use"))

  

      (opts, args) = parser.parse_args(args)
@@ -6868,12 +6870,18 @@

      else:

          command = args[2:]

      try:

-         task_id = session.runroot(tag, arch, command,

-                                 channel=opts.channel_override,

-                                 packages=opts.package, mounts=opts.mount,

-                                 repo_id=opts.repo_id,

-                                 skip_setarch=opts.skip_setarch,

-                                 weight=opts.weight)

+         kwargs = { 'channel':       opts.channel_override,

+                    'packages':      opts.package,

+                    'mounts':        opts.mount,

+                    'repo_id':       opts.repo_id,

+                    'skip_setarch':  opts.skip_setarch,

+                    'weight':        opts.weight }

+         # Only pass this kwarg if it is true - this prevents confusing older

+         # builders with a different function signature

+         if opts.new_chroot:

+             kwargs['new_chroot'] = True

+ 

+         task_id = session.runroot(tag, arch, command, **kwargs)

      except koji.GenericError, e:

          if 'Invalid method' in str(e):

              print "* The runroot plugin appears to not be installed on the",

plugins/builder/runroot.py
file modified
+3 -1
@@ -92,7 +92,7 @@

              if not path.startswith('/'):

                  raise koji.GenericError("bad config: all paths (default_mounts, safe_roots, path_subs) needs to be absolute: %s" % path)

  

-     def handler(self, root, arch, command, keep=False, packages=[], mounts=[], repo_id=None, skip_setarch=False, weight=None, upload_logs=None):

+     def handler(self, root, arch, command, keep=False, packages=[], mounts=[], repo_id=None, skip_setarch=False, weight=None, upload_logs=None, new_chroot=False):

          """Create a buildroot and run a command (as root) inside of it

  

          Command may be a string or a list.
@@ -188,6 +188,8 @@

              self.do_mounts(rootdir, [self._get_path_params(x) for x in self.config['default_mounts']])

              self.do_extra_mounts(rootdir, mounts)

              mock_cmd = ['chroot']

+             if new_chroot:

+                 mock_cmd.append('--new-chroot')

              if skip_setarch:

                  #we can't really skip it, but we can set it to the current one instead of of the chroot one

                  myarch = platform.uname()[5]

tests/test_cli/test_runroot.py
file modified
+1 -1
@@ -44,7 +44,7 @@

          command = 'command'

          arguments = [tag, arch, command]

          options = mock.MagicMock()

-         options.admin = True

+         options.new_chroot = False

          self.parser.parse_args.return_value = [options, arguments]

  

          # Mock out the xmlrpc server

no initial comment

Pull-Request has been closed by mikem

7 years ago