예제 #1
0
def connect_database(self, server_group, server_id, db_id):
    """
    This function verifies that database is exists and whether it connect
    successfully or not

    :param self: class object of test case class
    :type self: class
    :param server_group: server group id
    :type server_group: int
    :param server_id: server id
    :type server_id: str
    :param db_id: database id
    :type db_id: str
    :return: temp_db_con
    :rtype: list
    """

    # Verify servers
    server_utils.connect_server(self, server_id)

    # Connect to database
    db_con = self.tester.post('{0}{1}/{2}/{3}'.format(
        DATABASE_CONNECT_URL, server_group, server_id, db_id),
        follow_redirects=True)
    assert db_con.status_code == 200
    db_con = json.loads(db_con.data.decode('utf-8'))
    return db_con
 def setUp(self):
     self.db_name = parent_node_dict["database"][-1]["db_name"]
     schema_info = parent_node_dict["schema"][-1]
     self.server_id = schema_info["server_id"]
     self.db_id = schema_info["db_id"]
     server_con = server_utils.connect_server(self, self.server_id)
     if server_con:
         if "type" in server_con["data"]:
             if server_con["data"]["type"] == "pg":
                 message = "Synonyms are not supported by PG."
                 self.skipTest(message)
     db_con = database_utils.connect_database(self, utils.SERVER_GROUP,
                                              self.server_id, self.db_id)
     if not db_con['data']["connected"]:
         raise Exception("Could not connect to database to add synonym.")
     self.schema_id = schema_info["schema_id"]
     self.schema_name = schema_info["schema_name"]
     schema_response = schema_utils.verify_schemas(self.server,
                                                   self.db_name,
                                                   self.schema_name)
     if not schema_response:
         raise Exception("Could not find the schema to add the synonym.")
     self.sequence_name = "test_sequence_synonym_%s" % \
                          str(uuid.uuid4())[1:6]
     self.sequence_id = sequence_utils.create_sequences(
         self.server, self.db_name, self.schema_name, self.sequence_name)
     self.synonym_name = "test_synonym_delete_%s" % str(uuid.uuid4())[1:6]
     synonym_utils.create_synonym(self.server, self.db_name,
                                  self.schema_name, self.synonym_name,
                                  self.sequence_name)
예제 #3
0
 def runTest(self):
     """ This function will add database under 1st server of tree node. """
     self.db_name = ''
     self.server_id = parent_node_dict["server"][-1]["server_id"]
     server_response = server_utils.connect_server(self, self.server_id)
     if server_response["info"] == "Server connected.":
         db_owner = server_response['data']['user']['name']
         self.data = database_utils.get_db_data(db_owner)
         self.data['template'] = 'template0'
         self.db_name = self.data['name']
         response = self.tester.post(self.url + str(utils.SERVER_GROUP) +
                                     "/" + str(self.server_id) + "/",
                                     data=json.dumps(self.data),
                                     content_type='html/json')
         self.assertEquals(response.status_code, 200)
         response_data = json.loads(response.data.decode('utf-8'))
         db_id = response_data['node']['_id']
         db_dict = {
             "server_id": self.server_id,
             "db_id": db_id,
             "db_name": self.db_name
         }
         utils.write_node_info("did", db_dict)
     else:
         raise Exception("Error while connecting server to add the"
                         " database.")
