def test_run_scripts_from_metadata(self): scripts_dir = self.useFixture(TempDirectory()).path self.mock_run_scripts.return_value = 0 index_json = self.make_index_json(scripts_dir) mock_download_and_extract_tar = self.patch( maas_run_remote_scripts, 'download_and_extract_tar') mock_download_and_extract_tar.side_effect = ( self.mock_download_and_extract_tar) # Don't need to give the url, creds, or out_dir as we're not running # the scripts and sending the results. run_scripts_from_metadata(None, None, scripts_dir, None) self.assertThat( self.mock_run_scripts, MockAnyCall( None, None, scripts_dir, None, index_json['commissioning_scripts'], True)) self.assertThat( self.mock_run_scripts, MockAnyCall( None, None, scripts_dir, None, index_json['testing_scripts'], True)) self.assertThat(self.mock_signal, MockAnyCall(None, None, 'TESTING')) self.assertThat(mock_download_and_extract_tar, MockCalledOnceWith( 'None/maas-scripts/', None, scripts_dir))
def test_link_bootloader_copies_from_system(self): method = UEFIAMD64BootMethod() bootloader_dir = ('/var/lib/maas/boot-resources/%s' % factory.make_name('snapshot')) # Since the fall back looks for paths on the filesystem we need to # intercept the calls and make sure they were called with the right # arguments otherwise the test environment will interfere. allowed_src_files = [ '/usr/lib/shim/shim.efi.signed', '/usr/lib/grub/x86_64-efi-signed/grubnetx64.efi.signed', ] def fake_exists(path): if path in allowed_src_files: return True else: return False self.patch(uefi_amd64_module.os.path, 'exists').side_effect = (fake_exists) mock_atomic_symlink = self.patch(uefi_amd64_module, 'atomic_symlink') method._find_and_copy_bootloaders(bootloader_dir) self.assertThat( mock_atomic_symlink, MockAnyCall('/usr/lib/shim/shim.efi.signed', os.path.join(bootloader_dir, 'bootx64.efi'))) self.assertThat( mock_atomic_symlink, MockAnyCall( '/usr/lib/grub/x86_64-efi-signed/grubnetx64.efi.signed', os.path.join(bootloader_dir, 'grubx64.efi')))
def test_returns_mismatch_when_call_does_not_match(self): mock = Mock() mock(1, 2, a=5) matcher = MockAnyCall(1, 2, frob=5, nob=6) result = matcher.match(mock) self.assertMismatch(result, "call not found")
def test_link_bootloader_links_files_found_on_fs(self): method = PXEBootMethod() bootloader_dir = ('/var/lib/maas/boot-resources/snapshot-%s' % factory.make_name('snapshot')) def fake_exists(path): if '/usr/lib/syslinux/modules/bios' in path: return True else: return False self.patch(pxe_module.os.path, 'exists').side_effect = fake_exists mock_atomic_copy = self.patch(pxe_module, 'atomic_copy') mock_atomic_symlink = self.patch(pxe_module, 'atomic_symlink') mock_shutil_copy = self.patch(pxe_module.shutil, 'copy') method.link_bootloader(bootloader_dir) self.assertThat(mock_atomic_copy, MockNotCalled()) self.assertThat(mock_shutil_copy, MockNotCalled()) for bootloader_file in method.bootloader_files: bootloader_src = os.path.join('/usr/lib/syslinux/modules/bios', bootloader_file) bootloader_dst = os.path.join(bootloader_dir, bootloader_file) self.assertThat(mock_atomic_symlink, MockAnyCall(bootloader_src, bootloader_dst)) self.assertThat( mock_atomic_symlink, MockAnyCall('/usr/lib/syslinux/modules/bios', os.path.join(bootloader_dir, 'syslinux')))
def test_link_bootloader_links_files_found_on_fs(self): method = PXEBootMethod() bootloader_dir = ("/var/lib/maas/boot-resources/snapshot-%s" % factory.make_name("snapshot")) def fake_exists(path): if "/usr/lib/syslinux/modules/bios" in path: return True else: return False self.patch(pxe_module.os.path, "exists").side_effect = fake_exists mock_atomic_copy = self.patch(pxe_module, "atomic_copy") mock_atomic_symlink = self.patch(pxe_module, "atomic_symlink") mock_shutil_copy = self.patch(pxe_module.shutil, "copy") method.link_bootloader(bootloader_dir) self.assertThat(mock_atomic_copy, MockNotCalled()) self.assertThat(mock_shutil_copy, MockNotCalled()) for bootloader_file in method.bootloader_files: bootloader_src = os.path.join("/usr/lib/syslinux/modules/bios", bootloader_file) bootloader_dst = os.path.join(bootloader_dir, bootloader_file) self.assertThat( mock_atomic_symlink, MockAnyCall(bootloader_src, bootloader_dst), ) self.assertThat( mock_atomic_symlink, MockAnyCall( "/usr/lib/syslinux/modules/bios", os.path.join(bootloader_dir, "syslinux"), ), )
def test_run_scripts_from_metadata_redownloads_after_commiss(self): scripts_dir = self.useFixture(TempDirectory()).path self.mock_run_scripts.return_value = 0 testing_scripts = make_scripts() testing_scripts[0]['parameters'] = {'storage': {'type': 'storage'}} mock_download_and_extract_tar = self.patch( maas_run_remote_scripts, 'download_and_extract_tar') simple_dl_and_extract = lambda *args, **kwargs: self.make_index_json( scripts_dir, with_commissioning=False, testing_scripts=testing_scripts) mock_download_and_extract_tar.side_effect = simple_dl_and_extract index_json = self.make_index_json( scripts_dir, testing_scripts=testing_scripts) # Don't need to give the url, creds, or out_dir as we're not running # the scripts and sending the results. run_scripts_from_metadata(None, None, scripts_dir, None) self.assertThat( self.mock_run_scripts, MockAnyCall( None, None, scripts_dir, None, index_json['commissioning_scripts'], True)) self.assertThat(self.mock_signal, MockAnyCall(None, None, 'TESTING')) self.assertThat( mock_download_and_extract_tar, MockCalledOnceWith('None/maas-scripts/', None, scripts_dir)) self.assertThat( self.mock_run_scripts, MockAnyCall( None, None, scripts_dir, None, index_json['testing_scripts'], True))
def test_enable_lan_channel_if_disabled(self): """Test that Lan_Channel gets enabled if it is disabled""" # Mock the response of the BMC response = ("Section Lan_Channel\n" " Volatile_Access_Mode Disabled\n" " Non_Volatile_Access_Mode Disabled\n" "EndSection") self.patch(maas_ipmi_autodetect, "bmc_get").return_value = response # Mock the function 'bmc_set' bmc_set_mock = self.patch(maas_ipmi_autodetect, "bmc_set") # Call the function set_ipmi_lan_channel_settings() # Check that the 'bmc_set_mock' was called self.assertThat( bmc_set_mock, MockAnyCall("Lan_Channel:Volatile_Access_Mode", "Always_Available"), ) self.assertThat( bmc_set_mock, MockAnyCall("Lan_Channel:Non_Volatile_Access_Mode", "Always_Available"), )
def test_returns_none_when_matches(self): mock = Mock() mock(1, 2, frob=5, nob=6) matcher = MockAnyCall(1, 2, frob=5, nob=6) result = matcher.match(mock) self.assertIsNone(result)
def test_install_dependencies_snap_str_dict(self): mock_run_and_check = self.patch( maas_run_remote_scripts, 'run_and_check') scripts_dir = self.useFixture(TempDirectory()).path scripts = make_scripts(scripts_dir=scripts_dir, with_output=False) packages = [ {'name': factory.make_name('pkg')}, { 'name': factory.make_name('pkg'), 'channel': random.choice([ 'edge', 'beta', 'candidate', 'stable']), }, { 'name': factory.make_name('pkg'), 'channel': random.choice([ 'edge', 'beta', 'candidate', 'stable']), 'mode': random.choice(['dev', 'jail']), }, { 'name': factory.make_name('pkg'), 'channel': random.choice([ 'edge', 'beta', 'candidate', 'stable']), 'mode': random.choice(['dev', 'jail']), }, ] for script in scripts: script['packages'] = {'snap': packages} self.assertTrue(install_dependencies(scripts)) for script in scripts: self.assertThat(self.mock_output_and_send, MockAnyCall( 'Installing snap packages for %s' % script['msg_name'], True, status='INSTALLING')) # Verify cleanup self.assertFalse(os.path.exists(script['combined_path'])) self.assertFalse(os.path.exists(script['stdout_path'])) self.assertFalse(os.path.exists(script['stderr_path'])) self.assertThat(mock_run_and_check, MockAnyCall( ['snap', 'install', packages[0]['name']], scripts, True, True)) self.assertThat(mock_run_and_check, MockAnyCall( [ 'snap', 'install', packages[1]['name'], '--%s' % packages[1]['channel'] ], scripts, True, True)) self.assertThat(mock_run_and_check, MockAnyCall( [ 'snap', 'install', packages[2]['name'], '--%s' % packages[2]['channel'], '--%smode' % packages[2]['mode'], ], scripts, True, True)) self.assertThat(mock_run_and_check, MockAnyCall( [ 'snap', 'install', packages[3]['name'], '--%s' % packages[3]['channel'], '--%smode' % packages[3]['mode'], ], scripts, True, True))
def test_validate_hwe_kern_always_sets_kern_with_commissionable_os(self): self.patch(BootResource.objects, 'get_usable_hwe_kernels').return_value = ('hwe-t', 'hwe-v') mock_get_config = self.patch(Config.objects, "get_config") mock_get_config.return_value = 'trusty' kernel = validate_hwe_kernel(None, 'hwe-v', '%s/generic' % factory.make_name('arch'), factory.make_name("osystem"), factory.make_name("distro")) self.assertThat(mock_get_config, MockAnyCall('commissioning_osystem')) self.assertThat(mock_get_config, MockAnyCall('commissioning_distro_series')) self.assertEqual('hwe-v', kernel)
def test_stopService_calls_unregister_for_all_watching(self): processId = random.randint(0, 100) watching = {random.randint(0, 100) for _ in range(3)} listener = Mock() service = RackControllerService(sentinel.ipcWorker, listener) service.processId = processId service.watching = watching yield service.stopService() self.assertThat( listener.unregister, MockAnyCall("sys_core_%d" % processId, service.coreHandler)) for watch_id in watching: self.assertThat( listener.unregister, MockAnyCall("sys_dhcp_%d" % watch_id, service.dhcpHandler))
def test__mounts_and_unmounts_image(self): image = make_image_name() self.patch(uec2roottar, 'check_call') mountpoint = factory.make_name('mount') calls_before = len(uec2roottar.check_call.mock_calls) with uec2roottar.loop_mount(image, mountpoint): calls_during = len(uec2roottar.check_call.mock_calls) calls_after = len(uec2roottar.check_call.mock_calls) self.assertEqual((0, 1, 2), (calls_before, calls_during, calls_after)) self.assertThat(uec2roottar.check_call, MockAnyCall(['mount', '-o', 'ro', image, mountpoint])) self.assertThat(uec2roottar.check_call, MockAnyCall(['umount', mountpoint]))
def test_refresh_executes_lxd_binary_in_snap(self): signal = self.patch(refresh, "signal") script_name = LXD_OUTPUT_NAME info_scripts = self.create_scripts_success(script_name) path = factory.make_name() self.patch(os, "environ", {"SNAP": path}) system_id = factory.make_name("system_id") consumer_key = factory.make_name("consumer_key") token_key = factory.make_name("token_key") token_secret = factory.make_name("token_secret") url = factory.make_url() with patch.dict(refresh.NODE_INFO_SCRIPTS, info_scripts, clear=True): refresh.refresh( system_id, consumer_key, token_key, token_secret, url ) self.assertThat( signal, MockAnyCall( "%s/metadata/%s/" % (url, MD_VERSION), { "consumer_secret": "", "consumer_key": consumer_key, "token_key": token_key, "token_secret": token_secret, }, "WORKING", "Starting %s [1/1]" % script_name, ), )
def test_run_and_check_errors(self): scripts_dir = self.useFixture(TempDirectory()).path scripts = make_scripts(scripts_dir=scripts_dir, with_output=False) script = scripts[0] self.assertFalse(run_and_check( ['/bin/bash', '-c', 'echo %s;echo %s >&2;false' % ( script['stdout'], script['stderr'])], scripts)) self.assertEquals( '%s\n' % script['stdout'], open(script['stdout_path'], 'r').read()) self.assertEquals( '%s\n' % script['stderr'], open(script['stderr_path'], 'r').read()) self.assertEquals( '%s\n%s\n' % (script['stdout'], script['stderr']), open(script['combined_path'], 'r').read()) for script in scripts: self.assertThat( self.mock_output_and_send, MockAnyCall( 'Failed installing package(s) for %s' % script['msg_name'], exit_status=1, status='INSTALLING', files={ scripts[0]['combined_name']: ('%s\n%s\n' % ( scripts[0]['stdout'], scripts[0]['stderr'])).encode(), scripts[0]['stdout_name']: ( '%s\n' % scripts[0]['stdout']).encode(), scripts[0]['stderr_name']: ( '%s\n' % scripts[0]['stderr']).encode(), }))
def test_refresh_executes_lxd_binary(self): signal = self.patch(refresh, "signal") script_name = LXD_OUTPUT_NAME self.patch_scripts_success(script_name) system_id = factory.make_name("system_id") consumer_key = factory.make_name("consumer_key") token_key = factory.make_name("token_key") token_secret = factory.make_name("token_secret") url = factory.make_url() refresh.refresh(system_id, consumer_key, token_key, token_secret, url) self.assertThat( signal, MockAnyCall( "%s/metadata/%s/" % (url, MD_VERSION), { "consumer_secret": "", "consumer_key": consumer_key, "token_key": token_key, "token_secret": token_secret, }, "WORKING", "Starting %s [1/1]" % script_name, ), )
def test_refresh_executes_lxd_binary_in_snap(self): signal = self.patch(refresh, 'signal') script_name = LXD_OUTPUT_NAME self.patch_scripts_success(script_name) path = factory.make_name() self.patch(os, "environ", { "SNAP": path }) system_id = factory.make_name('system_id') consumer_key = factory.make_name('consumer_key') token_key = factory.make_name('token_key') token_secret = factory.make_name('token_secret') url = factory.make_url() refresh.refresh( system_id, consumer_key, token_key, token_secret, url) self.assertThat(signal, MockAnyCall( "%s/metadata/%s/" % (url, MD_VERSION), { 'consumer_secret': '', 'consumer_key': consumer_key, 'token_key': token_key, 'token_secret': token_secret, }, 'WORKING', 'Starting %s [1/1]' % script_name, ))
def test_warns_if_no_boot_resources_found(self): # The import code used to crash when no resources were found in the # Simplestreams repositories (bug 1305758). This could happen easily # with mistakes in the sources. Now, you just get a logged warning. sources_fixture = self.useFixture( BootSourcesFixture([{ "url": self.make_dir(), "keyring": factory.make_name("keyring"), "selections": [{ "release": factory.make_name("release") }], }])) self.patch(boot_resources, "download_all_image_descriptions") boot_resources.download_all_image_descriptions.return_value = ( BootImageMapping()) self.patch_maaslog() self.patch(boot_resources, "RepoWriter") args = self.make_args(sources_file=sources_fixture.filename) boot_resources.main(args) self.assertThat( boot_resources.maaslog.warning, MockAnyCall( "Finished importing boot images, the region does not have " "any boot images available."), )
def test_validate_hwe_kern_always_sets_kern_with_commissionable_os(self): self.patch(BootResource.objects, "get_usable_hwe_kernels").return_value = ("hwe-t", "hwe-v") mock_get_config = self.patch(Config.objects, "get_config") mock_get_config.return_value = "trusty" kernel = validate_hwe_kernel( None, "hwe-v", "%s/generic" % factory.make_name("arch"), factory.make_name("osystem"), factory.make_name("distro"), ) self.assertThat(mock_get_config, MockAnyCall("commissioning_osystem")) self.assertThat(mock_get_config, MockAnyCall("commissioning_distro_series")) self.assertEqual("hwe-v", kernel)
def test_geturl_raises_exception_on_failure(self): sleep = self.patch(maas_api_helper.time, 'sleep') warn = self.patch(maas_api_helper, 'warn') self.assertRaises(urllib.error.HTTPError, maas_api_helper.geturl, "http://%s-broken" % factory.make_hostname(), {}) self.assertEquals(7, sleep.call_count) self.assertThat(warn, MockAnyCall('date field not in 400 headers'))
def test_refresh_signals_failure(self): signal = self.patch(refresh, "signal") self.patch_scripts_failure() system_id = factory.make_name("system_id") consumer_key = factory.make_name("consumer_key") token_key = factory.make_name("token_key") token_secret = factory.make_name("token_secret") url = factory.make_url() refresh.refresh(system_id, consumer_key, token_key, token_secret, url) self.assertThat( signal, MockAnyCall( "%s/metadata/%s/" % (url, MD_VERSION), { "consumer_secret": "", "consumer_key": consumer_key, "token_key": token_key, "token_secret": token_secret, }, "FAILED", "Failed refreshing %s" % system_id, ), )
def test_refresh_signals_starting(self): signal = self.patch(refresh, "signal") script_name = factory.make_name("script_name") info_scripts = self.create_scripts_success(script_name) system_id = factory.make_name("system_id") consumer_key = factory.make_name("consumer_key") token_key = factory.make_name("token_key") token_secret = factory.make_name("token_secret") url = factory.make_url() with patch.dict(refresh.NODE_INFO_SCRIPTS, info_scripts, clear=True): refresh.refresh( system_id, consumer_key, token_key, token_secret, url ) self.assertThat( signal, MockAnyCall( "%s/metadata/%s/" % (url, MD_VERSION), { "consumer_secret": "", "consumer_key": consumer_key, "token_key": token_key, "token_secret": token_secret, }, "WORKING", "Starting %s [1/1]" % script_name, ), )
def test_refresh_signals_failure(self): signal = self.patch(refresh, "signal") info_scripts = self.create_scripts_failure() system_id = factory.make_name("system_id") consumer_key = factory.make_name("consumer_key") token_key = factory.make_name("token_key") token_secret = factory.make_name("token_secret") url = factory.make_url() with patch.dict(refresh.NODE_INFO_SCRIPTS, info_scripts, clear=True): refresh.refresh( system_id, consumer_key, token_key, token_secret, url ) self.assertThat( signal, MockAnyCall( "%s/metadata/%s/" % (url, MD_VERSION), { "consumer_secret": "", "consumer_key": consumer_key, "token_key": token_key, "token_secret": token_secret, }, "FAILED", "Failed refreshing %s" % system_id, ), )
def test_refresh_signals_failure_on_unexecutable_script_baderrno(self): signal = self.patch(refresh, "signal") script_name = factory.make_name("script_name") self.patch_scripts_failure(script_name) mock_popen = self.patch(refresh, "Popen") mock_popen.side_effect = OSError(0, "Exec format error") system_id = factory.make_name("system_id") consumer_key = factory.make_name("consumer_key") token_key = factory.make_name("token_key") token_secret = factory.make_name("token_secret") url = factory.make_url() refresh.refresh(system_id, consumer_key, token_key, token_secret, url) self.assertThat( signal, MockAnyCall( "%s/metadata/%s/" % (url, MD_VERSION), { "consumer_secret": "", "consumer_key": consumer_key, "token_key": token_key, "token_secret": token_secret, }, "WORKING", files={ script_name: b"[Errno 0] Exec format error", "%s.err" % script_name: b"[Errno 0] Exec format error", }, exit_status=2, error="Failed to execute %s [1/1]: 2" % script_name, ), )
def test_refresh_signals_finished(self): signal = self.patch(refresh, 'signal') script_name = factory.make_name('script_name') self.patch_scripts_success(script_name) system_id = factory.make_name('system_id') consumer_key = factory.make_name('consumer_key') token_key = factory.make_name('token_key') token_secret = factory.make_name('token_secret') url = factory.make_url() refresh.refresh(system_id, consumer_key, token_key, token_secret, url) self.assertThat( signal, MockAnyCall( "%s/metadata/%s/" % (url, MD_VERSION), { 'consumer_secret': '', 'consumer_key': consumer_key, 'token_key': token_key, 'token_secret': token_secret, }, 'OK', "Finished refreshing %s" % system_id, ))
def test_refresh_signals_failure_on_unexecutable_script_baderrno(self): signal = self.patch(refresh, "signal") script_name = factory.make_name("script_name") info_scripts = self.create_scripts_failure(script_name) mock_popen = self.patch(refresh, "Popen") mock_popen.side_effect = OSError(0, "Exec format error") system_id = factory.make_name("system_id") consumer_key = factory.make_name("consumer_key") token_key = factory.make_name("token_key") token_secret = factory.make_name("token_secret") url = factory.make_url() with patch.dict(refresh.NODE_INFO_SCRIPTS, info_scripts, clear=True): refresh.refresh(system_id, consumer_key, token_key, token_secret, url) self.assertThat( signal, MockAnyCall( ANY, ANY, "WORKING", files={ script_name: b"[Errno 0] Exec format error", "%s.err" % script_name: b"[Errno 0] Exec format error", }, exit_status=2, error="Failed to execute %s [1/1]: 2" % script_name, ), )
def test_refresh_signals_failure_on_timeout(self): signal = self.patch(refresh, 'signal') script_name = factory.make_name('script_name') timeout = timedelta(seconds=random.randint(1, 500)) self.patch_scripts_failure(script_name, timeout) self.patch(refresh.maas_api_helper, 'timedelta').return_value = (timedelta(microseconds=1)) system_id = factory.make_name('system_id') consumer_key = factory.make_name('consumer_key') token_key = factory.make_name('token_key') token_secret = factory.make_name('token_secret') url = factory.make_url() refresh.refresh(system_id, consumer_key, token_key, token_secret, url) self.assertThat( signal, MockAnyCall( "%s/metadata/%s/" % (url, MD_VERSION), { 'consumer_secret': '', 'consumer_key': consumer_key, 'token_key': token_key, 'token_secret': token_secret, }, 'TIMEDOUT', files={ script_name: b'test failed\n', '%s.out' % script_name: b'test failed\n', '%s.err' % script_name: b'', }, error='Timeout(%s) expired on %s [1/1]' % (str(timeout), script_name), ))
def test_refresh_signals_failure_on_unexecutable_script_baderrno(self): signal = self.patch(refresh, 'signal') script_name = factory.make_name('script_name') self.patch_scripts_failure(script_name) mock_popen = self.patch(refresh, 'Popen') mock_popen.side_effect = OSError(0, 'Exec format error') system_id = factory.make_name('system_id') consumer_key = factory.make_name('consumer_key') token_key = factory.make_name('token_key') token_secret = factory.make_name('token_secret') url = factory.make_url() refresh.refresh(system_id, consumer_key, token_key, token_secret, url) self.assertThat( signal, MockAnyCall( "%s/metadata/%s/" % (url, MD_VERSION), { 'consumer_secret': '', 'consumer_key': consumer_key, 'token_key': token_key, 'token_secret': token_secret, }, 'WORKING', files={ script_name: b'[Errno 0] Exec format error', '%s.err' % script_name: b'[Errno 0] Exec format error', }, exit_status=2, error='Failed to execute %s [1/1]: 2' % script_name, ))
def test_refresh_signals_results(self): signal = self.patch(refresh, 'signal') script_name = factory.make_name('script_name') self.patch_scripts_success(script_name) system_id = factory.make_name('system_id') consumer_key = factory.make_name('consumer_key') token_key = factory.make_name('token_key') token_secret = factory.make_name('token_secret') url = factory.make_url() refresh.refresh(system_id, consumer_key, token_key, token_secret, url) self.assertThat( signal, MockAnyCall( "%s/metadata/%s/" % (url, MD_VERSION), { 'consumer_secret': '', 'consumer_key': consumer_key, 'token_key': token_key, 'token_secret': token_secret, }, 'WORKING', files={ script_name: b'test script\n', '%s.out' % script_name: b'test script\n', '%s.err' % script_name: b'', }, exit_status=0, error='Finished %s [1/1]: 0' % script_name, ))
def test_refresh_accepts_defined_url(self): signal = self.patch(refresh, 'signal') script_name = factory.make_name('script_name') self.patch_scripts_success(script_name) system_id = factory.make_name('system_id') consumer_key = factory.make_name('consumer_key') token_key = factory.make_name('token_key') token_secret = factory.make_name('token_secret') url = factory.make_url() refresh.refresh(system_id, consumer_key, token_key, token_secret, url) self.assertThat( signal, MockAnyCall( "%s/metadata/%s/" % (url, MD_VERSION), { 'consumer_secret': '', 'consumer_key': consumer_key, 'token_key': token_key, 'token_secret': token_secret, }, 'WORKING', 'Starting %s [1/1]' % script_name, ))
def test_install_dependencies_url_deb(self): mock_run_and_check = self.patch( maas_run_remote_scripts, 'run_and_check') scripts_dir = self.useFixture(TempDirectory()).path scripts = make_scripts(scripts_dir=scripts_dir, with_output=False) deb_file = os.path.join(scripts[0]['download_path'], 'file.deb') open(deb_file, 'w').close() with open(scripts[0]['combined_path'], 'w') as output: output.write("Saving to: '%s'" % deb_file) for script in scripts: script['packages'] = {'url': [deb_file]} self.assertTrue(install_dependencies(scripts)) self.assertThat(mock_run_and_check, MockAnyCall( ['dpkg', '-i', deb_file], scripts, False, True)) self.assertThat(mock_run_and_check, MockAnyCall( ['apt-get', 'install', '-qyf'], scripts, True, True))