Exemplo n.º 1
0
    def validate(self):
        super(TftpAction, self).validate()
        if 'kernel' not in self.parameters:
            self.errors = "%s needs a kernel to deploy" % self.name
        if not self.valid:
            return
        if 'nfsrootfs' in self.parameters and 'nfs_url' in self.parameters:
            self.errors = "Only one of nfsrootfs or nfs_url can be specified"
        lava_test_results_dir = self.parameters['deployment_data'][
            'lava_test_results_dir']
        self.data[
            'lava_test_results_dir'] = lava_test_results_dir % self.job.job_id
        # Extract the 3 last path elements. See action.mkdtemp()
        suffix = os.path.join(*self.tftp_dir.split('/')[-2:])
        self.data[self.name].setdefault('suffix', suffix)
        self.errors = infrastructure_error('in.tftpd')

        # Check that the tmp directory is in the tftpd_dir or in /tmp for the
        # unit tests
        tftpd_directory = os.path.realpath(tftpd_dir())
        tftp_dir = os.path.realpath(self.tftp_dir)
        tmp_dir = tempfile.gettempdir()
        if not tftp_dir.startswith(tftpd_directory) and \
           not tftp_dir.startswith(tmp_dir):
            self.errors = "tftpd directory is not configured correctly, see /etc/default/tftpd-hpa"
Exemplo n.º 2
0
    def validate(self):
        super(TftpAction, self).validate()
        if 'kernel' not in self.parameters:
            self.errors = "%s needs a kernel to deploy" % self.name
        if not self.valid:
            return
        if 'nfs_url' in self.parameters:
            self.errors = "Use a persistent_nfs dictionary instead of nfs_url"
        if 'nfsrootfs' in self.parameters and 'persistent_nfs' in self.parameters:
            self.errors = "Only one of nfsrootfs or persistent_nfs can be specified"
        if self.test_needs_deployment(self.parameters):
            lava_test_results_base = self.parameters['deployment_data']['lava_test_results_dir']
            lava_test_results_dir = lava_test_results_base % self.job.job_id
            self.set_namespace_data(action='test', label='results', key='lava_test_results_dir', value=lava_test_results_dir)
        # Extract the 3 last path elements. See action.mkdtemp()
        suffix = os.path.join(*self.tftp_dir.split('/')[-2:])
        self.set_namespace_data(action=self.name, label='tftp', key='suffix', value=suffix)
        self.errors = infrastructure_error('in.tftpd')

        # Check that the tmp directory is in the tftpd_dir or in /tmp for the
        # unit tests
        tftpd_directory = os.path.realpath(tftpd_dir())
        tftp_dir = os.path.realpath(self.tftp_dir)
        tmp_dir = tempfile.gettempdir()
        if not tftp_dir.startswith(tftpd_directory) and \
           not tftp_dir.startswith(tmp_dir):
            self.errors = "tftpd directory is not configured correctly, see /etc/default/tftpd-hpa"
Exemplo n.º 3
0
 def test_tftp_pipeline(self):
     job = self.factory.create_bbb_job('sample_jobs/uboot-ramdisk.yaml')
     self.assertEqual(
         [action.name for action in job.pipeline.actions],
         ['tftp-deploy', 'uboot-action', 'lava-test-retry', 'finalize'])
     tftp = [
         action for action in job.pipeline.actions
         if action.name == 'tftp-deploy'
     ][0]
     self.assertTrue(
         tftp.get_namespace_data(action=tftp.name,
                                 label='tftp',
                                 key='ramdisk'))
     self.assertIsNotNone(tftp.internal_pipeline)
     self.assertEqual(
         [action.name for action in tftp.internal_pipeline.actions], [
             'download-retry', 'download-retry', 'download-retry',
             'prepare-tftp-overlay', 'deploy-device-env'
         ])
     self.assertIn('ramdisk', [
         action.key for action in tftp.internal_pipeline.actions
         if hasattr(action, 'key')
     ])
     self.assertIn('kernel', [
         action.key for action in tftp.internal_pipeline.actions
         if hasattr(action, 'key')
     ])
     self.assertIn('dtb', [
         action.key for action in tftp.internal_pipeline.actions
         if hasattr(action, 'key')
     ])
     self.assertNotIn('=', tftpd_dir())
     job.validate()
     tftp.validate()
     self.assertEqual([], tftp.errors)
