From 6cbc250f7454e3ad0c6dd57d61a14179fb2c3162 Mon Sep 17 00:00:00 2001 From: Jordan Singleton Date: Tue, 8 Sep 2015 17:20:33 -0400 Subject: [PATCH 1/3] better assets fix for non-running VM --- dusty/commands/assets.py | 9 ++++++++- dusty/commands/run.py | 4 +++- dusty/systems/virtualbox/__init__.py | 7 ++++++- 3 files changed, 17 insertions(+), 3 deletions(-) diff --git a/dusty/commands/assets.py b/dusty/commands/assets.py index ecfeebb6..05396481 100644 --- a/dusty/commands/assets.py +++ b/dusty/commands/assets.py @@ -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']: @@ -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(): @@ -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 @@ -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 diff --git a/dusty/commands/run.py b/dusty/commands/run.py index f782151c..984adaa8 100644 --- a/dusty/commands/run.py +++ b/dusty/commands/run.py @@ -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 diff --git a/dusty/systems/virtualbox/__init__.py b/dusty/systems/virtualbox/__init__.py index fad28866..4cf36ed0 100644 --- a/dusty/systems/virtualbox/__init__.py +++ b/dusty/systems/virtualbox/__init__.py @@ -64,9 +64,14 @@ def _init_docker_vm(): check_call_demoted(['docker-machine', 'create'] + machine_options + [constants.VM_MACHINE_NAME], redirect_stderr=True) +def _docker_vm_is_running(): + return check_output_demoted(['docker-machine', 'status', constants.VM_MACHINE_NAME]).rstrip() == 'Running' + 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.""" From 0212c62c3445be54ca2dc033298a817e392c03ba Mon Sep 17 00:00:00 2001 From: Jordan Singleton Date: Wed, 9 Sep 2015 15:11:28 -0400 Subject: [PATCH 2/3] initialize correctly on disk --- dusty/commands/disk.py | 6 +++--- dusty/systems/virtualbox/__init__.py | 5 +---- 2 files changed, 4 insertions(+), 7 deletions(-) diff --git a/dusty/commands/disk.py b/dusty/commands/disk.py index 8380889d..42caa59e 100644 --- a/dusty/commands/disk.py +++ b/dusty/commands/disk.py @@ -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 @@ -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) @@ -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) diff --git a/dusty/systems/virtualbox/__init__.py b/dusty/systems/virtualbox/__init__.py index 4cf36ed0..02bd5a23 100644 --- a/dusty/systems/virtualbox/__init__.py +++ b/dusty/systems/virtualbox/__init__.py @@ -64,12 +64,9 @@ def _init_docker_vm(): check_call_demoted(['docker-machine', 'create'] + machine_options + [constants.VM_MACHINE_NAME], redirect_stderr=True) -def _docker_vm_is_running(): - return check_output_demoted(['docker-machine', 'status', constants.VM_MACHINE_NAME]).rstrip() == 'Running' - def _start_docker_vm(): """Start the Dusty VM if it is not already running.""" - if not _docker_vm_is_running(): + 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) From e55e473f971990299895b3345ba85a8d36233343 Mon Sep 17 00:00:00 2001 From: Jordan Singleton Date: Wed, 9 Sep 2015 15:37:50 -0400 Subject: [PATCH 3/3] test fix --- tests/unit/commands/assets_test.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/tests/unit/commands/assets_test.py b/tests/unit/commands/assets_test.py index e695ce60..ff3f33c3 100644 --- a/tests/unit/commands/assets_test.py +++ b/tests/unit/commands/assets_test.py @@ -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): @@ -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()