Esempio n. 1
0
    def test_register_agent_to_auth_protected_host(self):
        r = PsDashRunner({
            'PSDASH_AUTH_USERNAME': '******',
            'PSDASH_AUTH_PASSWORD': '******'
        })
        agent = PsDashRunner({
            'PSDASH_AGENT': True,
            'PSDASH_PORT': 5001,
            'PSDASH_REGISTER_TO': 'http://localhost:5000',
            'PSDASH_AUTH_USERNAME': '******',
            'PSDASH_AUTH_PASSWORD': '******'
        })
        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)
Esempio n. 2
0
 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)
Esempio n. 3
0
 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)
Esempio n. 4
0
 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)
Esempio n. 5
0
 def test_reregister_node(self):
     r = PsDashRunner()
     now = int(time.time())
     r.register_node("examplehost", "example.org", 5000)
     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)
Esempio n. 6
0
    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")
Esempio n. 7
0
    def test_update_net_io_counters(self):
        r = PsDashRunner()
        socket.getaddrinfo('example.org', 80)
        counters = r.get_local_node().net_io_counters.update()

        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")
Esempio n. 8
0
 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)
Esempio n. 9
0
 def test_reload_logs(self):
     _, filename = tempfile.mkstemp()
     r = PsDashRunner.create_from_args(['-l', filename])
     pre_count = len(r.app.psdash.logs.available)
     r.reload_logs()
     post_count = len(r.app.psdash.logs.available)
     self.assertEqual(pre_count, post_count)
Esempio n. 10
0
 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)
Esempio n. 11
0
 def test_default_args_dont_override_config(self):
     _, filename = tempfile.mkstemp()
     with open(filename, "w") as f:
         f.write("PSDASH_LOGS = ['/var/log/boot.log', '/var/log/dmesg']\n")
         f.flush()
     os.environ['PSDASH_CONFIG'] = filename
     r = PsDashRunner()
     self.assertEquals(r.app.config['PSDASH_LOGS'],
                       ['/var/log/boot.log', '/var/log/dmesg'])
     del os.environ['PSDASH_CONFIG']
Esempio n. 12
0
    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)
Esempio n. 13
0
 def _run(self, https=False):
     options = {'PSDASH_PORT': 5051}
     if https:
         options.update({
             'PSDASH_HTTPS_KEYFILE':
             os.path.join(os.path.dirname(__file__), 'keyfile'),
             'PSDASH_HTTPS_CERTFILE':
             os.path.join(os.path.dirname(__file__), 'cacert.pem')
         })
     self.r = PsDashRunner(options)
     self.runner = gevent.spawn(self.r.run)
     gevent.sleep(0.3)
Esempio n. 14
0
 def _run(self, https=False):
     options = {"PSDASH_PORT": 5051}
     if https:
         options.update({
             "PSDASH_HTTPS_KEYFILE":
             os.path.join(os.path.dirname(__file__), "keyfile"),
             "PSDASH_HTTPS_CERTFILE":
             os.path.join(os.path.dirname(__file__), "cacert.pem"),
         })
     self.r = PsDashRunner(options)
     self.runner = gevent.spawn(self.r.run)
     gevent.sleep(0.3)
Esempio n. 15
0
    def test_register_agent_to_auth_protected_host(self):
        r = PsDashRunner({
            "PSDASH_AUTH_USERNAME": "******",
            "PSDASH_AUTH_PASSWORD": "******"
        })
        agent = PsDashRunner({
            "PSDASH_AGENT": True,
            "PSDASH_PORT": 5001,
            "PSDASH_REGISTER_TO": "http://localhost:5000",
            "PSDASH_AUTH_USERNAME": "******",
            "PSDASH_AUTH_PASSWORD": "******",
        })
        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.assertEqual(
            r.get_node("127.0.0.1:5001").name, socket.gethostname())
        self.assertEqual(r.get_node("127.0.0.1:5001").port, 5001)

        r.server.close()
        agent.server.close()
        gevent.killall(jobs)
