def test_is_node_up(self, fm_cass, fm_ccm): fm_ccm.return_value = True fm_cass.return_value = True host = "h1" HostMan.set_release_version("1.2.3") medusa_config_v4 = self.get_simple_medusa_config(is_ccm_active="1", yaml_file='resources/yaml/original/default-c4.yaml', config_checks={"health_check": "all"}) # TODO Setup the hostman to properly associate for this host to resolve to a release version # When ccm is active, expect ccm health check self.assertTrue(medusa.cassandra_utils.is_node_up(medusa_config_v4, host)) assert fm_cass.call_count == 0 assert fm_ccm.call_count == 1 # reset call counts fm_ccm.call_count = 0 fm_cass.call_count = 0 # And, when ccm is not active, expect a cassandra health check. medusa_config_v4 = self.get_simple_medusa_config(is_ccm_active="0", yaml_file='resources/yaml/original/default-c4.yaml', config_checks={"health_check": "all"}) self.assertTrue(medusa.cassandra_utils.is_node_up(medusa_config_v4, host)) assert fm_cass.call_count == 1 assert fm_ccm.call_count == 0 # generate exception as side-effect fm_cass.side_effect = Exception("Not good.") # And, when an exception occurs during the check, expect a return of False self.assertFalse(medusa.cassandra_utils.is_node_up(medusa_config_v4, host))
def setUp(self): config = configparser.ConfigParser(interpolation=None) config['storage'] = {'host_file_separator': ','} self.config = MedusaConfig( file_path=None, storage=_namedtuple_from_dict(StorageConfig, config['storage']), monitoring={}, cassandra=None, ssh=None, checks=None, logging=None, grpc=None, kubernetes=None, ) # Reset to ensure no stale singleton state exists HostMan.reset()
def test_capture_release_version_from_default(self, mock_storage, mock_abstract_storage): # WHEN api_version is not available from either CLI or the driver. mock_abstract_storage.driver = BaseDriver(key=Mock()) mock_storage.attach_mock(mock_abstract_storage, 'storage_driver') restore_node.capture_release_version(mock_storage, None) # THEN expect default release version will be captured. self.assertEqual(HostMan.get_release_version(), Version(HostMan.DEFAULT_RELEASE_VERSION))
def test_capture_release_version_from_driver(self, mock_storage, mock_abstract_storage): # WHEN api_version from driver is specified and no specified CLI version. mock_abstract_storage.driver = BaseDriver(key=Mock(), api_version='5.0.0') mock_storage.attach_mock(mock_abstract_storage, 'storage_driver') restore_node.capture_release_version(mock_storage, None) # THEN expect the api_version from driver is captured. self.assertEqual(HostMan.get_release_version(), Version('5.0.0'))
def test_capture_release_version_from_CLI(self, mock_storage, mock_abstract_storage): # WHEN api_version is specified from CLI, and api_version is available from driver. mock_abstract_storage.driver = BaseDriver(key=Mock(), api_version='5.0.0') mock_storage.attach_mock(mock_abstract_storage, 'storage_driver') restore_node.capture_release_version(mock_storage, '4.0.0') # THEN expect the api_version from driver is captured. self.assertEqual(HostMan.get_release_version(), Version('4.0.0'))
def test_get_release_version(self): rv_1 = "1.2.3" rv_2 = "5.6.7" rv_3 = "10.11.12" HostMan.set_release_version(rv_1) HostMan.set_release_version(rv_2) HostMan.set_release_version(rv_3) self.assertEqual(HostMan.get_release_version(), Version(rv_3))
def capture_release_version(storage, version_target): # Obtain version via CLI, driver or default. if version_target: HostMan.set_release_version(version_target) elif storage and storage.storage_driver and storage.storage_driver.driver and \ storage.storage_driver.driver.api_version: HostMan.set_release_version(storage.storage_driver.driver.api_version) else: HostMan.set_release_version(HostMan.DEFAULT_RELEASE_VERSION)
def is_node_up(config, host): """ If not configured with ccm, proceed with direct health check for Cassandra. """ try: check_type = config.checks.health_check logging.info('Verifying node state for host {} using check type {}'.format(host, check_type)) if int(config.cassandra.is_ccm) == 1: logging.debug('Checking ccm health') return is_ccm_healthy(check_type) return is_cassandra_healthy(check_type, Cassandra(config, release_version=HostMan.get_release_version()), host) except Exception as e: err_msg = 'Unable to determine if node is up for host: {}'.format(host) logging.debug(err_msg, exc_info=e) return False
def _capture_release_version(self, session): # If no version specified via CLI, but have a session, get version from driver. if not self._version_target and session: driver_app_version = session.cluster.application_version if driver_app_version: logging.debug('Driver version provided as: {}'.format( driver_app_version)) HostMan.set_release_version(driver_app_version) else: logging.debug( 'Unable to obtain app_version via driver or command line, ' 'using default: {}'.format( HostMan.DEFAULT_RELEASE_VERSION)) # Using default as target wasn't found by driver or provided to RestoreJob HostMan.set_release_version(HostMan.DEFAULT_RELEASE_VERSION) # If no session available or specified version from CLI, use default. elif not self._version_target: # Use default HostMan.set_release_version(HostMan.DEFAULT_RELEASE_VERSION) else: # Use what is specified from CLI as version. logging.debug('Target version provided as: {}'.format( self._version_target)) HostMan.set_release_version(self._version_target)
def test_set_release_version_singleton_check(self): rv_1 = "1.2.3" HostMan.set_release_version(rv_1) with self.assertRaises(RuntimeError): HostMan()
def test_set_release_version_missing_input(self): with self.assertRaises(RuntimeError): HostMan.set_release_version(None)
def test_get_release_version_not_set(self): with self.assertRaises(RuntimeError): HostMan.get_release_version()
def setUp(self): HostMan.reset()