Exemplo n.º 4
0
 def test_tftp_pipeline(self):
     factory = Factory()
     job = factory.create_job('sample_jobs/grub-ramdisk.yaml')
     self.assertEqual(
         [action.name for action in job.pipeline.actions],
         ['tftp-deploy', 'grub-main-action', 'lava-test-retry', 'finalize'])
     tftp = [
         action for action in job.pipeline.actions
         if action.name == 'tftp-deploy'
     ][0]
     self.assertTrue(tftp.get_common_data('tftp', 'ramdisk'))
     self.assertIsNotNone(tftp.internal_pipeline)
     self.assertEqual(
         [action.name for action in tftp.internal_pipeline.actions], [
             'download_retry', 'download_retry', 'download_retry',
             'prepare-tftp-overlay', 'deploy-device-env'
         ])
     self.assertIn('ramdisk', [
         action.key for action in tftp.internal_pipeline.actions
         if hasattr(action, 'key')
     ])
     self.assertIn('kernel', [
         action.key for action in tftp.internal_pipeline.actions
         if hasattr(action, 'key')
     ])
     self.assertIn('dtb', [
         action.key for action in tftp.internal_pipeline.actions
         if hasattr(action, 'key')
     ])
     self.assertNotIn('=', tftpd_dir())
Exemplo n.º 5
0
    def run(self, connection, max_end_time, args=None):
        connection = super(XnbdAction, self).run(connection, max_end_time,
                                                 args)
        self.logger.debug("%s: starting xnbd-server", self.name)
        # pull from parameters - as previously set
        self.nbd_server_port = self.parameters['lava-xnbd']['port']
        self.nbd_server_ip = self.parameters['lava-xnbd']['ip']
        self.nbd_root = self.parameters['lava-xnbd']['nbdroot']
        self.logger.debug(
            "NBD-IP: %s, NBD-PORT: %s, NBD-ROOT: %s" %
            (self.nbd_server_ip, self.nbd_server_port, self.nbd_root))
        nbd_cmd = [
            'xnbd-server', '--logpath',
            '/tmp/xnbd.log.%s' % self.nbd_server_port, '--daemon', '--target',
            '--lport',
            '%s' % self.nbd_server_port,
            '%s/%s' % (os.path.realpath(tftpd_dir()), self.nbd_root)
        ]
        command_output = self.run_command(nbd_cmd, allow_fail=False)

        if command_output and 'error' in command_output:
            self.errors = infrastructure_error('xnbd-server: %s' %
                                               command_output)
        self.logger.debug("%s: starting xnbd-server done", self.name)
        return connection
Exemplo n.º 6
0
    def populate(self, parameters):
        self.tftp_dir = self.mkdtemp(override=tftpd_dir())
        self.internal_pipeline = Pipeline(parent=self,
                                          job=self.job,
                                          parameters=parameters)
        self.set_namespace_data(action=self.name,
                                label='tftp',
                                key='tftp_dir',
                                value=self.tftp_dir,
                                parameters=parameters)

        for key in ['initrd', 'kernel', 'dtb', 'nbdroot']:
            if key in parameters:
                download = DownloaderAction(key, path=self.tftp_dir)
                download.max_retries = 3  # overridden by failure_retry in the parameters, if set.
                self.internal_pipeline.add_action(download)
                if key == 'initrd':
                    self.set_namespace_data(action="tftp-deploy",
                                            label='tftp',
                                            key='ramdisk',
                                            value=True,
                                            parameters=parameters)
                    self.set_namespace_data(action=self.name,
                                            label='nbd',
                                            key='initrd',
                                            value=True,
                                            parameters=parameters)

        # prepare overlay
        self.internal_pipeline.add_action(OverlayAction())
        # setup values for protocol and later steps
        self.set_namespace_data(action=self.name,
                                label='nbd',
                                key='initrd',
                                value=True,
                                parameters=parameters)
        # store in parameters for protocol 'xnbd' to tear-down xnbd-server
        # and store in namespace for boot action
        # ip
        parameters['lava-xnbd'] = {}
        self.nbd_ip = dispatcher_ip(self.job.parameters['dispatcher'])
        parameters['lava-xnbd']['ip'] = self.nbd_ip
        self.set_namespace_data(action=self.name,
                                label='nbd',
                                key='nbd_server_ip',
                                value=self.nbd_ip,
                                parameters=parameters)
        # port
        self.nbd_port = get_free_port(self.job.parameters['dispatcher'])
        parameters['lava-xnbd']['port'] = self.nbd_port
        self.set_namespace_data(action=self.name,
                                label='nbd',
                                key='nbd_server_port',
                                value=self.nbd_port,
                                parameters=parameters)
        # handle XnbdAction next - bring-up xnbd-server
        self.internal_pipeline.add_action(XnbdAction())