Esempio n. 16
0
    def test_register_agent_to_auth_protected_host(self):
        r = PsDashRunner({
            'PSDASH_AUTH_USERNAME': '******',
            'PSDASH_AUTH_PASSWORD': '******'
        })
        agent = PsDashRunner({
            'PSDASH_AGENT': True,
            'PSDASH_PORT': 5001,
            'PSDASH_REGISTER_TO': 'http://localhost:5000',
            'PSDASH_AUTH_USERNAME': '******',
            'PSDASH_AUTH_PASSWORD': '******'
        })
        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)
Esempio n. 17
0
 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)
Esempio n. 18
0
    def test_register_agent(self):
        jobs = []
        agent_options = {
            "PSDASH_AGENT": True,
            "PSDASH_PORT": 5001,
            "PSDASH_REGISTER_TO": "http://localhost:5000",
            "PSDASH_REGISTER_AS": "the_agent",
        }
        r = PsDashRunner()
        agent = PsDashRunner(agent_options)
        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.assertEqual(r.get_node("127.0.0.1:5001").name, "the_agent")
        self.assertEqual(r.get_node("127.0.0.1:5001").port, 5001)

        r.server.close()
        agent.server.close()
        gevent.killall(jobs)
Esempio n. 19
0
    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)
Esempio n. 20
0
    def test_register_agent(self):
        jobs = []
        agent_options = {
            'PSDASH_AGENT': True,
            'PSDASH_PORT': 5001,
            'PSDASH_REGISTER_TO': 'http://localhost:5000',
            'PSDASH_REGISTER_AS': 'the_agent'
        }
        r = PsDashRunner()
        agent = PsDashRunner(agent_options)
        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, 'the_agent')
        self.assertEquals(r.get_node('127.0.0.1:5001').port, 5001)

        r.server.close()
        agent.server.close()
        gevent.killall(jobs)
Esempio n. 21
0
    def test_multiple_remote_addresses_using_list(self):
        r = PsDashRunner(
            {"PSDASH_ALLOWED_REMOTE_ADDRESSES": ["127.0.0.1", "10.0.0.1"]})

        resp = r.app.test_client().get(
            "/", environ_overrides={"REMOTE_ADDR": "10.0.0.1"})
        self.assertEqual(resp.status_code, http.client.OK)

        resp = r.app.test_client().get(
            "/", environ_overrides={"REMOTE_ADDR": "127.0.0.1"})
        self.assertEqual(resp.status_code, http.client.OK)

        resp = r.app.test_client().get(
            "/", environ_overrides={"REMOTE_ADDR": "10.124.0.1"})
        self.assertEqual(resp.status_code, http.client.UNAUTHORIZED)
Esempio n. 22
0
    def test_multiple_remote_addresses_using_list(self):
        r = PsDashRunner(
            {'PSDASH_ALLOWED_REMOTE_ADDRESSES': ['127.0.0.1', '10.0.0.1']})

        resp = r.app.test_client().get(
            '/', environ_overrides={'REMOTE_ADDR': '10.0.0.1'})
        self.assertEqual(resp.status_code, httplib.OK)

        resp = r.app.test_client().get(
            '/', environ_overrides={'REMOTE_ADDR': '127.0.0.1'})
        self.assertEqual(resp.status_code, httplib.OK)

        resp = r.app.test_client().get(
            '/', environ_overrides={'REMOTE_ADDR': '10.124.0.1'})
        self.assertEqual(resp.status_code, httplib.UNAUTHORIZED)
Esempio n. 23
0
 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)
Esempio n. 24
0
 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)
Esempio n. 25
0
class TestBasicAuth(unittest2.TestCase):
    default_username = "******"
    default_password = "******"

    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]).encode("UTF-8"))
        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, http.client.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, http.client.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, http.client.UNAUTHORIZED)
Esempio n. 26
0
class TestBasicAuth(unittest2.TestCase):
    default_username = '******'
    default_password = '******'

    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)
