예제 #1
0
    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)
예제 #2
0
    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)
예제 #3
0
 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]")
예제 #4
0
    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
예제 #5
0
파일: Client.py 프로젝트: pombredanne/shine
    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 = {}
예제 #6
0
    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))
예제 #7
0
 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')
예제 #8
0
    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', {})
예제 #9
0
    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)
예제 #10
0
 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)
예제 #11
0
 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)
예제 #12
0
    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)
예제 #13
0
    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)
예제 #14
0
 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)
예제 #15
0
    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 = {}
예제 #16
0
 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)
예제 #17
0
 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
예제 #18
0
 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])
예제 #19
0
    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
예제 #20
0
    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
예제 #21
0
 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')
예제 #22
0
 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)
예제 #23
0
 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')
예제 #24
0
 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)
예제 #25
0
 def __init__(self, target, device):
     Component.__init__(self, target.fs, target.server,
                        target.action_enabled, target._mode)
     self.target = target
     self.dev = device
예제 #26
0
 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)
예제 #27
0
 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')
예제 #28
0
 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)