|
31 | 31 |
|
32 | 32 |
|
33 | 33 | @retry(reraise=True, stop=stop_after_attempt(5), wait=wait_fixed(60))
|
34 |
| -def mount_tape(robot, slot, drive): |
| 34 | +def mount_tape(robot, slot, drive, media_id='?'): |
35 | 35 | """
|
36 | 36 | Mounts tape from slot into drive
|
37 | 37 |
|
38 | 38 | Args:
|
39 | 39 | robot: The device used to mount the tape
|
40 | 40 | slot: Which slot to load from
|
41 | 41 | drive: Which drive to load to
|
| 42 | + media_id: The id for the medium, e.g. barcode (only for logging) |
42 | 43 | """
|
43 | 44 |
|
44 | 45 | logger = logging.getLogger('essarch.storage.tape')
|
45 | 46 | cmd = 'mtx -f %s load %d %d' % (robot, slot, drive)
|
46 | 47 | p = Popen(shlex.split(cmd), stdout=PIPE, stderr=PIPE, universal_newlines=True)
|
47 | 48 | logger.debug(
|
48 |
| - 'Mounting tape from {slot} to {drive} using {robot}: {cmd}'.format( |
49 |
| - slot=slot, drive=drive, robot=robot, cmd=cmd |
| 49 | + 'Mounting tape {media_id} from {slot} to {drive} using {robot}: {cmd}'.format( |
| 50 | + media_id=media_id, slot=slot, drive=drive, robot=robot, cmd=cmd |
50 | 51 | )
|
51 | 52 | )
|
52 | 53 | out, err = p.communicate()
|
53 | 54 |
|
54 | 55 | if p.returncode:
|
55 | 56 | if re.match(r'Drive \d+ Full \(Storage Element \d+ loaded\)', err):
|
56 | 57 | logger.warning(
|
57 |
| - 'Tried to mount already mounted tape from {slot} to {drive} using {robot}'.format( |
58 |
| - slot=slot, drive=drive, robot=robot |
| 58 | + 'Tried to mount already mounted tape {media_id} from {slot} to {drive} using {robot}'.format( |
| 59 | + media_id=media_id, slot=slot, drive=drive, robot=robot |
59 | 60 | )
|
60 | 61 | )
|
61 | 62 | raise TapeMountedError(err)
|
62 | 63 |
|
63 | 64 | logger.error(
|
64 |
| - 'Failed to mount tape from {slot} to {drive} using {robot}, err: {err}, returncode: {rcode}'.format( |
65 |
| - slot=slot, drive=drive, robot=robot, err=err, rcode=p.returncode |
66 |
| - ) |
| 65 | + 'Failed to mount tape {media_id} from {slot} to {drive} using {robot}, err: {err}, returncode: \ |
| 66 | +{rcode}'.format(media_id=media_id, slot=slot, drive=drive, robot=robot, err=err, rcode=p.returncode) |
67 | 67 | )
|
68 | 68 | raise RobotMountException('%s, return code: %s' % (err, p.returncode))
|
69 | 69 |
|
70 |
| - logger.info('Mounted tape from {slot} to {drive} using {robot}'.format(slot=slot, drive=drive, robot=robot)) |
| 70 | + logger.info('Mounted tape {media_id} from {slot} to {drive} using {robot}'.format( |
| 71 | + media_id=media_id, slot=slot, drive=drive, robot=robot)) |
71 | 72 | return out
|
72 | 73 |
|
73 | 74 |
|
74 | 75 | @retry(reraise=True, stop=stop_after_attempt(5), wait=wait_fixed(60))
|
75 |
| -def unmount_tape(robot, slot, drive): |
| 76 | +def unmount_tape(robot, slot, drive, media_id='?'): |
76 | 77 | """
|
77 | 78 | Unmounts tape from drive into slot
|
78 | 79 |
|
79 | 80 | Args:
|
80 | 81 | robot: The device used to unmount the tape
|
81 | 82 | slot: Which slot to unload to
|
82 | 83 | drive: Which drive to load from
|
| 84 | + media_id: The id for the medium, e.g. barcode (only for logging) |
83 | 85 | """
|
84 | 86 |
|
85 | 87 | logger = logging.getLogger('essarch.storage.tape')
|
86 | 88 | cmd = 'mtx -f %s unload %d %d' % (robot, slot, drive)
|
87 | 89 | p = Popen(shlex.split(cmd), stdout=PIPE, stderr=PIPE, universal_newlines=True)
|
88 | 90 | logger.debug(
|
89 |
| - 'Unmounting tape from {drive} to {slot} using {robot}: {cmd}'.format( |
90 |
| - drive=drive, slot=slot, robot=robot, cmd=cmd |
| 91 | + 'Unmounting tape {media_id} from {drive} to {slot} using {robot}: {cmd}'.format( |
| 92 | + media_id=media_id, drive=drive, slot=slot, robot=robot, cmd=cmd |
91 | 93 | )
|
92 | 94 | )
|
93 | 95 | out, err = p.communicate()
|
94 | 96 |
|
95 | 97 | if p.returncode:
|
96 | 98 | if re.match(r'Data Transfer Element \d+ is Empty', err):
|
97 | 99 | logger.warning(
|
98 |
| - 'Tried to unmount already unmounted tape from {drive} to {slot} using {robot}'.format( |
99 |
| - drive=drive, slot=slot, robot=robot |
| 100 | + 'Tried to unmount already unmounted tape {media_id} from {drive} to {slot} using {robot}'.format( |
| 101 | + media_id=media_id, drive=drive, slot=slot, robot=robot |
100 | 102 | )
|
101 | 103 | )
|
102 | 104 | raise TapeUnmountedError(err)
|
103 | 105 |
|
104 | 106 | logger.error(
|
105 |
| - 'Failed to unmount tape from {drive} to {slot} using {robot}, err: {err}, returncode: {rcode}'.format( |
106 |
| - drive=drive, slot=slot, robot=robot, err=err, rcode=p.returncode |
107 |
| - ) |
| 107 | + 'Failed to unmount tape {media_id} from {drive} to {slot} using {robot}, err: {err}, returncode: \ |
| 108 | +{rcode}'.format(media_id=media_id, drive=drive, slot=slot, robot=robot, err=err, rcode=p.returncode) |
108 | 109 | )
|
109 | 110 | raise RobotUnmountException('%s, return code: %s' % (err, p.returncode))
|
110 | 111 |
|
111 |
| - logger.info('Unmounted tape from {drive} to {slot} using {robot}'.format(drive=drive, slot=slot, robot=robot)) |
| 112 | + logger.info('Unmounted tape {media_id} from {drive} to {slot} using {robot}'.format( |
| 113 | + media_id=media_id, drive=drive, slot=slot, robot=robot)) |
112 | 114 | return out
|
113 | 115 |
|
114 | 116 |
|
|
0 commit comments