当前位置: 首页>>代码示例>>Python>>正文


Python run.PsDashRunner类代码示例

本文整理汇总了Python中psdash.run.PsDashRunner的典型用法代码示例。如果您正苦于以下问题:Python PsDashRunner类的具体用法?Python PsDashRunner怎么用?Python PsDashRunner使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了PsDashRunner类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_reload_logs

 def test_reload_logs(self):
     _, filename = tempfile.mkstemp()
     r = PsDashRunner(args=['-l', filename])
     pre_count = len(r.get_local_node().logs.available)
     r.get_local_node().logs.add_patterns(r.app.config['PSDASH_LOGS'])
     post_count = len(r.get_local_node().logs.available)
     self.assertEqual(pre_count, post_count)
开发者ID:ArcherSys,项目名称:psdash,代码行数:7,代码来源:test_run.py

示例2: test_register_node_creates_proper_node_dict

 def test_register_node_creates_proper_node_dict(self):
     r = PsDashRunner()
     now = int(time.time())
     node = r.register_node('examplehost', 'example.org', 5000)
     self.assertEqual(node.host, 'example.org')
     self.assertEqual(node.port, 5000)
     self.assertEqual(node.last_registered, now)
开发者ID:ArcherSys,项目名称:psdash,代码行数:7,代码来源:test_run.py

示例3: test_register_agent_to_auth_protected_host

    def test_register_agent_to_auth_protected_host(self):
        r = PsDashRunner({
            'PSDASH_AUTH_USERNAME': 'user',
            'PSDASH_AUTH_PASSWORD': 'pass'
        })
        agent = PsDashRunner({
            'PSDASH_AGENT': True,
            'PSDASH_PORT': 5001,
            'PSDASH_REGISTER_TO': 'http://localhost:5000',
            'PSDASH_AUTH_USERNAME': 'user',
            'PSDASH_AUTH_PASSWORD': 'pass'
        })
        jobs = []
        jobs.append(gevent.spawn(r.run))
        gevent.sleep(0.3)
        jobs.append(gevent.spawn(agent.run))
        gevent.sleep(0.3)

        self.assertIn('127.0.0.1:5001', r.get_nodes())
        self.assertEquals(r.get_node('127.0.0.1:5001').name, socket.gethostname())
        self.assertEquals(r.get_node('127.0.0.1:5001').port, 5001)

        r.server.close()
        agent.server.close()
        gevent.killall(jobs)
开发者ID:ArcherSys,项目名称:psdash,代码行数:25,代码来源:test_run.py

示例4: test_update_net_io_counters

    def test_update_net_io_counters(self):
        r = PsDashRunner()
        socket.getaddrinfo('example.org', 80)
        counters = r.update_net_io_counters()

        for c in counters.itervalues():
            if c['rx_per_sec'] > 0 and c['tx_per_sec'] > 0:
                break
        else:
            self.fail("Didn't find any changed network interface")
开发者ID:backchenlin,项目名称:psdash,代码行数:10,代码来源:test_run.py

示例5: test_nodes_from_config

 def test_nodes_from_config(self):
     config = {
         'PSDASH_NODES': [
             {
                 'name': 'test-node',
                 'host': 'remotehost.org',
                 'port': 5000
             }
         ]
     }
     r = PsDashRunner(config)
     self.assertEqual(len(r.get_nodes()), 2)
     self.assertIn('remotehost.org:5000', r.get_nodes())
     self.assertEqual(r.get_nodes()['remotehost.org:5000'].name, 'test-node')
     self.assertEqual(r.get_nodes()['remotehost.org:5000'].host, 'remotehost.org')
     self.assertEqual(r.get_nodes()['remotehost.org:5000'].port, 5000)
开发者ID:ArcherSys,项目名称:psdash,代码行数:16,代码来源:test_run.py

示例6: test_reload_logs

 def test_reload_logs(self):
     _, filename = tempfile.mkstemp()
     r = PsDashRunner.create_from_args(['-l', filename])
     pre_count = len(r.app.psdash.logs.available)
     c = r.reload_logs()
     post_count = len(r.app.psdash.logs.available)
     self.assertEqual(pre_count, post_count)
