def fetch_gui(juju_gui_source, logpath): """Retrieve the Juju GUI release/branch.""" # Retrieve a Juju GUI release. origin, version_or_branch = parse_source(juju_gui_source) if origin == 'branch': # Make sure we have the dependencies necessary for us to actually make # a build. _get_build_dependencies() # Create a release starting from a branch. juju_gui_source_dir = os.path.join(CURRENT_DIR, 'juju-gui-source') log('Retrieving Juju GUI source checkout from %s.' % version_or_branch) cmd_log(run('rm', '-rf', juju_gui_source_dir)) cmd_log(bzr_checkout(version_or_branch, juju_gui_source_dir)) log('Preparing a Juju GUI release.') logdir = os.path.dirname(logpath) fd, name = tempfile.mkstemp(prefix='make-distfile-', dir=logdir) log('Output from "make distfile" sent to %s' % name) with environ(NO_BZR='1'): run('make', '-C', juju_gui_source_dir, 'distfile', stdout=fd, stderr=fd) release_tarball = first_path_in_dir( os.path.join(juju_gui_source_dir, 'releases')) else: log('Retrieving Juju GUI release.') if origin == 'url': file_url = version_or_branch else: # Retrieve a release from Launchpad. launchpad = Launchpad.login_anonymously('Juju GUI charm', 'production') project = launchpad.projects['juju-gui'] file_url = get_release_file_url(project, origin, version_or_branch) log('Downloading release file from %s.' % file_url) release_tarball = os.path.join(CURRENT_DIR, 'release.tgz') cmd_log(run('curl', '-L', '-o', release_tarball, file_url)) return release_tarball
def fetch_gui_from_branch(branch_url, revision, logpath): """Retrieve the Juju GUI from a branch and build a release archive.""" # Inject NPM packages into the cache for faster building. prime_npm_cache(get_npm_cache_archive_url()) # Create a release starting from a branch. juju_gui_source_dir = os.path.join(CURRENT_DIR, 'juju-gui-source') checkout_args, revno = ([], 'latest revno') if revision is None else ( ['--revision', revision], 'revno {}'.format(revision)) log('Retrieving Juju GUI source checkout from {} ({}).'.format( branch_url, revno)) cmd_log(run('rm', '-rf', juju_gui_source_dir)) checkout_args.extend([branch_url, juju_gui_source_dir]) cmd_log(bzr_checkout(*checkout_args)) log('Preparing a Juju GUI release.') logdir = os.path.dirname(logpath) fd, name = tempfile.mkstemp(prefix='make-distfile-', dir=logdir) log('Output from "make distfile" sent to %s' % name) with environ(NO_BZR='1'): run('make', '-C', juju_gui_source_dir, 'distfile', stdout=fd, stderr=fd) return first_path_in_dir( os.path.join(juju_gui_source_dir, 'releases'))
def fetch_gui(juju_gui_source, logpath): """Retrieve the Juju GUI release/branch.""" # Retrieve a Juju GUI release. origin, version_or_branch = parse_source(juju_gui_source) if origin == 'branch': # Make sure we have the dependencies necessary for us to actually make # a build. _get_build_dependencies() # Create a release starting from a branch. juju_gui_source_dir = os.path.join(CURRENT_DIR, 'juju-gui-source') log('Retrieving Juju GUI source checkout from %s.' % version_or_branch) cmd_log(run('rm', '-rf', juju_gui_source_dir)) cmd_log(bzr_checkout(version_or_branch, juju_gui_source_dir)) log('Preparing a Juju GUI release.') logdir = os.path.dirname(logpath) fd, name = tempfile.mkstemp(prefix='make-distfile-', dir=logdir) log('Output from "make distfile" sent to %s' % name) with environ(NO_BZR='1'): run('make', '-C', juju_gui_source_dir, 'distfile', stdout=fd, stderr=fd) release_tarball = first_path_in_dir( os.path.join(juju_gui_source_dir, 'releases')) else: log('Retrieving Juju GUI release.') if origin == 'url': file_url = version_or_branch else: # Retrieve a release from Launchpad. launchpad = Launchpad.login_anonymously( 'Juju GUI charm', 'production') project = launchpad.projects['juju-gui'] file_url = get_release_file_url(project, origin, version_or_branch) log('Downloading release file from %s.' % file_url) release_tarball = os.path.join(CURRENT_DIR, 'release.tgz') cmd_log(run('curl', '-L', '-o', release_tarball, file_url)) return release_tarball
def test_both_env_and_agent_file(self): # If the API address is included in both the environment and the # agent.conf file, the environment variable takes precedence. with environ(JUJU_API_ADDRESSES=self.env_address): with self.agent_file([self.agent_address]) as (unit_dir, _): self.assertEqual(self.env_address, get_api_address(unit_dir))
def test_multiple_addresses_in_env(self): # If multiple API addresses are listed in the environment variable, # the first one is returned. addresses = "{} foo.example.com:42".format(self.env_address) with environ(JUJU_API_ADDRESSES=addresses): self.assertEqual(self.env_address, get_api_address())
def test_retrieving_address_from_env(self): # The API address is correctly retrieved from the environment. with environ(JUJU_API_ADDRESSES=self.env_address): self.assertEqual(self.env_address, get_api_address())
def test_multiple_addresses_in_env(self): # If multiple API addresses are listed in the environment variable, # the first one is returned. addresses = '{} foo.example.com:42'.format(self.env_address) with environ(JUJU_API_ADDRESSES=addresses): self.assertEqual(self.env_address, get_api_address())