Exemple #1
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"

        # 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
        which('in.tftpd')
        which('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"
Exemple #2
0
 def test_tftp_pipeline(self):
     job = self.factory.create_job('d02-01.jinja2',
                                   '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_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', 'lxc-create-udev-rule-action',
             '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())
Exemple #3
0
    def populate(self, parameters):
        self.tftp_dir = self.mkdtemp(override=filesystem.tftpd_dir())
        self.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:
                self.pipeline.add_action(
                    DownloaderAction(key,
                                     path=self.tftp_dir,
                                     params=parameters[key]))
                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.pipeline.add_action(PrepareOverlayTftp())
        self.pipeline.add_action(LxcCreateUdevRuleAction())
        if self.test_needs_deployment(parameters):
            self.pipeline.add_action(DeployDeviceEnvironment())
Exemple #4
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"
        # 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)
        which('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"
Exemple #5
0
    def run(self, connection, max_end_time):
        # 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)

        super().run(connection, max_end_time)
        tftp_size_limit = self.job.parameters["dispatcher"].get(
            "tftp_size_limit", TFTP_SIZE_LIMIT)
        self.logger.debug("Checking files for TFTP limit of %s bytes.",
                          tftp_size_limit)
        for (action, key) in [
            ("compress-ramdisk", "ramdisk"),
            ("download-action", "kernel"),
            ("download-action", "dtb"),
            ("download-action", "tee"),
        ]:
            if key in self.parameters:
                filename = self.get_namespace_data(action=action,
                                                   label="file",
                                                   key=key)
                filename = os.path.join(filesystem.tftpd_dir(), filename)
                fsize = os.stat(filename).st_size
                if fsize >= tftp_size_limit:
                    raise JobError(
                        "Unable to send '%s' over tftp: file too large (%d > %d)"
                        % (os.path.basename(filename), fsize, tftp_size_limit))
        return connection
Exemple #6
0
    def run(self, connection, max_end_time):
        connection = super().run(connection, max_end_time)
        self.logger.debug("%s: starting xnbd-server", self.name)
        # pull from parameters - as previously set
        self.nbd_root = self.parameters['lava-xnbd']['nbdroot']
        self.nbd_server_port = self.get_namespace_data(action='nbd-deploy',
                                                       label='nbd',
                                                       key='nbd_server_port')
        self.nbd_server_ip = self.get_namespace_data(action='nbd-deploy',
                                                     label='nbd',
                                                     key='nbd_server_ip')
        if self.nbd_server_port is None:
            self.errors = "NBD server port is unset"
            return connection
        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:
            raise JobError('xnbd-server: %s' % command_output)
        else:
            self.logger.debug("%s: starting xnbd-server done", self.name)
        return connection
Exemple #7
0
    def validate(self):
        super().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"

        # 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
        which('in.tftpd')
        which('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"
Exemple #8
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
Exemple #9
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:
                self.internal_pipeline.add_action(
                    DownloaderAction(key, path=self.tftp_dir))
                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())
        self.internal_pipeline.add_action(LxcCreateUdevRuleAction())
        if self.test_needs_deployment(parameters):
            self.internal_pipeline.add_action(DeployDeviceEnvironment())
Exemple #10
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())
Exemple #11
0
    def run(self, connection, max_end_time):
        connection = super().run(connection, max_end_time)
        self.logger.debug("%s: starting xnbd-server", self.name)
        # pull from parameters - as previously set
        self.nbd_root = self.parameters["lava-xnbd"]["nbdroot"]
        self.nbd_server_port = self.get_namespace_data(
            action="nbd-deploy", label="nbd", key="nbd_server_port"
        )
        self.nbd_server_ip = self.get_namespace_data(
            action="nbd-deploy", label="nbd", key="nbd_server_ip"
        )
        if self.nbd_server_port is None:
            self.errors = "NBD server port is unset"
            return connection
        self.logger.debug(
            "NBD-IP: %s, NBD-PORT: %s, NBD-ROOT: %s",
            self.nbd_server_ip,
            self.nbd_server_port,
            self.nbd_root,
        )
        if re.search(filesystem.tftpd_dir(), self.nbd_root):
            fullpath_nbdroot = self.nbd_root
        else:
            fullpath_nbdroot = "%s/%s" % (
                os.path.realpath(filesystem.tftpd_dir()),
                self.nbd_root,
            )
        nbd_cmd = [
            "xnbd-server",
            "--logpath",
            "/tmp/xnbd.log.%s" % self.nbd_server_port,
            "--daemon",
            "--target",
            "--lport",
            "%s" % self.nbd_server_port,
            fullpath_nbdroot,
        ]
        command_output = self.run_command(nbd_cmd, allow_fail=False)

        if command_output and "error" in command_output:
            raise JobError("xnbd-server: %s" % command_output)
        else:
            self.logger.debug("%s: starting xnbd-server done", self.name)
        return connection
Exemple #12
0
    def populate(self, parameters):
        self.tftp_dir = self.mkdtemp(override=filesystem.tftpd_dir())
        self.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,
                                            params=parameters[key])
                download.max_retries = (
                    3  # overridden by failure_retry in the parameters, if set.
                )
                self.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.pipeline.add_action(OverlayAction())
        if "kernel" in parameters and "type" in parameters["kernel"]:
            self.pipeline.add_action(PrepareKernelAction())
        # 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"] = {}
        # handle XnbdAction next - bring-up xnbd-server
        self.pipeline.add_action(XnbdAction())
Exemple #13
0
 def test_tftp_pipeline(self, which_mock):
     job = self.factory.create_bbb_job("sample_jobs/barebox-ramdisk.yaml")
     self.assertEqual(
         [action.name for action in job.pipeline.actions],
         ["tftp-deploy", "barebox-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",
             "lxc-create-udev-rule-action",
             "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)
Exemple #14
0
 def populate(self, parameters):
     self.preseed_path = self.mkdtemp(override=tftpd_dir())
     self.internal_pipeline = Pipeline(parent=self, job=self.job, parameters=parameters)
     self.internal_pipeline.add_action(IsoEmptyImage())
     # the preseed file needs to go into the dispatcher apache tmp directory.
     self.internal_pipeline.add_action(DownloaderAction('preseed', self.preseed_path))
     self.internal_pipeline.add_action(DownloaderAction('iso', self.mkdtemp()))
     self.internal_pipeline.add_action(IsoPullInstaller())
     self.internal_pipeline.add_action(QemuCommandLine())
     # prepare overlay at this stage - make it available after installation.
     self.internal_pipeline.add_action(OverlayAction())  # idempotent, includes testdef
     self.internal_pipeline.add_action(ApplyOverlayGuest())
     self.internal_pipeline.add_action(DeployDeviceEnvironment())
Exemple #15
0
 def test_tftp_pipeline(self):
     job = self.factory.create_job("d02-01.jinja2",
                                   "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_namespace_data(action=tftp.name,
                                 label="tftp",
                                 key="ramdisk"))
     self.assertIsNotNone(tftp.pipeline)
     self.assertEqual(
         [action.name for action in tftp.pipeline.actions],
         [
             "download-retry",
             "download-retry",
             "download-retry",
             "prepare-tftp-overlay",
             "lxc-create-udev-rule-action",
             "deploy-device-env",
         ],
     )
     self.assertIn(
         "ramdisk",
         [
             action.key
             for action in tftp.pipeline.actions if hasattr(action, "key")
         ],
     )
     self.assertIn(
         "kernel",
         [
             action.key
             for action in tftp.pipeline.actions if hasattr(action, "key")
         ],
     )
     self.assertIn(
         "dtb",
         [
             action.key
             for action in tftp.pipeline.actions if hasattr(action, "key")
         ],
     )
     self.assertNotIn("=", filesystem.tftpd_dir())
Exemple #16
0
 def run(self, connection, max_end_time, args=None):
     super(TftpAction, self).run(connection, max_end_time, args)
     tftp_size_limit = self.job.parameters['dispatcher'].get('tftp_size_limit',
                                                             TFTP_SIZE_LIMIT)
     self.logger.debug("Checking files for TFTP limit of %s bytes.", tftp_size_limit)
     for (action, key) in [('compress-ramdisk', 'ramdisk'),
                           ('download-action', 'kernel'),
                           ('download-action', 'dtb')]:
         if key in self.parameters:
             filename = self.get_namespace_data(action=action, label='file', key=key)
             filename = os.path.join(tftpd_dir(), filename)
             fsize = os.stat(filename).st_size
             if fsize >= tftp_size_limit:
                 raise JobError("Unable to send '%s' over tftp: file too large (%d > %d)" %
                                (os.path.basename(filename), fsize, tftp_size_limit))
     return connection
Exemple #17
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:
                self.internal_pipeline.add_action(DownloaderAction(key, path=self.tftp_dir))
                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())
        self.internal_pipeline.add_action(LxcCreateUdevRuleAction())
        if self.test_needs_deployment(parameters):
            self.internal_pipeline.add_action(DeployDeviceEnvironment())
Exemple #18
0
 def run(self, connection, max_end_time, args=None):
     super(TftpAction, self).run(connection, max_end_time, args)
     tftp_size_limit = self.job.parameters['dispatcher'].get('tftp_size_limit',
                                                             TFTP_SIZE_LIMIT)
     self.logger.debug("Checking files for TFTP limit of %s bytes.", tftp_size_limit)
     for (action, key) in [('compress-ramdisk', 'ramdisk'),
                           ('download-action', 'kernel'),
                           ('download-action', 'dtb')]:
         if key in self.parameters:
             filename = self.get_namespace_data(action=action, label='file', key=key)
             filename = os.path.join(tftpd_dir(), filename)
             fsize = os.stat(filename).st_size
             if fsize >= tftp_size_limit:
                 raise JobError("Unable to send '%s' over tftp: file too large (%d > %d)" %
                                (os.path.basename(filename), fsize, tftp_size_limit))
     return connection
Exemple #19
0
 def test_tftp_pipeline(self):
     job = self.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_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', 'lxc-create-udev-rule-action', '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())
