コード例 #1
0
 def __init__(self, parameters, job_id):
     super(LxcProtocol, self).__init__(parameters, job_id)
     self.system_timeout = Timeout('system', LAVA_LXC_TIMEOUT)
     self.persistence = parameters['protocols'][self.name].get('persist',
                                                               False)
     if self.persistence:
         self.lxc_name = parameters['protocols'][self.name]['name']
     else:
         self.lxc_name = '-'.join(
             [parameters['protocols'][self.name]['name'], str(job_id)])
     self.lxc_dist = parameters['protocols'][self.name]['distribution']
     self.lxc_release = parameters['protocols'][self.name]['release']
     self.lxc_arch = parameters['protocols'][self.name].get('arch', None)
     self.lxc_template = parameters['protocols'][self.name].get(
         'template', 'download')
     self.lxc_mirror = parameters['protocols'][self.name].get('mirror',
                                                              None)
     self.lxc_security_mirror = parameters['protocols'][self.name].get(
         'security_mirror', None)
     self.verbose = parameters['protocols'][self.name].get('verbose', False)
     self.fastboot_reboot = parameters.get('reboot_to_fastboot', True)
     self.custom_lxc_path = False
     if LXC_PATH != lxc_path(parameters['dispatcher']):
         self.custom_lxc_path = True
     self.logger = logging.getLogger('dispatcher')
コード例 #2
0
 def run(self, connection, max_end_time, args=None):
     connection = super(LxcCreateAction, self).run(connection, max_end_time,
                                                   args)
     verbose = '' if self.lxc_data['verbose'] else '-q'
     lxc_default_path = lxc_path(self.job.parameters['dispatcher'])
     if self.lxc_data['custom_lxc_path']:
         lxc_create = ['lxc-create', '-P', lxc_default_path]
     else:
         lxc_create = ['lxc-create']
     if self.lxc_data['lxc_template'] in LXC_TEMPLATE_WITH_MIRROR:
         lxc_cmd = lxc_create + [
             verbose, '-t', self.lxc_data['lxc_template'], '-n',
             self.lxc_data['lxc_name'], '--', '--release',
             self.lxc_data['lxc_release']
         ]
         if self.lxc_data['lxc_mirror']:
             lxc_cmd += ['--mirror', self.lxc_data['lxc_mirror']]
         if self.lxc_data['lxc_security_mirror']:
             lxc_cmd += [
                 '--security-mirror', self.lxc_data['lxc_security_mirror']
             ]
         # FIXME: Should be removed when LAVA's supported distro is bumped
         #        to Debian Stretch or any distro that supports systemd
         lxc_cmd += ['--packages', LXC_DEFAULT_PACKAGES]
     else:
         lxc_cmd = lxc_create + [
             verbose, '-t', self.lxc_data['lxc_template'], '-n',
             self.lxc_data['lxc_name'], '--', '--dist',
             self.lxc_data['lxc_distribution'], '--release',
             self.lxc_data['lxc_release']
         ]
     if self.lxc_data['lxc_arch']:
         lxc_cmd += ['--arch', self.lxc_data['lxc_arch']]
     cmd_out = self.run_command(lxc_cmd, allow_fail=True, allow_silent=True)
     if isinstance(cmd_out, str):
         if 'exists' in cmd_out and self.lxc_data['lxc_persist']:
             self.logger.debug('Persistant container exists')
             self.results = {'status': self.lxc_data['lxc_name']}
     elif not cmd_out:
         raise JobError("Unable to create lxc container")
     else:
         self.logger.debug('Container created successfully')
         self.results = {'status': self.lxc_data['lxc_name']}
     # Create symlink in default container path ie., /var/lib/lxc defined by
     # LXC_PATH so that we need not add '-P' option to every lxc-* command.
     dst = os.path.join(LXC_PATH, self.lxc_data['lxc_name'])
     if self.lxc_data['custom_lxc_path'] and not os.path.exists(dst):
         os.symlink(
             os.path.join(lxc_default_path, self.lxc_data['lxc_name']),
             os.path.join(LXC_PATH, self.lxc_data['lxc_name']))
     return connection
コード例 #3
0
    def run(self, connection, max_end_time, args=None):
        connection = super(ApplyLxcOverlay, self).run(connection, max_end_time,
                                                      args)
        overlay_file = self.get_namespace_data(action='compress-overlay',
                                               label='output',
                                               key='file')
        if overlay_file is None:
            self.logger.debug("skipped %s", self.name)
            return connection
        lxc_name = self.get_namespace_data(action='lxc-create-action',
                                           label='lxc',
                                           key='name')
        lxc_default_path = lxc_path(self.job.parameters['dispatcher'])
        lxc_rootfs_path = os.path.join(lxc_default_path, lxc_name, 'rootfs')
        if not os.path.exists(lxc_rootfs_path):
            raise LAVABug("Lxc container rootfs not found")
        tar_cmd = [
            'tar', '--warning', 'no-timestamp', '-C', lxc_rootfs_path, '-xaf',
            overlay_file
        ]
        command_output = self.run_command(tar_cmd)
        if command_output and command_output is not '':
            raise JobError("Unable to untar overlay: %s" % command_output)

        # FIXME: Avoid copying this special 'lava-test-runner' which does not
        #        have 'sync' in cleanup. This should be handled during the
        #        creation of the overlay instead. Make a special case to copy
        #        lxc specific scripts, with distro specific versions.
        fname = os.path.join(self.lava_test_dir, 'lava-test-runner')
        output_file = '%s/bin/%s' % (lxc_rootfs_path, os.path.basename(fname))
        self.logger.debug("Copying %s", output_file)
        try:
            shutil.copy(fname, output_file)
        except IOError:
            raise InfrastructureError("Unable to copy: %s" % output_file)

        return connection