예제 #1
0
 def test_read_config_missing(self):
     agent = OpenCenterAgentNoInitialization([])
     agent.config_section = 'taskerator'
     with utils.temporary_file() as config_file:
         os.remove(config_file)
         self.assertRaises(exceptions.FileNotFound, agent._read_config,
                           config_file)
예제 #2
0
 def test_read_config_missing(self):
     agent = OpenCenterAgentNoInitialization([])
     agent.config_section = 'taskerator'
     with utils.temporary_file() as config_file:
         os.remove(config_file)
         self.assertRaises(exceptions.FileNotFound, agent._read_config,
                           config_file)
    def test_handle_modules_load(self):
        with utils.temporary_directory() as path:
            om = output_manager.OutputManager(path)
            om.loadfile = self.fake_loadfile

            out = om.handle_modules({'action': 'modules.load'})
            self.assertEqual(out['result_code'], 1)
            self.assertEqual(out['result_str'],
                             'no payload specified')

            out = om.handle_modules({'action': 'modules.load',
                                     'payload': {'gerbil': True}})
            self.assertEqual(out['result_code'], 1)
            self.assertEqual(out['result_str'],
                             'no "path" specified in payload')

            out = om.handle_modules({'action': 'modules.load',
                                     'payload': {'path': '/tmp/no/such'}})
            self.assertEqual(out['result_code'], 1)
            self.assertEqual(out['result_str'],
                             'specified module does not exist')

            self.loadfile_calls = 0
            with utils.temporary_file() as path:
                out = om.handle_modules({'action': 'modules.load',
                                         'payload': {'path': path}})
                self.assertEqual(out['result_code'], 0)
                self.assertEqual(self.loadfile_calls, 1)
예제 #4
0
    def test_handle_pidfile_new(self):
        self.useFixture(fixtures.MonkeyPatch('sys.exit', self.fake_exit))

        with utils.temporary_file() as pid_file:
            agent = OpenCenterAgentNoInitialization([])
            agent.config_section = 'testing'
            agent.config = {'testing': {'pidfile': pid_file}}
            agent._handle_pidfile()

            with open(pid_file, 'r') as pidfile:
                pid_from_pidfile = int(pidfile.read())
            self.assertEqual(os.getpid(), pid_from_pidfile)
예제 #5
0
    def test_handle_pidfile_exists(self):
        self.useFixture(fixtures.MonkeyPatch('sys.exit', self.fake_exit))

        with utils.temporary_file() as pid_file:
            with open(pid_file, 'a+') as pidfile:
                fcntl.flock(pidfile.fileno(), fcntl.LOCK_EX | fcntl.LOCK_NB)

                agent = OpenCenterAgentNoInitialization([])
                agent.config_section = 'testing'
                agent.config = {'testing': {'pidfile': pid_file}}

                self.assertRaises(ExitCalledException, agent._handle_pidfile)
예제 #6
0
    def test_handle_pidfile_new(self):
        self.useFixture(fixtures.MonkeyPatch('sys.exit', self.fake_exit))

        with utils.temporary_file() as pid_file:
            agent = OpenCenterAgentNoInitialization([])
            agent.config_section = 'testing'
            agent.config = {'testing': {'pidfile': pid_file}}
            agent._handle_pidfile()

            with open(pid_file, 'r') as pidfile:
                pid_from_pidfile = int(pidfile.read())
            self.assertEqual(os.getpid(), pid_from_pidfile)
예제 #7
0
    def test_handle_pidfile_exists(self):
        self.useFixture(fixtures.MonkeyPatch('sys.exit', self.fake_exit))

        with utils.temporary_file() as pid_file:
            with open(pid_file, 'a+') as pidfile:
                fcntl.flock(pidfile.fileno(), fcntl.LOCK_EX | fcntl.LOCK_NB)

                agent = OpenCenterAgentNoInitialization([])
                agent.config_section = 'testing'
                agent.config = {'testing': {'pidfile': pid_file}}

                self.assertRaises(ExitCalledException, agent._handle_pidfile)