Exemple #20
0
    def validate(self):
        super().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 "persistent_nfs" in self.parameters:
            self.errors = "Only one of nfsrootfs or persistent_nfs can be specified"
        which("in.tftpd")

        # Check that the tmp directory is in the tftpd_dir or in /tmp for the
        # unit tests
        tftpd_directory = os.path.realpath(filesystem.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"
Exemple #21
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"
        # 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)
        which('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"
Exemple #22
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_root = self.parameters['lava-xnbd']['nbdroot']
        self.nbd_server_port = self.get_namespace_data(action='nbd-deploy', label='nbd', key='nbd_server_port')
        self.nbd_server_ip = self.get_namespace_data(action='nbd-deploy', label='nbd', key='nbd_server_ip')
        if self.nbd_server_port is None:
            self.errors = "NBD server port is unset"
            return connection
        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:
            raise JobError('xnbd-server: %s' % command_output)
        else:
            self.logger.debug("%s: starting xnbd-server done", self.name)
        return connection
Exemple #23
0
 def populate(self, parameters):
     self.preseed_path = self.mkdtemp(override=filesystem.tftpd_dir())
     self.pipeline = Pipeline(parent=self,
                              job=self.job,
                              parameters=parameters)
     self.pipeline.add_action(IsoEmptyImage())
     # the preseed file needs to go into the dispatcher apache tmp directory.
     self.pipeline.add_action(
         DownloaderAction("preseed",
                          self.preseed_path,
                          params=parameters["images"]["preseed"]))
     self.pipeline.add_action(
         DownloaderAction("iso",
                          self.mkdtemp(),
                          params=parameters["images"]["iso"]))
     self.pipeline.add_action(IsoPullInstaller())
     self.pipeline.add_action(QemuCommandLine())
     # prepare overlay at this stage - make it available after installation.
     if self.test_needs_overlay(parameters):
         self.pipeline.add_action(
             OverlayAction())  # idempotent, includes testdef
         self.pipeline.add_action(ApplyOverlayGuest())
     if self.test_needs_deployment(parameters):
         self.pipeline.add_action(DeployDeviceEnvironment())
Exemple #24
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'] = {}
        # handle XnbdAction next - bring-up xnbd-server
        self.internal_pipeline.add_action(XnbdAction())