symfony4: how do I configure dataFixture to write in test db - unit-testing

I want to load the testdata for my unit tests into the test db via DataFixtures.
The documentation says, that if I set the environment variable the test db should be used:
$ php bin/console doctrine:fixtures:load --env=test
Careful, database will be purged. Do you want to continue y/N ?y
> purging database
> loading App\DataFixtures\PropertyFixtures
> loading App\DataFixtures\UserFixtures
> loading App\DataFixtures\UserPropertyFixtures
However if I check the data end up in my default database.
Where do I configure my test db with symfony 4?
And where do I configure it, so that DataFixtures knows where to write?
For my functional tests I configured the db setting in the phpunit.xml

What we did to solve it was the following. I don't know if that is a good way, so alternative solutions are still appreciated.
in ../config/packages there is the file doctrine.yaml
I copied the file in the folder ./config/packages/test and edited it in the following way:
parameters:
# Adds a fallback DATABASE_URL if the env var is not set.
# This allows you to run cache:warmup even if your
# environment variables are not available yet.
# You should not need to change this value.
env(DATABASE_URL): ''
doctrine:
dbal:
# configure these for your database server
driver: 'pdo_mysql'
server_version: '5.7'
charset: utf8
default_table_options:
charset: utf8
collate: utf8_unicode_ci
url: mysql://%db_user_test%:%db_password_test%#%db_host_test%:%db_port_test%/%db_name_test%
orm:
auto_generate_proxy_classes: '%kernel.debug%'
naming_strategy: doctrine.orm.naming_strategy.underscore
auto_mapping: true
mappings:
App:
is_bundle: false
type: annotation
dir: '%kernel.project_dir%/src/Entity'
prefix: 'App\Entity'
So what I changed was the like with the url: mysql....
In my parameters I had added the parameters db_user_test etc and used them to connect to the test db.
It works, but still I am not sure if this is how it should be done.

Related

Redmine don't send e-mail, execution expired error

I'm having problems using email in redmine. This is my redmine Environment versions:
Environment:
Redmine version 2.4.2.stable
Ruby version 1.9.3-p484 (2013-11-22) [x86_64-linux]
Rails version 3.2.16
Environment production
Database adapter MySQL
SCM:
Git 1.9.1
Filesystem
Redmine plugins:
no plugin installed
I configured the configuration.yml file like this:
production:
email_delivery:
delivery_method: :smtp
smtp_settings:
enable_starttls_auto: true
address: "smtp.office365.com"
port: 587
domain: "mydomain.com.br"
authentication: :login
user_name: "user#mydomain.com.br"
password: "mypassword"
attachments_storage_path: /home/redmin/Downloads/redmine-2.3.2/files
autologin_cookie_name:
autologin_cookie_path:
autologin_cookie_secure:
scm_subversion_command: svn
scm_mercurial_command:
scm_git_command: /usr/bin/git
scm_cvs_command:
scm_bazaar_command:
scm_darcs_command:
scm_stderr_log_file:
database_cipher_key:
rmagick_font_path:
So, i access redmine in browser and click in button "Send Test Email" but i got the following error: execution expired after a lot of time loading page.
In my production.log file i got a success message without any error, but e-mail never arrive:
Sent email "Redmine test" (30215ms)
to: target#gmail.com
Edit 1:
If i change the devlivery_method to ":sendmail" the test works but email never arrives.

Symfony 4 doctrine yaml mappng

