def _add_defaults(app, amqp_manager, script_config): """Add default tenant, admin user and provider context to the DB """ # Add the default network to the provider context context = script_config['provider_context'] networks = context['cloudify']['cloudify_agent']['networks'] networks['default'] = script_config['ip'] provider_context = models.ProviderContext(id=PROVIDER_CONTEXT_ID, name=PROVIDER_NAME, context=context) db.session.add(provider_context) default_tenant = create_default_user_tenant_and_roles( admin_username=script_config['username'], admin_password=script_config['password'], amqp_manager=amqp_manager, authorization_file_path=script_config['config']['authorization']) create_status_reporter_user_and_assign_role(MANAGER_STATUS_REPORTER, 'password', MANAGER_STATUS_REPORTER, MANAGER_STATUS_REPORTER_ID) for scope, configs in script_config['manager_config'].items(): for name, value in configs.items(): item = (db.session.query(models.Config).filter_by(scope=scope, name=name).one()) item.value = value db.session.add(item) db.session.commit() app.config[CURRENT_TENANT_CONFIG] = default_tenant return default_tenant
def _handle_default_db_config(): Migrate(app=server.app, db=server.db) try: upgrade(directory=MIGRATION_DIR) except sqlalchemy.exc.OperationalError: logger = logging.getLogger() logger.error("Could not connect to the database - is a " "postgresql server running on localhost?") logger.error("HINT: Create a docker container running postgresql " "by doing `docker run --name cloudify-db-unit-test " "-e POSTGRES_PASSWORD=cloudify -e POSTGRES_USER="******"cloudify -e POSTGRES_DB=cloudify_db -p 5432:5432 " "-d postgres`") raise admin_user = get_admin_user() fd, temp_auth_file = tempfile.mkstemp() os.close(fd) with open(temp_auth_file, 'w') as f: yaml.dump(auth_dict, f) try: # We're mocking the AMQPManager, we aren't really using Rabbit here default_tenant = create_default_user_tenant_and_roles( admin_username=admin_user['username'], admin_password=admin_user['password'], amqp_manager=MagicMock(), authorization_file_path=temp_auth_file ) default_tenant.rabbitmq_username = \ 'rabbitmq_username_default_tenant' default_tenant.rabbitmq_vhost = \ 'rabbitmq_vhost_defualt_tenant' default_tenant.rabbitmq_password = \ 'gAAAAABb9p7U_Lnlmg7vyijjoxovyg215ThYi-VCTCzVYa1p-vpzi31WGko' \ 'KD_hK1mQyKgjRss_Nz-3m-cgHpZChnVT4bxZIjnOnL6sF8RtozvlRoGHtnF' \ 'G6jxqQDeEf5Heos0ia4Q5H ' for reporter in get_status_reporters(): create_status_reporter_user_and_assign_role( reporter['username'], reporter['password'], reporter['role'], reporter['id'] ) if premium_enabled: # License is required only when working with Cloudify Premium upload_mock_cloudify_license(get_storage_manager()) finally: os.remove(temp_auth_file) utils.set_current_tenant(default_tenant)
def _add_db_status_reporter_user(): logger.info('Creating the DB Status Reporter user, default tenant and ' 'security roles') user = storage_utils.create_status_reporter_user_and_assign_role( script_config['db_status_reporter_username'], script_config['db_status_reporter_password'], script_config['db_status_reporter_role'], script_config['db_status_reporter_user_id']) RETURN_DICT['db_status_reporter_token'] = user.api_token