Ejemplo n.º 1
0
 def test_register_action_duplicate(self):
     with utils.temporary_directory() as path:
         om = output_manager.OutputManager(path)
         om.dispatch_table['action'] = {
             'short_path': 'shortpath',
             'method': 'method'
         }
         self.assertRaises(NameError, om.register_action, 'shortpath',
                           'plugin', 'action', 'method')
Ejemplo n.º 2
0
 def test_handle_modules_actions(self):
     with utils.temporary_directory() as path:
         om = output_manager.OutputManager(path)
         out = om.handle_modules({'action': 'modules.actions'})
         self.assertEqual(out['result_code'], 0)
         self.assertEqual(out['result_str'], 'success')
         self.assertTrue('name' in out['result_data'])
         self.assertEqual(out['result_data']['name'],
                          'opencenter_agent_actions')
         self.assertTrue('value' in out['result_data'])
Ejemplo n.º 3
0
 def test_handle_logfile_no_such_logfile(self):
     with utils.temporary_directory() as path:
         with utils.temporary_directory() as logdir:
             om = output_manager.OutputManager(path)
             om.config = {'main': {'trans_log_dir': logdir}}
             out = om.handle_logfile({
                 'action': 'modules.load',
                 'payload': {
                     'task_id': '42',
                     'dest_ip': '127.0.0.1',
                     'dest_port': 4242,
                     'offset': 1024
                 }
             })
             self.assertEqual(out['result_code'], 1)
             self.assertEqual(out['result_str'],
                              'no such transaction log file')
Ejemplo n.º 4
0
    def test_handle_logfile_remote_connection_failed(self):
        with utils.temporary_directory() as path:
            with utils.temporary_directory() as logdir:
                om = output_manager.OutputManager(path)
                om.config = {'main': {'trans_log_dir': logdir}}

                with open(os.path.join(logdir, 'trans_42.log'), 'w') as f:
                    f.write('This\nis\na\nlog\nfile')

                out = om.handle_logfile({
                    'action': 'logfile.tail',
                    'payload': {
                        'task_id': '42',
                        'dest_ip': '127.0.0.1',
                        'dest_port': 4242,
                        'offset': 1024
                    }
                })
                self.assertEqual(out['result_code'], 1)
Ejemplo n.º 5
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)
Ejemplo n.º 6
0
    def test_handle_logfile_tail_socket_fail(self):
        self.useFixture(
            fixtures.MonkeyPatch('socket.socket', FakeSocketSendFails))

        with utils.temporary_directory() as path:
            with utils.temporary_directory() as logdir:
                om = output_manager.OutputManager(path)
                om.config = {'main': {'trans_log_dir': logdir}}

                with open(os.path.join(logdir, 'trans_42.log'), 'w') as f:
                    f.write('This\nis\na\nlog\nfile')

                out = om.handle_logfile({
                    'action': 'logfile.tail',
                    'payload': {
                        'task_id': '42',
                        'dest_ip': '127.0.0.1',
                        'dest_port': 4242,
                        'offset': 1024
                    }
                })
                self.assertEqual(out['result_code'], 1)
                self.assertEqual(out['result_str'], 'remote socket disconnect')
Ejemplo n.º 7
0
    def test_handle_logfile_tail(self):
        sock = FakeSocket(socket.AF_INET, socket.SOCK_STREAM)
        with utils.temporary_directory() as path:
            with utils.temporary_directory() as logdir:
                om = output_manager.OutputManager(path)
                om.config = {'main': {'trans_log_dir': logdir}}

                with open(os.path.join(logdir, 'trans_42.log'), 'w') as f:
                    f.write('This\nis\na\nlog\nfile')

                out = om.handle_logfile(
                    {
                        'action': 'logfile.tail',
                        'payload': {
                            'task_id': '42',
                            'dest_ip': '127.0.0.1',
                            'dest_port': 4242,
                            'offset': 1024
                        }
                    },
                    sock=sock)
                self.assertEqual(out['result_code'], 0)
                self.assertNotEqual(sock.sent, [])
Ejemplo n.º 8
0
    def test_handle_logfile_watch(self):
        sock = FakeSocket(socket.AF_INET, socket.SOCK_STREAM)
        self.useFixture(fixtures.MonkeyPatch('time.sleep', self.fake_sleep))

        with utils.temporary_directory() as path:
            with utils.temporary_directory() as logdir:
                om = output_manager.OutputManager(path)
                om.config = {'main': {'trans_log_dir': logdir}}

                with open(os.path.join(logdir, 'trans_42.log'), 'w') as f:
                    f.write('This\nis\na\nlog\nfile')

                    self.sleep_count = 0
                    self.sleep_writes_to = f

                    out = om.handle_logfile(
                        {
                            'action': 'logfile.watch',
                            'payload': {
                                'task_id': '42',
                                'dest_ip': '127.0.0.1',
                                'dest_port': 4242,
                                'timeout': 10
                            }
                        },
                        sock=sock)
                    self.assertEqual(out['result_code'], 0)

                    # NOTE(mikal): this one is a little complicated. The
                    # timeout is from the last bit of seen data... So, because
                    # we return data for the first ten sleeps, we expect to
                    # sleep 20 times before we timeout.
                    self.assertEqual(self.sleep_count, 20)

                    self.assertNotEqual(sock.sent, [])
                    self.assertEqual(len(sock.sent), 10)
Ejemplo n.º 9
0
 def test_actions(self):
     with utils.temporary_directory() as path:
         om = output_manager.OutputManager(path)
         self.assertTrue(len(om.actions()) > 0)
Ejemplo n.º 10
0
 def test_init(self):
     with utils.temporary_directory() as path:
         om = output_manager.OutputManager(path)
         self.assertTrue(len(om.dispatch_table) > 0)
Ejemplo n.º 11
0
 def test_handle_logfile_no_payload(self):
     with utils.temporary_directory() as path:
         om = output_manager.OutputManager(path)
         out = om.handle_logfile({'action': 'modules.load', 'payload': {}})
         self.assertEqual(out['result_code'], 1)
Ejemplo n.º 12
0
 def test_handle_modules_reload(self):
     with utils.temporary_directory() as path:
         om = output_manager.OutputManager(path)
         out = om.handle_modules({'action': 'modules.reload'})
         self.assertEqual(out['result_code'], 0)
         self.assertEqual(out['result_str'], 'success')