def test_fetch_roles_file(self, mock_exists):
     with tempfile.NamedTemporaryFile(mode='w') as roles_file:
         yaml.dump([{'name': 'Foobar'}], roles_file)
         with mock.patch('tripleoclient.utils.rel_or_abs_path') as mock_rf:
             mock_rf.return_value = roles_file.name
             self.assertEqual(utils.fetch_roles_file(roles_file.name),
                              [{'name': 'Foobar'}])
    def take_action(self, parsed_args):
        self.log.debug("take_action(%s)" % parsed_args)

        if parsed_args.cleanup not in image_uploader.CLEANUP:
            raise oscexc.CommandError('--cleanup must be one of: %s' %
                                      ', '.join(image_uploader.CLEANUP))

        roles_data = utils.fetch_roles_file(parsed_args.roles_file)

        env = utils.build_prepare_env(
            parsed_args.environment_files,
            parsed_args.environment_directories
        )

        lock = processlock.ProcessLock()
        params = kolla_builder.container_images_prepare_multi(
            env, roles_data, dry_run=parsed_args.dry_run,
            cleanup=parsed_args.cleanup, lock=lock)
        env_data = build_env_file(params, self.app.command_options)
        if parsed_args.output_env_file:
            if os.path.exists(parsed_args.output_env_file):
                self.log.warning("Output env file exists, "
                                 "moving it to backup.")
                shutil.move(parsed_args.output_env_file,
                            parsed_args.output_env_file + ".backup")
            utils.safe_write(parsed_args.output_env_file, env_data)
        else:
            self.app.stdout.write(env_data)
示例#3
0
    def take_action(self, parsed_args):
        self.log.debug("take_action(%s)" % parsed_args)

        if parsed_args.cleanup not in image_uploader.CLEANUP:
            raise oscexc.CommandError('--cleanup must be one of: %s' %
                                      ', '.join(image_uploader.CLEANUP))

        roles_data = utils.fetch_roles_file(parsed_args.roles_file)

        env = utils.build_prepare_env(parsed_args.environment_files,
                                      parsed_args.environment_directories)

        params = kolla_builder.container_images_prepare_multi(
            env,
            roles_data,
            dry_run=parsed_args.dry_run,
            cleanup=parsed_args.cleanup)
        env_data = build_env_file(params, self.app.command_options)
        if parsed_args.output_env_file:
            with os.fdopen(
                    os.open(parsed_args.output_env_file,
                            os.O_CREAT | os.O_TRUNC | os.O_WRONLY, 0o666),
                    'w') as f:
                f.write(env_data)
        else:
            self.app.stdout.write(env_data)
    def _get_default_role_counts(self, parsed_args):

        if parsed_args.roles_file:
            roles_data = utils.fetch_roles_file(parsed_args.roles_file,
                                                parsed_args.templates)
        else:
            # Assume default role counts
            return {
                'ControllerCount': 1,
                'ComputeCount': 1,
                'ObjectStorageCount': 0,
                'BlockStorageCount': 0,
                'CephStorageCount': 0
            }

        default_role_counts = {}
        for r in roles_data:
            count_default = r.get('CountDefault', 0)
            default_role_counts.setdefault(
                "%sCount" % r['name'],
                count_default)

        return default_role_counts
    def take_action(self, parsed_args):
        self.log.debug("take_action(%s)" % parsed_args)
        self.log.warning("[DEPRECATED] This command has been deprecated and "
                         "replaced by the 'openstack tripleo container image "
                         "prepare' command.")

        roles_data = utils.fetch_roles_file(parsed_args.roles_file) or set()

        env = utils.build_prepare_env(
            parsed_args.environment_files,
            parsed_args.environment_directories
        )

        if roles_data:
            service_filter = kolla_builder.build_service_filter(
                env, roles_data)
        else:
            service_filter = None
        mapping_args = {
            'tag': parsed_args.tag,
            'namespace': parsed_args.namespace,
            'name_prefix': parsed_args.prefix,
            'name_suffix': parsed_args.suffix,
        }
        self.parse_set_values(mapping_args, parsed_args.set)
        pd = env.get('parameter_defaults', {})
        kolla_builder.set_neutron_driver(pd, mapping_args)

        output_images_file = (parsed_args.output_images_file
                              or 'container_images.yaml')
        modify_role = None
        modify_vars = None
        append_tag = None
        if parsed_args.modify_role:
            modify_role = parsed_args.modify_role
            append_tag = time.strftime('-modified-%Y%m%d%H%M%S')
        if parsed_args.modify_vars:
            with open(parsed_args.modify_vars) as m:
                modify_vars = yaml.safe_load(m.read())

        prepare_data = kolla_builder.container_images_prepare(
            excludes=parsed_args.excludes,
            includes=parsed_args.includes,
            service_filter=service_filter,
            push_destination=parsed_args.push_destination,
            mapping_args=mapping_args,
            output_env_file=parsed_args.output_env_file,
            output_images_file=output_images_file,
            tag_from_label=parsed_args.tag_from_label,
            modify_role=modify_role,
            modify_vars=modify_vars,
            append_tag=append_tag,
            template_file=parsed_args.template_file
        )
        if parsed_args.output_env_file:
            params = prepare_data[parsed_args.output_env_file]
            output_env_file_expanded = os.path.expanduser(
                parsed_args.output_env_file)
            if os.path.exists(output_env_file_expanded):
                self.log.warning("Output env file exists, "
                                 "moving it to backup.")
                shutil.move(output_env_file_expanded,
                            output_env_file_expanded + ".backup")
            utils.safe_write(output_env_file_expanded,
                             build_env_file(params, self.app.command_options))

        result = prepare_data[output_images_file]
        result_str = yaml.safe_dump({'container_images': result},
                                    default_flow_style=False)
        sys.stdout.write(result_str)

        if parsed_args.output_images_file:
            utils.safe_write(parsed_args.output_images_file, result_str)
