def test_run_module(self): worker = server_plugins.PluginWorker(**self.conf_worker) module = 'tests.server.smoker_test_resources.smokermodule' result = worker.run_module(module).result assert 'status' in result and result['status'] == 'OK' assert 'info' in result['messages'] assert result['messages']['info'] == [' '.join(os.uname())]
def test_run_invalid_module(self): worker = server_plugins.PluginWorker(**self.conf_worker) module = 'InvalidModule' with pytest.raises(ImportError) as exc_info: worker.run_module(module) assert 'No module named ' in repr(exc_info.value) assert 'InvalidModule' in repr(exc_info.value)
def test_run_parser(self): expected = { 'Unit tests': { 'status': 'OK', 'messages': { 'info': ['GoodData'], 'warn': [], 'error': [] } } } test_params = { 'Command': 'echo "Output : GoodData Smoker"', 'Parser': 'tests.server.smoker_test_resources.smokerparser' } params = dict(self.params_default, **test_params) worker = server_plugins.PluginWorker(name='Hostname', queue=self.queue, params=params) result = worker.run_parser(stdout='GoodData', stderr='').result assert 'status' in result and result['status'] == 'OK' assert result['componentResults'] == expected assert 'messages' in result and not result['messages'] assert (result['componentResults']['Unit tests']['status'] == result['status'])
def test_drop_privileged_with_invalid_params(self): test_params = {'uid': 99999, 'gid': 99999} params = dict(self.params_default, **test_params) worker = server_plugins.PluginWorker(name='Hostname', queue=self.queue, params=params) with pytest.raises(OSError) as exc_info: worker.run() assert 'Operation not permitted' in repr(exc_info.value)
def test_drop_privileged_with_invalid_params_type(self): test_params = { 'uid': 'InvalidType', 'gid': 'InvalidType', } params = dict(self.params_default, **test_params) worker = server_plugins.PluginWorker(name='Hostname', queue=self.queue, params=params) with pytest.raises(TypeError): worker.run()
def test_run_invalid_command(self): expected = 'InvalidCommand|command not found' test_params = {'Command': 'InvalidCommand'} params = dict(self.params_default, **test_params) worker = server_plugins.PluginWorker(name='InvalidCommand', queue=self.queue, params=params) worker.run() assert 'status' in worker.result and worker.result['status'] == 'ERROR' assert 'warn' in worker.result['messages'] assert re.search(expected, worker.result['messages']['error'][0])
def test_run_invalid_parser(self): test_params = { 'Command': 'echo "Output : GoodData Smoker"', 'Parser': 'InvalidParser' } params = dict(self.params_default, **test_params) worker = server_plugins.PluginWorker(name='Hostname', queue=self.queue, params=params) with pytest.raises(ImportError) as exc_info: worker.run_parser(stdout='GoodData', stderr='') assert 'No module named InvalidParser' in exc_info.value
def test_run_command_with_invalid_parser_path(self): expected_info = ['GoodData Smoker'] expected_error = ['Parser run failed: No module named InvalidParser'] test_params = { 'Command': 'echo "GoodData Smoker"', 'Parser': 'InvalidParser' } params = dict(self.params_default, **test_params) worker = server_plugins.PluginWorker(name='Hostname', queue=self.queue, params=params) worker.run() assert 'status' in worker.result and worker.result['status'] == 'ERROR' assert 'info' and 'error' in worker.result['messages'] assert worker.result['messages']['info'] == expected_info assert worker.result['messages']['error'] == expected_error
def test_escape(self): worker = server_plugins.PluginWorker(**self.conf_worker) tbe_str = 'string \ ' assert worker.escape(tbe=tbe_str) == re.escape(tbe_str) tbe_dict = {'dict': '\ "" '} expected_dict = {'dict': '\\\\\\ \\"\\"\\ '} assert worker.escape(tbe=tbe_dict) == expected_dict tbe_list = [1, '[Good]Data', '/\G'] expected_list = [1, '\\[Good\\]Data', '\\/\\\\G'] assert worker.escape(tbe=tbe_list) == expected_list tbe_tuple = (1, '[Good]Data', '/\G') with pytest.raises(Exception) as exc_info: worker.escape(tbe=tbe_tuple) assert 'Unknown data type' in repr(exc_info.value)
def test_run_command_with_parser(self): expected = { 'Unit tests': { 'status': 'OK', 'messages': { 'info': ['GoodData'], 'warn': [], 'error': [] } } } test_params = { 'Command': 'echo "GoodData Smoker"', 'Parser': 'tests.server.smoker_test_resources.smokerparser' } params = dict(self.params_default, **test_params) worker = server_plugins.PluginWorker(name='Hostname', queue=self.queue, params=params) worker.run() assert 'status' in worker.result and worker.result['status'] == 'OK' assert 'componentResults' in worker.result assert worker.result['componentResults'] == expected assert 'messages' in worker.result and not worker.result['messages']
def test_get_params(self): worker = server_plugins.PluginWorker(**self.conf_worker) assert worker.get_param('Command') == 'hostname' assert worker.get_param('Timeout') == 30 assert not worker.get_param('InvalidParamater')
def test_running_worker_process_title_should_be_changed(self): expected = 'smokerd plugin Hostname' worker = server_plugins.PluginWorker(**self.conf_worker) worker.run() procs = get_process_list() assert expected in procs.values()
def test_running_worker_process(self): worker = server_plugins.PluginWorker(**self.conf_worker) worker.run() assert 'status' in worker.result and worker.result['status'] == 'OK' assert 'info' in worker.result['messages'] assert worker.result['messages']['info'] == [os.uname()[1]]