开发者ID:backchenlin,项目名称:psdash,代码行数:7,代码来源:test_run.py

示例7: test_register_agent_without_name_defaults_to_hostname

    def test_register_agent_without_name_defaults_to_hostname(self):
        agent_options = {
            'PSDASH_AGENT': True,
            'PSDASH_PORT': 5001,
            'PSDASH_REGISTER_TO': 'http://localhost:5000'
        }
        r = PsDashRunner()
        agent = PsDashRunner(agent_options)
        jobs = []
        jobs.append(gevent.spawn(r.run))
        gevent.sleep(0.3)
        jobs.append(gevent.spawn(agent.run))
        gevent.sleep(0.3)

        self.assertIn('127.0.0.1:5001', r.get_nodes())
        self.assertEquals(r.get_node('127.0.0.1:5001').name, socket.gethostname())
        self.assertEquals(r.get_node('127.0.0.1:5001').port, 5001)

        r.server.close()
        agent.server.close()
        gevent.killall(jobs)
开发者ID:ArcherSys,项目名称:psdash,代码行数:21,代码来源:test_run.py

示例8: test_register_agent

    def test_register_agent(self):
        agent_options = {
            'PSDASH_AGENT': True,
            'PSDASH_PORT': 5001,
            'PSDASH_REGISTER_TO': 'localhost:5000',
            'PSDASH_REGISTER_AS': 'the_agent'
        }
        r = PsDashRunner()
        agent = PsDashRunner(agent_options)
        jobs = []
        jobs.append(gevent.spawn(r.run))
        gevent.sleep(0.2)
        jobs.append(gevent.spawn(agent.run))
        gevent.sleep(0.2)

        self.assertIn('127.0.0.1:5001', r.get_nodes())
        self.assertEquals(r.get_node('127.0.0.1:5001').name, 'the_agent')
        self.assertEquals(r.get_node('127.0.0.1:5001').port, 5001)

        r.server.close()
        agent.server.close()
        gevent.killall(jobs)
开发者ID:achun2080,项目名称:psdash,代码行数:22,代码来源:test_run.py

示例9: TestBasicAuth

class TestBasicAuth(unittest2.TestCase):
    default_username = 'tester'
    default_password = 'secret'

    def setUp(self):
        self.app = PsDashRunner().app
        self.client = self.app.test_client()

    def _enable_basic_auth(self, username, password):
        self.app.config['PSDASH_AUTH_USERNAME'] = username
        self.app.config['PSDASH_AUTH_PASSWORD'] = password

    def _create_auth_headers(self, username, password):
        data = base64.b64encode(':'.join([username, password]))
        headers = [('Authorization', 'Basic %s' % data)]
        return headers

    def test_missing_credentials(self):
        self._enable_basic_auth(self.default_username, self.default_password)
        resp = self.client.get('/')
        self.assertEqual(resp.status_code, httplib.UNAUTHORIZED)

    def test_correct_credentials(self):
        self._enable_basic_auth(self.default_username, self.default_password)
        
        headers = self._create_auth_headers(self.default_username, self.default_password)
        resp = self.client.get('/', headers=headers)
        
        self.assertEqual(resp.status_code, httplib.OK)

    def test_incorrect_credentials(self):
        self._enable_basic_auth(self.default_username, self.default_password)

        headers = self._create_auth_headers(self.default_username, 'wrongpass')
        resp = self.client.get('/', headers=headers)

        self.assertEqual(resp.status_code, httplib.UNAUTHORIZED)
开发者ID:n3storm,项目名称:psdash,代码行数:37,代码来源:test_web.py

示例10: setUp

 def setUp(self):
     self.app = PsDashRunner().app
     self.client = self.app.test_client()
开发者ID:n3storm,项目名称:psdash,代码行数:3,代码来源:test_web.py

示例11: test_args_debug

 def test_args_debug(self):
     r = PsDashRunner.create_from_args(['-d'])
     self.assertTrue(r.app.debug)
开发者ID:backchenlin,项目名称:psdash,代码行数:3,代码来源:test_run.py