Esempio n. 27
0
class TestBasicAuth(unittest2.TestCase):
    default_username = '******'
    default_password = '******'

    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)
Esempio n. 28
0
 def setUp(self):
     self.r = PsDashRunner()
     self.app = self.r.app
     self.client = self.app.test_client()
     self.filename = self._create_log_file()
     self.r.get_local_node().logs.add_available(self.filename)
Esempio n. 29
0
 def test_missing_trailing_slash_works(self):
     r = PsDashRunner({'PSDASH_URL_PREFIX': '/subfolder'})
     resp = r.app.test_client().get('/subfolder/')
     self.assertEqual(resp.status_code, httplib.OK)
Esempio n. 30
0
 def test_get_all_nodes(self):
     r = PsDashRunner()
     r.register_node('examplehost', 'example.org', 5000)
     self.assertEqual(len(r.get_nodes()), 2) # local + registered
Esempio n. 31
0
 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')
Esempio n. 32
0
 def test_incorrect_remote_address(self):
     r = PsDashRunner({'PSDASH_ALLOWED_REMOTE_ADDRESSES': '127.0.0.1'})
     resp = r.app.test_client().get(
         '/', environ_overrides={'REMOTE_ADDR': '10.0.0.1'})
     self.assertEqual(resp.status_code, httplib.UNAUTHORIZED)
Esempio n. 33
0
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.r = PsDashRunner()
        self.app = self.r.app
        self.client = self.app.test_client()
        self.filename = self._create_log_file()
        self.r.get_local_node().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.r.get_local_node().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.r.get_local_node().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)
Esempio n. 34
0
 def setUp(self):
     self.r = PsDashRunner()
     self.app = self.r.app
     self.client = self.app.test_client()
     self.pid = os.getpid()
     self.r.get_local_node().net_io_counters.update()
Esempio n. 35
0
class TestEndpoints(unittest2.TestCase):
    def setUp(self):
        self.app = PsDashRunner().app
        self.client = self.app.test_client()
        self.pid = os.getpid()
        self.app.psdash.net_io_counters.update()

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

    @unittest2.skipIf('TRAVIS' in os.environ, 'Functionality not supported on Travis CI')
    def test_disks(self):
        resp = self.client.get('/disks')
        self.assertEqual(resp.status_code, httplib.OK)

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

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

    def test_process_overview(self):
        resp = self.client.get('/process/%d' % self.pid)
        self.assertEqual(resp.status_code, httplib.OK)

    @unittest2.skipIf(os.environ.get('USER') == 'root', 'It would fail as root as we would have access to pid 1')
    def test_process_no_access(self):
        resp = self.client.get('/process/1')  # pid 1 == init
        self.assertEqual(resp.status_code, httplib.UNAUTHORIZED)

    def test_process_non_existing_pid(self):
        resp = self.client.get('/process/0')
        self.assertEqual(resp.status_code, httplib.NOT_FOUND)

    def test_process_children(self):
        resp = self.client.get('/process/%d/children' % self.pid)
        self.assertEqual(resp.status_code, httplib.OK)

    def test_process_connections(self):
        resp = self.client.get('/process/%d/connections' % self.pid)
        self.assertEqual(resp.status_code, httplib.OK)

    def test_process_environment(self):
        resp = self.client.get('/process/%d/environment' % self.pid)
        self.assertEqual(resp.status_code, httplib.OK)

    def test_process_files(self):
        resp = self.client.get('/process/%d/files' % self.pid)
        self.assertEqual(resp.status_code, httplib.OK)

    def test_process_threads(self):
        resp = self.client.get('/process/%d/threads' % self.pid)
        self.assertEqual(resp.status_code, httplib.OK)

    def test_process_memory(self):
        resp = self.client.get('/process/%d/memory' % self.pid)
        self.assertEqual(resp.status_code, httplib.OK)

    @unittest2.skipIf('TRAVIS' in os.environ, 'Functionality not supported on Travis CI')
    def test_process_limits(self):
        resp = self.client.get('/process/%d/limits' % self.pid)
        self.assertEqual(resp.status_code, httplib.OK)

    def test_process_invalid_section(self):
        resp = self.client.get('/process/%d/whatnot' % self.pid)
        self.assertEqual(resp.status_code, httplib.NOT_FOUND)

    def test_non_existing(self):
        resp = self.client.get('/prettywronghuh')
        self.assertEqual(resp.status_code, httplib.NOT_FOUND)

    def test_connection_filters(self):
        resp = self.client.get('/network?laddr=127.0.0.1')
        self.assertEqual(resp.status_code, httplib.OK)