예제 #4
0
    def setUp(self):
        self.db_name = parent_node_dict["database"][-1]["db_name"]
        schema_info = parent_node_dict["schema"][-1]
        self.server_id = schema_info["server_id"]
        self.db_id = schema_info["db_id"]
        server_response = server_utils.connect_server(self, self.server_id)

        if server_response["data"]["version"] < 90300 and "mview" in self.url:
            message = "Materialized Views are not supported by PG9.2 " \
                      "and PPAS9.2 and below."
            self.skipTest(message)

        db_con = database_utils.connect_database(self, utils.SERVER_GROUP,
                                                 self.server_id, self.db_id)
        if not db_con['data']["connected"]:
            raise Exception("Could not connect to database to fetch the view.")
        self.schema_id = schema_info["schema_id"]
        self.schema_name = schema_info["schema_name"]
        schema_response = schema_utils.verify_schemas(self.server,
                                                      self.db_name,
                                                      self.schema_name)
        if not schema_response:
            raise Exception("Could not find the schema to fetch the view.")
        self.view_id = views_utils.create_view(self.server, self.db_name,
                                               self.schema_name,
                                               self.sql_query, self.view_name)
 def setUp(self):
     self.schema_data = parent_node_dict['schema'][-1]
     self.server_id = self.schema_data['server_id']
     self.db_id = self.schema_data['db_id']
     self.schema_name = self.schema_data['schema_name']
     self.schema_id = self.schema_data['schema_id']
     self.extension_name = "postgres_fdw"
     self.db_name = parent_node_dict["database"][-1]["db_name"]
     self.db_user = self.server["username"]
     self.func_name = "trigger_func_%s" % str(uuid.uuid4())[1:6]
     self.trigger_name = "event_trigger_get_%s" % (str(uuid.uuid4())[1:6])
     server_con = server_utils.connect_server(self, self.server_id)
     if not server_con["info"] == "Server connected.":
         raise Exception("Could not connect to server to add resource "
                         "groups.")
     server_version = 0
     if "type" in server_con["data"]:
         if server_con["data"]["version"] < 90300:
             message = "Event triggers are not supported by PG9.2 " \
                       "and PPAS9.2 and below."
             self.skipTest(message)
     self.function_info = trigger_funcs_utils.create_trigger_function(
         self.server, self.db_name, self.schema_name, self.func_name,
         server_version)
     self.event_trigger_id = event_trigger_utils.create_event_trigger(
         self.server, self.db_name, self.schema_name, self.func_name,
         self.trigger_name)
예제 #6
0
    def setUp(self):
        self.db_name = parent_node_dict["database"][-1]["db_name"]
        schema_info = parent_node_dict["schema"][-1]
        self.server_id = schema_info["server_id"]
        self.db_id = schema_info["db_id"]
        db_con = database_utils.connect_database(self, utils.SERVER_GROUP,
                                                 self.server_id, self.db_id)
        if not db_con['data']["connected"]:
            raise Exception("Could not connect to database to add a table.")
        self.schema_id = schema_info["schema_id"]
        self.schema_name = schema_info["schema_name"]
        schema_response = schema_utils.verify_schemas(self.server,
                                                      self.db_name,
                                                      self.schema_name)
        if not schema_response:
            raise Exception("Could not find the schema to add a table.")

        self.is_partition = False
        if hasattr(self, 'server_min_version'):
            server_con = server_utils.connect_server(self, self.server_id)
            if not server_con["info"] == "Server connected.":
                raise Exception("Could not connect to server to add "
                                "partitioned table.")
            if server_con["data"]["version"] < self.server_min_version:
                message = "Partitioned table are not supported by " \
                          "PPAS/PG 10.0 and below."
                self.skipTest(message)
            else:
                self.is_partition = True
예제 #7
0
    def runTest(self):
        """ This function will delete schema under database node. """
        schema = parent_node_dict["schema"][-1]
        db_id = schema["db_id"]
        server_id = schema["server_id"]

        server_response = server_utils.connect_server(self, server_id)
        if not server_response["data"]["connected"]:
            raise Exception("Could not connect to server to connect the"
                            " database.")

        db_con = database_utils.connect_database(self,
                                                 utils.SERVER_GROUP,
                                                 server_id,
                                                 db_id)
        if not db_con["info"] == "Database connected.":
            raise Exception("Could not connect to database to get the schema.")

        schema_id = schema["schema_id"]
        schema_response = self.tester.get(
            self.url + str(utils.SERVER_GROUP) + '/' +
            str(server_id) + '/' + str(db_id) +
            '/' + str(schema_id),
            content_type='html/json')
        self.assertEquals(schema_response.status_code, 200)
        # Disconnect the database
        database_utils.disconnect_database(self, server_id, db_id)
