Exemplo n.º 1
0
    def setUpClass(cls):
        '''
        '''
        # Create temp dir
        cls.image_build_rootdir = tempfile.mkdtemp(dir=TMP)
        # Generate image name
        cls.image = random_name(prefix='salt_busybox_')

        script_path = \
            os.path.join(FILES, 'file/base/mkimage-busybox-static')
        cmd = [script_path, cls.image_build_rootdir, cls.image]
        log.debug('Running \'%s\' to build busybox image', ' '.join(cmd))
        process = subprocess.Popen(cmd,
                                   close_fds=True,
                                   stdout=subprocess.PIPE,
                                   stderr=subprocess.STDOUT)
        output = process.communicate()[0]
        log.debug('Output from mkimge-busybox-static:\n%s', output)

        if process.returncode != 0:
            raise Exception('Failed to build image')

        try:
            salt.utils.files.rm_rf(cls.image_build_rootdir)
        except OSError as exc:
            if exc.errno != errno.ENOENT:
                raise
Exemplo n.º 2
0
    def setUpClass(cls):
        """
        """
        # Create temp dir
        cls.image_build_rootdir = tempfile.mkdtemp(dir=RUNTIME_VARS.TMP)
        # Generate image name
        cls.image = random_name(prefix="salt_busybox_")

        script_path = os.path.join(RUNTIME_VARS.BASE_FILES,
                                   "mkimage-busybox-static")
        cmd = [script_path, cls.image_build_rootdir, cls.image]
        log.debug("Running '%s' to build busybox image", " ".join(cmd))
        process = subprocess.Popen(cmd,
                                   close_fds=True,
                                   stdout=subprocess.PIPE,
                                   stderr=subprocess.STDOUT)
        output = process.communicate()[0]

        log.debug("Output from mkimge-busybox-static:\n%s", output)
        if process.returncode != 0:
            raise Exception(
                "Failed to build image. Output from mkimge-busybox-static:\n{}"
                .format(output))

        try:
            salt.utils.files.rm_rf(cls.image_build_rootdir)
        except OSError as exc:
            if exc.errno != errno.ENOENT:
                raise
Exemplo n.º 3
0
 def wrapper(self, *args, **kwargs):
     name = random_name(prefix='salt_test_')
     try:
         return func(self, name, *args, **kwargs)
     finally:
         try:
             self.run_function('docker.rm', [name], force=True)
         except CommandExecutionError as exc:
             if 'No such container' not in exc.__str__():
                 raise
Exemplo n.º 4
0
 def wrapper(self, *args, **kwargs):
     name = random_name(prefix="salt_net_")
     try:
         return func(self, name, *args, **kwargs)
     finally:
         self.run_function("docker.disconnect_all_containers_from_network", [name])
         try:
             self.run_function("docker.remove_network", [name])
         except CommandExecutionError as exc:
             if "No such network" not in exc.__str__():
                 raise
Exemplo n.º 5
0
    def wrapper(self, *args, **kwargs):
        try:
            self.run_function('docker.inspect_image', [IMAGE_NAME])
        except CommandExecutionError:
            pass
        else:
            build_image()

        name = random_name(prefix='salt_test_')
        self.run_function('docker.create',
                          name=name,
                          image=IMAGE_NAME,
                          command='sleep 600',
                          start=True)
        try:
            return func(self, name, *args, **kwargs)
        finally:
            try:
                self.run_function('docker.rm', [name], force=True)
            except CommandExecutionError as exc:
                if 'No such container' not in exc.__str__():
                    raise
Exemplo n.º 6
0
import salt.utils.files
import salt.utils.network
import salt.utils.path
from salt.exceptions import CommandExecutionError
from tests.support.case import ModuleCase
from tests.support.docker import random_name, with_network
from tests.support.helpers import destructiveTest, requires_system_grains, slowTest
from tests.support.mixins import SaltReturnAssertsMixin

# Import Salt Testing Libs
from tests.support.runtests import RUNTIME_VARS
from tests.support.unit import skipIf

log = logging.getLogger(__name__)

IMAGE_NAME = random_name(prefix="salt_busybox_")
IPV6_ENABLED = bool(salt.utils.network.ip_addrs6(include_loopback=True))


def network_name(func):
    """
    Generate a randomized name for a network and clean it up afterward
    """
    @functools.wraps(func)
    def wrapper(self, *args, **kwargs):
        name = random_name(prefix="salt_net_")
        try:
            return func(self, name, *args, **kwargs)
        finally:
            self.run_function("docker.disconnect_all_containers_from_network",
                              [name])
Exemplo n.º 7
0
from tests.support.case import ModuleCase
from tests.support.docker import with_network, random_name
from tests.support.paths import FILES, TMP
from tests.support.helpers import destructiveTest, requires_system_grains
from tests.support.mixins import SaltReturnAssertsMixin

# Import Salt Libs
import salt.utils.files
import salt.utils.network
import salt.utils.path
from salt.exceptions import CommandExecutionError

log = logging.getLogger(__name__)


IMAGE_NAME = random_name(prefix='salt_busybox_')
IPV6_ENABLED = bool(salt.utils.network.ip_addrs6(include_loopback=True))


def network_name(func):
    '''
    Generate a randomized name for a network and clean it up afterward
    '''
    @functools.wraps(func)
    def wrapper(self, *args, **kwargs):
        name = random_name(prefix='salt_net_')
        try:
            return func(self, name, *args, **kwargs)
        finally:
            self.run_function(
                'docker.disconnect_all_containers_from_network', [name])