Beispiel #1
0
 def test_make_charm_config_file(self):
     # make_charm_config_file() writes the passed configuration to a
     # temporary file as YAML.
     charm_config = {'foo': 'bar', 'spam': 'eggs', 'ham': 'jam'}
     # make_charm_config_file() returns the file object so that it
     # can be garbage collected properly.
     charm_config_file = charmhelpers.make_charm_config_file(charm_config)
     with open(charm_config_file.name) as config_in:
         written_config = config_in.read()
     self.assertEqual(yaml.dump(charm_config), written_config)
 def test_make_charm_config_file(self):
     # make_charm_config_file() writes the passed configuration to a
     # temporary file as YAML.
     charm_config = {'foo': 'bar',
                     'spam': 'eggs',
                     'ham': 'jam'}
     # make_charm_config_file() returns the file object so that it
     # can be garbage collected properly.
     charm_config_file = charmhelpers.make_charm_config_file(charm_config)
     with open(charm_config_file.name) as config_in:
         written_config = config_in.read()
     self.assertEqual(yaml.dump(charm_config), written_config)
Beispiel #3
0
def juju_deploy(
        charm_name, service_name=None, options=None, force_machine=None,
        charm_source=None, series=None):
    """Deploy and expose the charm. Return the first unit's public address.

    Also wait until the service is exposed and the first unit started.

    If service_name is None, use the name of the charm.
    If options are provided, they will be used when deploying the charm.
    If force_machine is not None, create the unit in the specified machine.
    If charm_source is None, dynamically retrieve the charm source directory.
    If series is None, the series specified in the SERIES environment variable
    is used if found, defaulting to "trusty".
    """
    # Note: this function is used by both the functional tests and
    # "make deploy": see the "if main" section below.
    if charm_source is None:
        # Dynamically retrieve the charm source based on the path of this file.
        charm_source = os.path.join(os.path.dirname(__file__), '..')
    if series is None:
        series = os.getenv('SERIES', '').strip() or 'trusty'
    logging.debug('setting up the charms repository')
    repo = setup_repository(charm_name, charm_source, series=series)
    args = ['deploy', '--repository', repo]
    if service_name is None:
        service_name = charm_name
    if options is not None:
        config_file = make_charm_config_file({service_name: options})
        args.extend(['--config', config_file.name])
    if force_machine is not None:
        args.extend(['--to', str(force_machine)])
    charm_url = 'local:{}/{}'.format(series, charm_name)
    args.append(charm_url)
    args.append(service_name)
    logging.debug('deploying {} from the repository in {}'.format(
        charm_url, repo))
    juju(*args)
    logging.debug('exposing {}'.format(service_name))
    juju('expose', service_name)
    logging.debug('waiting for the unit to be ready')
    return wait_for_unit(service_name)