예제 #8
0
 def runTest(self):
     """ This function will delete the database."""
     server_response = server_utils.connect_server(self, self.server_id)
     if server_response["data"]["connected"]:
         db_id = self.db_id
         response = self.tester.delete(self.url + str(utils.SERVER_GROUP) +
                                       '/' + str(self.server_id) + '/' +
                                       str(db_id),
                                       follow_redirects=True)
         self.assertEquals(response.status_code, 200)
     else:
         raise Exception("Could not connect to server to delete the "
                         "database.")
예제 #9
0
    def runTest(self):
        """ This function will update trigger function under database node. """
        schema_info = parent_node_dict["schema"][-1]
        server_id = schema_info["server_id"]
        db_id = schema_info["db_id"]
        func_name = "test_event_put_%s" % str(uuid.uuid4())[1:6]
        server_con = server_utils.connect_server(self, server_id)
        if not server_con["info"] == "Server connected.":
            raise Exception("Could not connect to server to add resource "
                            "groups.")
        server_version = 0
        if "type" in server_con["data"]:
            if server_con["data"]["version"] < 90300:
                server_version = server_con["data"]["version"]
        self.function_info = trigger_funcs_utils.create_trigger_function(
            self.server, self.db_name, self.schema_name, func_name,
            server_version)
        db_con = database_utils.connect_database(self, utils.SERVER_GROUP,
                                                 server_id, db_id)
        if not db_con['data']["connected"]:
            raise Exception("Could not connect to database to add collation.")
        schema_response = schema_utils.verify_schemas(self.server,
                                                      self.db_name,
                                                      self.schema_name)
        if not schema_response:
            raise Exception("Could not find the schema to add the collation.")
        func_name = self.function_info[1]
        func_response = trigger_funcs_utils.verify_trigger_function(
            self.server,
            self.db_name,
            func_name)
        if not func_response:
            raise Exception("Could not find the trigger function to update"
                            " it's details.")

        trigger_func_id = self.function_info[0]
        data = {
            "description": "This is trigger function update comment",
            "id": trigger_func_id
        }

        put_response = self.tester.put(self.url + str(utils.SERVER_GROUP) +
                                       '/' + str(server_id) + '/' + str(db_id)
                                       + '/' + str(self.schema_id) + '/' +
                                       str(trigger_func_id),
                                       data=json.dumps(data),
                                       follow_redirects=True)
        self.assertEquals(put_response.status_code, 200)
        # Disconnect the database
        database_utils.disconnect_database(self, server_id, db_id)
예제 #10
0
    def runTest(self):
        """This function test the get table space scenario"""
        server_response = server_utils.connect_server(self, self.server_id)
        if not server_response['data']['connected']:
            raise Exception("Unable to connect server to get tablespace.")

        tablespace_count = tablespace_utils.verify_table_space(
            self.server, self.tablespace_name)
        if tablespace_count == 0:
            raise Exception("No tablespace(s) to update!!!")
        response = self.tester.get(self.url + str(utils.SERVER_GROUP) + '/' +
                                   str(self.server_id) + '/' +
                                   str(self.tablespace_id),
                                   follow_redirects=True)
        self.assertEquals(response.status_code, 200)
예제 #11
0
    def setUp(self):

        schema_info = parent_node_dict["schema"][-1]
        self.schema_id = schema_info["schema_id"]
        self.schema_name = schema_info["schema_name"]
        self.db_name = parent_node_dict["database"][-1]["db_name"]
        self.server_id = schema_info["server_id"]
        self.db_id = schema_info["db_id"]
        server_con = server_utils.connect_server(self, self.server_id)

        if server_con:
            if "type" in server_con["data"]:
                if server_con["data"]["type"] == "pg":
                    message = "Packages are not supported by PG."
                    self.skipTest(message)
예제 #12
0
 def setUp(self):
     self.server_id = parent_node_dict["server"][-1]["server_id"]
     server_con = server_utils.connect_server(self, self.server_id)
     if not server_con["info"] == "Server connected.":
         raise Exception("Could not connect to server to add resource "
                         "groups.")
     if "type" in server_con["data"]:
         if server_con["data"]["type"] == "pg":
             message = "Resource groups are not supported by PG."
             self.skipTest(message)
         else:
             if server_con["data"]["version"] < 90400:
                 message = "Resource groups are not supported by PPAS 9.3" \
                           " and below."
                 self.skipTest(message)
