diff --git a/.gitmodules b/.gitmodules index 7cc71821..0c168c12 100644 --- a/.gitmodules +++ b/.gitmodules @@ -1,3 +1,9 @@ [submodule "cont-postgresql"] path = postgresql/cont-postgresql url = https://github.com/devexp-db/cont-postgresql.git +[submodule "mysql/tests/steps/common_steps"] + path = mysql/tests/steps/common_steps + url = https://github.com/Containers-Testing-Framework/common-steps.git +[submodule "mysql/tests/features/common_features"] + path = mysql/tests/features/common_features + url = https://github.com/Containers-Testing-Framework/common-features.git diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 00000000..31aa2a8d --- /dev/null +++ b/.travis.yml @@ -0,0 +1,12 @@ +sudo: required +services: docker +language: python + +install: + - pip install behave ansible ctf-cli --upgrade + +before_script: +- cd mysql + +script: +- docker build -t fedora/mysql . && ctf-cli run -d IMAGE=fedora/mysql \ No newline at end of file diff --git a/mysql/Dockerfile b/mysql/Dockerfile index 83eaa38b..c6798332 100644 --- a/mysql/Dockerfile +++ b/mysql/Dockerfile @@ -1,4 +1,4 @@ -FROM fedora:20 +FROM fedora:latest MAINTAINER http://fedoraproject.org/wiki/Cloud RUN yum -y update && yum clean all diff --git a/mysql/ctf.conf b/mysql/ctf.conf new file mode 100644 index 00000000..00d9bdd9 --- /dev/null +++ b/mysql/ctf.conf @@ -0,0 +1,7 @@ +[ctf] +ExecType=ansible + +[ansible] +Host=192.168.1.1 +Method=local +User=root diff --git a/mysql/tests/environment.py b/mysql/tests/environment.py new file mode 100644 index 00000000..43407e9a --- /dev/null +++ b/mysql/tests/environment.py @@ -0,0 +1,11 @@ +from steps.common_steps.common_environment import docker_setup + + +def before_all(context): + docker_setup(context) + context.build_or_pull_image(skip_pull=True, skip_build=True) + context.mysql = {} + + +def after_scenario(context, scenario): + context.remove_container() diff --git a/mysql/tests/features/common_features b/mysql/tests/features/common_features new file mode 160000 index 00000000..10a7998b --- /dev/null +++ b/mysql/tests/features/common_features @@ -0,0 +1 @@ +Subproject commit 10a7998b970cac5a81b5e8b124365e968fc45326 diff --git a/mysql/tests/features/mysql.feature b/mysql/tests/features/mysql.feature new file mode 100644 index 00000000..aec7a44f --- /dev/null +++ b/mysql/tests/features/mysql.feature @@ -0,0 +1,23 @@ +Feature: MySQL connection + + Scenario: Root account - positive test + When mysql container is started + Then mysql connection with parameters can be established: + | param | value | + | MYSQL_USER | root | + | MYSQL_PASSWORD | mysqlPassword | + | MYSQL_DATABASE | testdb | + + Scenario Outline: Incorrect connection data for root account + When mysql container is started + Then mysql connection with parameters can not be established: + | param | value | + | MYSQL_USER | root | + | MYSQL_PASSWORD | | + | MYSQL_DATABASE | | + + Examples: + | password | db | + | mysqlPassword1 | testdb | + | mysqlPassword | testdb1 | + | ' | testdb | diff --git a/mysql/tests/steps/__init__.py b/mysql/tests/steps/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/mysql/tests/steps/common_steps b/mysql/tests/steps/common_steps new file mode 160000 index 00000000..6db5a318 --- /dev/null +++ b/mysql/tests/steps/common_steps @@ -0,0 +1 @@ +Subproject commit 6db5a31895ea5d8e039f48cc84b7c24da3839d61 diff --git a/mysql/tests/steps/steps.py b/mysql/tests/steps/steps.py new file mode 100644 index 00000000..c2a41d2c --- /dev/null +++ b/mysql/tests/steps/steps.py @@ -0,0 +1,41 @@ +# -*- coding: UTF-8 -*- +from behave import when, then, given +from time import sleep +from common_steps import common_docker_steps, common_connection_steps + + +@when(u'mysql container is started') +def mysql_container_is_started(context): + # Read mysql params from context var + context.execute_steps(u'* Docker container is started with params " --privileged=true --name=ctf"') + sleep(10) + + +@then(u'mysql connection can be established') +@then(u'mysql connection can {action:w} be established') +@then(u'mysql connection with parameters can be established') +@then(u'mysql connection with parameters can {action:w} be established') +def mysql_connect(context, action=False): + if context.table: + for row in context.table: + context.mysql[row['param']] = row['value'] + + user = context.mysql['MYSQL_USER'] + password = context.mysql['MYSQL_PASSWORD'] + db = context.mysql['MYSQL_DATABASE'] + + context.execute_steps(u'* port 3306 is open') + + for attempts in xrange(0, 5): + try: + context.run('docker run --rm -i --volumes-from=ctf %s mysql -u"%s" -p"%s" -e "SELECT 1;" %s' % ( + context.image, user, password, db)) + return + except AssertionError: + # If negative part was set, then we expect a bad code + # This enables steps like "can not be established" + if action != 'can': + return + sleep(5) + + raise Exception("Failed to connect to mysql")