I use yaml mapping
And when I try php bin/console doctrine:generate:entities App --no-backup, I get the error
Can't find base path for "App\Entity\User"
doctrine.yaml:
doctrine:
dbal:
# configure these for your database server
driver: 'pdo_mysql'
server_version: '5.7'
charset: utf8mb4
# With Symfony 3.3, remove the `resolve:` prefix
url: '%env(resolve:DATABASE_URL)%'
orm:
auto_generate_proxy_classes: '%kernel.debug%'
naming_strategy: doctrine.orm.naming_strategy.underscore
auto_mapping: true
mappings:
App:
is_bundle: false
type: 'yml'
dir: '%kernel.project_dir%/config/doctrine'
prefix: 'App\Entity'
alias: 'App'
Sample User.orm.yml:
App\Entity\User:
type: entity
table: tbl_user
repositoryClass: App\Entity\UserRepository
fields:
username:
type: string
length: 40
nullable: true
password:
type: string
length: 40
nullable: true
This command is provided by the sensio/generator-bundle, which is not compatible with Symfony 4, and will never be.
On the readme file, they advice to use the MakeBundle instead.
But it seems there no equivalent for the generate:entities command. In most of IDE (I'm using PhpStorm), there is helper to generate getter and setter.

how can I confing Config.yaml in elasticalert?

I am completely new in usung of Elastcalert. I am trying to use Elasticalert for striking email when no log is sent to logstash from my client server. I have successfully installed Elastcalert on my master server. However, when I run elastalert-create-index I get following error:
Traceback (most recent call last):
File "/usr/bin/elastalert-create-index", line 11, in <module>
load_entry_point('elastalert==0.1.21', 'console_scripts', 'elastalert-
create-index')()
File "/usr/lib/python2.7/site-packages/elastalert-0.1.21-
py2.7.egg/elastalert/create_index.py", line 77, in main
username = args.username if args.username else data.get('es_username')
UnboundLocalError: local variable 'data' referenced before assignment
My config.yaml is as follow:
# This is the folder that contains the rule yaml files
# Any .yaml file will be loaded as a rule
rules_folder: example_rules
# How often ElastAlert will query Elasticsearch
# The unit can be anything from weeks to seconds
run_every:
minutes: 1
# ElastAlert will buffer results from the most recent
# period of time, in case some log sources are not in real time
buffer_time:
minutes: 15
# The Elasticsearch hostname for metadata writeback
# Note that every rule can have its own Elasticsearch host
es_host: localhost
# The Elasticsearch port
es_port: 9200
# The AWS region to use. Set this when using AWS-managed elasticsearch
#aws_region: us-east-1
# The AWS profile to use. Use this if you are using an aws-cli profile.
# See http://docs.aws.amazon.com/cli/latest/userguide/cli-chap-getting-
started.html
# for details
#profile: test
# Optional URL prefix for Elasticsearch
#es_url_prefix: elasticsearch
# Connect with TLS to Elasticsearch
#use_ssl: True
# Verify TLS certificates
#verify_certs: True
# GET request with body is the default option for Elasticsearch.
# If it fails for some reason, you can pass 'GET', 'POST' or 'source'.
# See http://elasticsearch-py.readthedocs.io/en/master/connection.html?
highlight=send_get_body_as#transport
# for details
#es_send_get_body_as: GET
# Option basic-auth username and password for Elasticsearch
#es_username:
#es_password:
# Use SSL authentication with client certificates client_cert must be
# a pem file containing both cert and key for client
#verify_certs: True
#ca_certs: /path/to/cacert.pem
#client_cert: /path/to/client_cert.pem
#client_key: /path/to/client_key.key
# The index on es_host which is used for metadata storage
# This can be a unmapped index, but it is recommended that you run
# elastalert-create-index to set a mapping
writeback_index: elastalert_status
# If an alert fails for some reason, ElastAlert will retry
# sending the alert until this time period has elapsed
alert_time_limit:
days: 2
Did you try running elastalert-create-index without any arguments? It guides you through the setup process like this:
$>elastalert-create-index
Enter Elasticsearch host: localhost
Enter Elasticsearch port: 9200
Use SSL? t/f: f
Enter optional basic-auth username (or leave blank):
Enter optional basic-auth password (or leave blank):
Enter optional Elasticsearch URL prefix (prepends a string to the URL of every request):
New index name? (Default elastalert_status)
Name of existing index to copy? (Default None)
Elastic Version:6
Mapping used for string:{'type': 'keyword'}
New index elastalert_status created
Done!

Unable to execute bash scripts from heat template

I am new to heat templates and I am trying to run bash scripts from the heat template. However, the instance is coming up in active state but the shell script was not executed at all. Any suggestions will be highly appreciated.
Hope this is helpful for you.
parameters: DBRootPassword:
type: string
label: Database Password
description: Root password for MySQL
hidden: true
resources: my_instance:
type: OS::Nova::Server
properties:
# general properties ...
user_data:
str_replace:
template: |
#!/bin/bash
echo "Hello world"
echo "Setting MySQL root password"
mysqladmin -u root password $db_rootpassword
# do more things ...
params:
$db_rootpassword: { get_param: DBRootPassword }

Octopus gem is sending 2 SQL queries for every ActiveRecord query

Currently I have a "State" model and following config details in shards.yml.
I am checking the following in "development" environment.
octopus:
environments:
- development
- staging
- production
replicated: true
fully_replicated: true
development:
slave1:
host: 192.168.5.130
adapter: mysql2
database: mydb
username: user
password: Password
reconnect: false
staging:
slave1:
host: 192.168.1.2
adapter: mysql2
database: server_db
username: admin
password: fake_staging_password
reconnect: false
production:
slave1:
host: 192.168.1.5
adapter: mysql2
database: production_db_name
username: admin
password: fake_production_password
reconnect: true
When ever I issue State.all or any active record query, I see the same SQL statment is sent to server 2 times
For example State.count sends the following SQL two times.
[Shard: slave1] (1.5ms) SELECT COUNT(*) FROM `states`
[Shard: slave1] (2.1ms) SELECT COUNT(*) FROM `states`
=> 35
Is this normal? or I have any issue in settings?
I think you're supposed to place either replicated: true or fully_replicated: true
Not both.