def default_config_update(self, name, description, datastore, datastore_version, config_id): try: self.db_api.configure_db(CONF) context = TroveContext(tenant = CONF.default_template_tenant_id) context.is_admin = True tenant_id = CONF.default_template_tenant_id #datastore = ds_models.DBDatastore.find_by(name=datastore) ds = ds_models.Datastore.load(datastore) version_id = ds.default_version_id if datastore_version: version = ds_models.DatastoreVersion.load(ds, datastore_version) if version: version_id = version.id try: group = config_models.KSC_Configuration.load(context, config_id) group.name = name group.description = description group.datastore_version_id = version_id self.db_api.save(group) except exception.ModelNotFoundError: # Create a new one config_models.KSC_Configuration.create(name, description, tenant_id, ds, version_id) print("Configuration '%s' update." % name) except exception as e: print(e)
def default_config_delete(self, id): try: self.db_api.configure_db(CONF) context = TroveContext(tenant = CONF.default_template_tenant_id) context.is_admin = True group = config_models.KSC_Configuration.load(context, id) config_models.KSC_Configuration.delete(context, group) print("Configuration '%s' delete." % id) except exception as e: print(e)
def default_config_items_update(self, id, value_file, config_name = None, description = None): try: self.db_api.configure_db(CONF) context = TroveContext(tenant = CONF.default_template_tenant_id) context.is_admin = True group = config_models.KSC_Configuration.load(context, id) ''' instances = instances_models.DBInstance.find_all( tenant_id=context.tenant, configuration_id=id, deleted=False).all() ''' # if name/description are provided in the request body, update the # model with these values as well. if config_name is not None: group.name = config_name if description is not None: group.description = description fmt_values = {} if value_file is not None and os.path.isfile(value_file): config = open(value_file).read() cfg_parser = configurations.MySQLConfParser(config) parsed = cfg_parser.parse() values = dict(parsed) rules = configurations.get_validation_rules(datastore_manager='mysql') fmt_values = {} for k, v in values.iteritems(): # get the validation rule dictionary, which will ensure there is a # rule for the given key name. An exception will be thrown if no # valid rule is located. rule = config_service.ConfigurationsController._get_item(k, rules['configuration-parameters']) valueType = rule.get('type') if "integer" == valueType: fmt_values[k] = int(v) elif "boolean" == valueType: fmt_values[k] = bool(v) else: fmt_values[k] = v if len(fmt_values) > 0: config_service.ConfigurationsController._validate_configuration(fmt_values, datastore_manager='mysql') config_models.KSC_Configuration.remove_all_items(context,id, utils.utcnow()) items = config_models.KSC_Configuration.get_items_by_overrides(context,id, fmt_values) config_models.KSC_Configuration.save(context, group, items, []) except exception as e: print(e)
def test_create_with_conf_override_trailing_slash(self): heat_url_from_conf = 'http://example.com/' tenant_from_ctx = uuid.uuid4().hex cfg.CONF.set_override('heat_url', heat_url_from_conf) client = remote.create_heat_client( TroveContext(tenant=tenant_from_ctx)) self.assertEqual('%s%s' % (heat_url_from_conf, tenant_from_ctx), client.http_client.endpoint)
def test_create_with_conf_override_trailing_slash(self): cinder_url_from_conf = 'http://example.com/' tenant_from_ctx = 'abc' cfg.CONF.set_override('cinder_url', cinder_url_from_conf) client = remote.create_cinder_client( TroveContext(tenant=tenant_from_ctx)) self.assertEqual('%s%s' % (cinder_url_from_conf, tenant_from_ctx), client.client.management_url)
def setUp(self): super(GuestAgentManagerTest, self).setUp() self.manager = mariadb_manager.Manager() self.context = TroveContext() patcher_rs = patch( 'trove.guestagent.strategies.replication.get_instance') patcher_rs.start() self.addCleanup(patcher_rs.stop)
def test_create_with_catalog_all_opts(self): cfg.CONF.set_override('swift_service_type', 'object-storev3', enforce_type=True) cfg.CONF.set_override('os_region_name', 'RegionTwo', enforce_type=True) client = remote.create_swift_client( TroveContext(service_catalog=self.service_catalog)) self.assertEqual(self.swiftv3_public_url_region_two, client.url)
def test_create_with_conf_override_trailing_slash(self): nova_url_from_conf = 'http://example.com/' tenant_from_ctx = uuid.uuid4().hex cfg.CONF.set_override('nova_compute_url', nova_url_from_conf) client = remote.create_nova_client( TroveContext(tenant=tenant_from_ctx)) self.assertEqual('%s%s' % (nova_url_from_conf, tenant_from_ctx), client.client.management_url)
def test_create_with_conf_override(self): cinder_url_from_conf = 'http://example.com' tenant_from_ctx = uuid.uuid4().hex cfg.CONF.set_override('cinder_url', cinder_url_from_conf) client = remote.create_cinder_client( TroveContext(tenant=tenant_from_ctx)) self.assertEqual('%s/%s' % (cinder_url_from_conf, tenant_from_ctx), client.client.management_url)
def setUp(self): super(ManagerTest, self).setUp() self.chmod_patch = patch.object(operating_system, 'chmod') self.chmod_mock = self.chmod_patch.start() self.addCleanup(self.chmod_patch.stop) self.manager = MockManager() self.context = TroveContext() self.log_name_sys = 'guest' self.log_name_user = '******' self.prefix = 'log_prefix' self.container = 'log_container' self.size = 1024 self.published = 128 self.guest_log_user = guest_log.GuestLog(self.context, self.log_name_user, guest_log.LogType.USER, None, '/tmp/gen.log', True) self.guest_log_sys = guest_log.GuestLog(self.context, self.log_name_sys, guest_log.LogType.SYS, None, '/tmp/guest.log', True) for gl in [self.guest_log_user, self.guest_log_sys]: gl._container_name = self.container gl._refresh_details = MagicMock() gl._log_rotated = MagicMock(return_value=False) gl._publish_to_container = MagicMock() gl._delete_log_components = MagicMock() gl._object_prefix = MagicMock(return_value=self.prefix) gl._size = self.size gl._published_size = self.published self.manager._guest_log_cache = { self.log_name_user: self.guest_log_user, self.log_name_sys: self.guest_log_sys } self.expected_details_user = { 'status': 'Disabled', 'prefix': self.prefix, 'container': self.container, 'name': self.log_name_user, 'published': self.published, 'metafile': self.prefix + '_metafile', 'type': 'USER', 'pending': self.size - self.published } self.expected_details_sys = dict(self.expected_details_user) self.expected_details_sys['type'] = 'SYS' self.expected_details_sys['status'] = 'Enabled' self.expected_details_sys['name'] = self.log_name_sys self.expected_module_details = { 'name': 'mymod', 'type': 'ping', 'contents': 'e262cfe36134' } self.manager.module_manager = Mock()
def test_create_with_conf_override(self): nova_url_from_conf = 'http://example.com' tenant_from_ctx = 'abc' cfg.CONF.set_override('nova_compute_url', nova_url_from_conf) client = remote.create_nova_client( TroveContext(tenant=tenant_from_ctx)) self.assertEqual('%s/%s' % (nova_url_from_conf, tenant_from_ctx), client.client.management_url)
def test_create_with_conf_override(self): heat_url_from_conf = 'http://example.com' tenant_from_ctx = 'abc' cfg.CONF.set_override('heat_url', heat_url_from_conf) client = remote.create_heat_client( TroveContext(tenant=tenant_from_ctx)) self.assertEqual('%s/%s' % (heat_url_from_conf, tenant_from_ctx), client.http_client.endpoint)
def test_create_with_catalog_all_opts(self): cfg.CONF.set_override('nova_compute_service_type', 'computev3', enforce_type=True) cfg.CONF.set_override('os_region_name', 'RegionTwo', enforce_type=True) client = remote.create_nova_client( TroveContext(service_catalog=self.service_catalog)) self.assertEqual(self.computev3_public_url_region_two, client.client.management_url)
def setUp(self): super(GuestAgentManagerTest, self).setUp() self.manager = galera_manager.GaleraManager( GaleraTestApp, mysql_service.BaseMySqlAppStatus, GaleraTestAdmin) self.context = TroveContext() patcher_rs = patch( 'trove.guestagent.strategies.replication.get_instance') patcher_rs.start() self.addCleanup(patcher_rs.stop)
def test_create_with_catalog_all_opts(self): cfg.CONF.set_override('heat_service_type', 'orchestrationv3', enforce_type=True) cfg.CONF.set_override('os_region_name', 'RegionTwo', enforce_type=True) client = remote.create_heat_client( TroveContext(service_catalog=self.service_catalog)) self.assertEqual(self.heatv3_public_url_region_two, client.http_client.endpoint)
def setUp(self): super(RedisGuestAgentManagerTest, self).setUp() self.context = TroveContext() self.manager = RedisManager() self.packages = 'redis-server' self.origin_RedisAppStatus = redis_service.RedisAppStatus self.origin_stop_redis = redis_service.RedisApp.stop_db self.origin_start_redis = redis_service.RedisApp.start_redis self.origin_install_redis = redis_service.RedisApp._install_redis
def test_create_with_conf_override(self): swift_url_from_conf = 'http://example.com/AUTH_' tenant_from_ctx = uuid.uuid4().hex cfg.CONF.set_override('swift_url', swift_url_from_conf) client = remote.create_swift_client( TroveContext(tenant=tenant_from_ctx)) self.assertEqual('%s%s' % (swift_url_from_conf, tenant_from_ctx), client.url)
def __init__(self): super(Manager, self).__init__(CONF) self.admin_context = TroveContext( user=CONF.nova_proxy_admin_user, auth_token=CONF.nova_proxy_admin_pass, tenant=CONF.nova_proxy_admin_tenant_id) if CONF.exists_notification_transformer: self.exists_transformer = importutils.import_object( CONF.exists_notification_transformer, context=self.admin_context)
def _send_msg_with_timeout(self): self.rabbit.declare_queue(topic_name()) context = TroveContext(is_admin=True, limit=5, marker=None) version = rpc.call(context, topic_name(), { "method": "version", "args": { "package_name": "dpkg" } }) return {"status": "good", "version": version}
def __init__(self): super(Manager, self).__init__(CONF) self.admin_context = TroveContext( user=CONF.service_credentials.username, tenant=CONF.service_credentials.project_id, user_domain_name=CONF.service_credentials.user_domain_name) if CONF.exists_notification_transformer: self.exists_transformer = importutils.import_object( CONF.exists_notification_transformer, context=self.admin_context)
def setUp(self): super(SwiftMetadataTests, self).setUp() self.swift_client = FakeSwiftConnection() self.context = TroveContext() self.create_swift_client_patch = patch.object( swift, 'create_swift_client', MagicMock(return_value=self.swift_client)) self.create_swift_client_mock = self.create_swift_client_patch.start() self.addCleanup(self.create_swift_client_patch.stop) self.swift = SwiftStorage(self.context)
def setUp(self): super(GuestAgentMongoDBManagerTest, self).setUp() self.context = TroveContext() self.manager = mongo_manager.Manager() self.origin_MongoDbAppStatus = mongo_service.MongoDbAppStatus self.origin_os_path_exists = os.path.exists self.origin_format = volume.VolumeDevice.format self.origin_migrate_data = volume.VolumeDevice.migrate_data self.origin_mount = volume.VolumeDevice.mount self.origin_stop_db = mongo_service.MongoDBApp.stop_db self.origin_start_db = mongo_service.MongoDBApp.start_db
def setUp(self): super(GuestAgentCouchbaseManagerTest, self).setUp() self.context = TroveContext() self.manager = couch_manager.Manager() self.packages = 'couchbase-server' self.origin_CouchbaseAppStatus = couch_service.CouchbaseAppStatus self.origin_format = volume.VolumeDevice.format self.origin_mount = volume.VolumeDevice.mount self.origin_stop_db = couch_service.CouchbaseApp.stop_db self.origin_start_db = couch_service.CouchbaseApp.start_db operating_system.get_ip_address = Mock()
def test_report_root_enabled(self): mock_db_api = mock() when(trove.extensions.mysql.models).get_db_api().thenReturn( mock_db_api) when(mock_db_api).find_by(any(), id=None).thenReturn(None) root_history = RootHistory('x', 'root') when(mock_db_api).save(any(RootHistory)).thenReturn(root_history) # invocation history = MySqlRootAccess.report_root_enabled(TroveContext()) # verification self.assertThat(history, Is(root_history)) verify(mock_db_api).save(any(RootHistory))
def setUp(self): super(GuestAgentManagerTest, self).setUp() self.manager = Manager() self.context = TroveContext() self.patcher_rs = patch( 'trove.guestagent.strategies.replication.get_instance') self.mock_rs_class = self.patcher_rs.start() status_patcher = patch.object(dbaas.PXCAppStatus, 'get', return_value=MagicMock()) self.addCleanup(status_patcher.stop) self.status_get_mock = status_patcher.start()
def setUp(self): super(GuestAgentManagerTest, self).setUp() self.context = TroveContext() self.manager = Manager() self.origin_MySqlAppStatus = dbaas.MySqlAppStatus self.origin_os_path_exists = os.path.exists self.origin_format = volume.VolumeDevice.format self.origin_migrate_data = volume.VolumeDevice.migrate_data self.origin_mount = volume.VolumeDevice.mount self.origin_is_installed = dbaas.MySqlApp.is_installed self.origin_stop_mysql = dbaas.MySqlApp.stop_db self.origin_start_mysql = dbaas.MySqlApp.start_mysql self.origin_install_mysql = dbaas.MySqlApp._install_mysql
def test_create_swift_client(self): mock_resp = MagicMock() with patch.object(swiftclient.client.Connection, 'get_container', MagicMock(return_value=["text", mock_resp])): service_catalog = [{'endpoints': [{'region': 'RegionOne', 'publicURL': 'example.com'}], 'type': 'object-store'}] client = remote.create_swift_client(TroveContext( tenant=uuid.uuid4().hex, service_catalog=service_catalog)) headers, container = client.get_container('bob') self.assertIs(headers, "text") self.assertIs(container, mock_resp)
def setUp(self): super(MockMgmtInstanceTest, self).setUp() self.context = TroveContext() self.context.auth_token = 'some_secret_password' self.client = MagicMock(spec=Client) self.server_mgr = MagicMock(spec=ServerManager) self.client.servers = self.server_mgr self.flavor_mgr = MagicMock(spec=FlavorManager) self.client.flavors = self.flavor_mgr remote.create_admin_nova_client = MagicMock(return_value=self.client) CONF.set_override('host', 'test_host') CONF.set_override('exists_notification_ticks', 1) CONF.set_override('report_interval', 20) CONF.set_override('notification_service_id', {'mysql': '123'})
def setUp(self): super(GuestAgentCouchbaseManagerTest, self).setUp() self.context = TroveContext() self.manager = couch_manager.Manager() self.packages = 'couchbase-server' self.origin_CouchbaseAppStatus = couch_service.CouchbaseAppStatus self.origin_format = volume.VolumeDevice.format self.origin_mount = volume.VolumeDevice.mount self.origin_mount_points = volume.VolumeDevice.mount_points self.origin_stop_db = couch_service.CouchbaseApp.stop_db self.origin_start_db = couch_service.CouchbaseApp.start_db self.origin_restart = couch_service.CouchbaseApp.restart self.origin_install_if = couch_service.CouchbaseApp.install_if_needed netutils.get_my_ipv4 = MagicMock()
def setUp(self): super(GuestAgentCouchbaseManagerTest, self).setUp() self.context = TroveContext() self.manager = couch_manager.Manager() self.packages = 'couchbase-server' app_patcher = patch.multiple( couch_service.CouchbaseApp, stop_db=DEFAULT, start_db=DEFAULT, restart=DEFAULT) self.addCleanup(app_patcher.stop) app_patcher.start() netutils_patcher = patch.object(netutils, 'get_my_ipv4') self.addCleanup(netutils_patcher.stop) netutils_patcher.start()
def _create_instance(self): self.context = TroveContext(is_admin=True) self.tenant_id = 999 self.db_info = DBInstance.create(name="instance", flavor_id=1, tenant_id=self.tenant_id, volume_size=None, service_type='mysql', task_status=InstanceTasks.NONE) self.server = self.mock.CreateMock(Server) self.instance = imodels.Instance(self.context, self.db_info, self.server, service_status="ACTIVE")
def setUp(self): super(GuestAgentMongoDBManagerTest, self).setUp() self.context = TroveContext() self.manager = mongo_manager.Manager() self.origin_MongoDbAppStatus = mongo_service.MongoDbAppStatus self.origin_os_path_exists = os.path.exists self.origin_format = volume.VolumeDevice.format self.origin_migrate_data = volume.VolumeDevice.migrate_data self.origin_mount = volume.VolumeDevice.mount self.origin_mount_points = volume.VolumeDevice.mount_points self.origin_stop_db = mongo_service.MongoDBApp.stop_db self.origin_start_db = mongo_service.MongoDBApp.start_db self.orig_exec_with_to = utils.execute_with_timeout self.orig_backup_restore = backup.restore
def test_create_admin_client(self): nova_url_from_conf = 'http://adminexample.com/' cfg.CONF.set_override('nova_compute_url', nova_url_from_conf) admin_user = '******' admin_pass = '******' admin_tenant_id = uuid.uuid4().hex admin_client = remote.create_admin_nova_client( TroveContext(user=admin_user, auth_token=admin_pass, tenant=admin_tenant_id)) # self.assertEqual(admin_user, admin_client.client.user) # self.assertEqual(admin_pass, admin_client.client.password) self.assertEqual('%s%s' % (nova_url_from_conf, admin_tenant_id), admin_client.client.endpoint_override)
def _deserialize_context(self, context): trace_info = context.pop("trace_info", None) if trace_info: profiler.init(**trace_info) return TroveContext.from_dict(context)