Ejemplo n.º 1
0
def deploy_bundle(bundle, model, model_ctxt=None, force=False):
    """Deploy the given bundle file in the specified model.

    The force param is used to enable zaza testing with Juju with charms
    that would be rejected by juju (e.g. series not supported).

    :param bundle: Path to bundle file
    :type bundle: str
    :param model: Name of model to deploy bundle in
    :type model: str
    :param model_ctxt: Additional context to be used when rendering bundle
                       templates.
    :type model_ctxt: {}
    :param force: Pass the force parameter if True
    :type force: Boolean
    """
    logging.info("Deploying bundle '{}' on to '{}' model"
                 .format(bundle, model))
    cmd = ['juju', 'deploy', '-m', model, bundle]
    if force:
        cmd.append('--force')
    with tempfile.TemporaryDirectory() as tmpdirname:
        for overlay in render_overlays(bundle, tmpdirname,
                                       model_ctxt=model_ctxt):
            logging.info("Deploying overlay '{}' on to '{}' model"
                         .format(overlay, model))
            cmd.extend(['--overlay', overlay])
        utils.check_output_logging(cmd)
Ejemplo n.º 2
0
 def test_check_output_logging_process_error(self):
     self.patch_object(lc_utils.logging, 'info')
     self.patch_object(lc_utils.subprocess, 'Popen')
     popen_mock = mock.MagicMock()
     popen_mock.stdout = io.StringIO("logline1\n")
     poll_output = [1, 1, None]
     popen_mock.poll.side_effect = poll_output.pop
     self.Popen.return_value = popen_mock
     with self.assertRaises(subprocess.CalledProcessError):
         lc_utils.check_output_logging(['cmd', 'arg1', 'arg2'])
Ejemplo n.º 3
0
 def test_check_output_logging(self):
     self.patch_object(lc_utils.logging, 'info')
     self.patch_object(lc_utils.subprocess, 'Popen')
     popen_mock = mock.MagicMock()
     popen_mock.stdout = io.StringIO("logline1\nlogline2\nlogline3\n")
     poll_output = [0, 0, None, None, None]
     popen_mock.poll.side_effect = poll_output.pop
     self.Popen.return_value = popen_mock
     lc_utils.check_output_logging(['cmd', 'arg1', 'arg2'])
     log_calls = [
         mock.call('logline1'),
         mock.call('logline2'),
         mock.call('logline3')]
     self.info.assert_has_calls(log_calls)
Ejemplo n.º 4
0
def deploy_bundle(bundle, model, model_ctxt=None, force=False):
    """Deploy the given bundle file in the specified model.

    The force param is used to enable zaza testing with Juju with charms
    that would be rejected by juju (e.g. series not supported).

    :param bundle: Path to bundle file
    :type bundle: str
    :param model: Name of model to deploy bundle in
    :type model: str
    :param model_ctxt: Additional context to be used when rendering bundle
                       templates.
    :type model_ctxt: {}
    :param force: Pass the force parameter if True
    :type force: Boolean
    """
    logging.info("Deploying bundle '{}' on to '{}' model".format(
        bundle, model))
    cmd = ['juju', 'deploy', '-m', model]
    if force:
        cmd.append('--force')
    with tempfile.TemporaryDirectory() as tmpdirname:
        bundle_out = '{}/{}'.format(tmpdirname, os.path.basename(bundle))
        # Bundle templates should only exist in the bundle directory so
        # explicitly set the Jinja2 load path.
        bundle_template = get_template(bundle,
                                       template_dir=os.path.dirname(bundle))
        if bundle_template:
            if os.path.exists(bundle):
                raise zaza_exceptions.TemplateConflict(
                    "Found bundle template ({}) and bundle ({})".format(
                        bundle_template.filename, bundle))
            render_template(bundle_template, bundle_out, model_ctxt=model_ctxt)
            cmd.append(bundle_out)
        else:
            cmd.append(bundle)
        for overlay in render_overlays(bundle,
                                       tmpdirname,
                                       model_ctxt=model_ctxt):
            logging.info("Deploying overlay '{}' on to '{}' model".format(
                overlay, model))
            cmd.extend(['--overlay', overlay])
        for attempt in tenacity.Retrying(stop=tenacity.stop_after_attempt(3),
                                         wait=tenacity.wait_exponential(
                                             multiplier=1, min=2, max=10)):
            with attempt:
                utils.check_output_logging(cmd)
Ejemplo n.º 5
0
def deploy_bundle(bundle, model):
    """Deploy the given bundle file in the specified model.

    :param bundle: Path to bundle file
    :type bundle: str
    :param model: Name of model to deploy bundle in
    :type model: str
    """
    logging.info("Deploying bundle '{}' on to '{}' model".format(
        bundle, model))
    cmd = ['juju', 'deploy', '-m', model, bundle]
    with tempfile.TemporaryDirectory() as tmpdirname:
        for overlay in render_overlays(bundle, tmpdirname):
            logging.info("Deploying overlay '{}' on to '{}' model".format(
                overlay, model))
            cmd.extend(['--overlay', overlay])
        utils.check_output_logging(cmd)