Skip to content

Commit 24c4358

Browse files
authored
Merge pull request #1997 from dhermes/fix-1989
Making HappyBase enabled/disabled checks into no-ops.
2 parents d171791 + 0cb6e60 commit 24c4358

File tree

2 files changed

+94
-34
lines changed

2 files changed

+94
-34
lines changed

gcloud/bigtable/happybase/connection.py

Lines changed: 43 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -49,9 +49,16 @@
4949

5050
_LEGACY_ARGS = frozenset(('host', 'port', 'compat', 'transport', 'protocol'))
5151
_WARN = warnings.warn
52+
_BASE_DISABLE = 'Cloud Bigtable has no concept of enabled / disabled tables.'
5253
_DISABLE_DELETE_MSG = ('The disable argument should not be used in '
53-
'delete_table(). Cloud Bigtable has no concept '
54-
'of enabled / disabled tables.')
54+
'delete_table(). ') + _BASE_DISABLE
55+
_ENABLE_TMPL = 'Connection.enable_table(%r) was called, but ' + _BASE_DISABLE
56+
_DISABLE_TMPL = 'Connection.disable_table(%r) was called, but ' + _BASE_DISABLE
57+
_IS_ENABLED_TMPL = ('Connection.is_table_enabled(%r) was called, but ' +
58+
_BASE_DISABLE)
59+
_COMPACT_TMPL = ('Connection.compact_table(%r, major=%r) was called, but the '
60+
'Cloud Bigtable API handles table compactions automatically '
61+
'and does not expose an API for it.')
5562

5663

5764
def _get_instance(timeout=None):
@@ -378,61 +385,70 @@ def delete_table(self, name, disable=False):
378385
name = self._table_name(name)
379386
_LowLevelTable(name, self._instance).delete()
380387

381-
def enable_table(self, name):
388+
@staticmethod
389+
def enable_table(name):
382390
"""Enable the specified table.
383391
384392
.. warning::
385393
386394
Cloud Bigtable has no concept of enabled / disabled tables so this
387-
method does not work. It is provided simply for compatibility.
395+
method does nothing. It is provided simply for compatibility.
388396
389-
:raises: :class:`NotImplementedError <exceptions.NotImplementedError>`
390-
always
397+
:type name: str
398+
:param name: The name of the table to be enabled.
391399
"""
392-
raise NotImplementedError('The Cloud Bigtable API has no concept of '
393-
'enabled or disabled tables.')
400+
_WARN(_ENABLE_TMPL % (name,))
394401

395-
def disable_table(self, name):
402+
@staticmethod
403+
def disable_table(name):
396404
"""Disable the specified table.
397405
398406
.. warning::
399407
400408
Cloud Bigtable has no concept of enabled / disabled tables so this
401-
method does not work. It is provided simply for compatibility.
409+
method does nothing. It is provided simply for compatibility.
402410
403-
:raises: :class:`NotImplementedError <exceptions.NotImplementedError>`
404-
always
411+
:type name: str
412+
:param name: The name of the table to be disabled.
405413
"""
406-
raise NotImplementedError('The Cloud Bigtable API has no concept of '
407-
'enabled or disabled tables.')
414+
_WARN(_DISABLE_TMPL % (name,))
408415

409-
def is_table_enabled(self, name):
416+
@staticmethod
417+
def is_table_enabled(name):
410418
"""Return whether the specified table is enabled.
411419
412420
.. warning::
413421
414422
Cloud Bigtable has no concept of enabled / disabled tables so this
415-
method does not work. It is provided simply for compatibility.
423+
method always returns :data:`True`. It is provided simply for
424+
compatibility.
416425
417-
:raises: :class:`NotImplementedError <exceptions.NotImplementedError>`
418-
always
426+
:type name: str
427+
:param name: The name of the table to check enabled / disabled status.
428+
429+
:rtype: bool
430+
:returns: The value :data:`True` always.
419431
"""
420-
raise NotImplementedError('The Cloud Bigtable API has no concept of '
421-
'enabled or disabled tables.')
432+
_WARN(_IS_ENABLED_TMPL % (name,))
433+
return True
422434