示例12: test_args_bind

 def test_args_bind(self):
     r = PsDashRunner.create_from_args(['-b', '10.0.0.1'])
     self.assertEqual(r.app.config['PSDASH_BIND_HOST'], '10.0.0.1')
开发者ID:backchenlin,项目名称:psdash,代码行数:3,代码来源:test_run.py

示例13: test_get_all_nodes

 def test_get_all_nodes(self):
     r = PsDashRunner()
     r.register_node('examplehost', 'example.org', 5000)
     self.assertEqual(len(r.get_nodes()), 2) # local + registered
开发者ID:ArcherSys,项目名称:psdash,代码行数:4,代码来源:test_run.py

示例14: test_local_node_is_added

 def test_local_node_is_added(self):
     r = PsDashRunner()
     self.assertIsInstance(r.get_local_node(), LocalNode)
开发者ID:ArcherSys,项目名称:psdash,代码行数:3,代码来源:test_run.py

示例15: TestLogs

class TestLogs(unittest2.TestCase):
    def _create_log_file(self):
        fd, filename = tempfile.mkstemp()
        fp = os.fdopen(fd, 'w')
        fp.write('woha\n' * 100)
        fp.write('something\n')
        fp.write('woha\n' * 100)
        fp.flush()
        return filename

    def setUp(self):
        self.app = PsDashRunner().app
        self.client = self.app.test_client()
        self.filename = self._create_log_file()
        self.app.psdash.logs.add_available(self.filename)

    def test_logs(self):
        resp = self.client.get('/logs')
        self.assertEqual(resp.status_code, httplib.OK)

    def test_logs_removed_file(self):
        filename = self._create_log_file()
        self.app.psdash.logs.add_available(filename)

        # first visit to make sure the logs are properly initialized
        resp = self.client.get('/logs')
        self.assertEqual(resp.status_code, httplib.OK)

        os.unlink(filename)

        resp = self.client.get('/logs')
        self.assertEqual(resp.status_code, httplib.OK)

    def test_logs_removed_file_uninitialized(self):
        filename = self._create_log_file()
        self.app.psdash.logs.add_available(filename)

        os.unlink(filename)

        resp = self.client.get('/logs')
        self.assertEqual(resp.status_code, httplib.OK)

    def test_view(self):
        resp = self.client.get('/log?filename=%s' % self.filename)
        self.assertEqual(resp.status_code, httplib.OK)

    def test_search(self):
        resp = self.client.get('/log/search?filename=%s&text=%s' % (self.filename, 'something'),
                               environ_overrides={'HTTP_X_REQUESTED_WITH': 'xmlhttprequest'})

        self.assertEqual(resp.status_code, httplib.OK)
        try:
            data = json.loads(resp.data)
            self.assertIn('something', data['content'])
        except ValueError:
            self.fail('Log search did not return valid json data')

    def test_read(self):
        resp = self.client.get('/log?filename=%s' % self.filename,
                               environ_overrides={'HTTP_X_REQUESTED_WITH': 'xmlhttprequest'})
        self.assertEqual(resp.status_code, httplib.OK)

    def test_read_tail(self):
        resp = self.client.get('/log?filename=%s&seek_tail=1' % self.filename)
        self.assertEqual(resp.status_code, httplib.OK)

    def test_non_existing_file(self):
        filename = "/var/log/surelynotaroundright.log"

        resp = self.client.get('/log?filename=%s' % filename)
        self.assertEqual(resp.status_code, httplib.NOT_FOUND)

        resp = self.client.get('/log/search?filename=%s&text=%s' % (filename, 'something'))
        self.assertEqual(resp.status_code, httplib.NOT_FOUND)

        resp = self.client.get('/log/read?filename=%s' % filename)
        self.assertEqual(resp.status_code, httplib.NOT_FOUND)

        resp = self.client.get('/log/read_tail?filename=%s' % filename)
        self.assertEqual(resp.status_code, httplib.NOT_FOUND)
开发者ID:n3storm,项目名称:psdash,代码行数:80,代码来源:test_web.py


注:本文中的psdash.run.PsDashRunner类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。