示例#6
0
    def take_action(self, parsed_args):
        self.log.debug("take_action(%s)" % parsed_args)

        roles_data = utils.fetch_roles_file(parsed_args.roles_file) or set()

        env = utils.build_prepare_env(parsed_args.environment_files,
                                      parsed_args.environment_directories)

        if roles_data:
            service_filter = kolla_builder.build_service_filter(
                env, roles_data)
        else:
            service_filter = None
        mapping_args = {
            'tag': parsed_args.tag,
            'namespace': parsed_args.namespace,
            'name_prefix': parsed_args.prefix,
            'name_suffix': parsed_args.suffix,
        }
        self.parse_set_values(mapping_args, parsed_args.set)

        output_images_file = (parsed_args.output_images_file
                              or 'container_images.yaml')
        modify_role = None
        modify_vars = None
        append_tag = None
        if parsed_args.modify_role:
            modify_role = parsed_args.modify_role
            append_tag = time.strftime('-modified-%Y%m%d%H%M%S')
        if parsed_args.modify_vars:
            modify_vars = yaml.safe_load(open(parsed_args.modify_vars).read())

        prepare_data = kolla_builder.container_images_prepare(
            excludes=parsed_args.excludes,
            includes=parsed_args.includes,
            service_filter=service_filter,
            pull_source=parsed_args.pull_source,
            push_destination=parsed_args.push_destination,
            mapping_args=mapping_args,
            output_env_file=parsed_args.output_env_file,
            output_images_file=output_images_file,
            tag_from_label=parsed_args.tag_from_label,
            modify_role=modify_role,
            modify_vars=modify_vars,
            append_tag=append_tag)
        if parsed_args.output_env_file:
            params = prepare_data[parsed_args.output_env_file]
            with os.fdopen(
                    os.open(parsed_args.output_env_file,
                            os.O_CREAT | os.O_TRUNC | os.O_WRONLY, 0o666),
                    'w') as f:
                f.write(build_env_file(params, self.app.command_options))

        result = prepare_data[output_images_file]
        result_str = yaml.safe_dump({'container_images': result},
                                    default_flow_style=False)
        sys.stdout.write(result_str)

        if parsed_args.output_images_file:
            with os.fdopen(
                    os.open(parsed_args.output_images_file,
                            os.O_CREAT | os.O_TRUNC | os.O_WRONLY, 0o666),
                    'w') as f:
                f.write(result_str)