423-
def compact_table(self, name, major=False):
435+
@staticmethod
436+
def compact_table(name, major=False):
424437
"""Compact the specified table.
425438
426439
.. warning::
427440
428-
Cloud Bigtable does not support compacting a table, so this
429-
method does not work. It is provided simply for compatibility.
441+
Cloud Bigtable supports table compactions, it just doesn't expose
442+
an API for that feature, so this method does nothing. It is
443+
provided simply for compatibility.
444+
445+
:type name: str
446+
:param name: The name of the table to compact.
430447
431-
:raises: :class:`NotImplementedError <exceptions.NotImplementedError>`
432-
always
448+
:type major: bool
449+
:param major: Whether to perform a major compaction.
433450
"""
434-
raise NotImplementedError('The Cloud Bigtable API does not support '
435-
'compacting a table.')
451+
_WARN(_COMPACT_TMPL % (name, major))
436452

437453

438454
def _parse_family_option(option):

gcloud/bigtable/happybase/test_connection.py

Lines changed: 51 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -488,37 +488,81 @@ def mock_warn(msg):
488488
self.assertEqual(warned, [MUT._DISABLE_DELETE_MSG])
489489

490490
def test_enable_table(self):
491+
from gcloud._testing import _Monkey
492+
from gcloud.bigtable.happybase import connection as MUT
493+
491494
instance = _Instance() # Avoid implicit environ check.
492495
connection = self._makeOne(autoconnect=False, instance=instance)
493496

494497
name = 'table-name'
495-
with self.assertRaises(NotImplementedError):
498+
499+
warned = []
500+
501+
def mock_warn(msg):
502+
warned.append(msg)
503+
504+
with _Monkey(MUT, _WARN=mock_warn):
496505
connection.enable_table(name)
497506

507+
self.assertEqual(warned, [MUT._ENABLE_TMPL % (name,)])
508+
498509
def test_disable_table(self):
510+
from gcloud._testing import _Monkey
511+
from gcloud.bigtable.happybase import connection as MUT
512+
499513
instance = _Instance() # Avoid implicit environ check.
500514
connection = self._makeOne(autoconnect=False, instance=instance)
501515

502516
name = 'table-name'
503-
with self.assertRaises(NotImplementedError):
517+
518+
warned = []
519+
520+
def mock_warn(msg):
521+
warned.append(msg)
522+
523+
with _Monkey(MUT, _WARN=mock_warn):
504524
connection.disable_table(name)
505525

526+
self.assertEqual(warned, [MUT._DISABLE_TMPL % (name,)])
527+
506528
def test_is_table_enabled(self):
529+
from gcloud._testing import _Monkey
530+
from gcloud.bigtable.happybase import connection as MUT
531+
507532
instance = _Instance() # Avoid implicit environ check.
508533
connection = self._makeOne(autoconnect=False, instance=instance)
509534

510535
name = 'table-name'
511-
with self.assertRaises(NotImplementedError):
512-
connection.is_table_enabled(name)
536+
537+
warned = []
538+
539+
def mock_warn(msg):
540+
warned.append(msg)
541+
542+
with _Monkey(MUT, _WARN=mock_warn):
543+
result = connection.is_table_enabled(name)
544+
545+
self.assertTrue(result)
546+
self.assertEqual(warned, [MUT._IS_ENABLED_TMPL % (name,)])
513547

514548
def test_compact_table(self):
549+
from gcloud._testing import _Monkey
550+
from gcloud.bigtable.happybase import connection as MUT
551+
515552
instance = _Instance() # Avoid implicit environ check.
516553
connection = self._makeOne(autoconnect=False, instance=instance)
517554

518555
name = 'table-name'
519-
major = True
520-
with self.assertRaises(NotImplementedError):
521-
connection.compact_table(name, major=major)
556+
557+
warned = []
558+
559+
def mock_warn(msg):
560+
warned.append(msg)
561+
562+
with _Monkey(MUT, _WARN=mock_warn):
563+
connection.compact_table(name)
564+
565+
self.assertEqual(warned, [MUT._COMPACT_TMPL % (name, False)])
522566

523567

524568
class Test__parse_family_option(unittest2.TestCase):

0 commit comments

Comments
 (0)