示例#1
0
 def test_ping_established(self):
     self.server.expect(method='GET', url='/api$').and_return(mime_type="application/json",
                                                              file_content=test_path + "Fusion_ping_established_response.json")
     self.server.expect(method='GET', url='/api$').and_return(mime_type="application/json",
                                                              file_content=test_path + "Fusion_ping_established_response.json")
     f = Fusion(**fa)
     self.assertTrue(f.ping())
示例#2
0
 def test_ping_established(self):
     self.server.expect(method='GET', url='/api$').and_return(
         mime_type="application/json",
         file_content=test_path + "Fusion_ping_established_response.json")
     self.server.expect(method='GET', url='/api$').and_return(
         mime_type="application/json",
         file_content=test_path + "Fusion_ping_established_response.json")
     f = Fusion(**fa)
     self.assertTrue(f.ping())
示例#3
0
文件: tool.py 项目: ke4roh/fusionpy
def dir(args):
    """
    Write to stdout a json file listing the collections and pipelines available for export.
    This file can then be pruned to only the things that should be collected.
    """
    f = Fusion()
    print json.dumps({
        "collections": f.get_collections(),
        "indexPipelines": [p["id"] for p in f.index_pipelines.get_pipelines()],
        "queryPipelines": [p["id"] for p in f.query_pipelines.get_pipelines()]
    }, indent=True, separators=(',', ':'), sort_keys=True)
示例#4
0
 def test_set_admin_pw(self):
     #        HTTP/1.1 201 Created
     #        (no content)
     self.server.expect(method='GET', url='/api$').and_return(mime_type="application/json",
                                                              file_content=test_path + "Fusion_ping_virgin_response.json")
     self.server.expect(method='POST', url='/api$', data=json.dumps({"password": "******"})).and_return(
         reply_code=201)
     self.server.expect(method='GET', url='/api$').and_return(mime_type="application/json",
                                                              file_content=test_path + "Fusion_ping_established_response.json")
     f = Fusion(**fa)
     f.set_admin_password()
     f.ping()
示例#5
0
    def test_Set_admin_pw_again(self):
        #          HTTP/1.1 409 Conflict
        self.server.expect(method='GET', url='/api$').and_return(mime_type="application/json",
                                                                 file_content=test_path + "Fusion_ping_established_response.json")
        self.server.expect(method='POST', url='/api$', data=json.dumps({"password": "******"})).and_return(
            reply_code=409)

        f = Fusion(**fa)
        try:
            f.set_admin_password()
            self.fail("Should have had an exception")
        except fusionpy.FusionError as fe:
            self.assertEqual(409, fe.response.status)
示例#6
0
    def test_set_admin_pw_bad_pw(self):
        #        HTTP/1.1 400 Bad Request
        #        {"code":"invalid-password"}
        self.server.expect(method='GET', url='/api$').and_return(mime_type="application/json",
                                                                 file_content=test_path + "Fusion_ping_virgin_response.json")
        self.server.expect(method='POST', url='/api$', data=json.dumps({"password": "******"})).and_return(
            reply_code=400,
            content='{"code":"invalid-password"}')

        f = Fusion(**fa)
        try:
            f.set_admin_password("top_secret")
            self.fail("Should have had an exception")
        except fusionpy.FusionError as fe:
            self.assertTrue(fe.response.status == 400)
示例#7
0
    def test_Set_admin_pw_again(self):
        #          HTTP/1.1 409 Conflict
        self.server.expect(method='GET', url='/api$').and_return(
            mime_type="application/json",
            file_content=test_path + "Fusion_ping_established_response.json")
        self.server.expect(method='POST',
                           url='/api$',
                           data=json.dumps({"password": "******"
                                            })).and_return(reply_code=409)

        f = Fusion(**fa)
        try:
            f.set_admin_password()
            self.fail("Should have had an exception")
        except fusionpy.FusionError as fe:
            self.assertEqual(409, fe.response.status)
