Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Atomic storage test #98

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion features/rhelah/atomic/atomic_mount.feature
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ Background: Atomic hosts are discovered
@run_rhel7_in_bg
Scenario: 6. docker run rhel7 with detach mode
When docker run "registry.access.redhat.com/rhel7" in detach mode with "mount_test" "top -b"
Then find latest created container by name "mount_test"
Then find latest created container by "mount_test"

@mount_container_without_option
Scenario: 7. mount running container by name to a specified directory
Expand Down
6 changes: 3 additions & 3 deletions features/rhelah/atomic/atomic_scanner.feature
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#@atomic @host_subscribed @ah_upgrade
@atomic @host_subscribed @ah_upgrade
Feature: Atomic scanner test
Describes the basic 'atomic scan' command test

Expand Down Expand Up @@ -73,12 +73,12 @@ Background: Atomic hosts are discovered
@run_container1_in_bg
Scenario: 13. docker run container1 with detach mode
When docker run "centos" in detach mode with "C1" "top -b"
Then find latest created container by name "C1"
Then find latest created container by "C1"

@run_container2_in_bg
Scenario: 14. docker run container2 with detach mode
When docker run "rhel7" in detach mode with "C2" "top -b"
Then find latest created container by name "C2"
Then find latest created container by "C2"

@scan_containers
Scenario: 15. scan containers
Expand Down
117 changes: 117 additions & 0 deletions features/rhelah/atomic/atomic_storage.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
@atomic @host_subscribed @ah_upgrade
Feature: Atomic storage sanity test
Describes the basic 'atomic storage' command test

Background: Atomic hosts are discovered
Given "all" hosts can be pinged

@pull_busybox_image
Scenario: 1. Pull latest busybox image from repository
When atomic update latest "busybox" from repository
Then check whether "busybox" is installed

@pull_rhel7_image
Scenario: 2. Pull latest rhel7 image from repository
When atomic update latest "registry.access.redhat.com/rhel7" from repository
Then check whether "rhel7" is installed

@run_busybox_in_bg
Scenario: 3. docker run busybox with detach mode
When docker run "busybox" in detach mode with "storage_test" "top -b"
Then find latest created container by "storage_test"

@export_storage_into_default_directory
Scenario: 4. export all the current images, volumes, and containers into default directory
When export containers and associated contents into default directory

@export_storage_into_specified_directory_1
Scenario: 5. export all the current images, volumes, and containers into specified directory
When export containers and associated contents into "/tmp/atomic_storage_export_1"

@export_storage_into_specified_directory_2
Scenario: 6. export all the current images, volumes, and containers into specified directory
When export containers and associated contents into "/tmp/atomic_storage_export_2"

@stop_docker_service_1
Scenario: 7 stop docker service
When run command "service name=docker state=stopped" on "all"

@reset_storage_1
Scenario: 8. reset storage to its initial configuration
When reset storage to its initial configuration

@start_docker_service_1
Scenario: 9. start docker service
When run command "service name=docker state=started" on "all"

@import_storage_from_default_directory
Scenario: 10. import images, volumes, and containers from the default directory
When import containers and associated contents from default directory

@restart_docker_service_1
Scenario: 11. restart docker service and find previously imported container
When run command "service name=docker state=restarted" on "all"
Then check image "busybox" have been imported
and check image "registry.access.redhat.com/rhel7" have been imported
and find latest created container by "storage_test"
and find latest created container by "top -b"

@stop_docker_service_2
Scenario: 12. stop docker service
When run command "service name=docker state=stopped" on "all"

@reset_storage_2
Scenario: 13. reset storage to its initial configuration
When reset storage to its initial configuration

@start_docker_service_2
Scenario: 14. start docker service
When run command "service name=docker state=started" on "all"

@import_storage_from_specified_directory_1
Scenario: 15. import images, volumes, and containers from the specified directory
When import containers and associated contents from "/tmp/atomic_storage_export_1"

@restart_docker_service_1
Scenario: 16. restart docker service and find previously imported container
When run command "service name=docker state=restarted" on "all"
Then check image "busybox" have been imported
and check image "registry.access.redhat.com/rhel7" have been imported
and find latest created container by "storage_test"
and find latest created container by "top -b"

@stop_docker_service_3
Scenario: 17. stop docker service
When run command "service name=docker state=stopped" on "all"

@reset_storage_3
Scenario: 18. reset storage to its initial configuration
When reset storage to its initial configuration

@start_docker_service_3
Scenario: 19. start docker service
When run command "service name=docker state=started" on "all"

@import_storage_from_specified_directory_2
Scenario: 20. import images, volumes, and containers from the specified directory
When import containers and associated contents from "/tmp/atomic_storage_export_2"

@restart_docker_service_1
Scenario: 21. restart docker service and find previously imported container
When run command "service name=docker state=restarted" on "all"
Then check image "busybox" have been imported
and check image "registry.access.redhat.com/rhel7" have been imported
and find latest created container by "storage_test"
and find latest created container by "top -b"

@stop_docker_service_2
Scenario: 22. stop docker service
When run command "service name=docker state=stopped" on "all"

@reset_storage_2
Scenario: 23. reset storage to its initial configuration
When reset storage to its initial configuration

@start_docker_service_2
Scenario: 24. start docker service
When run command "service name=docker state=started" on "all"
2 changes: 1 addition & 1 deletion features/rhelah/atomic/sanity_test.feature
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ Background: Atomic hosts are discovered
@run_container_in_bg
Scenario: 5. docker run centos with detach mode
When docker run "centos" in detach mode with "mount_test" "top -b"
Then find latest created container by name "mount_test"
Then find latest created container by "mount_test"