예제 #13
0
 def setUp(self):
     self.server_id = parent_node_dict["server"][-1]["server_id"]
     server_response = server_utils.connect_server(self, self.server_id)
     if not server_response["info"] == "Server connected.":
         raise Exception("Could not connect to server to add resource "
                         "groups.")
     if "type" in server_response["data"]:
         if server_response["data"]["type"] == "pg":
             message = "Resource groups are not supported by PG."
             self.skipTest(message)
         else:
             if server_response["data"]["version"] < 90400:
                 message = "Resource groups are not supported by PPAS 9.3" \
                           " and below."
                 self.skipTest(message)
     self.resource_group = "test_resource_group_get%s" % \
                      str(uuid.uuid4())[1:6]
     self.resource_group_id = resource_groups_utils.create_resource_groups(
         self.server, self.resource_group)
예제 #14
0
    def runTest(self):
        """This function test the add role scenario"""
        server_id = parent_node_dict["server"][-1]["server_id"]
        server_response = server_utils.connect_server(self, server_id)
        if not server_response['data']['connected']:
            raise Exception("Server not found to add the role.")

        data = roles_utils.get_role_data(self.server['db_password'])
        self.role_name = data['rolname']
        response = self.tester.post(self.url + str(utils.SERVER_GROUP) + '/'
                                    + str(server_id) + '/',
                                    data=json.dumps(data),
                                    content_type='html/json')
        self.assertEquals(response.status_code, 200)
        response_data = json.loads(response.data.decode('utf-8'))
        role_id = response_data['node']['_id']
        role_dict = {"server_id": server_id, "role_id": role_id,
                     "role_name": self.role_name}
        utils.write_node_info("lrid", role_dict)
예제 #15
0
    def setUp(self):

        schema_info = parent_node_dict["schema"][-1]
        self.schema_id = schema_info["schema_id"]
        self.schema_name = schema_info["schema_name"]
        self.db_name = parent_node_dict["database"][-1]["db_name"]
        self.pkg_name = "pkg_%s" % str(uuid.uuid4())[1:8]
        self.proc_name = "proc_%s" % str(uuid.uuid4())[1:8]
        self.server_id = schema_info["server_id"]
        self.db_id = schema_info["db_id"]
        server_con = server_utils.connect_server(self, self.server_id)

        if server_con:
            if "type" in server_con["data"]:
                if server_con["data"]["type"] == "pg":
                    message = "Packages are not supported by PG."
                    self.skipTest(message)

        self.package_id = package_utils.create_package(self.server,
                                                       self.db_name,
                                                       self.schema_name,
                                                       self.pkg_name,
                                                       self.proc_name)
예제 #16
0
    def runTest(self):
        """ This function will delete trigger function under database node. """
        schema_info = parent_node_dict["schema"][-1]
        server_id = schema_info["server_id"]
        db_id = schema_info["db_id"]
        func_name = "test_event_get_%s" % str(uuid.uuid4())[1:8]
        db_user = self.server["username"]
        server_con = server_utils.connect_server(self, server_id)
        if not server_con["info"] == "Server connected.":
            raise Exception("Could not connect to server to add resource "
                            "groups.")
        server_version = 0
        if "type" in server_con["data"]:
            if server_con["data"]["version"] < 90300:
                server_version = server_con["data"]["version"]
        self.function_info = trigger_funcs_utils.create_trigger_function(
            self.server, self.db_name, self.schema_name, func_name,
            server_version)

        db_con = database_utils.connect_database(self, utils.SERVER_GROUP,
                                                 server_id, db_id)
        if not db_con['data']["connected"]:
            raise Exception("Could not connect to database to add collation.")
        schema_response = schema_utils.verify_schemas(self.server,
                                                      self.db_name,
                                                      self.schema_name)
        if not schema_response:
            raise Exception("Could not find the schema to add the collation.")
        trigger_func_id = self.function_info[0]
        response = self.tester.get(self.url + str(utils.SERVER_GROUP) + '/' +
                                   str(server_id) + '/' + str(db_id) + '/' +
                                   str(self.schema_id) + '/' +
                                   str(trigger_func_id),
                                   content_type='html/json')
        self.assertEquals(response.status_code, 200)
        # Disconnect the database
        database_utils.disconnect_database(self, server_id, db_id)
