2017-05-02 22:16:51 +00:00
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
'''
|
|
|
|
Integration tests for the docker_container states
|
|
|
|
'''
|
|
|
|
|
|
|
|
# Import Python Libs
|
|
|
|
from __future__ import absolute_import
|
|
|
|
import functools
|
|
|
|
import random
|
2017-05-02 22:31:38 +00:00
|
|
|
import string
|
2017-05-02 22:16:51 +00:00
|
|
|
import tempfile
|
|
|
|
|
|
|
|
# Import Salt Testing Libs
|
|
|
|
from tests.support.unit import skipIf
|
|
|
|
from tests.support.case import ModuleCase
|
|
|
|
from tests.support.paths import FILES, TMP
|
|
|
|
from tests.support.helpers import destructiveTest
|
|
|
|
from tests.support.mixins import SaltReturnAssertsMixin
|
|
|
|
|
2017-05-02 22:31:38 +00:00
|
|
|
# Import Salt Libs
|
|
|
|
import salt.utils
|
|
|
|
|
2017-05-02 22:16:51 +00:00
|
|
|
|
|
|
|
def _random_name(prefix=''):
|
|
|
|
ret = prefix
|
|
|
|
for _ in range(8):
|
|
|
|
ret += random.choice(string.ascii_lowercase)
|
|
|
|
return ret
|
|
|
|
|
|
|
|
|
|
|
|
def with_random_name(func):
|
|
|
|
'''
|
|
|
|
generate a randomized name for a container
|
|
|
|
'''
|
|
|
|
@functools.wraps(func)
|
|
|
|
def wrapper(self, *args, **kwargs):
|
|
|
|
name = _random_name(prefix='salt_')
|
|
|
|
return func(self, _random_name(prefix='salt_test_'), *args, **kwargs)
|
|
|
|
return wrapper
|
|
|
|
|
|
|
|
|
|
|
|
@destructiveTest
|
|
|
|
@skipIf(not salt.utils.which('dockerd'), 'Docker not installed')
|
|
|
|
class DockerCallTestCase(ModuleCase, SaltReturnAssertsMixin):
|
|
|
|
'''
|
|
|
|
Test docker_container states
|
|
|
|
'''
|
|
|
|
@with_random_name
|
|
|
|
def setUp(self, name):
|
|
|
|
'''
|
|
|
|
'''
|
|
|
|
# Create temp dir
|
|
|
|
self.random_name = name
|
|
|
|
tmp_build_dir= tempfile.mkdtemp(dir=TMP)
|
|
|
|
|
|
|
|
self.run_state('file.managed',
|
2017-05-02 22:31:38 +00:00
|
|
|
source='salt://docker_non_root/Dockerfile',
|
2017-05-02 22:16:51 +00:00
|
|
|
name='{0}/Dockerfile'.format(tmp_build_dir))
|
|
|
|
self.run_state('docker_image.present',
|
|
|
|
build=tmp_build_dir,
|
|
|
|
name=self.random_name)
|
|
|
|
self.run_state('docker_container.running',
|
|
|
|
name=self.random_name,
|
|
|
|
image=self.random_name)
|
|
|
|
|
|
|
|
def tearDown(self):
|
|
|
|
pass
|
|
|
|
|
|
|
|
def test_docker_call(self):
|
|
|
|
ret = self.run_function('docker.call', [self.random_name, 'test.ping'])
|
|
|
|
self.assertTrue(ret)
|