def __init__(self, key, opterr=None): # Check the XML definition file exists if not os.path.exists(XML_DEFS): print "No XML def file found" raise Exception.__init__(self, '') # Read the definition list self._fromxml('SM-errorcodes') ########DEBUG####### #for val in self.errorlist.keys(): # subdict = self.errorlist[val] # print "KEY [%s]" % val # for subval in subdict.keys(): # print "\tSUBKEY: %s, VALUE: %s" % (subval,subdict[subval]) ########END####### # Now find the specific error if self.errorlist.has_key(key): subdict = self.errorlist[key] errorcode = int(subdict['value']) errormessage = subdict['description'] if opterr is not None: errormessage += " [opterr=%s]" % opterr util.SMlog("Raising exception [%d, %s]" % (errorcode, errormessage)) raise SR.SROSError(errorcode, errormessage) # development error raise SR.SROSError(1, "Error reporting error, unknown key %s" % key)
def create(self, sr_uuid, size): if self.checkmount(): raise SR.SROSError(113, 'GlusterFS mount point already attached') try: self.mount() except GlusterFSException, exc: # noinspection PyBroadException try: os.rmdir(self.mountpoint) except: # we have no recovery strategy pass raise SR.SROSError(111, "GlusterFS mount error [opterr=%s]" % exc.errstr)
def attach(self, sr_uuid): if not self.checkmount(): try: self.mount() os.symlink(self.linkpath, self.path) except GlusterFSException, exc: raise SR.SROSError(12, exc.errstr)
def delete(self, sr_uuid): # try to remove/delete non VDI contents first super(GlusterFSSR, self).delete(sr_uuid) try: if self.checkmount(): self.detach(sr_uuid) self.mount() if util.ioretry(lambda: util.pathexists(self.linkpath)): util.ioretry(lambda: os.rmdir(self.linkpath)) self.unmount(self.mountpoint, True) except util.CommandException, inst: self.detach(sr_uuid) if inst.code != errno.ENOENT: raise SR.SROSError(114, "Failed to remove GlusterFS mount point")
def test_attach_nfs_no_server(self, _checkmount, testHost, makedirs, validate_nfsversion, convertDNS, gen_uuid): isosr = self.create_isosr(location='aServer:/aLocation', atype='nfs_iso', sr_uuid='asr_uuid') _checkmount.side_effect = [False] testHost.side_effect = SR.SROSError( 140, 'Incorrect DNS name, unable to resolve.') with self.assertRaises(SR.SROSError) as ose: isosr.attach(None) self.assertEqual(140, ose.exception.errno)
def test_after_master_attach_vdi_not_available( self, mock_log, mock_scan, mock_xenapi): """ Test that after_master_attach calls scan """ mock_session = mock.MagicMock(name='MockXapiSession') mock_xenapi.xapi_local.return_value = mock_session sr1 = self.create_SR("sr_create", {'ISCSIid': '12333423'}, {'session_ref': 'session1'}) mock_scan.side_effect = SR.SROSError(46, "The VDI is not available") sr1.after_master_attach('dummy uuid') mock_scan.assert_called_once_with(sr1, 'dummy uuid') self.assertEquals(1, mock_log.call_count) self.assertIn("Error in SR.after_master_attach", mock_log.call_args[0][0]) mock_session.xenapi.message.create.assert_called_once_with( "POST_ATTACH_SCAN_FAILED", 2, 'SR', 'dummy uuid', mock.ANY)
if util.ioretry(lambda: util.pathexists(self.linkpath)): if len(util.ioretry(lambda: util.listdir(self.linkpath))) != 0: self.detach(sr_uuid) raise xs_errors.XenError('SRExists') else: try: util.ioretry(lambda: util.makedirs(self.linkpath)) os.symlink(self.linkpath, self.path) except util.CommandException, inst: if inst.code != errno.EEXIST: try: self.unmount(self.mountpoint, True) except GlusterFSException: util.logException('GlusterFSSR.unmount()') raise SR.SROSError( 116, "Failed to create GlusterFS SR. remote directory creation error: {}" .format(os.strerror(inst.code))) self.detach(sr_uuid) def delete(self, sr_uuid): # try to remove/delete non VDI contents first super(GlusterFSSR, self).delete(sr_uuid) try: if self.checkmount(): self.detach(sr_uuid) self.mount() if util.ioretry(lambda: util.pathexists(self.linkpath)): util.ioretry(lambda: os.rmdir(self.linkpath)) self.unmount(self.mountpoint, True) except util.CommandException, inst: self.detach(sr_uuid)