Пример #1
0
 def test_environment_in_context(self, mock_juju_command):
     # The command includes the environment if found in the context as
     # the environment variable JUJU_ENV.
     with self.patch_environ:
         juju('deploy', 'test-charm')
     mock_juju_command.assert_called_once_with(
         'deploy', '-e', self.env, 'test-charm')
Пример #2
0
 def test_model_in_context(self, mock_juju_command):
     # The command includes the model if found in the context as the
     # environment variable JUJU_MODEL.
     with self.patch_model:
         juju('deploy', 'test-charm')
     mock_juju_command.assert_called_once_with(
         'deploy', '-m', self.model, 'test-charm')
Пример #3
0
 def test_environment_in_context(self, mock_juju_command):
     # The command includes the environment if found in the context as
     # the environment variable JUJU_ENV.
     with self.patch_environ:
         juju('deploy', 'test-charm')
     mock_juju_command.assert_called_once_with('deploy', '-e', self.env,
                                               'test-charm')
Пример #4
0
 def test_raise_process_errors(self, mock_juju_command):
     # The command raises the last ProcessError after a number of retries.
     mock_juju_command.side_effect = [self.process_error] * 10
     with mock.patch("time.sleep") as mock_sleep:
         with mock.patch("os.environ", {}):
             with self.assertRaises(ProcessError) as info:
                 juju("deploy", "test-charm")
     self.assertIs(self.process_error, info.exception)
     self.assertEqual(10, mock_juju_command.call_count)
     mock_juju_command.assert_called_with("deploy", "test-charm")
     self.assertEqual(10, mock_sleep.call_count)
     mock_sleep.assert_called_with(1)
Пример #5
0
 def test_raise_process_errors(self, mock_juju_command):
     # The command raises the last ProcessError after a number of retries.
     mock_juju_command.side_effect = [self.process_error] * 10
     with mock.patch('time.sleep') as mock_sleep:
         with mock.patch('os.environ', {}):
             with self.assertRaises(ProcessError) as info:
                 juju('deploy', 'test-charm')
     self.assertIs(self.process_error, info.exception)
     self.assertEqual(10, mock_juju_command.call_count)
     mock_juju_command.assert_called_with('deploy', 'test-charm')
     self.assertEqual(10, mock_sleep.call_count)
     mock_sleep.assert_called_with(1)
Пример #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_handle_process_errors(self, mock_juju_command):
     # The command retries several times before failing if a ProcessError is
     # raised.
     mock_juju_command.side_effect = ([self.process_error] * 9) + ["value"]
     with mock.patch("time.sleep") as mock_sleep:
         with mock.patch("os.environ", {}):
             result = juju("deploy", "test-charm")
     self.assertEqual("value", result)
     self.assertEqual(10, mock_juju_command.call_count)
     mock_juju_command.assert_called_with("deploy", "test-charm")
     self.assertEqual(9, mock_sleep.call_count)
     mock_sleep.assert_called_with(1)
Пример #9
0
 def test_handle_process_errors(self, mock_juju_command):
     # The command retries several times before failing if a ProcessError is
     # raised.
     mock_juju_command.side_effect = ([self.process_error] * 9) + ['value']
     with mock.patch('time.sleep') as mock_sleep:
         with mock.patch('os.environ', {}):
             result = juju('deploy', 'test-charm')
     self.assertEqual('value', result)
     self.assertEqual(10, mock_juju_command.call_count)
     mock_juju_command.assert_called_with('deploy', 'test-charm')
     self.assertEqual(9, mock_sleep.call_count)
     mock_sleep.assert_called_with(1)
Пример #10
0
 def test_environment_in_args(self, mock_juju_command):
     # The command includes the environment if provided with --environment.
     with self.patch_environ:
         juju("deploy", "--environment", "another-env", "test-charm")
     mock_juju_command.assert_called_once_with("deploy", "--environment", "another-env", "test-charm")
Пример #11
0
 def test_environment_not_in_context(self, mock_juju_command):
     # The command does not include the environment if not found in the
     # context as the environment variable JUJU_ENV.
     with mock.patch("os.environ", {}):
         juju("deploy", "test-charm")
     mock_juju_command.assert_called_once_with("deploy", "test-charm")
Пример #12
0
 def test_model_in_args(self, mock_juju_command):
     # The command includes the model if provided with --model.
     with self.patch_model:
         juju('deploy', '--model', 'another-model', 'test-charm')
     mock_juju_command.assert_called_once_with(
         'deploy', '--model', 'another-model', 'test-charm')
Пример #13
0
 def test_model_not_in_context(self, mock_juju_command):
     # The command does not include the model if not found in the context as
     # the environment variable JUJU_MODEL.
     with mock.patch('os.environ', {}):
         juju('deploy', 'test-charm')
     mock_juju_command.assert_called_once_with('deploy', 'test-charm')
Пример #14
0
 def test_environment_in_args(self, mock_juju_command):
     # The command includes the environment if provided with --environment.
     with self.patch_environ:
         juju('deploy', '--environment', 'another-env', 'test-charm')
     mock_juju_command.assert_called_once_with(
         'deploy', '--environment', 'another-env', 'test-charm')
Пример #15
0
 def test_environment_in_args(self, mock_juju_command):
     # The command includes the environment if provided with --environment.
     with self.patch_environ:
         juju('deploy', '--environment', 'another-env', 'test-charm')
     mock_juju_command.assert_called_once_with('deploy', '--environment',
                                               'another-env', 'test-charm')