Skip to content
This repository has been archived by the owner on Feb 13, 2020. It is now read-only.

Commit

Permalink
Merge pull request #575 from gamechanger/js-assets-fixes
Browse files Browse the repository at this point in the history
better assets fix for non-running VM
  • Loading branch information
jsingle committed Sep 9, 2015
2 parents e5db5a0 + e55e473 commit fde59d9
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 9 deletions.
9 changes: 8 additions & 1 deletion dusty/commands/assets.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,14 @@
from prettytable import PrettyTable

from ..compiler.spec_assembler import get_specs, get_assembled_specs
from ..systems.virtualbox import asset_is_set, asset_value, asset_vm_path, remove_asset, initialize_docker_vm
from ..systems.virtualbox import (asset_is_set, asset_value, asset_vm_path, remove_asset,
initialize_docker_vm, docker_vm_is_running)
from ..systems.rsync import sync_local_path_to_vm
from ..log import log_to_client
from .. import constants

def list_by_app_or_lib(app_or_lib):
initialize_docker_vm()
spec = get_specs().get_app_or_lib(app_or_lib)
table = PrettyTable(["Asset", "Is Set", "Required", "In-Container Path"])
for asset in spec['assets']:
Expand All @@ -18,6 +21,8 @@ def _get_string_of_set(items):
return ', '.join(sorted(items))

def list_all():
initialize_docker_vm()
log_to_client('Listing assets used by active apps and libs')
table = PrettyTable(["Asset", "Is Set", "Used By", "Required By"])
assembled_specs = get_assembled_specs()
for asset_name, asset_info in assembled_specs['assets'].iteritems():
Expand All @@ -27,6 +32,7 @@ def list_all():
log_to_client(table.get_string())

def read_asset(asset_key):
initialize_docker_vm()
if not asset_is_set(asset_key):
log_to_client('Asset {} isn\'t set'.format(asset_key))
return
Expand All @@ -37,6 +43,7 @@ def set_asset(asset_key, local_path):
sync_local_path_to_vm(local_path, asset_vm_path(asset_key))

def unset_asset(asset_key):
initialize_docker_vm()
if not asset_is_set(asset_key):
log_to_client('Asset {} isn\'t set'.format(asset_key))
return
Expand Down
6 changes: 3 additions & 3 deletions dusty/commands/disk.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from ..log import log_to_client
from ..path import dir_modified_time, set_mac_user_ownership
from ..systems.docker.cleanup import remove_exited_dusty_containers, remove_images
from ..systems.virtualbox import get_docker_vm_disk_info, ensure_docker_vm_is_started
from ..systems.virtualbox import get_docker_vm_disk_info, ensure_docker_vm_is_started, initialize_docker_vm
from ..systems.rsync import sync_local_path_to_vm, sync_local_path_from_vm
from ..payload import daemon_command

Expand Down Expand Up @@ -41,7 +41,7 @@ def _ensure_backup_dir_exists(destination_path):
def backup(path):
destination_path = _full_destination_dir(path)
_ensure_backup_dir_exists(destination_path)
ensure_docker_vm_is_started()
initialize_docker_vm()
log_to_client("Syncing data from your VM to {}...".format(destination_path))
sync_local_path_from_vm(destination_path, constants.VM_PERSIST_DIR)
set_mac_user_ownership(destination_path)
Expand All @@ -51,6 +51,6 @@ def restore(source_path):
if not os.path.exists(source_path):
log_to_client("Can't find backup data to restore at {}".format(source_path))
return
ensure_docker_vm_is_started()
initialize_docker_vm()
log_to_client("Restoring your backup last modified at {}".format(dir_modified_time(source_path)))
sync_local_path_to_vm(source_path, constants.VM_PERSIST_DIR)
4 changes: 3 additions & 1 deletion dusty/commands/run.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,13 @@ def start_local_env(recreate_containers=True, pull_repos=True):
assembled_spec = spec_assembler.get_assembled_specs()
if not assembled_spec[constants.CONFIG_BUNDLES_KEY]:
raise RuntimeError('No bundles are activated. Use `dusty bundles` to activate bundles before running `dusty up`.')

virtualbox.initialize_docker_vm()

required_absent_assets = virtualbox.required_absent_assets(assembled_spec)
if required_absent_assets:
raise RuntimeError('Assets {} are specified as required but are not set. Set them with `dusty assets set`'.format(required_absent_assets))

virtualbox.initialize_docker_vm()
docker_ip = virtualbox.get_docker_vm_ip()

# Stop will fail if we've never written a Composefile before
Expand Down
4 changes: 3 additions & 1 deletion dusty/systems/virtualbox/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,9 @@ def _init_docker_vm():

def _start_docker_vm():
"""Start the Dusty VM if it is not already running."""
check_and_log_output_and_error_demoted(['docker-machine', 'start', constants.VM_MACHINE_NAME], quiet_on_success=True)
if not docker_vm_is_running():
logging.info('Starting docker-machine VM {}'.format(constants.VM_MACHINE_NAME))
check_and_log_output_and_error_demoted(['docker-machine', 'start', constants.VM_MACHINE_NAME], quiet_on_success=True)

def _stop_docker_vm():
"""Stop the Dusty VM if it is not already stopped."""
Expand Down
7 changes: 4 additions & 3 deletions tests/unit/commands/assets_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

from ...testcases import DustyTestCase

@patch('dusty.commands.assets.initialize_docker_vm')
@patch('dusty.commands.assets.asset_is_set')
class TestAssetsCommands(DustyTestCase):
def assertAppOrLibAssetListed(self, asset_name, path):
Expand All @@ -14,19 +15,19 @@ def assertAssetListed(self, asset_name, used_by, required_by):
self.assertTrue(any([asset_name in line and assets._get_string_of_set(used_by) in line and assets._get_string_of_set(required_by) in line
for line in self.last_client_output.splitlines()]))

def test_list_by_app(self, fake_asset_is_set):
def test_list_by_app(self, fake_asset_is_set, *args):
fake_asset_is_set.return_value = True
assets.list_by_app_or_lib('app-a')
self.assertAppOrLibAssetListed('required_asset', 'required_path')
self.assertAppOrLibAssetListed('optional_asset', 'optional_path')

def test_list_by_lib(self, fake_asset_is_set):
def test_list_by_lib(self, fake_asset_is_set, *args):
fake_asset_is_set.return_value = False
assets.list_by_app_or_lib('lib-a')
self.assertAppOrLibAssetListed('required_lib_asset', 'required_path')
self.assertAppOrLibAssetListed('optional_lib_asset', 'optional_path')

def test_list(self, fake_asset_is_set):
def test_list(self, fake_asset_is_set, *args):
fake_asset_is_set.return_value = True
bundles.activate_bundle(['bundle-a'])
assets.list_all()
Expand Down

0 comments on commit fde59d9

Please sign in to comment.