Example #1
0
    def _check_blacklisted_tables(self, tablet, expected):
        status = tablet.get_status()
        if expected:
            self.assertIn("BlacklistedTables: %s" % " ".join(expected), status)
        else:
            self.assertNotIn("BlacklistedTables", status)

        # check we can or cannot access the tables
        utils.run_vtctl(['ReloadSchema', tablet.tablet_alias])
        conn = tablet.conn()
        for t in ["moving1", "moving2"]:
            if expected and "moving.*" in expected:
                # table is blacklisted, should get the error
                try:
                    results, rowcount, lastrowid, fields = conn._execute(
                        "select count(1) from %s" % t, {})
                    self.fail("blacklisted query execution worked")
                except dbexceptions.RetryError as e:
                    self.assertTrue(
                        str(e).find(
                            "retry: Query disallowed due to rule: enforce blacklisted tables"
                        ) != -1,
                        "Cannot find the right error message in query for blacklisted table: %s"
                        % e)
            else:
                # table is not blacklisted, should just work
                results, rowcount, lastrowid, fields = conn._execute(
                    "select count(1) from %s" % t, {})
                logging.debug("Got %d rows from table %s on tablet %s",
                              results[0][0], t, tablet.tablet_alias)
        conn.close()
Example #2
0
 def _exec_dml(self, tablet, sql, bindvars):
     conn = tablet.conn()
     conn.begin()
     try:
         results = conn._execute(sql, bindvars)
         conn.commit()
         return results(0)
     finally:
         conn.close()
Example #3
0
 def _exec_dml(self, tablet, sql, bindvars):
     conn = tablet.conn()
     conn.begin()
     try:
         results = conn._execute(sql, bindvars)
         conn.commit()
         return results(0)
     finally:
         conn.close()
Example #4
0
  def _check_blacklisted_tables(self, tablet, expected):
    status = tablet.get_status()
    if expected:
      self.assertIn("BlacklistedTables: %s" % " ".join(expected), status)
    else:
      self.assertNotIn("BlacklistedTables", status)

    # check we can or cannot access the tables
    utils.run_vtctl(['ReloadSchema', tablet.tablet_alias])
    conn = tablet.conn()
    for t in ["moving1", "moving2"]:
      if expected and "moving.*" in expected:
        # table is blacklisted, should get the error
        try:
          results, rowcount, lastrowid, fields = conn._execute("select count(1) from %s" % t, {})
          self.fail("blacklisted query execution worked")
        except dbexceptions.RetryError as e:
          self.assertTrue(str(e).find("retry: Query disallowed due to rule: enforce blacklisted tables") != -1, "Cannot find the right error message in query for blacklisted table: %s" % e)
      else:
        # table is not blacklisted, should just work
        results, rowcount, lastrowid, fields = conn._execute("select count(1) from %s" % t, {})
        logging.debug("Got %d rows from table %s on tablet %s", results[0][0], t, tablet.tablet_alias)
    conn.close()