def testGenericComponent(self): """test ComponentGroup simple methods""" fs = FileSystem('comp') grp = ComponentGroup() self.assertEqual(len(grp), 0) comp = Component(fs, Server('foo', ['foo@tcp'])) comp.TYPE = 'A' # add() grp.add(comp) # __len__ self.assertEqual(len(grp), 1) # __str__ self.assertEqual(str(grp), 'comp-A') # __getitem__ self.assertEqual(grp[comp.uniqueid()], comp) # __contains__ self.assertTrue(comp in grp) # __iter__ self.assertEqual(list(iter(grp)), [ comp ]) # Could not add() twice the same component try: grp.add(comp) except KeyError as error: txt = "'A component with id comp-A-foo@tcp already exists.'" self.assertEqual(str(error), txt)
def testGenericComponent(self): """test ComponentGroup simple methods""" fs = FileSystem('comp') grp = ComponentGroup() self.assertEqual(len(grp), 0) comp = Component(fs, Server('foo', ['foo@tcp'])) comp.TYPE = 'A' # add() grp.add(comp) # __len__ self.assertEqual(len(grp), 1) # __str__ self.assertEqual(str(grp), 'comp-A') # __getitem__ self.assertEqual(grp[comp.uniqueid()], comp) # __contains__ self.assertTrue(comp in grp) # __iter__ self.assertEqual(list(iter(grp)), [ comp ]) # Could not add() twice the same component try: grp.add(comp) except KeyError, error: txt = "'A component with id comp-A-foo@tcp already exists.'" self.assertEqual(str(error), txt)
def testServers(self): """test ComponentGroup.servers()""" fs = FileSystem('comp') grp = ComponentGroup() grp.add(Component(fs, Server('foo1', ['foo1@tcp']))) grp.add(Component(fs, Server('foo2', ['foo2@tcp']))) self.assertEqual(str(grp.servers()), "foo[1-2]")
def __init__(self, fs, server, index, dev, jdev=None, group=None, tag=None, enabled=True, mode='managed', network=None, active='yes'): """ Initialize a Lustre target object. """ Disk.__init__(self, dev) self._states = {} Component.__init__(self, fs, server, enabled, mode, active) self.defaultserver = server # Default server the target runs on self.failservers = ServerGroup() # All failover servers assert index is not None self.index = int(index) self.group = group self.tag = tag self.network = network self.mntdev = self.dev self.recov_info = None if jdev: self.journal = Journal(self, jdev) else: self.journal = None # If target mode is external then set target state accordingly if self.is_external(): self.state = EXTERNAL # If target is inactive, then set target state accordingly if not self.is_active(): self.state = INACTIVE
def __init__(self, fs, server, mount_path, mount_options=None, enabled=True): """ Initialize a Lustre client object. """ self.mount_options = mount_options self.mount_path = mount_path Component.__init__(self, fs, server, enabled) self.mtpt = None self.proc_states = {}
def update(self, other): """ Update my serializable fields from other/distant object. """ Disk.update(self, other) Component.update(self, other) self.index = other.index # Compat v0.910: 'recov_info' value depends on remote version self.recov_info = getattr(other, 'recov_info', getattr(other, 'status_info', None))
def testLabels(self): """test ComponentGroup.labels()""" fs = FileSystem('comp') grp = ComponentGroup() comp = Component(fs, Server('foo1', ['foo1@tcp'])) comp.TYPE = 'A' grp.add(comp) comp = Component(fs, Server('foo2', ['foo2@tcp'])) comp.TYPE = 'B' grp.add(comp) self.assertEqual(str(grp.labels()), 'comp-A,comp-B')
def update(self, other): """ Update my serializable fields from other/distant object. """ Component.update(self, other) self.mount_path = other.mount_path # Compat v0.910: Following values depend on Shine remote version self.mount_options = getattr(other, 'mount_options', None) self.mtpt = getattr(other, 'mtpt', getattr(other, 'status_info', None)) self.proc_states = getattr(other, 'proc_states', {})
def update(self, other): """ Update my serializable fields from other/distant object. """ Component.update(self, other) self.mount_path = other.mount_path # Compat v0.910: Following values depend on Shine remote version self.mount_options = getattr(other, 'mount_options', None) self.mtpt = getattr(other, 'mtpt', getattr(other, 'status_info', None)) self.proc_states = getattr(other, 'proc_states', {}) self.subdir = getattr(other, 'subdir', None)
def testUpdate(self): """test ComponentGroup.update()""" fs = FileSystem('comp') grp1 = ComponentGroup() comp1 = Component(fs, Server('foo1', ['foo1@tcp'])) grp1.add(comp1) grp2 = ComponentGroup() comp2 = Component(fs, Server('foo2', ['foo2@tcp'])) grp2.add(comp2) grp1.update(grp2) self.assertEqual(len(grp1), 2) self.assertTrue(comp1 in grp1) self.assertTrue(comp2 in grp1)
def testOr(self): """test ComponentGroup.__or__()""" fs = FileSystem('comp') grp1 = ComponentGroup() comp1 = Component(fs, Server('foo1', ['foo1@tcp'])) grp1.add(comp1) grp2 = ComponentGroup() comp2 = Component(fs, Server('foo2', ['foo2@tcp'])) grp2.add(comp2) merge = grp1|grp2 self.assertEqual(len(merge), 2) self.assertTrue(comp1 in merge) self.assertTrue(comp2 in merge)
def uniqueid(self): """ Return a unique string representing this client. This takes self.mount_path in account. """ return "%s-%s" % (Component.uniqueid(self), self.mount_path)
def testManaged(self): """test ComponentGroup.managed()""" fs = FileSystem('comp') grp = ComponentGroup() comp1 = Component(fs, Server('foo1', ['foo1@tcp']), mode="external") grp.add(comp1) comp2 = Component(fs, Server('foo2', ['foo2@tcp'])) grp.add(comp2) comp3 = Component(fs, Server('foo3', ['foo3@tcp']), enabled=False) grp.add(comp3) comp4 = Component(fs, Server('foo4', ['foo4@tcp'])) grp.add(comp4) offgrp = grp.managed() self.assertEqual(len(offgrp), 2) self.assertTrue(comp2 in offgrp) self.assertTrue(comp4 in offgrp)
def __init__(self, fs, server, mount_path, mount_options=None, subdir=None, enabled=True): """ Initialize a Lustre client object. """ self.mount_options = mount_options self.mount_path = mount_path self.subdir = subdir Component.__init__(self, fs, server, enabled) self.mtpt = None self.proc_states = {}
def text_status(self): """ Return a human text form for the target state. """ if self.state == RECOVERING: return "%s for %s" % (self.STATE_TEXT_MAP.get(RECOVERING), self.recov_info) else: return Component.text_status(self)
def text_status(self): """ Return a human text form for the target state. """ state = Component.text_status(self) if self.state not in (TARGET_ERROR, RUNTIME_ERROR) and \ set((RUNTIME_ERROR, TARGET_ERROR)) & set(self._states.values()): state += "*" if self.state == RECOVERING: state += " for %s" % self.recov_info return state
def testGroupBy(self): """test ComponentGroup.groupby()""" fs = FileSystem('comp') grp = ComponentGroup() comp1 = Component(fs, Server('foo1', ['foo1@tcp']), mode="external") grp.add(comp1) comp2 = Component(fs, Server('foo2', ['foo2@tcp'])) grp.add(comp2) comp3 = Component(fs, Server('foo3', ['foo3@tcp']), mode="external") grp.add(comp3) comp4 = Component(fs, Server('foo4', ['foo4@tcp'])) grp.add(comp4) results = [[mode, list(comps)] for mode, comps in grp.groupby(attr='_mode')] self.assertEqual(len(results), 2) self.assertEqual(results[0][0], "external") self.assertTrue(comp1 in results[0][1]) self.assertTrue(comp3 in results[0][1]) self.assertEqual(results[1][0], "managed") self.assertTrue(comp2 in results[1][1]) self.assertTrue(comp4 in results[1][1])
def text_status(self): """ Return a human text form for the client state, displaying the various connection states if there are not FULL. """ text = Component.text_status(self) states = [] for state, total in self.proc_states.iteritems(): if state != 'FULL': states.append("%s=%d" % (state.lower(), total)) if states: text += ' (%s)' % ' '.join(states) return text
def text_status(self): """ Return a human text form for the client state, displaying the various connection states if there are not FULL. """ text = Component.text_status(self) states = [] for state, total in self.proc_states.items(): if state != 'FULL': states.append("%s=%d" % (state.lower(), total)) if states: text += ' (%s)' % ' '.join(states) return text
def testFilterSupports(self): """test ComponentGroup.filter(supports and key)""" fs = FileSystem('comp') grp = ComponentGroup() comp1 = Component(fs, Server('foo1', ['foo1@tcp'])) comp1.state = MOUNTED grp.add(comp1) comp2 = Component(fs, Server('foo2', ['foo2@tcp'])) comp2.state = OFFLINE grp.add(comp2) comp3 = Component(fs, Server('foo3', ['foo3@tcp'])) comp3.state = MOUNTED grp.add(comp3) comp4 = Component(fs, Server('foo4', ['foo4@tcp'])) comp4.state = OFFLINE grp.add(comp4) offgrp = grp.filter(supports='is_external', key=lambda comp: comp.state == OFFLINE) self.assertEqual(len(offgrp), 2) self.assertTrue(comp2 in offgrp) self.assertTrue(comp4 in offgrp)
def test_managed_active(self): """test ComponentGroup.managed() with active option""" fs = FileSystem('active') grp = ComponentGroup() srv = Server('foo1', ['foo1@tcp']) comp1 = Component(fs, srv) comp1.TYPE = 'A' grp.add(comp1) comp2 = Component(fs, srv, active='no') comp2.TYPE = 'B' grp.add(comp2) comp3 = Component(fs, srv, active='nocreate') comp3.TYPE = 'C' grp.add(comp3) comp4 = Component(fs, srv, active='no', mode='external') comp4.TYPE = 'D' grp.add(comp4) self.assertEqual(str(grp.managed()), 'active-A,active-C') self.assertEqual(str(grp.managed(inactive=True)), 'active-A,active-B,active-C,active-D')
def testGroupByServer(self): """test ComponentGroup.groupbyserver()""" fs = FileSystem('comp') grp = ComponentGroup() srv1 = Server('foo1', ['foo1@tcp']) srv2 = Server('foo2', ['foo2@tcp']) comp1 = Component(fs, srv1) comp1.TYPE = 'A' grp.add(comp1) comp2 = Component(fs, srv2) comp2.TYPE = 'B' grp.add(comp2) comp3 = Component(fs, srv1) comp3.TYPE = 'C' grp.add(comp3) comp4 = Component(fs, srv2) comp4.TYPE = 'D' grp.add(comp4) key = lambda c: c.TYPE results = [[srv, sorted(comps, key=key)] for srv, comps in grp.groupbyserver()] self.assertEqual(len(results), 2) self.assertTrue([srv1, [comp1, comp3]] in results) self.assertTrue([srv2, [comp2, comp4]] in results)
def __init__(self, target, device): Component.__init__(self, target.fs, target.server, target.action_enabled, target._mode) self.target = target self.dev = device