def test_file_discovery(self): with patch.object(os.path, "isfile", side_effect=[False, True]): config_file = operating_system.file_discovery(["/etc/mongodb.conf", "/etc/mongod.conf"]) self.assertEqual("/etc/mongod.conf", config_file) with patch.object(os.path, "isfile", side_effect=[False]): config_file = operating_system.file_discovery(["/etc/mongodb.conf"]) self.assertEqual("", config_file)
def test_file_discovery(self): with patch.object(os.path, 'isfile', side_effect=[False, True]): config_file = operating_system.file_discovery( ["/etc/mongodb.conf", "/etc/mongod.conf"]) self.assertEqual('/etc/mongod.conf', config_file) with patch.object(os.path, 'isfile', side_effect=[False]): config_file = operating_system.file_discovery( ["/etc/mongodb.conf"]) self.assertEqual('', config_file)
def clear_file(filename): LOG.debug("Creating clean file %s" % filename) if operating_system.file_discovery([filename]): operating_system.remove(filename) # force file creation by just opening it open(filename, "wb") operating_system.chmod(filename, operating_system.FileMode.SET_USR_RW, as_root=True)
def clear_file(filename): LOG.debug("Creating clean file %s", filename) if operating_system.file_discovery([filename]): operating_system.remove(filename) # force file creation by just opening it open(filename, 'wb') operating_system.chmod(filename, operating_system.FileMode.SET_USR_RW, as_root=True)
def enable_ldap(self): LOG.debug("Starting saslauthd for LDAP support.") # Ubuntu and RHEL have different ways of enabling the service saslauthd_init_file = operating_system.file_discovery( ['/etc/default/saslauthd']) if saslauthd_init_file: codec = stream_codecs.KeyValueCodec(line_terminator='\n') saslauthd_init = operating_system.read_file( saslauthd_init_file, codec=codec, as_root=True) saslauthd_init['START'] = 'yes' operating_system.write_file( saslauthd_init_file, saslauthd_init, codec=codec, as_root=True) elif operating_system.file_discovery(['/etc/sysconfig/saslauthd']): operating_system.enable_service_on_boot(['saslauthd']) else: LOG.exception(_("Cannot find saslauthd service to enable for LDAP " "client. Skipping.")) return operating_system.start_service(['saslauthd']) saslauthd_conf_file = '/etc/saslauthd.conf' saslauthd_conf = operating_system.read_file( saslauthd_conf_file, stream_codecs.YamlCodec(), as_root=True) saslauthd_conf.update({ 'ldap_servers': CONF.get(self.manager).get('ldap_servers'), 'ldap_search_base': CONF.get(self.manager).get('ldap_search_base') }) ldap_tls_cacert_dir = CONF.get(self.manager).get('ldap_tls_cacert_dir', None) if ldap_tls_cacert_dir: saslauthd_conf.update({ 'ldap_tls_cacert_dir': ldap_tls_cacert_dir, }) ldap_tls_cacert_file = (CONF.get(self.manager) .get('ldap_tls_cacert_file', None)) if ldap_tls_cacert_file: saslauthd_conf.update({ 'ldap_tls_cacert_file': ldap_tls_cacert_file, }) operating_system.write_file( saslauthd_conf_file, saslauthd_conf, stream_codecs.YamlCodec(), as_root=True) LOG.debug("Enabled saslauthd as an LDAP client.")
from trove.common.i18n import _ from trove.common import instance as ds_instance from trove.common.stream_codecs import JsonCodec, SafeYamlCodec from trove.common import utils as utils from trove.guestagent.common.configuration import ConfigurationManager from trove.guestagent.common.configuration import OneFileOverrideStrategy from trove.guestagent.common import guestagent_utils from trove.guestagent.common import operating_system from trove.guestagent.datastore.experimental.mongodb import system from trove.guestagent.datastore import service from trove.guestagent.db import models LOG = logging.getLogger(__name__) CONF = cfg.CONF CONFIG_FILE = operating_system.file_discovery(system.CONFIG_CANDIDATES) MANAGER = CONF.datastore_manager if CONF.datastore_manager else 'mongodb' # Configuration group for clustering-related settings. CNF_CLUSTER = 'clustering' MONGODB_PORT = CONF.mongodb.mongodb_port CONFIGSVR_PORT = CONF.mongodb.configsvr_port class MongoDBApp(object): """Prepares DBaaS on a Guest container.""" def __init__(self): self.state_change_wait_time = CONF.state_change_wait_time
from trove.common import exception from trove.common.i18n import _ from trove.common import instance as ds_instance from trove.common.stream_codecs import JsonCodec, SafeYamlCodec from trove.common import utils as utils from trove.guestagent.common.configuration import ConfigurationManager from trove.guestagent.common.configuration import OneFileOverrideStrategy from trove.guestagent.common import guestagent_utils from trove.guestagent.common import operating_system from trove.guestagent.datastore.experimental.mongodb import system from trove.guestagent.datastore import service from trove.guestagent.db import models LOG = logging.getLogger(__name__) CONF = cfg.CONF CONFIG_FILE = operating_system.file_discovery(system.CONFIG_CANDIDATES) MANAGER = CONF.datastore_manager if CONF.datastore_manager else 'mongodb' # Configuration group for clustering-related settings. CNF_CLUSTER = 'clustering' MONGODB_PORT = CONF.mongodb.mongodb_port CONFIGSVR_PORT = CONF.mongodb.configsvr_port class MongoDBApp(object): """Prepares DBaaS on a Guest container.""" def __init__(self): self.state_change_wait_time = CONF.state_change_wait_time revision_dir = guestagent_utils.build_file_path(
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the # License for the specific language governing permissions and limitations # under the License. from os import path from trove.guestagent.common import operating_system from trove.guestagent import pkg OS_NAME = operating_system.get_os() CONFIG_DIR = "/etc" MONGOD_CONFIG_CANDIDATES = [path.join(CONFIG_DIR, name) for name in ['mongodb.conf', 'mongod.conf']] MONGOD_CONFIG_FILE = operating_system.file_discovery(MONGOD_CONFIG_CANDIDATES) MONGOD_CONFIG_OVERRIDES_DIR = path.join(CONFIG_DIR, 'mongod_overrides') MONGOS_CONFIG_CANDIDATES = [path.join(CONFIG_DIR, name) for name in ['mongodb.conf', 'mongos.conf']] MONGOS_CONFIG_FILE = operating_system.file_discovery(MONGOS_CONFIG_CANDIDATES) MONGOS_CONFIG_OVERRIDES_DIR = path.join(CONFIG_DIR, 'mongos_overrides') MONGO_ADMIN_NAME = 'os_admin' MONGO_ADMIN_ROLES = [{'db': 'admin', 'role': 'userAdminAnyDatabase'}, {'db': 'admin', 'role': 'dbAdminAnyDatabase'}, {'db': 'admin', 'role': 'clusterAdmin'}, {'db': 'admin', 'role': 'readWriteAnyDatabase'}] MONGO_ADMIN_CREDS_FILENAME = '.os_mongo_admin_creds.json' MONGO_ADMIN_CREDS_FILE = path.join(path.expanduser('~'), MONGO_ADMIN_CREDS_FILENAME)
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the # License for the specific language governing permissions and limitations # under the License. from os import path from trove.guestagent.common import operating_system from trove.guestagent import pkg OS_NAME = operating_system.get_os() CONFIG_DIR = "/etc" MONGOD_CONFIG_CANDIDATES = [ path.join(CONFIG_DIR, name) for name in ['mongodb.conf', 'mongod.conf'] ] MONGOD_CONFIG_FILE = operating_system.file_discovery(MONGOD_CONFIG_CANDIDATES) MONGOD_CONFIG_OVERRIDES_DIR = path.join(CONFIG_DIR, 'mongod_overrides') MONGOS_CONFIG_CANDIDATES = [ path.join(CONFIG_DIR, name) for name in ['mongodb.conf', 'mongos.conf'] ] MONGOS_CONFIG_FILE = operating_system.file_discovery(MONGOS_CONFIG_CANDIDATES) MONGOS_CONFIG_OVERRIDES_DIR = path.join(CONFIG_DIR, 'mongos_overrides') MONGO_ADMIN_NAME = 'os_admin' MONGO_ADMIN_ROLES = [{ 'db': 'admin', 'role': 'userAdminAnyDatabase' }, { 'db': 'admin', 'role': 'dbAdminAnyDatabase'