def test_image_extract(self): img1 = self._create_tar({ 'file1': BytesIO(b'a'), 'file2': BytesIO(b'b') }) img1_dev = '/dev/1.%s' % os.path.basename(img1) img2 = self._create_tar({ 'file3': BytesIO(b'a'), 'file4': BytesIO(b'b') }) img2_dev = '/dev/2.%s' % os.path.basename(img2) opts = '--zvm-image=%s --zvm-image=%s,/lib' % (img1, img2) self.program = 'file2' self.argv = [ZVSH] self.argv.extend(opts.split()) self.argv.append(self.program) cmd_line = self.program shell = Shell(self.argv) try: with pytest.raises(SystemExit): shell.run() files = os.listdir(shell.zvsh.tmpdir) self.assertTrue('manifest.1' in files) self.assertTrue('nvram.1' in files) manifest = _read_manifest( join_path(shell.zvsh.tmpdir, 'manifest.1')) boot = os.path.join(os.path.abspath(shell.zvsh.tmpdir), 'boot.1') reference = self._reference_manifest(shell.zvsh.tmpdir, executable=boot) channels = reference['channel'] img1_chan = [ os.path.abspath(img1), img1_dev, '3', '0', str(DEFAULT_LIMITS['reads']), str(DEFAULT_LIMITS['rbytes']), str(DEFAULT_LIMITS['writes']), str(DEFAULT_LIMITS['wbytes']) ] img2_chan = [ os.path.abspath(img2), img2_dev, '3', '0', str(DEFAULT_LIMITS['reads']), str(DEFAULT_LIMITS['rbytes']), str(DEFAULT_LIMITS['writes']), str(DEFAULT_LIMITS['wbytes']) ] # insert in reverse order channels.insert(3, img2_chan) channels.insert(3, img1_chan) self.assertEqual(manifest, reference) nvram = _read_nvram(join_path(shell.zvsh.tmpdir, 'nvram.1')) reference = _reference_nvram(cmd_line, images=[(img1_dev, '/', 'ro', 'no'), (img2_dev, '/lib', 'ro', 'no') ]) self.assertEqual(nvram, reference) finally: shell.zvsh.orig_cleanup()
def test_image_extract(self): img1 = self._create_tar({'file1': BytesIO(b'a'), 'file2': BytesIO(b'b')}) img1_dev = '/dev/1.%s' % os.path.basename(img1) img2 = self._create_tar({'file3': BytesIO(b'a'), 'file4': BytesIO(b'b')}) img2_dev = '/dev/2.%s' % os.path.basename(img2) opts = '--zvm-image=%s --zvm-image=%s,/lib' % (img1, img2) self.program = 'file2' self.argv = [ZVSH] self.argv.extend(opts.split()) self.argv.append(self.program) cmd_line = self.program shell = Shell(self.argv) try: with pytest.raises(SystemExit): shell.run() files = os.listdir(shell.zvsh.tmpdir) self.assertTrue('manifest.1' in files) self.assertTrue('nvram.1' in files) manifest = _read_manifest(join_path(shell.zvsh.tmpdir, 'manifest.1')) boot = os.path.join(os.path.abspath(shell.zvsh.tmpdir), 'boot.1') reference = self._reference_manifest(shell.zvsh.tmpdir, executable=boot) channels = reference['channel'] img1_chan = [os.path.abspath(img1), img1_dev, '3', '0', str(DEFAULT_LIMITS['reads']), str(DEFAULT_LIMITS['rbytes']), str(DEFAULT_LIMITS['writes']), str(DEFAULT_LIMITS['wbytes'])] img2_chan = [os.path.abspath(img2), img2_dev, '3', '0', str(DEFAULT_LIMITS['reads']), str(DEFAULT_LIMITS['rbytes']), str(DEFAULT_LIMITS['writes']), str(DEFAULT_LIMITS['wbytes'])] # insert in reverse order channels.insert(3, img2_chan) channels.insert(3, img1_chan) self.assertEqual(manifest, reference) nvram = _read_nvram(join_path(shell.zvsh.tmpdir, 'nvram.1')) reference = _reference_nvram( cmd_line, images=[(img1_dev, '/', 'ro', 'no'), (img2_dev, '/lib', 'ro', 'no')]) self.assertEqual(nvram, reference) finally: shell.zvsh.orig_cleanup()
def test_input_output_file(self): in_fd, in_name = mkstemp(dir=self.testdir) os.write(in_fd, b'test') os.close(in_fd) out_fd, out_name = mkstemp(dir=self.testdir) os.close(out_fd) os.unlink(out_name) self.assertFalse(os.path.exists(out_name)) opts = '-i @%s -o @%s' % (in_name, out_name) in_dev_name = '/dev/1.%s' % os.path.basename(in_name) out_dev_name = '/dev/2.%s' % os.path.basename(out_name) cmd_line = ' '.join([self.program, '-i %s -o %s' % (in_dev_name, out_dev_name)]) self.argv.extend(opts.split()) shell = Shell(self.argv) try: with pytest.raises(SystemExit): shell.run() files = os.listdir(shell.zvsh.tmpdir) self.assertTrue('manifest.1' in files) self.assertTrue('nvram.1' in files) manifest = _read_manifest(join_path(shell.zvsh.tmpdir, 'manifest.1')) reference = self._reference_manifest(shell.zvsh.tmpdir) channels = reference['channel'] file_chan = [out_name, out_dev_name, '3', '0', str(DEFAULT_LIMITS['reads']), str(DEFAULT_LIMITS['rbytes']), str(DEFAULT_LIMITS['writes']), str(DEFAULT_LIMITS['wbytes'])] channels.insert(3, file_chan) file_chan = [in_name, in_dev_name, '3', '0', str(DEFAULT_LIMITS['reads']), str(DEFAULT_LIMITS['rbytes']), str(DEFAULT_LIMITS['writes']), str(DEFAULT_LIMITS['wbytes'])] channels.insert(3, file_chan) self.assertEqual(manifest, reference) nvram = _read_nvram(join_path(shell.zvsh.tmpdir, 'nvram.1')) reference = _reference_nvram(cmd_line, [{'channel': in_dev_name, 'mode': 'file'}, {'channel': out_dev_name, 'mode': 'file'}]) self.assertEqual(nvram, reference) self.assertTrue(os.path.exists(out_name)) finally: shell.zvsh.orig_cleanup()
def test_one_command(self): cmd_line = self.program shell = Shell(self.argv) try: with pytest.raises(SystemExit): shell.run() files = os.listdir(shell.zvsh.tmpdir) self.assertTrue('manifest.1' in files) self.assertTrue('nvram.1' in files) manifest = _read_manifest( join_path(shell.zvsh.tmpdir, 'manifest.1')) reference = self._reference_manifest(shell.zvsh.tmpdir) self.assertEqual(manifest, reference) nvram = _read_nvram(join_path(shell.zvsh.tmpdir, 'nvram.1')) reference = _reference_nvram(cmd_line) self.assertEqual(nvram, reference) finally: shell.zvsh.orig_cleanup()
def test_one_command(self): cmd_line = self.program shell = Shell(self.argv) try: with pytest.raises(SystemExit): shell.run() files = os.listdir(shell.zvsh.tmpdir) self.assertTrue('manifest.1' in files) self.assertTrue('nvram.1' in files) manifest = _read_manifest(join_path(shell.zvsh.tmpdir, 'manifest.1')) reference = self._reference_manifest(shell.zvsh.tmpdir) self.assertEqual(manifest, reference) nvram = _read_nvram(join_path(shell.zvsh.tmpdir, 'nvram.1')) reference = _reference_nvram(cmd_line) self.assertEqual(nvram, reference) finally: shell.zvsh.orig_cleanup()
def test_command_with_args(self): opts = '-t --test test' cmd_line = ' '.join([self.program, opts]) self.argv.extend(opts.split()) shell = Shell(self.argv) try: with pytest.raises(SystemExit): shell.run() files = os.listdir(shell.zvsh.tmpdir) self.assertTrue('manifest.1' in files) self.assertTrue('nvram.1' in files) manifest = _read_manifest( join_path(shell.zvsh.tmpdir, 'manifest.1')) reference = self._reference_manifest(shell.zvsh.tmpdir) self.assertEqual(manifest, reference) nvram = _read_nvram(join_path(shell.zvsh.tmpdir, 'nvram.1')) reference = _reference_nvram(cmd_line) self.assertEqual(nvram, reference) finally: shell.zvsh.orig_cleanup()
def test_command_with_args(self): opts = '-t --test test' cmd_line = ' '.join([self.program, opts]) self.argv.extend(opts.split()) shell = Shell(self.argv) try: with pytest.raises(SystemExit): shell.run() files = os.listdir(shell.zvsh.tmpdir) self.assertTrue('manifest.1' in files) self.assertTrue('nvram.1' in files) manifest = _read_manifest(join_path(shell.zvsh.tmpdir, 'manifest.1')) reference = self._reference_manifest(shell.zvsh.tmpdir) self.assertEqual(manifest, reference) nvram = _read_nvram(join_path(shell.zvsh.tmpdir, 'nvram.1')) reference = _reference_nvram(cmd_line) self.assertEqual(nvram, reference) finally: shell.zvsh.orig_cleanup()
def test_wo_image(self): img1 = self._create_tar({'file1': BytesIO(b'a'), 'file2': BytesIO(b'b')}) img1_dev = '/dev/1.%s' % os.path.basename(img1) opts = '--zvm-image=%s,/,wo' % img1 self.argv = [ZVSH] self.argv.extend(opts.split()) self.argv.append(self.program) cmd_line = self.program shell = Shell(self.argv) try: with pytest.raises(SystemExit): shell.run() files = os.listdir(shell.zvsh.tmpdir) self.assertTrue('manifest.1' in files) self.assertTrue('nvram.1' in files) manifest = _read_manifest(join_path(shell.zvsh.tmpdir, 'manifest.1')) reference = self._reference_manifest(shell.zvsh.tmpdir) channels = reference['channel'] img1_chan = [os.path.abspath(img1), img1_dev, '3', '0', str(DEFAULT_LIMITS['reads']), str(DEFAULT_LIMITS['rbytes']), str(DEFAULT_LIMITS['writes']), str(DEFAULT_LIMITS['wbytes'])] channels.insert(3, img1_chan) self.assertEqual(manifest, reference) nvram = _read_nvram(join_path(shell.zvsh.tmpdir, 'nvram.1')) reference = _reference_nvram( cmd_line, images=[(img1_dev, '/', 'wo', 'no')]) self.assertEqual(nvram, reference) finally: shell.zvsh.orig_cleanup()
def test_existing_file(self): fd, name = mkstemp(dir=self.testdir) os.write(fd, b'test') os.close(fd) opts = '-f @%s' % name dev_name = '/dev/1.%s' % os.path.basename(name) cmd_line = ' '.join([self.program, '-f %s' % dev_name]) self.argv.extend(opts.split()) shell = Shell(self.argv) try: with pytest.raises(SystemExit): shell.run() files = os.listdir(shell.zvsh.tmpdir) self.assertTrue('manifest.1' in files) self.assertTrue('nvram.1' in files) manifest = _read_manifest(join_path(shell.zvsh.tmpdir, 'manifest.1')) reference = self._reference_manifest(shell.zvsh.tmpdir) channels = reference['channel'] file_chan = [name, dev_name, '3', '0', str(DEFAULT_LIMITS['reads']), str(DEFAULT_LIMITS['rbytes']), str(DEFAULT_LIMITS['writes']), str(DEFAULT_LIMITS['wbytes'])] channels.insert(3, file_chan) self.assertEqual(manifest, reference) nvram = _read_nvram(join_path(shell.zvsh.tmpdir, 'nvram.1')) reference = _reference_nvram(cmd_line, [{'channel': dev_name, 'mode': 'file'}]) self.assertEqual(nvram, reference) finally: shell.zvsh.orig_cleanup()