예제 #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])
        for t in ["moving1", "moving2"]:
            if expected and "moving.*" in expected:
                # table is blacklisted, should get the error
                out, err = tablet.vquery("select count(1) from %s" % t,
                                         path='source_keyspace/0',
                                         raise_on_error=False)
                self.assertTrue(
                    err.find(
                        "retry: Query disallowed due to rule: enforce blacklisted tables"
                    ) != -1,
                    "Cannot find the right error message in query for blacklisted table: out=\n%serr=\n%s"
                    % (out, err))
            else:
                # table is not blacklisted, should just work
                tablet.vquery("select count(1) from %s" % t,
                              path='source_keyspace/0')
예제 #2
0
  def _check_query_service(self, tablet, serving, tablet_control_disabled):
    """_check_query_service will check that the query service is enabled
    or disabled on the tablet. It will also check if the tablet control
    status is the reason for being enabled / disabled.

    It will also run a remote RunHealthCheck to be sure it doesn't change
    the serving state.
    """
    tablet_vars = utils.get_vars(tablet.port)
    if serving:
      expected_state = 'SERVING'
    else:
      expected_state = 'NOT_SERVING'
    self.assertEqual(tablet_vars['TabletStateName'], expected_state, 'tablet %s is not in the right serving state: got %s expected %s' % (tablet.tablet_alias, tablet_vars['TabletStateName'], expected_state))

    status = tablet.get_status()
    if tablet_control_disabled:
      self.assertIn("Query Service disabled by TabletControl", status)
    else:
      self.assertNotIn("Query Service disabled by TabletControl", status)

    if tablet.tablet_type == 'rdonly':
      utils.run_vtctl(['RunHealthCheck', tablet.tablet_alias, 'rdonly'],
                      auto_log=True)

      tablet_vars = utils.get_vars(tablet.port)
      if serving:
        expected_state = 'SERVING'
      else:
        expected_state = 'NOT_SERVING'
      self.assertEqual(tablet_vars['TabletStateName'], expected_state, 'tablet %s is not in the right serving state after health check: got %s expected %s' % (tablet.tablet_alias, tablet_vars['TabletStateName'], expected_state))
예제 #3
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()
예제 #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])
        for t in ["moving1", "moving2"]:
            if expected and "moving.*" in expected:
                # table is blacklisted, should get the error
                _, stderr = utils.run_vtctl(
                    [
                        "VtTabletExecute",
                        "-keyspace",
                        tablet.keyspace,
                        "-shard",
                        tablet.shard,
                        tablet.tablet_alias,
                        "select count(1) from %s" % t,
                    ],
                    expect_fail=True,
                )
                self.assertIn("retry: Query disallowed due to rule: enforce blacklisted tables", stderr)
            else:
                # table is not blacklisted, should just work
                qr = tablet.execute("select count(1) from %s" % t)
                logging.debug("Got %s rows from table %s on tablet %s", qr["Rows"][0][0], t, tablet.tablet_alias)
예제 #5
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
        for t in ['moving1', 'moving2']:
            if expected and 'moving.*' in expected:
                # table is blacklisted, should get the error
                _, stderr = utils.run_vtctl([
                    'VtTabletExecute', '-keyspace', tablet.keyspace, '-shard',
                    tablet.shard, tablet.tablet_alias,
                    'select count(1) from %s' % t
                ],
                                            expect_fail=True)
                self.assertIn(
                    'retry: Query disallowed due to rule: enforce blacklisted tables',
                    stderr)
            else:
                # table is not blacklisted, should just work
                qr = tablet.execute('select count(1) from %s' % t)
                logging.debug('Got %s rows from table %s on tablet %s',
                              qr['Rows'][0][0], t, tablet.tablet_alias)
예제 #6
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])
    for t in ['moving1', 'moving2']:
      if expected and 'moving.*' in expected:
        # table is blacklisted, should get the error
        _, stderr = utils.run_vtctl(['VtTabletExecute',
                                     '-keyspace', tablet.keyspace,
                                     '-shard', tablet.shard,
                                     tablet.tablet_alias,
                                     'select count(1) from %s' % t],
                                    expect_fail=True)
        self.assertIn(
            'retry: Query disallowed due to rule: enforce blacklisted tables',
            stderr)
      else:
        # table is not blacklisted, should just work
        qr = tablet.execute('select count(1) from %s' % t)
        logging.debug('Got %s rows from table %s on tablet %s',
                      qr['Rows'][0][0], t, tablet.tablet_alias)
예제 #7
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])
    for t in ["moving1", "moving2"]:
      if expected and "moving.*" in expected:
        # table is blacklisted, should get the error
        out, err = tablet.vquery("select count(1) from %s" % t,
                                 path='source_keyspace/0', raise_on_error=False)
        self.assertTrue(err.find("retry: Query disallowed due to rule: enforce blacklisted tables") != -1, "Cannot find the right error message in query for blacklisted table: out=\n%serr=\n%s" % (out, err))
      else:
        # table is not blacklisted, should just work
        tablet.vquery("select count(1) from %s" % t, path='source_keyspace/0')
예제 #8
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()