Exemplo n.º 1
0
class ServerActionTest(CommonTestCase):
    def _clean_modules(self):
        """Remove all already loaded modules, before a test."""
        self.srv.lustre_check()
        if 'libcfs' in self.srv.modules or 'ldiskfs' in self.srv.modules:
            self.srv.unload_modules().launch()
            self.fs._run_actions()
            self.eh.clear()

    def setUp(self):
        CommonTestCase.setUp(self)
        self.srv = Server(Utils.HOSTNAME, ["%s@lo" % Utils.HOSTNAME],
                          hdlr=self.eh)
        self._clean_modules()

    def tearDown(self):
        self._clean_modules()

    #
    # Modules
    #

    @Utils.rootonly
    def test_module_load(self):
        """Load lustre modules is ok"""
        act = self.srv.load_modules()
        result = self.check_base(self.srv, 'server', act, ACT_OK,
                                 ['start', 'done'], "load module 'lustre'")
        self.assertEqual(result.retcode, 0)
        self.assertEqual(sorted(self.srv.modules.keys()), ['libcfs', 'lustre'])

    @Utils.rootonly
    def test_module_load_dryrun(self):
        """Load lustre modules in dry-run mode"""
        act = self.srv.load_modules(dryrun=True)
        text = 'modprobe lustre'
        self.check_dryrun(act, text, 'server', 'load modules',
                          ['start', 'done'], self.srv, "load module 'lustre'")
        self.assertEqual(sorted(self.srv.modules.keys()), [])

    @Utils.rootonly
    def test_module_load_custom(self):
        """Load a custom module is ok"""
        act = self.srv.load_modules(modname='ldiskfs')
        result = self.check_base(self.srv, 'server', act, ACT_OK,
                                 ['start', 'done'], "load module 'ldiskfs'")
        self.assertEqual(self.srv.modules.keys(), ['ldiskfs'])

    @Utils.rootonly
    def test_module_load_error(self):
        """Load a bad module is an error"""
        act = self.srv.load_modules(modname='ERROR')
        result = self.check_base(self.srv, 'server', act, ACT_ERROR,
                                 ['start', 'failed'], "load module 'ERROR'")
        self.assertEqual(result.retcode, 1)
        self.assertEqual(self.srv.modules, {})

    @Utils.rootonly
    def test_module_load_already_done(self):
        """Load modules when already loaded is ok"""
        def lustre_check(self):
            self.modules = {'lustre': 0, 'libcfs': 1}

        self.srv.lustre_check = types.MethodType(lustre_check, self.srv)
        act = self.srv.load_modules()
        result = self.check_base(self.srv, 'server', act, ACT_OK,
                                 ['start', 'done'], "load module 'lustre'")
        self.assertEqual(str(result), "'lustre' is already loaded")
        self.assertEqual(result.retcode, None)
        self.assertEqual(sorted(self.srv.modules.keys()), ['libcfs', 'lustre'])

    @Utils.rootonly
    def test_module_unload(self):
        """Unload modules"""
        # First load modules
        self.srv.load_modules().launch()
        self.fs._run_actions()
        self.eh.clear()

        act = self.srv.unload_modules()
        result = self.check_base(self.srv, 'server', act, ACT_OK,
                                 ['start', 'done'], 'unload modules')
        self.assertEqual(result.retcode, 0)
        self.assertEqual(self.srv.modules, {})

    @Utils.rootonly
    def test_module_unload_already_done(self):
        """Unload modules when already done is ok"""
        # By default modules are not loaded
        act = self.srv.unload_modules()
        result = self.check_base(self.srv, 'server', act, ACT_OK,
                                 ['start', 'done'], 'unload modules')
        self.assertEqual(str(result), 'modules already unloaded')
        self.assertEqual(result.retcode, None)
        self.assertEqual(self.srv.modules, {})