Exemplo n.º 7
0
 def test_multi_uboot(self):
     self.assertIsNotNone(self.job)
     description_ref = pipeline_reference('uboot-multiple.yaml')
     self.assertEqual(description_ref, self.job.pipeline.describe(False))
     deploy = [action for action in self.job.pipeline.actions if action.name == 'tftp-deploy'][0]
     downloads = [action for action in deploy.internal_pipeline.actions if action.name == 'download_retry']
     for download in downloads:
         if download.key == 'nfsrootfs':
             # if using root, the path would be appended.
             self.assertIn(DISPATCHER_DOWNLOAD_DIR, download.path)
         else:
             self.assertIn(tftpd_dir(), download.path)
Exemplo n.º 8
0
 def test_tftp_pipeline(self):
     factory = Factory()
     job = factory.create_bbb_job('sample_jobs/uboot-ramdisk.yaml')
     self.assertEqual(
         [action.name for action in job.pipeline.actions],
         ['tftp-deploy', 'uboot-action', 'lava-test-retry', 'finalize']
     )
     tftp = [action for action in job.pipeline.actions if action.name == 'tftp-deploy'][0]
     self.assertTrue(tftp.get_common_data('tftp', 'ramdisk'))
     self.assertIsNotNone(tftp.internal_pipeline)
     self.assertEqual(
         [action.name for action in tftp.internal_pipeline.actions],
         ['download_retry', 'download_retry', 'download_retry', 'prepare-tftp-overlay', 'deploy-device-env']
     )
     self.assertIn('ramdisk', [action.key for action in tftp.internal_pipeline.actions if hasattr(action, 'key')])
     self.assertIn('kernel', [action.key for action in tftp.internal_pipeline.actions if hasattr(action, 'key')])
     self.assertIn('dtb', [action.key for action in tftp.internal_pipeline.actions if hasattr(action, 'key')])
     # allow root to compare the path (with the mkdtemp added)
     paths = {action.path for action in tftp.internal_pipeline.actions if hasattr(action, 'path')}
     self.assertNotIn('=', tftpd_dir())
     self.assertIn(
         tftpd_dir(),
         [item for item in paths][0]
     )
Exemplo n.º 9
0
 def __init__(self):
     """
     Uses the tftp directory for easier cleanup and for parity
     with the non-QEMU Debian Installer support.
     """
     super(DeployIsoAction, self).__init__()
     self.name = 'deploy-iso-installer'
     self.description = 'setup deployment for emulated installer'
     self.summary = 'pull kernel and initrd out of iso'
     self.suffix = None
     try:
         self.preseed_path = mkdtemp(basedir=tftpd_dir())
     except OSError:
         self.suffix = '/'
         self.preseed_path = mkdtemp()  # unit test support
     self.suffix = os.path.basename(self.preseed_path)
Exemplo n.º 10
0
 def __init__(self):
     super(TftpAction, self).__init__()
     self.name = "tftp-deploy"
     self.description = "download files and deploy using tftp"
     self.summary = "tftp deployment"
     self.tftp_dir = tftpd_dir()
     self.suffix = None
     try:
         self.tftp_dir = mkdtemp(basedir=self.tftp_dir)
     except OSError:
         # allows for unit tests to operate as normal user.
         self.suffix = '/'
     self.download_dir = DISPATCHER_DOWNLOAD_DIR  # used for NFS
     try:
         self.download_dir = mkdtemp(basedir=DISPATCHER_DOWNLOAD_DIR)
     except OSError:
         pass