예제 #8
0
    def test_read_config_simple_with_default(self):
        agent = OpenCenterAgentNoInitialization([])
        with utils.temporary_file() as config_file:
            with open(config_file, 'w') as f:
                f.write("""[taskerator]
endpoint = http://127.0.0.1:8080/admin
banana = False""")

            agent.config_section = 'taskerator'
            config = agent._read_config(
                config_file, defaults={'taskerator': {'banana': True}})
            self.assertTrue(config['taskerator']['banana'])
            self.assertEqual(config['taskerator']['endpoint'],
                             'http://127.0.0.1:8080/admin')
예제 #9
0
    def test_read_config_simple_with_default(self):
        agent = OpenCenterAgentNoInitialization([])
        with utils.temporary_file() as config_file:
            with open(config_file, 'w') as f:
                f.write("""[taskerator]
endpoint = http://127.0.0.1:8080/admin
banana = False""")

            agent.config_section = 'taskerator'
            config = agent._read_config(
                config_file, defaults={'taskerator': {
                    'banana': True
                }})
            self.assertTrue(config['taskerator']['banana'])
            self.assertEqual(config['taskerator']['endpoint'],
                             'http://127.0.0.1:8080/admin')
    def test_handle_modules_load(self):
        with utils.temporary_directory() as path:
            om = output_manager.OutputManager(path)
            om.loadfile = self.fake_loadfile

            out = om.handle_modules({"action": "modules.load"})
            self.assertEqual(out["result_code"], 1)
            self.assertEqual(out["result_str"], "no payload specified")

            out = om.handle_modules({"action": "modules.load", "payload": {"gerbil": True}})
            self.assertEqual(out["result_code"], 1)
            self.assertEqual(out["result_str"], 'no "path" specified in payload')

            out = om.handle_modules({"action": "modules.load", "payload": {"path": "/tmp/no/such"}})
            self.assertEqual(out["result_code"], 1)
            self.assertEqual(out["result_str"], "specified module does not exist")

            self.loadfile_calls = 0
            with utils.temporary_file() as path:
                out = om.handle_modules({"action": "modules.load", "payload": {"path": path}})
                self.assertEqual(out["result_code"], 0)
                self.assertEqual(self.loadfile_calls, 1)
예제 #11
0
    def test_handle_modules_load(self):
        with utils.temporary_directory() as path:
            om = output_manager.OutputManager(path)
            om.loadfile = self.fake_loadfile

            out = om.handle_modules({'action': 'modules.load'})
            self.assertEqual(out['result_code'], 1)
            self.assertEqual(out['result_str'], 'no payload specified')

            out = om.handle_modules({
                'action': 'modules.load',
                'payload': {
                    'gerbil': True
                }
            })
            self.assertEqual(out['result_code'], 1)
            self.assertEqual(out['result_str'],
                             'no "path" specified in payload')

            out = om.handle_modules({
                'action': 'modules.load',
                'payload': {
                    'path': '/tmp/no/such'
                }
            })
            self.assertEqual(out['result_code'], 1)
            self.assertEqual(out['result_str'],
                             'specified module does not exist')

            self.loadfile_calls = 0
            with utils.temporary_file() as path:
                out = om.handle_modules({
                    'action': 'modules.load',
                    'payload': {
                        'path': path
                    }
                })
                self.assertEqual(out['result_code'], 0)
                self.assertEqual(self.loadfile_calls, 1)
예제 #12
0
 def test_read_config_empty(self):
     agent = OpenCenterAgentNoInitialization([])
     agent.config_section = 'taskerator'
     with utils.temporary_file() as config_file:
         self.assertRaises(exceptions.NoConfigFound, agent._read_config,
                           config_file)
예제 #13
0
 def test_temporary_file(self):
     with utils.temporary_file() as filename:
         self.assertTrue(os.path.exists(filename))
     self.assertFalse(os.path.exists(filename))
예제 #14
0
 def test_read_config_empty(self):
     agent = OpenCenterAgentNoInitialization([])
     agent.config_section = 'taskerator'
     with utils.temporary_file() as config_file:
         self.assertRaises(exceptions.NoConfigFound, agent._read_config,
                           config_file)