def take_action(self, parsed_args):
        self.log.debug("take_action(%s)" % parsed_args)
        osc_plugin = self.app.client_manager.rdomanager_oscplugin
        if parsed_args.templates:
            management = None
        else:
            management = osc_plugin.management()

        orchestration = osc_plugin.orchestration()
        update_manager = update.PackageUpdateManager(
            tuskarclient=management,
            heatclient=orchestration,
            novaclient=self.app.client_manager.compute,
            plan_id=parsed_args.plan,
            stack_id=parsed_args.stack,
            tht_dir=parsed_args.templates,
            environment_files=parsed_args.environment_files)
        if parsed_args.abort_update:
            print("cancelling package update on stack {0}".format(
                parsed_args.stack))
            update_manager.cancel()
        else:
            status, resources = update_manager.get_status()
            if status not in ['IN_PROGRESS', 'WAITING']:
                print("starting package update on stack {0}".format(
                    parsed_args.stack))
                update_manager.update()

        if parsed_args.interactive:
            update_manager.do_interactive_update()
        else:
            print("stack {0} status: {1}".format(parsed_args.stack, status))
Ejemplo n.º 2
0
 def test_update(self, mock_time):
     heatclient = mock.MagicMock()
     novaclient = mock.MagicMock()
     mock_time.return_value = 123.5
     heatclient.stacks.get.return_value = mock.MagicMock(
         stack_name='stack', id='stack_id')
     stack_fields = {
         'stack_id': 'stack_id',
         'stack_name': 'mystack',
         'template': 'template body',
         'environment': {},
         'files': {},
     }
     update.PackageUpdateManager(
         heatclient=heatclient,
         novaclient=novaclient,
         stack_id='stack_id',
         stack_fields=stack_fields,
     ).update()
     params = {
         'existing': True,
         'stack_name': 'mystack',
         'stack_id': 'stack_id',
         'template': 'template body',
         'files': {},
         'environment': {
             'resource_registry': {
                 'resources': {
                     '*': {
                         '*': {
                             'UpdateDeployment': {'hooks': 'pre-update'}
                         }
                     }
                 }
             },
             'parameter_defaults': {
                 'DeployIdentifier': 123,
                 'UpdateIdentifier': 123,
                 'StackAction': 'UPDATE'
             },
         },
         'timeout_mins': 240,
     }
     heatclient.stacks.update.assert_called_once_with(**params)
    def take_action(self, parsed_args):
        if parsed_args.templates is None and parsed_args.answers_file is None:
            raise oscexc.CommandError(
                "You must specify either --templates or --answers-file")

        if parsed_args.answers_file is not None:
            with open(parsed_args.answers_file, 'r') as answers_file:
                answers = yaml.load(answers_file)

                if parsed_args.templates is None:
                    parsed_args.templates = answers['templates']
                if 'environments' in answers:
                    if parsed_args.environment_files is not None:
                        answers.environments.extend(
                            parsed_args.environment_files)
                    parsed_args.environment_files = answers['environments']

        self.log.debug("take_action(%s)" % parsed_args)
        clients = self.app.client_manager

        update_manager = update.PackageUpdateManager(
            heatclient=clients.orchestration,
            novaclient=clients.compute,
            stack_id=parsed_args.stack,
            tht_dir=parsed_args.templates,
            environment_files=parsed_args.environment_files)
        if parsed_args.abort_update:
            print("cancelling package update on stack {0}".format(
                parsed_args.stack))
            update_manager.cancel()
        else:
            status, resources = update_manager.get_status()
            if status not in ['IN_PROGRESS', 'WAITING']:
                print("starting package update on stack {0}".format(
                    parsed_args.stack))
                update_manager.update()

        if parsed_args.interactive:
            update_manager.do_interactive_update()
            status, _ = update_manager.get_status()
            if status not in ['COMPLETE']:
                raise exceptions.DeploymentError("Stack update failed.")
        else:
            print("stack {0} status: {1}".format(parsed_args.stack, status))
Ejemplo n.º 4
0
 def test_update(self, mock_template_contents, mock_env_files, mock_time):
     heatclient = mock.MagicMock()
     novaclient = mock.MagicMock()
     mock_time.return_value = 123.5
     heatclient.stacks.get.return_value = mock.MagicMock(stack_name='stack',
                                                         id='stack_id')
     mock_template_contents.return_value = ({}, 'template body')
     mock_env_files.return_value = ({}, {})
     update.PackageUpdateManager(heatclient=heatclient,
                                 novaclient=novaclient,
                                 stack_id='stack_id',
                                 tht_dir='/tmp/').update()
     params = {
         'existing': True,
         'stack_id': 'stack_id',
         'template': 'template body',
         'files': {},
         'parameters': {
             'UpdateIdentifier': 123,
             'StackAction': 'UPDATE'
         },
         'environment': {
             'resource_registry': {
                 'resources': {
                     '*': {
                         '*': {
                             'UpdateDeployment': {
                                 'hooks': 'pre-update'
                             }
                         }
                     }
                 }
             }
         },
         'timeout_mins': 240,
     }
     heatclient.stacks.update.assert_called_once_with(**params)
     mock_env_files.assert_called_once_with(env_paths=[])