def _publish_isos(self, repo, config, progress_callback=None): """ Extracts the necessary configuration information for the ISO creator and then calls it. :param repo: metadata describing the repository :type repo: pulp.plugins.model.Repository :param config: plugin configuration instance :type config: pulp.plugins.config.PluginCallConfiguration :param progress_callback: callback to report progress info to publish_conduit. This function is expected to take the following arguments: type_id, a string, and status, which is a dict :type progress_callback: function """ http_publish_dir = os.path.join(constants.EXPORT_HTTP_DIR, repo.id).rstrip('/') https_publish_dir = os.path.join(constants.EXPORT_HTTPS_DIR, repo.id).rstrip('/') image_prefix = config.get(constants.ISO_PREFIX_KEYWORD) or repo.id # Clean up the old export publish directories. shutil.rmtree(http_publish_dir, ignore_errors=True) shutil.rmtree(https_publish_dir, ignore_errors=True) # If publishing isn't enabled for http or https, set the path to None if not config.get(constants.PUBLISH_HTTP_KEYWORD): http_publish_dir = None if not config.get(constants.PUBLISH_HTTPS_KEYWORD): https_publish_dir = None export_utils.publish_isos(repo.working_dir, image_prefix, http_publish_dir, https_publish_dir, config.get(constants.ISO_SIZE_KEYWORD), progress_callback)
def test_make_http_dir(self): """ Tests the the http publishing directory is created by publish_isos if it does not exist """ # Setup os.path.isdir.return_value = False # Confirm that when https_dir is not None and the directory doesn't exist, it is created export_utils.publish_isos('/working/dir', 'prefix', http_dir='/http/dir') os.makedirs.assert_called_once_with('/http/dir')
def test_removing_dirs(self): """ Tests that publish_isos cleans out all the directories in the working directory except the ISOs. Since storing stuff in the working directory is bad form and should eventually change, this """ # Setup os.walk.return_value = [('/root', ['dir1', 'dir2'], [])] # Test that for each directory, rmtree is called export_utils.publish_isos('/working/dir', 'prefix') self.assertEqual(2, shutil.rmtree.call_count) self.assertEqual('/root/dir1', shutil.rmtree.call_args_list[0][0][0]) self.assertEqual('/root/dir2', shutil.rmtree.call_args_list[1][0][0])
def test_linking_https_iso_images(self): """ Tests that each file in the working directory (after it is cleaned up) is symlinked to the https publishing directory """ # Setup os.walk.return_value = [('/root', [], ['file1', 'file2'])] expected_call1 = ('/root/file1', '/https/dir/file1') expected_call2 = ('/root/file2', '/https/dir/file2') # Test that for each file, os.symlink is called correctly export_utils.publish_isos('/working/dir', 'prefix', https_dir='/https/dir') self.assertEqual(2, os.symlink.call_count) self.assertEqual(expected_call1, os.symlink.call_args_list[0][0]) self.assertEqual(expected_call2, os.symlink.call_args_list[1][0])