Exemplo n.º 11
0
 def __init__(self):
     super(TftpAction, self).__init__()
     self.name = "tftp-deploy"
     self.description = "download files and deploy using tftp"
     self.summary = "tftp deploment"
     self.tftp_dir = tftpd_dir()
     self.suffix = None
     try:
         self.tftp_dir = mkdtemp(basedir=self.tftp_dir)
     except OSError:
         # allows for unit tests to operate as normal user.
         self.suffix = '/'
     self.download_dir = DISPATCHER_DOWNLOAD_DIR  # used for NFS
     try:
         self.download_dir = mkdtemp(basedir=DISPATCHER_DOWNLOAD_DIR)
     except OSError:
         pass
Exemplo n.º 12
0
    def populate(self, parameters):
        self.tftp_dir = self.mkdtemp(override=tftpd_dir())
        self.internal_pipeline = Pipeline(parent=self, job=self.job, parameters=parameters)
        self.set_namespace_data(action=self.name, label='tftp', key='tftp_dir', value=self.tftp_dir, parameters=parameters)

        for key in ['ramdisk', 'kernel', 'dtb', 'nfsrootfs', 'modules', 'preseed']:
            if key in parameters:
                download = DownloaderAction(key, path=self.tftp_dir)
                download.max_retries = 3  # overridden by failure_retry in the parameters, if set.
                self.internal_pipeline.add_action(download)
                if key == 'ramdisk':
                    self.set_namespace_data(action=self.name, label='tftp', key='ramdisk', value=True, parameters=parameters)

        # TftpAction is a deployment, so once the files are in place, just do the overlay
        self.internal_pipeline.add_action(PrepareOverlayTftp())
        if self.test_needs_deployment(parameters):
            self.internal_pipeline.add_action(DeployDeviceEnvironment())
Exemplo n.º 13
0
 def test_tftp_pipeline(self):
     factory = Factory()
     job = factory.create_job('sample_jobs/grub-ramdisk.yaml')
     self.assertEqual(
         [action.name for action in job.pipeline.actions],
         ['tftp-deploy', 'grub-main-action', 'lava-test-retry', 'finalize']
     )
     tftp = [action for action in job.pipeline.actions if action.name == 'tftp-deploy'][0]
     self.assertTrue(tftp.get_common_data('tftp', 'ramdisk'))
     self.assertIsNotNone(tftp.internal_pipeline)
     self.assertEqual(
         [action.name for action in tftp.internal_pipeline.actions],
         ['download_retry', 'download_retry', 'download_retry', 'prepare-tftp-overlay', 'deploy-device-env']
     )
     self.assertIn('ramdisk', [action.key for action in tftp.internal_pipeline.actions if hasattr(action, 'key')])
     self.assertIn('kernel', [action.key for action in tftp.internal_pipeline.actions if hasattr(action, 'key')])
     self.assertIn('dtb', [action.key for action in tftp.internal_pipeline.actions if hasattr(action, 'key')])
     self.assertNotIn('=', tftpd_dir())
Exemplo n.º 14
0
 def test_multi_uboot(self):
     self.assertIsNotNone(self.job)
     description_ref = pipeline_reference('uboot-multiple.yaml')
     self.assertEqual(description_ref, self.job.pipeline.describe(False))
     deploy = [
         action for action in self.job.pipeline.actions
         if action.name == 'tftp-deploy'
     ][0]
     downloads = [
         action for action in deploy.internal_pipeline.actions
         if action.name == 'download_retry'
     ]
     for download in downloads:
         if download.key == 'nfsrootfs':
             # if using root, the path would be appended.
             self.assertIn(DISPATCHER_DOWNLOAD_DIR, download.path)
         else:
             self.assertIn(tftpd_dir(), download.path)
