예제 #1
0
 def test_not_started(self, mock_juju_status):
     # The function waits until the unit is in a started state.
     mock_juju_status.side_effect = (
         self.get_status(state='pending'), self.get_status(),
     )
     unit_info = wait_for_unit(self.service)
     self.assertEqual(self.address, unit_info['public-address'])
     self.assertEqual(2, mock_juju_status.call_count)
예제 #2
0
 def test_service_not_exposed(self, mock_juju_status):
     # The function waits until the service is exposed.
     mock_juju_status.side_effect = (
         self.get_status(exposed=False), self.get_status(),
     )
     unit_info = wait_for_unit(self.service)
     self.assertEqual(self.address, unit_info['public-address'])
     self.assertEqual(2, mock_juju_status.call_count)
예제 #3
0
 def test_service_not_deployed(self, mock_juju_status):
     # The function waits until the service is deployed.
     mock_juju_status.side_effect = (
         {}, {'services': {}}, self.get_status(),
     )
     unit_info = wait_for_unit(self.service)
     self.assertEqual(self.address, unit_info['public-address'])
     self.assertEqual(3, mock_juju_status.call_count)
예제 #4
0
 def test_unit_not_ready(self, mock_juju_status):
     # The function waits until the unit is created.
     mock_juju_status.side_effect = (
         {"services": {"juju-gui": {}}},
         {"services": {"juju-gui": {"units": {}}}},
         self.get_status(),
     )
     unit_info = wait_for_unit(self.service)
     self.assertEqual(self.address, unit_info["public-address"])
     self.assertEqual(3, mock_juju_status.call_count)
예제 #5
0
 def test_unit_not_ready(self, mock_juju_status):
     # The function waits until the unit is created.
     mock_juju_status.side_effect = (
         {'services': {'juju-gui': {}}},
         {'services': {'juju-gui': {'units': {}}}},
         self.get_status(),
     )
     unit_info = wait_for_unit(self.service)
     self.assertEqual(self.address, unit_info['public-address'])
     self.assertEqual(3, mock_juju_status.call_count)
예제 #6
0
def juju_deploy(charm_name,
                app_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 app_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 "xenial".
    """
    # 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 DEFAULT_SERIES
    logging.debug('setting up the charm')
    path = tempfile.mkdtemp()
    rsync(charm_source, path)
    args = ['deploy', '--series', series]
    if app_name is None:
        app_name = charm_name
    if options is not None:
        config_file = make_charm_config_file({app_name: options})
        args.extend(['--config', config_file.name])
    if force_machine is not None:
        args.extend(['--to', str(force_machine)])
    args.append(path)
    args.append(app_name)
    logging.debug('deploying {} (series: {}) from {}'.format(
        app_name, series, path))
    juju(*args)
    logging.debug('exposing {}'.format(app_name))
    juju('expose', app_name)
    logging.debug('waiting for the unit to be ready')
    return wait_for_unit(app_name)
예제 #7
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)
예제 #8
0
 def test_public_address(self, mock_juju_status):
     # The public address is returned when the service is ready.
     mock_juju_status.return_value = self.get_status()
     unit_info = wait_for_unit(self.service)
     self.assertEqual(self.address, unit_info["public-address"])
     self.assertEqual(1, mock_juju_status.call_count)
예제 #9
0
 def test_unit_number(self, mock_juju_status):
     # Different unit names are correctly handled.
     mock_juju_status.return_value = self.get_status(unit=42)
     unit_info = wait_for_unit(self.service)
     self.assertEqual(self.address, unit_info["public-address"])
     self.assertEqual(1, mock_juju_status.call_count)
예제 #10
0
 def test_public_address(self, mock_juju_status):
     # The public address is returned when the service is ready.
     mock_juju_status.return_value = self.get_status()
     unit_info = wait_for_unit(self.service)
     self.assertEqual(self.address, unit_info['public-address'])
     self.assertEqual(1, mock_juju_status.call_count)
예제 #11
0
 def test_unit_number(self, mock_juju_status):
     # Different unit names are correctly handled.
     mock_juju_status.return_value = self.get_status(unit=42)
     unit_info = wait_for_unit(self.service)
     self.assertEqual(self.address, unit_info['public-address'])
     self.assertEqual(1, mock_juju_status.call_count)