Exemplo n.º 2
0
class ServerActionTest(CommonTestCase):

    def _clean_modules(self):
        """Remove all already loaded modules, before a test."""
        self.srv.lustre_check()
        if 'libcfs' in self.srv.modules or 'ldiskfs' in self.srv.modules:
            self.srv.unload_modules().launch()
            self.fs._run_actions()
            self.eh.clear()

    def setUp(self):
        CommonTestCase.setUp(self)
        self.srv = Server(Utils.HOSTNAME, ["%s@lo" % Utils.HOSTNAME],
                          hdlr=self.eh)
        self._clean_modules()

    def tearDown(self):
        self._clean_modules()

    #
    # Modules
    #

    @Utils.rootonly
    def test_module_load(self):
        """Load lustre modules is ok"""
        act = self.srv.load_modules()
        result = self.check_base(self.srv, 'server', act, ACT_OK,
                                 ['start', 'done'],
                                 "load module 'lustre'")
        self.assertEqual(result.retcode, 0)
        self.assertEqual(sorted(self.srv.modules.keys()), ['libcfs', 'lustre'])

    @Utils.rootonly
    def test_module_load_dryrun(self):
        """Load lustre modules in dry-run mode"""
        act = self.srv.load_modules(dryrun=True)
        text = 'modprobe lustre'
        self.check_dryrun(act, text, 'server', 'load modules',
                          ['start', 'done'], self.srv, "load module 'lustre'")
        self.assertEqual(sorted(self.srv.modules.keys()), [])

    @Utils.rootonly
    def test_module_load_custom(self):
        """Load a custom module is ok"""
        act = self.srv.load_modules(modname='ldiskfs')
        result = self.check_base(self.srv, 'server', act, ACT_OK,
                                 ['start', 'done'],
                                 "load module 'ldiskfs'")
        self.assertEqual(self.srv.modules.keys(), ['ldiskfs'])

    @Utils.rootonly
    def test_module_load_error(self):
        """Load a bad module is an error"""
        act = self.srv.load_modules(modname='ERROR')
        result = self.check_base(self.srv, 'server', act, ACT_ERROR,
                                 ['start', 'failed'],
                                 "load module 'ERROR'")
        self.assertEqual(result.retcode, 1)
        self.assertEqual(self.srv.modules, {})

    @Utils.rootonly
    def test_module_load_already_done(self):
        """Load modules when already loaded is ok"""
        def lustre_check(self):
            self.modules = {'lustre': 0, 'libcfs': 1}
        self.srv.lustre_check = types.MethodType(lustre_check, self.srv)
        act = self.srv.load_modules()
        result = self.check_base(self.srv, 'server', act, ACT_OK,
                                 ['start', 'done'],
                                 "load module 'lustre'")
        self.assertEqual(str(result), "'lustre' is already loaded")
        self.assertEqual(result.retcode, None)
        self.assertEqual(sorted(self.srv.modules.keys()), ['libcfs', 'lustre'])

    @Utils.rootonly
    def test_module_unload(self):
        """Unload modules"""
        # First load modules
        self.srv.load_modules().launch()
        self.fs._run_actions()
        self.eh.clear()

        act = self.srv.unload_modules()
        result = self.check_base(self.srv, 'server', act, ACT_OK,
                                 ['start', 'done'],
                                 'unload modules')
        self.assertEqual(result.retcode, 0)
        self.assertEqual(self.srv.modules, {})

    @Utils.rootonly
    def test_module_unload_already_done(self):
        """Unload modules when already done is ok"""
        # By default modules are not loaded
        act = self.srv.unload_modules()
        result = self.check_base(self.srv, 'server', act, ACT_OK,
                                 ['start', 'done'],
                                 'unload modules')
        self.assertEqual(str(result), 'modules already unloaded')
        self.assertEqual(result.retcode, None)
        self.assertEqual(self.srv.modules, {})