Exemplo n.º 15
0
    def validate(self):
        super(NbdAction, self).validate()
        if 'kernel' not in self.parameters:
            self.errors = "%s needs a kernel to deploy" % self.name
        if not self.valid:
            return
        if 'nbdroot' not in self.parameters:
            self.errors = "NBD deployment needs a 'nbdroot' parameter"
        if 'initrd' not in self.parameters:
            self.errors = "NBD deployment needs an 'initrd' parameter"
        # we cannot work with these when using nbd
        if 'nfsrootfs' in self.parameters or 'nfs_url' in self.parameters:
            self.errors = "nfsrootfs or nfs_url cannot be used with NBD deployment, use a e.g. ext3/4 filesystem as 'nbdroot=' parameter"
        if 'ramdisk' in self.parameters:
            self.errors = "ramdisk cannot be used with NBD deployment, use a e.g. ext3/4 filesystem as 'initrd' parameter"

        if self.test_needs_deployment(self.parameters):
            lava_test_results_base = self.parameters['deployment_data'][
                'lava_test_results_dir']
            lava_test_results_dir = lava_test_results_base % self.job.job_id
            self.set_namespace_data(action='test',
                                    label='results',
                                    key='lava_test_results_dir',
                                    value=lava_test_results_dir)

        # Extract the 3 last path elements. See action.mkdtemp()
        suffix = os.path.join(*self.tftp_dir.split('/')[-2:])
        self.set_namespace_data(action="tftp-deploy",
                                label='tftp',
                                key='suffix',
                                value=suffix)
        # we need tftp _and_ xnbd-server
        self.errors = infrastructure_error('in.tftpd')
        self.errors = infrastructure_error('xnbd-server')

        # Check that the tmp directory is in the nbdd_dir or in /tmp for the
        # unit tests
        tftpd_directory = os.path.realpath(tftpd_dir())
        tftp_dir = os.path.realpath(self.tftp_dir)
        tmp_dir = tempfile.gettempdir()
        if not tftp_dir.startswith(tftpd_directory) and \
           not tftp_dir.startswith(tmp_dir):
            self.errors = "tftpd directory is not configured correctly, see /etc/default/tftpd-hpa"
Exemplo n.º 16
0
    def validate(self):
        super(TftpAction, self).validate()
        if "kernel" not in self.parameters:
            self.errors = "%s needs a kernel to deploy" % self.name
        if not self.valid:
            return
        if "nfsrootfs" in self.parameters and "nfs_url" in self.parameters:
            self.errors = "Only one of nfsrootfs or nfs_url can be specified"
        lava_test_results_dir = self.parameters["deployment_data"]["lava_test_results_dir"]
        self.data["lava_test_results_dir"] = lava_test_results_dir % self.job.job_id
        # Extract the 3 last path elements. See action.mkdtemp()
        suffix = os.path.join(*self.tftp_dir.split("/")[-2:])
        self.data[self.name].setdefault("suffix", suffix)
        self.errors = infrastructure_error("in.tftpd")

        # Check that the tmp directory is in the tftpd_dir or in /tmp for the
        # unit tests
        tftpd_directory = os.path.realpath(tftpd_dir())
        tftp_dir = os.path.realpath(self.tftp_dir)
        tmp_dir = tempfile.gettempdir()
        if not tftp_dir.startswith(tftpd_directory) and not tftp_dir.startswith(tmp_dir):
            self.errors = "tftpd directory is not configured correctly, see /etc/default/tftpd-hpa"
Exemplo n.º 17
0
 def test_tftp_pipeline(self):
     factory = Factory()
     job = factory.create_bbb_job('sample_jobs/uboot-ramdisk.yaml')
     self.assertEqual(
         [action.name for action in job.pipeline.actions],
         ['tftp-deploy', 'uboot-action', 'lava-test-retry', 'finalize'])
     tftp = [
         action for action in job.pipeline.actions
         if action.name == 'tftp-deploy'
     ][0]
     self.assertTrue(tftp.get_common_data('tftp', 'ramdisk'))
     self.assertIsNotNone(tftp.internal_pipeline)
     self.assertEqual(
         [action.name for action in tftp.internal_pipeline.actions], [
             'download_retry', 'download_retry', 'download_retry',
             'prepare-tftp-overlay', 'deploy-device-env'
         ])
     self.assertIn('ramdisk', [
         action.key for action in tftp.internal_pipeline.actions
         if hasattr(action, 'key')
     ])
     self.assertIn('kernel', [
         action.key for action in tftp.internal_pipeline.actions
         if hasattr(action, 'key')
     ])
     self.assertIn('dtb', [
         action.key for action in tftp.internal_pipeline.actions
         if hasattr(action, 'key')
     ])
     # allow root to compare the path (with the mkdtemp added)
     paths = {
         action.path
         for action in tftp.internal_pipeline.actions
         if hasattr(action, 'path')
     }
     self.assertIn(tftpd_dir(), [item for item in paths][0])