def setup_method(self, _, mocked_transports): """Initialize the test environment for MysqlLegacy.""" # pylint: disable=attribute-defined-outside-init self.config = Config(get_fixture_path("remote", "config.yaml")) self.mocked_transports = mocked_transports self.mocked_remote = mock.MagicMock(spec_set=Remote) self.mysql = mysql_legacy.MysqlLegacy(self.mocked_remote, dry_run=False)
def setup_method(self, _, mocked_transports): """Setup the test environment.""" # pylint: disable=attribute-defined-outside-init self.config = Config(get_fixture_path("remote", "config.yaml")) self.mocked_transports = mocked_transports self.mysql_remote_hosts = mysql_legacy.MysqlLegacyRemoteHosts( RemoteHosts(self.config, NodeSet("host[1-9]"), dry_run=False) ) self.expected = [(NodeSet("host1"), "output1")]
def __init__(self, config: str, dry_run: bool = True) -> None: """Initialize the instance. Arguments: config (str): the path of Cumin's configuration file. dry_run (bool, optional): whether this is a DRY-RUN. """ self._config = Config(config) self._dry_run = dry_run
def main(): """Check Cumin aliases for inconsistencies. Note: Those are the performed checks - each alias should return some hosts. - the sum of all DC-related aliases should return all hosts. - the sum of all the other aliases should return all hosts. Returns: int: zero on success, positive integer on failure. """ ret = 0 config = Config() dc_hosts = NodeSet() alias_hosts = NodeSet() all_hosts = query.Query(config).execute('*') for alias in config['aliases']: try: match = query.Query(config).execute('A:' + alias) except InvalidQueryError as e: print('Unable to execute query for alias {alias}: {msg}'.format( alias=alias, msg=e)) ret = 1 continue if not match: print('Alias {alias} matched 0 hosts'.format(alias=alias)) ret = 1 if alias in DCS: dc_hosts |= match else: alias_hosts |= match time.sleep(2) # Go gentle on PuppetDB base_ret = 2 for hosts, name in ((dc_hosts, 'DC'), (alias_hosts, 'Other')): if all_hosts - hosts: print('{name} aliases do not cover all hosts: {hosts}'.format( name=name, hosts=(all_hosts - hosts))) ret += base_ret elif dc_hosts - all_hosts: print('{name} aliases have unknown hosts: {hosts}'.format( name=name, hosts=(hosts - all_hosts))) ret += base_ret * 2 base_ret *= 4 return ret
def main(): """Check Cumin aliases for inconsistencies. Note: Those are the performed checks - each alias should return some hosts, unless listed in OPTIONAL_ALIASES. - the sum of all DC-related aliases should return all hosts. - the sum of all the other aliases should return all hosts. """ config = Config() dc_hosts = NodeSet() alias_hosts = NodeSet() all_hosts = query.Query(config).execute('*') for alias in config['aliases']: try: match = query.Query(config).execute('A:' + alias) except InvalidQueryError as e: print('Unable to execute query for alias {alias}: {msg}'.format( alias=alias, msg=e)) continue if not match and alias not in OPTIONAL_ALIASES: print('Alias {alias} matched 0 hosts'.format(alias=alias)) if alias in DCS: dc_hosts |= match else: alias_hosts |= match time.sleep(2) # Go gentle on PuppetDB for hosts, name in ((dc_hosts, 'DC'), (alias_hosts, 'Other')): if all_hosts - hosts: print('{name} aliases do not cover all hosts: {hosts}'.format( name=name, hosts=(all_hosts - hosts))) elif dc_hosts - all_hosts: print('{name} aliases have unknown hosts: {hosts}'.format( name=name, hosts=(hosts - all_hosts))) return 0