Fixed the broken MySQL job
* Moved `created_at` and `updated_at` to MistralModelBase to generate a default value without microseconds * Increased time delay in scheduler tests. This change doesn't affect a test duration * Removed the PostgreSQL database generation commands because there already are in the `tools/test-setup.sh` script * Downloaded the python MySQL driver Change-Id: I50c924ee94619c6622fc553f05a929607646f1fe Signed-off-by: Vitalii Solodilov <mcdkr@yandex.ru>
This commit is contained in:
@@ -33,6 +33,9 @@ def id_column():
|
||||
class _MistralModelBase(oslo_models.ModelBase, oslo_models.TimestampMixin):
|
||||
"""Base class for all Mistral SQLAlchemy DB Models."""
|
||||
|
||||
created_at = sa.Column(sa.DateTime, default=lambda: utils.utc_now_sec())
|
||||
updated_at = sa.Column(sa.DateTime, onupdate=lambda: utils.utc_now_sec())
|
||||
|
||||
__table__ = None
|
||||
|
||||
__hash__ = object.__hash__
|
||||
@@ -134,8 +137,6 @@ class MistralSecureModelBase(MistralModelBase):
|
||||
|
||||
scope = sa.Column(sa.String(80), default='private')
|
||||
project_id = sa.Column(sa.String(80), default=security.get_project_id)
|
||||
created_at = sa.Column(sa.DateTime, default=lambda: utils.utc_now_sec())
|
||||
updated_at = sa.Column(sa.DateTime, onupdate=lambda: utils.utc_now_sec())
|
||||
|
||||
|
||||
def _set_project_id(target, value, oldvalue, initiator):
|
||||
|
@@ -26,6 +26,7 @@ from mistral.db.v2.sqlalchemy import models as db_models
|
||||
from mistral import exceptions as exc
|
||||
from mistral.services import security
|
||||
from mistral.tests.unit import base as test_base
|
||||
from mistral import utils
|
||||
from mistral.utils import filter_utils
|
||||
|
||||
|
||||
@@ -397,7 +398,7 @@ CRON_TRIGGER = {
|
||||
'workflow_id': None,
|
||||
'workflow_input': {},
|
||||
'next_execution_time':
|
||||
datetime.datetime.now() + datetime.timedelta(days=1),
|
||||
datetime.datetime.now() + datetime.timedelta(days=1),
|
||||
'remaining_executions': 42,
|
||||
'scope': 'private',
|
||||
'project_id': '<default-project>'
|
||||
@@ -2197,7 +2198,8 @@ CRON_TRIGGERS = [
|
||||
'workflow_id': None,
|
||||
'workflow_input': {},
|
||||
'next_execution_time':
|
||||
datetime.datetime.now() + datetime.timedelta(days=1),
|
||||
utils.drop_microseconds(
|
||||
datetime.datetime.now() + datetime.timedelta(days=1)),
|
||||
'remaining_executions': 42,
|
||||
'scope': 'private',
|
||||
'project_id': '<default-project>'
|
||||
@@ -2210,7 +2212,8 @@ CRON_TRIGGERS = [
|
||||
'workflow_id': None,
|
||||
'workflow_input': {'param': 'val'},
|
||||
'next_execution_time':
|
||||
datetime.datetime.now() + datetime.timedelta(days=1),
|
||||
utils.drop_microseconds(
|
||||
datetime.datetime.now() + datetime.timedelta(days=1)),
|
||||
'remaining_executions': 42,
|
||||
'scope': 'private',
|
||||
'project_id': '<default-project>'
|
||||
|
@@ -22,11 +22,12 @@ from mistral.services import expiration_policy
|
||||
from mistral.services.expiration_policy import ExecutionExpirationPolicy
|
||||
from mistral.tests.unit import base
|
||||
from mistral.tests.unit.base import get_context
|
||||
from mistral import utils
|
||||
from oslo_config import cfg
|
||||
|
||||
|
||||
def _create_workflow_executions():
|
||||
time_now = datetime.datetime.utcnow()
|
||||
time_now = utils.utc_now_sec()
|
||||
|
||||
wf_execs = [
|
||||
{
|
||||
|
@@ -32,7 +32,7 @@ TARGET_METHOD_PATH = (
|
||||
DELAY = 1.5
|
||||
|
||||
|
||||
def get_time_delay(delay=DELAY):
|
||||
def get_time_delay(delay=DELAY * 2):
|
||||
return datetime.datetime.now() + datetime.timedelta(seconds=delay)
|
||||
|
||||
|
||||
|
@@ -494,7 +494,12 @@ def generate_key_pair(key_length=2048):
|
||||
def utc_now_sec():
|
||||
"""Returns current time and drops microseconds."""
|
||||
|
||||
return timeutils.utcnow().replace(microsecond=0)
|
||||
return drop_microseconds(timeutils.utcnow())
|
||||
|
||||
|
||||
def drop_microseconds(date):
|
||||
"""Drops microseconds and returns date."""
|
||||
return date.replace(microsecond=0)
|
||||
|
||||
|
||||
def datetime_to_str(val, sep=' '):
|
||||
|
50
run_tests.sh
50
run_tests.sh
@@ -123,50 +123,24 @@ function setup_db {
|
||||
sqlite )
|
||||
rm -f tests.sqlite
|
||||
;;
|
||||
postgresql )
|
||||
echo "Setting up Mistral DB in PostgreSQL"
|
||||
|
||||
# If CI_PROJECT is specified it means that this script is executing on
|
||||
# Jenkins gate, so we should use already created postgresql db
|
||||
if [ -n "$CI_PROJECT"]
|
||||
then
|
||||
echo "PostgreSQL is initialized. 'openstack_citest' db will be used."
|
||||
dbname="openstack_citest"
|
||||
username="openstack_citest"
|
||||
password="openstack_citest"
|
||||
else
|
||||
# Create the user and database.
|
||||
# Assume trust is setup on localhost in the postgresql config file.
|
||||
dbname="mistral"
|
||||
username="mistral"
|
||||
password="m1stral"
|
||||
|
||||
pg_command "SELECT pg_terminate_backend(pg_stat_activity.pid)
|
||||
FROM pg_stat_activity
|
||||
WHERE pg_stat_activity.datname = '$dbname'
|
||||
AND pid <> pg_backend_pid();"
|
||||
pg_command "DROP DATABASE IF EXISTS $dbname;"
|
||||
pg_command "DROP USER IF EXISTS $username;"
|
||||
pg_command "CREATE USER $username
|
||||
WITH ENCRYPTED PASSWORD '$password';"
|
||||
pg_command "CREATE DATABASE $dbname OWNER $username;"
|
||||
fi
|
||||
"postgresql" | "mysql" )
|
||||
dbname="openstack_citest"
|
||||
username="openstack_citest"
|
||||
password="openstack_citest"
|
||||
;;
|
||||
esac
|
||||
}
|
||||
|
||||
function pg_command {
|
||||
command=$1
|
||||
|
||||
sudo -u postgres psql -h localhost -c "${command}"
|
||||
}
|
||||
|
||||
function setup_db_pylib {
|
||||
case ${db_type} in
|
||||
postgresql )
|
||||
echo "Installing python library for PostgreSQL."
|
||||
${wrapper} pip install psycopg2
|
||||
;;
|
||||
mysql )
|
||||
echo "Installing python library for MySQL"
|
||||
${wrapper} pip install mysql-python
|
||||
;;
|
||||
esac
|
||||
}
|
||||
|
||||
@@ -175,9 +149,11 @@ function setup_db_cfg {
|
||||
sqlite )
|
||||
rm -f .mistral.conf
|
||||
;;
|
||||
postgresql )
|
||||
oslo-config-generator --config-file ./tools/config/config-generator.mistral.conf --output-file .mistral.conf
|
||||
sed -i "s/#connection = <None>/connection = postgresql:\/\/$username:$password@localhost\/$dbname/g" .mistral.conf
|
||||
"postgresql" | "mysql" )
|
||||
oslo-config-generator --config-file \
|
||||
./tools/config/config-generator.mistral.conf \
|
||||
--output-file .mistral.conf
|
||||
sed -i "s/#connection = <None>/connection = $db_type:\/\/$username:$password@localhost\/$dbname/g" .mistral.conf
|
||||
;;
|
||||
esac
|
||||
}
|
||||
|
Reference in New Issue
Block a user