Merge pull request #28 from thelittlefireman/master

fix file error when start/stop/start container
This commit is contained in:
Budi Utomo 2017-08-01 16:16:12 +02:00 committed by GitHub
commit c9ab42ecfb
3 changed files with 28 additions and 3 deletions

View file

@ -4,6 +4,7 @@ import json
import logging
import os
import subprocess
import errno
from src import CONFIG_FILE, ROOT, CHROME_DRIVER
from src import log
@ -11,6 +12,13 @@ from src import log
log.init()
logger = logging.getLogger('app')
def symlink_force(target, link_name):
try:
os.symlink(target, link_name)
except OSError as e:
if e.errno == errno.EEXIST:
os.remove(link_name)
os.symlink(target, link_name)
def get_or_raise(env: str) -> str:
"""
@ -71,7 +79,7 @@ def prepare_avd(device: str, avd_name: str):
skin_dst_path = os.path.join(ANDROID_HOME, 'platforms', 'android-{api}'.format(api=API_LEVEL), 'skins')
logger.info('Skin destination path: {dst}'.format(dst=skin_dst_path))
for s in os.listdir(skin_rsc_path):
os.symlink(os.path.join(skin_rsc_path, s), os.path.join(skin_dst_path, s))
symlink_force(os.path.join(skin_rsc_path, s), os.path.join(skin_dst_path, s))
# Hardware and its skin
device_name_bash = device.replace(' ', '\ ')
@ -85,7 +93,7 @@ def prepare_avd(device: str, avd_name: str):
profile_src_path = os.path.join(ROOT, 'devices', 'profiles', '{profile}.xml'.format(profile=skin_name))
logger.info('Hardware profile resource path: {rsc}'.format(rsc=profile_src_path))
logger.info('Hardware profile destination path: {dst}'.format(dst=profile_dst_path))
os.symlink(profile_src_path, profile_dst_path)
symlink_force(profile_src_path, profile_dst_path)
# Append command
cmd += ' -d {device} -s {skin}'.format(device=device_name_bash, skin=skin_name)

View file

@ -10,6 +10,23 @@ from src import app
class TestApp(TestCase):
"""Unit test class to test other methods in the app."""
#create symlink
@classmethod
def test_symlink_correct(self):
os.mknod(os.path.join("./","testFile1.txt"))
app.symlink_force(os.path.join("./","testFile1.txt"),os.path.join("./","link_testFile1.txt"))
os.remove(os.path.join("./","testFile1.txt"))
os.remove(os.path.join("./","link_testFile1.txt"))
#link already exist
@classmethod
def test_symlink_already_exist(self):
os.mknod(os.path.join("./","testFile2.txt"))
os.mknod(os.path.join("./","link_testFile2.txt"))
app.symlink_force(os.path.join("./","testFile2.txt"),os.path.join("./","link_testFile2.txt"))
os.remove(os.path.join("./","testFile2.txt"))
os.remove(os.path.join("./","link_testFile2.txt"))
def test_valid_env(self):
key = 'ENV_1'
os.environ[key] = 'test'

View file

@ -5,7 +5,7 @@ childlogdir=%(ENV_LOG_PATH)s
priority=1
[program:xvfb]
command=/usr/bin/Xvfb %(ENV_DISPLAY)s -screen %(ENV_SCREEN)s %(ENV_SCREEN_WIDTH)sx%(ENV_SCREEN_HEIGHT)sx%(ENV_SCREEN_DEPTH)s
command=rm -r /tmp/ && /usr/bin/Xvfb %(ENV_DISPLAY)s -screen %(ENV_SCREEN)s %(ENV_SCREEN_WIDTH)sx%(ENV_SCREEN_HEIGHT)sx%(ENV_SCREEN_DEPTH)s
stdout_logfile=%(ENV_LOG_PATH)s/xvfb.stdout.log
stderr_logfile=%(ENV_LOG_PATH)s/xvfb.stderr.log
priority=1