@mount_container_to_path
Scenario: 6. mount running container by name to a specified directory
Expand Down
29 changes: 20 additions & 9 deletions steps/docker.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,13 @@
from common import string_to_bool


def get_running_container_id(context):
'''get running container id'''
def get_containers_id(context, state="active"):
'''get running containers id'''
cmd = "docker ps"
if state == "inactive":
cmd += " -a"
container_result = context.remote_cmd(cmd='command',
module_args='docker ps')
module_args=cmd)

assert container_result, "Error running 'docker ps'"

Expand All @@ -30,6 +33,13 @@ def get_running_container_id(context):

return container_id

def get_container_id_by_name(context, name):
'''get container id by name'''
container_id = context.remote_cmd(cmd='command',
module_args='docker ps -aq -f name=%s' % name)
assert not container_id is False, context.result['contacted']
return container_id[0]['stdout']

def get_images_id(context):
'''get images id'''
images_result = context.remote_cmd(cmd='command',
Expand Down Expand Up @@ -65,7 +75,7 @@ def step_impl(context, rpm, image, host):
@when('docker stop container')
def step_impl(context):
'''docker stop container'''
container_id = get_running_container_id(context)
container_id = get_containers_id(context)
assert container_id, "There is not a running container"
assert context.remote_cmd('command',
module_args='docker stop %s' % container_id)
Expand All @@ -88,7 +98,7 @@ def step_impl(context, image, command, ignore_rc="false", bg="true", name="", op
if option:
options += option
options += ' ' + image + ' ' + command
module_args='docker run %s' % options
module_args = 'docker run %s' % options
context.docker_run_result = context.remote_cmd('command',
ignore_rc=ignore_rc,
module_args=module_args)
Expand All @@ -97,14 +107,14 @@ def step_impl(context, image, command, ignore_rc="false", bg="true", name="", op
@then('check whether there is a running container')
def step_impl(context):
'''check whether container is running'''
container_id = get_running_container_id(context)
container_id = get_containers_id(context)
assert container_id, "There is not a running container"

@then('find latest created container by name "{name}"')
@then('find latest created container by "{condition}"')
def step_impl(context, name):
'''find latest created container by name'''
'''find latest created container by condition'''
assert context.remote_cmd('shell',
module_args='docker ps -l | grep %s' % name)
module_args='docker ps -al | grep %s' % condition)

@then('check if "{matches}" is in result of docker run')
def step_impl(context, matches):
Expand Down Expand Up @@ -150,3 +160,4 @@ def step_impl(context):
'''Remove all of containers'''
assert context.remote_cmd('shell',
module_args='docker ps -a -q | xargs -r docker rm')

47 changes: 45 additions & 2 deletions steps/rhelah.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@
import filecmp
from behave import *
from distutils.version import LooseVersion
from docker import get_image_id_by_name, get_running_container_id, string_to_bool
from docker import get_image_id_by_name, get_containers_id
from docker import string_to_bool, get_container_id_by_name
from ostree import get_ostree_admin_status


Expand All @@ -20,6 +21,7 @@ def get_atomic_version(context):

return atomic_version


def get_atomic_status(context):
status_result = context.remote_cmd(cmd='command',
module_args='atomic host status')
Expand Down Expand Up @@ -476,7 +478,7 @@ def step_impl(context, name=None):
if name is not None:
container = name
else:
container = get_running_container_id(context)
container = get_containers_id(context)
assert container, "No running container"
assert context.remote_cmd('command',
module_args='atomic stop %s' % container)
Expand Down Expand Up @@ -810,3 +812,44 @@ def step_impl(context, target_file="/usr/unlock_test"):
mkfile = context.remote_cmd('file',
module_args='path=%s state=touch' % target_file)
assert mkfile, "Failed to create %s" % target_file

@when(u'export containers and associated contents into "{path}"')
@when(u'export containers and running docker at a custom location "{graph}"')
@when(u'export containers and associated contents into default directory')
@when(u'from custom running docker location "{graph}" exporting containers and associated contents into "{path}"')
def step_impl(context, path="/var/lib/atomic/migrate", graph="/var/lib/docker"):
'''Export containers and associated contents into a filesystem directory'''
options = ""
options += "--dir %s --graph %s" % (path, graph)
assert context.remote_cmd(cmd='command',
module_args='atomic storage export %s' % options)

@when(u'import containers and associated contents from "{path}"')
@when(u'import containers and running docker at a custom location "{graph}"')
@when(u'import containers and associated contents from default directory')
@when(u'from custom running docker location "{graph}" and "{path}" importing containers and associated contents')
def step_impl(context, path="/var/lib/atomic/migrate", graph="/var/lib/docker"):
'''Import containers and associated contents from a filesystem directory'''
options = ""
options += "--dir %s --graph %s" % (path, graph)
assert context.remote_cmd(cmd='shell',
module_args="atomic -y storage import %s" % options)

@then(u'check image "{image}" have been imported')
def step_impl(context, image):
'''Check if image is imported'''
context.execute_steps(u"""
Then check whether "{image}" is installed
""".format(image=image))

@then(u'check container "{container}" have been imported')
def step_impl(context, container, path="/var/lib/atomic/migrate"):
'''Check if container is imported'''
container_id = get_container_id_by_name(context, container)
assert container_id, "Error can't find container: %s" % container

@when(u'reset storage to its initial configuration')
def step_impl(context):
'''Reset storage to its initial configuration'''
assert context.remote_cmd(cmd='command',
module_args='atomic storage reset')