def run(self, connection, max_end_time): connection = super().run(connection, max_end_time) self.mntdir = mkdtemp(autoremove=False) lava_test_results_dir = self.get_namespace_data( action="test", label="results", key="lava_test_results_dir") test_mntdir = os.path.abspath("%s/%s" % (self.mntdir, lava_test_results_dir)) self.set_namespace_data(action=self.name, label="mntdir", key="mntdir", value=self.mntdir) self.set_namespace_data(action="mount-action", label="mntdir", key="mntdir", value=test_mntdir) offset = self.get_namespace_data(action="download-action", label=self.key, key="offset") mount_cmd = [ "mount", "-o", "loop,offset=%s" % offset, self.get_namespace_data(action="download-action", label=self.key, key="file"), self.mntdir, ] command_output = self.run_command(mount_cmd) if command_output and command_output != "": raise JobError("Unable to mount: %s" % command_output) # FIXME: JobError needs a unit test return connection
def run(self, connection, max_end_time): connection = self.get_namespace_data(action="shared", label="shared", key="connection", deepcopy=False) connection = super().run(connection, max_end_time) dstdir = mkdtemp() # mount self.run_cmd( ["mount", "-t", "vfat", self.usb_mass_device, dstdir], error_msg="Unable to mount USB device %s" % self.usb_mass_device, ) # copy files for f in self.filelist: self.logger.debug("Copying %s to %s", f, dstdir) shutil.copy2(f, dstdir) # sync self.run_cmd(["sync", dstdir], error_msg="Unable to sync %s" % dstdir) # umount self.run_cmd( ["umount", self.usb_mass_device], error_msg="Unable to unmount USB device %s" % self.usb_mass_device, ) self.set_namespace_data(action="shared", label="shared", key="connection", value=connection) return connection
def run(self, connection, max_end_time): connection = super().run(connection, max_end_time) self.mntdir = mkdtemp(autoremove=False) lava_test_results_dir = self.get_namespace_data( action='test', label='results', key='lava_test_results_dir') test_mntdir = os.path.abspath("%s/%s" % (self.mntdir, lava_test_results_dir)) self.set_namespace_data(action=self.name, label='mntdir', key='mntdir', value=self.mntdir) self.set_namespace_data(action='mount-action', label='mntdir', key='mntdir', value=test_mntdir) offset = self.get_namespace_data(action='download-action', label=self.key, key='offset') mount_cmd = [ 'mount', '-o', 'loop,offset=%s' % offset, self.get_namespace_data(action='download-action', label=self.key, key='file'), self.mntdir ] command_output = self.run_command(mount_cmd) if command_output and command_output != '': raise JobError("Unable to mount: %s" % command_output) # FIXME: JobError needs a unit test return connection
def run(self, connection, max_end_time, args=None): connection = super(FlashCMSISAction, self).run(connection, max_end_time, args) dstdir = mkdtemp() mount_command = "mount -t vfat %s %s" % (self.usb_mass_device, dstdir) self.run_command(mount_command.split(' '), allow_silent=True) # mount for f in self.filelist: self.logger.debug("Copying %s to %s", f, dstdir) shutil.copy2(f, dstdir) # umount umount_command = "umount %s" % self.usb_mass_device self.run_command(umount_command.split(' '), allow_silent=True) if self.errors: raise InfrastructureError("Unable to (un)mount USB device: %s" % self.usb_mass_device) self.set_namespace_data(action='shared', label='shared', key='connection', value=connection) return connection
def run(self, connection, max_end_time): connection = super().run(connection, max_end_time) dstdir = mkdtemp() mount_command = "mount -t vfat %s %s" % (self.usb_mass_device, dstdir) self.run_command(mount_command.split(' '), allow_silent=True) # mount for f in self.filelist: self.logger.debug("Copying %s to %s", f, dstdir) shutil.copy2(f, dstdir) # umount umount_command = "umount %s" % self.usb_mass_device self.run_command(umount_command.split(' '), allow_silent=True) if self.errors: raise InfrastructureError("Unable to (un)mount USB device: %s" % self.usb_mass_device) self.set_namespace_data(action='shared', label='shared', key='connection', value=connection) return connection
def test_pipeline(self): description_ref = self.pipeline_reference('kvm-inline.yaml') self.assertEqual(description_ref, self.job.pipeline.describe(False)) self.assertEqual(len(self.job.pipeline.describe()), 4) inline_repo = None for action in self.job.pipeline.actions: if isinstance(action, DeployAction): self.assertIsNotNone(action.internal_pipeline.actions[1]) overlay = action.pipeline.actions[1] self.assertIsNotNone(overlay.internal_pipeline.actions[1]) testdef = overlay.internal_pipeline.actions[2] self.assertIsNotNone(testdef.internal_pipeline.actions[0]) inline_repo = testdef.internal_pipeline.actions[0] break # Test the InlineRepoAction directly self.assertIsNotNone(inline_repo) location = mkdtemp() # other actions have not been run, so fake up inline_repo.set_namespace_data(action='test', label='results', key='lava_test_results_dir', value=location) inline_repo.set_namespace_data(action='test', label='test-definition', key='overlay_dir', value=location) inline_repo.set_namespace_data(action='test', label='shared', key='location', value=location) inline_repo.set_namespace_data(action='test', label='test-definiton', key='overlay_dir', value=location) inline_repo.run(None, None) yaml_file = os.path.join(location, '0/tests/0_smoke-tests-inline/inline/smoke-tests-basic.yaml') self.assertTrue(os.path.exists(yaml_file)) with open(yaml_file, 'r') as f_in: testdef = yaml.safe_load(f_in) expected_testdef = {'metadata': {'description': 'Basic system test command for Linaro Ubuntu images', 'devices': ['panda', 'panda-es', 'arndale', 'vexpress-a9', 'vexpress-tc2'], 'format': 'Lava-Test Test Definition 1.0', 'name': 'smoke-tests-basic', 'os': ['ubuntu'], 'scope': ['functional'], 'yaml_line': 39}, 'run': {'steps': ['lava-test-case linux-INLINE-pwd --shell pwd', 'lava-test-case linux-INLINE-uname --shell uname -a', 'lava-test-case linux-INLINE-vmstat --shell vmstat', 'lava-test-case linux-INLINE-ifconfig --shell ifconfig -a', 'lava-test-case linux-INLINE-lscpu --shell lscpu', 'lava-test-case linux-INLINE-lsusb --shell lsusb', 'lava-test-case linux-INLINE-lsb_release --shell lsb_release -a'], 'yaml_line': 53}, 'yaml_line': 38} self.assertEqual(set(testdef), set(expected_testdef))
def test_pipeline(self): description_ref = self.pipeline_reference('kvm-inline.yaml') self.assertEqual(description_ref, self.job.pipeline.describe(False)) self.assertEqual(len(self.job.pipeline.describe()), 4) inline_repo = None for action in self.job.pipeline.actions: if isinstance(action, DeployAction): self.assertIsNotNone(action.internal_pipeline.actions[1]) overlay = action.pipeline.actions[1] self.assertIsNotNone(overlay.internal_pipeline.actions[1]) testdef = overlay.internal_pipeline.actions[2] self.assertIsNotNone(testdef.internal_pipeline.actions[0]) inline_repo = testdef.internal_pipeline.actions[0] break # Test the InlineRepoAction directly self.assertIsNotNone(inline_repo) location = mkdtemp() # other actions have not been run, so fake up inline_repo.set_namespace_data(action='test', label='results', key='lava_test_results_dir', value=location) inline_repo.set_namespace_data(action='test', label='test-definition', key='overlay_dir', value=location) inline_repo.set_namespace_data(action='test', label='shared', key='location', value=location) inline_repo.set_namespace_data(action='test', label='test-definiton', key='overlay_dir', value=location) inline_repo.run(None, None) yaml_file = os.path.join(location, '0/tests/0_smoke-tests-inline/inline/smoke-tests-basic.yaml') self.assertTrue(os.path.exists(yaml_file)) with open(yaml_file, 'r') as f_in: testdef = yaml.load(f_in) expected_testdef = {'metadata': {'description': 'Basic system test command for Linaro Ubuntu images', 'devices': ['panda', 'panda-es', 'arndale', 'vexpress-a9', 'vexpress-tc2'], 'format': 'Lava-Test Test Definition 1.0', 'name': 'smoke-tests-basic', 'os': ['ubuntu'], 'scope': ['functional'], 'yaml_line': 39}, 'run': {'steps': ['lava-test-case linux-INLINE-pwd --shell pwd', 'lava-test-case linux-INLINE-uname --shell uname -a', 'lava-test-case linux-INLINE-vmstat --shell vmstat', 'lava-test-case linux-INLINE-ifconfig --shell ifconfig -a', 'lava-test-case linux-INLINE-lscpu --shell lscpu', 'lava-test-case linux-INLINE-lsusb --shell lsusb', 'lava-test-case linux-INLINE-lsb_release --shell lsb_release -a'], 'yaml_line': 53}, 'yaml_line': 38} self.assertEqual(set(testdef), set(expected_testdef))
def run(self, connection, max_end_time, args=None): connection = super(LoopMountAction, self).run(connection, max_end_time, args) self.mntdir = mkdtemp(autoremove=False) lava_test_results_dir = self.get_namespace_data(action='test', label='results', key='lava_test_results_dir') test_mntdir = os.path.abspath("%s/%s" % (self.mntdir, lava_test_results_dir)) self.set_namespace_data(action=self.name, label='mntdir', key='mntdir', value=self.mntdir) self.set_namespace_data(action='mount-action', label='mntdir', key='mntdir', value=test_mntdir) offset = self.get_namespace_data(action='download-action', label=self.key, key='offset') mount_cmd = [ 'mount', '-o', 'loop,offset=%s' % offset, self.get_namespace_data(action='download-action', label=self.key, key='file'), self.mntdir ] command_output = self.run_command(mount_cmd) if command_output and command_output is not '': raise JobError("Unable to mount: %s" % command_output) # FIXME: JobError needs a unit test return connection
def run(self, connection, max_end_time): connection = super().run(connection, max_end_time) dstdir = mkdtemp() # mount self.run_cmd( ["mount", "-t", "vfat", self.usb_mass_device, dstdir], error_msg="Unable to mount USB device %s" % self.usb_mass_device, ) # copy files for f in self.filelist: self.logger.debug("Copying %s to %s", f, dstdir) shutil.copy2(f, dstdir) # sync self.run_cmd(["sync", dstdir], error_msg="Unable to sync %s" % dstdir) # umount self.run_cmd( ["umount", self.usb_mass_device], error_msg="Unable to unmount USB device %s" % self.usb_mass_device, ) return connection
def run(self, connection, max_end_time): connection = super().run(connection, max_end_time) method_parameters = self.job.device["actions"]["boot"]["methods"][ "cmsis-dap"]["parameters"] dstdir = mkdtemp() # mount self.run_cmd( ["mount", "-t", "vfat", self.usb_mass_device, dstdir], error_msg="Unable to mount USB device %s" % self.usb_mass_device, ) # log DAPLink metadata, to be able to correlate possible job issues # with bootloader version/options self.logger.debug("DAPLink virtual disk files: %s" % os.listdir(dstdir)) if os.path.isfile(dstdir + "/DETAILS.TXT"): with open(dstdir + "/DETAILS.TXT") as f: self.logger.debug("DAPLink Firmware DETAILS.TXT:\n%s" % f.read().replace("\r\n", "\n")) try: # copy files for f in self.filelist: self.logger.debug("Copying %s to %s", f, dstdir) shutil.copy2(f, dstdir) # sync written data self._sync_data(dstdir, method_parameters) finally: # umount self.run_cmd( ["umount", self.usb_mass_device], error_msg="Unable to unmount USB device %s" % self.usb_mass_device, ) post_unmount_delay = method_parameters.get("post_unmount_delay", 1) self.logger.debug("Post-unmount stabilization delay: %ss" % post_unmount_delay) time.sleep(post_unmount_delay) return connection
def test_pipeline(self): description_ref = self.pipeline_reference("kvm-inline.yaml") self.assertEqual(description_ref, self.job.pipeline.describe(False)) self.assertEqual(len(self.job.pipeline.describe()), 4) inline_repo = None for action in self.job.pipeline.actions: if isinstance(action, DeployAction): self.assertIsNotNone(action.internal_pipeline.actions[1]) overlay = action.pipeline.actions[1] self.assertIsNotNone(overlay.internal_pipeline.actions[1]) testdef = overlay.internal_pipeline.actions[2] self.assertIsNotNone(testdef.internal_pipeline.actions[0]) inline_repo = testdef.internal_pipeline.actions[0] break # Test the InlineRepoAction directly self.assertIsNotNone(inline_repo) location = mkdtemp() # other actions have not been run, so fake up inline_repo.set_namespace_data(action="test", label="results", key="lava_test_results_dir", value=location) inline_repo.set_namespace_data(action="test", label="test-definition", key="overlay_dir", value=location) inline_repo.set_namespace_data(action="test", label="shared", key="location", value=location) inline_repo.set_namespace_data(action="test", label="test-definiton", key="overlay_dir", value=location) inline_repo.run(None, None) yaml_file = os.path.join( location, "0/tests/0_smoke-tests-inline/inline/smoke-tests-basic.yaml") self.assertTrue(os.path.exists(yaml_file)) with open(yaml_file, "r") as f_in: testdef = yaml.safe_load(f_in) expected_testdef = { "metadata": { "description": "Basic system test command for Linaro Ubuntu images", "devices": [ "panda", "panda-es", "arndale", "vexpress-a9", "vexpress-tc2", ], "format": "Lava-Test Test Definition 1.0", "name": "smoke-tests-basic", "os": ["ubuntu"], "scope": ["functional"], }, "run": { "steps": [ "lava-test-case linux-INLINE-pwd --shell pwd", "lava-test-case linux-INLINE-uname --shell uname -a", "lava-test-case linux-INLINE-vmstat --shell vmstat", "lava-test-case linux-INLINE-ifconfig --shell ifconfig -a", "lava-test-case linux-INLINE-lscpu --shell lscpu", "lava-test-case linux-INLINE-lsusb --shell lsusb", "lava-test-case linux-INLINE-lsb_release --shell lsb_release -a", ] }, } self.assertEqual(set(testdef), set(expected_testdef))
def run(self, connection, max_end_time, args=None): # pylint: disable=too-many-branches connection = super(ApplyOverlayTftp, self).run(connection, max_end_time, args) directory = None nfs_address = None overlay_file = None namespace = self.parameters.get('namespace', None) if self.parameters.get('nfsrootfs', None) is not None: if not self.parameters['nfsrootfs'].get('install_overlay', True): self.logger.info("[%s] Skipping applying overlay to NFS", namespace) return connection overlay_file = self.get_namespace_data(action='compress-overlay', label='output', key='file') directory = self.get_namespace_data(action='extract-rootfs', label='file', key='nfsroot') if overlay_file: self.logger.info("[%s] Applying overlay to NFS", namespace) elif self.parameters.get('images', {}).get('nfsrootfs', None) is not None: if not self.parameters['images']['nfsrootfs'].get( 'install_overlay', True): self.logger.info("[%s] Skipping applying overlay to NFS", namespace) return connection overlay_file = self.get_namespace_data(action='compress-overlay', label='output', key='file') directory = self.get_namespace_data(action='extract-rootfs', label='file', key='nfsroot') if overlay_file: self.logger.info("[%s] Applying overlay to NFS", namespace) elif self.parameters.get('persistent_nfs', None) is not None: if not self.parameters['persistent_nfs'].get( 'install_overlay', True): self.logger.info( "[%s] Skipping applying overlay to persistent NFS", namespace) return connection overlay_file = self.get_namespace_data(action='compress-overlay', label='output', key='file') nfs_address = self.parameters['persistent_nfs'].get('address') if overlay_file: self.logger.info( "[%s] Applying overlay to persistent NFS address %s", namespace, nfs_address) # need to mount the persistent NFS here. # We can't use self.mkdtemp() here because this directory should # not be removed if umount fails. directory = mkdtemp(autoremove=False) try: subprocess.check_output( ['mount', '-t', 'nfs', nfs_address, directory]) except subprocess.CalledProcessError as exc: raise JobError(exc) elif self.parameters.get('ramdisk', None) is not None: if not self.parameters['ramdisk'].get('install_overlay', True): self.logger.info("[%s] Skipping applying overlay to ramdisk", namespace) return connection overlay_file = self.get_namespace_data(action='compress-overlay', label='output', key='file') directory = self.get_namespace_data( action='extract-overlay-ramdisk', label='extracted_ramdisk', key='directory') if overlay_file: self.logger.info("[%s] Applying overlay %s to ramdisk", namespace, overlay_file) elif self.parameters.get('rootfs', None) is not None: overlay_file = self.get_namespace_data(action='compress-overlay', label='output', key='file') directory = self.get_namespace_data(action='apply-overlay', label='file', key='root') else: self.logger.debug("[%s] No overlay directory", namespace) self.logger.debug(self.parameters) if self.parameters.get('os', None) == "centos_installer": # centos installer ramdisk doesnt like having anything other # than the kickstart config being inserted. Instead, make the # overlay accessible through tftp. Yuck. tftp_dir = os.path.dirname( self.get_namespace_data(action='download-action', label='ramdisk', key='file')) shutil.copy(overlay_file, tftp_dir) suffix = self.get_namespace_data(action='tftp-deploy', label='tftp', key='suffix') if not suffix: suffix = '' self.set_namespace_data(action=self.name, label='file', key='overlay', value=os.path.join( suffix, "ramdisk", os.path.basename(overlay_file))) if overlay_file: self.logger.debug("[%s] Applying overlay %s to directory %s", namespace, overlay_file, directory) untar_file(overlay_file, directory) if nfs_address: subprocess.check_output(['umount', directory]) os.rmdir(directory) # fails if the umount fails return connection
def run(self, connection, max_end_time): connection = super().run(connection, max_end_time) directory = None nfs_address = None overlay_file = None namespace = self.parameters.get("namespace") if self.parameters.get("nfsrootfs") is not None: if not self.parameters["nfsrootfs"].get("install_overlay", True): self.logger.info("[%s] Skipping applying overlay to NFS", namespace) return connection overlay_file = self.get_namespace_data(action="compress-overlay", label="output", key="file") directory = self.get_namespace_data(action="extract-rootfs", label="file", key="nfsroot") if overlay_file: self.logger.info("[%s] Applying overlay to NFS", namespace) elif self.parameters.get("images", {}).get("nfsrootfs") is not None: if not self.parameters["images"]["nfsrootfs"].get( "install_overlay", True): self.logger.info("[%s] Skipping applying overlay to NFS", namespace) return connection overlay_file = self.get_namespace_data(action="compress-overlay", label="output", key="file") directory = self.get_namespace_data(action="extract-rootfs", label="file", key="nfsroot") if overlay_file: self.logger.info("[%s] Applying overlay to NFS", namespace) elif self.parameters.get("persistent_nfs") is not None: if not self.parameters["persistent_nfs"].get( "install_overlay", True): self.logger.info( "[%s] Skipping applying overlay to persistent NFS", namespace) return connection overlay_file = self.get_namespace_data(action="compress-overlay", label="output", key="file") nfs_address = self.parameters["persistent_nfs"].get("address") if overlay_file: self.logger.info( "[%s] Applying overlay to persistent NFS address %s", namespace, nfs_address, ) # need to mount the persistent NFS here. # We can't use self.mkdtemp() here because this directory should # not be removed if umount fails. directory = mkdtemp(autoremove=False) try: subprocess.check_output( # nosec - internal. ["mount", "-t", "nfs", nfs_address, directory]) except subprocess.CalledProcessError as exc: raise JobError(exc) elif self.parameters.get("ramdisk") is not None: if not self.parameters["ramdisk"].get("install_overlay", True): self.logger.info("[%s] Skipping applying overlay to ramdisk", namespace) return connection overlay_file = self.get_namespace_data(action="compress-overlay", label="output", key="file") directory = self.get_namespace_data( action="extract-overlay-ramdisk", label="extracted_ramdisk", key="directory", ) if overlay_file: self.logger.info("[%s] Applying overlay %s to ramdisk", namespace, overlay_file) elif self.parameters.get("rootfs") is not None: overlay_file = self.get_namespace_data(action="compress-overlay", label="output", key="file") directory = self.get_namespace_data(action="apply-overlay", label="file", key="root") else: self.logger.debug("[%s] No overlay directory", namespace) self.logger.debug(self.parameters) if self.parameters.get("os") == "centos_installer": # centos installer ramdisk doesnt like having anything other # than the kickstart config being inserted. Instead, make the # overlay accessible through tftp. Yuck. tftp_dir = os.path.dirname( self.get_namespace_data(action="download-action", label="ramdisk", key="file")) shutil.copy(overlay_file, tftp_dir) suffix = self.get_namespace_data(action="tftp-deploy", label="tftp", key="suffix") if not suffix: suffix = "" self.set_namespace_data( action=self.name, label="file", key="overlay", value=os.path.join(suffix, "ramdisk", os.path.basename(overlay_file)), ) if overlay_file: self.logger.debug( "[%s] Applying overlay %s to directory %s", namespace, overlay_file, directory, ) untar_file(overlay_file, directory) if nfs_address: subprocess.check_output(["umount", directory]) # nosec - internal. os.rmdir(directory) # fails if the umount fails return connection
def run(self, connection, max_end_time, args=None): # pylint: disable=too-many-branches connection = super(ApplyOverlayTftp, self).run(connection, max_end_time, args) directory = None nfs_address = None overlay_file = None namespace = self.parameters.get('namespace', None) if self.parameters.get('nfsrootfs', None) is not None: if not self.parameters['nfsrootfs'].get('install_overlay', True): self.logger.info("[%s] Skipping applying overlay to NFS", namespace) return connection overlay_file = self.get_namespace_data(action='compress-overlay', label='output', key='file') directory = self.get_namespace_data(action='extract-rootfs', label='file', key='nfsroot') if overlay_file: self.logger.info("[%s] Applying overlay to NFS", namespace) elif self.parameters.get('images', {}).get('nfsrootfs', None) is not None: if not self.parameters['images']['nfsrootfs'].get('install_overlay', True): self.logger.info("[%s] Skipping applying overlay to NFS", namespace) return connection overlay_file = self.get_namespace_data(action='compress-overlay', label='output', key='file') directory = self.get_namespace_data(action='extract-rootfs', label='file', key='nfsroot') if overlay_file: self.logger.info("[%s] Applying overlay to NFS", namespace) elif self.parameters.get('persistent_nfs', None) is not None: if not self.parameters['persistent_nfs'].get('install_overlay', True): self.logger.info("[%s] Skipping applying overlay to persistent NFS", namespace) return connection overlay_file = self.get_namespace_data(action='compress-overlay', label='output', key='file') nfs_address = self.parameters['persistent_nfs'].get('address') if overlay_file: self.logger.info("[%s] Applying overlay to persistent NFS address %s", namespace, nfs_address) # need to mount the persistent NFS here. # We can't use self.mkdtemp() here because this directory should # not be removed if umount fails. directory = mkdtemp(autoremove=False) try: subprocess.check_output(['mount', '-t', 'nfs', nfs_address, directory]) except subprocess.CalledProcessError as exc: raise JobError(exc) elif self.parameters.get('ramdisk', None) is not None: if not self.parameters['ramdisk'].get('install_overlay', True): self.logger.info("[%s] Skipping applying overlay to ramdisk", namespace) return connection overlay_file = self.get_namespace_data(action='compress-overlay', label='output', key='file') directory = self.get_namespace_data(action='extract-overlay-ramdisk', label='extracted_ramdisk', key='directory') if overlay_file: self.logger.info("[%s] Applying overlay %s to ramdisk", namespace, overlay_file) elif self.parameters.get('rootfs', None) is not None: overlay_file = self.get_namespace_data(action='compress-overlay', label='output', key='file') directory = self.get_namespace_data(action='apply-overlay', label='file', key='root') else: self.logger.debug("[%s] No overlay directory", namespace) self.logger.debug(self.parameters) if self.parameters.get('os', None) == "centos_installer": # centos installer ramdisk doesnt like having anything other # than the kickstart config being inserted. Instead, make the # overlay accessible through tftp. Yuck. tftp_dir = os.path.dirname(self.get_namespace_data(action='download-action', label='ramdisk', key='file')) shutil.copy(overlay_file, tftp_dir) suffix = self.get_namespace_data(action='tftp-deploy', label='tftp', key='suffix') if not suffix: suffix = '' self.set_namespace_data(action=self.name, label='file', key='overlay', value=os.path.join(suffix, "ramdisk", os.path.basename(overlay_file))) if overlay_file: self.logger.debug("[%s] Applying overlay %s to directory %s", namespace, overlay_file, directory) untar_file(overlay_file, directory) if nfs_address: subprocess.check_output(['umount', directory]) os.rmdir(directory) # fails if the umount fails return connection