예제 #17
0
    def runTest(self):
        """This function test the add tablespace API"""
        server_id = parent_node_dict["server"][-1]["server_id"]
        server_response = server_utils.connect_server(self, server_id)
        if not server_response['data']['connected']:
            raise Exception("Unable to connect server to get tablespace.")

        db_owner = server_response['data']['user']['name']
        table_space_path = self.server['tablespace_path']
        data = tablespace_utils.get_tablespace_data(table_space_path, db_owner)
        self.tablespace_name = data['name']
        response = self.tester.post(self.url + str(utils.SERVER_GROUP) + '/' +
                                    str(server_id) + '/',
                                    data=json.dumps(data),
                                    content_type='html/json')
        self.assertEquals(response.status_code, 200)
        response_data = json.loads(response.data.decode('utf-8'))
        tablespace_id = response_data['node']['_id']
        tablespace_dict = {
            "tablespace_id": tablespace_id,
            "tablespace_name": self.tablespace_name,
            "server_id": server_id
        }
        utils.write_node_info("tsid", tablespace_dict)
예제 #18
0
    def runTest(self):
        """ This function will add trigger function under schema node. """
        db_name = parent_node_dict["database"][-1]["db_name"]
        schema_info = parent_node_dict["schema"][-1]
        server_id = schema_info["server_id"]
        db_id = schema_info["db_id"]
        prorettypename = "event_trigger/trigger"
        server_con = server_utils.connect_server(self, server_id)
        if not server_con["info"] == "Server connected.":
            raise Exception("Could not connect to server to add resource "
                            "groups.")
        if "type" in server_con["data"]:
            if server_con["data"]["version"] < 90300:
                prorettypename = "trigger"

        db_con = database_utils.connect_database(self, utils.SERVER_GROUP,
                                                 server_id, db_id)
        if not db_con['data']["connected"]:
            raise Exception("Could not connect to database to add a function.")
        schema_id = schema_info["schema_id"]
        schema_name = schema_info["schema_name"]
        schema_response = schema_utils.verify_schemas(self.server,
                                                      db_name,
                                                      schema_name)
        if not schema_response:
            raise Exception("Could not find the schema to add a function.")
        db_user = self.server["username"]
        data = {
            "acl": [
                {
                    "grantee": db_user,
                    "grantor": db_user,
                    "privileges":
                        [
                            {
                                "privilege_type": "X",
                                "privilege": True,
                                "with_grant": True
                            }
                        ]
                }
            ],
            "arguments": [],
            "funcowner": db_user,
            "lanname": "plpgsql",
            "name": "test_abort_any_command",
            "options": [],
            "proleakproof": True,
            "pronamespace": 2200,
            "prorettypename": prorettypename,
            "prosecdef": True,
            "prosrc": "BEGIN RAISE EXCEPTION 'command % is disabled',"
                      " tg_tag; END;",
            "provolatile": "s",
            "seclabels": [],
            "variables": [
                {
                    "name": "enable_sort",
                    "value": True
                }
            ]
        }
        # Get the type from data. We are adding two types
        # i.e. event_trigger and trigger.
        trigger_func_types = data['prorettypename'].split('/')
        for func_type in trigger_func_types:
            data['prorettypename'] = func_type
            data["name"] = "test_event_add_%s" % str(uuid.uuid4())[1:6]
            if schema_id:
                data['pronamespace'] = schema_id
            else:
                schema_id = data['pronamespace']
            response = self.tester.post(
                self.url + str(utils.SERVER_GROUP) + '/' +
                str(server_id) + '/' + str(db_id) + '/' + str(schema_id)
                + '/', data=json.dumps(data), content_type='html/json')

            self.assertEquals(response.status_code, 200)
        # Disconnect the database
        database_utils.disconnect_database(self, server_id, db_id)