Exemplo n.º 3
0
class RouterActionTest(CommonTestCase):
    def net_up(self, options):
        self.srv1.load_modules(modname='lnet', options=options).launch()
        self.fs._run_actions()
        self.eh.clear()

    def setUp(self):
        CommonTestCase.setUp(self)
        self.srv1 = Server(Utils.HOSTNAME, ["%s@tcp" % Utils.HOSTNAME])
        self.router = self.fs.new_router(self.srv1)
        self.srv1.unload_modules().launch()
        self.fs._run_actions()

    def tearDown(self):
        self.router.lustre_check()
        if self.router.is_started():
            self.router.stop().launch()
            self.fs._run_actions()
        self.srv1.unload_modules().launch()
        self.fs._run_actions()

    #
    # Start Router
    #
    @Utils.rootonly
    def test_start_router_ok(self):
        """Start a stopped router is ok"""
        self.net_up('forwarding=enabled')
        act = self.router.start()
        result = self.check_base(self.router, 'comp', act, ACT_OK,
                                 ['start', 'done'],
                                 'start of router on %s' % self.router.server)
        self.assertEqual(result.retcode, 0)
        self.assertEqual(self.router.state, MOUNTED)

    @Utils.rootonly
    def test_start_router_dryrun(self):
        """Start a router in dry-run mode"""
        self.net_up('forwarding=enabled')
        act = self.router.start(dryrun=True)
        text = '/sbin/modprobe ptlrpc'
        self.check_dryrun(act, text, 'comp', 'start', ['start', 'done'],
                          self.router,
                          'start of router on %s' % self.router.server)
        self.assertEqual(self.router.state, OFFLINE)

    @Utils.rootonly
    def test_start_router_already_done(self):
        """Start an already started router is ok"""
        self.net_up('forwarding=enabled')
        # Start the router
        self.router.start().launch()
        self.fs._run_actions()
        self.eh.clear()

        # Then try to restart it
        act = self.router.start()
        result = self.check_base(self.router, 'comp', act, ACT_OK,
                                 ['start', 'done'],
                                 'start of router on %s' % self.router.server)
        self.assertEqual(str(result), "router is already enabled")
        self.assertEqual(result.retcode, None)
        self.assertEqual(self.router.state, MOUNTED)

    #
    # Stop Router
    #
    @Utils.rootonly
    def test_stop_router_ok(self):
        """Stop a started router is ok"""
        self.net_up('forwarding=enabled')
        # Start the router
        self.router.start().launch()
        self.fs._run_actions()
        self.eh.clear()

        # Then stop it
        act = self.router.stop()
        result = self.check_base(self.router, 'comp', act, ACT_OK,
                                 ['start', 'done'],
                                 'stop of router on %s' % self.router.server)
        self.assertEqual(result.retcode, 0)
        self.assertEqual(self.router.state, OFFLINE)

    @Utils.rootonly
    def test_stop_router_dryrun(self):
        """Stop a router in dryrun mode"""
        self.net_up('forwarding=enabled')
        # Start the router
        self.router.start().launch()
        self.fs._run_actions()
        self.eh.clear()

        # Then stop it
        act = self.router.stop(dryrun=True)
        text = 'lustre_rmmod'
        self.check_dryrun(act, text, 'comp', 'stop', ['start', 'done'],
                          self.router,
                          'stop of router on %s' % self.router.server)
        self.assertEqual(self.router.state, MOUNTED)

    @Utils.rootonly
    def test_stop_router_already_done(self):
        """Stop an already stopped router fails"""
        self.net_up('forwarding=enabled')
        act = self.router.stop()
        result = self.check_base(self.router, 'comp', act, ACT_OK,
                                 ['start', 'done'],
                                 'stop of router on %s' % self.router.server)
        self.assertEqual(str(result), "router is already disabled")
        self.assertEqual(result.retcode, None)
        self.assertEqual(self.router.state, OFFLINE)
