def test_check_instance_es_major_6(self): """Test whether the major version is correctly calculated for ElasticSearch 6.x""" body = """{ "name" : "44BPNNH", "cluster_name" : "elasticsearch", "cluster_uuid" : "fIa1j8AQRfSrmuhTwb9a0Q", "version" : { "number" : "6.1.0", "build_hash" : "c0c1ba0", "build_date" : "2017-12-12T12:32:54.550Z", "build_snapshot" : false, "lucene_version" : "7.1.0", "minimum_wire_compatibility_version" : "5.6.0", "minimum_index_compatibility_version" : "5.0.0" }, "tagline" : "You Know, for Search" }""" es_con = "http://es6.com" httpretty.register_uri(httpretty.GET, es_con, body=body, status=200) major = ElasticSearch.check_instance(es_con, insecure=False) self.assertEqual(major, '6')
def test_check_instance_os_major_1(self): """Test whether the major version is correctly calculated for OpenSearch 1.x""" body = """{ "name" : "AAHAA", "cluster_name" : "docker-cluster", "cluster_uuid" : "XABU6jucSkG48cd7ccUTxQ", "version" : { "distribution" : "opensearch", "number" : "1.2.4", "build_type" : "tar", "build_hash" : "e505b10357c03ae8d26d675172402f2f2144ef0f", "build_date" : "2022-01-14T03:38:06.881862Z", "build_snapshot" : false, "lucene_version" : "8.10.1", "minimum_wire_compatibility_version" : "6.8.0", "minimum_index_compatibility_version" : "6.0.0-beta1" }, "tagline" : "The OpenSearch Project: https://opensearch.org/" }""" os_con = "http://os1.com" httpretty.register_uri(httpretty.GET, os_con, body=body, status=200) major, distribution = ElasticSearch.check_instance(os_con, insecure=False) self.assertEqual(major, '1') self.assertEqual(distribution, OS_DISTRIBUTION)
def test_check_instance_not_reachable(self): """Test whether an exception is thrown when the ElasticSearch is not reachable""" es_con = "http://es_err.com" httpretty.register_uri(httpretty.GET, es_con, body={}, status=400) with self.assertRaises(ElasticError): _ = ElasticSearch.check_instance(es_con, insecure=False)
def test_check_instance_es_major_error(self): """Test whether an exception is thrown when the ElasticSearch version number is not retrieved""" body = """{ "name" : "Amber Hunt", "cluster_name" : "jgbarah", "version" : { "build_hash" : "e3126df", "build_date" : "2016-04-26T12:08:58.960Z", "build_snapshot" : false, "lucene_version" : "6.0.0" }, "tagline" : "You Know, for Search" }""" es_con = "http://es_err.com" httpretty.register_uri(httpretty.GET, es_con, body=body, status=200) with self.assertRaises(ElasticError): _, _ = ElasticSearch.check_instance(es_con, insecure=False)
def test_check_instance_es_major_5(self): """Test whether the major version is correctly calculated for ElasticSearch 5.x""" body = """{ "name" : "Amber Hunt", "cluster_name" : "jgbarah", "version" : { "number" : "5.0.0-alpha2", "build_hash" : "e3126df", "build_date" : "2016-04-26T12:08:58.960Z", "build_snapshot" : false, "lucene_version" : "6.0.0" }, "tagline" : "You Know, for Search" }""" es_con = "http://es5.com" httpretty.register_uri(httpretty.GET, es_con, body=body, status=200) major = ElasticSearch.check_instance(es_con, insecure=False) self.assertEqual(major, '5')