示例#8
0
文件: tool.py 项目: ke4roh/fusionpy
def delete(args):
    """
    Delete a collection if it exists.  If the named collection does not exist, do nothing.

    :param args:  Optional, the name of a single collection to delete
    """
    if len(args) > 1:
        print "Too many arguments.  Name at most one collection."
        sys.exit(2)

    collection = None
    if len(args) == 1:
        collection = args[0]

    collection = Fusion().get_collection(collection)
    if collection.exists():
        collection.delete_collection(purge=True, solr=True)
示例#9
0
文件: tool.py 项目: ke4roh/fusionpy
def dir(args):
    """
    Write to stdout a json file listing the collections and pipelines available for export.
    This file can then be pruned to only the things that should be collected.
    """
    f = Fusion()
    print json.dumps(
        {
            "collections": f.get_collections(),
            "indexPipelines":
            [p["id"] for p in f.index_pipelines.get_pipelines()],
            "queryPipelines":
            [p["id"] for p in f.query_pipelines.get_pipelines()]
        },
        indent=True,
        separators=(',', ':'),
        sort_keys=True)
示例#10
0
文件: tool.py 项目: ke4roh/fusionpy
def delete(args):
    """
    Delete a collection if it exists.  If the named collection does not exist, do nothing.

    :param args:  Optional, the name of a single collection to delete
    """
    if len(args) > 1:
        print "Too many arguments.  Name at most one collection."
        sys.exit(2)

    collection = None
    if len(args) == 1:
        collection = args[0]

    collection = Fusion().get_collection(collection)
    if collection.exists():
        collection.delete_collection(purge=True, solr=True)
示例#11
0
文件: tool.py 项目: ke4roh/fusionpy
def export(args):
    """
    Save out the current configuration from Fusion to file and folder(s) to permit re-import
    :param args: either a file name, preceeded by @, or a json string of elements to
    """
    with open(args[0]) as fh:
        things_to_save = json.load(fh)

    Fusion().export_config(things_to_save)
示例#12
0
    def test_set_admin_pw_bad_pw(self):
        #        HTTP/1.1 400 Bad Request
        #        {"code":"invalid-password"}
        self.server.expect(method='GET', url='/api$').and_return(
            mime_type="application/json",
            file_content=test_path + "Fusion_ping_virgin_response.json")
        self.server.expect(method='POST',
                           url='/api$',
                           data=json.dumps(
                               {"password": "******"})).and_return(
                                   reply_code=400,
                                   content='{"code":"invalid-password"}')

        f = Fusion(**fa)
        try:
            f.set_admin_password("top_secret")
            self.fail("Should have had an exception")
        except fusionpy.FusionError as fe:
            self.assertTrue(fe.response.status == 400)
示例#13
0
    def test_get_collections(self):
        self.server.expect(method='GET', url='/api$'). \
            and_return(mime_type="application/json",
                       file_content=test_path + "Fusion_ping_established_response.json")
        self.server.expect(method='GET', url='/api/apollo/collections/$'). \
            and_return(mime_type="application/json",
                       file_content=test_path + "list_of_collections.json")
        self.server.expect(method='GET', url='/api/apollo/collections/$'). \
            and_return(mime_type="application/json",
                       file_content=test_path + "list_of_collections.json")
        f = Fusion(**fa)
        c = f.get_collections()
        self.assertEquals(['solutiondupes'], c)

        c = f.get_collections(include_system=True)
        self.assertEquals([
            "system_metrics", "system_blobs", "solutiondupes",
            "system_messages", "logs", "audit_logs"
        ], c)
示例#14
0
    def test_get_collection_stats(self):
        self.server.expect(method='GET', url='/api$'). \
            and_return(mime_type="application/json",
                       file_content=test_path + "Fusion_ping_established_response.json")
        self.server.expect(
            method='GET', url='/api/apollo/collections/phi/stats$').and_return(
                file_content=test_path + "phi-stats.json")
        with open(test_path + "phi-stats.json") as f:
            json_stats = json.loads(f.read())

        self.assertEquals(json_stats, Fusion(**fa).get_collection().stats())