Esempio n. 36
0
 def test_get_all_nodes(self):
     r = PsDashRunner()
     r.register_node('examplehost', 'example.org', 5000)
     self.assertEqual(len(r.get_nodes()), 2)  # local + registered
Esempio n. 37
0
 def setUp(self):
     self.app = PsDashRunner().app
     self.client = self.app.test_client()
     self.pid = os.getpid()
     self.app.psdash.net_io_counters.update()
Esempio n. 38
0
 def test_local_node_is_added(self):
     r = PsDashRunner()
     self.assertIsInstance(r.get_local_node(), LocalNode)
Esempio n. 39
0
 def setUp(self):
     self.app = PsDashRunner().app
     self.client = self.app.test_client()
Esempio n. 40
0
 def test_args_debug(self):
     r = PsDashRunner.create_from_args(['-d'])
     self.assertTrue(r.app.debug)
Esempio n. 41
0
class TestEndpoints(unittest2.TestCase):
    def setUp(self):
        self.r = PsDashRunner()
        self.app = self.r.app
        self.client = self.app.test_client()
        self.pid = os.getpid()
        self.r.get_local_node().net_io_counters.update()

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

    @unittest2.skipIf('TRAVIS' in os.environ,
                      'Functionality not supported on Travis CI')
    def test_disks(self):
        resp = self.client.get('/disks')
        self.assertEqual(resp.status_code, httplib.OK)

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

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

    def test_process_overview(self):
        resp = self.client.get('/process/%d' % self.pid)
        self.assertEqual(resp.status_code, httplib.OK)

    @unittest2.skipIf(
        os.environ.get('USER') == 'root',
        'It would fail as root as we would have access to pid 1')
    def test_process_no_access(self):
        resp = self.client.get('/process/1')  # pid 1 == init
        self.assertEqual(resp.status_code, httplib.UNAUTHORIZED)

    def test_process_non_existing_pid(self):
        resp = self.client.get('/process/0')
        self.assertEqual(resp.status_code, httplib.NOT_FOUND)

    def test_process_children(self):
        resp = self.client.get('/process/%d/children' % self.pid)
        self.assertEqual(resp.status_code, httplib.OK)

    def test_process_connections(self):
        resp = self.client.get('/process/%d/connections' % self.pid)
        self.assertEqual(resp.status_code, httplib.OK)

    def test_process_environment(self):
        resp = self.client.get('/process/%d/environment' % self.pid)
        self.assertEqual(resp.status_code, httplib.OK)

    def test_process_files(self):
        resp = self.client.get('/process/%d/files' % self.pid)
        self.assertEqual(resp.status_code, httplib.OK)

    def test_process_threads(self):
        resp = self.client.get('/process/%d/threads' % self.pid)
        self.assertEqual(resp.status_code, httplib.OK)

    def test_process_memory(self):
        resp = self.client.get('/process/%d/memory' % self.pid)
        self.assertEqual(resp.status_code, httplib.OK)

    @unittest2.skipIf('TRAVIS' in os.environ,
                      'Functionality not supported on Travis CI')
    def test_process_limits(self):
        resp = self.client.get('/process/%d/limits' % self.pid)
        self.assertEqual(resp.status_code, httplib.OK)

    def test_process_invalid_section(self):
        resp = self.client.get('/process/%d/whatnot' % self.pid)
        self.assertEqual(resp.status_code, httplib.NOT_FOUND)

    def test_non_existing(self):
        resp = self.client.get('/prettywronghuh')
        self.assertEqual(resp.status_code, httplib.NOT_FOUND)

    def test_connection_filters(self):
        resp = self.client.get('/network?laddr=127.0.0.1')
        self.assertEqual(resp.status_code, httplib.OK)

    def test_register_node(self):
        resp = self.client.get('/register?name=examplehost&port=500')
        self.assertEqual(resp.status_code, httplib.OK)

    def test_register_node_all_params_required(self):
        resp = self.client.get('/register?name=examplehost')
        self.assertEqual(resp.status_code, httplib.BAD_REQUEST)

        resp = self.client.get('/register?port=500')
        self.assertEqual(resp.status_code, httplib.BAD_REQUEST)
