def test_add_metric_duplicate_empty_server(self): params = {"type": "metric", "name": uhex(), "cluster": "East", "bucket": "default", "collector": "ns_server"} request = self.factory.post("/add_metric_or_event", params) rest_api.dispatcher(request, path="add_metric_or_event") response = rest_api.dispatcher(request, path="add_metric_or_event") self.response = response
def test_pdf(self): params = {"snapshot": "run-1_access-phase_vperf-reb_2.0.0-1976"} request = self.factory.post("/pdf", params) self.response = rest_api.dispatcher(request, path="pdf") self.assertEqual("/media/run-1_access-phase_vperf-reb_2.0.0-1976.pdf", self.response.content)
def test_get_snapshots(self): request = self.factory.get("/get_snapshots") self.response = rest_api.dispatcher(request, path="get_snapshots") # Verify content expected = json.dumps(["run-1_access-phase_vperf-reb_2.0.0-1976"]) self.assertEquals(self.response.content, expected)
def test_plot(self): params = {"snapshot": "run-1_access-phase_vperf-reb_2.0.0-1976"} request = self.factory.post("/plot", params) self.response = rest_api.dispatcher(request, path="plot") # Verify content expected = json.dumps([]) self.assertEquals(self.response.content, expected)
def test_get_servers(self): params = {"cluster": "East"} request = self.factory.get("/get_servers", params) self.response = rest_api.dispatcher(request, path="get_servers") # Verify content expected = json.dumps(["ec2-54-242-160-13.compute-1.amazonaws.com"]) self.assertEquals(self.response.content, expected)
def test_get_buckets(self): params = {"cluster": "East"} request = self.factory.get("/get_buckets", params) self.response = rest_api.dispatcher(request, path="get_buckets") # Verify content expected = json.dumps(["default"]) self.assertEquals(self.response.content, expected)
def test_add_event_no_cluster(self): params = {"type": uhex(), "name": "failover", "server": "ec2-54-242-160-13.compute-1.amazonaws.com", "bucket": "default", "collector": "ns_server"} request = self.factory.post("/add_metric_or_event", params) self.response = rest_api.dispatcher(request, path="add_metric_or_event")
def test_add_metric_no_server(self): params = {"type": "metric", "name": uhex(), "cluster": "East", "bucket": "default", "collector": "ns_server"} request = self.factory.post("/add_metric_or_event", params) response = rest_api.dispatcher(request, path="add_metric_or_event") # Verify persistence self.test_get_metrics_no_server(params) self.response = response
def test_add_metric_with_too_long_unit(self): params = {"type": "metric", "name": uhex(), "cluster": "East", "server": "ec2-54-242-160-13.compute-1.amazonaws.com", "bucket": "default", "collector": "ns_server", "unit": uhex()} request = self.factory.post("/add_metric_or_event", params) response = rest_api.dispatcher(request, path="add_metric_or_event") # Verify persistence self.response = response
def test_get_metrics_no_server(self, params=None): if not params: params = {"type": "metric", "cluster": "East", "bucket": "default"} expected = [{"name": "disk_queue", "collector": "ns_server"}] else: expected = [ {"name": "disk_queue", "collector": "ns_server"}, {"name": params["name"], "collector": params["collector"]} ] request = self.factory.get("/get_metrics_and_events", params) self.response = rest_api.dispatcher(request, path="get_metrics_and_events") # Verify content self.assertEquals(sorted(self.response.content), sorted(json.dumps(expected)))
def test_get_events(self, params=None): if not params: params = {"type": "event", "cluster": "East", "server": "ec2-54-242-160-13.compute-1.amazonaws.com", "bucket": "default"} expected = [{"name": "Rebalance start", "collector": "ns_server"}] else: expected = [ {"name": "Rebalance start", "collector": "ns_server"}, {"name": params["name"], "collector": params["collector"]} ] request = self.factory.get("/get_metrics_and_events", params) self.response = rest_api.dispatcher(request, path="get_metrics_and_events") # Verify content self.assertEquals(sorted(self.response.content), sorted(json.dumps(expected)))
def test_get_servers_wrong_param(self): params = {"cluster": "West"} request = self.factory.get("/get_servers", params) self.response = rest_api.dispatcher(request, path="get_servers")
def test_get_servers_with_missing_param(self): request = self.factory.get("/get_servers") self.response = rest_api.dispatcher(request, path="get_servers")
def test_get_clusters(self): request = self.factory.get("/get_clusters") self.response = rest_api.dispatcher(request, path="get_clusters") # Verify content self.assertEquals(self.response.content, json.dumps(["East"]))
def test_get_tree_data(self): request = self.factory.get("/get_tree_data") self.response = rest_api.dispatcher(request, path="get_tree_data")
def delete_item(self, item, params): """Add new cluster/server/bucket""" request = self.factory.post("/delete_" + item, params) response = rest_api.dispatcher(request, path="delete_" + item) return response