示例#15
0
文件: tool.py 项目: ke4roh/fusionpy
def configure(args):
    """
    Configure collection(s) if not already there, fail if the collection(s) exist but differ from the given
    configuration.

    :param args: the name of a file with configuration information
    """
    with open(args[0]) as f:
        cfg = __ascii_keys(json.load(f))

    fusion = Fusion().ensure_config(write=False, **cfg)
    if fusion is None:
        # It's not there, so safe to write
        Fusion().ensure_config(**cfg)
    elif not fusion:
        # Cowardly not overwriting a differing configuration
        print "Fusion configuration differs from files.  Maybe clean to start over."
        sys.exit(5)

    print "Fusion collection matches file configuration."
示例#16
0
    def test_create_query_pipeline(self):
        self.server.expect(method='GET', url='/api$'). \
            and_return(mime_type="application/json",
                       file_content=test_path + "Fusion_ping_established_response.json")
        self.server.expect(
            method='POST', url='/api/apollo/query-pipelines/$').and_return(
                file_content=test_path + "create-pipeline-response.json")

        with open(test_path + "create-pipeline-response.json") as f:
            qp = json.loads(f.read())

        Fusion(**fa).query_pipelines.add_pipeline(qp)
示例#17
0
    def test_get_index_pipelines(self):
        self.server.expect(method='GET', url='/api$'). \
            and_return(mime_type="application/json",
                       file_content=test_path + "Fusion_ping_established_response.json")
        for i in range(0, 2):
            self.server.expect(method='GET', url='/api/apollo/index-pipelines$'). \
                and_return(mime_type="application/json",
                           file_content=test_path + "some_index_pipelines.json")
        f = Fusion(**fa)
        pipelines = f.get_index_pipelines()

        # This reference pipeline file may change, so this test could assert that certain pipelines are present
        # and even go so far as to dissect them, but this is not a test of json.loads().
        self.assertTrue(len(pipelines) > 8)
        pmap = {}
        for p in pipelines:
            pmap[p['id']] = p['stages']

        self.assertEqual(len(pipelines), len(pmap))

        allpipelines = f.get_index_pipelines(include_system=True)

        self.assertTrue(len(allpipelines) > len(pipelines))
示例#18
0
 def test_set_admin_pw(self):
     #        HTTP/1.1 201 Created
     #        (no content)
     self.server.expect(method='GET', url='/api$').and_return(
         mime_type="application/json",
         file_content=test_path + "Fusion_ping_virgin_response.json")
     self.server.expect(method='POST',
                        url='/api$',
                        data=json.dumps({"password": "******"
                                         })).and_return(reply_code=201)
     self.server.expect(method='GET', url='/api$').and_return(
         mime_type="application/json",
         file_content=test_path + "Fusion_ping_established_response.json")
     f = Fusion(**fa)
     f.set_admin_password()
     f.ping()
示例#19
0
    def test_get_query_pipelines(self):
        self.server.expect(method='GET', url='/api$'). \
            and_return(mime_type="application/json",
                       file_content=test_path + "Fusion_ping_established_response.json")
        for i in range(0, 2):
            self.server.expect(method='GET', url='/api/apollo/query-pipelines$'). \
                and_return(mime_type="application/json",
                           file_content=test_path + "some_query_pipelines.json")
        f = Fusion(**fa)
        pipelines = f.query_pipelines.get_pipelines(include_system=False)

        # This reference pipeline file may change, so this test could assert that certain pipelines are present
        # and even go so far as to dissect them, but this is not a test of json.loads().
        self.assertTrue(len(pipelines) > 7, len(pipelines))
        pmap = {}
        for p in pipelines:
            pmap[p['id']] = p['stages']

        self.assertEqual(len(pipelines), len(pmap))

        allpipelines = f.query_pipelines.get_pipelines(include_system=True)

        self.assertTrue(len(allpipelines) > len(pipelines))