Esempio n. 42
0
class TestLogs(unittest2.TestCase):
    def _create_log_file(self):
        fd, filename = tempfile.mkstemp()
        fp = os.fdopen(fd, 'w')
        fp.write('woha\n' * 10)
        fp.write('something\n')
        fp.write('woha\n' * 10)
        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'))
        self.assertEqual(resp.status_code, httplib.OK)

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

    def test_read_tail(self):
        resp = self.client.get('/log/read_tail?filename=%s' % 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)
Esempio n. 43
0
 def setUp(self):
     self.app = PsDashRunner().app
     self.client = self.app.test_client()
Esempio n. 44
0
 def test_page_not_found_on_root(self):
     r = PsDashRunner({'PSDASH_URL_PREFIX': self.default_prefix})
     resp = r.app.test_client().get('/')
     self.assertEqual(resp.status_code, httplib.NOT_FOUND)
Esempio n. 45
0
 def setUp(self):
     self.r = PsDashRunner()
     self.app = self.r.app
     self.client = self.app.test_client()
     self.filename = self._create_log_file()
     self.r.get_local_node().logs.add_available(self.filename)
Esempio n. 46
0
 def test_works_on_prefix(self):
     r = PsDashRunner({'PSDASH_URL_PREFIX': self.default_prefix})
     resp = r.app.test_client().get(self.default_prefix)
     self.assertEqual(resp.status_code, httplib.OK)
Esempio n. 47
0
 def setUp(self):
     self.r = PsDashRunner()
     self.app = self.r.app
     self.client = self.app.test_client()
     self.pid = os.getpid()
     self.r.get_local_node().net_io_counters.update()
Esempio n. 48
0
 def test_multiple_level_prefix(self):
     r = PsDashRunner({'PSDASH_URL_PREFIX': '/use/this/folder/'})
     resp = r.app.test_client().get('/use/this/folder/')
     self.assertEqual(resp.status_code, httplib.OK)
Esempio n. 49
0
 def test_args_port(self):
     r = PsDashRunner.create_from_args(['-p', '5555'])
     self.assertEqual(r.app.config['PSDASH_PORT'], 5555)
Esempio n. 50
0
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)
Esempio n. 51
0
 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)
Esempio n. 52
0
 def test_show_only_whitelisted(self):
     r = PsDashRunner({'PSDASH_ENVIRON_WHITELIST': ['USER']})
     resp = r.app.test_client().get('/process/%d/environment' % os.getpid())
     self.assertTrue(os.environ['USER'] in resp.data)
     self.assertTrue('*hidden by whitelist*' in resp.data)
Esempio n. 53
0
 def test_args_log(self):
     _, filename = tempfile.mkstemp()
     r = PsDashRunner.create_from_args(['-l', filename])
     self.assertEqual(r.app.config['PSDASH_LOGS'][0], filename)
Esempio n. 54
0
from psdash.run import PsDashRunner
application = PsDashRunner.create_from_args().app

application.config['SECRET_KEY'] = 'ravioliravioligivemetheformuoli'
application.psdash.logs.add_patterns(['/var/log/nginx/access.log'])