Exemplo n.º 4
0
class RouterActionTest(CommonTestCase):

    def net_up(self, options):
        self.srv1.load_modules(modname='lnet', options=options).launch()
        self.fs._run_actions()
        self.eh.clear()

    def setUp(self):
        CommonTestCase.setUp(self)
        self.srv1 = Server(Utils.HOSTNAME, ["%s@tcp" % Utils.HOSTNAME])
        self.router = self.fs.new_router(self.srv1)
        self.srv1.unload_modules().launch()
        self.fs._run_actions()

    def tearDown(self):
        self.router.lustre_check()
        if self.router.is_started():
            self.router.stop().launch()
            self.fs._run_actions()
        self.srv1.unload_modules().launch()
        self.fs._run_actions()

    #
    # Start Router
    #
    @Utils.rootonly
    def test_start_router_ok(self):
        """Start a stopped router is ok"""
        self.net_up('forwarding=enabled')
        act = self.router.start()
        result = self.check_base(self.router, 'comp', act, ACT_OK,
                                 ['start', 'done'],
                                 'start of router on %s' % self.router.server)
        self.assertEqual(result.retcode, 0)
        self.assertEqual(self.router.state, MOUNTED)

    @Utils.rootonly
    def test_start_router_dryrun(self):
        """Start a router in dry-run mode"""
        self.net_up('forwarding=enabled')
        act = self.router.start(dryrun=True)
        text = '/sbin/modprobe ptlrpc'
        self.check_dryrun(act, text, 'comp', 'start', ['start', 'done'],
                          self.router,
                          'start of router on %s' % self.router.server)
        self.assertEqual(self.router.state, OFFLINE)

    @Utils.rootonly
    def test_start_router_already_done(self):
        """Start an already started router is ok"""
        self.net_up('forwarding=enabled')
        # Start the router
        self.router.start().launch()
        self.fs._run_actions()
        self.eh.clear()

        # Then try to restart it
        act = self.router.start()
        result = self.check_base(self.router, 'comp', act, ACT_OK,
                                 ['start', 'done'],
                                 'start of router on %s' % self.router.server)
        self.assertEqual(str(result), "router is already enabled")
        self.assertEqual(result.retcode, None)
        self.assertEqual(self.router.state, MOUNTED)

    #
    # Stop Router
    #
    @Utils.rootonly
    def test_stop_router_ok(self):
        """Stop a started router is ok"""
        self.net_up('forwarding=enabled')
        # Start the router
        self.router.start().launch()
        self.fs._run_actions()
        self.eh.clear()

        # Then stop it
        act = self.router.stop()
        result = self.check_base(self.router, 'comp', act, ACT_OK,
                                 ['start', 'done'],
                                 'stop of router on %s' % self.router.server)
        self.assertEqual(result.retcode, 0)
        self.assertEqual(self.router.state, OFFLINE)

    @Utils.rootonly
    def test_stop_router_dryrun(self):
        """Stop a router in dryrun mode"""
        self.net_up('forwarding=enabled')
        # Start the router
        self.router.start().launch()
        self.fs._run_actions()
        self.eh.clear()

        # Then stop it
        act = self.router.stop(dryrun=True)
        text = 'lustre_rmmod'
        self.check_dryrun(act, text, 'comp', 'stop', ['start', 'done'],
                          self.router, 'stop of router on %s' %
                          self.router.server)
        self.assertEqual(self.router.state, MOUNTED)

    @Utils.rootonly
    def test_stop_router_already_done(self):
        """Stop an already stopped router fails"""
        self.net_up('forwarding=enabled')
        act = self.router.stop()
        result = self.check_base(self.router, 'comp', act, ACT_OK,
                                 ['start', 'done'],
                                 'stop of router on %s' % self.router.server)
        self.assertEqual(str(result), "router is already disabled")
        self.assertEqual(result.retcode, None)
        self.assertEqual(self.router.state, OFFLINE)